| # Translate the bits making up a GFP mask |
| # (c) 2009, Mel Gorman <mel@csn.ul.ie> |
| # Licensed under the terms of the GNU GPL License version 2 |
| # Helper function to report failures and exit |
| if [ "$TMPFILE" != "" ]; then |
| echo "usage: gfp-translate [-h] [ --source DIRECTORY ] gfpmask" |
| # Parse command-line arguments |
| # Guess the kernel source directory if it's not set. Preference is in order of |
| if [ "$SOURCE" = "" ]; then |
| if [ -r "/usr/src/linux/Makefile" ]; then |
| if [ -r "`pwd`/Makefile" ]; then |
| # Confirm that a source directory exists |
| if [ ! -r "$SOURCE/Makefile" ]; then |
| die "Could not locate kernel source directory or it is invalid" |
| # Confirm that a GFP mask has been specified |
| if [ "$GFPMASK" = "none" ]; then |
| # Extract GFP flags from the kernel source |
| TMPFILE=`mktemp -t gfptranslate-XXXXXX` || exit 1 |
| 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 |
| for LINE in `cat $TMPFILE`; do |
| MASK=`echo $LINE | awk '{print $3}'` |
| if [ $(($GFPMASK&$MASK)) -ne 0 ]; then |