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