Re: svn commit: r301931 - head/tools/tools/decioctl

2016-06-15 Thread Sepherosa Ziehau
On Thu, Jun 16, 2016 at 5:12 AM, John Baldwin  wrote:
> On Wednesday, June 15, 2016 09:01:53 PM John Baldwin wrote:
>> Author: jhb
>> Date: Wed Jun 15 21:01:53 2016
>> New Revision: 301931
>> URL: https://svnweb.freebsd.org/changeset/base/301931
>>
>> Log:
>>   Add a tool to decode ioctl commands.
>>
>>   One or more ioctl command values can be passed as arguments on the command
>>   line.  For each value, the command is broken down into it's components
>>   (direction, group, number, and length).  In addition, if a command has a
>>   known name it is output via sysdecode_ioctlname().
>>
>>   Reviewed by:kib, emaste, avg
>>   Approved by:re (gjb)
>>   Differential Revision:  https://reviews.freebsd.org/D6851
>
> I've had a version of this in a private tree of utilities for several years.
> I added the sysdecode stuff yesterday though now that it's easy to do so.
>
> Sample output:
>
> % ./decioctl 0xc4d01902 0xc4e01902 0x4004667f
>   command :  dir  group num  len name
> 0xc4d01902: INOUT  0x19   2 1232 CAMIOCOMMAND
> 0xc4e01902: INOUT  0x19   2 1248
> 0x4004667f: OUT'f'  1274 FIONREAD

Haha, very nice :D

-- 
Tomorrow Will Never Die
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r301931 - head/tools/tools/decioctl

2016-06-15 Thread John Baldwin
On Wednesday, June 15, 2016 09:01:53 PM John Baldwin wrote:
> Author: jhb
> Date: Wed Jun 15 21:01:53 2016
> New Revision: 301931
> URL: https://svnweb.freebsd.org/changeset/base/301931
> 
> Log:
>   Add a tool to decode ioctl commands.
>   
>   One or more ioctl command values can be passed as arguments on the command
>   line.  For each value, the command is broken down into it's components
>   (direction, group, number, and length).  In addition, if a command has a
>   known name it is output via sysdecode_ioctlname().
>   
>   Reviewed by:kib, emaste, avg
>   Approved by:re (gjb)
>   Differential Revision:  https://reviews.freebsd.org/D6851

I've had a version of this in a private tree of utilities for several years.
I added the sysdecode stuff yesterday though now that it's easy to do so.

Sample output:

% ./decioctl 0xc4d01902 0xc4e01902 0x4004667f
  command :  dir  group num  len name
0xc4d01902: INOUT  0x19   2 1232 CAMIOCOMMAND
0xc4e01902: INOUT  0x19   2 1248
0x4004667f: OUT'f'  1274 FIONREAD

-- 
John Baldwin
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r301931 - head/tools/tools/decioctl

2016-06-15 Thread John Baldwin
Author: jhb
Date: Wed Jun 15 21:01:53 2016
New Revision: 301931
URL: https://svnweb.freebsd.org/changeset/base/301931

Log:
  Add a tool to decode ioctl commands.
  
  One or more ioctl command values can be passed as arguments on the command
  line.  For each value, the command is broken down into it's components
  (direction, group, number, and length).  In addition, if a command has a
  known name it is output via sysdecode_ioctlname().
  
  Reviewed by:  kib, emaste, avg
  Approved by:  re (gjb)
  Differential Revision:https://reviews.freebsd.org/D6851

Added:
  head/tools/tools/decioctl/
  head/tools/tools/decioctl/Makefile   (contents, props changed)
  head/tools/tools/decioctl/decioctl.c   (contents, props changed)

Added: head/tools/tools/decioctl/Makefile
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/tools/decioctl/Makefile  Wed Jun 15 21:01:53 2016
(r301931)
@@ -0,0 +1,10 @@
+# $FreeBSD$
+
+PROG=  decioctl
+SRCS=  decioctl.c
+MAN=
+BINDIR?= /usr/bin
+
+LIBADD=sysdecode
+
+.include 

Added: head/tools/tools/decioctl/decioctl.c
==
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ head/tools/tools/decioctl/decioctl.cWed Jun 15 21:01:53 2016
(r301931)
@@ -0,0 +1,94 @@
+/*-
+ * Copyright (c) 2005-2006,2016 John H. Baldwin 
+ * 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.
+ */
+
+#include 
+__FBSDID("$FreeBSD$");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static void
+usage(char **av)
+{
+   fprintf(stderr, "%s:  [ ... ]\n", av[0]);
+   exit(1);
+}
+
+int
+main(int ac, char **av)
+{
+   unsigned long cmd;
+   const char *name;
+   char *cp;
+   int group, i;
+
+   if (ac < 2)
+   usage(av);
+   printf("  command :  dir  group num  len name\n");
+   for (i = 1; i < ac; i++) {
+   errno = 0;
+   cmd = strtoul(av[i], , 0);
+   if (*cp != '\0' || errno != 0) {
+   fprintf(stderr, "Invalid integer: %s\n", av[i]);
+   usage(av);
+   }
+   printf("0x%08lx: ", cmd);
+   switch (cmd & IOC_DIRMASK) {
+   case IOC_VOID:
+   printf("VOID ");
+   break;
+   case IOC_OUT:
+   printf("OUT  ");
+   break;
+   case IOC_IN:
+   printf("IN   ");
+   break;
+   case IOC_INOUT:
+   printf("INOUT");
+   break;
+   default:
+   printf("%01lx ???", (cmd & IOC_DIRMASK) >> 29);
+   break;
+   }
+   printf(" ");
+   group = IOCGROUP(cmd);
+   if (isprint(group))
+   printf(" '%c' ", group);
+   else
+   printf(" 0x%02x", group);
+   printf(" %3lu %4lu", cmd & 0xff, IOCPARM_LEN(cmd));
+   name = sysdecode_ioctlname(cmd);
+   if (name != NULL)
+   printf(" %s", name);
+   printf("\n");
+   }
+   return (0);
+}
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"