]> granicus.if.org Git - strace/blob - ioctl.c
Merge Harald Böhme's solaris patches
[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-1999 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 struct ioctlent ioctlent0[] = {
36 /*
37  * `ioctlent.h' may be generated from `ioctlent.raw' by the auxiliary
38  * program `ioctlsort', such that the list is sorted by the `code' field.
39  * This has the side-effect of resolving the _IO.. macros into
40  * plain integers, eliminating the need to include here everything
41  * in "/usr/include" .
42  */
43 #include "ioctlent.h"
44 };
45
46 int nioctlents0 = sizeof ioctlent0 / sizeof ioctlent0[0];
47
48 #if SUPPORTED_PERSONALITIES >= 2
49 struct ioctlent ioctlent1[] = {
50 #include "ioctlent1.h"
51 };
52
53 int nioctlents1 = sizeof ioctlent1 / sizeof ioctlent1[0];
54 #endif /* SUPPORTED_PERSONALITIES >= 2 */
55
56 #if SUPPORTED_PERSONALITIES >= 3
57 struct ioctlent ioctlent2[] = {
58 #include "ioctlent2.h"
59 };
60
61 int nioctlents1 = sizeof ioctlent2 / sizeof ioctlent2[0];
62 #endif /* SUPPORTED_PERSONALITIES >= 3 */
63
64 struct ioctlent *ioctlent;
65 int nioctlents;
66
67 static int
68 compare(a, b)
69 const void *a;
70 const void *b;
71 {
72         unsigned long code1 = ((struct ioctlent *) a)->code;
73         unsigned long code2 = ((struct ioctlent *) b)->code;
74         return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
75 }
76
77 char *
78 ioctl_lookup(code)
79 long code;
80 {
81         struct ioctlent *iop, ioent;
82
83         ioent.code = code;
84         iop = (struct ioctlent *) bsearch((char *) &ioent, (char *) ioctlent,
85                         nioctlents, sizeof(struct ioctlent), compare);
86         return iop ? iop->symbol : NULL;
87 }
88
89 int
90 ioctl_decode(tcp, code, arg)
91 struct tcb *tcp;
92 long code, arg;
93 {
94         switch ((code >> 8) & 0xff) {
95 #ifdef LINUX
96 #ifdef ALPHA
97         case 'f': case 't': case 'T':
98 #else /* !ALPHA */
99         case 0x54:
100 #endif /* !ALPHA */
101 #else /* !LINUX */
102         case 'f': case 't': case 'T':
103 #endif /* !LINUX */
104                 return term_ioctl(tcp, code, arg);
105 #ifdef LINUX
106         case 0x89:
107 #else /* !LINUX */
108         case 'r': case 's': case 'i':
109 #ifndef FREEBSD         
110         case 'p':
111 #endif          
112 #endif /* !LINUX */
113                 return sock_ioctl(tcp, code, arg);
114 #ifdef USE_PROCFS
115 #ifndef HAVE_MP_PROCFS
116 #ifndef FREEBSD
117         case 'q':
118 #else
119         case 'p':
120 #endif          
121                 return proc_ioctl(tcp, code, arg);
122 #endif
123 #endif /* USE_PROCFS */
124 #ifdef HAVE_SYS_STREAM_H
125         case 'S':
126                 return stream_ioctl(tcp, code, arg);
127 #endif /* HAVE_SYS_STREAM_H */
128         default:
129                 break;
130         }
131         return 0;
132 }
133
134 /*
135  * Registry of ioctl characters, culled from
136  *      @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86
137  *
138  * char file where defined              notes
139  * ---- ------------------              -----
140  *   F  sun/fbio.h
141  *   G  sun/gpio.h
142  *   H  vaxif/if_hy.h
143  *   M  sundev/mcpcmd.h                 *overlap*
144  *   M  sys/modem.h                     *overlap*
145  *   S  sys/stropts.h
146  *   T  sys/termio.h                    -no overlap-
147  *   T  sys/termios.h                   -no overlap-
148  *   V  sundev/mdreg.h
149  *   a  vaxuba/adreg.h
150  *   d  sun/dkio.h                      -no overlap with sys/des.h-
151  *   d  sys/des.h                       (possible overlap)
152  *   d  vax/dkio.h                      (possible overlap)
153  *   d  vaxuba/rxreg.h                  (possible overlap)
154  *   f  sys/filio.h
155  *   g  sunwindow/win_ioctl.h           -no overlap-
156  *   g  sunwindowdev/winioctl.c         !no manifest constant! -no overlap-
157  *   h  sundev/hrc_common.h
158  *   i  sys/sockio.h                    *overlap*
159  *   i  vaxuba/ikreg.h                  *overlap*
160  *   k  sundev/kbio.h
161  *   m  sundev/msio.h                   (possible overlap)
162  *   m  sundev/msreg.h                  (possible overlap)
163  *   m  sys/mtio.h                      (possible overlap)
164  *   n  sun/ndio.h
165  *   p  net/nit_buf.h                   (possible overlap)
166  *   p  net/nit_if.h                    (possible overlap)
167  *   p  net/nit_pf.h                    (possible overlap)
168  *   p  sundev/fpareg.h                 (possible overlap)
169  *   p  sys/sockio.h                    (possible overlap)
170  *   p  vaxuba/psreg.h                  (possible overlap)
171  *   q  sun/sqz.h
172  *   r  sys/sockio.h
173  *   s  sys/sockio.h
174  *   t  sys/ttold.h                     (possible overlap)
175  *   t  sys/ttycom.h                    (possible overlap)
176  *   v  sundev/vuid_event.h             *overlap*
177  *   v  sys/vcmd.h                      *overlap*
178  *
179  * End of Registry
180  */
181