Implement new way to get the ioctl list for Linux: instead of

trying to #include every possible kernel header grab all the relevant
#defines from them and use those directly.
This commit is contained in:
Wichert Akkerman 2001-03-17 17:26:34 +00:00
parent cf1de759ed
commit a966785753
8 changed files with 623 additions and 620 deletions

View File

@ -1,3 +1,14 @@
2001-03-17 Wichert Akkerman <wakkerma@debian.org>
* linux/ioclsort.c: new file
* linux/ioctlent.sh: complete rewrite to use a more sane approach to get
the ioctl list that doesn't involve attempting to #include all kernel
headers
* linux/.cvsignore: added ioctdefs.h and ioctls.h which are generated
by the new ioctlent.sh
* ioctl.c: only look at the number and type bits for linux, since
ioctlent.sh no longer supplies the others
2001-03-08 John Hughes <john@Calva.COM>
* freebsd/syscalls.pl: On FreeBSD we must cope with COMPATibility syscalls,

1
NEWS
View File

@ -2,6 +2,7 @@ Changes in 4.3
==============
* Linux/ia64 port added
* The usual Linux syscall updates (includes 32bit uid/gid support),
* Linux ioctl list updated
* Support IPv6 scope ids
see ChangeLog for details

View File

@ -43,6 +43,10 @@ struct ioctlent ioctlent0[] = {
#include "ioctlent.h"
};
#ifdef LINUX
#include <asm/ioctl.h>
#endif
int nioctlents0 = sizeof ioctlent0 / sizeof ioctlent0[0];
#if SUPPORTED_PERSONALITIES >= 2
@ -81,6 +85,9 @@ long code;
struct ioctlent *iop, ioent;
ioent.code = code;
#ifdef LINUX
ioent.code &= (_IOC_NRMASK|_IOC_TYPEMASK);
#endif
iop = (struct ioctlent *) bsearch((char *) &ioent, (char *) ioctlent,
nioctlents, sizeof(struct ioctlent), compare);
return iop ? iop->symbol : NULL;

View File

@ -28,9 +28,6 @@
* $Id$
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>

View File

@ -1 +1,3 @@
Makefile
ioctldefs.h
ioctls.h

View File

