1set -e 2 3# $FreeBSD: src/usr.bin/kdump/mkioctls,v 1.15.2.5 2002/11/15 18:22:31 ru Exp $ 4# $DragonFly: src/usr.bin/kdump/mkioctls,v 1.9 2008/01/05 13:36:37 corecode Exp $ 5 6if [ "x$1" = "x-s" ]; then 7 use_switch=1 8 shift 9else 10 use_switch=0 11fi 12 13if [ -z "$1" ]; then 14 echo "usage: sh $0 [-s] include-dir" 15 exit 1 16fi 17 18LC_ALL=C; export LC_ALL 19 20# Build a list of headers that have ioctls in them. 21# XXX should we use an ANSI cpp? 22# XXX netipx conflicts with netns (leave out netns). 23# XXX leave out cam/, isa/ pccard/, pci/, and usb/ because they 24# are fake softlinks and handled by bus/ 25ioctl_includes=` 26 cd $1 27 find -s * -name '*.h' -follow | 28 egrep -v '^(netns/)|^(cam/)|^(isa/)|^(pccard/)|^(pci/)|^(usb/)|^(netproto/natm/)' | 29 xargs egrep -l \ 30'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | 31 awk '{printf("#include <%s>\\\\n", $1)}' 32` 33 34awk -v x="$ioctl_includes" 'BEGIN {print x}' | 35 gcc -D_KERNEL_STRUCTURES -E -I$1 -dM - | 36 awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" ' 37BEGIN { 38 print "/* XXX obnoxious prerequisites. */" 39 print "#define COMPAT_43" 40 print "#define _KERNEL_STRUCTURES" 41 print "#include <sys/param.h>" 42 print "#include <sys/devicestat.h>" 43 print "#include <sys/disklabel.h>" 44 print "#include <sys/diskslice.h>" 45 print "#include <sys/socket.h>" 46 print "#include <sys/time.h>" 47 print "#include <sys/tty.h>" 48 print "#include <net/ethernet.h>" 49 print "#include <net/if.h>" 50 print "#include <net/if_arp.h>" 51 print "#include <net/if_var.h>" 52 print "#include <net/route.h>" 53 print "#include <netatm/atm.h>" 54 print "#include <netatm/atm_if.h>" 55 print "#include <netatm/atm_sap.h>" 56 print "#include <netatm/atm_sys.h>" 57 print "#include <netinet/in.h>" 58 print "#include <net/ip_mroute/ip_mroute.h>" 59 print "#include <netinet6/in6_var.h>" 60 print "#include <netinet6/nd6.h>" 61 print "#include <netinet6/ip6_mroute.h>" 62 print "#include <stdio.h>" 63 print "#include <cam/cam.h>" 64 print "" 65 print ioctl_includes 66 print "" 67 print "const char *ioctlname(u_long);" 68 print "" 69 print "const char *" 70 print "ioctlname(u_long val)" 71 print "{" 72 print "" 73 if (use_switch) 74 print "\tswitch(val) {" 75} 76 77/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ { 78 79 # find where the name starts 80 for (i = 1; i <= NF; i++) 81 if ($i ~ /define/) 82 break; 83 ++i; 84 # 85 if (use_switch) 86 printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i); 87 else 88 printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i); 89 90} 91END { 92 if (use_switch) 93 print "\t}" 94 print "\n\treturn(NULL);" 95 print "}" 96} 97' 98