blob: d7927c65819763b3ab68ebc431f2cc6ac9a4d25d [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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>
Wichert Akkermanc6c1ea52001-08-03 21:52:13 +00005 * Copyright (c) 1996-2001 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * 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
Roland McGrathee36ce12004-09-04 03:53:10 +000035const struct ioctlent ioctlent0[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036/*
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
Wichert Akkermana9667852001-03-17 17:26:34 +000046#ifdef LINUX
47#include <asm/ioctl.h>
48#endif
49
Dmitry V. Levinfcda7a52011-06-13 21:58:43 +000050const int nioctlents0 = ARRAY_SIZE(ioctlent0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051
52#if SUPPORTED_PERSONALITIES >= 2
Roland McGrathee36ce12004-09-04 03:53:10 +000053const struct ioctlent ioctlent1[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054#include "ioctlent1.h"
55};
56
Dmitry V. Levinfcda7a52011-06-13 21:58:43 +000057const int nioctlents1 = ARRAY_SIZE(ioctlent1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058#endif /* SUPPORTED_PERSONALITIES >= 2 */
59
60#if SUPPORTED_PERSONALITIES >= 3
Roland McGrathee36ce12004-09-04 03:53:10 +000061const struct ioctlent ioctlent2[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000062#include "ioctlent2.h"
63};
64
Dmitry V. Levinfcda7a52011-06-13 21:58:43 +000065const int nioctlents2 = ARRAY_SIZE(ioctlent2);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000066#endif /* SUPPORTED_PERSONALITIES >= 3 */
67
Roland McGrathee36ce12004-09-04 03:53:10 +000068const struct ioctlent *ioctlent;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000069int nioctlents;
70
71static int
Denys Vlasenko12014262011-05-30 14:00:14 +020072compare(const void *a, const void *b)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000073{
74 unsigned long code1 = ((struct ioctlent *) a)->code;
75 unsigned long code2 = ((struct ioctlent *) b)->code;
76 return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
77}
78
Roland McGrathee36ce12004-09-04 03:53:10 +000079const struct ioctlent *
Denys Vlasenko12014262011-05-30 14:00:14 +020080ioctl_lookup(long code)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000081{
82 struct ioctlent *iop, ioent;
83
84 ioent.code = code;
Wichert Akkermana9667852001-03-17 17:26:34 +000085#ifdef LINUX
Wichert Akkerman1c595a42001-08-03 21:51:35 +000086 ioent.code &= (_IOC_NRMASK<<_IOC_NRSHIFT) | (_IOC_TYPEMASK<<_IOC_TYPESHIFT);
Wichert Akkermana9667852001-03-17 17:26:34 +000087#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000088 iop = (struct ioctlent *) bsearch((char *) &ioent, (char *) ioctlent,
89 nioctlents, sizeof(struct ioctlent), compare);
Roland McGrath2843a4e2003-11-14 02:54:03 +000090 while (iop > ioctlent)
91 if ((--iop)->code != ioent.code) {
92 iop++;
93 break;
94 }
95 return iop;
96}
97
Roland McGrathee36ce12004-09-04 03:53:10 +000098const struct ioctlent *
Roland McGrath2843a4e2003-11-14 02:54:03 +000099ioctl_next_match(iop)
Roland McGrathee36ce12004-09-04 03:53:10 +0000100const struct ioctlent *iop;
Roland McGrath2843a4e2003-11-14 02:54:03 +0000101{
102 long code;
103
104 code = (iop++)->code;
105 if (iop < ioctlent + nioctlents && iop->code == code)
106 return iop;
107 return NULL;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000108}
109
110int
Denys Vlasenko12014262011-05-30 14:00:14 +0200111ioctl_decode(struct tcb *tcp, long code, long arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000112{
113 switch ((code >> 8) & 0xff) {
114#ifdef LINUX
Roland McGrathbb3af522003-01-14 07:53:34 +0000115#if defined(ALPHA) || defined(POWERPC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000116 case 'f': case 't': case 'T':
117#else /* !ALPHA */
118 case 0x54:
119#endif /* !ALPHA */
120#else /* !LINUX */
121 case 'f': case 't': case 'T':
122#endif /* !LINUX */
123 return term_ioctl(tcp, code, arg);
124#ifdef LINUX
125 case 0x89:
126#else /* !LINUX */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000127 case 'r': case 's': case 'i':
Roland McGrathee36ce12004-09-04 03:53:10 +0000128#ifndef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000129 case 'p':
Roland McGrathee36ce12004-09-04 03:53:10 +0000130#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000131#endif /* !LINUX */
132 return sock_ioctl(tcp, code, arg);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000133#ifdef USE_PROCFS
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000134#ifndef HAVE_MP_PROCFS
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000135#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000136 case 'q':
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000137#else
138 case 'p':
Roland McGrathee36ce12004-09-04 03:53:10 +0000139#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000140 return proc_ioctl(tcp, code, arg);
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000141#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000142#endif /* USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000143#ifdef HAVE_SYS_STREAM_H
144 case 'S':
145 return stream_ioctl(tcp, code, arg);
146#endif /* HAVE_SYS_STREAM_H */
Roland McGrathd83c50b2004-10-06 22:27:43 +0000147#ifdef LINUX
148 case 'p':
149 return rtc_ioctl(tcp, code, arg);
Dmitry V. Levin4ef6db42011-01-15 20:15:31 +0000150 case 0x03:
151 case 0x12:
152 return block_ioctl(tcp, code, arg);
Dmitry V. Levinb011af52007-06-30 11:37:09 +0000153 case 0x22:
154 return scsi_ioctl(tcp, code, arg);
Roland McGrathd83c50b2004-10-06 22:27:43 +0000155#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156 default:
157 break;
158 }
159 return 0;
160}
161
162/*
163 * Registry of ioctl characters, culled from
164 * @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86
165 *
166 * char file where defined notes
167 * ---- ------------------ -----
168 * F sun/fbio.h
169 * G sun/gpio.h
170 * H vaxif/if_hy.h
171 * M sundev/mcpcmd.h *overlap*
172 * M sys/modem.h *overlap*
173 * S sys/stropts.h
174 * T sys/termio.h -no overlap-
175 * T sys/termios.h -no overlap-
176 * V sundev/mdreg.h
177 * a vaxuba/adreg.h
178 * d sun/dkio.h -no overlap with sys/des.h-
179 * d sys/des.h (possible overlap)
180 * d vax/dkio.h (possible overlap)
181 * d vaxuba/rxreg.h (possible overlap)
182 * f sys/filio.h
183 * g sunwindow/win_ioctl.h -no overlap-
184 * g sunwindowdev/winioctl.c !no manifest constant! -no overlap-
185 * h sundev/hrc_common.h
186 * i sys/sockio.h *overlap*
187 * i vaxuba/ikreg.h *overlap*
188 * k sundev/kbio.h
189 * m sundev/msio.h (possible overlap)
190 * m sundev/msreg.h (possible overlap)
191 * m sys/mtio.h (possible overlap)
192 * n sun/ndio.h
193 * p net/nit_buf.h (possible overlap)
194 * p net/nit_if.h (possible overlap)
195 * p net/nit_pf.h (possible overlap)
196 * p sundev/fpareg.h (possible overlap)
197 * p sys/sockio.h (possible overlap)
198 * p vaxuba/psreg.h (possible overlap)
199 * q sun/sqz.h
200 * r sys/sockio.h
201 * s sys/sockio.h
202 * t sys/ttold.h (possible overlap)
203 * t sys/ttycom.h (possible overlap)
204 * v sundev/vuid_event.h *overlap*
205 * v sys/vcmd.h *overlap*
206 *
207 * End of Registry
208 */