2 # Translate the bits making up a GFP mask
3 # (c) 2009, Mel Gorman <mel@csn.ul.ie>
4 # Licensed under the terms of the GNU GPL License version 2
8 # Helper function to report failures and exit
11 if [ "$TMPFILE" != "" ]; then
18 echo "usage: gfp-translate [-h] [ --source DIRECTORY ] gfpmask"
22 # Parse command-line arguments
23 while [ $# -gt 0 ]; do
42 # Guess the kernel source directory if it's not set. Preference is in order of
45 if [ "$SOURCE" = "" ]; then
46 if [ -r "/usr/src/linux/Makefile" ]; then
49 if [ -r "`pwd`/Makefile" ]; then
54 # Confirm that a source directory exists
55 if [ ! -r "$SOURCE/Makefile" ]; then
56 die
"Could not locate kernel source directory or it is invalid"
59 # Confirm that a GFP mask has been specified
60 if [ "$GFPMASK" = "none" ]; then
64 # Extract GFP flags from the kernel source
65 TMPFILE
=`mktemp -t gfptranslate-XXXXXX` ||
exit 1
66 grep -q ___GFP
$SOURCE/include
/linux
/gfp.h
68 grep "^#define ___GFP" $SOURCE/include
/linux
/gfp.h |
sed -e 's/u$//' |
grep -v GFP_BITS
> $TMPFILE
70 grep "^#define __GFP" $SOURCE/include
/linux
/gfp.h |
sed -e 's/(__force gfp_t)//' |
sed -e 's/u)/)/' |
grep -v GFP_BITS |
sed -e 's/)\//) \//' > $TMPFILE
77 echo Parsing
: $GFPMASK
78 for LINE
in `cat $TMPFILE`; do
79 MASK
=`echo $LINE | awk '{print $3}'`
80 if [ $
(($GFPMASK&$MASK)) -ne 0 ]; then