Wichert Akkerman | a966785 | 2001-03-17 17:26:34 +0000 | [diff] [blame] | 1 | #! /bin/sh |
Wichert Akkerman | b2c12f3 | 2001-08-03 21:53:26 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2001 Wichert Akkerman <wichert@cistron.nl> |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions |
| 8 | # are met: |
| 9 | # 1. Redistributions of source code must retain the above copyright |
| 10 | # notice, this list of conditions and the following disclaimer. |
| 11 | # 2. Redistributions in binary form must reproduce the above copyright |
| 12 | # notice, this list of conditions and the following disclaimer in the |
| 13 | # documentation and/or other materials provided with the distribution. |
| 14 | # 3. The name of the author may not be used to endorse or promote products |
| 15 | # derived from this software without specific prior written permission. |
| 16 | # |
| 17 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 18 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 19 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 20 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 21 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 22 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | # |
| 28 | # $Id$ |
| 29 | # |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 30 | |
Roland McGrath | 1e1b61d | 2003-03-31 01:03:34 +0000 | [diff] [blame] | 31 | # Validate arg count. |
Roland McGrath | d265669 | 2004-07-08 19:01:28 +0000 | [diff] [blame] | 32 | case $# in |
| 33 | 1) |
| 34 | dir="$1" |
| 35 | asm=asm |
| 36 | ;; |
| 37 | 2) |
| 38 | dir="$1" |
| 39 | asm="$2" |
| 40 | ;; |
| 41 | *) |
| 42 | echo "usage: $0 include-directory [asm-subdirectory]" >&2 |
Roland McGrath | 1e1b61d | 2003-03-31 01:03:34 +0000 | [diff] [blame] | 43 | exit 1 |
Roland McGrath | d265669 | 2004-07-08 19:01:28 +0000 | [diff] [blame] | 44 | ;; |
| 45 | esac |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 46 | |
Roland McGrath | 718f9a6 | 2004-06-04 02:03:06 +0000 | [diff] [blame] | 47 | lookup_ioctls() |
| 48 | { |
| 49 | type="$1" |
| 50 | shift |
| 51 | |
| 52 | # Build the list of all ioctls |
| 53 | regexp='^[[:space:]]*#[[:space:]]*define[[:space:]]\+[A-Z][A-Z0-9_]*[[:space:]]\+0x'"$type"'..\>' |
Denys Vlasenko | e6d113f | 2009-02-23 13:22:06 +0000 | [diff] [blame] | 54 | (cd "$dir" && grep "$regexp" "$@" /dev/null 2>/dev/null) | |
Roland McGrath | 61e0beb | 2004-07-12 06:11:16 +0000 | [diff] [blame] | 55 | sed -ne "s,$asm/,asm/,g"' |
| 56 | s/^\(.*\):[[:space:]]*#[[:space:]]*define[[:space:]]*\([A-Z0-9_]*\)[[:space:]]*\(0x'"$type"'..\).*/ { "\1", "\2", \3 },/p' \ |
Roland McGrath | 718f9a6 | 2004-06-04 02:03:06 +0000 | [diff] [blame] | 57 | >> ioctls.h |
| 58 | } |
| 59 | |
Denys Vlasenko | e6d113f | 2009-02-23 13:22:06 +0000 | [diff] [blame] | 60 | |
| 61 | > ioctls.h |
| 62 | |
Roland McGrath | 7166bb0 | 2004-10-06 22:31:38 +0000 | [diff] [blame] | 63 | lookup_ioctls 22 scsi/sg.h |
Roland McGrath | 718f9a6 | 2004-06-04 02:03:06 +0000 | [diff] [blame] | 64 | lookup_ioctls 46 linux/fb.h |
| 65 | lookup_ioctls 4B linux/kd.h |
Roland McGrath | 7166bb0 | 2004-10-06 22:31:38 +0000 | [diff] [blame] | 66 | lookup_ioctls 53 linux/cdrom.h scsi/scsi.h scsi/scsi_ioctl.h |
Dmitry V. Levin | ae4db5e | 2010-04-07 11:22:28 +0000 | [diff] [blame] | 67 | lookup_ioctls 54 $asm/ioctls.h asm-generic/ioctls.h |
Roland McGrath | 718f9a6 | 2004-06-04 02:03:06 +0000 | [diff] [blame] | 68 | lookup_ioctls 56 linux/vt.h |
| 69 | lookup_ioctls '7[12]' linux/videotext.h |
Dmitry V. Levin | ae4db5e | 2010-04-07 11:22:28 +0000 | [diff] [blame] | 70 | lookup_ioctls 89 $asm/sockios.h asm-generic/sockios.h linux/sockios.h |
Roland McGrath | 718f9a6 | 2004-06-04 02:03:06 +0000 | [diff] [blame] | 71 | lookup_ioctls 8B linux/wireless.h |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 72 | |
Denys Vlasenko | e6d113f | 2009-02-23 13:22:06 +0000 | [diff] [blame] | 73 | if [ -e $dir/Kbuild ]; then |
| 74 | # kernel has exported user space headers, so query only them |
| 75 | files=$( |
| 76 | cd $dir || exit |
| 77 | find . -mindepth 2 -name Kbuild | \ |
| 78 | sed -e 's:^\./::' -e 's:/Kbuild:/*:' | \ |
| 79 | grep -v '^asm-' |
| 80 | echo "$asm/* asm-generic/*" |
| 81 | ) |
| 82 | else |
| 83 | # older kernel so just assume some headers |
Dmitry V. Levin | ae4db5e | 2010-04-07 11:22:28 +0000 | [diff] [blame] | 84 | files="linux/* $asm/* asm-generic/* scsi/* sound/*" |
Denys Vlasenko | e6d113f | 2009-02-23 13:22:06 +0000 | [diff] [blame] | 85 | fi |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 86 | |
Wichert Akkerman | a966785 | 2001-03-17 17:26:34 +0000 | [diff] [blame] | 87 | # Build the list of all ioctls |
Denys Vlasenko | e6d113f | 2009-02-23 13:22:06 +0000 | [diff] [blame] | 88 | # Example output: |
| 89 | # { "asm/ioctls.h", "TIOCSWINSZ", 0x5414 }, |
| 90 | # { "asm/mce.h", "MCE_GETCLEAR_FLAGS", _IOC(_IOC_NONE,'M',3,0) }, |
Wichert Akkerman | b50c907 | 2001-08-03 21:49:34 +0000 | [diff] [blame] | 91 | regexp='^[[:space:]]*#[[:space:]]*define[[:space:]]\+[A-Z][A-Z0-9_]*[[:space:]]\+_S\?\(IO\|IOW\|IOR\|IOWR\)\>' |
Denys Vlasenko | e6d113f | 2009-02-23 13:22:06 +0000 | [diff] [blame] | 92 | (cd $dir && grep $regexp $files 2>/dev/null) | \ |
| 93 | sed -n \ |
| 94 | -e "s,$asm/,asm/,g" \ |
| 95 | -e 's/^\(.*\):[[:space:]]*#[[:space:]]*define[[:space:]]*\([A-Z0-9_]*\)[[:space:]]*_S\?I.*(\([^[,]*\)[[:space:]]*,[[:space:]]*\([^,)]*\).*/ { "\1", "\2", _IOC(_IOC_NONE,\3,\4,0) },/p' \ |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 96 | >> ioctls.h |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 97 | |
Denys Vlasenko | e6d113f | 2009-02-23 13:22:06 +0000 | [diff] [blame] | 98 | # Sort and drop dups? |
| 99 | # sort -u <ioctls.h >ioctls1.h && mv ioctls1.h ioctls.h |
| 100 | |
| 101 | |
| 102 | > ioctldefs.h |
| 103 | |
| 104 | # Collect potential ioctl names. ('bases' is a bad name. Sigh) |
Wichert Akkerman | a966785 | 2001-03-17 17:26:34 +0000 | [diff] [blame] | 105 | # Some use a special base to offset their ioctls on. Extract that as well. |
Denys Vlasenko | 3566e3d | 2009-02-20 17:32:34 +0000 | [diff] [blame] | 106 | # Some use 2 defines: _IOC(_IOC_NONE,DM_IOCTL,DM_LIST_DEVICES_CMD,....) |
Denys Vlasenko | 3566e3d | 2009-02-20 17:32:34 +0000 | [diff] [blame] | 107 | bases=$(sed -n \ |
| 108 | -e 's/.*_IOC_NONE.*,[[:space:]]*\([A-Z][A-Z0-9_]\+\)[[:space:]]*,[[:space:]]*\([A-Z][A-Z0-9_]\+\)[[:space:]+,].*/\1\n\2/p' \ |
| 109 | -e 's/.*_IOC_NONE.*,[[:space:]]*\([A-Z][A-Z0-9_]\+\)[[:space:]+,].*/\1/p' \ |
Denys Vlasenko | 8a4bdf8 | 2009-02-22 03:01:20 +0000 | [diff] [blame] | 110 | ioctls.h | sort -u) |
Denys Vlasenko | e6d113f | 2009-02-23 13:22:06 +0000 | [diff] [blame] | 111 | |
| 112 | for base in $bases; do |
Wichert Akkerman | a966785 | 2001-03-17 17:26:34 +0000 | [diff] [blame] | 113 | echo "Looking for $base" |
| 114 | regexp="^[[:space:]]*#[[:space:]]*define[[:space:]]\+$base" |
Denys Vlasenko | e6d113f | 2009-02-23 13:22:06 +0000 | [diff] [blame] | 115 | line=$( (cd $dir && grep -h $regexp 2>/dev/null $files) | grep -v '\<_IO') |
| 116 | if [ x"$line" != x ]; then |
| 117 | echo "$base is a #define" # "($line)" |
| 118 | echo "$line" >> ioctldefs.h |
| 119 | fi |
| 120 | |
| 121 | if ! grep "\<$base\>" ioctldefs.h >/dev/null 2>/dev/null; then |
| 122 | # Not all ioctl's are defines ... some (like the DM_* stuff) |
| 123 | # are enums, so we have to extract that crap ourself |
| 124 | ( |
| 125 | cd $dir || exit |
| 126 | # -P: inhibit generation of linemarkers |
| 127 | ${CPP:-cpp} -P $(grep -l $base $files 2>/dev/null) | sed '/^$/d' | \ |
| 128 | awk -v base="$base" '{ |
| 129 | if ($1 == "enum") { |
| 130 | val = 0 |
| 131 | while ($NF != "};") { |
| 132 | if (!getline) |
| 133 | exit |
| 134 | gsub(/,/, "") |
| 135 | if ($0 ~ /=/) |
| 136 | val = $NF |
| 137 | if ($1 == base) { |
| 138 | print "#define " base " (" val ")" |
| 139 | exit |
| 140 | } |
| 141 | val++ |
| 142 | } |
| 143 | } |
| 144 | }' |
| 145 | ) >> ioctldefs.h |
| 146 | if ! grep "\<$base\>" ioctldefs.h >/dev/null 2>/dev/null; then |
| 147 | echo "Can't find the definition for $base" |
| 148 | else |
| 149 | echo "$base is an enum" |
| 150 | fi |
| 151 | fi |
Wichert Akkerman | a966785 | 2001-03-17 17:26:34 +0000 | [diff] [blame] | 152 | done |
Denys Vlasenko | e6d113f | 2009-02-23 13:22:06 +0000 | [diff] [blame] | 153 | |
| 154 | # Sort and drop dups? |
| 155 | # sort -u <ioctldefs.h >ioctldefs1.h && mv ioctldefs1.h ioctldefs.h |