Module Name:    src
Committed By:   christos
Date:           Thu Apr  2 17:40:33 UTC 2020

Modified Files:
        src/usr.bin/kdump: ioctlprint.1 kdump.c mkioctls


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/usr.bin/kdump/ioctlprint.1
cvs rdiff -u -r1.133 -r1.134 src/usr.bin/kdump/kdump.c
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/kdump/mkioctls

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/kdump/ioctlprint.1
diff -u src/usr.bin/kdump/ioctlprint.1:1.2 src/usr.bin/kdump/ioctlprint.1:1.3
--- src/usr.bin/kdump/ioctlprint.1:1.2	Thu Apr  2 04:38:22 2020
+++ src/usr.bin/kdump/ioctlprint.1	Thu Apr  2 13:40:33 2020
@@ -1,4 +1,4 @@
-.\" $NetBSD: ioctlprint.1,v 1.2 2020/04/02 08:38:22 wiz Exp $
+.\" $NetBSD: ioctlprint.1,v 1.3 2020/04/02 17:40:33 christos Exp $
 .\"
 .\" Copyright (c) 2020 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -35,6 +35,7 @@
 .Nd display descriptive ioctl value
 .Sh SYNOPSIS
 .Nm
+.Op Fl l
 .Op Fl e Ar emulation
 .Op Fl f Ar format
 .Op Ar arg ...
@@ -45,6 +46,10 @@ utility displays information about the f
 to by one or more
 .Ar arg
 arguments.
+The argument can either be an
+.Xr ioctl
+symbolic name or the
+ioctl value.
 .Pp
 The options are as follows:
 .Bl -tag -width Fl
@@ -61,8 +66,10 @@ output.
 .Pp
 The following conversion characters can be used:
 .Bl -tag -width xxxx
+.It \&%E
+Symbolic decoded ioctl string.
 .It \&%e
-Decoded ioctl string.
+Decoded ioctl string with hex values.
 .It \&%n
 Descriptive ioctl operation name.
 .It \&%x
@@ -77,6 +84,10 @@ The default format is:
 .Bd -literal -offset indent
 "%n %e %x\\n"
 .Ed
+.It Fl l
+List all 
+.Xr ioctl 2
+known.
 .El
 .Sh SEE ALSO
 .Xr kdump 1 ,

