blob: 153e5dfba965b92a97091f36978f3ea65d3be2a5 [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
Wichert Akkermana9667852001-03-17 17:26:34 +000035#ifdef LINUX
36#include <asm/ioctl.h>
37#endif
38
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000039static int
Denys Vlasenko12014262011-05-30 14:00:14 +020040compare(const void *a, const void *b)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041{
42 unsigned long code1 = ((struct ioctlent *) a)->code;
43 unsigned long code2 = ((struct ioctlent *) b)->code;
44 return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
45}
46
Roland McGrathee36ce12004-09-04 03:53:10 +000047const struct ioctlent *
Denys Vlasenko12014262011-05-30 14:00:14 +020048ioctl_lookup(long code)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000049{
50 struct ioctlent *iop, ioent;
51
52 ioent.code = code;
Wichert Akkermana9667852001-03-17 17:26:34 +000053#ifdef LINUX
Wichert Akkerman1c595a42001-08-03 21:51:35 +000054 ioent.code &= (_IOC_NRMASK<<_IOC_NRSHIFT) | (_IOC_TYPEMASK<<_IOC_TYPESHIFT);
Wichert Akkermana9667852001-03-17 17:26:34 +000055#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000056 iop = (struct ioctlent *) bsearch((char *) &ioent, (char *) ioctlent,
57 nioctlents, sizeof(struct ioctlent), compare);
Roland McGrath2843a4e2003-11-14 02:54:03 +000058 while (iop > ioctlent)
59 if ((--iop)->code != ioent.code) {
60 iop++;
61 break;
62 }
63 return iop;
64}
65
Roland McGrathee36ce12004-09-04 03:53:10 +000066const struct ioctlent *
Roland McGrath2843a4e2003-11-14 02:54:03 +000067ioctl_next_match(iop)
Roland McGrathee36ce12004-09-04 03:53:10 +000068const struct ioctlent *iop;
Roland McGrath2843a4e2003-11-14 02:54:03 +000069{
70 long code;
71
72 code = (iop++)->code;
73 if (iop < ioctlent + nioctlents && iop->code == code)
74 return iop;
75 return NULL;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000076}
77
78int
Denys Vlasenko12014262011-05-30 14:00:14 +020079ioctl_decode(struct tcb *tcp, long code, long arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000080{
81 switch ((code >> 8) & 0xff) {
82#ifdef LINUX
Roland McGrathbb3af522003-01-14 07:53:34 +000083#if defined(ALPHA) || defined(POWERPC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084 case 'f': case 't': case 'T':
85#else /* !ALPHA */
86 case 0x54:
87#endif /* !ALPHA */
88#else /* !LINUX */
89 case 'f': case 't': case 'T':
90#endif /* !LINUX */
91 return term_ioctl(tcp, code, arg);
92#ifdef LINUX
93 case 0x89:
94#else /* !LINUX */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000095 case 'r': case 's': case 'i':
Roland McGrathee36ce12004-09-04 03:53:10 +000096#ifndef FREEBSD
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000097 case 'p':
Roland McGrathee36ce12004-09-04 03:53:10 +000098#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000099#endif /* !LINUX */
100 return sock_ioctl(tcp, code, arg);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000101#ifdef USE_PROCFS
Wichert Akkermanea78f0f1999-11-29 15:34:02 +0000102#ifndef HAVE_MP_PROCFS
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000103#ifndef FREEBSD
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000104 case 'q':
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000105#else
106 case 'p':
Roland McGrathee36ce12004-09-04 03:53:10 +0000107#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000108 return proc_ioctl(tcp, code, arg);
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000109#endif
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000110#endif /* USE_PROCFS */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000111#ifdef HAVE_SYS_STREAM_H
112 case 'S':
113 return stream_ioctl(tcp, code, arg);
114#endif /* HAVE_SYS_STREAM_H */
Roland McGrathd83c50b2004-10-06 22:27:43 +0000115#ifdef LINUX
116 case 'p':
117 return rtc_ioctl(tcp, code, arg);
Dmitry V. Levin4ef6db42011-01-15 20:15:31 +0000118 case 0x03:
119 case 0x12:
120 return block_ioctl(tcp, code, arg);
Dmitry V. Levinb011af52007-06-30 11:37:09 +0000121 case 0x22:
122 return scsi_ioctl(tcp, code, arg);
Roland McGrathd83c50b2004-10-06 22:27:43 +0000123#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000124 default:
125 break;
126 }
127 return 0;
128}
129
130/*
131 * Registry of ioctl characters, culled from
132 * @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86
133 *
134 * char file where defined notes
135 * ---- ------------------ -----
136 * F sun/fbio.h
137 * G sun/gpio.h
138 * H vaxif/if_hy.h
139 * M sundev/mcpcmd.h *overlap*
140 * M sys/modem.h *overlap*
141 * S sys/stropts.h
142 * T sys/termio.h -no overlap-
143 * T sys/termios.h -no overlap-
144 * V sundev/mdreg.h
145 * a vaxuba/adreg.h
146 * d sun/dkio.h -no overlap with sys/des.h-
147 * d sys/des.h (possible overlap)
148 * d vax/dkio.h (possible overlap)
149 * d vaxuba/rxreg.h (possible overlap)
150 * f sys/filio.h
151 * g sunwindow/win_ioctl.h -no overlap-
152 * g sunwindowdev/winioctl.c !no manifest constant! -no overlap-
153 * h sundev/hrc_common.h
154 * i sys/sockio.h *overlap*
155 * i vaxuba/ikreg.h *overlap*
156 * k sundev/kbio.h
157 * m sundev/msio.h (possible overlap)
158 * m sundev/msreg.h (possible overlap)
159 * m sys/mtio.h (possible overlap)
160 * n sun/ndio.h
161 * p net/nit_buf.h (possible overlap)
162 * p net/nit_if.h (possible overlap)
163 * p net/nit_pf.h (possible overlap)
164 * p sundev/fpareg.h (possible overlap)
165 * p sys/sockio.h (possible overlap)
166 * p vaxuba/psreg.h (possible overlap)
167 * q sun/sqz.h
168 * r sys/sockio.h
169 * s sys/sockio.h
170 * t sys/ttold.h (possible overlap)
171 * t sys/ttycom.h (possible overlap)
172 * v sundev/vuid_event.h *overlap*
173 * v sys/vcmd.h *overlap*
174 *
175 * End of Registry
176 */