diff options
Diffstat (limited to 'lib/libsysdecode')
-rw-r--r-- | lib/libsysdecode/Makefile | 23 | ||||
-rw-r--r-- | lib/libsysdecode/mkioctls | 97 | ||||
-rw-r--r-- | lib/libsysdecode/sysdecode.3 | 1 | ||||
-rw-r--r-- | lib/libsysdecode/sysdecode.h | 1 | ||||
-rw-r--r-- | lib/libsysdecode/sysdecode_ioctlname.3 | 57 |
5 files changed, 178 insertions, 1 deletions
diff --git a/lib/libsysdecode/Makefile b/lib/libsysdecode/Makefile index 8eb7908..a6d3ba1 100644 --- a/lib/libsysdecode/Makefile +++ b/lib/libsysdecode/Makefile @@ -4,10 +4,31 @@ LIB= sysdecode -SRCS= utrace.c +SRCS= ioctl.c utrace.c INCS= sysdecode.h MAN+= sysdecode.3 \ + sysdecode_ioctlname.3 \ sysdecode_utrace.3 +CLEANFILES= ioctl.c + +.if defined(COMPAT_32BIT) +CPP+= -m32 +.endif + +.if ${MK_PF} != "no" +CFLAGS+=-DPF +.endif + +# Workaround duplicate declarations in <netinet/ip_compat.h> +CFLAGS.gcc.ioctl.c+= -Wno-redundant-decls +CFLAGS.gcc+= ${CFLAGS.gcc.${.IMPSRC}} + +ioctl.c: mkioctls + env MACHINE=${MACHINE} CPP="${CPP}" \ + /bin/sh ${.CURDIR}/mkioctls ${DESTDIR}${INCLUDEDIR} > ${.TARGET} + +beforedepend: ioctl.c + .include <bsd.lib.mk> diff --git a/lib/libsysdecode/mkioctls b/lib/libsysdecode/mkioctls new file mode 100644 index 0000000..e174d30 --- /dev/null +++ b/lib/libsysdecode/mkioctls @@ -0,0 +1,97 @@ +#!/bin/sh +# +# $FreeBSD$ + +set -e + +if [ $# -ne 1 ]; then + echo "usage: sh $0 include-dir" + exit 1 +fi + +includedir="$1" + +LC_ALL=C; export LC_ALL + +# Build a list of headers that have ioctls in them. +# XXX should we use an ANSI cpp? +ioctl_includes=$( + cd $includedir + find -H -s * -name '*.h' | \ + egrep -v '(.*disk.*|net/pfvar|net/if_pfsync)\.h' | \ + xargs egrep -l \ +'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | + awk '{printf("#include <%s>\\n", $1)}' +) + +: ${MACHINE=$(uname -m)} +case "${MACHINE}" in +*pc98*) + ioctl_includes="$ioctl_includes#include <sys/diskpc98.h>\\n" + ;; +*) + ioctl_includes="$ioctl_includes#include <sys/diskmbr.h>\\n" + ;; +esac + +awk -v x="$ioctl_includes" 'BEGIN {print x}' | + $CPP -nostdinc -I$includedir -dM -DCOMPAT_43TTY - | + awk -v ioctl_includes="$ioctl_includes" ' +BEGIN { + print "/* XXX obnoxious prerequisites. */" + print "#define COMPAT_43" + print "#define COMPAT_43TTY" + 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 <bsm/audit.h>" + print "#include <net/ethernet.h>" + print "#include <net/if.h>" + print "#ifdef PF" + print "#include <net/pfvar.h>" + print "#include <net/if_pfsync.h>" + print "#endif" + print "#include <net/route.h>" + print "#include <netinet/in.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 <stdio.h>" + print "#include <cam/cam.h>" + print "#include <stddef.h>" + print "#include <stdint.h>" + print "#include <sysdecode.h>" + print "" + print ioctl_includes + print "" + print "const char *" + print "sysdecode_ioctlname(unsigned long val)" + print "{" + print "\tconst char *str = NULL;" + print "" +} + +/^#[ ]*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; + # + printf("\t"); + if (n++ > 0) + printf("else "); + printf("if (val == %s)\n", $i); + printf("\t\tstr = \"%s\";\n", $i); +} +END { + print "" + print "\treturn (str);" + print "}" +} +' diff --git a/lib/libsysdecode/sysdecode.3 b/lib/libsysdecode/sysdecode.3 index fd1677d..52faf53 100644 --- a/lib/libsysdecode/sysdecode.3 +++ b/lib/libsysdecode/sysdecode.3 @@ -39,6 +39,7 @@ The library includes several functions that provide descriptive names of values associated with system calls. .Sh SEE ALSO +.Xr sysdecode_ioctlname 3 , .Xr sysdecode_utrace 3 .Sh HISTORY The diff --git a/lib/libsysdecode/sysdecode.h b/lib/libsysdecode/sysdecode.h index 10feee1..aa95838 100644 --- a/lib/libsysdecode/sysdecode.h +++ b/lib/libsysdecode/sysdecode.h @@ -29,6 +29,7 @@ #ifndef __SYSDECODE_H__ #define __SYSDECODE_H__ +const char *sysdecode_ioctlname(unsigned long _val); int sysdecode_utrace(FILE *_fp, void *_buf, size_t _len); #endif /* !__SYSDECODE_H__ */ diff --git a/lib/libsysdecode/sysdecode_ioctlname.3 b/lib/libsysdecode/sysdecode_ioctlname.3 new file mode 100644 index 0000000..6479f03 --- /dev/null +++ b/lib/libsysdecode/sysdecode_ioctlname.3 @@ -0,0 +1,57 @@ +.\" +.\" Copyright (c) 2015 John Baldwin <jhb@FreeBSD.org> +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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. +.\" +.\" $FreeBSD$ +.\" +.Dd December 12, 2015 +.Dt sysdecode_ioctlname 3 +.Os +.Sh NAME +.Nm sysdecode_ioctlname +.Nd lookup name of device control command +.Sh LIBRARY +.Lb libsysdecode +.Sh SYNOPSIS +.Ft conts char * +.Fn sysdecode_ioctlname "unsigned long request" +.Sh DESCRIPTION +The +.Fn sysdecode_ioctlname +function returns the name of a device control request identified by +.Fa request . +A table of names is generated during the build of the +.Nm sysdecode +library from system headers that maps device control request values to +the name of the corresponding C macro. +.Sh RETURN VALUES +The +.Fn sysdecode_ioctlname +function returns the name of a device control request if +.Fa request +is a known value; +otherwise +.Dv NULL . +.Sh SEE ALSO +.Xr sysdecode 3 |