blob: e9a503da7d5bff0d19548ff29ea966155992eea5 [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkermana9667852001-03-17 17:26:34 +000032#include <asm/ioctl.h>
Wichert Akkermana9667852001-03-17 17:26:34 +000033
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000034static int
Denys Vlasenko12014262011-05-30 14:00:14 +020035compare(const void *a, const void *b)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036{
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010037 unsigned long code1 = (long) a;
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010038 unsigned long code2 = ((struct_ioctlent *) b)->code;
Denys Vlasenkofeb40c42012-03-20 13:11:51 +010039 return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040}
41
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010042const struct_ioctlent *
Denys Vlasenko12014262011-05-30 14:00:14 +020043ioctl_lookup(long code)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000044{
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010045 struct_ioctlent *iop;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010047 code &= (_IOC_NRMASK<<_IOC_NRSHIFT) | (_IOC_TYPEMASK<<_IOC_TYPESHIFT);
48 iop = bsearch((void*)code, ioctlent,
49 nioctlents, sizeof(ioctlent[0]), compare);
50 while (iop > ioctlent) {
51 iop--;
52 if (iop->code != code) {
Roland McGrath2843a4e2003-11-14 02:54:03 +000053 iop++;
54 break;
55 }
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010056 }
Roland McGrath2843a4e2003-11-14 02:54:03 +000057 return iop;
58}
59
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010060const struct_ioctlent *
61ioctl_next_match(const struct_ioctlent *iop)
Roland McGrath2843a4e2003-11-14 02:54:03 +000062{
63 long code;
64
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010065 code = iop->code;
66 iop++;
Roland McGrath2843a4e2003-11-14 02:54:03 +000067 if (iop < ioctlent + nioctlents && iop->code == code)
68 return iop;
69 return NULL;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000070}
71
72int
Denys Vlasenko12014262011-05-30 14:00:14 +020073ioctl_decode(struct tcb *tcp, long code, long arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000074{
75 switch ((code >> 8) & 0xff) {
Roland McGrathbb3af522003-01-14 07:53:34 +000076#if defined(ALPHA) || defined(POWERPC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077 case 'f': case 't': case 'T':
78#else /* !ALPHA */
79 case 0x54:
80#endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000081 return term_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000082 case 0x89:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000083 return sock_ioctl(tcp, code, arg);
Roland McGrathd83c50b2004-10-06 22:27:43 +000084 case 'p':
85 return rtc_ioctl(tcp, code, arg);
Dmitry V. Levin4ef6db42011-01-15 20:15:31 +000086 case 0x03:
87 case 0x12:
88 return block_ioctl(tcp, code, arg);
Dmitry V. Levinb011af52007-06-30 11:37:09 +000089 case 0x22:
90 return scsi_ioctl(tcp, code, arg);
Mike Frysingerebee04c2012-04-17 22:19:31 -040091 case 'L':
92 return loop_ioctl(tcp, code, arg);
Mike Frysinger0cbed352012-04-04 22:22:01 -040093 case 'M':
94 return mtd_ioctl(tcp, code, arg);
Mike Frysingerd648f292013-05-01 23:35:30 -040095 case 'o':
96 case 'O':
97 return ubi_ioctl(tcp, code, arg);
Stefan Sørensenb88a6f82014-01-31 12:01:01 +010098 case '=':
99 return ptp_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000100 default:
101 break;
102 }
103 return 0;
104}
105
106/*
107 * Registry of ioctl characters, culled from
108 * @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86
109 *
110 * char file where defined notes
111 * ---- ------------------ -----
112 * F sun/fbio.h
113 * G sun/gpio.h
114 * H vaxif/if_hy.h
115 * M sundev/mcpcmd.h *overlap*
116 * M sys/modem.h *overlap*
117 * S sys/stropts.h
118 * T sys/termio.h -no overlap-
119 * T sys/termios.h -no overlap-
120 * V sundev/mdreg.h
121 * a vaxuba/adreg.h
122 * d sun/dkio.h -no overlap with sys/des.h-
123 * d sys/des.h (possible overlap)
124 * d vax/dkio.h (possible overlap)
125 * d vaxuba/rxreg.h (possible overlap)
126 * f sys/filio.h
127 * g sunwindow/win_ioctl.h -no overlap-
128 * g sunwindowdev/winioctl.c !no manifest constant! -no overlap-
129 * h sundev/hrc_common.h
130 * i sys/sockio.h *overlap*
131 * i vaxuba/ikreg.h *overlap*
132 * k sundev/kbio.h
133 * m sundev/msio.h (possible overlap)
134 * m sundev/msreg.h (possible overlap)
135 * m sys/mtio.h (possible overlap)
136 * n sun/ndio.h
137 * p net/nit_buf.h (possible overlap)
138 * p net/nit_if.h (possible overlap)
139 * p net/nit_pf.h (possible overlap)
140 * p sundev/fpareg.h (possible overlap)
141 * p sys/sockio.h (possible overlap)
142 * p vaxuba/psreg.h (possible overlap)
143 * q sun/sqz.h
144 * r sys/sockio.h
145 * s sys/sockio.h
146 * t sys/ttold.h (possible overlap)
147 * t sys/ttycom.h (possible overlap)
148 * v sundev/vuid_event.h *overlap*
149 * v sys/vcmd.h *overlap*
150 *
151 * End of Registry
152 */