decioctl.c revision 301931
1156283Srwatson/*- 2156283Srwatson * Copyright (c) 2005-2006,2016 John H. Baldwin <jhb@FreeBSD.org> 3156283Srwatson * All rights reserved. 4156283Srwatson * 5156283Srwatson * Redistribution and use in source and binary forms, with or without 6156283Srwatson * modification, are permitted provided that the following conditions 7156283Srwatson * are met: 8156283Srwatson * 1. Redistributions of source code must retain the above copyright 9156283Srwatson * notice, this list of conditions and the following disclaimer. 10156283Srwatson * 2. Redistributions in binary form must reproduce the above copyright 11156283Srwatson * notice, this list of conditions and the following disclaimer in the 12156283Srwatson * documentation and/or other materials provided with the distribution. 13156283Srwatson * 14156283Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15161630Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16161630Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17161630Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18156283Srwatson * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19156283Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20156283Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21156283Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22156283Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23156283Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24156283Srwatson * SUCH DAMAGE. 25156283Srwatson */ 26156283Srwatson 27156283Srwatson#include <sys/cdefs.h> 28156283Srwatson__FBSDID("$FreeBSD: head/tools/tools/decioctl/decioctl.c 301931 2016-06-15 21:01:53Z jhb $"); 29156283Srwatson 30156283Srwatson#include <sys/ioccom.h> 31156283Srwatson#include <ctype.h> 32156283Srwatson#include <errno.h> 33156283Srwatson#include <limits.h> 34156283Srwatson#include <stdio.h> 35156283Srwatson#include <stdlib.h> 36156283Srwatson#include <sysdecode.h> 37156283Srwatson 38156283Srwatsonstatic void 39156283Srwatsonusage(char **av) 40156283Srwatson{ 41156283Srwatson fprintf(stderr, "%s: <ioctl> [ ... ]\n", av[0]); 42156283Srwatson exit(1); 43156283Srwatson} 44156283Srwatson 45156283Srwatsonint 46156283Srwatsonmain(int ac, char **av) 47156283Srwatson{ 48156283Srwatson unsigned long cmd; 49156283Srwatson const char *name; 50156283Srwatson char *cp; 51156283Srwatson int group, i; 52156283Srwatson 53156283Srwatson if (ac < 2) 54156283Srwatson usage(av); 55156283Srwatson printf(" command : dir group num len name\n"); 56156283Srwatson for (i = 1; i < ac; i++) { 57156283Srwatson errno = 0; 58156283Srwatson cmd = strtoul(av[i], &cp, 0); 59156283Srwatson if (*cp != '\0' || errno != 0) { 60156283Srwatson fprintf(stderr, "Invalid integer: %s\n", av[i]); 61156283Srwatson usage(av); 62156283Srwatson } 63156283Srwatson printf("0x%08lx: ", cmd); 64156283Srwatson switch (cmd & IOC_DIRMASK) { 65156283Srwatson case IOC_VOID: 66156283Srwatson printf("VOID "); 67156283Srwatson break; 68156283Srwatson case IOC_OUT: 69156283Srwatson printf("OUT "); 70156283Srwatson break; 71156283Srwatson case IOC_IN: 72156283Srwatson printf("IN "); 73156283Srwatson break; 74156283Srwatson case IOC_INOUT: 75156283Srwatson printf("INOUT"); 76156283Srwatson break; 77156283Srwatson default: 78156283Srwatson printf("%01lx ???", (cmd & IOC_DIRMASK) >> 29); 79156283Srwatson break; 80156283Srwatson } 81156283Srwatson printf(" "); 82156283Srwatson group = IOCGROUP(cmd); 83156283Srwatson if (isprint(group)) 84156283Srwatson printf(" '%c' ", group); 85156283Srwatson else 86156283Srwatson printf(" 0x%02x", group); 87156283Srwatson printf(" %3lu %4lu", cmd & 0xff, IOCPARM_LEN(cmd)); 88156283Srwatson name = sysdecode_ioctlname(cmd); 89156283Srwatson if (name != NULL) 90156283Srwatson printf(" %s", name); 91156283Srwatson printf("\n"); 92156283Srwatson } 93156283Srwatson return (0); 94156283Srwatson} 95156283Srwatson