@ -23,19 +23,17 @@ includedir = @includedir@
all: ioctlent.h errnoent.h signalent.h syscallent.h
ioctlent.raw: ioctlent.sh
$(SHELL) $(srcdir)/ioctlent.sh $(includedir) >$@
ioctlent.h: ioctlent.raw ioctlsort
ioctlent.h: ioctlsort
./ioctlsort >$@
ioctlsort: ioctlsort.o
$(CC) $(LDFLAGS) ioctlsort.o -o ioctlsort
ioctlsort.o: ../ioctlsort.c
ioctlsort.o: ioctlsort.c ioctdefs.h ioctls.h
$(CC) $(WARNFLAGS) $(DEFS) $(CPPFLAGS) $(INCLUDES) $(CFLAGS) -c $(srcdir)/../ioctlsort.c
ioctlsort.o: ioctlent.raw
ioctldefs.h ioctls.h: ioctlent.sh
sh ioctlent.sh
errnoent.h: ../errnoent.sh $(includedir)/linux/errno.h
$(SHELL) $(srcdir)/../errnoent.sh $(includedir)/*/errno.h >$@

File diff suppressed because it is too large Load Diff

View File

@ -1,98 +1,21 @@
#!/bin/sh
# Copyright (c) 1993, 1994, 1995 Rick Sladkey <jrs@world.std.com>
# All rights reserved.
#
# Copyright (c) 1995, 1996 Michael Elizabeth Chastain <mec@duracef.shout.net>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# $Id$
#! /bin/sh
# Files to find.
file_find='asm/*.h linux/*.h scsi/*.h'
files="linux/* asm/* scsi/*"
# Files to stop.
file_stop='asm/byteorder.h linux/config.h linux/pci.h linux/xd.h'
# Build the list of all ioctls
regexp='^[[:space:]]*#[[:space:]]*define[[:space:]]\+[A-Z][A-Z0-9_]*[[:space:]]\+_\(IO\|IOW\|IOR\|IOWR\)\>'
grep $regexp $files 2>/dev/null | \
sed -ne 's/^\(.*\):[[:space:]]*#[[:space:]]*define[[:space:]]*\([A-Z0-9_]*\)[[:space:]]*_I.*(\([^[,]*\),\([^,)]*\).*/ { "\1", "\2", _IOC(_IOC_NONE,\3,\4,0) },/p' \
> ioctls.h
# Defs to find.
# Work on the kernel source to convert all to df_iowr.
# Don't know how to find low-numbered ioctls in linux/mc146818rtc.h.
df_name='^[ ]*#[ ]*define[ ]+[A-Z_][A-Z0-9_]*[ ]+'
df_iowr='_IO|_IOR|_IOW|_IOWR'
df_NNNN='0[Xx](03|06|22|46|4B|4C|53|54|56|89|90)[0-9A-Fa-f][0-9A-Fa-f]'
df_4359='0[Xx]4359[0-9A-Fa-f][0-9A-Fa-f]' # linux/cyclades.h
df_470N='470[0-9]' # linux/fs.h (only in 1.2.13)
df_smix='MIXER_READ|MIXER_WRITE' # linux/soundcard.h
df_12NN='12[3-4][0-9]' # linux/umsdos_fs.h (only in 1.2.13)
df_tail='([() ]|$)'
def_find="$df_name($df_iowr|$df_NNNN|$df_4359|$df_470N|$df_smix|$df_12NN)$df_tail"
# Some use a special base to offset their ioctls on. Extract that as well.
: > ioctldefs.h
# Defs to stop.
ds_tail='_MAGIC|_PATCH'
ds_fdmp='FD(DEF|GET|SET)MEDIAPRM' # linux/fd.h aliases (only in 1.2.13)
ds_mtio='MTIOC(GET|SET)CONFIG' # linux/mtio.h needs config (only in 1.2.13)
def_stop="$ds_tail|$ds_fdmp|$ds_mtio"
bases=$(sed -ne 's/.*_IOC_NONE,\([A-Z][A-Z0-9_]\+\),.*/\1/p' ioctls.h | uniq | sort)
for base in $bases ; do
echo "Looking for $base"
regexp="^[[:space:]]*#[[:space:]]*define[[:space:]]\+$base"
grep -h $regexp 2>/dev/null $files | grep -v '\<_IO' >> ioctldefs.h
done
# Validate arg count.
if [ $# -ne 1 ]
then
echo "usage: $0 include-directory" >&2
exit 1
fi
# Grep through the files.
(
# Construct list: find files minus stop files.
cd $1 || exit
file_list=`(ls $file_find $file_stop $file_stop 2>/dev/null) | sort | uniq -u`
# Grep matching #define lines.
# Transform to C structure form.
# Filter out stop list.
egrep "$def_find" $file_list |
sed -n -e 's/^\(.*\):#[ ]*define[ ]*\([A-Z_][A-Z0-9_]*\).*$/ { "\1", "\2", \2 },/p' |
egrep -v "$def_stop"
) > ioctlent.tmp
# Generate the output file.
echo '/* This file is automatically generated by ioctlent.sh */'
echo
echo '#include <sys/types.h>'
echo
echo '/* Needed for <linux/baycom.h> */'
echo '#define BAYCOM_DEBUG'
echo
echo '/* Needed for <linux/cyclades.h> */'
echo '#include <linux/termios.h>'
echo '#include <linux/tqueue.h>'
echo
awk '{ print "#include <" substr($2, 2, length($2) - 3) ">" }' ioctlent.tmp | sort -u
echo
echo 'struct ioctlent ioctlent [] ='
echo '{'
cat ioctlent.tmp
echo '};'
# Clean up.
rm -f ioctlent.tmp