Back to home page

LXR

 
 

    


0001 #!/bin/bash
0002 # Translate the bits making up a GFP mask
0003 # (c) 2009, Mel Gorman <mel@csn.ul.ie>
0004 # Licensed under the terms of the GNU GPL License version 2
0005 SOURCE=
0006 GFPMASK=none
0007 
0008 # Helper function to report failures and exit
0009 die() {
0010         echo ERROR: $@
0011         if [ "$TMPFILE" != "" ]; then
0012                 rm -f $TMPFILE
0013         fi
0014         exit -1
0015 }
0016 
0017 usage() {
0018         echo "usage: gfp-translate [-h] [ --source DIRECTORY ] gfpmask"
0019         exit 0
0020 }
0021 
0022 # Parse command-line arguments
0023 while [ $# -gt 0 ]; do
0024         case $1 in
0025                 --source)
0026                         SOURCE=$2
0027                         shift 2
0028                         ;;
0029                 -h)
0030                         usage
0031                         ;;
0032                 --help)
0033                         usage
0034                         ;;
0035                 *)
0036                         GFPMASK=$1
0037                         shift
0038                         ;;
0039         esac
0040 done
0041 
0042 # Guess the kernel source directory if it's not set. Preference is in order of
0043 # o current directory
0044 # o /usr/src/linux
0045 if [ "$SOURCE" = "" ]; then
0046         if [ -r "/usr/src/linux/Makefile" ]; then
0047                 SOURCE=/usr/src/linux
0048         fi
0049         if [ -r "`pwd`/Makefile" ]; then
0050                 SOURCE=`pwd`
0051         fi
0052 fi
0053 
0054 # Confirm that a source directory exists
0055 if [ ! -r "$SOURCE/Makefile" ]; then
0056         die "Could not locate kernel source directory or it is invalid"
0057 fi
0058 
0059 # Confirm that a GFP mask has been specified
0060 if [ "$GFPMASK" = "none" ]; then
0061         usage
0062 fi
0063 
0064 # Extract GFP flags from the kernel source
0065 TMPFILE=`mktemp -t gfptranslate-XXXXXX` || exit 1
0066 grep -q ___GFP $SOURCE/include/linux/gfp.h
0067 if [ $? -eq 0 ]; then
0068         grep "^#define ___GFP" $SOURCE/include/linux/gfp.h | sed -e 's/u$//' | grep -v GFP_BITS > $TMPFILE
0069 else
0070         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
0071 fi
0072 
0073 # Parse the flags
0074 IFS="
0075 "
0076 echo Source: $SOURCE
0077 echo Parsing: $GFPMASK
0078 for LINE in `cat $TMPFILE`; do
0079         MASK=`echo $LINE | awk '{print $3}'`
0080         if [ $(($GFPMASK&$MASK)) -ne 0 ]; then
0081                 echo $LINE
0082         fi
0083 done
0084 
0085 rm -f $TMPFILE
0086 exit 0