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. |
| 29 | * |
| 30 | * $Id$ |
| 31 | */ |
| 32 | |
| 33 | #include "defs.h" |
| 34 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 35 | const struct ioctlent ioctlent0[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 36 | /* |
| 37 | * `ioctlent.h' may be generated from `ioctlent.raw' by the auxiliary |
| 38 | * program `ioctlsort', such that the list is sorted by the `code' field. |
| 39 | * This has the side-effect of resolving the _IO.. macros into |
| 40 | * plain integers, eliminating the need to include here everything |
| 41 | * in "/usr/include" . |
| 42 | */ |
| 43 | #include "ioctlent.h" |
| 44 | }; |
| 45 | |
Wichert Akkerman | a966785 | 2001-03-17 17:26:34 +0000 | [diff] [blame] | 46 | #ifdef LINUX |
| 47 | #include <asm/ioctl.h> |
| 48 | #endif |
| 49 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 50 | const int nioctlents0 = sizeof ioctlent0 / sizeof ioctlent0[0]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 51 | |
| 52 | #if SUPPORTED_PERSONALITIES >= 2 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 53 | const struct ioctlent ioctlent1[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 54 | #include "ioctlent1.h" |
| 55 | }; |
| 56 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 57 | const int nioctlents1 = sizeof ioctlent1 / sizeof ioctlent1[0]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 58 | #endif /* SUPPORTED_PERSONALITIES >= 2 */ |
| 59 | |
| 60 | #if SUPPORTED_PERSONALITIES >= 3 |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 61 | const struct ioctlent ioctlent2[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 62 | #include "ioctlent2.h" |
| 63 | }; |
| 64 | |
Roland McGrath | ddce11b | 2005-02-02 20:32:13 +0000 | [diff] [blame] | 65 | const int nioctlents2 = sizeof ioctlent2 / sizeof ioctlent2[0]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 66 | #endif /* SUPPORTED_PERSONALITIES >= 3 */ |
| 67 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 68 | const struct ioctlent *ioctlent; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 69 | int nioctlents; |
| 70 | |
| 71 | static int |
| 72 | compare(a, b) |
| 73 | const void *a; |
| 74 | const void *b; |
| 75 | { |
| 76 | unsigned long code1 = ((struct ioctlent *) a)->code; |
| 77 | unsigned long code2 = ((struct ioctlent *) b)->code; |
| 78 | return (code1 > code2) ? 1 : (code1 < code2) ? -1 : 0; |
| 79 | } |
| 80 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 81 | const struct ioctlent * |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 82 | ioctl_lookup(code) |
| 83 | long code; |
| 84 | { |
| 85 | struct ioctlent *iop, ioent; |
| 86 | |
| 87 | ioent.code = code; |
Wichert Akkerman | a966785 | 2001-03-17 17:26:34 +0000 | [diff] [blame] | 88 | #ifdef LINUX |
Wichert Akkerman | 1c595a4 | 2001-08-03 21:51:35 +0000 | [diff] [blame] | 89 | ioent.code &= (_IOC_NRMASK<<_IOC_NRSHIFT) | (_IOC_TYPEMASK<<_IOC_TYPESHIFT); |
Wichert Akkerman | a966785 | 2001-03-17 17:26:34 +0000 | [diff] [blame] | 90 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 91 | iop = (struct ioctlent *) bsearch((char *) &ioent, (char *) ioctlent, |
| 92 | nioctlents, sizeof(struct ioctlent), compare); |
Roland McGrath | 2843a4e | 2003-11-14 02:54:03 +0000 | [diff] [blame] | 93 | while (iop > ioctlent) |
| 94 | if ((--iop)->code != ioent.code) { |
| 95 | iop++; |
| 96 | break; |
| 97 | } |
| 98 | return iop; |
| 99 | } |
| 100 | |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 101 | const struct ioctlent * |
Roland McGrath | 2843a4e | 2003-11-14 02:54:03 +0000 | [diff] [blame] | 102 | ioctl_next_match(iop) |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 103 | const struct ioctlent *iop; |
Roland McGrath | 2843a4e | 2003-11-14 02:54:03 +0000 | [diff] [blame] | 104 | { |
| 105 | long code; |
| 106 | |
| 107 | code = (iop++)->code; |
| 108 | if (iop < ioctlent + nioctlents && iop->code == code) |
| 109 | return iop; |
| 110 | return NULL; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | int |
| 114 | ioctl_decode(tcp, code, arg) |
| 115 | struct tcb *tcp; |
| 116 | long code, arg; |
| 117 | { |
| 118 | switch ((code >> 8) & 0xff) { |
| 119 | #ifdef LINUX |
Roland McGrath | bb3af52 | 2003-01-14 07:53:34 +0000 | [diff] [blame] | 120 | #if defined(ALPHA) || defined(POWERPC) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 121 | case 'f': case 't': case 'T': |
| 122 | #else /* !ALPHA */ |
| 123 | case 0x54: |
| 124 | #endif /* !ALPHA */ |
| 125 | #else /* !LINUX */ |
| 126 | case 'f': case 't': case 'T': |
| 127 | #endif /* !LINUX */ |
| 128 | return term_ioctl(tcp, code, arg); |
| 129 | #ifdef LINUX |
| 130 | case 0x89: |
| 131 | #else /* !LINUX */ |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 132 | case 'r': case 's': case 'i': |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 133 | #ifndef FREEBSD |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 134 | case 'p': |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 135 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 136 | #endif /* !LINUX */ |
| 137 | return sock_ioctl(tcp, code, arg); |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 138 | #ifdef USE_PROCFS |
Wichert Akkerman | ea78f0f | 1999-11-29 15:34:02 +0000 | [diff] [blame] | 139 | #ifndef HAVE_MP_PROCFS |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 140 | #ifndef FREEBSD |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 141 | case 'q': |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 142 | #else |
| 143 | case 'p': |
Roland McGrath | ee36ce1 | 2004-09-04 03:53:10 +0000 | [diff] [blame] | 144 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 145 | return proc_ioctl(tcp, code, arg); |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 146 | #endif |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 147 | #endif /* USE_PROCFS */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 148 | #ifdef HAVE_SYS_STREAM_H |
| 149 | case 'S': |
| 150 | return stream_ioctl(tcp, code, arg); |
| 151 | #endif /* HAVE_SYS_STREAM_H */ |
Roland McGrath | d83c50b | 2004-10-06 22:27:43 +0000 | [diff] [blame] | 152 | #ifdef LINUX |
| 153 | case 'p': |
| 154 | return rtc_ioctl(tcp, code, arg); |
Dmitry V. Levin | b011af5 | 2007-06-30 11:37:09 +0000 | [diff] [blame] | 155 | case 0x22: |
| 156 | return scsi_ioctl(tcp, code, arg); |
Roland McGrath | d83c50b | 2004-10-06 22:27:43 +0000 | [diff] [blame] | 157 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 158 | default: |
| 159 | break; |
| 160 | } |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | /* |
| 165 | * Registry of ioctl characters, culled from |
| 166 | * @(#)ioccom.h 1.7 89/06/16 SMI; from UCB ioctl.h 7.1 6/4/86 |
| 167 | * |
| 168 | * char file where defined notes |
| 169 | * ---- ------------------ ----- |
| 170 | * F sun/fbio.h |
| 171 | * G sun/gpio.h |
| 172 | * H vaxif/if_hy.h |
| 173 | * M sundev/mcpcmd.h *overlap* |
| 174 | * M sys/modem.h *overlap* |
| 175 | * S sys/stropts.h |
| 176 | * T sys/termio.h -no overlap- |
| 177 | * T sys/termios.h -no overlap- |
| 178 | * V sundev/mdreg.h |
| 179 | * a vaxuba/adreg.h |
| 180 | * d sun/dkio.h -no overlap with sys/des.h- |
| 181 | * d sys/des.h (possible overlap) |
| 182 | * d vax/dkio.h (possible overlap) |
| 183 | * d vaxuba/rxreg.h (possible overlap) |
| 184 | * f sys/filio.h |
| 185 | * g sunwindow/win_ioctl.h -no overlap- |
| 186 | * g sunwindowdev/winioctl.c !no manifest constant! -no overlap- |
| 187 | * h sundev/hrc_common.h |
| 188 | * i sys/sockio.h *overlap* |
| 189 | * i vaxuba/ikreg.h *overlap* |
| 190 | * k sundev/kbio.h |
| 191 | * m sundev/msio.h (possible overlap) |
| 192 | * m sundev/msreg.h (possible overlap) |
| 193 | * m sys/mtio.h (possible overlap) |
| 194 | * n sun/ndio.h |
| 195 | * p net/nit_buf.h (possible overlap) |
| 196 | * p net/nit_if.h (possible overlap) |
| 197 | * p net/nit_pf.h (possible overlap) |
| 198 | * p sundev/fpareg.h (possible overlap) |
| 199 | * p sys/sockio.h (possible overlap) |
| 200 | * p vaxuba/psreg.h (possible overlap) |
| 201 | * q sun/sqz.h |
| 202 | * r sys/sockio.h |
| 203 | * s sys/sockio.h |
| 204 | * t sys/ttold.h (possible overlap) |
| 205 | * t sys/ttycom.h (possible overlap) |
| 206 | * v sundev/vuid_event.h *overlap* |
| 207 | * v sys/vcmd.h *overlap* |
| 208 | * |
| 209 | * End of Registry |
| 210 | */ |