blob: f9d570e8357172075d9e5556bf99a064a6fa7689 [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>
Dmitry V. Levin924996a2015-01-20 00:24:36 +000033#include "xlat/ioctl_dirs.h"
Wichert Akkermana9667852001-03-17 17:26:34 +000034
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000035static int
Denys Vlasenko12014262011-05-30 14:00:14 +020036compare(const void *a, const void *b)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037{
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000038 const unsigned int code1 = (const unsigned long) a;
39 const unsigned int code2 = ((struct_ioctlent *) b)->code;
Denys Vlasenkofeb40c42012-03-20 13:11:51 +010040 return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000041}
42
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010043const struct_ioctlent *
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000044ioctl_lookup(unsigned int code)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045{
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010046 struct_ioctlent *iop;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000047
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010048 code &= (_IOC_NRMASK<<_IOC_NRSHIFT) | (_IOC_TYPEMASK<<_IOC_TYPESHIFT);
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000049 iop = bsearch((const void *) (const unsigned long) code, ioctlent,
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010050 nioctlents, sizeof(ioctlent[0]), compare);
51 while (iop > ioctlent) {
52 iop--;
53 if (iop->code != code) {
Roland McGrath2843a4e2003-11-14 02:54:03 +000054 iop++;
55 break;
56 }
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010057 }
Roland McGrath2843a4e2003-11-14 02:54:03 +000058 return iop;
59}
60
Denys Vlasenkoa9fe13c2013-02-22 13:26:10 +010061const struct_ioctlent *
62ioctl_next_match(const struct_ioctlent *iop)
Roland McGrath2843a4e2003-11-14 02:54:03 +000063{
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000064 const unsigned int code = iop->code;
Denys Vlasenko1c2e9122012-03-20 10:57:41 +010065 iop++;
Roland McGrath2843a4e2003-11-14 02:54:03 +000066 if (iop < ioctlent + nioctlents && iop->code == code)
67 return iop;
68 return NULL;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000069}
70
Dmitry V. Levin924996a2015-01-20 00:24:36 +000071void
72ioctl_print_code(const unsigned int code)
73{
74 tprints("_IOC(");
75 printflags(ioctl_dirs, _IOC_DIR(code), "_IOC_???");
76 tprintf(", 0x%02x, 0x%02x, 0x%02x)",
77 _IOC_TYPE(code), _IOC_NR(code), _IOC_SIZE(code));
78}
79
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000080int
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000081ioctl_decode(struct tcb *tcp, unsigned int code, long arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000082{
Dmitry V. Levinc7afb482015-01-19 18:44:21 +000083 switch (_IOC_TYPE(code)) {
Roland McGrathbb3af522003-01-14 07:53:34 +000084#if defined(ALPHA) || defined(POWERPC)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000085 case 'f': case 't': case 'T':
86#else /* !ALPHA */
87 case 0x54:
88#endif /* !ALPHA */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000089 return term_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000090 case 0x89:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000091 return sock_ioctl(tcp, code, arg);
Roland McGrathd83c50b2004-10-06 22:27:43 +000092 case 'p':
93 return rtc_ioctl(tcp, code, arg);
Dmitry V. Levin4ef6db42011-01-15 20:15:31 +000094 case 0x03:
95 case 0x12:
Mike Frysinger5b886082014-11-21 16:13:16 -050096 case 'X':
Dmitry V. Levin4ef6db42011-01-15 20:15:31 +000097 return block_ioctl(tcp, code, arg);
Dmitry V. Levinfdb896e2014-02-25 23:04:55 +000098#ifdef HAVE_SCSI_SG_H
Dmitry V. Levinb011af52007-06-30 11:37:09 +000099 case 0x22:
100 return scsi_ioctl(tcp, code, arg);
Dmitry V. Levinfdb896e2014-02-25 23:04:55 +0000101#endif
Mike Frysingerebee04c2012-04-17 22:19:31 -0400102 case 'L':
103 return loop_ioctl(tcp, code, arg);
Mike Frysinger0cbed352012-04-04 22:22:01 -0400104 case 'M':
105 return mtd_ioctl(tcp, code, arg);
Mike Frysingerd648f292013-05-01 23:35:30 -0400106 case 'o':
107 case 'O':
108 return ubi_ioctl(tcp, code, arg);
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100109 case 'V':
110 return v4l2_ioctl(tcp, code, arg);
Stefan Sørensenb88a6f82014-01-31 12:01:01 +0100111 case '=':
112 return ptp_ioctl(tcp, code, arg);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000113 default:
114 break;
115 }
116 return 0;
117}
118
119/*
120 * Registry of ioctl characters, culled from
121 * @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86
122 *
123 * char file where defined notes
124 * ---- ------------------ -----
125 * F sun/fbio.h
126 * G sun/gpio.h
127 * H vaxif/if_hy.h
128 * M sundev/mcpcmd.h *overlap*
129 * M sys/modem.h *overlap*
130 * S sys/stropts.h
131 * T sys/termio.h -no overlap-
132 * T sys/termios.h -no overlap-
133 * V sundev/mdreg.h
134 * a vaxuba/adreg.h
135 * d sun/dkio.h -no overlap with sys/des.h-
136 * d sys/des.h (possible overlap)
137 * d vax/dkio.h (possible overlap)
138 * d vaxuba/rxreg.h (possible overlap)
139 * f sys/filio.h
140 * g sunwindow/win_ioctl.h -no overlap-
141 * g sunwindowdev/winioctl.c !no manifest constant! -no overlap-
142 * h sundev/hrc_common.h
143 * i sys/sockio.h *overlap*
144 * i vaxuba/ikreg.h *overlap*
145 * k sundev/kbio.h
146 * m sundev/msio.h (possible overlap)
147 * m sundev/msreg.h (possible overlap)
148 * m sys/mtio.h (possible overlap)
149 * n sun/ndio.h
150 * p net/nit_buf.h (possible overlap)
151 * p net/nit_if.h (possible overlap)
152 * p net/nit_pf.h (possible overlap)
153 * p sundev/fpareg.h (possible overlap)
154 * p sys/sockio.h (possible overlap)
155 * p vaxuba/psreg.h (possible overlap)
156 * q sun/sqz.h
157 * r sys/sockio.h
158 * s sys/sockio.h
159 * t sys/ttold.h (possible overlap)
160 * t sys/ttycom.h (possible overlap)
161 * v sundev/vuid_event.h *overlap*
162 * v sys/vcmd.h *overlap*
Philippe De Muyter0cc96142014-11-03 21:27:40 +0100163 * V linux/videodev2.h
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164 *
165 * End of Registry
166 */