summaryrefslogtreecommitdiffstats
path: root/usr.bin/kdump/mkioctls
blob: b8e4451e07f893695abd07049384c0041e77f3cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
set -e

# $FreeBSD$

if [ "x$1" = "x-s" ]; then
	use_switch=1
	shift
else
	use_switch=0
fi

if [ -z "$1" ]; then
	echo "usage: sh $0 [-s] include-dir"
	exit 1
fi

# Build a list of headers that have ioctls in them.
# XXX should we use an ANSI cpp?
# XXX netipx conflicts with netns (leave out netns).
ioctl_includes=`
	cd $1
	find * -name '*.h' -follow |
		egrep -v '^(netns)/' |
		xargs egrep -l \
'^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO[^a-z0-9_]' |
		sed -e 's/^/#include </' -e s'/$/>/'
`

echo "$ioctl_includes" |
	gcc -E -I$1 -dM - |
	awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" '
BEGIN {
	print "/* XXX obnoxious prerequisites. */"
	print "#define COMPAT_43"
	print "#include <sys/param.h>"
	print "#include <sys/devicestat.h>"
	print "#include <sys/disklabel.h>"
	print "#include <sys/socket.h>"
	print "#include <sys/time.h>"
	print "#include <sys/tty.h>"
	print "#include <net/ethernet.h>"
	print "#include <net/if.h>"
	print "#include <net/if_var.h>"
	print "#include <net/route.h>"
	print "#include <netatm/atm.h>"
	print "#include <netatm/atm_if.h>"
	print "#include <netatm/atm_sap.h>"
	print "#include <netatm/atm_sys.h>"
	print "#include <netinet/in.h>"
	print "#include <netinet/ip_compat.h>"
	print "#include <netinet/ip_fil.h>"
	print "#include <netinet/ip_auth.h>"
	print "#include <netinet/ip_nat.h>"
	print "#include <netinet/ip_frag.h>"
	print "#include <netinet/ip_state.h>"
	print "#include <netinet/ip_mroute.h>"
	print "#include <netinet6/in6_var.h>"
	print "#include <netinet6/nd6.h>"
	print "#include <netinet6/ip6_mroute.h>"
	print "#include <cam/cam.h>"
	print "#include <stdio.h>"
	print ""
	print ioctl_includes
	print ""
	print "char *"
	print "ioctlname(register_t val)"
	print "{"
	print ""
	if (use_switch)
		print "\tswitch(val) {"
}

/^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO/ {
	
	# find where the name starts
	for (i = 1; i <= NF; i++)
		if ($i ~ /define/)
			break;
	++i;
	# 
	if (use_switch)
		printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i);
	else
		printf("\tif (val ==  %s)\n\t\treturn(\"%s\");\n", $i, $i);

}
END {
	if (use_switch)
		print "\t}"
	print "\n\treturn(NULL);"
	print "}"
}
'
OpenPOWER on IntegriCloud