]> granicus.if.org Git - strace/blob - ioctl.c
ioctl: print unrecognized ioctl codes in _IOC(dir,type,nr,size) format
[strace] / ioctl.c
1 /*
2  * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5  * Copyright (c) 1996-2001 Wichert Akkerman <wichert@cistron.nl>
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of the author may not be used to endorse or promote products
17  *    derived from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "defs.h"
32 #include <asm/ioctl.h>
33 #include "xlat/ioctl_dirs.h"
34
35 static int
36 compare(const void *a, const void *b)
37 {
38         const unsigned int code1 = (const unsigned long) a;
39         const unsigned int code2 = ((struct_ioctlent *) b)->code;
40         return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
41 }
42
43 const struct_ioctlent *
44 ioctl_lookup(unsigned int code)
45 {
46         struct_ioctlent *iop;
47
48         code &= (_IOC_NRMASK<<_IOC_NRSHIFT) | (_IOC_TYPEMASK<<_IOC_TYPESHIFT);
49         iop = bsearch((const void *) (const unsigned long) code, ioctlent,
50                         nioctlents, sizeof(ioctlent[0]), compare);
51         while (iop > ioctlent) {
52                 iop--;
53                 if (iop->code != code) {
54                         iop++;
55                         break;
56                 }
57         }
58         return iop;
59 }
60
61 const struct_ioctlent *
62 ioctl_next_match(const struct_ioctlent *iop)
63 {
64         const unsigned int code = iop->code;
65         iop++;
66         if (iop < ioctlent + nioctlents && iop->code == code)
67                 return iop;
68         return NULL;
69 }
70
71 void
72 ioctl_print_code(const unsigned int code)
73 {
74         tprints("_IOC(");
75         printflags(ioctl_dirs, _IOC_DIR(code), "_IOC_???");
76         tprintf(", 0x%02x, 0x%02x, 0x%02x)",
77                 _IOC_TYPE(code), _IOC_NR(code), _IOC_SIZE(code));
78 }
79
80 int
81 ioctl_decode(struct tcb *tcp, unsigned int code, long arg)
82 {
83         switch (_IOC_TYPE(code)) {
84 #if defined(ALPHA) || defined(POWERPC)
85         case 'f': case 't': case 'T':
86 #else /* !ALPHA */
87         case 0x54:
88 #endif /* !ALPHA */
89                 return term_ioctl(tcp, code, arg);
90         case 0x89:
91                 return sock_ioctl(tcp, code, arg);
92         case 'p':
93                 return rtc_ioctl(tcp, code, arg);
94         case 0x03:
95         case 0x12:
96         case 'X':
97                 return block_ioctl(tcp, code, arg);
98 #ifdef HAVE_SCSI_SG_H
99         case 0x22:
100                 return scsi_ioctl(tcp, code, arg);
101 #endif
102         case 'L':
103                 return loop_ioctl(tcp, code, arg);
104         case 'M':
105                 return mtd_ioctl(tcp, code, arg);
106         case 'o':
107         case 'O':
108                 return ubi_ioctl(tcp, code, arg);
109         case 'V':
110                 return v4l2_ioctl(tcp, code, arg);
111         case '=':
112                 return ptp_ioctl(tcp, code, arg);
113         default:
114                 break;
115         }
116         return 0;
117 }
118
119 /*
120  * Registry of ioctl characters, culled from
121  *      @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86
122  *
123  * char file where defined              notes
124  * ---- ------------------              -----
125  *   F  sun/fbio.h
126  *   G  sun/gpio.h
127  *   H  vaxif/if_hy.h
128  *   M  sundev/mcpcmd.h                 *overlap*
129  *   M  sys/modem.h                     *overlap*
130  *   S  sys/stropts.h
131  *   T  sys/termio.h                    -no overlap-
132  *   T  sys/termios.h                   -no overlap-
133  *   V  sundev/mdreg.h
134  *   a  vaxuba/adreg.h
135  *   d  sun/dkio.h                      -no overlap with sys/des.h-
136  *   d  sys/des.h                       (possible overlap)
137  *   d  vax/dkio.h                      (possible overlap)
138  *   d  vaxuba/rxreg.h                  (possible overlap)
139  *   f  sys/filio.h
140  *   g  sunwindow/win_ioctl.h           -no overlap-
141  *   g  sunwindowdev/winioctl.c         !no manifest constant! -no overlap-
142  *   h  sundev/hrc_common.h
143  *   i  sys/sockio.h                    *overlap*
144  *   i  vaxuba/ikreg.h                  *overlap*
145  *   k  sundev/kbio.h
146  *   m  sundev/msio.h                   (possible overlap)
147  *   m  sundev/msreg.h                  (possible overlap)
148  *   m  sys/mtio.h                      (possible overlap)
149  *   n  sun/ndio.h
150  *   p  net/nit_buf.h                   (possible overlap)
151  *   p  net/nit_if.h                    (possible overlap)
152  *   p  net/nit_pf.h                    (possible overlap)
153  *   p  sundev/fpareg.h                 (possible overlap)
154  *   p  sys/sockio.h                    (possible overlap)
155  *   p  vaxuba/psreg.h                  (possible overlap)
156  *   q  sun/sqz.h
157  *   r  sys/sockio.h
158  *   s  sys/sockio.h
159  *   t  sys/ttold.h                     (possible overlap)
160  *   t  sys/ttycom.h                    (possible overlap)
161  *   v  sundev/vuid_event.h             *overlap*
162  *   v  sys/vcmd.h                      *overlap*
163  *   V  linux/videodev2.h
164  *
165  * End of Registry
166  */