Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 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 Akkerman | c6c1ea5 | 2001-08-03 21:52:13 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-2001 Wichert Akkerman <wichert@cistron.nl> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 6 | * 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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #include "defs.h" |
Wichert Akkerman | a966785 | 2001-03-17 17:26:34 +0000 | [diff] [blame] | 32 | #include <asm/ioctl.h> |
Wichert Akkerman | a966785 | 2001-03-17 17:26:34 +0000 | [diff] [blame] | 33 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 34 | static int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 35 | compare(const void *a, const void *b) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | { |
Denys Vlasenko | 1c2e912 | 2012-03-20 10:57:41 +0100 | [diff] [blame] | 37 | unsigned long code1 = (long) a; |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 38 | unsigned long code2 = ((struct_ioctlent *) b)->code; |
Denys Vlasenko | feb40c4 | 2012-03-20 13:11:51 +0100 | [diff] [blame] | 39 | return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 42 | const struct_ioctlent * |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 43 | ioctl_lookup(long code) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 44 | { |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 45 | struct_ioctlent *iop; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 46 | |
Denys Vlasenko | 1c2e912 | 2012-03-20 10:57:41 +0100 | [diff] [blame] | 47 | 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 McGrath | 2843a4e | 2003-11-14 02:54:03 +0000 | [diff] [blame] | 53 | iop++; |
| 54 | break; |
| 55 | } |
Denys Vlasenko | 1c2e912 | 2012-03-20 10:57:41 +0100 | [diff] [blame] | 56 | } |
Roland McGrath | 2843a4e | 2003-11-14 02:54:03 +0000 | [diff] [blame] | 57 | return iop; |
| 58 | } |
| 59 | |
Denys Vlasenko | a9fe13c | 2013-02-22 13:26:10 +0100 | [diff] [blame] | 60 | const struct_ioctlent * |
| 61 | ioctl_next_match(const struct_ioctlent *iop) |
Roland McGrath | 2843a4e | 2003-11-14 02:54:03 +0000 | [diff] [blame] | 62 | { |
| 63 | long code; |
| 64 | |
Denys Vlasenko | 1c2e912 | 2012-03-20 10:57:41 +0100 | [diff] [blame] | 65 | code = iop->code; |
| 66 | iop++; |
Roland McGrath | 2843a4e | 2003-11-14 02:54:03 +0000 | [diff] [blame] | 67 | if (iop < ioctlent + nioctlents && iop->code == code) |
| 68 | return iop; |
| 69 | return NULL; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | int |
Denys Vlasenko | 1201426 | 2011-05-30 14:00:14 +0200 | [diff] [blame] | 73 | ioctl_decode(struct tcb *tcp, long code, long arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 74 | { |
| 75 | switch ((code >> 8) & 0xff) { |
Roland McGrath | bb3af52 | 2003-01-14 07:53:34 +0000 | [diff] [blame] | 76 | #if defined(ALPHA) || defined(POWERPC) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 77 | case 'f': case 't': case 'T': |
| 78 | #else /* !ALPHA */ |
| 79 | case 0x54: |
| 80 | #endif /* !ALPHA */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 81 | return term_ioctl(tcp, code, arg); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 82 | case 0x89: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 83 | return sock_ioctl(tcp, code, arg); |
Roland McGrath | d83c50b | 2004-10-06 22:27:43 +0000 | [diff] [blame] | 84 | case 'p': |
| 85 | return rtc_ioctl(tcp, code, arg); |
Dmitry V. Levin | 4ef6db4 | 2011-01-15 20:15:31 +0000 | [diff] [blame] | 86 | case 0x03: |
| 87 | case 0x12: |
| 88 | return block_ioctl(tcp, code, arg); |
Dmitry V. Levin | b011af5 | 2007-06-30 11:37:09 +0000 | [diff] [blame] | 89 | case 0x22: |
| 90 | return scsi_ioctl(tcp, code, arg); |
Mike Frysinger | ebee04c | 2012-04-17 22:19:31 -0400 | [diff] [blame] | 91 | case 'L': |
| 92 | return loop_ioctl(tcp, code, arg); |
Mike Frysinger | 0cbed35 | 2012-04-04 22:22:01 -0400 | [diff] [blame] | 93 | case 'M': |
| 94 | return mtd_ioctl(tcp, code, arg); |
Mike Frysinger | d648f29 | 2013-05-01 23:35:30 -0400 | [diff] [blame] | 95 | case 'o': |
| 96 | case 'O': |
| 97 | return ubi_ioctl(tcp, code, arg); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 98 | default: |
| 99 | break; |
| 100 | } |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * Registry of ioctl characters, culled from |
| 106 | * @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86 |
| 107 | * |
| 108 | * char file where defined notes |
| 109 | * ---- ------------------ ----- |
| 110 | * F sun/fbio.h |
| 111 | * G sun/gpio.h |
| 112 | * H vaxif/if_hy.h |
| 113 | * M sundev/mcpcmd.h *overlap* |
| 114 | * M sys/modem.h *overlap* |
| 115 | * S sys/stropts.h |
| 116 | * T sys/termio.h -no overlap- |
| 117 | * T sys/termios.h -no overlap- |
| 118 | * V sundev/mdreg.h |
| 119 | * a vaxuba/adreg.h |
| 120 | * d sun/dkio.h -no overlap with sys/des.h- |
| 121 | * d sys/des.h (possible overlap) |
| 122 | * d vax/dkio.h (possible overlap) |
| 123 | * d vaxuba/rxreg.h (possible overlap) |
| 124 | * f sys/filio.h |
| 125 | * g sunwindow/win_ioctl.h -no overlap- |
| 126 | * g sunwindowdev/winioctl.c !no manifest constant! -no overlap- |
| 127 | * h sundev/hrc_common.h |
| 128 | * i sys/sockio.h *overlap* |
| 129 | * i vaxuba/ikreg.h *overlap* |
| 130 | * k sundev/kbio.h |
| 131 | * m sundev/msio.h (possible overlap) |
| 132 | * m sundev/msreg.h (possible overlap) |
| 133 | * m sys/mtio.h (possible overlap) |
| 134 | * n sun/ndio.h |
| 135 | * p net/nit_buf.h (possible overlap) |
| 136 | * p net/nit_if.h (possible overlap) |
| 137 | * p net/nit_pf.h (possible overlap) |
| 138 | * p sundev/fpareg.h (possible overlap) |
| 139 | * p sys/sockio.h (possible overlap) |
| 140 | * p vaxuba/psreg.h (possible overlap) |
| 141 | * q sun/sqz.h |
| 142 | * r sys/sockio.h |
| 143 | * s sys/sockio.h |
| 144 | * t sys/ttold.h (possible overlap) |
| 145 | * t sys/ttycom.h (possible overlap) |
| 146 | * v sundev/vuid_event.h *overlap* |
| 147 | * v sys/vcmd.h *overlap* |
| 148 | * |
| 149 | * End of Registry |
| 150 | */ |