3 # Copyright (c) 2001 Wichert Akkerman <wichert@cistron.nl>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
42 echo "usage: $0 include-directory [asm-subdirectory]" >&2
52 # Build the list of all ioctls
53 regexp='^[[:space:]]*#[[:space:]]*define[[:space:]]\+[A-Z][A-Z0-9_]*[[:space:]]\+0x'"$type"'..\>'
54 (cd "$dir" && grep "$regexp" "$@" /dev/null 2>/dev/null) |
55 sed -ne "s,$asm/,asm/,g"'
56 s/^\(.*\):[[:space:]]*#[[:space:]]*define[[:space:]]*\([A-Z0-9_]*\)[[:space:]]*\(0x'"$type"'..\).*/ { "\1", "\2", \3 },/p' \
62 lookup_ioctls 03 linux/hdreg.h
63 lookup_ioctls 22 scsi/sg.h
64 lookup_ioctls 46 linux/fb.h
65 lookup_ioctls 4B linux/kd.h
66 lookup_ioctls 4C linux/loop.h
67 lookup_ioctls 53 linux/cdrom.h scsi/scsi.h scsi/scsi_ioctl.h
68 lookup_ioctls 54 $asm/ioctls.h asm-generic/ioctls.h
69 lookup_ioctls 56 linux/vt.h
70 lookup_ioctls '7[12]' linux/videotext.h
71 lookup_ioctls 89 $asm/sockios.h asm-generic/sockios.h linux/sockios.h
72 lookup_ioctls 8B linux/wireless.h
74 if [ -e $dir/Kbuild ]; then
75 # kernel has exported user space headers, so query only them
78 find . -mindepth 2 -name Kbuild | \
79 sed -e 's:^\./::' -e 's:/Kbuild:/*:' | \
81 echo "$asm/* asm-generic/*"
83 # special case: some headers aren't exported directly
84 files="${files} media/* net/bluetooth/* pcmcia/*"
86 # older kernel so just assume some headers
87 files="linux/* $asm/* asm-generic/* scsi/* sound/*"
90 # Build the list of all ioctls
92 # { "asm/ioctls.h", "TIOCSWINSZ", 0x5414 },
93 # { "asm/mce.h", "MCE_GETCLEAR_FLAGS", _IOC(_IOC_NONE,'M',3,0) },
94 regexp='^[[:space:]]*#[[:space:]]*define[[:space:]]\+[A-Z][A-Z0-9_]*[[:space:]]\+_S\?\(IO\|IOW\|IOR\|IOWR\)\>'
95 (cd $dir && grep $regexp $files 2>/dev/null) | \
98 -e 's/^\(.*\):[[:space:]]*#[[:space:]]*define[[:space:]]*\([A-Z0-9_]*\)[[:space:]]*_S\?I.*(\([^[,]*\)[[:space:]]*,[[:space:]]*\([^,)]*\).*/ { "\1", "\2", _IOC(_IOC_NONE,\3,\4,0) },/p' \
101 # Sort and drop dups?
102 # sort -u <ioctls.h >ioctls1.h && mv ioctls1.h ioctls.h
106 # Collect potential ioctl names. ('bases' is a bad name. Sigh)
107 # Some use a special base to offset their ioctls on. Extract that as well.
108 # Some use 2 defines: _IOC(_IOC_NONE,DM_IOCTL,DM_LIST_DEVICES_CMD,....)
110 -e 's/.*_IOC_NONE.*,[[:space:]]*\([A-Z][A-Z0-9_]\+\)[[:space:]]*,[[:space:]]*\([A-Z][A-Z0-9_]\+\)[[:space:]+,].*/\1\n\2/p' \
111 -e 's/.*_IOC_NONE.*,[[:space:]]*\([A-Z][A-Z0-9_]\+\)[[:space:]+,].*/\1/p' \
114 for base in $bases; do
115 echo "Looking for $base"
116 regexp="^[[:space:]]*#[[:space:]]*define[[:space:]]\+$base"
117 line=$( (cd $dir && grep -h $regexp 2>/dev/null $files) | grep -v '\<_IO')
118 if [ x"$line" != x ]; then
119 echo "$base is a #define" # "($line)"
120 echo "$line" >> ioctldefs.h
123 if ! grep "\<$base\>" ioctldefs.h >/dev/null 2>/dev/null; then
124 # Not all ioctl's are defines ... some (like the DM_* stuff)
125 # are enums, so we have to extract that crap ourself
128 # -P: inhibit generation of linemarkers
129 ${CPP:-cpp} -P $(grep -l $base $files 2>/dev/null) | sed '/^$/d' | \
130 awk -v base="$base" '{
133 while ($NF != "};") {
140 print "#define " base " (" val ")"
148 if ! grep "\<$base\>" ioctldefs.h >/dev/null 2>/dev/null; then
149 echo "Can't find the definition for $base"
151 echo "$base is an enum"
156 # Sort and drop dups?
157 # sort -u <ioctldefs.h >ioctldefs1.h && mv ioctldefs1.h ioctldefs.h