]> granicus.if.org Git - strace/blob - ioctl.c
0ea6b2e5239ae9b2a12f136c31882e76e38a2f31
[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  *      $Id$
31  */
32
33 #include "defs.h"
34
35 #include <asm/ioctl.h>
36
37 static int
38 compare(const void *a, const void *b)
39 {
40         unsigned long code1 = ((struct ioctlent *) a)->code;
41         unsigned long code2 = ((struct ioctlent *) b)->code;
42         return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
43 }
44
45 const struct ioctlent *
46 ioctl_lookup(long code)
47 {
48         struct ioctlent *iop, ioent;
49
50         ioent.code = code;
51         ioent.code &= (_IOC_NRMASK<<_IOC_NRSHIFT) | (_IOC_TYPEMASK<<_IOC_TYPESHIFT);
52         iop = (struct ioctlent *) bsearch((char *) &ioent, (char *) ioctlent,
53                         nioctlents, sizeof(struct ioctlent), compare);
54         while (iop > ioctlent)
55                 if ((--iop)->code != ioent.code) {
56                         iop++;
57                         break;
58                 }
59         return iop;
60 }
61
62 const struct ioctlent *
63 ioctl_next_match(const struct ioctlent *iop)
64 {
65         long code;
66
67         code = (iop++)->code;
68         if (iop < ioctlent + nioctlents && iop->code == code)
69                 return iop;
70         return NULL;
71 }
72
73 int
74 ioctl_decode(struct tcb *tcp, long code, long arg)
75 {
76         switch ((code >> 8) & 0xff) {
77 #if defined(ALPHA) || defined(POWERPC)
78         case 'f': case 't': case 'T':
79 #else /* !ALPHA */
80         case 0x54:
81 #endif /* !ALPHA */
82                 return term_ioctl(tcp, code, arg);
83         case 0x89:
84                 return sock_ioctl(tcp, code, arg);
85         case 'p':
86                 return rtc_ioctl(tcp, code, arg);
87         case 0x03:
88         case 0x12:
89                 return block_ioctl(tcp, code, arg);
90         case 0x22:
91                 return scsi_ioctl(tcp, code, arg);
92         default:
93                 break;
94         }
95         return 0;
96 }
97
98 /*
99  * Registry of ioctl characters, culled from
100  *      @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86
101  *
102  * char file where defined              notes
103  * ---- ------------------              -----
104  *   F  sun/fbio.h
105  *   G  sun/gpio.h
106  *   H  vaxif/if_hy.h
107  *   M  sundev/mcpcmd.h                 *overlap*
108  *   M  sys/modem.h                     *overlap*
109  *   S  sys/stropts.h
110  *   T  sys/termio.h                    -no overlap-
111  *   T  sys/termios.h                   -no overlap-
112  *   V  sundev/mdreg.h
113  *   a  vaxuba/adreg.h
114  *   d  sun/dkio.h                      -no overlap with sys/des.h-
115  *   d  sys/des.h                       (possible overlap)
116  *   d  vax/dkio.h                      (possible overlap)
117  *   d  vaxuba/rxreg.h                  (possible overlap)
118  *   f  sys/filio.h
119  *   g  sunwindow/win_ioctl.h           -no overlap-
120  *   g  sunwindowdev/winioctl.c         !no manifest constant! -no overlap-
121  *   h  sundev/hrc_common.h
122  *   i  sys/sockio.h                    *overlap*
123  *   i  vaxuba/ikreg.h                  *overlap*
124  *   k  sundev/kbio.h
125  *   m  sundev/msio.h                   (possible overlap)
126  *   m  sundev/msreg.h                  (possible overlap)
127  *   m  sys/mtio.h                      (possible overlap)
128  *   n  sun/ndio.h
129  *   p  net/nit_buf.h                   (possible overlap)
130  *   p  net/nit_if.h                    (possible overlap)
131  *   p  net/nit_pf.h                    (possible overlap)
132  *   p  sundev/fpareg.h                 (possible overlap)
133  *   p  sys/sockio.h                    (possible overlap)
134  *   p  vaxuba/psreg.h                  (possible overlap)
135  *   q  sun/sqz.h
136  *   r  sys/sockio.h
137  *   s  sys/sockio.h
138  *   t  sys/ttold.h                     (possible overlap)
139  *   t  sys/ttycom.h                    (possible overlap)
140  *   v  sundev/vuid_event.h             *overlap*
141  *   v  sys/vcmd.h                      *overlap*
142  *
143  * End of Registry
144  */