1301931Sjhb/*- 2301931Sjhb * Copyright (c) 2005-2006,2016 John H. Baldwin <jhb@FreeBSD.org> 3301931Sjhb * 4301931Sjhb * Redistribution and use in source and binary forms, with or without 5301931Sjhb * modification, are permitted provided that the following conditions 6301931Sjhb * are met: 7301931Sjhb * 1. Redistributions of source code must retain the above copyright 8301931Sjhb * notice, this list of conditions and the following disclaimer. 9301931Sjhb * 2. Redistributions in binary form must reproduce the above copyright 10301931Sjhb * notice, this list of conditions and the following disclaimer in the 11301931Sjhb * documentation and/or other materials provided with the distribution. 12301931Sjhb * 13301931Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14301931Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15301931Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16301931Sjhb * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17301931Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18301931Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19301931Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20301931Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21301931Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22301931Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23301931Sjhb * SUCH DAMAGE. 24301931Sjhb */ 25301931Sjhb 26301931Sjhb#include <sys/cdefs.h> 27301931Sjhb__FBSDID("$FreeBSD: stable/11/tools/tools/decioctl/decioctl.c 367457 2020-11-07 18:10:59Z dim $"); 28301931Sjhb 29301931Sjhb#include <sys/ioccom.h> 30301931Sjhb#include <ctype.h> 31301931Sjhb#include <errno.h> 32301931Sjhb#include <limits.h> 33301931Sjhb#include <stdio.h> 34301931Sjhb#include <stdlib.h> 35301931Sjhb#include <sysdecode.h> 36301931Sjhb 37301931Sjhbstatic void 38301931Sjhbusage(char **av) 39301931Sjhb{ 40301931Sjhb fprintf(stderr, "%s: <ioctl> [ ... ]\n", av[0]); 41301931Sjhb exit(1); 42301931Sjhb} 43301931Sjhb 44301931Sjhbint 45301931Sjhbmain(int ac, char **av) 46301931Sjhb{ 47301931Sjhb unsigned long cmd; 48301931Sjhb const char *name; 49301931Sjhb char *cp; 50301931Sjhb int group, i; 51301931Sjhb 52301931Sjhb if (ac < 2) 53301931Sjhb usage(av); 54301931Sjhb printf(" command : dir group num len name\n"); 55301931Sjhb for (i = 1; i < ac; i++) { 56301931Sjhb errno = 0; 57301931Sjhb cmd = strtoul(av[i], &cp, 0); 58301931Sjhb if (*cp != '\0' || errno != 0) { 59301931Sjhb fprintf(stderr, "Invalid integer: %s\n", av[i]); 60301931Sjhb usage(av); 61301931Sjhb } 62301931Sjhb printf("0x%08lx: ", cmd); 63301931Sjhb switch (cmd & IOC_DIRMASK) { 64301931Sjhb case IOC_VOID: 65301931Sjhb printf("VOID "); 66301931Sjhb break; 67301931Sjhb case IOC_OUT: 68301931Sjhb printf("OUT "); 69301931Sjhb break; 70301931Sjhb case IOC_IN: 71301931Sjhb printf("IN "); 72301931Sjhb break; 73301931Sjhb case IOC_INOUT: 74301931Sjhb printf("INOUT"); 75301931Sjhb break; 76301931Sjhb default: 77301931Sjhb printf("%01lx ???", (cmd & IOC_DIRMASK) >> 29); 78301931Sjhb break; 79301931Sjhb } 80301931Sjhb printf(" "); 81301931Sjhb group = IOCGROUP(cmd); 82301931Sjhb if (isprint(group)) 83301931Sjhb printf(" '%c' ", group); 84301931Sjhb else 85301931Sjhb printf(" 0x%02x", group); 86301931Sjhb printf(" %3lu %4lu", cmd & 0xff, IOCPARM_LEN(cmd)); 87301931Sjhb name = sysdecode_ioctlname(cmd); 88301931Sjhb if (name != NULL) 89301931Sjhb printf(" %s", name); 90301931Sjhb printf("\n"); 91301931Sjhb } 92301931Sjhb return (0); 93301931Sjhb} 94