blob: cfd5a245f21da6d5477c432202b7f675e9e1bf4b [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{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +000037 unsigned long code1 = (unsigned 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 *
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +000043ioctl_lookup(unsigned 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{
Dmitry V. Levin3ed5d022014-09-10 13:46:04 +000063 unsigned long code;
Roland McGrath2843a4e2003-11-14 02:54:03 +000064
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:
Mike Frysinger5b886082014-11-21 16:13:16 -050088 case 'X':
Dmitry V. Levin4ef6db42011-01-15 20:15:31 +000089 return block_ioctl(tcp, code, arg);
Dmitry V. Levinfdb896e2014-02-25 23:04:55 +000090#ifdef HAVE_SCSI_SG_H
Dmitry V. Levinb011af52007-06-30 11:37:09 +000091 case 0x22:
92 return scsi_ioctl(tcp, code, arg);
Dmitry V. Levinfdb896e2014-02-25 23:04:55 +000093#endif
Mike Frysingerebee04c2012-04-17 22:19:31 -040094 case 'L':
95 return loop_ioctl(tcp, code, arg);
Mike Frysinger0cbed352012-04-04 22:22:01 -040096 case 'M':
97 return mtd_ioctl(tcp, code, arg);
Mike Frysingerd648f292013-05-01 23:35:30 -040098 case 'o':
99 case 'O':
100 return ubi_ioctl(tcp, code, arg);
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100101 case 'V':
102 return v4l2_ioctl(tcp, code, arg);
Stefan Sørensenb88a6f82014-01-31 12:01:01 +0100103 case '=':
104 return ptp_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000105 default:
106 break;
107 }
108 return 0;
109}
110
111/*
112 * Registry of ioctl characters, culled from
113 * @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86
114 *
115 * char file where defined notes
116 * ---- ------------------ -----
117 * F sun/fbio.h
118 * G sun/gpio.h
119 * H vaxif/if_hy.h
120 * M sundev/mcpcmd.h *overlap*
121 * M sys/modem.h *overlap*
122 * S sys/stropts.h
123 * T sys/termio.h -no overlap-
124 * T sys/termios.h -no overlap-
125 * V sundev/mdreg.h
126 * a vaxuba/adreg.h
127 * d sun/dkio.h -no overlap with sys/des.h-
128 * d sys/des.h (possible overlap)
129 * d vax/dkio.h (possible overlap)
130 * d vaxuba/rxreg.h (possible overlap)
131 * f sys/filio.h
132 * g sunwindow/win_ioctl.h -no overlap-
133 * g sunwindowdev/winioctl.c !no manifest constant! -no overlap-
134 * h sundev/hrc_common.h
135 * i sys/sockio.h *overlap*
136 * i vaxuba/ikreg.h *overlap*
137 * k sundev/kbio.h
138 * m sundev/msio.h (possible overlap)
139 * m sundev/msreg.h (possible overlap)
140 * m sys/mtio.h (possible overlap)
141 * n sun/ndio.h
142 * p net/nit_buf.h (possible overlap)
143 * p net/nit_if.h (possible overlap)
144 * p net/nit_pf.h (possible overlap)
145 * p sundev/fpareg.h (possible overlap)
146 * p sys/sockio.h (possible overlap)
147 * p vaxuba/psreg.h (possible overlap)
148 * q sun/sqz.h
149 * r sys/sockio.h
150 * s sys/sockio.h
151 * t sys/ttold.h (possible overlap)
152 * t sys/ttycom.h (possible overlap)
153 * v sundev/vuid_event.h *overlap*
154 * v sys/vcmd.h *overlap*
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100155 * V linux/videodev2.h
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156 *
157 * End of Registry
158 */