Index: src/usr.bin/kdump/kdump.c
diff -u src/usr.bin/kdump/kdump.c:1.133 src/usr.bin/kdump/kdump.c:1.134
--- src/usr.bin/kdump/kdump.c:1.133	Wed Apr  1 23:32:46 2020
+++ src/usr.bin/kdump/kdump.c	Thu Apr  2 13:40:33 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: kdump.c,v 1.133 2020/04/02 03:32:46 kamil Exp $	*/
+/*	$NetBSD: kdump.c,v 1.134 2020/04/02 17:40:33 christos Exp $	*/
 
 /*-
  * Copyright (c) 1988, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1988, 19
 #if 0
 static char sccsid[] = "@(#)kdump.c	8.4 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: kdump.c,v 1.133 2020/04/02 03:32:46 kamil Exp $");
+__RCSID("$NetBSD: kdump.c,v 1.134 2020/04/02 17:40:33 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -108,9 +108,9 @@ static const char * const linux_ptrace_o
 	"PTRACE_SYSCALL",
 };
 
-static const char default_format[] = { "%n %e %x\n" };
+static const char default_format[] = { "%n\t%E\t%x\n" };
 
-static void	fmtprint(const char *, unsigned long int);
+static void	fmtprint(const char *, const struct ioctlinfo *ii);
 static int	fread_tail(void *, size_t, size_t);
 static int	dumpheader(struct ktr_header *);
 static int	output_ts(const struct timespec *);
@@ -132,11 +132,11 @@ static void	rprint(register_t);
 static const char *signame(long, int);
 static void hexdump_buf(const void *, int, int);
 static void visdump_buf(const void *, int, int);
+static const struct ioctlinfo *find_ioctl(const char *);
 
 int
 main(int argc, char **argv)
 {
-	unsigned long int u;
 	unsigned int ktrlen, size;
 	int ch;
 	void *m;
@@ -145,15 +145,16 @@ main(int argc, char **argv)
 	const char *emul_name = "netbsd";
 	const char *format = default_format;
 	int col;
-	int e;
 	char *cp;
 
 	setprogname(argv[0]);
 
 	if (strcmp(getprogname(), "ioctlprint") == 0) {
+		const struct ioctlinfo *ii;
+		int list = 0;
 		int i;
 
-		while ((ch = getopt(argc, argv, "e:f:")) != -1)
+		while ((ch = getopt(argc, argv, "e:f:l")) != -1)
 			switch (ch) {
 			case 'e':
 				emul_name = optarg;
@@ -163,22 +164,34 @@ main(int argc, char **argv)
 					errx(1, "Too many formats");
 				format = optarg;
 				break;
+			case 'l':
+				list = 1;
+				break;
 			default:
 				usage();
 				break;
 			}
+
 		setemul(emul_name, 0, 0);
 		argv += optind;
 		argc -= optind;
 
-		if (argc < 1)
+		if (argc < 1 && !list)
 			usage();
 
+		if (list) {
+			for (i = 0; ioctlinfo[i].name != NULL; i++) {
+				fmtprint(format, &ioctlinfo[i]);
+			}
+			return 0;
+		}
+
 		for (i = 0; i < argc; i++) {
-			u = strtou(argv[i], NULL, 0, 0, ULONG_MAX, &e);
-			if (e)
-				errc(1, e, "invalid argument: `%s'", argv[i]);
-			fmtprint(format, u);
+			if ((ii = find_ioctl(argv[i])) == NULL) {
+				warnx("Can't find ioctl `%s'", argv[i]);
+				continue;
+			}
+			fmtprint(format, ii);
 		}
 		return 0;
 	}
@@ -338,11 +351,11 @@ main(int argc, char **argv)
 }
 
 static void
-fmtprint(const char *fmt, unsigned long int u)
+fmtprint(const char *fmt, const struct ioctlinfo *ii)
 {
-	const char *name;
 	int c;
 
+
 	while ((c = *fmt++) != '\0') {
 		switch (c) {
 		default:
@@ -368,21 +381,23 @@ fmtprint(const char *fmt, unsigned long 
 			default:
 				putchar(c);
 				break;
+			case 'E':
+				printf("%s", ii->expr);
+				break;
 			case 'e':
-				ioctldecode(u);
+				ioctldecode(ii->value);
 				break;
 			case 'n':
-				name = ioctlname(u);
-				printf("%s", name ? name : "(null)");
+				printf("%s", ii->name);
 				break;
 			case 'x':
-				printf("%#lx", u);
+				printf("%#lx", ii->value);
 				break;
 			case 'o':
-				printf("%#lo", u);
+				printf("%#lo", ii->value);
 				break;
 			case 'd': case 'i':
-				printf("%ld", u);
+				printf("%ld", ii->value);
 				break;
 			}
 			break;
@@ -1313,3 +1328,36 @@ usage(void)
 	}
 	exit(1);
 }
+
+static const struct ioctlinfo *
+find_ioctl_by_name(const char *name)
+{
+	for (size_t i = 0; ioctlinfo[i].name != NULL; i++) {
+		if (strcmp(name, ioctlinfo[i].name) == 0)
+			return &ioctlinfo[i];
+	}
+	return NULL;
+}
+
+static const struct ioctlinfo *
+find_ioctl_by_value(unsigned long value)
+{
+	for (size_t i = 0; ioctlinfo[i].name != NULL; i++) {
+		if (value == ioctlinfo[i].value)
+			return &ioctlinfo[i];
+	}
+	return NULL;
+}
+
+static const struct ioctlinfo *
+find_ioctl(const char *name)
+{
+	if (isalpha((unsigned char)*name)) {
+		return find_ioctl_by_name(name);
+	}
+	int e;
+	unsigned long u = strtou(name, NULL, 0, 0, ULONG_MAX, &e);
+	if (e)
+		errc(1, e, "invalid argument: `%s'", name);
+	return find_ioctl_by_value(u);
+}

Index: src/usr.bin/kdump/mkioctls
diff -u src/usr.bin/kdump/mkioctls:1.53 src/usr.bin/kdump/mkioctls:1.54
--- src/usr.bin/kdump/mkioctls:1.53	Sat Sep 29 10:41:36 2018
+++ src/usr.bin/kdump/mkioctls	Thu Apr  2 13:40:33 2020
@@ -1,5 +1,5 @@
 #!/bin/sh
-#	$NetBSD: mkioctls,v 1.53 2018/09/29 14:41:36 rmind Exp $
+#	$NetBSD: mkioctls,v 1.54 2020/04/02 17:40:33 christos Exp $
 #
 # Copyright (c) 1994
 #	The Regents of the University of California.  All rights reserved.
@@ -39,6 +39,9 @@
 : ${CC:=cc}
 : ${SED:=sed}
 
+set -x
+AWK=gawk
+
 echo "/* Automatically generated file, do not edit! */"
 #echo "#define const" 	# XXX: timepps lossage
 echo "#define COMPAT_43"
@@ -198,20 +201,36 @@ BEGIN {
 		if ($i ~ /define/)
 			break;
 	++i;
-	printf("/* %s [%s] */\n", $0, $i);
+	name = $i;
+	printf("/* %s [%s] */\n", $0, name);
 	# 
-	if ($i ~ /^[A-Z0-9a-z_]*$/) {
-		if (keep[$i] != 1) {
-			printf("\t#ifdef %s\n", $i);
-			printf("\tcase %s:\n\t\treturn \"%s\";\n", $i, $i);
-			printf("\t#endif /* %s */\n", $i);
-			keep[$i] = 1;
-		}
-	}
+	if (name !~ /^[A-Z0-9a-z_]*$/)
+		next;
+	if (keep[name] == 1)
+		next;
+	keep[name] = 1;
+	printf("\t#ifdef %s\n", name);
+	printf("\tcase %s:\n\t\treturn \"%s\";\n", name, name);
+	printf("\t#endif /* %s */\n", $i);
+	name = name;
+	names[name] = name;
+	exprs[name] = "";
+	files[name] = filename;
+	do {
+		++i;
+		exprs[name] = exprs[name] " " $i;
+	} while ($i !~ /.*)/);
+	exprs[name] = substr(exprs[name], 2);
 }
 END {
 	print "\tdefault:\n\t\treturn NULL;\n"
 	print "\t}\n"
 	print "}"
+	print "const struct ioctlinfo ioctlinfo[] = {\n";
+	for (name in names) {
+		printf("\t{ .name = \"%s\", .expr = \"%s\", .value = %s },\n",
+		    names[name], exprs[name], names[name]);
+	}
+	print "\t{ .name = NULL, .expr = NULL, .value = 0 },\n};";
 }
 '

Reply via email to