1/* 2 * Copyright (c) 1994-1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 *
| 1/* 2 * Copyright (c) 1994-1995 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer 10 * in this position and unchanged. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 *
|
28 * $FreeBSD: head/sys/compat/linux/linux_ioctl.c 111741 2003-03-02 15:50:23Z des $
| 28 * $FreeBSD: head/sys/compat/linux/linux_ioctl.c 111742 2003-03-02 15:56:49Z des $
|
29 */ 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/sysproto.h> 34#include <sys/cdio.h> 35#include <sys/dvdio.h> 36#include <sys/consio.h> 37#include <sys/ctype.h> 38#include <sys/disklabel.h> 39#include <sys/fcntl.h> 40#include <sys/file.h> 41#include <sys/filedesc.h> 42#include <sys/filio.h> 43#include <sys/kbio.h> 44#include <sys/linker_set.h> 45#include <sys/malloc.h> 46#include <sys/proc.h> 47#include <sys/socket.h> 48#include <sys/sockio.h> 49#include <sys/soundcard.h> 50#include <sys/tty.h> 51#include <sys/uio.h> 52#include <net/if.h> 53#include <net/if_dl.h> 54#include <net/if_types.h> 55 56#include <machine/../linux/linux.h> 57#include <machine/../linux/linux_proto.h> 58 59#include <compat/linux/linux_ioctl.h> 60#include <compat/linux/linux_mib.h> 61#include <compat/linux/linux_util.h> 62 63static linux_ioctl_function_t linux_ioctl_cdrom; 64static linux_ioctl_function_t linux_ioctl_vfat; 65static linux_ioctl_function_t linux_ioctl_console; 66static linux_ioctl_function_t linux_ioctl_disk; 67static linux_ioctl_function_t linux_ioctl_socket; 68static linux_ioctl_function_t linux_ioctl_sound; 69static linux_ioctl_function_t linux_ioctl_termio; 70static linux_ioctl_function_t linux_ioctl_private; 71static linux_ioctl_function_t linux_ioctl_special; 72 73static struct linux_ioctl_handler cdrom_handler = 74{ linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN, LINUX_IOCTL_CDROM_MAX }; 75static struct linux_ioctl_handler vfat_handler = 76{ linux_ioctl_vfat, LINUX_IOCTL_VFAT_MIN, LINUX_IOCTL_VFAT_MAX }; 77static struct linux_ioctl_handler console_handler = 78{ linux_ioctl_console, LINUX_IOCTL_CONSOLE_MIN, LINUX_IOCTL_CONSOLE_MAX }; 79static struct linux_ioctl_handler disk_handler = 80{ linux_ioctl_disk, LINUX_IOCTL_DISK_MIN, LINUX_IOCTL_DISK_MAX }; 81static struct linux_ioctl_handler socket_handler = 82{ linux_ioctl_socket, LINUX_IOCTL_SOCKET_MIN, LINUX_IOCTL_SOCKET_MAX }; 83static struct linux_ioctl_handler sound_handler = 84{ linux_ioctl_sound, LINUX_IOCTL_SOUND_MIN, LINUX_IOCTL_SOUND_MAX }; 85static struct linux_ioctl_handler termio_handler = 86{ linux_ioctl_termio, LINUX_IOCTL_TERMIO_MIN, LINUX_IOCTL_TERMIO_MAX }; 87static struct linux_ioctl_handler private_handler = 88{ linux_ioctl_private, LINUX_IOCTL_PRIVATE_MIN, LINUX_IOCTL_PRIVATE_MAX }; 89 90DATA_SET(linux_ioctl_handler_set, cdrom_handler); 91DATA_SET(linux_ioctl_handler_set, vfat_handler); 92DATA_SET(linux_ioctl_handler_set, console_handler); 93DATA_SET(linux_ioctl_handler_set, disk_handler); 94DATA_SET(linux_ioctl_handler_set, socket_handler); 95DATA_SET(linux_ioctl_handler_set, sound_handler); 96DATA_SET(linux_ioctl_handler_set, termio_handler); 97DATA_SET(linux_ioctl_handler_set, private_handler); 98
| 29 */ 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/sysproto.h> 34#include <sys/cdio.h> 35#include <sys/dvdio.h> 36#include <sys/consio.h> 37#include <sys/ctype.h> 38#include <sys/disklabel.h> 39#include <sys/fcntl.h> 40#include <sys/file.h> 41#include <sys/filedesc.h> 42#include <sys/filio.h> 43#include <sys/kbio.h> 44#include <sys/linker_set.h> 45#include <sys/malloc.h> 46#include <sys/proc.h> 47#include <sys/socket.h> 48#include <sys/sockio.h> 49#include <sys/soundcard.h> 50#include <sys/tty.h> 51#include <sys/uio.h> 52#include <net/if.h> 53#include <net/if_dl.h> 54#include <net/if_types.h> 55 56#include <machine/../linux/linux.h> 57#include <machine/../linux/linux_proto.h> 58 59#include <compat/linux/linux_ioctl.h> 60#include <compat/linux/linux_mib.h> 61#include <compat/linux/linux_util.h> 62 63static linux_ioctl_function_t linux_ioctl_cdrom; 64static linux_ioctl_function_t linux_ioctl_vfat; 65static linux_ioctl_function_t linux_ioctl_console; 66static linux_ioctl_function_t linux_ioctl_disk; 67static linux_ioctl_function_t linux_ioctl_socket; 68static linux_ioctl_function_t linux_ioctl_sound; 69static linux_ioctl_function_t linux_ioctl_termio; 70static linux_ioctl_function_t linux_ioctl_private; 71static linux_ioctl_function_t linux_ioctl_special; 72 73static struct linux_ioctl_handler cdrom_handler = 74{ linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN, LINUX_IOCTL_CDROM_MAX }; 75static struct linux_ioctl_handler vfat_handler = 76{ linux_ioctl_vfat, LINUX_IOCTL_VFAT_MIN, LINUX_IOCTL_VFAT_MAX }; 77static struct linux_ioctl_handler console_handler = 78{ linux_ioctl_console, LINUX_IOCTL_CONSOLE_MIN, LINUX_IOCTL_CONSOLE_MAX }; 79static struct linux_ioctl_handler disk_handler = 80{ linux_ioctl_disk, LINUX_IOCTL_DISK_MIN, LINUX_IOCTL_DISK_MAX }; 81static struct linux_ioctl_handler socket_handler = 82{ linux_ioctl_socket, LINUX_IOCTL_SOCKET_MIN, LINUX_IOCTL_SOCKET_MAX }; 83static struct linux_ioctl_handler sound_handler = 84{ linux_ioctl_sound, LINUX_IOCTL_SOUND_MIN, LINUX_IOCTL_SOUND_MAX }; 85static struct linux_ioctl_handler termio_handler = 86{ linux_ioctl_termio, LINUX_IOCTL_TERMIO_MIN, LINUX_IOCTL_TERMIO_MAX }; 87static struct linux_ioctl_handler private_handler = 88{ linux_ioctl_private, LINUX_IOCTL_PRIVATE_MIN, LINUX_IOCTL_PRIVATE_MAX }; 89 90DATA_SET(linux_ioctl_handler_set, cdrom_handler); 91DATA_SET(linux_ioctl_handler_set, vfat_handler); 92DATA_SET(linux_ioctl_handler_set, console_handler); 93DATA_SET(linux_ioctl_handler_set, disk_handler); 94DATA_SET(linux_ioctl_handler_set, socket_handler); 95DATA_SET(linux_ioctl_handler_set, sound_handler); 96DATA_SET(linux_ioctl_handler_set, termio_handler); 97DATA_SET(linux_ioctl_handler_set, private_handler); 98
|
99struct handler_element
| 99struct handler_element
|
100{ 101 TAILQ_ENTRY(handler_element) list; 102 int (*func)(struct thread *, struct linux_ioctl_args *); 103 int low, high, span; 104}; 105 106static TAILQ_HEAD(, handler_element) handlers = 107 TAILQ_HEAD_INITIALIZER(handlers); 108 109static int 110linux_ioctl_disk(struct thread *td, struct linux_ioctl_args *args) 111{ 112 struct file *fp; 113 int error; 114 struct disklabel dl; 115 116 if ((error = fget(td, args->fd, &fp)) != 0) 117 return (error); 118 switch (args->cmd & 0xffff) { 119 case LINUX_BLKGETSIZE: 120 /* XXX: wrong, should use DIOCGMEDIASIZE/DIOCGSECTORSIZE */ 121 error = fo_ioctl(fp, DIOCGDINFO, (caddr_t)&dl, td->td_ucred, 122 td); 123 fdrop(fp, td); 124 if (error) 125 return (error); 126 return (copyout(&(dl.d_secperunit), (caddr_t)args->arg, 127 sizeof(dl.d_secperunit))); 128 } 129 fdrop(fp, td); 130 return (ENOIOCTL); 131} 132 133/* 134 * termio related ioctls 135 */ 136 137struct linux_termio { 138 unsigned short c_iflag; 139 unsigned short c_oflag; 140 unsigned short c_cflag; 141 unsigned short c_lflag; 142 unsigned char c_line; 143 unsigned char c_cc[LINUX_NCC]; 144}; 145 146struct linux_termios { 147 unsigned int c_iflag; 148 unsigned int c_oflag; 149 unsigned int c_cflag; 150 unsigned int c_lflag; 151#ifdef __alpha__ 152 unsigned char c_cc[LINUX_NCCS]; 153 unsigned char c_line; 154 unsigned int c_ispeed; 155 unsigned int c_ospeed; 156#else 157 unsigned char c_line; 158 unsigned char c_cc[LINUX_NCCS]; 159#endif 160}; 161 162struct linux_winsize { 163 unsigned short ws_row, ws_col; 164 unsigned short ws_xpixel, ws_ypixel; 165}; 166 167static struct speedtab sptab[] = { 168 { B0, LINUX_B0 }, { B50, LINUX_B50 }, 169 { B75, LINUX_B75 }, { B110, LINUX_B110 }, 170 { B134, LINUX_B134 }, { B150, LINUX_B150 }, 171 { B200, LINUX_B200 }, { B300, LINUX_B300 }, 172 { B600, LINUX_B600 }, { B1200, LINUX_B1200 }, 173 { B1800, LINUX_B1800 }, { B2400, LINUX_B2400 }, 174 { B4800, LINUX_B4800 }, { B9600, LINUX_B9600 }, 175 { B19200, LINUX_B19200 }, { B38400, LINUX_B38400 }, 176 { B57600, LINUX_B57600 }, { B115200, LINUX_B115200 }, 177 {-1, -1 } 178}; 179 180struct linux_serial_struct { 181 int type; 182 int line; 183 int port; 184 int irq; 185 int flags; 186 int xmit_fifo_size; 187 int custom_divisor; 188 int baud_base; 189 unsigned short close_delay; 190 char reserved_char[2]; 191 int hub6; 192 unsigned short closing_wait; 193 unsigned short closing_wait2; 194 int reserved[4]; 195}; 196 197static int 198linux_to_bsd_speed(int code, struct speedtab *table) 199{ 200 for ( ; table->sp_code != -1; table++) 201 if (table->sp_code == code) 202 return (table->sp_speed); 203 return -1; 204} 205 206static int 207bsd_to_linux_speed(int speed, struct speedtab *table) 208{ 209 for ( ; table->sp_speed != -1; table++) 210 if (table->sp_speed == speed) 211 return (table->sp_code); 212 return -1; 213} 214 215static void 216bsd_to_linux_termios(struct termios *bios, struct linux_termios *lios) 217{ 218 int i; 219 220#ifdef DEBUG 221 if (ldebug(ioctl)) { 222 printf("LINUX: BSD termios structure (input):\n"); 223 printf("i=%08x o=%08x c=%08x l=%08x ispeed=%d ospeed=%d\n", 224 bios->c_iflag, bios->c_oflag, bios->c_cflag, bios->c_lflag, 225 bios->c_ispeed, bios->c_ospeed); 226 printf("c_cc "); 227 for (i=0; i<NCCS; i++) 228 printf("%02x ", bios->c_cc[i]); 229 printf("\n"); 230 } 231#endif 232 233 lios->c_iflag = 0; 234 if (bios->c_iflag & IGNBRK) 235 lios->c_iflag |= LINUX_IGNBRK; 236 if (bios->c_iflag & BRKINT) 237 lios->c_iflag |= LINUX_BRKINT; 238 if (bios->c_iflag & IGNPAR) 239 lios->c_iflag |= LINUX_IGNPAR; 240 if (bios->c_iflag & PARMRK) 241 lios->c_iflag |= LINUX_PARMRK; 242 if (bios->c_iflag & INPCK) 243 lios->c_iflag |= LINUX_INPCK; 244 if (bios->c_iflag & ISTRIP) 245 lios->c_iflag |= LINUX_ISTRIP; 246 if (bios->c_iflag & INLCR) 247 lios->c_iflag |= LINUX_INLCR; 248 if (bios->c_iflag & IGNCR) 249 lios->c_iflag |= LINUX_IGNCR; 250 if (bios->c_iflag & ICRNL) 251 lios->c_iflag |= LINUX_ICRNL; 252 if (bios->c_iflag & IXON) 253 lios->c_iflag |= LINUX_IXON; 254 if (bios->c_iflag & IXANY) 255 lios->c_iflag |= LINUX_IXANY; 256 if (bios->c_iflag & IXOFF) 257 lios->c_iflag |= LINUX_IXOFF; 258 if (bios->c_iflag & IMAXBEL) 259 lios->c_iflag |= LINUX_IMAXBEL; 260 261 lios->c_oflag = 0; 262 if (bios->c_oflag & OPOST) 263 lios->c_oflag |= LINUX_OPOST; 264 if (bios->c_oflag & ONLCR) 265 lios->c_oflag |= LINUX_ONLCR; 266 if (bios->c_oflag & OXTABS) 267 lios->c_oflag |= LINUX_XTABS; 268 269 lios->c_cflag = bsd_to_linux_speed(bios->c_ispeed, sptab); 270 lios->c_cflag |= (bios->c_cflag & CSIZE) >> 4; 271 if (bios->c_cflag & CSTOPB) 272 lios->c_cflag |= LINUX_CSTOPB; 273 if (bios->c_cflag & CREAD) 274 lios->c_cflag |= LINUX_CREAD; 275 if (bios->c_cflag & PARENB) 276 lios->c_cflag |= LINUX_PARENB; 277 if (bios->c_cflag & PARODD) 278 lios->c_cflag |= LINUX_PARODD; 279 if (bios->c_cflag & HUPCL) 280 lios->c_cflag |= LINUX_HUPCL; 281 if (bios->c_cflag & CLOCAL) 282 lios->c_cflag |= LINUX_CLOCAL; 283 if (bios->c_cflag & CRTSCTS) 284 lios->c_cflag |= LINUX_CRTSCTS; 285 286 lios->c_lflag = 0; 287 if (bios->c_lflag & ISIG) 288 lios->c_lflag |= LINUX_ISIG; 289 if (bios->c_lflag & ICANON) 290 lios->c_lflag |= LINUX_ICANON; 291 if (bios->c_lflag & ECHO) 292 lios->c_lflag |= LINUX_ECHO; 293 if (bios->c_lflag & ECHOE) 294 lios->c_lflag |= LINUX_ECHOE; 295 if (bios->c_lflag & ECHOK) 296 lios->c_lflag |= LINUX_ECHOK; 297 if (bios->c_lflag & ECHONL) 298 lios->c_lflag |= LINUX_ECHONL; 299 if (bios->c_lflag & NOFLSH) 300 lios->c_lflag |= LINUX_NOFLSH; 301 if (bios->c_lflag & TOSTOP) 302 lios->c_lflag |= LINUX_TOSTOP; 303 if (bios->c_lflag & ECHOCTL) 304 lios->c_lflag |= LINUX_ECHOCTL; 305 if (bios->c_lflag & ECHOPRT) 306 lios->c_lflag |= LINUX_ECHOPRT; 307 if (bios->c_lflag & ECHOKE) 308 lios->c_lflag |= LINUX_ECHOKE; 309 if (bios->c_lflag & FLUSHO) 310 lios->c_lflag |= LINUX_FLUSHO; 311 if (bios->c_lflag & PENDIN) 312 lios->c_lflag |= LINUX_PENDIN; 313 if (bios->c_lflag & IEXTEN) 314 lios->c_lflag |= LINUX_IEXTEN; 315 316 for (i=0; i<LINUX_NCCS; i++) 317 lios->c_cc[i] = LINUX_POSIX_VDISABLE; 318 lios->c_cc[LINUX_VINTR] = bios->c_cc[VINTR]; 319 lios->c_cc[LINUX_VQUIT] = bios->c_cc[VQUIT]; 320 lios->c_cc[LINUX_VERASE] = bios->c_cc[VERASE]; 321 lios->c_cc[LINUX_VKILL] = bios->c_cc[VKILL]; 322 lios->c_cc[LINUX_VEOF] = bios->c_cc[VEOF]; 323 lios->c_cc[LINUX_VEOL] = bios->c_cc[VEOL]; 324 lios->c_cc[LINUX_VMIN] = bios->c_cc[VMIN]; 325 lios->c_cc[LINUX_VTIME] = bios->c_cc[VTIME]; 326 lios->c_cc[LINUX_VEOL2] = bios->c_cc[VEOL2]; 327 lios->c_cc[LINUX_VSUSP] = bios->c_cc[VSUSP]; 328 lios->c_cc[LINUX_VSTART] = bios->c_cc[VSTART]; 329 lios->c_cc[LINUX_VSTOP] = bios->c_cc[VSTOP]; 330 lios->c_cc[LINUX_VREPRINT] = bios->c_cc[VREPRINT]; 331 lios->c_cc[LINUX_VDISCARD] = bios->c_cc[VDISCARD]; 332 lios->c_cc[LINUX_VWERASE] = bios->c_cc[VWERASE]; 333 lios->c_cc[LINUX_VLNEXT] = bios->c_cc[VLNEXT]; 334 335 for (i=0; i<LINUX_NCCS; i++) { 336 if (lios->c_cc[i] == _POSIX_VDISABLE) 337 lios->c_cc[i] = LINUX_POSIX_VDISABLE; 338 } 339 lios->c_line = 0; 340 341#ifdef DEBUG 342 if (ldebug(ioctl)) { 343 printf("LINUX: LINUX termios structure (output):\n"); 344 printf("i=%08x o=%08x c=%08x l=%08x line=%d\n", 345 lios->c_iflag, lios->c_oflag, lios->c_cflag, 346 lios->c_lflag, (int)lios->c_line); 347 printf("c_cc ");
| 100{ 101 TAILQ_ENTRY(handler_element) list; 102 int (*func)(struct thread *, struct linux_ioctl_args *); 103 int low, high, span; 104}; 105 106static TAILQ_HEAD(, handler_element) handlers = 107 TAILQ_HEAD_INITIALIZER(handlers); 108 109static int 110linux_ioctl_disk(struct thread *td, struct linux_ioctl_args *args) 111{ 112 struct file *fp; 113 int error; 114 struct disklabel dl; 115 116 if ((error = fget(td, args->fd, &fp)) != 0) 117 return (error); 118 switch (args->cmd & 0xffff) { 119 case LINUX_BLKGETSIZE: 120 /* XXX: wrong, should use DIOCGMEDIASIZE/DIOCGSECTORSIZE */ 121 error = fo_ioctl(fp, DIOCGDINFO, (caddr_t)&dl, td->td_ucred, 122 td); 123 fdrop(fp, td); 124 if (error) 125 return (error); 126 return (copyout(&(dl.d_secperunit), (caddr_t)args->arg, 127 sizeof(dl.d_secperunit))); 128 } 129 fdrop(fp, td); 130 return (ENOIOCTL); 131} 132 133/* 134 * termio related ioctls 135 */ 136 137struct linux_termio { 138 unsigned short c_iflag; 139 unsigned short c_oflag; 140 unsigned short c_cflag; 141 unsigned short c_lflag; 142 unsigned char c_line; 143 unsigned char c_cc[LINUX_NCC]; 144}; 145 146struct linux_termios { 147 unsigned int c_iflag; 148 unsigned int c_oflag; 149 unsigned int c_cflag; 150 unsigned int c_lflag; 151#ifdef __alpha__ 152 unsigned char c_cc[LINUX_NCCS]; 153 unsigned char c_line; 154 unsigned int c_ispeed; 155 unsigned int c_ospeed; 156#else 157 unsigned char c_line; 158 unsigned char c_cc[LINUX_NCCS]; 159#endif 160}; 161 162struct linux_winsize { 163 unsigned short ws_row, ws_col; 164 unsigned short ws_xpixel, ws_ypixel; 165}; 166 167static struct speedtab sptab[] = { 168 { B0, LINUX_B0 }, { B50, LINUX_B50 }, 169 { B75, LINUX_B75 }, { B110, LINUX_B110 }, 170 { B134, LINUX_B134 }, { B150, LINUX_B150 }, 171 { B200, LINUX_B200 }, { B300, LINUX_B300 }, 172 { B600, LINUX_B600 }, { B1200, LINUX_B1200 }, 173 { B1800, LINUX_B1800 }, { B2400, LINUX_B2400 }, 174 { B4800, LINUX_B4800 }, { B9600, LINUX_B9600 }, 175 { B19200, LINUX_B19200 }, { B38400, LINUX_B38400 }, 176 { B57600, LINUX_B57600 }, { B115200, LINUX_B115200 }, 177 {-1, -1 } 178}; 179 180struct linux_serial_struct { 181 int type; 182 int line; 183 int port; 184 int irq; 185 int flags; 186 int xmit_fifo_size; 187 int custom_divisor; 188 int baud_base; 189 unsigned short close_delay; 190 char reserved_char[2]; 191 int hub6; 192 unsigned short closing_wait; 193 unsigned short closing_wait2; 194 int reserved[4]; 195}; 196 197static int 198linux_to_bsd_speed(int code, struct speedtab *table) 199{ 200 for ( ; table->sp_code != -1; table++) 201 if (table->sp_code == code) 202 return (table->sp_speed); 203 return -1; 204} 205 206static int 207bsd_to_linux_speed(int speed, struct speedtab *table) 208{ 209 for ( ; table->sp_speed != -1; table++) 210 if (table->sp_speed == speed) 211 return (table->sp_code); 212 return -1; 213} 214 215static void 216bsd_to_linux_termios(struct termios *bios, struct linux_termios *lios) 217{ 218 int i; 219 220#ifdef DEBUG 221 if (ldebug(ioctl)) { 222 printf("LINUX: BSD termios structure (input):\n"); 223 printf("i=%08x o=%08x c=%08x l=%08x ispeed=%d ospeed=%d\n", 224 bios->c_iflag, bios->c_oflag, bios->c_cflag, bios->c_lflag, 225 bios->c_ispeed, bios->c_ospeed); 226 printf("c_cc "); 227 for (i=0; i<NCCS; i++) 228 printf("%02x ", bios->c_cc[i]); 229 printf("\n"); 230 } 231#endif 232 233 lios->c_iflag = 0; 234 if (bios->c_iflag & IGNBRK) 235 lios->c_iflag |= LINUX_IGNBRK; 236 if (bios->c_iflag & BRKINT) 237 lios->c_iflag |= LINUX_BRKINT; 238 if (bios->c_iflag & IGNPAR) 239 lios->c_iflag |= LINUX_IGNPAR; 240 if (bios->c_iflag & PARMRK) 241 lios->c_iflag |= LINUX_PARMRK; 242 if (bios->c_iflag & INPCK) 243 lios->c_iflag |= LINUX_INPCK; 244 if (bios->c_iflag & ISTRIP) 245 lios->c_iflag |= LINUX_ISTRIP; 246 if (bios->c_iflag & INLCR) 247 lios->c_iflag |= LINUX_INLCR; 248 if (bios->c_iflag & IGNCR) 249 lios->c_iflag |= LINUX_IGNCR; 250 if (bios->c_iflag & ICRNL) 251 lios->c_iflag |= LINUX_ICRNL; 252 if (bios->c_iflag & IXON) 253 lios->c_iflag |= LINUX_IXON; 254 if (bios->c_iflag & IXANY) 255 lios->c_iflag |= LINUX_IXANY; 256 if (bios->c_iflag & IXOFF) 257 lios->c_iflag |= LINUX_IXOFF; 258 if (bios->c_iflag & IMAXBEL) 259 lios->c_iflag |= LINUX_IMAXBEL; 260 261 lios->c_oflag = 0; 262 if (bios->c_oflag & OPOST) 263 lios->c_oflag |= LINUX_OPOST; 264 if (bios->c_oflag & ONLCR) 265 lios->c_oflag |= LINUX_ONLCR; 266 if (bios->c_oflag & OXTABS) 267 lios->c_oflag |= LINUX_XTABS; 268 269 lios->c_cflag = bsd_to_linux_speed(bios->c_ispeed, sptab); 270 lios->c_cflag |= (bios->c_cflag & CSIZE) >> 4; 271 if (bios->c_cflag & CSTOPB) 272 lios->c_cflag |= LINUX_CSTOPB; 273 if (bios->c_cflag & CREAD) 274 lios->c_cflag |= LINUX_CREAD; 275 if (bios->c_cflag & PARENB) 276 lios->c_cflag |= LINUX_PARENB; 277 if (bios->c_cflag & PARODD) 278 lios->c_cflag |= LINUX_PARODD; 279 if (bios->c_cflag & HUPCL) 280 lios->c_cflag |= LINUX_HUPCL; 281 if (bios->c_cflag & CLOCAL) 282 lios->c_cflag |= LINUX_CLOCAL; 283 if (bios->c_cflag & CRTSCTS) 284 lios->c_cflag |= LINUX_CRTSCTS; 285 286 lios->c_lflag = 0; 287 if (bios->c_lflag & ISIG) 288 lios->c_lflag |= LINUX_ISIG; 289 if (bios->c_lflag & ICANON) 290 lios->c_lflag |= LINUX_ICANON; 291 if (bios->c_lflag & ECHO) 292 lios->c_lflag |= LINUX_ECHO; 293 if (bios->c_lflag & ECHOE) 294 lios->c_lflag |= LINUX_ECHOE; 295 if (bios->c_lflag & ECHOK) 296 lios->c_lflag |= LINUX_ECHOK; 297 if (bios->c_lflag & ECHONL) 298 lios->c_lflag |= LINUX_ECHONL; 299 if (bios->c_lflag & NOFLSH) 300 lios->c_lflag |= LINUX_NOFLSH; 301 if (bios->c_lflag & TOSTOP) 302 lios->c_lflag |= LINUX_TOSTOP; 303 if (bios->c_lflag & ECHOCTL) 304 lios->c_lflag |= LINUX_ECHOCTL; 305 if (bios->c_lflag & ECHOPRT) 306 lios->c_lflag |= LINUX_ECHOPRT; 307 if (bios->c_lflag & ECHOKE) 308 lios->c_lflag |= LINUX_ECHOKE; 309 if (bios->c_lflag & FLUSHO) 310 lios->c_lflag |= LINUX_FLUSHO; 311 if (bios->c_lflag & PENDIN) 312 lios->c_lflag |= LINUX_PENDIN; 313 if (bios->c_lflag & IEXTEN) 314 lios->c_lflag |= LINUX_IEXTEN; 315 316 for (i=0; i<LINUX_NCCS; i++) 317 lios->c_cc[i] = LINUX_POSIX_VDISABLE; 318 lios->c_cc[LINUX_VINTR] = bios->c_cc[VINTR]; 319 lios->c_cc[LINUX_VQUIT] = bios->c_cc[VQUIT]; 320 lios->c_cc[LINUX_VERASE] = bios->c_cc[VERASE]; 321 lios->c_cc[LINUX_VKILL] = bios->c_cc[VKILL]; 322 lios->c_cc[LINUX_VEOF] = bios->c_cc[VEOF]; 323 lios->c_cc[LINUX_VEOL] = bios->c_cc[VEOL]; 324 lios->c_cc[LINUX_VMIN] = bios->c_cc[VMIN]; 325 lios->c_cc[LINUX_VTIME] = bios->c_cc[VTIME]; 326 lios->c_cc[LINUX_VEOL2] = bios->c_cc[VEOL2]; 327 lios->c_cc[LINUX_VSUSP] = bios->c_cc[VSUSP]; 328 lios->c_cc[LINUX_VSTART] = bios->c_cc[VSTART]; 329 lios->c_cc[LINUX_VSTOP] = bios->c_cc[VSTOP]; 330 lios->c_cc[LINUX_VREPRINT] = bios->c_cc[VREPRINT]; 331 lios->c_cc[LINUX_VDISCARD] = bios->c_cc[VDISCARD]; 332 lios->c_cc[LINUX_VWERASE] = bios->c_cc[VWERASE]; 333 lios->c_cc[LINUX_VLNEXT] = bios->c_cc[VLNEXT]; 334 335 for (i=0; i<LINUX_NCCS; i++) { 336 if (lios->c_cc[i] == _POSIX_VDISABLE) 337 lios->c_cc[i] = LINUX_POSIX_VDISABLE; 338 } 339 lios->c_line = 0; 340 341#ifdef DEBUG 342 if (ldebug(ioctl)) { 343 printf("LINUX: LINUX termios structure (output):\n"); 344 printf("i=%08x o=%08x c=%08x l=%08x line=%d\n", 345 lios->c_iflag, lios->c_oflag, lios->c_cflag, 346 lios->c_lflag, (int)lios->c_line); 347 printf("c_cc ");
|
348 for (i=0; i<LINUX_NCCS; i++)
| 348 for (i=0; i |
349 printf("%02x ", lios->c_cc[i]); 350 printf("\n"); 351 } 352#endif 353} 354 355static void 356linux_to_bsd_termios(struct linux_termios *lios, struct termios *bios) 357{ 358 int i; 359 360#ifdef DEBUG 361 if (ldebug(ioctl)) { 362 printf("LINUX: LINUX termios structure (input):\n");
| 349 printf("%02x ", lios->c_cc[i]); 350 printf("\n"); 351 } 352#endif 353} 354 355static void 356linux_to_bsd_termios(struct linux_termios *lios, struct termios *bios) 357{ 358 int i; 359 360#ifdef DEBUG 361 if (ldebug(ioctl)) { 362 printf("LINUX: LINUX termios structure (input):\n");
|
363 printf("i=%08x o=%08x c=%08x l=%08x line=%d\n",
| 363 printf("i=%08x o=%08x c=%08x l=%08x line=%d\n",
|
364 lios->c_iflag, lios->c_oflag, lios->c_cflag, 365 lios->c_lflag, (int)lios->c_line); 366 printf("c_cc "); 367 for (i=0; i<LINUX_NCCS; i++) 368 printf("%02x ", lios->c_cc[i]); 369 printf("\n"); 370 } 371#endif 372 373 bios->c_iflag = 0; 374 if (lios->c_iflag & LINUX_IGNBRK) 375 bios->c_iflag |= IGNBRK; 376 if (lios->c_iflag & LINUX_BRKINT) 377 bios->c_iflag |= BRKINT; 378 if (lios->c_iflag & LINUX_IGNPAR) 379 bios->c_iflag |= IGNPAR; 380 if (lios->c_iflag & LINUX_PARMRK) 381 bios->c_iflag |= PARMRK; 382 if (lios->c_iflag & LINUX_INPCK) 383 bios->c_iflag |= INPCK; 384 if (lios->c_iflag & LINUX_ISTRIP) 385 bios->c_iflag |= ISTRIP; 386 if (lios->c_iflag & LINUX_INLCR) 387 bios->c_iflag |= INLCR; 388 if (lios->c_iflag & LINUX_IGNCR) 389 bios->c_iflag |= IGNCR; 390 if (lios->c_iflag & LINUX_ICRNL) 391 bios->c_iflag |= ICRNL; 392 if (lios->c_iflag & LINUX_IXON) 393 bios->c_iflag |= IXON; 394 if (lios->c_iflag & LINUX_IXANY) 395 bios->c_iflag |= IXANY; 396 if (lios->c_iflag & LINUX_IXOFF) 397 bios->c_iflag |= IXOFF; 398 if (lios->c_iflag & LINUX_IMAXBEL) 399 bios->c_iflag |= IMAXBEL; 400 401 bios->c_oflag = 0; 402 if (lios->c_oflag & LINUX_OPOST) 403 bios->c_oflag |= OPOST; 404 if (lios->c_oflag & LINUX_ONLCR) 405 bios->c_oflag |= ONLCR; 406 if (lios->c_oflag & LINUX_XTABS) 407 bios->c_oflag |= OXTABS; 408 409 bios->c_cflag = (lios->c_cflag & LINUX_CSIZE) << 4; 410 if (lios->c_cflag & LINUX_CSTOPB) 411 bios->c_cflag |= CSTOPB; 412 if (lios->c_cflag & LINUX_CREAD) 413 bios->c_cflag |= CREAD; 414 if (lios->c_cflag & LINUX_PARENB) 415 bios->c_cflag |= PARENB; 416 if (lios->c_cflag & LINUX_PARODD) 417 bios->c_cflag |= PARODD; 418 if (lios->c_cflag & LINUX_HUPCL) 419 bios->c_cflag |= HUPCL; 420 if (lios->c_cflag & LINUX_CLOCAL) 421 bios->c_cflag |= CLOCAL; 422 if (lios->c_cflag & LINUX_CRTSCTS) 423 bios->c_cflag |= CRTSCTS; 424 425 bios->c_lflag = 0; 426 if (lios->c_lflag & LINUX_ISIG) 427 bios->c_lflag |= ISIG; 428 if (lios->c_lflag & LINUX_ICANON) 429 bios->c_lflag |= ICANON; 430 if (lios->c_lflag & LINUX_ECHO) 431 bios->c_lflag |= ECHO; 432 if (lios->c_lflag & LINUX_ECHOE) 433 bios->c_lflag |= ECHOE; 434 if (lios->c_lflag & LINUX_ECHOK) 435 bios->c_lflag |= ECHOK; 436 if (lios->c_lflag & LINUX_ECHONL) 437 bios->c_lflag |= ECHONL; 438 if (lios->c_lflag & LINUX_NOFLSH) 439 bios->c_lflag |= NOFLSH; 440 if (lios->c_lflag & LINUX_TOSTOP) 441 bios->c_lflag |= TOSTOP; 442 if (lios->c_lflag & LINUX_ECHOCTL) 443 bios->c_lflag |= ECHOCTL; 444 if (lios->c_lflag & LINUX_ECHOPRT) 445 bios->c_lflag |= ECHOPRT; 446 if (lios->c_lflag & LINUX_ECHOKE) 447 bios->c_lflag |= ECHOKE; 448 if (lios->c_lflag & LINUX_FLUSHO) 449 bios->c_lflag |= FLUSHO; 450 if (lios->c_lflag & LINUX_PENDIN) 451 bios->c_lflag |= PENDIN; 452 if (lios->c_lflag & LINUX_IEXTEN) 453 bios->c_lflag |= IEXTEN; 454 455 for (i=0; i<NCCS; i++) 456 bios->c_cc[i] = _POSIX_VDISABLE; 457 bios->c_cc[VINTR] = lios->c_cc[LINUX_VINTR]; 458 bios->c_cc[VQUIT] = lios->c_cc[LINUX_VQUIT]; 459 bios->c_cc[VERASE] = lios->c_cc[LINUX_VERASE]; 460 bios->c_cc[VKILL] = lios->c_cc[LINUX_VKILL]; 461 bios->c_cc[VEOF] = lios->c_cc[LINUX_VEOF]; 462 bios->c_cc[VEOL] = lios->c_cc[LINUX_VEOL]; 463 bios->c_cc[VMIN] = lios->c_cc[LINUX_VMIN]; 464 bios->c_cc[VTIME] = lios->c_cc[LINUX_VTIME]; 465 bios->c_cc[VEOL2] = lios->c_cc[LINUX_VEOL2]; 466 bios->c_cc[VSUSP] = lios->c_cc[LINUX_VSUSP]; 467 bios->c_cc[VSTART] = lios->c_cc[LINUX_VSTART]; 468 bios->c_cc[VSTOP] = lios->c_cc[LINUX_VSTOP]; 469 bios->c_cc[VREPRINT] = lios->c_cc[LINUX_VREPRINT]; 470 bios->c_cc[VDISCARD] = lios->c_cc[LINUX_VDISCARD]; 471 bios->c_cc[VWERASE] = lios->c_cc[LINUX_VWERASE]; 472 bios->c_cc[VLNEXT] = lios->c_cc[LINUX_VLNEXT]; 473 474 for (i=0; i<NCCS; i++) { 475 if (bios->c_cc[i] == LINUX_POSIX_VDISABLE) 476 bios->c_cc[i] = _POSIX_VDISABLE; 477 } 478 479 bios->c_ispeed = bios->c_ospeed = 480 linux_to_bsd_speed(lios->c_cflag & LINUX_CBAUD, sptab); 481 482#ifdef DEBUG 483 if (ldebug(ioctl)) { 484 printf("LINUX: BSD termios structure (output):\n"); 485 printf("i=%08x o=%08x c=%08x l=%08x ispeed=%d ospeed=%d\n", 486 bios->c_iflag, bios->c_oflag, bios->c_cflag, bios->c_lflag, 487 bios->c_ispeed, bios->c_ospeed); 488 printf("c_cc ");
| 364 lios->c_iflag, lios->c_oflag, lios->c_cflag, 365 lios->c_lflag, (int)lios->c_line); 366 printf("c_cc "); 367 for (i=0; i<LINUX_NCCS; i++) 368 printf("%02x ", lios->c_cc[i]); 369 printf("\n"); 370 } 371#endif 372 373 bios->c_iflag = 0; 374 if (lios->c_iflag & LINUX_IGNBRK) 375 bios->c_iflag |= IGNBRK; 376 if (lios->c_iflag & LINUX_BRKINT) 377 bios->c_iflag |= BRKINT; 378 if (lios->c_iflag & LINUX_IGNPAR) 379 bios->c_iflag |= IGNPAR; 380 if (lios->c_iflag & LINUX_PARMRK) 381 bios->c_iflag |= PARMRK; 382 if (lios->c_iflag & LINUX_INPCK) 383 bios->c_iflag |= INPCK; 384 if (lios->c_iflag & LINUX_ISTRIP) 385 bios->c_iflag |= ISTRIP; 386 if (lios->c_iflag & LINUX_INLCR) 387 bios->c_iflag |= INLCR; 388 if (lios->c_iflag & LINUX_IGNCR) 389 bios->c_iflag |= IGNCR; 390 if (lios->c_iflag & LINUX_ICRNL) 391 bios->c_iflag |= ICRNL; 392 if (lios->c_iflag & LINUX_IXON) 393 bios->c_iflag |= IXON; 394 if (lios->c_iflag & LINUX_IXANY) 395 bios->c_iflag |= IXANY; 396 if (lios->c_iflag & LINUX_IXOFF) 397 bios->c_iflag |= IXOFF; 398 if (lios->c_iflag & LINUX_IMAXBEL) 399 bios->c_iflag |= IMAXBEL; 400 401 bios->c_oflag = 0; 402 if (lios->c_oflag & LINUX_OPOST) 403 bios->c_oflag |= OPOST; 404 if (lios->c_oflag & LINUX_ONLCR) 405 bios->c_oflag |= ONLCR; 406 if (lios->c_oflag & LINUX_XTABS) 407 bios->c_oflag |= OXTABS; 408 409 bios->c_cflag = (lios->c_cflag & LINUX_CSIZE) << 4; 410 if (lios->c_cflag & LINUX_CSTOPB) 411 bios->c_cflag |= CSTOPB; 412 if (lios->c_cflag & LINUX_CREAD) 413 bios->c_cflag |= CREAD; 414 if (lios->c_cflag & LINUX_PARENB) 415 bios->c_cflag |= PARENB; 416 if (lios->c_cflag & LINUX_PARODD) 417 bios->c_cflag |= PARODD; 418 if (lios->c_cflag & LINUX_HUPCL) 419 bios->c_cflag |= HUPCL; 420 if (lios->c_cflag & LINUX_CLOCAL) 421 bios->c_cflag |= CLOCAL; 422 if (lios->c_cflag & LINUX_CRTSCTS) 423 bios->c_cflag |= CRTSCTS; 424 425 bios->c_lflag = 0; 426 if (lios->c_lflag & LINUX_ISIG) 427 bios->c_lflag |= ISIG; 428 if (lios->c_lflag & LINUX_ICANON) 429 bios->c_lflag |= ICANON; 430 if (lios->c_lflag & LINUX_ECHO) 431 bios->c_lflag |= ECHO; 432 if (lios->c_lflag & LINUX_ECHOE) 433 bios->c_lflag |= ECHOE; 434 if (lios->c_lflag & LINUX_ECHOK) 435 bios->c_lflag |= ECHOK; 436 if (lios->c_lflag & LINUX_ECHONL) 437 bios->c_lflag |= ECHONL; 438 if (lios->c_lflag & LINUX_NOFLSH) 439 bios->c_lflag |= NOFLSH; 440 if (lios->c_lflag & LINUX_TOSTOP) 441 bios->c_lflag |= TOSTOP; 442 if (lios->c_lflag & LINUX_ECHOCTL) 443 bios->c_lflag |= ECHOCTL; 444 if (lios->c_lflag & LINUX_ECHOPRT) 445 bios->c_lflag |= ECHOPRT; 446 if (lios->c_lflag & LINUX_ECHOKE) 447 bios->c_lflag |= ECHOKE; 448 if (lios->c_lflag & LINUX_FLUSHO) 449 bios->c_lflag |= FLUSHO; 450 if (lios->c_lflag & LINUX_PENDIN) 451 bios->c_lflag |= PENDIN; 452 if (lios->c_lflag & LINUX_IEXTEN) 453 bios->c_lflag |= IEXTEN; 454 455 for (i=0; i<NCCS; i++) 456 bios->c_cc[i] = _POSIX_VDISABLE; 457 bios->c_cc[VINTR] = lios->c_cc[LINUX_VINTR]; 458 bios->c_cc[VQUIT] = lios->c_cc[LINUX_VQUIT]; 459 bios->c_cc[VERASE] = lios->c_cc[LINUX_VERASE]; 460 bios->c_cc[VKILL] = lios->c_cc[LINUX_VKILL]; 461 bios->c_cc[VEOF] = lios->c_cc[LINUX_VEOF]; 462 bios->c_cc[VEOL] = lios->c_cc[LINUX_VEOL]; 463 bios->c_cc[VMIN] = lios->c_cc[LINUX_VMIN]; 464 bios->c_cc[VTIME] = lios->c_cc[LINUX_VTIME]; 465 bios->c_cc[VEOL2] = lios->c_cc[LINUX_VEOL2]; 466 bios->c_cc[VSUSP] = lios->c_cc[LINUX_VSUSP]; 467 bios->c_cc[VSTART] = lios->c_cc[LINUX_VSTART]; 468 bios->c_cc[VSTOP] = lios->c_cc[LINUX_VSTOP]; 469 bios->c_cc[VREPRINT] = lios->c_cc[LINUX_VREPRINT]; 470 bios->c_cc[VDISCARD] = lios->c_cc[LINUX_VDISCARD]; 471 bios->c_cc[VWERASE] = lios->c_cc[LINUX_VWERASE]; 472 bios->c_cc[VLNEXT] = lios->c_cc[LINUX_VLNEXT]; 473 474 for (i=0; i<NCCS; i++) { 475 if (bios->c_cc[i] == LINUX_POSIX_VDISABLE) 476 bios->c_cc[i] = _POSIX_VDISABLE; 477 } 478 479 bios->c_ispeed = bios->c_ospeed = 480 linux_to_bsd_speed(lios->c_cflag & LINUX_CBAUD, sptab); 481 482#ifdef DEBUG 483 if (ldebug(ioctl)) { 484 printf("LINUX: BSD termios structure (output):\n"); 485 printf("i=%08x o=%08x c=%08x l=%08x ispeed=%d ospeed=%d\n", 486 bios->c_iflag, bios->c_oflag, bios->c_cflag, bios->c_lflag, 487 bios->c_ispeed, bios->c_ospeed); 488 printf("c_cc ");
|
489 for (i=0; i<NCCS; i++)
| 489 for (i=0; i |
490 printf("%02x ", bios->c_cc[i]); 491 printf("\n"); 492 } 493#endif 494} 495 496static void 497bsd_to_linux_termio(struct termios *bios, struct linux_termio *lio) 498{ 499 struct linux_termios lios; 500 501 bsd_to_linux_termios(bios, &lios); 502 lio->c_iflag = lios.c_iflag; 503 lio->c_oflag = lios.c_oflag; 504 lio->c_cflag = lios.c_cflag; 505 lio->c_lflag = lios.c_lflag; 506 lio->c_line = lios.c_line; 507#ifdef __alpha__ 508 lio->c_cc[LINUX__VINTR] = lios.c_cc[LINUX_VINTR]; 509 lio->c_cc[LINUX__VQUIT] = lios.c_cc[LINUX_VQUIT]; 510 lio->c_cc[LINUX__VERASE] = lios.c_cc[LINUX_VERASE]; 511 lio->c_cc[LINUX__VKILL] = lios.c_cc[LINUX_VKILL]; 512 lio->c_cc[LINUX__VEOF] = 513 lios.c_cc[(lios.c_lflag & ICANON) ? LINUX_VEOF : LINUX_VMIN]; 514 lio->c_cc[LINUX__VEOL] = 515 lios.c_cc[(lios.c_lflag & ICANON) ? LINUX_VEOL : LINUX_VTIME]; 516 lio->c_cc[LINUX__VEOL2] = lios.c_cc[LINUX_VEOL2]; 517 lio->c_cc[LINUX__VSWTC] = lios.c_cc[LINUX_VSWTC]; 518#else 519 memcpy(lio->c_cc, lios.c_cc, LINUX_NCC); 520#endif 521} 522 523static void 524linux_to_bsd_termio(struct linux_termio *lio, struct termios *bios) 525{ 526 struct linux_termios lios; 527 int i; 528 529 lios.c_iflag = lio->c_iflag; 530 lios.c_oflag = lio->c_oflag; 531 lios.c_cflag = lio->c_cflag; 532 lios.c_lflag = lio->c_lflag; 533#ifdef __alpha__ 534 for (i=0; i<LINUX_NCCS; i++) 535 lios.c_cc[i] = LINUX_POSIX_VDISABLE; 536 lios.c_cc[LINUX_VINTR] = lio->c_cc[LINUX__VINTR]; 537 lios.c_cc[LINUX_VQUIT] = lio->c_cc[LINUX__VQUIT]; 538 lios.c_cc[LINUX_VERASE] = lio->c_cc[LINUX__VERASE]; 539 lios.c_cc[LINUX_VKILL] = lio->c_cc[LINUX__VKILL]; 540 lios.c_cc[LINUX_VEOL2] = lio->c_cc[LINUX__VEOL2]; 541 lios.c_cc[LINUX_VSWTC] = lio->c_cc[LINUX__VSWTC]; 542 lios.c_cc[(lio->c_lflag & ICANON) ? LINUX_VEOF : LINUX_VMIN] = 543 lio->c_cc[LINUX__VEOF]; 544 lios.c_cc[(lio->c_lflag & ICANON) ? LINUX_VEOL : LINUX_VTIME] = 545 lio->c_cc[LINUX__VEOL]; 546#else 547 for (i=LINUX_NCC; i<LINUX_NCCS; i++) 548 lios.c_cc[i] = LINUX_POSIX_VDISABLE; 549 memcpy(lios.c_cc, lio->c_cc, LINUX_NCC); 550#endif 551 linux_to_bsd_termios(&lios, bios); 552} 553 554static int 555linux_ioctl_termio(struct thread *td, struct linux_ioctl_args *args) 556{ 557 struct termios bios; 558 struct linux_termios lios; 559 struct linux_termio lio; 560 struct file *fp; 561 int error; 562 563 if ((error = fget(td, args->fd, &fp)) != 0) 564 return (error); 565 566 switch (args->cmd & 0xffff) { 567 568 case LINUX_TCGETS: 569 error = fo_ioctl(fp, TIOCGETA, (caddr_t)&bios, td->td_ucred, 570 td); 571 if (error) 572 break; 573 bsd_to_linux_termios(&bios, &lios); 574 error = copyout(&lios, (caddr_t)args->arg, sizeof(lios)); 575 break; 576 577 case LINUX_TCSETS: 578 error = copyin((caddr_t)args->arg, &lios, sizeof(lios)); 579 if (error) 580 break; 581 linux_to_bsd_termios(&lios, &bios); 582 error = (fo_ioctl(fp, TIOCSETA, (caddr_t)&bios, td->td_ucred, 583 td)); 584 break; 585 586 case LINUX_TCSETSW: 587 error = copyin((caddr_t)args->arg, &lios, sizeof(lios)); 588 if (error) 589 break; 590 linux_to_bsd_termios(&lios, &bios); 591 error = (fo_ioctl(fp, TIOCSETAW, (caddr_t)&bios, td->td_ucred, 592 td)); 593 break; 594 595 case LINUX_TCSETSF: 596 error = copyin((caddr_t)args->arg, &lios, sizeof(lios)); 597 if (error) 598 break; 599 linux_to_bsd_termios(&lios, &bios); 600 error = (fo_ioctl(fp, TIOCSETAF, (caddr_t)&bios, td->td_ucred, 601 td)); 602 break; 603 604 case LINUX_TCGETA: 605 error = fo_ioctl(fp, TIOCGETA, (caddr_t)&bios, td->td_ucred, 606 td); 607 if (error) 608 break; 609 bsd_to_linux_termio(&bios, &lio); 610 error = (copyout(&lio, (caddr_t)args->arg, sizeof(lio))); 611 break; 612 613 case LINUX_TCSETA: 614 error = copyin((caddr_t)args->arg, &lio, sizeof(lio)); 615 if (error) 616 break; 617 linux_to_bsd_termio(&lio, &bios); 618 error = (fo_ioctl(fp, TIOCSETA, (caddr_t)&bios, td->td_ucred, 619 td)); 620 break; 621 622 case LINUX_TCSETAW: 623 error = copyin((caddr_t)args->arg, &lio, sizeof(lio)); 624 if (error) 625 break; 626 linux_to_bsd_termio(&lio, &bios); 627 error = (fo_ioctl(fp, TIOCSETAW, (caddr_t)&bios, td->td_ucred, 628 td)); 629 break; 630 631 case LINUX_TCSETAF: 632 error = copyin((caddr_t)args->arg, &lio, sizeof(lio)); 633 if (error) 634 break; 635 linux_to_bsd_termio(&lio, &bios); 636 error = (fo_ioctl(fp, TIOCSETAF, (caddr_t)&bios, td->td_ucred, 637 td)); 638 break; 639 640 /* LINUX_TCSBRK */ 641 642 case LINUX_TCXONC: { 643 switch (args->arg) { 644 case LINUX_TCOOFF: 645 args->cmd = TIOCSTOP; 646 break; 647 case LINUX_TCOON: 648 args->cmd = TIOCSTART; 649 break; 650 case LINUX_TCIOFF: 651 case LINUX_TCION: { 652 int c; 653 struct write_args wr; 654 error = fo_ioctl(fp, TIOCGETA, (caddr_t)&bios, 655 td->td_ucred, td); 656 if (error) 657 break; 658 fdrop(fp, td); 659 c = (args->arg == LINUX_TCIOFF) ? VSTOP : VSTART; 660 c = bios.c_cc[c]; 661 if (c != _POSIX_VDISABLE) { 662 wr.fd = args->fd; 663 wr.buf = &c; 664 wr.nbyte = sizeof(c); 665 return (write(td, &wr)); 666 } else 667 return (0); 668 } 669 default: 670 fdrop(fp, td); 671 return (EINVAL); 672 } 673 args->arg = 0; 674 error = (ioctl(td, (struct ioctl_args *)args)); 675 break; 676 } 677 678 case LINUX_TCFLSH: { 679 args->cmd = TIOCFLUSH; 680 switch (args->arg) { 681 case LINUX_TCIFLUSH: 682 args->arg = FREAD; 683 break; 684 case LINUX_TCOFLUSH: 685 args->arg = FWRITE; 686 break; 687 case LINUX_TCIOFLUSH: 688 args->arg = FREAD | FWRITE; 689 break; 690 default: 691 fdrop(fp, td); 692 return (EINVAL); 693 } 694 error = (ioctl(td, (struct ioctl_args *)args)); 695 break; 696 } 697 698 case LINUX_TIOCEXCL: 699 args->cmd = TIOCEXCL; 700 error = (ioctl(td, (struct ioctl_args *)args)); 701 break; 702 703 case LINUX_TIOCNXCL: 704 args->cmd = TIOCNXCL; 705 error = (ioctl(td, (struct ioctl_args *)args)); 706 break; 707 708 case LINUX_TIOCSCTTY: 709 args->cmd = TIOCSCTTY; 710 error = (ioctl(td, (struct ioctl_args *)args)); 711 break; 712 713 case LINUX_TIOCGPGRP: 714 args->cmd = TIOCGPGRP; 715 error = (ioctl(td, (struct ioctl_args *)args)); 716 break; 717 718 case LINUX_TIOCSPGRP: 719 args->cmd = TIOCSPGRP; 720 error = (ioctl(td, (struct ioctl_args *)args)); 721 break; 722 723 /* LINUX_TIOCOUTQ */ 724 /* LINUX_TIOCSTI */ 725 726 case LINUX_TIOCGWINSZ: 727 args->cmd = TIOCGWINSZ; 728 error = (ioctl(td, (struct ioctl_args *)args)); 729 break; 730 731 case LINUX_TIOCSWINSZ: 732 args->cmd = TIOCSWINSZ; 733 error = (ioctl(td, (struct ioctl_args *)args)); 734 break; 735 736 case LINUX_TIOCMGET: 737 args->cmd = TIOCMGET; 738 error = (ioctl(td, (struct ioctl_args *)args)); 739 break; 740 741 case LINUX_TIOCMBIS: 742 args->cmd = TIOCMBIS; 743 error = (ioctl(td, (struct ioctl_args *)args)); 744 break; 745 746 case LINUX_TIOCMBIC: 747 args->cmd = TIOCMBIC; 748 error = (ioctl(td, (struct ioctl_args *)args)); 749 break; 750 751 case LINUX_TIOCMSET: 752 args->cmd = TIOCMSET; 753 error = (ioctl(td, (struct ioctl_args *)args)); 754 break; 755 756 /* TIOCGSOFTCAR */ 757 /* TIOCSSOFTCAR */ 758 759 case LINUX_FIONREAD: /* LINUX_TIOCINQ */ 760 args->cmd = FIONREAD; 761 error = (ioctl(td, (struct ioctl_args *)args)); 762 break; 763 764 /* LINUX_TIOCLINUX */ 765 766 case LINUX_TIOCCONS: 767 args->cmd = TIOCCONS; 768 error = (ioctl(td, (struct ioctl_args *)args)); 769 break; 770 771 case LINUX_TIOCGSERIAL: { 772 struct linux_serial_struct lss; 773 lss.type = LINUX_PORT_16550A; 774 lss.flags = 0; 775 lss.close_delay = 0; 776 error = copyout(&lss, (caddr_t)args->arg, sizeof(lss)); 777 break; 778 } 779 780 case LINUX_TIOCSSERIAL: { 781 struct linux_serial_struct lss; 782 error = copyin((caddr_t)args->arg, &lss, sizeof(lss)); 783 if (error) 784 break; 785 /* XXX - It really helps to have an implementation that 786 * does nothing. NOT! 787 */ 788 error = 0; 789 break; 790 } 791 792 /* LINUX_TIOCPKT */ 793 794 case LINUX_FIONBIO: 795 args->cmd = FIONBIO; 796 error = (ioctl(td, (struct ioctl_args *)args)); 797 break; 798 799 case LINUX_TIOCNOTTY: 800 args->cmd = TIOCNOTTY; 801 error = (ioctl(td, (struct ioctl_args *)args)); 802 break; 803 804 case LINUX_TIOCSETD: { 805 int line; 806 switch (args->arg) { 807 case LINUX_N_TTY: 808 line = TTYDISC; 809 break; 810 case LINUX_N_SLIP: 811 line = SLIPDISC; 812 break; 813 case LINUX_N_PPP: 814 line = PPPDISC; 815 break; 816 default: 817 fdrop(fp, td); 818 return (EINVAL); 819 } 820 error = (fo_ioctl(fp, TIOCSETD, (caddr_t)&line, td->td_ucred, 821 td)); 822 break; 823 } 824 825 case LINUX_TIOCGETD: { 826 int linux_line; 827 int bsd_line = TTYDISC; 828 error = fo_ioctl(fp, TIOCGETD, (caddr_t)&bsd_line, 829 td->td_ucred, td); 830 if (error) 831 return (error); 832 switch (bsd_line) { 833 case TTYDISC: 834 linux_line = LINUX_N_TTY; 835 break; 836 case SLIPDISC: 837 linux_line = LINUX_N_SLIP; 838 break; 839 case PPPDISC: 840 linux_line = LINUX_N_PPP; 841 break; 842 default: 843 fdrop(fp, td); 844 return (EINVAL); 845 } 846 error = (copyout(&linux_line, (caddr_t)args->arg, sizeof(int))); 847 break; 848 } 849 850 /* LINUX_TCSBRKP */ 851 /* LINUX_TIOCTTYGSTRUCT */ 852 853 case LINUX_FIONCLEX: 854 args->cmd = FIONCLEX; 855 error = (ioctl(td, (struct ioctl_args *)args)); 856 break; 857 858 case LINUX_FIOCLEX: 859 args->cmd = FIOCLEX; 860 error = (ioctl(td, (struct ioctl_args *)args)); 861 break; 862 863 case LINUX_FIOASYNC: 864 args->cmd = FIOASYNC; 865 error = (ioctl(td, (struct ioctl_args *)args)); 866 break; 867 868 /* LINUX_TIOCSERCONFIG */ 869 /* LINUX_TIOCSERGWILD */ 870 /* LINUX_TIOCSERSWILD */ 871 /* LINUX_TIOCGLCKTRMIOS */ 872 /* LINUX_TIOCSLCKTRMIOS */ 873 874 default: 875 error = ENOIOCTL; 876 break; 877 } 878 879 fdrop(fp, td); 880 return (error); 881} 882 883/* 884 * CDROM related ioctls 885 */ 886 887struct linux_cdrom_msf 888{ 889 u_char cdmsf_min0; 890 u_char cdmsf_sec0; 891 u_char cdmsf_frame0; 892 u_char cdmsf_min1; 893 u_char cdmsf_sec1; 894 u_char cdmsf_frame1; 895}; 896 897struct linux_cdrom_tochdr 898{ 899 u_char cdth_trk0; 900 u_char cdth_trk1; 901}; 902 903union linux_cdrom_addr 904{ 905 struct { 906 u_char minute; 907 u_char second; 908 u_char frame; 909 } msf; 910 int lba; 911}; 912 913struct linux_cdrom_tocentry 914{
| 490 printf("%02x ", bios->c_cc[i]); 491 printf("\n"); 492 } 493#endif 494} 495 496static void 497bsd_to_linux_termio(struct termios *bios, struct linux_termio *lio) 498{ 499 struct linux_termios lios; 500 501 bsd_to_linux_termios(bios, &lios); 502 lio->c_iflag = lios.c_iflag; 503 lio->c_oflag = lios.c_oflag; 504 lio->c_cflag = lios.c_cflag; 505 lio->c_lflag = lios.c_lflag; 506 lio->c_line = lios.c_line; 507#ifdef __alpha__ 508 lio->c_cc[LINUX__VINTR] = lios.c_cc[LINUX_VINTR]; 509 lio->c_cc[LINUX__VQUIT] = lios.c_cc[LINUX_VQUIT]; 510 lio->c_cc[LINUX__VERASE] = lios.c_cc[LINUX_VERASE]; 511 lio->c_cc[LINUX__VKILL] = lios.c_cc[LINUX_VKILL]; 512 lio->c_cc[LINUX__VEOF] = 513 lios.c_cc[(lios.c_lflag & ICANON) ? LINUX_VEOF : LINUX_VMIN]; 514 lio->c_cc[LINUX__VEOL] = 515 lios.c_cc[(lios.c_lflag & ICANON) ? LINUX_VEOL : LINUX_VTIME]; 516 lio->c_cc[LINUX__VEOL2] = lios.c_cc[LINUX_VEOL2]; 517 lio->c_cc[LINUX__VSWTC] = lios.c_cc[LINUX_VSWTC]; 518#else 519 memcpy(lio->c_cc, lios.c_cc, LINUX_NCC); 520#endif 521} 522 523static void 524linux_to_bsd_termio(struct linux_termio *lio, struct termios *bios) 525{ 526 struct linux_termios lios; 527 int i; 528 529 lios.c_iflag = lio->c_iflag; 530 lios.c_oflag = lio->c_oflag; 531 lios.c_cflag = lio->c_cflag; 532 lios.c_lflag = lio->c_lflag; 533#ifdef __alpha__ 534 for (i=0; i<LINUX_NCCS; i++) 535 lios.c_cc[i] = LINUX_POSIX_VDISABLE; 536 lios.c_cc[LINUX_VINTR] = lio->c_cc[LINUX__VINTR]; 537 lios.c_cc[LINUX_VQUIT] = lio->c_cc[LINUX__VQUIT]; 538 lios.c_cc[LINUX_VERASE] = lio->c_cc[LINUX__VERASE]; 539 lios.c_cc[LINUX_VKILL] = lio->c_cc[LINUX__VKILL]; 540 lios.c_cc[LINUX_VEOL2] = lio->c_cc[LINUX__VEOL2]; 541 lios.c_cc[LINUX_VSWTC] = lio->c_cc[LINUX__VSWTC]; 542 lios.c_cc[(lio->c_lflag & ICANON) ? LINUX_VEOF : LINUX_VMIN] = 543 lio->c_cc[LINUX__VEOF]; 544 lios.c_cc[(lio->c_lflag & ICANON) ? LINUX_VEOL : LINUX_VTIME] = 545 lio->c_cc[LINUX__VEOL]; 546#else 547 for (i=LINUX_NCC; i<LINUX_NCCS; i++) 548 lios.c_cc[i] = LINUX_POSIX_VDISABLE; 549 memcpy(lios.c_cc, lio->c_cc, LINUX_NCC); 550#endif 551 linux_to_bsd_termios(&lios, bios); 552} 553 554static int 555linux_ioctl_termio(struct thread *td, struct linux_ioctl_args *args) 556{ 557 struct termios bios; 558 struct linux_termios lios; 559 struct linux_termio lio; 560 struct file *fp; 561 int error; 562 563 if ((error = fget(td, args->fd, &fp)) != 0) 564 return (error); 565 566 switch (args->cmd & 0xffff) { 567 568 case LINUX_TCGETS: 569 error = fo_ioctl(fp, TIOCGETA, (caddr_t)&bios, td->td_ucred, 570 td); 571 if (error) 572 break; 573 bsd_to_linux_termios(&bios, &lios); 574 error = copyout(&lios, (caddr_t)args->arg, sizeof(lios)); 575 break; 576 577 case LINUX_TCSETS: 578 error = copyin((caddr_t)args->arg, &lios, sizeof(lios)); 579 if (error) 580 break; 581 linux_to_bsd_termios(&lios, &bios); 582 error = (fo_ioctl(fp, TIOCSETA, (caddr_t)&bios, td->td_ucred, 583 td)); 584 break; 585 586 case LINUX_TCSETSW: 587 error = copyin((caddr_t)args->arg, &lios, sizeof(lios)); 588 if (error) 589 break; 590 linux_to_bsd_termios(&lios, &bios); 591 error = (fo_ioctl(fp, TIOCSETAW, (caddr_t)&bios, td->td_ucred, 592 td)); 593 break; 594 595 case LINUX_TCSETSF: 596 error = copyin((caddr_t)args->arg, &lios, sizeof(lios)); 597 if (error) 598 break; 599 linux_to_bsd_termios(&lios, &bios); 600 error = (fo_ioctl(fp, TIOCSETAF, (caddr_t)&bios, td->td_ucred, 601 td)); 602 break; 603 604 case LINUX_TCGETA: 605 error = fo_ioctl(fp, TIOCGETA, (caddr_t)&bios, td->td_ucred, 606 td); 607 if (error) 608 break; 609 bsd_to_linux_termio(&bios, &lio); 610 error = (copyout(&lio, (caddr_t)args->arg, sizeof(lio))); 611 break; 612 613 case LINUX_TCSETA: 614 error = copyin((caddr_t)args->arg, &lio, sizeof(lio)); 615 if (error) 616 break; 617 linux_to_bsd_termio(&lio, &bios); 618 error = (fo_ioctl(fp, TIOCSETA, (caddr_t)&bios, td->td_ucred, 619 td)); 620 break; 621 622 case LINUX_TCSETAW: 623 error = copyin((caddr_t)args->arg, &lio, sizeof(lio)); 624 if (error) 625 break; 626 linux_to_bsd_termio(&lio, &bios); 627 error = (fo_ioctl(fp, TIOCSETAW, (caddr_t)&bios, td->td_ucred, 628 td)); 629 break; 630 631 case LINUX_TCSETAF: 632 error = copyin((caddr_t)args->arg, &lio, sizeof(lio)); 633 if (error) 634 break; 635 linux_to_bsd_termio(&lio, &bios); 636 error = (fo_ioctl(fp, TIOCSETAF, (caddr_t)&bios, td->td_ucred, 637 td)); 638 break; 639 640 /* LINUX_TCSBRK */ 641 642 case LINUX_TCXONC: { 643 switch (args->arg) { 644 case LINUX_TCOOFF: 645 args->cmd = TIOCSTOP; 646 break; 647 case LINUX_TCOON: 648 args->cmd = TIOCSTART; 649 break; 650 case LINUX_TCIOFF: 651 case LINUX_TCION: { 652 int c; 653 struct write_args wr; 654 error = fo_ioctl(fp, TIOCGETA, (caddr_t)&bios, 655 td->td_ucred, td); 656 if (error) 657 break; 658 fdrop(fp, td); 659 c = (args->arg == LINUX_TCIOFF) ? VSTOP : VSTART; 660 c = bios.c_cc[c]; 661 if (c != _POSIX_VDISABLE) { 662 wr.fd = args->fd; 663 wr.buf = &c; 664 wr.nbyte = sizeof(c); 665 return (write(td, &wr)); 666 } else 667 return (0); 668 } 669 default: 670 fdrop(fp, td); 671 return (EINVAL); 672 } 673 args->arg = 0; 674 error = (ioctl(td, (struct ioctl_args *)args)); 675 break; 676 } 677 678 case LINUX_TCFLSH: { 679 args->cmd = TIOCFLUSH; 680 switch (args->arg) { 681 case LINUX_TCIFLUSH: 682 args->arg = FREAD; 683 break; 684 case LINUX_TCOFLUSH: 685 args->arg = FWRITE; 686 break; 687 case LINUX_TCIOFLUSH: 688 args->arg = FREAD | FWRITE; 689 break; 690 default: 691 fdrop(fp, td); 692 return (EINVAL); 693 } 694 error = (ioctl(td, (struct ioctl_args *)args)); 695 break; 696 } 697 698 case LINUX_TIOCEXCL: 699 args->cmd = TIOCEXCL; 700 error = (ioctl(td, (struct ioctl_args *)args)); 701 break; 702 703 case LINUX_TIOCNXCL: 704 args->cmd = TIOCNXCL; 705 error = (ioctl(td, (struct ioctl_args *)args)); 706 break; 707 708 case LINUX_TIOCSCTTY: 709 args->cmd = TIOCSCTTY; 710 error = (ioctl(td, (struct ioctl_args *)args)); 711 break; 712 713 case LINUX_TIOCGPGRP: 714 args->cmd = TIOCGPGRP; 715 error = (ioctl(td, (struct ioctl_args *)args)); 716 break; 717 718 case LINUX_TIOCSPGRP: 719 args->cmd = TIOCSPGRP; 720 error = (ioctl(td, (struct ioctl_args *)args)); 721 break; 722 723 /* LINUX_TIOCOUTQ */ 724 /* LINUX_TIOCSTI */ 725 726 case LINUX_TIOCGWINSZ: 727 args->cmd = TIOCGWINSZ; 728 error = (ioctl(td, (struct ioctl_args *)args)); 729 break; 730 731 case LINUX_TIOCSWINSZ: 732 args->cmd = TIOCSWINSZ; 733 error = (ioctl(td, (struct ioctl_args *)args)); 734 break; 735 736 case LINUX_TIOCMGET: 737 args->cmd = TIOCMGET; 738 error = (ioctl(td, (struct ioctl_args *)args)); 739 break; 740 741 case LINUX_TIOCMBIS: 742 args->cmd = TIOCMBIS; 743 error = (ioctl(td, (struct ioctl_args *)args)); 744 break; 745 746 case LINUX_TIOCMBIC: 747 args->cmd = TIOCMBIC; 748 error = (ioctl(td, (struct ioctl_args *)args)); 749 break; 750 751 case LINUX_TIOCMSET: 752 args->cmd = TIOCMSET; 753 error = (ioctl(td, (struct ioctl_args *)args)); 754 break; 755 756 /* TIOCGSOFTCAR */ 757 /* TIOCSSOFTCAR */ 758 759 case LINUX_FIONREAD: /* LINUX_TIOCINQ */ 760 args->cmd = FIONREAD; 761 error = (ioctl(td, (struct ioctl_args *)args)); 762 break; 763 764 /* LINUX_TIOCLINUX */ 765 766 case LINUX_TIOCCONS: 767 args->cmd = TIOCCONS; 768 error = (ioctl(td, (struct ioctl_args *)args)); 769 break; 770 771 case LINUX_TIOCGSERIAL: { 772 struct linux_serial_struct lss; 773 lss.type = LINUX_PORT_16550A; 774 lss.flags = 0; 775 lss.close_delay = 0; 776 error = copyout(&lss, (caddr_t)args->arg, sizeof(lss)); 777 break; 778 } 779 780 case LINUX_TIOCSSERIAL: { 781 struct linux_serial_struct lss; 782 error = copyin((caddr_t)args->arg, &lss, sizeof(lss)); 783 if (error) 784 break; 785 /* XXX - It really helps to have an implementation that 786 * does nothing. NOT! 787 */ 788 error = 0; 789 break; 790 } 791 792 /* LINUX_TIOCPKT */ 793 794 case LINUX_FIONBIO: 795 args->cmd = FIONBIO; 796 error = (ioctl(td, (struct ioctl_args *)args)); 797 break; 798 799 case LINUX_TIOCNOTTY: 800 args->cmd = TIOCNOTTY; 801 error = (ioctl(td, (struct ioctl_args *)args)); 802 break; 803 804 case LINUX_TIOCSETD: { 805 int line; 806 switch (args->arg) { 807 case LINUX_N_TTY: 808 line = TTYDISC; 809 break; 810 case LINUX_N_SLIP: 811 line = SLIPDISC; 812 break; 813 case LINUX_N_PPP: 814 line = PPPDISC; 815 break; 816 default: 817 fdrop(fp, td); 818 return (EINVAL); 819 } 820 error = (fo_ioctl(fp, TIOCSETD, (caddr_t)&line, td->td_ucred, 821 td)); 822 break; 823 } 824 825 case LINUX_TIOCGETD: { 826 int linux_line; 827 int bsd_line = TTYDISC; 828 error = fo_ioctl(fp, TIOCGETD, (caddr_t)&bsd_line, 829 td->td_ucred, td); 830 if (error) 831 return (error); 832 switch (bsd_line) { 833 case TTYDISC: 834 linux_line = LINUX_N_TTY; 835 break; 836 case SLIPDISC: 837 linux_line = LINUX_N_SLIP; 838 break; 839 case PPPDISC: 840 linux_line = LINUX_N_PPP; 841 break; 842 default: 843 fdrop(fp, td); 844 return (EINVAL); 845 } 846 error = (copyout(&linux_line, (caddr_t)args->arg, sizeof(int))); 847 break; 848 } 849 850 /* LINUX_TCSBRKP */ 851 /* LINUX_TIOCTTYGSTRUCT */ 852 853 case LINUX_FIONCLEX: 854 args->cmd = FIONCLEX; 855 error = (ioctl(td, (struct ioctl_args *)args)); 856 break; 857 858 case LINUX_FIOCLEX: 859 args->cmd = FIOCLEX; 860 error = (ioctl(td, (struct ioctl_args *)args)); 861 break; 862 863 case LINUX_FIOASYNC: 864 args->cmd = FIOASYNC; 865 error = (ioctl(td, (struct ioctl_args *)args)); 866 break; 867 868 /* LINUX_TIOCSERCONFIG */ 869 /* LINUX_TIOCSERGWILD */ 870 /* LINUX_TIOCSERSWILD */ 871 /* LINUX_TIOCGLCKTRMIOS */ 872 /* LINUX_TIOCSLCKTRMIOS */ 873 874 default: 875 error = ENOIOCTL; 876 break; 877 } 878 879 fdrop(fp, td); 880 return (error); 881} 882 883/* 884 * CDROM related ioctls 885 */ 886 887struct linux_cdrom_msf 888{ 889 u_char cdmsf_min0; 890 u_char cdmsf_sec0; 891 u_char cdmsf_frame0; 892 u_char cdmsf_min1; 893 u_char cdmsf_sec1; 894 u_char cdmsf_frame1; 895}; 896 897struct linux_cdrom_tochdr 898{ 899 u_char cdth_trk0; 900 u_char cdth_trk1; 901}; 902 903union linux_cdrom_addr 904{ 905 struct { 906 u_char minute; 907 u_char second; 908 u_char frame; 909 } msf; 910 int lba; 911}; 912 913struct linux_cdrom_tocentry 914{
|
915 u_char cdte_track;
| 915 u_char cdte_track;
|
916 u_char cdte_adr:4; 917 u_char cdte_ctrl:4;
| 916 u_char cdte_adr:4; 917 u_char cdte_ctrl:4;
|
918 u_char cdte_format;
| 918 u_char cdte_format;
|
919 union linux_cdrom_addr cdte_addr;
| 919 union linux_cdrom_addr cdte_addr;
|
920 u_char cdte_datamode;
| 920 u_char cdte_datamode;
|
921}; 922 923struct linux_cdrom_subchnl 924{ 925 u_char cdsc_format; 926 u_char cdsc_audiostatus; 927 u_char cdsc_adr:4; 928 u_char cdsc_ctrl:4; 929 u_char cdsc_trk; 930 u_char cdsc_ind; 931 union linux_cdrom_addr cdsc_absaddr; 932 union linux_cdrom_addr cdsc_reladdr; 933}; 934 935struct l_cdrom_read_audio { 936 union linux_cdrom_addr addr; 937 u_char addr_format; 938 l_int nframes; 939 u_char *buf; 940}; 941 942struct l_dvd_layer { 943 u_char book_version:4; 944 u_char book_type:4; 945 u_char min_rate:4; 946 u_char disc_size:4; 947 u_char layer_type:4; 948 u_char track_path:1; 949 u_char nlayers:2; 950 u_char track_density:4; 951 u_char linear_density:4; 952 u_char bca:1; 953 u_int32_t start_sector; 954 u_int32_t end_sector; 955 u_int32_t end_sector_l0; 956}; 957 958struct l_dvd_physical { 959 u_char type; 960 u_char layer_num; 961 struct l_dvd_layer layer[4]; 962}; 963 964struct l_dvd_copyright { 965 u_char type; 966 u_char layer_num; 967 u_char cpst; 968 u_char rmi; 969}; 970 971struct l_dvd_disckey { 972 u_char type; 973 l_uint agid:2; 974 u_char value[2048]; 975}; 976 977struct l_dvd_bca { 978 u_char type; 979 l_int len; 980 u_char value[188]; 981}; 982 983struct l_dvd_manufact { 984 u_char type; 985 u_char layer_num; 986 l_int len; 987 u_char value[2048]; 988}; 989 990typedef union { 991 u_char type; 992 struct l_dvd_physical physical; 993 struct l_dvd_copyright copyright; 994 struct l_dvd_disckey disckey; 995 struct l_dvd_bca bca; 996 struct l_dvd_manufact manufact; 997} l_dvd_struct; 998 999typedef u_char l_dvd_key[5]; 1000typedef u_char l_dvd_challenge[10]; 1001 1002struct l_dvd_lu_send_agid { 1003 u_char type; 1004 l_uint agid:2; 1005}; 1006 1007struct l_dvd_host_send_challenge { 1008 u_char type; 1009 l_uint agid:2; 1010 l_dvd_challenge chal; 1011}; 1012 1013struct l_dvd_send_key { 1014 u_char type; 1015 l_uint agid:2; 1016 l_dvd_key key; 1017}; 1018 1019struct l_dvd_lu_send_challenge { 1020 u_char type; 1021 l_uint agid:2; 1022 l_dvd_challenge chal; 1023}; 1024 1025struct l_dvd_lu_send_title_key { 1026 u_char type; 1027 l_uint agid:2; 1028 l_dvd_key title_key; 1029 l_int lba; 1030 l_uint cpm:1; 1031 l_uint cp_sec:1; 1032 l_uint cgms:2; 1033}; 1034 1035struct l_dvd_lu_send_asf { 1036 u_char type; 1037 l_uint agid:2; 1038 l_uint asf:1; 1039}; 1040 1041struct l_dvd_host_send_rpcstate { 1042 u_char type; 1043 u_char pdrc; 1044}; 1045 1046struct l_dvd_lu_send_rpcstate { 1047 u_char type:2; 1048 u_char vra:3; 1049 u_char ucca:3; 1050 u_char region_mask; 1051 u_char rpc_scheme; 1052}; 1053 1054typedef union { 1055 u_char type; 1056 struct l_dvd_lu_send_agid lsa; 1057 struct l_dvd_host_send_challenge hsc; 1058 struct l_dvd_send_key lsk; 1059 struct l_dvd_lu_send_challenge lsc; 1060 struct l_dvd_send_key hsk; 1061 struct l_dvd_lu_send_title_key lstk; 1062 struct l_dvd_lu_send_asf lsasf; 1063 struct l_dvd_host_send_rpcstate hrpcs; 1064 struct l_dvd_lu_send_rpcstate lrpcs; 1065} l_dvd_authinfo; 1066 1067static void 1068bsd_to_linux_msf_lba(u_char af, union msf_lba *bp, union linux_cdrom_addr *lp) 1069{ 1070 if (af == CD_LBA_FORMAT) 1071 lp->lba = bp->lba; 1072 else { 1073 lp->msf.minute = bp->msf.minute; 1074 lp->msf.second = bp->msf.second; 1075 lp->msf.frame = bp->msf.frame; 1076 } 1077} 1078 1079static void 1080linux_to_bsd_msf_lba(u_char af, union linux_cdrom_addr *lp, union msf_lba *bp) 1081{ 1082 if (af == CD_LBA_FORMAT) 1083 bp->lba = lp->lba; 1084 else { 1085 bp->msf.minute = lp->msf.minute; 1086 bp->msf.second = lp->msf.second; 1087 bp->msf.frame = lp->msf.frame; 1088 } 1089} 1090 1091static void 1092set_linux_cdrom_addr(union linux_cdrom_addr *addr, int format, int lba) 1093{ 1094 if (format == LINUX_CDROM_MSF) { 1095 addr->msf.frame = lba % 75; 1096 lba /= 75; 1097 lba += 2; 1098 addr->msf.second = lba % 60; 1099 addr->msf.minute = lba / 60; 1100 } else 1101 addr->lba = lba; 1102} 1103 1104static int 1105linux_to_bsd_dvd_struct(l_dvd_struct *lp, struct dvd_struct *bp) 1106{ 1107 bp->format = lp->type; 1108 switch (bp->format) { 1109 case DVD_STRUCT_PHYSICAL: 1110 if (bp->layer_num >= 4) 1111 return (EINVAL); 1112 bp->layer_num = lp->physical.layer_num; 1113 break; 1114 case DVD_STRUCT_COPYRIGHT: 1115 bp->layer_num = lp->copyright.layer_num; 1116 break; 1117 case DVD_STRUCT_DISCKEY: 1118 bp->agid = lp->disckey.agid; 1119 break; 1120 case DVD_STRUCT_BCA: 1121 case DVD_STRUCT_MANUFACT: 1122 break; 1123 default: 1124 return (EINVAL); 1125 } 1126 return (0); 1127} 1128 1129static int 1130bsd_to_linux_dvd_struct(struct dvd_struct *bp, l_dvd_struct *lp) 1131{ 1132 switch (bp->format) { 1133 case DVD_STRUCT_PHYSICAL: { 1134 struct dvd_layer *blp = (struct dvd_layer *)bp->data; 1135 struct l_dvd_layer *llp = &lp->physical.layer[bp->layer_num]; 1136 memset(llp, 0, sizeof(*llp)); 1137 llp->book_version = blp->book_version; 1138 llp->book_type = blp->book_type; 1139 llp->min_rate = blp->max_rate; 1140 llp->disc_size = blp->disc_size; 1141 llp->layer_type = blp->layer_type; 1142 llp->track_path = blp->track_path; 1143 llp->nlayers = blp->nlayers; 1144 llp->track_density = blp->track_density; 1145 llp->linear_density = blp->linear_density; 1146 llp->bca = blp->bca; 1147 llp->start_sector = blp->start_sector; 1148 llp->end_sector = blp->end_sector; 1149 llp->end_sector_l0 = blp->end_sector_l0; 1150 break; 1151 } 1152 case DVD_STRUCT_COPYRIGHT: 1153 lp->copyright.cpst = bp->cpst; 1154 lp->copyright.rmi = bp->rmi; 1155 break; 1156 case DVD_STRUCT_DISCKEY: 1157 memcpy(lp->disckey.value, bp->data, sizeof(lp->disckey.value)); 1158 break; 1159 case DVD_STRUCT_BCA: 1160 lp->bca.len = bp->length; 1161 memcpy(lp->bca.value, bp->data, sizeof(lp->bca.value)); 1162 break; 1163 case DVD_STRUCT_MANUFACT: 1164 lp->manufact.len = bp->length; 1165 memcpy(lp->manufact.value, bp->data, 1166 sizeof(lp->manufact.value)); 1167 /* lp->manufact.layer_num is unused in linux (redhat 7.0) */ 1168 break; 1169 default: 1170 return (EINVAL); 1171 } 1172 return (0); 1173} 1174 1175static int 1176linux_to_bsd_dvd_authinfo(l_dvd_authinfo *lp, int *bcode, 1177 struct dvd_authinfo *bp) 1178{ 1179 switch (lp->type) { 1180 case LINUX_DVD_LU_SEND_AGID: 1181 *bcode = DVDIOCREPORTKEY; 1182 bp->format = DVD_REPORT_AGID; 1183 bp->agid = lp->lsa.agid; 1184 break; 1185 case LINUX_DVD_HOST_SEND_CHALLENGE: 1186 *bcode = DVDIOCSENDKEY; 1187 bp->format = DVD_SEND_CHALLENGE; 1188 bp->agid = lp->hsc.agid; 1189 memcpy(bp->keychal, lp->hsc.chal, 10); 1190 break; 1191 case LINUX_DVD_LU_SEND_KEY1: 1192 *bcode = DVDIOCREPORTKEY; 1193 bp->format = DVD_REPORT_KEY1; 1194 bp->agid = lp->lsk.agid; 1195 break; 1196 case LINUX_DVD_LU_SEND_CHALLENGE: 1197 *bcode = DVDIOCREPORTKEY; 1198 bp->format = DVD_REPORT_CHALLENGE; 1199 bp->agid = lp->lsc.agid; 1200 break; 1201 case LINUX_DVD_HOST_SEND_KEY2: 1202 *bcode = DVDIOCSENDKEY; 1203 bp->format = DVD_SEND_KEY2; 1204 bp->agid = lp->hsk.agid; 1205 memcpy(bp->keychal, lp->hsk.key, 5); 1206 break; 1207 case LINUX_DVD_LU_SEND_TITLE_KEY: 1208 *bcode = DVDIOCREPORTKEY; 1209 bp->format = DVD_REPORT_TITLE_KEY; 1210 bp->agid = lp->lstk.agid; 1211 bp->lba = lp->lstk.lba; 1212 break; 1213 case LINUX_DVD_LU_SEND_ASF: 1214 *bcode = DVDIOCREPORTKEY; 1215 bp->format = DVD_REPORT_ASF; 1216 bp->agid = lp->lsasf.agid; 1217 break; 1218 case LINUX_DVD_INVALIDATE_AGID: 1219 *bcode = DVDIOCREPORTKEY; 1220 bp->format = DVD_INVALIDATE_AGID; 1221 bp->agid = lp->lsa.agid; 1222 break; 1223 case LINUX_DVD_LU_SEND_RPC_STATE: 1224 *bcode = DVDIOCREPORTKEY; 1225 bp->format = DVD_REPORT_RPC; 1226 break; 1227 case LINUX_DVD_HOST_SEND_RPC_STATE: 1228 *bcode = DVDIOCSENDKEY; 1229 bp->format = DVD_SEND_RPC; 1230 bp->region = lp->hrpcs.pdrc; 1231 break; 1232 default: 1233 return (EINVAL); 1234 } 1235 return (0); 1236} 1237 1238static int 1239bsd_to_linux_dvd_authinfo(struct dvd_authinfo *bp, l_dvd_authinfo *lp) 1240{ 1241 switch (lp->type) { 1242 case LINUX_DVD_LU_SEND_AGID: 1243 lp->lsa.agid = bp->agid; 1244 break; 1245 case LINUX_DVD_HOST_SEND_CHALLENGE: 1246 lp->type = LINUX_DVD_LU_SEND_KEY1; 1247 break; 1248 case LINUX_DVD_LU_SEND_KEY1: 1249 memcpy(lp->lsk.key, bp->keychal, sizeof(lp->lsk.key)); 1250 break; 1251 case LINUX_DVD_LU_SEND_CHALLENGE: 1252 memcpy(lp->lsc.chal, bp->keychal, sizeof(lp->lsc.chal)); 1253 break; 1254 case LINUX_DVD_HOST_SEND_KEY2: 1255 lp->type = LINUX_DVD_AUTH_ESTABLISHED; 1256 break; 1257 case LINUX_DVD_LU_SEND_TITLE_KEY: 1258 memcpy(lp->lstk.title_key, bp->keychal, 1259 sizeof(lp->lstk.title_key)); 1260 lp->lstk.cpm = bp->cpm; 1261 lp->lstk.cp_sec = bp->cp_sec; 1262 lp->lstk.cgms = bp->cgms; 1263 break; 1264 case LINUX_DVD_LU_SEND_ASF: 1265 lp->lsasf.asf = bp->asf; 1266 break; 1267 case LINUX_DVD_INVALIDATE_AGID: 1268 break; 1269 case LINUX_DVD_LU_SEND_RPC_STATE: 1270 lp->lrpcs.type = bp->reg_type; 1271 lp->lrpcs.vra = bp->vend_rsts; 1272 lp->lrpcs.ucca = bp->user_rsts; 1273 lp->lrpcs.region_mask = bp->region; 1274 lp->lrpcs.rpc_scheme = bp->rpc_scheme; 1275 break; 1276 case LINUX_DVD_HOST_SEND_RPC_STATE: 1277 break; 1278 default: 1279 return (EINVAL); 1280 } 1281 return (0); 1282} 1283 1284static int 1285linux_ioctl_cdrom(struct thread *td, struct linux_ioctl_args *args) 1286{ 1287 struct file *fp; 1288 int error; 1289 1290 if ((error = fget(td, args->fd, &fp)) != 0) 1291 return (error); 1292 switch (args->cmd & 0xffff) { 1293 1294 case LINUX_CDROMPAUSE: 1295 args->cmd = CDIOCPAUSE; 1296 error = (ioctl(td, (struct ioctl_args *)args)); 1297 break; 1298 1299 case LINUX_CDROMRESUME: 1300 args->cmd = CDIOCRESUME; 1301 error = (ioctl(td, (struct ioctl_args *)args)); 1302 break; 1303 1304 case LINUX_CDROMPLAYMSF: 1305 args->cmd = CDIOCPLAYMSF; 1306 error = (ioctl(td, (struct ioctl_args *)args)); 1307 break; 1308 1309 case LINUX_CDROMPLAYTRKIND: 1310 args->cmd = CDIOCPLAYTRACKS; 1311 error = (ioctl(td, (struct ioctl_args *)args)); 1312 break; 1313 1314 case LINUX_CDROMREADTOCHDR: { 1315 struct ioc_toc_header th; 1316 struct linux_cdrom_tochdr lth; 1317 error = fo_ioctl(fp, CDIOREADTOCHEADER, (caddr_t)&th, 1318 td->td_ucred, td); 1319 if (!error) { 1320 lth.cdth_trk0 = th.starting_track; 1321 lth.cdth_trk1 = th.ending_track; 1322 copyout(<h, (caddr_t)args->arg, sizeof(lth)); 1323 } 1324 break; 1325 } 1326 1327 case LINUX_CDROMREADTOCENTRY: { 1328 struct linux_cdrom_tocentry lte, *ltep = 1329 (struct linux_cdrom_tocentry *)args->arg; 1330 struct ioc_read_toc_single_entry irtse; 1331 irtse.address_format = ltep->cdte_format; 1332 irtse.track = ltep->cdte_track; 1333 error = fo_ioctl(fp, CDIOREADTOCENTRY, (caddr_t)&irtse, 1334 td->td_ucred, td); 1335 if (!error) { 1336 lte = *ltep; 1337 lte.cdte_ctrl = irtse.entry.control; 1338 lte.cdte_adr = irtse.entry.addr_type; 1339 bsd_to_linux_msf_lba(irtse.address_format, 1340 &irtse.entry.addr, <e.cdte_addr); 1341 copyout(<e, (caddr_t)args->arg, sizeof(lte)); 1342 } 1343 break; 1344 } 1345 1346 case LINUX_CDROMSTOP: 1347 args->cmd = CDIOCSTOP; 1348 error = (ioctl(td, (struct ioctl_args *)args)); 1349 break; 1350 1351 case LINUX_CDROMSTART: 1352 args->cmd = CDIOCSTART; 1353 error = (ioctl(td, (struct ioctl_args *)args)); 1354 break; 1355 1356 case LINUX_CDROMEJECT: 1357 args->cmd = CDIOCEJECT; 1358 error = (ioctl(td, (struct ioctl_args *)args)); 1359 break; 1360 1361 /* LINUX_CDROMVOLCTRL */ 1362 1363 case LINUX_CDROMSUBCHNL: { 1364 struct linux_cdrom_subchnl sc; 1365 struct ioc_read_subchannel bsdsc; 1366 struct cd_sub_channel_info *bsdinfo; 1367 caddr_t sg = stackgap_init(); 1368 bsdinfo = (struct cd_sub_channel_info*)stackgap_alloc(&sg, 1369 sizeof(struct cd_sub_channel_info)); 1370 bsdsc.address_format = CD_LBA_FORMAT; 1371 bsdsc.data_format = CD_CURRENT_POSITION; 1372 bsdsc.track = 0; 1373 bsdsc.data_len = sizeof(struct cd_sub_channel_info); 1374 bsdsc.data = bsdinfo; 1375 error = fo_ioctl(fp, CDIOCREADSUBCHANNEL, (caddr_t)&bsdsc, 1376 td->td_ucred, td); 1377 if (error) 1378 break; 1379 error = copyin((caddr_t)args->arg, &sc, 1380 sizeof(struct linux_cdrom_subchnl)); 1381 if (error) 1382 break; 1383 sc.cdsc_audiostatus = bsdinfo->header.audio_status; 1384 sc.cdsc_adr = bsdinfo->what.position.addr_type; 1385 sc.cdsc_ctrl = bsdinfo->what.position.control; 1386 sc.cdsc_trk = bsdinfo->what.position.track_number; 1387 sc.cdsc_ind = bsdinfo->what.position.index_number; 1388 set_linux_cdrom_addr(&sc.cdsc_absaddr, sc.cdsc_format, 1389 bsdinfo->what.position.absaddr.lba); 1390 set_linux_cdrom_addr(&sc.cdsc_reladdr, sc.cdsc_format, 1391 bsdinfo->what.position.reladdr.lba); 1392 error = copyout(&sc, (caddr_t)args->arg, 1393 sizeof(struct linux_cdrom_subchnl)); 1394 break; 1395 } 1396 1397 /* LINUX_CDROMREADMODE2 */ 1398 /* LINUX_CDROMREADMODE1 */ 1399 1400 case LINUX_CDROMREADAUDIO: { 1401 struct l_cdrom_read_audio lra; 1402 struct ioc_read_audio bra; 1403 1404 error = copyin((caddr_t)args->arg, &lra, sizeof(lra)); 1405 if (error) 1406 break; 1407 bra.address_format = lra.addr_format; 1408 linux_to_bsd_msf_lba(bra.address_format, &lra.addr, 1409 &bra.address); 1410 bra.nframes = lra.nframes; 1411 bra.buffer = lra.buf; 1412 error = fo_ioctl(fp, CDIOCREADAUDIO, (caddr_t)&bra, 1413 td->td_ucred, td); 1414 break; 1415 } 1416 1417 /* LINUX_CDROMEJECT_SW */ 1418 /* LINUX_CDROMMULTISESSION */ 1419 /* LINUX_CDROM_GET_UPC */ 1420 1421 case LINUX_CDROMRESET: 1422 args->cmd = CDIOCRESET; 1423 error = (ioctl(td, (struct ioctl_args *)args)); 1424 break; 1425 1426 /* LINUX_CDROMVOLREAD */ 1427 /* LINUX_CDROMREADRAW */ 1428 /* LINUX_CDROMREADCOOKED */ 1429 /* LINUX_CDROMSEEK */ 1430 /* LINUX_CDROMPLAYBLK */ 1431 /* LINUX_CDROMREADALL */ 1432 /* LINUX_CDROMCLOSETRAY */ 1433 /* LINUX_CDROMLOADFROMSLOT */ 1434 /* LINUX_CDROMGETSPINDOWN */ 1435 /* LINUX_CDROMSETSPINDOWN */ 1436 /* LINUX_CDROM_SET_OPTIONS */ 1437 /* LINUX_CDROM_CLEAR_OPTIONS */ 1438 /* LINUX_CDROM_SELECT_SPEED */ 1439 /* LINUX_CDROM_SELECT_DISC */ 1440 /* LINUX_CDROM_MEDIA_CHANGED */ 1441 /* LINUX_CDROM_DRIVE_STATUS */ 1442 /* LINUX_CDROM_DISC_STATUS */ 1443 /* LINUX_CDROM_CHANGER_NSLOTS */ 1444 /* LINUX_CDROM_LOCKDOOR */ 1445 /* LINUX_CDROM_DEBUG */ 1446 /* LINUX_CDROM_GET_CAPABILITY */ 1447 /* LINUX_CDROMAUDIOBUFSIZ */ 1448 1449 case LINUX_DVD_READ_STRUCT: { 1450 l_dvd_struct lds; 1451 struct dvd_struct bds; 1452 1453 error = copyin((caddr_t)args->arg, &lds, sizeof(l_dvd_struct)); 1454 if (error) 1455 break; 1456 error = linux_to_bsd_dvd_struct(&lds, &bds); 1457 if (error) 1458 break; 1459 error = fo_ioctl(fp, DVDIOCREADSTRUCTURE, (caddr_t)&bds, 1460 td->td_ucred, td); 1461 if (error) 1462 break; 1463 error = bsd_to_linux_dvd_struct(&bds, &lds); 1464 if (error) 1465 break; 1466 error = copyout(&lds, (caddr_t)args->arg, 1467 sizeof(l_dvd_struct)); 1468 break; 1469 } 1470 1471 /* LINUX_DVD_WRITE_STRUCT */ 1472 1473 case LINUX_DVD_AUTH: { 1474 l_dvd_authinfo lda; 1475 struct dvd_authinfo bda; 1476 int bcode; 1477 1478 error = copyin((caddr_t)args->arg, &lda, 1479 sizeof(l_dvd_authinfo)); 1480 if (error) 1481 break; 1482 error = linux_to_bsd_dvd_authinfo(&lda, &bcode, &bda); 1483 if (error) 1484 break; 1485 error = fo_ioctl(fp, bcode, (caddr_t)&bda, td->td_ucred, 1486 td); 1487 if (error) { 1488 if (lda.type == LINUX_DVD_HOST_SEND_KEY2) { 1489 lda.type = LINUX_DVD_AUTH_FAILURE; 1490 copyout(&lda, (caddr_t)args->arg, 1491 sizeof(l_dvd_authinfo)); 1492 } 1493 break; 1494 } 1495 error = bsd_to_linux_dvd_authinfo(&bda, &lda); 1496 if (error) 1497 break; 1498 error = copyout(&lda, (caddr_t)args->arg, 1499 sizeof(l_dvd_authinfo)); 1500 break; 1501 } 1502 1503 /* LINUX_CDROM_SEND_PACKET */ 1504 /* LINUX_CDROM_NEXT_WRITABLE */ 1505 /* LINUX_CDROM_LAST_WRITTEN */ 1506 1507 default: 1508 error = ENOIOCTL; 1509 break; 1510 } 1511 1512 fdrop(fp, td); 1513 return (error); 1514} 1515 1516static int 1517linux_ioctl_vfat(struct thread *td, struct linux_ioctl_args *args) 1518{ 1519 1520 return (ENOTTY); 1521} 1522 1523/* 1524 * Sound related ioctls 1525 */ 1526 1527static u_int32_t dirbits[4] = { IOC_VOID, IOC_IN, IOC_OUT, IOC_INOUT }; 1528 1529#define SETDIR(c) (((c) & ~IOC_DIRMASK) | dirbits[args->cmd >> 30]) 1530 1531static int 1532linux_ioctl_sound(struct thread *td, struct linux_ioctl_args *args) 1533{ 1534 1535 switch (args->cmd & 0xffff) { 1536 1537 case LINUX_SOUND_MIXER_WRITE_VOLUME: 1538 args->cmd = SETDIR(SOUND_MIXER_WRITE_VOLUME); 1539 return (ioctl(td, (struct ioctl_args *)args)); 1540 1541 case LINUX_SOUND_MIXER_WRITE_BASS: 1542 args->cmd = SETDIR(SOUND_MIXER_WRITE_BASS); 1543 return (ioctl(td, (struct ioctl_args *)args)); 1544 1545 case LINUX_SOUND_MIXER_WRITE_TREBLE: 1546 args->cmd = SETDIR(SOUND_MIXER_WRITE_TREBLE); 1547 return (ioctl(td, (struct ioctl_args *)args)); 1548 1549 case LINUX_SOUND_MIXER_WRITE_SYNTH: 1550 args->cmd = SETDIR(SOUND_MIXER_WRITE_SYNTH); 1551 return (ioctl(td, (struct ioctl_args *)args)); 1552 1553 case LINUX_SOUND_MIXER_WRITE_PCM: 1554 args->cmd = SETDIR(SOUND_MIXER_WRITE_PCM); 1555 return (ioctl(td, (struct ioctl_args *)args)); 1556 1557 case LINUX_SOUND_MIXER_WRITE_SPEAKER: 1558 args->cmd = SETDIR(SOUND_MIXER_WRITE_SPEAKER); 1559 return (ioctl(td, (struct ioctl_args *)args)); 1560 1561 case LINUX_SOUND_MIXER_WRITE_LINE: 1562 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE); 1563 return (ioctl(td, (struct ioctl_args *)args)); 1564 1565 case LINUX_SOUND_MIXER_WRITE_MIC: 1566 args->cmd = SETDIR(SOUND_MIXER_WRITE_MIC); 1567 return (ioctl(td, (struct ioctl_args *)args)); 1568 1569 case LINUX_SOUND_MIXER_WRITE_CD: 1570 args->cmd = SETDIR(SOUND_MIXER_WRITE_CD); 1571 return (ioctl(td, (struct ioctl_args *)args)); 1572 1573 case LINUX_SOUND_MIXER_WRITE_IMIX: 1574 args->cmd = SETDIR(SOUND_MIXER_WRITE_IMIX); 1575 return (ioctl(td, (struct ioctl_args *)args)); 1576 1577 case LINUX_SOUND_MIXER_WRITE_ALTPCM: 1578 args->cmd = SETDIR(SOUND_MIXER_WRITE_ALTPCM); 1579 return (ioctl(td, (struct ioctl_args *)args)); 1580 1581 case LINUX_SOUND_MIXER_WRITE_RECLEV: 1582 args->cmd = SETDIR(SOUND_MIXER_WRITE_RECLEV); 1583 return (ioctl(td, (struct ioctl_args *)args)); 1584 1585 case LINUX_SOUND_MIXER_WRITE_IGAIN: 1586 args->cmd = SETDIR(SOUND_MIXER_WRITE_IGAIN); 1587 return (ioctl(td, (struct ioctl_args *)args)); 1588 1589 case LINUX_SOUND_MIXER_WRITE_OGAIN: 1590 args->cmd = SETDIR(SOUND_MIXER_WRITE_OGAIN); 1591 return (ioctl(td, (struct ioctl_args *)args)); 1592 1593 case LINUX_SOUND_MIXER_WRITE_LINE1: 1594 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE1); 1595 return (ioctl(td, (struct ioctl_args *)args)); 1596 1597 case LINUX_SOUND_MIXER_WRITE_LINE2: 1598 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE2); 1599 return (ioctl(td, (struct ioctl_args *)args)); 1600 1601 case LINUX_SOUND_MIXER_WRITE_LINE3: 1602 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE3); 1603 return (ioctl(td, (struct ioctl_args *)args)); 1604 1605 case LINUX_OSS_GETVERSION: { 1606 int version = linux_get_oss_version(td->td_proc); 1607 return (copyout(&version, (caddr_t)args->arg, sizeof(int))); 1608 } 1609 1610 case LINUX_SOUND_MIXER_READ_STEREODEVS: 1611 args->cmd = SOUND_MIXER_READ_STEREODEVS; 1612 return (ioctl(td, (struct ioctl_args *)args)); 1613 1614 case LINUX_SOUND_MIXER_READ_DEVMASK: 1615 args->cmd = SOUND_MIXER_READ_DEVMASK; 1616 return (ioctl(td, (struct ioctl_args *)args)); 1617 1618 case LINUX_SOUND_MIXER_WRITE_RECSRC: 1619 args->cmd = SETDIR(SOUND_MIXER_WRITE_RECSRC); 1620 return (ioctl(td, (struct ioctl_args *)args)); 1621 1622 case LINUX_SNDCTL_DSP_RESET: 1623 args->cmd = SNDCTL_DSP_RESET; 1624 return (ioctl(td, (struct ioctl_args *)args)); 1625 1626 case LINUX_SNDCTL_DSP_SYNC: 1627 args->cmd = SNDCTL_DSP_SYNC; 1628 return (ioctl(td, (struct ioctl_args *)args)); 1629 1630 case LINUX_SNDCTL_DSP_SPEED: 1631 args->cmd = SNDCTL_DSP_SPEED; 1632 return (ioctl(td, (struct ioctl_args *)args)); 1633 1634 case LINUX_SNDCTL_DSP_STEREO: 1635 args->cmd = SNDCTL_DSP_STEREO; 1636 return (ioctl(td, (struct ioctl_args *)args)); 1637 1638 case LINUX_SNDCTL_DSP_GETBLKSIZE: /* LINUX_SNDCTL_DSP_SETBLKSIZE */ 1639 args->cmd = SNDCTL_DSP_GETBLKSIZE; 1640 return (ioctl(td, (struct ioctl_args *)args)); 1641 1642 case LINUX_SNDCTL_DSP_SETFMT: 1643 args->cmd = SNDCTL_DSP_SETFMT; 1644 return (ioctl(td, (struct ioctl_args *)args)); 1645 1646 case LINUX_SOUND_PCM_WRITE_CHANNELS: 1647 args->cmd = SOUND_PCM_WRITE_CHANNELS; 1648 return (ioctl(td, (struct ioctl_args *)args)); 1649 1650 case LINUX_SOUND_PCM_WRITE_FILTER: 1651 args->cmd = SOUND_PCM_WRITE_FILTER; 1652 return (ioctl(td, (struct ioctl_args *)args)); 1653 1654 case LINUX_SNDCTL_DSP_POST: 1655 args->cmd = SNDCTL_DSP_POST; 1656 return (ioctl(td, (struct ioctl_args *)args)); 1657 1658 case LINUX_SNDCTL_DSP_SUBDIVIDE: 1659 args->cmd = SNDCTL_DSP_SUBDIVIDE; 1660 return (ioctl(td, (struct ioctl_args *)args)); 1661 1662 case LINUX_SNDCTL_DSP_SETFRAGMENT: 1663 args->cmd = SNDCTL_DSP_SETFRAGMENT; 1664 return (ioctl(td, (struct ioctl_args *)args)); 1665 1666 case LINUX_SNDCTL_DSP_GETFMTS: 1667 args->cmd = SNDCTL_DSP_GETFMTS; 1668 return (ioctl(td, (struct ioctl_args *)args)); 1669 1670 case LINUX_SNDCTL_DSP_GETOSPACE: 1671 args->cmd = SNDCTL_DSP_GETOSPACE; 1672 return (ioctl(td, (struct ioctl_args *)args)); 1673 1674 case LINUX_SNDCTL_DSP_GETISPACE: 1675 args->cmd = SNDCTL_DSP_GETISPACE; 1676 return (ioctl(td, (struct ioctl_args *)args)); 1677 1678 case LINUX_SNDCTL_DSP_NONBLOCK: 1679 args->cmd = SNDCTL_DSP_NONBLOCK; 1680 return (ioctl(td, (struct ioctl_args *)args)); 1681 1682 case LINUX_SNDCTL_DSP_GETCAPS: 1683 args->cmd = SNDCTL_DSP_GETCAPS; 1684 return (ioctl(td, (struct ioctl_args *)args)); 1685 1686 case LINUX_SNDCTL_DSP_SETTRIGGER: /* LINUX_SNDCTL_GETTRIGGER */ 1687 args->cmd = SNDCTL_DSP_SETTRIGGER; 1688 return (ioctl(td, (struct ioctl_args *)args)); 1689 1690 case LINUX_SNDCTL_DSP_GETIPTR: 1691 args->cmd = SNDCTL_DSP_GETIPTR; 1692 return (ioctl(td, (struct ioctl_args *)args)); 1693 1694 case LINUX_SNDCTL_DSP_GETOPTR: 1695 args->cmd = SNDCTL_DSP_GETOPTR; 1696 return (ioctl(td, (struct ioctl_args *)args)); 1697 1698 case LINUX_SNDCTL_DSP_GETODELAY: 1699 args->cmd = SNDCTL_DSP_GETODELAY; 1700 return (ioctl(td, (struct ioctl_args *)args)); 1701 1702 case LINUX_SNDCTL_SEQ_RESET: 1703 args->cmd = SNDCTL_SEQ_RESET; 1704 return (ioctl(td, (struct ioctl_args *)args)); 1705 1706 case LINUX_SNDCTL_SEQ_SYNC: 1707 args->cmd = SNDCTL_SEQ_SYNC; 1708 return (ioctl(td, (struct ioctl_args *)args)); 1709 1710 case LINUX_SNDCTL_SYNTH_INFO: 1711 args->cmd = SNDCTL_SYNTH_INFO; 1712 return (ioctl(td, (struct ioctl_args *)args)); 1713 1714 case LINUX_SNDCTL_SEQ_CTRLRATE: 1715 args->cmd = SNDCTL_SEQ_CTRLRATE; 1716 return (ioctl(td, (struct ioctl_args *)args)); 1717 1718 case LINUX_SNDCTL_SEQ_GETOUTCOUNT: 1719 args->cmd = SNDCTL_SEQ_GETOUTCOUNT; 1720 return (ioctl(td, (struct ioctl_args *)args)); 1721 1722 case LINUX_SNDCTL_SEQ_GETINCOUNT: 1723 args->cmd = SNDCTL_SEQ_GETINCOUNT; 1724 return (ioctl(td, (struct ioctl_args *)args)); 1725 1726 case LINUX_SNDCTL_SEQ_PERCMODE: 1727 args->cmd = SNDCTL_SEQ_PERCMODE; 1728 return (ioctl(td, (struct ioctl_args *)args)); 1729 1730 case LINUX_SNDCTL_FM_LOAD_INSTR: 1731 args->cmd = SNDCTL_FM_LOAD_INSTR; 1732 return (ioctl(td, (struct ioctl_args *)args)); 1733 1734 case LINUX_SNDCTL_SEQ_TESTMIDI: 1735 args->cmd = SNDCTL_SEQ_TESTMIDI; 1736 return (ioctl(td, (struct ioctl_args *)args)); 1737 1738 case LINUX_SNDCTL_SEQ_RESETSAMPLES: 1739 args->cmd = SNDCTL_SEQ_RESETSAMPLES; 1740 return (ioctl(td, (struct ioctl_args *)args)); 1741 1742 case LINUX_SNDCTL_SEQ_NRSYNTHS: 1743 args->cmd = SNDCTL_SEQ_NRSYNTHS; 1744 return (ioctl(td, (struct ioctl_args *)args)); 1745 1746 case LINUX_SNDCTL_SEQ_NRMIDIS: 1747 args->cmd = SNDCTL_SEQ_NRMIDIS; 1748 return (ioctl(td, (struct ioctl_args *)args)); 1749 1750 case LINUX_SNDCTL_MIDI_INFO: 1751 args->cmd = SNDCTL_MIDI_INFO; 1752 return (ioctl(td, (struct ioctl_args *)args)); 1753 1754 case LINUX_SNDCTL_SEQ_TRESHOLD: 1755 args->cmd = SNDCTL_SEQ_TRESHOLD; 1756 return (ioctl(td, (struct ioctl_args *)args)); 1757 1758 case LINUX_SNDCTL_SYNTH_MEMAVL: 1759 args->cmd = SNDCTL_SYNTH_MEMAVL; 1760 return (ioctl(td, (struct ioctl_args *)args)); 1761 1762 } 1763 1764 return (ENOIOCTL); 1765} 1766 1767/* 1768 * Console related ioctls 1769 */ 1770 1771#define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG) 1772 1773static int 1774linux_ioctl_console(struct thread *td, struct linux_ioctl_args *args) 1775{ 1776 struct file *fp; 1777 int error; 1778 1779 if ((error = fget(td, args->fd, &fp)) != 0) 1780 return (error); 1781 switch (args->cmd & 0xffff) { 1782 1783 case LINUX_KIOCSOUND: 1784 args->cmd = KIOCSOUND; 1785 error = (ioctl(td, (struct ioctl_args *)args)); 1786 break; 1787 1788 case LINUX_KDMKTONE: 1789 args->cmd = KDMKTONE; 1790 error = (ioctl(td, (struct ioctl_args *)args)); 1791 break; 1792 1793 case LINUX_KDGETLED: 1794 args->cmd = KDGETLED; 1795 error = (ioctl(td, (struct ioctl_args *)args)); 1796 break; 1797 1798 case LINUX_KDSETLED: 1799 args->cmd = KDSETLED; 1800 error = (ioctl(td, (struct ioctl_args *)args)); 1801 break; 1802 1803 case LINUX_KDSETMODE: 1804 args->cmd = KDSETMODE; 1805 error = (ioctl(td, (struct ioctl_args *)args)); 1806 break; 1807 1808 case LINUX_KDGETMODE: 1809 args->cmd = KDGETMODE; 1810 error = (ioctl(td, (struct ioctl_args *)args)); 1811 break; 1812 1813 case LINUX_KDGKBMODE: 1814 args->cmd = KDGKBMODE; 1815 error = (ioctl(td, (struct ioctl_args *)args)); 1816 break; 1817 1818 case LINUX_KDSKBMODE: { 1819 int kbdmode; 1820 switch (args->arg) { 1821 case LINUX_KBD_RAW: 1822 kbdmode = K_RAW; 1823 break; 1824 case LINUX_KBD_XLATE: 1825 kbdmode = K_XLATE; 1826 break; 1827 case LINUX_KBD_MEDIUMRAW: 1828 kbdmode = K_RAW; 1829 break; 1830 default: 1831 fdrop(fp, td); 1832 return (EINVAL); 1833 } 1834 error = (fo_ioctl(fp, KDSKBMODE, (caddr_t)&kbdmode, 1835 td->td_ucred, td)); 1836 break; 1837 } 1838 1839 case LINUX_VT_OPENQRY: 1840 args->cmd = VT_OPENQRY; 1841 error = (ioctl(td, (struct ioctl_args *)args)); 1842 break; 1843 1844 case LINUX_VT_GETMODE: 1845 args->cmd = VT_GETMODE; 1846 error = (ioctl(td, (struct ioctl_args *)args)); 1847 break; 1848 1849 case LINUX_VT_SETMODE: { 1850 struct vt_mode *mode; 1851 args->cmd = VT_SETMODE; 1852 mode = (struct vt_mode *)args->arg; 1853 if (!ISSIGVALID(mode->frsig) && ISSIGVALID(mode->acqsig)) 1854 mode->frsig = mode->acqsig; 1855 error = (ioctl(td, (struct ioctl_args *)args)); 1856 break; 1857 } 1858 1859 case LINUX_VT_GETSTATE: 1860 args->cmd = VT_GETACTIVE; 1861 error = (ioctl(td, (struct ioctl_args *)args)); 1862 break; 1863 1864 case LINUX_VT_RELDISP: 1865 args->cmd = VT_RELDISP; 1866 error = (ioctl(td, (struct ioctl_args *)args)); 1867 break; 1868 1869 case LINUX_VT_ACTIVATE: 1870 args->cmd = VT_ACTIVATE; 1871 error = (ioctl(td, (struct ioctl_args *)args)); 1872 break; 1873 1874 case LINUX_VT_WAITACTIVE: 1875 args->cmd = VT_WAITACTIVE; 1876 error = (ioctl(td, (struct ioctl_args *)args)); 1877 break; 1878 1879 default: 1880 error = ENOIOCTL; 1881 break; 1882 }
| 921}; 922 923struct linux_cdrom_subchnl 924{ 925 u_char cdsc_format; 926 u_char cdsc_audiostatus; 927 u_char cdsc_adr:4; 928 u_char cdsc_ctrl:4; 929 u_char cdsc_trk; 930 u_char cdsc_ind; 931 union linux_cdrom_addr cdsc_absaddr; 932 union linux_cdrom_addr cdsc_reladdr; 933}; 934 935struct l_cdrom_read_audio { 936 union linux_cdrom_addr addr; 937 u_char addr_format; 938 l_int nframes; 939 u_char *buf; 940}; 941 942struct l_dvd_layer { 943 u_char book_version:4; 944 u_char book_type:4; 945 u_char min_rate:4; 946 u_char disc_size:4; 947 u_char layer_type:4; 948 u_char track_path:1; 949 u_char nlayers:2; 950 u_char track_density:4; 951 u_char linear_density:4; 952 u_char bca:1; 953 u_int32_t start_sector; 954 u_int32_t end_sector; 955 u_int32_t end_sector_l0; 956}; 957 958struct l_dvd_physical { 959 u_char type; 960 u_char layer_num; 961 struct l_dvd_layer layer[4]; 962}; 963 964struct l_dvd_copyright { 965 u_char type; 966 u_char layer_num; 967 u_char cpst; 968 u_char rmi; 969}; 970 971struct l_dvd_disckey { 972 u_char type; 973 l_uint agid:2; 974 u_char value[2048]; 975}; 976 977struct l_dvd_bca { 978 u_char type; 979 l_int len; 980 u_char value[188]; 981}; 982 983struct l_dvd_manufact { 984 u_char type; 985 u_char layer_num; 986 l_int len; 987 u_char value[2048]; 988}; 989 990typedef union { 991 u_char type; 992 struct l_dvd_physical physical; 993 struct l_dvd_copyright copyright; 994 struct l_dvd_disckey disckey; 995 struct l_dvd_bca bca; 996 struct l_dvd_manufact manufact; 997} l_dvd_struct; 998 999typedef u_char l_dvd_key[5]; 1000typedef u_char l_dvd_challenge[10]; 1001 1002struct l_dvd_lu_send_agid { 1003 u_char type; 1004 l_uint agid:2; 1005}; 1006 1007struct l_dvd_host_send_challenge { 1008 u_char type; 1009 l_uint agid:2; 1010 l_dvd_challenge chal; 1011}; 1012 1013struct l_dvd_send_key { 1014 u_char type; 1015 l_uint agid:2; 1016 l_dvd_key key; 1017}; 1018 1019struct l_dvd_lu_send_challenge { 1020 u_char type; 1021 l_uint agid:2; 1022 l_dvd_challenge chal; 1023}; 1024 1025struct l_dvd_lu_send_title_key { 1026 u_char type; 1027 l_uint agid:2; 1028 l_dvd_key title_key; 1029 l_int lba; 1030 l_uint cpm:1; 1031 l_uint cp_sec:1; 1032 l_uint cgms:2; 1033}; 1034 1035struct l_dvd_lu_send_asf { 1036 u_char type; 1037 l_uint agid:2; 1038 l_uint asf:1; 1039}; 1040 1041struct l_dvd_host_send_rpcstate { 1042 u_char type; 1043 u_char pdrc; 1044}; 1045 1046struct l_dvd_lu_send_rpcstate { 1047 u_char type:2; 1048 u_char vra:3; 1049 u_char ucca:3; 1050 u_char region_mask; 1051 u_char rpc_scheme; 1052}; 1053 1054typedef union { 1055 u_char type; 1056 struct l_dvd_lu_send_agid lsa; 1057 struct l_dvd_host_send_challenge hsc; 1058 struct l_dvd_send_key lsk; 1059 struct l_dvd_lu_send_challenge lsc; 1060 struct l_dvd_send_key hsk; 1061 struct l_dvd_lu_send_title_key lstk; 1062 struct l_dvd_lu_send_asf lsasf; 1063 struct l_dvd_host_send_rpcstate hrpcs; 1064 struct l_dvd_lu_send_rpcstate lrpcs; 1065} l_dvd_authinfo; 1066 1067static void 1068bsd_to_linux_msf_lba(u_char af, union msf_lba *bp, union linux_cdrom_addr *lp) 1069{ 1070 if (af == CD_LBA_FORMAT) 1071 lp->lba = bp->lba; 1072 else { 1073 lp->msf.minute = bp->msf.minute; 1074 lp->msf.second = bp->msf.second; 1075 lp->msf.frame = bp->msf.frame; 1076 } 1077} 1078 1079static void 1080linux_to_bsd_msf_lba(u_char af, union linux_cdrom_addr *lp, union msf_lba *bp) 1081{ 1082 if (af == CD_LBA_FORMAT) 1083 bp->lba = lp->lba; 1084 else { 1085 bp->msf.minute = lp->msf.minute; 1086 bp->msf.second = lp->msf.second; 1087 bp->msf.frame = lp->msf.frame; 1088 } 1089} 1090 1091static void 1092set_linux_cdrom_addr(union linux_cdrom_addr *addr, int format, int lba) 1093{ 1094 if (format == LINUX_CDROM_MSF) { 1095 addr->msf.frame = lba % 75; 1096 lba /= 75; 1097 lba += 2; 1098 addr->msf.second = lba % 60; 1099 addr->msf.minute = lba / 60; 1100 } else 1101 addr->lba = lba; 1102} 1103 1104static int 1105linux_to_bsd_dvd_struct(l_dvd_struct *lp, struct dvd_struct *bp) 1106{ 1107 bp->format = lp->type; 1108 switch (bp->format) { 1109 case DVD_STRUCT_PHYSICAL: 1110 if (bp->layer_num >= 4) 1111 return (EINVAL); 1112 bp->layer_num = lp->physical.layer_num; 1113 break; 1114 case DVD_STRUCT_COPYRIGHT: 1115 bp->layer_num = lp->copyright.layer_num; 1116 break; 1117 case DVD_STRUCT_DISCKEY: 1118 bp->agid = lp->disckey.agid; 1119 break; 1120 case DVD_STRUCT_BCA: 1121 case DVD_STRUCT_MANUFACT: 1122 break; 1123 default: 1124 return (EINVAL); 1125 } 1126 return (0); 1127} 1128 1129static int 1130bsd_to_linux_dvd_struct(struct dvd_struct *bp, l_dvd_struct *lp) 1131{ 1132 switch (bp->format) { 1133 case DVD_STRUCT_PHYSICAL: { 1134 struct dvd_layer *blp = (struct dvd_layer *)bp->data; 1135 struct l_dvd_layer *llp = &lp->physical.layer[bp->layer_num]; 1136 memset(llp, 0, sizeof(*llp)); 1137 llp->book_version = blp->book_version; 1138 llp->book_type = blp->book_type; 1139 llp->min_rate = blp->max_rate; 1140 llp->disc_size = blp->disc_size; 1141 llp->layer_type = blp->layer_type; 1142 llp->track_path = blp->track_path; 1143 llp->nlayers = blp->nlayers; 1144 llp->track_density = blp->track_density; 1145 llp->linear_density = blp->linear_density; 1146 llp->bca = blp->bca; 1147 llp->start_sector = blp->start_sector; 1148 llp->end_sector = blp->end_sector; 1149 llp->end_sector_l0 = blp->end_sector_l0; 1150 break; 1151 } 1152 case DVD_STRUCT_COPYRIGHT: 1153 lp->copyright.cpst = bp->cpst; 1154 lp->copyright.rmi = bp->rmi; 1155 break; 1156 case DVD_STRUCT_DISCKEY: 1157 memcpy(lp->disckey.value, bp->data, sizeof(lp->disckey.value)); 1158 break; 1159 case DVD_STRUCT_BCA: 1160 lp->bca.len = bp->length; 1161 memcpy(lp->bca.value, bp->data, sizeof(lp->bca.value)); 1162 break; 1163 case DVD_STRUCT_MANUFACT: 1164 lp->manufact.len = bp->length; 1165 memcpy(lp->manufact.value, bp->data, 1166 sizeof(lp->manufact.value)); 1167 /* lp->manufact.layer_num is unused in linux (redhat 7.0) */ 1168 break; 1169 default: 1170 return (EINVAL); 1171 } 1172 return (0); 1173} 1174 1175static int 1176linux_to_bsd_dvd_authinfo(l_dvd_authinfo *lp, int *bcode, 1177 struct dvd_authinfo *bp) 1178{ 1179 switch (lp->type) { 1180 case LINUX_DVD_LU_SEND_AGID: 1181 *bcode = DVDIOCREPORTKEY; 1182 bp->format = DVD_REPORT_AGID; 1183 bp->agid = lp->lsa.agid; 1184 break; 1185 case LINUX_DVD_HOST_SEND_CHALLENGE: 1186 *bcode = DVDIOCSENDKEY; 1187 bp->format = DVD_SEND_CHALLENGE; 1188 bp->agid = lp->hsc.agid; 1189 memcpy(bp->keychal, lp->hsc.chal, 10); 1190 break; 1191 case LINUX_DVD_LU_SEND_KEY1: 1192 *bcode = DVDIOCREPORTKEY; 1193 bp->format = DVD_REPORT_KEY1; 1194 bp->agid = lp->lsk.agid; 1195 break; 1196 case LINUX_DVD_LU_SEND_CHALLENGE: 1197 *bcode = DVDIOCREPORTKEY; 1198 bp->format = DVD_REPORT_CHALLENGE; 1199 bp->agid = lp->lsc.agid; 1200 break; 1201 case LINUX_DVD_HOST_SEND_KEY2: 1202 *bcode = DVDIOCSENDKEY; 1203 bp->format = DVD_SEND_KEY2; 1204 bp->agid = lp->hsk.agid; 1205 memcpy(bp->keychal, lp->hsk.key, 5); 1206 break; 1207 case LINUX_DVD_LU_SEND_TITLE_KEY: 1208 *bcode = DVDIOCREPORTKEY; 1209 bp->format = DVD_REPORT_TITLE_KEY; 1210 bp->agid = lp->lstk.agid; 1211 bp->lba = lp->lstk.lba; 1212 break; 1213 case LINUX_DVD_LU_SEND_ASF: 1214 *bcode = DVDIOCREPORTKEY; 1215 bp->format = DVD_REPORT_ASF; 1216 bp->agid = lp->lsasf.agid; 1217 break; 1218 case LINUX_DVD_INVALIDATE_AGID: 1219 *bcode = DVDIOCREPORTKEY; 1220 bp->format = DVD_INVALIDATE_AGID; 1221 bp->agid = lp->lsa.agid; 1222 break; 1223 case LINUX_DVD_LU_SEND_RPC_STATE: 1224 *bcode = DVDIOCREPORTKEY; 1225 bp->format = DVD_REPORT_RPC; 1226 break; 1227 case LINUX_DVD_HOST_SEND_RPC_STATE: 1228 *bcode = DVDIOCSENDKEY; 1229 bp->format = DVD_SEND_RPC; 1230 bp->region = lp->hrpcs.pdrc; 1231 break; 1232 default: 1233 return (EINVAL); 1234 } 1235 return (0); 1236} 1237 1238static int 1239bsd_to_linux_dvd_authinfo(struct dvd_authinfo *bp, l_dvd_authinfo *lp) 1240{ 1241 switch (lp->type) { 1242 case LINUX_DVD_LU_SEND_AGID: 1243 lp->lsa.agid = bp->agid; 1244 break; 1245 case LINUX_DVD_HOST_SEND_CHALLENGE: 1246 lp->type = LINUX_DVD_LU_SEND_KEY1; 1247 break; 1248 case LINUX_DVD_LU_SEND_KEY1: 1249 memcpy(lp->lsk.key, bp->keychal, sizeof(lp->lsk.key)); 1250 break; 1251 case LINUX_DVD_LU_SEND_CHALLENGE: 1252 memcpy(lp->lsc.chal, bp->keychal, sizeof(lp->lsc.chal)); 1253 break; 1254 case LINUX_DVD_HOST_SEND_KEY2: 1255 lp->type = LINUX_DVD_AUTH_ESTABLISHED; 1256 break; 1257 case LINUX_DVD_LU_SEND_TITLE_KEY: 1258 memcpy(lp->lstk.title_key, bp->keychal, 1259 sizeof(lp->lstk.title_key)); 1260 lp->lstk.cpm = bp->cpm; 1261 lp->lstk.cp_sec = bp->cp_sec; 1262 lp->lstk.cgms = bp->cgms; 1263 break; 1264 case LINUX_DVD_LU_SEND_ASF: 1265 lp->lsasf.asf = bp->asf; 1266 break; 1267 case LINUX_DVD_INVALIDATE_AGID: 1268 break; 1269 case LINUX_DVD_LU_SEND_RPC_STATE: 1270 lp->lrpcs.type = bp->reg_type; 1271 lp->lrpcs.vra = bp->vend_rsts; 1272 lp->lrpcs.ucca = bp->user_rsts; 1273 lp->lrpcs.region_mask = bp->region; 1274 lp->lrpcs.rpc_scheme = bp->rpc_scheme; 1275 break; 1276 case LINUX_DVD_HOST_SEND_RPC_STATE: 1277 break; 1278 default: 1279 return (EINVAL); 1280 } 1281 return (0); 1282} 1283 1284static int 1285linux_ioctl_cdrom(struct thread *td, struct linux_ioctl_args *args) 1286{ 1287 struct file *fp; 1288 int error; 1289 1290 if ((error = fget(td, args->fd, &fp)) != 0) 1291 return (error); 1292 switch (args->cmd & 0xffff) { 1293 1294 case LINUX_CDROMPAUSE: 1295 args->cmd = CDIOCPAUSE; 1296 error = (ioctl(td, (struct ioctl_args *)args)); 1297 break; 1298 1299 case LINUX_CDROMRESUME: 1300 args->cmd = CDIOCRESUME; 1301 error = (ioctl(td, (struct ioctl_args *)args)); 1302 break; 1303 1304 case LINUX_CDROMPLAYMSF: 1305 args->cmd = CDIOCPLAYMSF; 1306 error = (ioctl(td, (struct ioctl_args *)args)); 1307 break; 1308 1309 case LINUX_CDROMPLAYTRKIND: 1310 args->cmd = CDIOCPLAYTRACKS; 1311 error = (ioctl(td, (struct ioctl_args *)args)); 1312 break; 1313 1314 case LINUX_CDROMREADTOCHDR: { 1315 struct ioc_toc_header th; 1316 struct linux_cdrom_tochdr lth; 1317 error = fo_ioctl(fp, CDIOREADTOCHEADER, (caddr_t)&th, 1318 td->td_ucred, td); 1319 if (!error) { 1320 lth.cdth_trk0 = th.starting_track; 1321 lth.cdth_trk1 = th.ending_track; 1322 copyout(<h, (caddr_t)args->arg, sizeof(lth)); 1323 } 1324 break; 1325 } 1326 1327 case LINUX_CDROMREADTOCENTRY: { 1328 struct linux_cdrom_tocentry lte, *ltep = 1329 (struct linux_cdrom_tocentry *)args->arg; 1330 struct ioc_read_toc_single_entry irtse; 1331 irtse.address_format = ltep->cdte_format; 1332 irtse.track = ltep->cdte_track; 1333 error = fo_ioctl(fp, CDIOREADTOCENTRY, (caddr_t)&irtse, 1334 td->td_ucred, td); 1335 if (!error) { 1336 lte = *ltep; 1337 lte.cdte_ctrl = irtse.entry.control; 1338 lte.cdte_adr = irtse.entry.addr_type; 1339 bsd_to_linux_msf_lba(irtse.address_format, 1340 &irtse.entry.addr, <e.cdte_addr); 1341 copyout(<e, (caddr_t)args->arg, sizeof(lte)); 1342 } 1343 break; 1344 } 1345 1346 case LINUX_CDROMSTOP: 1347 args->cmd = CDIOCSTOP; 1348 error = (ioctl(td, (struct ioctl_args *)args)); 1349 break; 1350 1351 case LINUX_CDROMSTART: 1352 args->cmd = CDIOCSTART; 1353 error = (ioctl(td, (struct ioctl_args *)args)); 1354 break; 1355 1356 case LINUX_CDROMEJECT: 1357 args->cmd = CDIOCEJECT; 1358 error = (ioctl(td, (struct ioctl_args *)args)); 1359 break; 1360 1361 /* LINUX_CDROMVOLCTRL */ 1362 1363 case LINUX_CDROMSUBCHNL: { 1364 struct linux_cdrom_subchnl sc; 1365 struct ioc_read_subchannel bsdsc; 1366 struct cd_sub_channel_info *bsdinfo; 1367 caddr_t sg = stackgap_init(); 1368 bsdinfo = (struct cd_sub_channel_info*)stackgap_alloc(&sg, 1369 sizeof(struct cd_sub_channel_info)); 1370 bsdsc.address_format = CD_LBA_FORMAT; 1371 bsdsc.data_format = CD_CURRENT_POSITION; 1372 bsdsc.track = 0; 1373 bsdsc.data_len = sizeof(struct cd_sub_channel_info); 1374 bsdsc.data = bsdinfo; 1375 error = fo_ioctl(fp, CDIOCREADSUBCHANNEL, (caddr_t)&bsdsc, 1376 td->td_ucred, td); 1377 if (error) 1378 break; 1379 error = copyin((caddr_t)args->arg, &sc, 1380 sizeof(struct linux_cdrom_subchnl)); 1381 if (error) 1382 break; 1383 sc.cdsc_audiostatus = bsdinfo->header.audio_status; 1384 sc.cdsc_adr = bsdinfo->what.position.addr_type; 1385 sc.cdsc_ctrl = bsdinfo->what.position.control; 1386 sc.cdsc_trk = bsdinfo->what.position.track_number; 1387 sc.cdsc_ind = bsdinfo->what.position.index_number; 1388 set_linux_cdrom_addr(&sc.cdsc_absaddr, sc.cdsc_format, 1389 bsdinfo->what.position.absaddr.lba); 1390 set_linux_cdrom_addr(&sc.cdsc_reladdr, sc.cdsc_format, 1391 bsdinfo->what.position.reladdr.lba); 1392 error = copyout(&sc, (caddr_t)args->arg, 1393 sizeof(struct linux_cdrom_subchnl)); 1394 break; 1395 } 1396 1397 /* LINUX_CDROMREADMODE2 */ 1398 /* LINUX_CDROMREADMODE1 */ 1399 1400 case LINUX_CDROMREADAUDIO: { 1401 struct l_cdrom_read_audio lra; 1402 struct ioc_read_audio bra; 1403 1404 error = copyin((caddr_t)args->arg, &lra, sizeof(lra)); 1405 if (error) 1406 break; 1407 bra.address_format = lra.addr_format; 1408 linux_to_bsd_msf_lba(bra.address_format, &lra.addr, 1409 &bra.address); 1410 bra.nframes = lra.nframes; 1411 bra.buffer = lra.buf; 1412 error = fo_ioctl(fp, CDIOCREADAUDIO, (caddr_t)&bra, 1413 td->td_ucred, td); 1414 break; 1415 } 1416 1417 /* LINUX_CDROMEJECT_SW */ 1418 /* LINUX_CDROMMULTISESSION */ 1419 /* LINUX_CDROM_GET_UPC */ 1420 1421 case LINUX_CDROMRESET: 1422 args->cmd = CDIOCRESET; 1423 error = (ioctl(td, (struct ioctl_args *)args)); 1424 break; 1425 1426 /* LINUX_CDROMVOLREAD */ 1427 /* LINUX_CDROMREADRAW */ 1428 /* LINUX_CDROMREADCOOKED */ 1429 /* LINUX_CDROMSEEK */ 1430 /* LINUX_CDROMPLAYBLK */ 1431 /* LINUX_CDROMREADALL */ 1432 /* LINUX_CDROMCLOSETRAY */ 1433 /* LINUX_CDROMLOADFROMSLOT */ 1434 /* LINUX_CDROMGETSPINDOWN */ 1435 /* LINUX_CDROMSETSPINDOWN */ 1436 /* LINUX_CDROM_SET_OPTIONS */ 1437 /* LINUX_CDROM_CLEAR_OPTIONS */ 1438 /* LINUX_CDROM_SELECT_SPEED */ 1439 /* LINUX_CDROM_SELECT_DISC */ 1440 /* LINUX_CDROM_MEDIA_CHANGED */ 1441 /* LINUX_CDROM_DRIVE_STATUS */ 1442 /* LINUX_CDROM_DISC_STATUS */ 1443 /* LINUX_CDROM_CHANGER_NSLOTS */ 1444 /* LINUX_CDROM_LOCKDOOR */ 1445 /* LINUX_CDROM_DEBUG */ 1446 /* LINUX_CDROM_GET_CAPABILITY */ 1447 /* LINUX_CDROMAUDIOBUFSIZ */ 1448 1449 case LINUX_DVD_READ_STRUCT: { 1450 l_dvd_struct lds; 1451 struct dvd_struct bds; 1452 1453 error = copyin((caddr_t)args->arg, &lds, sizeof(l_dvd_struct)); 1454 if (error) 1455 break; 1456 error = linux_to_bsd_dvd_struct(&lds, &bds); 1457 if (error) 1458 break; 1459 error = fo_ioctl(fp, DVDIOCREADSTRUCTURE, (caddr_t)&bds, 1460 td->td_ucred, td); 1461 if (error) 1462 break; 1463 error = bsd_to_linux_dvd_struct(&bds, &lds); 1464 if (error) 1465 break; 1466 error = copyout(&lds, (caddr_t)args->arg, 1467 sizeof(l_dvd_struct)); 1468 break; 1469 } 1470 1471 /* LINUX_DVD_WRITE_STRUCT */ 1472 1473 case LINUX_DVD_AUTH: { 1474 l_dvd_authinfo lda; 1475 struct dvd_authinfo bda; 1476 int bcode; 1477 1478 error = copyin((caddr_t)args->arg, &lda, 1479 sizeof(l_dvd_authinfo)); 1480 if (error) 1481 break; 1482 error = linux_to_bsd_dvd_authinfo(&lda, &bcode, &bda); 1483 if (error) 1484 break; 1485 error = fo_ioctl(fp, bcode, (caddr_t)&bda, td->td_ucred, 1486 td); 1487 if (error) { 1488 if (lda.type == LINUX_DVD_HOST_SEND_KEY2) { 1489 lda.type = LINUX_DVD_AUTH_FAILURE; 1490 copyout(&lda, (caddr_t)args->arg, 1491 sizeof(l_dvd_authinfo)); 1492 } 1493 break; 1494 } 1495 error = bsd_to_linux_dvd_authinfo(&bda, &lda); 1496 if (error) 1497 break; 1498 error = copyout(&lda, (caddr_t)args->arg, 1499 sizeof(l_dvd_authinfo)); 1500 break; 1501 } 1502 1503 /* LINUX_CDROM_SEND_PACKET */ 1504 /* LINUX_CDROM_NEXT_WRITABLE */ 1505 /* LINUX_CDROM_LAST_WRITTEN */ 1506 1507 default: 1508 error = ENOIOCTL; 1509 break; 1510 } 1511 1512 fdrop(fp, td); 1513 return (error); 1514} 1515 1516static int 1517linux_ioctl_vfat(struct thread *td, struct linux_ioctl_args *args) 1518{ 1519 1520 return (ENOTTY); 1521} 1522 1523/* 1524 * Sound related ioctls 1525 */ 1526 1527static u_int32_t dirbits[4] = { IOC_VOID, IOC_IN, IOC_OUT, IOC_INOUT }; 1528 1529#define SETDIR(c) (((c) & ~IOC_DIRMASK) | dirbits[args->cmd >> 30]) 1530 1531static int 1532linux_ioctl_sound(struct thread *td, struct linux_ioctl_args *args) 1533{ 1534 1535 switch (args->cmd & 0xffff) { 1536 1537 case LINUX_SOUND_MIXER_WRITE_VOLUME: 1538 args->cmd = SETDIR(SOUND_MIXER_WRITE_VOLUME); 1539 return (ioctl(td, (struct ioctl_args *)args)); 1540 1541 case LINUX_SOUND_MIXER_WRITE_BASS: 1542 args->cmd = SETDIR(SOUND_MIXER_WRITE_BASS); 1543 return (ioctl(td, (struct ioctl_args *)args)); 1544 1545 case LINUX_SOUND_MIXER_WRITE_TREBLE: 1546 args->cmd = SETDIR(SOUND_MIXER_WRITE_TREBLE); 1547 return (ioctl(td, (struct ioctl_args *)args)); 1548 1549 case LINUX_SOUND_MIXER_WRITE_SYNTH: 1550 args->cmd = SETDIR(SOUND_MIXER_WRITE_SYNTH); 1551 return (ioctl(td, (struct ioctl_args *)args)); 1552 1553 case LINUX_SOUND_MIXER_WRITE_PCM: 1554 args->cmd = SETDIR(SOUND_MIXER_WRITE_PCM); 1555 return (ioctl(td, (struct ioctl_args *)args)); 1556 1557 case LINUX_SOUND_MIXER_WRITE_SPEAKER: 1558 args->cmd = SETDIR(SOUND_MIXER_WRITE_SPEAKER); 1559 return (ioctl(td, (struct ioctl_args *)args)); 1560 1561 case LINUX_SOUND_MIXER_WRITE_LINE: 1562 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE); 1563 return (ioctl(td, (struct ioctl_args *)args)); 1564 1565 case LINUX_SOUND_MIXER_WRITE_MIC: 1566 args->cmd = SETDIR(SOUND_MIXER_WRITE_MIC); 1567 return (ioctl(td, (struct ioctl_args *)args)); 1568 1569 case LINUX_SOUND_MIXER_WRITE_CD: 1570 args->cmd = SETDIR(SOUND_MIXER_WRITE_CD); 1571 return (ioctl(td, (struct ioctl_args *)args)); 1572 1573 case LINUX_SOUND_MIXER_WRITE_IMIX: 1574 args->cmd = SETDIR(SOUND_MIXER_WRITE_IMIX); 1575 return (ioctl(td, (struct ioctl_args *)args)); 1576 1577 case LINUX_SOUND_MIXER_WRITE_ALTPCM: 1578 args->cmd = SETDIR(SOUND_MIXER_WRITE_ALTPCM); 1579 return (ioctl(td, (struct ioctl_args *)args)); 1580 1581 case LINUX_SOUND_MIXER_WRITE_RECLEV: 1582 args->cmd = SETDIR(SOUND_MIXER_WRITE_RECLEV); 1583 return (ioctl(td, (struct ioctl_args *)args)); 1584 1585 case LINUX_SOUND_MIXER_WRITE_IGAIN: 1586 args->cmd = SETDIR(SOUND_MIXER_WRITE_IGAIN); 1587 return (ioctl(td, (struct ioctl_args *)args)); 1588 1589 case LINUX_SOUND_MIXER_WRITE_OGAIN: 1590 args->cmd = SETDIR(SOUND_MIXER_WRITE_OGAIN); 1591 return (ioctl(td, (struct ioctl_args *)args)); 1592 1593 case LINUX_SOUND_MIXER_WRITE_LINE1: 1594 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE1); 1595 return (ioctl(td, (struct ioctl_args *)args)); 1596 1597 case LINUX_SOUND_MIXER_WRITE_LINE2: 1598 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE2); 1599 return (ioctl(td, (struct ioctl_args *)args)); 1600 1601 case LINUX_SOUND_MIXER_WRITE_LINE3: 1602 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE3); 1603 return (ioctl(td, (struct ioctl_args *)args)); 1604 1605 case LINUX_OSS_GETVERSION: { 1606 int version = linux_get_oss_version(td->td_proc); 1607 return (copyout(&version, (caddr_t)args->arg, sizeof(int))); 1608 } 1609 1610 case LINUX_SOUND_MIXER_READ_STEREODEVS: 1611 args->cmd = SOUND_MIXER_READ_STEREODEVS; 1612 return (ioctl(td, (struct ioctl_args *)args)); 1613 1614 case LINUX_SOUND_MIXER_READ_DEVMASK: 1615 args->cmd = SOUND_MIXER_READ_DEVMASK; 1616 return (ioctl(td, (struct ioctl_args *)args)); 1617 1618 case LINUX_SOUND_MIXER_WRITE_RECSRC: 1619 args->cmd = SETDIR(SOUND_MIXER_WRITE_RECSRC); 1620 return (ioctl(td, (struct ioctl_args *)args)); 1621 1622 case LINUX_SNDCTL_DSP_RESET: 1623 args->cmd = SNDCTL_DSP_RESET; 1624 return (ioctl(td, (struct ioctl_args *)args)); 1625 1626 case LINUX_SNDCTL_DSP_SYNC: 1627 args->cmd = SNDCTL_DSP_SYNC; 1628 return (ioctl(td, (struct ioctl_args *)args)); 1629 1630 case LINUX_SNDCTL_DSP_SPEED: 1631 args->cmd = SNDCTL_DSP_SPEED; 1632 return (ioctl(td, (struct ioctl_args *)args)); 1633 1634 case LINUX_SNDCTL_DSP_STEREO: 1635 args->cmd = SNDCTL_DSP_STEREO; 1636 return (ioctl(td, (struct ioctl_args *)args)); 1637 1638 case LINUX_SNDCTL_DSP_GETBLKSIZE: /* LINUX_SNDCTL_DSP_SETBLKSIZE */ 1639 args->cmd = SNDCTL_DSP_GETBLKSIZE; 1640 return (ioctl(td, (struct ioctl_args *)args)); 1641 1642 case LINUX_SNDCTL_DSP_SETFMT: 1643 args->cmd = SNDCTL_DSP_SETFMT; 1644 return (ioctl(td, (struct ioctl_args *)args)); 1645 1646 case LINUX_SOUND_PCM_WRITE_CHANNELS: 1647 args->cmd = SOUND_PCM_WRITE_CHANNELS; 1648 return (ioctl(td, (struct ioctl_args *)args)); 1649 1650 case LINUX_SOUND_PCM_WRITE_FILTER: 1651 args->cmd = SOUND_PCM_WRITE_FILTER; 1652 return (ioctl(td, (struct ioctl_args *)args)); 1653 1654 case LINUX_SNDCTL_DSP_POST: 1655 args->cmd = SNDCTL_DSP_POST; 1656 return (ioctl(td, (struct ioctl_args *)args)); 1657 1658 case LINUX_SNDCTL_DSP_SUBDIVIDE: 1659 args->cmd = SNDCTL_DSP_SUBDIVIDE; 1660 return (ioctl(td, (struct ioctl_args *)args)); 1661 1662 case LINUX_SNDCTL_DSP_SETFRAGMENT: 1663 args->cmd = SNDCTL_DSP_SETFRAGMENT; 1664 return (ioctl(td, (struct ioctl_args *)args)); 1665 1666 case LINUX_SNDCTL_DSP_GETFMTS: 1667 args->cmd = SNDCTL_DSP_GETFMTS; 1668 return (ioctl(td, (struct ioctl_args *)args)); 1669 1670 case LINUX_SNDCTL_DSP_GETOSPACE: 1671 args->cmd = SNDCTL_DSP_GETOSPACE; 1672 return (ioctl(td, (struct ioctl_args *)args)); 1673 1674 case LINUX_SNDCTL_DSP_GETISPACE: 1675 args->cmd = SNDCTL_DSP_GETISPACE; 1676 return (ioctl(td, (struct ioctl_args *)args)); 1677 1678 case LINUX_SNDCTL_DSP_NONBLOCK: 1679 args->cmd = SNDCTL_DSP_NONBLOCK; 1680 return (ioctl(td, (struct ioctl_args *)args)); 1681 1682 case LINUX_SNDCTL_DSP_GETCAPS: 1683 args->cmd = SNDCTL_DSP_GETCAPS; 1684 return (ioctl(td, (struct ioctl_args *)args)); 1685 1686 case LINUX_SNDCTL_DSP_SETTRIGGER: /* LINUX_SNDCTL_GETTRIGGER */ 1687 args->cmd = SNDCTL_DSP_SETTRIGGER; 1688 return (ioctl(td, (struct ioctl_args *)args)); 1689 1690 case LINUX_SNDCTL_DSP_GETIPTR: 1691 args->cmd = SNDCTL_DSP_GETIPTR; 1692 return (ioctl(td, (struct ioctl_args *)args)); 1693 1694 case LINUX_SNDCTL_DSP_GETOPTR: 1695 args->cmd = SNDCTL_DSP_GETOPTR; 1696 return (ioctl(td, (struct ioctl_args *)args)); 1697 1698 case LINUX_SNDCTL_DSP_GETODELAY: 1699 args->cmd = SNDCTL_DSP_GETODELAY; 1700 return (ioctl(td, (struct ioctl_args *)args)); 1701 1702 case LINUX_SNDCTL_SEQ_RESET: 1703 args->cmd = SNDCTL_SEQ_RESET; 1704 return (ioctl(td, (struct ioctl_args *)args)); 1705 1706 case LINUX_SNDCTL_SEQ_SYNC: 1707 args->cmd = SNDCTL_SEQ_SYNC; 1708 return (ioctl(td, (struct ioctl_args *)args)); 1709 1710 case LINUX_SNDCTL_SYNTH_INFO: 1711 args->cmd = SNDCTL_SYNTH_INFO; 1712 return (ioctl(td, (struct ioctl_args *)args)); 1713 1714 case LINUX_SNDCTL_SEQ_CTRLRATE: 1715 args->cmd = SNDCTL_SEQ_CTRLRATE; 1716 return (ioctl(td, (struct ioctl_args *)args)); 1717 1718 case LINUX_SNDCTL_SEQ_GETOUTCOUNT: 1719 args->cmd = SNDCTL_SEQ_GETOUTCOUNT; 1720 return (ioctl(td, (struct ioctl_args *)args)); 1721 1722 case LINUX_SNDCTL_SEQ_GETINCOUNT: 1723 args->cmd = SNDCTL_SEQ_GETINCOUNT; 1724 return (ioctl(td, (struct ioctl_args *)args)); 1725 1726 case LINUX_SNDCTL_SEQ_PERCMODE: 1727 args->cmd = SNDCTL_SEQ_PERCMODE; 1728 return (ioctl(td, (struct ioctl_args *)args)); 1729 1730 case LINUX_SNDCTL_FM_LOAD_INSTR: 1731 args->cmd = SNDCTL_FM_LOAD_INSTR; 1732 return (ioctl(td, (struct ioctl_args *)args)); 1733 1734 case LINUX_SNDCTL_SEQ_TESTMIDI: 1735 args->cmd = SNDCTL_SEQ_TESTMIDI; 1736 return (ioctl(td, (struct ioctl_args *)args)); 1737 1738 case LINUX_SNDCTL_SEQ_RESETSAMPLES: 1739 args->cmd = SNDCTL_SEQ_RESETSAMPLES; 1740 return (ioctl(td, (struct ioctl_args *)args)); 1741 1742 case LINUX_SNDCTL_SEQ_NRSYNTHS: 1743 args->cmd = SNDCTL_SEQ_NRSYNTHS; 1744 return (ioctl(td, (struct ioctl_args *)args)); 1745 1746 case LINUX_SNDCTL_SEQ_NRMIDIS: 1747 args->cmd = SNDCTL_SEQ_NRMIDIS; 1748 return (ioctl(td, (struct ioctl_args *)args)); 1749 1750 case LINUX_SNDCTL_MIDI_INFO: 1751 args->cmd = SNDCTL_MIDI_INFO; 1752 return (ioctl(td, (struct ioctl_args *)args)); 1753 1754 case LINUX_SNDCTL_SEQ_TRESHOLD: 1755 args->cmd = SNDCTL_SEQ_TRESHOLD; 1756 return (ioctl(td, (struct ioctl_args *)args)); 1757 1758 case LINUX_SNDCTL_SYNTH_MEMAVL: 1759 args->cmd = SNDCTL_SYNTH_MEMAVL; 1760 return (ioctl(td, (struct ioctl_args *)args)); 1761 1762 } 1763 1764 return (ENOIOCTL); 1765} 1766 1767/* 1768 * Console related ioctls 1769 */ 1770 1771#define ISSIGVALID(sig) ((sig) > 0 && (sig) < NSIG) 1772 1773static int 1774linux_ioctl_console(struct thread *td, struct linux_ioctl_args *args) 1775{ 1776 struct file *fp; 1777 int error; 1778 1779 if ((error = fget(td, args->fd, &fp)) != 0) 1780 return (error); 1781 switch (args->cmd & 0xffff) { 1782 1783 case LINUX_KIOCSOUND: 1784 args->cmd = KIOCSOUND; 1785 error = (ioctl(td, (struct ioctl_args *)args)); 1786 break; 1787 1788 case LINUX_KDMKTONE: 1789 args->cmd = KDMKTONE; 1790 error = (ioctl(td, (struct ioctl_args *)args)); 1791 break; 1792 1793 case LINUX_KDGETLED: 1794 args->cmd = KDGETLED; 1795 error = (ioctl(td, (struct ioctl_args *)args)); 1796 break; 1797 1798 case LINUX_KDSETLED: 1799 args->cmd = KDSETLED; 1800 error = (ioctl(td, (struct ioctl_args *)args)); 1801 break; 1802 1803 case LINUX_KDSETMODE: 1804 args->cmd = KDSETMODE; 1805 error = (ioctl(td, (struct ioctl_args *)args)); 1806 break; 1807 1808 case LINUX_KDGETMODE: 1809 args->cmd = KDGETMODE; 1810 error = (ioctl(td, (struct ioctl_args *)args)); 1811 break; 1812 1813 case LINUX_KDGKBMODE: 1814 args->cmd = KDGKBMODE; 1815 error = (ioctl(td, (struct ioctl_args *)args)); 1816 break; 1817 1818 case LINUX_KDSKBMODE: { 1819 int kbdmode; 1820 switch (args->arg) { 1821 case LINUX_KBD_RAW: 1822 kbdmode = K_RAW; 1823 break; 1824 case LINUX_KBD_XLATE: 1825 kbdmode = K_XLATE; 1826 break; 1827 case LINUX_KBD_MEDIUMRAW: 1828 kbdmode = K_RAW; 1829 break; 1830 default: 1831 fdrop(fp, td); 1832 return (EINVAL); 1833 } 1834 error = (fo_ioctl(fp, KDSKBMODE, (caddr_t)&kbdmode, 1835 td->td_ucred, td)); 1836 break; 1837 } 1838 1839 case LINUX_VT_OPENQRY: 1840 args->cmd = VT_OPENQRY; 1841 error = (ioctl(td, (struct ioctl_args *)args)); 1842 break; 1843 1844 case LINUX_VT_GETMODE: 1845 args->cmd = VT_GETMODE; 1846 error = (ioctl(td, (struct ioctl_args *)args)); 1847 break; 1848 1849 case LINUX_VT_SETMODE: { 1850 struct vt_mode *mode; 1851 args->cmd = VT_SETMODE; 1852 mode = (struct vt_mode *)args->arg; 1853 if (!ISSIGVALID(mode->frsig) && ISSIGVALID(mode->acqsig)) 1854 mode->frsig = mode->acqsig; 1855 error = (ioctl(td, (struct ioctl_args *)args)); 1856 break; 1857 } 1858 1859 case LINUX_VT_GETSTATE: 1860 args->cmd = VT_GETACTIVE; 1861 error = (ioctl(td, (struct ioctl_args *)args)); 1862 break; 1863 1864 case LINUX_VT_RELDISP: 1865 args->cmd = VT_RELDISP; 1866 error = (ioctl(td, (struct ioctl_args *)args)); 1867 break; 1868 1869 case LINUX_VT_ACTIVATE: 1870 args->cmd = VT_ACTIVATE; 1871 error = (ioctl(td, (struct ioctl_args *)args)); 1872 break; 1873 1874 case LINUX_VT_WAITACTIVE: 1875 args->cmd = VT_WAITACTIVE; 1876 error = (ioctl(td, (struct ioctl_args *)args)); 1877 break; 1878 1879 default: 1880 error = ENOIOCTL; 1881 break; 1882 }
|
1883
| 1883
|
1884 fdrop(fp, td); 1885 return (error); 1886} 1887 1888/* 1889 * Criteria for interface name translation 1890 */ 1891#define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER) 1892 1893/* 1894 * Interface function used by linprocfs (at the time of writing). It's not 1895 * used by the Linuxulator itself. 1896 */ 1897int 1898linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen) 1899{ 1900 struct ifnet *ifscan; 1901 int ethno; 1902 1903 /* Short-circuit non ethernet interfaces */ 1904 if (!IFP_IS_ETH(ifp)) 1905 return (snprintf(buffer, buflen, "%s%d", ifp->if_name, 1906 ifp->if_unit)); 1907 1908 /* Determine the (relative) unit number for ethernet interfaces */ 1909 ethno = 0; 1910 IFNET_RLOCK(); 1911 TAILQ_FOREACH(ifscan, &ifnet, if_link) { 1912 if (ifscan == ifp) { 1913 IFNET_RUNLOCK(); 1914 return (snprintf(buffer, buflen, "eth%d", ethno)); 1915 } 1916 if (IFP_IS_ETH(ifscan)) 1917 ethno++; 1918 } 1919 IFNET_RUNLOCK(); 1920 1921 return (0); 1922} 1923 1924/* 1925 * Translate a Linux interface name to a FreeBSD interface name, 1926 * and return the associated ifnet structure 1927 * bsdname and lxname need to be least IFNAMSIZ bytes long, but 1928 * can point to the same buffer. 1929 */ 1930 1931static struct ifnet * 1932ifname_linux_to_bsd(const char *lxname, char *bsdname) 1933{ 1934 struct ifnet *ifp; 1935 int len, unit; 1936 char *ep; 1937 int is_eth, index; 1938 1939 for (len = 0; len < LINUX_IFNAMSIZ; ++len) 1940 if (!isalpha(lxname[len])) 1941 break; 1942 if (len == 0 || len == LINUX_IFNAMSIZ) 1943 return (NULL); 1944 unit = (int)strtoul(lxname + len, &ep, 10); 1945 if (ep == NULL || ep == lxname + len || ep >= lxname + LINUX_IFNAMSIZ) 1946 return (NULL); 1947 index = 0; 1948 is_eth = (len == 3 && !strncmp(lxname, "eth", len)) ? 1 : 0; 1949 IFNET_RLOCK(); 1950 TAILQ_FOREACH(ifp, &ifnet, if_link) { 1951 /* 1952 * Allow Linux programs to use FreeBSD names. Don't presume 1953 * we never have an interface named "eth", so don't make 1954 * the test optional based on is_eth. 1955 */ 1956 if (ifp->if_unit == unit && ifp->if_name[len] == '\0' && 1957 strncmp(ifp->if_name, lxname, len) == 0) 1958 break; 1959 if (is_eth && IFP_IS_ETH(ifp) && unit == index++) 1960 break; 1961 } 1962 IFNET_RUNLOCK(); 1963 if (ifp != NULL) 1964 snprintf(bsdname, IFNAMSIZ, "%s%d", ifp->if_name, ifp->if_unit); 1965 return (ifp); 1966} 1967 1968/* 1969 * Implement the SIOCGIFCONF ioctl 1970 */ 1971 1972static int 1973linux_ifconf(struct thread *td, struct ifconf *uifc) 1974{ 1975 struct ifconf ifc; 1976 struct l_ifreq ifr; 1977 struct ifnet *ifp; 1978 struct ifaddr *ifa; 1979 struct iovec iov; 1980 struct uio uio; 1981 int error, ethno; 1982 1983 error = copyin(uifc, &ifc, sizeof ifc); 1984 if (error != 0) 1985 return (error); 1986 1987 /* much easier to use uiomove than keep track ourselves */ 1988 iov.iov_base = ifc.ifc_buf; 1989 iov.iov_len = ifc.ifc_len; 1990 uio.uio_iov = &iov; 1991 uio.uio_iovcnt = 1; 1992 uio.uio_offset = 0; 1993 uio.uio_resid = ifc.ifc_len; 1994 uio.uio_segflg = UIO_USERSPACE; 1995 uio.uio_rw = UIO_READ; 1996 uio.uio_td = td; 1997 1998 /* Keep track of eth interfaces */ 1999 ethno = 0; 2000 2001 /* Return all AF_INET addresses of all interfaces */ 2002 IFNET_RLOCK(); /* could sleep XXX */ 2003 TAILQ_FOREACH(ifp, &ifnet, if_link) { 2004 if (uio.uio_resid <= 0) 2005 break; 2006 2007 bzero(&ifr, sizeof ifr); 2008 if (IFP_IS_ETH(ifp)) 2009 snprintf(ifr.ifr_name, LINUX_IFNAMSIZ, "eth%d", 2010 ethno++); 2011 else 2012 snprintf(ifr.ifr_name, LINUX_IFNAMSIZ, "%s%d", 2013 ifp->if_name, ifp->if_unit); 2014 2015 /* Walk the address list */ 2016 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { 2017 struct sockaddr *sa = ifa->ifa_addr; 2018 2019 if (uio.uio_resid <= 0) 2020 break; 2021 2022 if (sa->sa_family == AF_INET) { 2023 ifr.ifr_addr.sa_family = LINUX_AF_INET; 2024 memcpy(ifr.ifr_addr.sa_data, sa->sa_data, 2025 sizeof(ifr.ifr_addr.sa_data)); 2026 2027 error = uiomove(&ifr, sizeof ifr, &uio); 2028 if (error != 0) { 2029 IFNET_RUNLOCK(); 2030 return (error); 2031 } 2032 } 2033 } 2034 } 2035 IFNET_RUNLOCK(); 2036 2037 ifc.ifc_len -= uio.uio_resid; 2038 error = copyout(&ifc, uifc, sizeof ifc); 2039 2040 return (error); 2041} 2042 2043static int 2044linux_gifflags(struct thread *td, struct ifnet *ifp, struct l_ifreq *ifr) 2045{ 2046 l_short flags; 2047 2048 flags = ifp->if_flags & 0xffff; 2049 /* these flags have no Linux equivalent */ 2050 flags &= ~(IFF_SMART|IFF_OACTIVE|IFF_SIMPLEX| 2051 IFF_LINK0|IFF_LINK1|IFF_LINK2); 2052 /* Linux' multicast flag is in a different bit */ 2053 if (flags & IFF_MULTICAST) { 2054 flags &= ~IFF_MULTICAST; 2055 flags |= 0x1000; 2056 } 2057 2058 return (copyout(&flags, &ifr->ifr_flags, sizeof flags)); 2059} 2060 2061#define ARPHRD_ETHER 1 2062#define ARPHRD_LOOPBACK 772 2063 2064static int 2065linux_gifhwaddr(struct ifnet *ifp, struct l_ifreq *ifr) 2066{ 2067 struct ifaddr *ifa; 2068 struct sockaddr_dl *sdl; 2069 struct l_sockaddr lsa; 2070 2071 if (ifp->if_type == IFT_LOOP) { 2072 bzero(&lsa, sizeof lsa); 2073 lsa.sa_family = ARPHRD_LOOPBACK; 2074 return (copyout(&lsa, &ifr->ifr_hwaddr, sizeof lsa)); 2075 }
| 1884 fdrop(fp, td); 1885 return (error); 1886} 1887 1888/* 1889 * Criteria for interface name translation 1890 */ 1891#define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER) 1892 1893/* 1894 * Interface function used by linprocfs (at the time of writing). It's not 1895 * used by the Linuxulator itself. 1896 */ 1897int 1898linux_ifname(struct ifnet *ifp, char *buffer, size_t buflen) 1899{ 1900 struct ifnet *ifscan; 1901 int ethno; 1902 1903 /* Short-circuit non ethernet interfaces */ 1904 if (!IFP_IS_ETH(ifp)) 1905 return (snprintf(buffer, buflen, "%s%d", ifp->if_name, 1906 ifp->if_unit)); 1907 1908 /* Determine the (relative) unit number for ethernet interfaces */ 1909 ethno = 0; 1910 IFNET_RLOCK(); 1911 TAILQ_FOREACH(ifscan, &ifnet, if_link) { 1912 if (ifscan == ifp) { 1913 IFNET_RUNLOCK(); 1914 return (snprintf(buffer, buflen, "eth%d", ethno)); 1915 } 1916 if (IFP_IS_ETH(ifscan)) 1917 ethno++; 1918 } 1919 IFNET_RUNLOCK(); 1920 1921 return (0); 1922} 1923 1924/* 1925 * Translate a Linux interface name to a FreeBSD interface name, 1926 * and return the associated ifnet structure 1927 * bsdname and lxname need to be least IFNAMSIZ bytes long, but 1928 * can point to the same buffer. 1929 */ 1930 1931static struct ifnet * 1932ifname_linux_to_bsd(const char *lxname, char *bsdname) 1933{ 1934 struct ifnet *ifp; 1935 int len, unit; 1936 char *ep; 1937 int is_eth, index; 1938 1939 for (len = 0; len < LINUX_IFNAMSIZ; ++len) 1940 if (!isalpha(lxname[len])) 1941 break; 1942 if (len == 0 || len == LINUX_IFNAMSIZ) 1943 return (NULL); 1944 unit = (int)strtoul(lxname + len, &ep, 10); 1945 if (ep == NULL || ep == lxname + len || ep >= lxname + LINUX_IFNAMSIZ) 1946 return (NULL); 1947 index = 0; 1948 is_eth = (len == 3 && !strncmp(lxname, "eth", len)) ? 1 : 0; 1949 IFNET_RLOCK(); 1950 TAILQ_FOREACH(ifp, &ifnet, if_link) { 1951 /* 1952 * Allow Linux programs to use FreeBSD names. Don't presume 1953 * we never have an interface named "eth", so don't make 1954 * the test optional based on is_eth. 1955 */ 1956 if (ifp->if_unit == unit && ifp->if_name[len] == '\0' && 1957 strncmp(ifp->if_name, lxname, len) == 0) 1958 break; 1959 if (is_eth && IFP_IS_ETH(ifp) && unit == index++) 1960 break; 1961 } 1962 IFNET_RUNLOCK(); 1963 if (ifp != NULL) 1964 snprintf(bsdname, IFNAMSIZ, "%s%d", ifp->if_name, ifp->if_unit); 1965 return (ifp); 1966} 1967 1968/* 1969 * Implement the SIOCGIFCONF ioctl 1970 */ 1971 1972static int 1973linux_ifconf(struct thread *td, struct ifconf *uifc) 1974{ 1975 struct ifconf ifc; 1976 struct l_ifreq ifr; 1977 struct ifnet *ifp; 1978 struct ifaddr *ifa; 1979 struct iovec iov; 1980 struct uio uio; 1981 int error, ethno; 1982 1983 error = copyin(uifc, &ifc, sizeof ifc); 1984 if (error != 0) 1985 return (error); 1986 1987 /* much easier to use uiomove than keep track ourselves */ 1988 iov.iov_base = ifc.ifc_buf; 1989 iov.iov_len = ifc.ifc_len; 1990 uio.uio_iov = &iov; 1991 uio.uio_iovcnt = 1; 1992 uio.uio_offset = 0; 1993 uio.uio_resid = ifc.ifc_len; 1994 uio.uio_segflg = UIO_USERSPACE; 1995 uio.uio_rw = UIO_READ; 1996 uio.uio_td = td; 1997 1998 /* Keep track of eth interfaces */ 1999 ethno = 0; 2000 2001 /* Return all AF_INET addresses of all interfaces */ 2002 IFNET_RLOCK(); /* could sleep XXX */ 2003 TAILQ_FOREACH(ifp, &ifnet, if_link) { 2004 if (uio.uio_resid <= 0) 2005 break; 2006 2007 bzero(&ifr, sizeof ifr); 2008 if (IFP_IS_ETH(ifp)) 2009 snprintf(ifr.ifr_name, LINUX_IFNAMSIZ, "eth%d", 2010 ethno++); 2011 else 2012 snprintf(ifr.ifr_name, LINUX_IFNAMSIZ, "%s%d", 2013 ifp->if_name, ifp->if_unit); 2014 2015 /* Walk the address list */ 2016 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { 2017 struct sockaddr *sa = ifa->ifa_addr; 2018 2019 if (uio.uio_resid <= 0) 2020 break; 2021 2022 if (sa->sa_family == AF_INET) { 2023 ifr.ifr_addr.sa_family = LINUX_AF_INET; 2024 memcpy(ifr.ifr_addr.sa_data, sa->sa_data, 2025 sizeof(ifr.ifr_addr.sa_data)); 2026 2027 error = uiomove(&ifr, sizeof ifr, &uio); 2028 if (error != 0) { 2029 IFNET_RUNLOCK(); 2030 return (error); 2031 } 2032 } 2033 } 2034 } 2035 IFNET_RUNLOCK(); 2036 2037 ifc.ifc_len -= uio.uio_resid; 2038 error = copyout(&ifc, uifc, sizeof ifc); 2039 2040 return (error); 2041} 2042 2043static int 2044linux_gifflags(struct thread *td, struct ifnet *ifp, struct l_ifreq *ifr) 2045{ 2046 l_short flags; 2047 2048 flags = ifp->if_flags & 0xffff; 2049 /* these flags have no Linux equivalent */ 2050 flags &= ~(IFF_SMART|IFF_OACTIVE|IFF_SIMPLEX| 2051 IFF_LINK0|IFF_LINK1|IFF_LINK2); 2052 /* Linux' multicast flag is in a different bit */ 2053 if (flags & IFF_MULTICAST) { 2054 flags &= ~IFF_MULTICAST; 2055 flags |= 0x1000; 2056 } 2057 2058 return (copyout(&flags, &ifr->ifr_flags, sizeof flags)); 2059} 2060 2061#define ARPHRD_ETHER 1 2062#define ARPHRD_LOOPBACK 772 2063 2064static int 2065linux_gifhwaddr(struct ifnet *ifp, struct l_ifreq *ifr) 2066{ 2067 struct ifaddr *ifa; 2068 struct sockaddr_dl *sdl; 2069 struct l_sockaddr lsa; 2070 2071 if (ifp->if_type == IFT_LOOP) { 2072 bzero(&lsa, sizeof lsa); 2073 lsa.sa_family = ARPHRD_LOOPBACK; 2074 return (copyout(&lsa, &ifr->ifr_hwaddr, sizeof lsa)); 2075 }
|
2076
| 2076
|
2077 if (ifp->if_type != IFT_ETHER) 2078 return (ENOENT); 2079 2080 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { 2081 sdl = (struct sockaddr_dl*)ifa->ifa_addr; 2082 if (sdl != NULL && (sdl->sdl_family == AF_LINK) && 2083 (sdl->sdl_type == IFT_ETHER)) { 2084 bzero(&lsa, sizeof lsa); 2085 lsa.sa_family = ARPHRD_ETHER; 2086 bcopy(LLADDR(sdl), lsa.sa_data, LINUX_IFHWADDRLEN); 2087 return (copyout(&lsa, &ifr->ifr_hwaddr, sizeof lsa)); 2088 } 2089 }
| 2077 if (ifp->if_type != IFT_ETHER) 2078 return (ENOENT); 2079 2080 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { 2081 sdl = (struct sockaddr_dl*)ifa->ifa_addr; 2082 if (sdl != NULL && (sdl->sdl_family == AF_LINK) && 2083 (sdl->sdl_type == IFT_ETHER)) { 2084 bzero(&lsa, sizeof lsa); 2085 lsa.sa_family = ARPHRD_ETHER; 2086 bcopy(LLADDR(sdl), lsa.sa_data, LINUX_IFHWADDRLEN); 2087 return (copyout(&lsa, &ifr->ifr_hwaddr, sizeof lsa)); 2088 } 2089 }
|
2090
| 2090
|
2091 return (ENOENT); 2092} 2093 2094/* 2095 * Socket related ioctls 2096 */ 2097 2098static int 2099linux_ioctl_socket(struct thread *td, struct linux_ioctl_args *args) 2100{ 2101 char lifname[LINUX_IFNAMSIZ], ifname[IFNAMSIZ]; 2102 struct ifnet *ifp; 2103 struct file *fp; 2104 int error, type; 2105 2106 KASSERT(LINUX_IFNAMSIZ == IFNAMSIZ, 2107 ("%s(): LINUX_IFNAMSIZ != IFNAMSIZ", __func__));
| 2091 return (ENOENT); 2092} 2093 2094/* 2095 * Socket related ioctls 2096 */ 2097 2098static int 2099linux_ioctl_socket(struct thread *td, struct linux_ioctl_args *args) 2100{ 2101 char lifname[LINUX_IFNAMSIZ], ifname[IFNAMSIZ]; 2102 struct ifnet *ifp; 2103 struct file *fp; 2104 int error, type; 2105 2106 KASSERT(LINUX_IFNAMSIZ == IFNAMSIZ, 2107 ("%s(): LINUX_IFNAMSIZ != IFNAMSIZ", __func__));
|
2108
| 2108
|
2109 ifp = NULL; 2110 error = 0;
| 2109 ifp = NULL; 2110 error = 0;
|
2111
| 2111
|
2112 if ((error = fget(td, args->fd, &fp)) != 0) 2113 return (error); 2114 type = fp->f_type; 2115 fdrop(fp, td); 2116 if (type != DTYPE_SOCKET) { 2117 /* not a socket - probably a tap / vmnet device */ 2118 switch (args->cmd) { 2119 case LINUX_SIOCGIFADDR: 2120 case LINUX_SIOCSIFADDR: 2121 case LINUX_SIOCGIFFLAGS: 2122 return (linux_ioctl_special(td, args)); 2123 default: 2124 return (ENOIOCTL); 2125 } 2126 } 2127 2128 switch (args->cmd & 0xffff) {
| 2112 if ((error = fget(td, args->fd, &fp)) != 0) 2113 return (error); 2114 type = fp->f_type; 2115 fdrop(fp, td); 2116 if (type != DTYPE_SOCKET) { 2117 /* not a socket - probably a tap / vmnet device */ 2118 switch (args->cmd) { 2119 case LINUX_SIOCGIFADDR: 2120 case LINUX_SIOCSIFADDR: 2121 case LINUX_SIOCGIFFLAGS: 2122 return (linux_ioctl_special(td, args)); 2123 default: 2124 return (ENOIOCTL); 2125 } 2126 } 2127 2128 switch (args->cmd & 0xffff) {
|
2129
| 2129
|
2130 case LINUX_FIOGETOWN: 2131 case LINUX_FIOSETOWN: 2132 case LINUX_SIOCADDMULTI: 2133 case LINUX_SIOCATMARK: 2134 case LINUX_SIOCDELMULTI: 2135 case LINUX_SIOCGIFCONF: 2136 case LINUX_SIOCGPGRP: 2137 case LINUX_SIOCSPGRP: 2138 /* these ioctls don't take an interface name */ 2139#ifdef DEBUG 2140 printf("%s(): ioctl %d\n", __func__, 2141 args->cmd & 0xffff); 2142#endif 2143 break;
| 2130 case LINUX_FIOGETOWN: 2131 case LINUX_FIOSETOWN: 2132 case LINUX_SIOCADDMULTI: 2133 case LINUX_SIOCATMARK: 2134 case LINUX_SIOCDELMULTI: 2135 case LINUX_SIOCGIFCONF: 2136 case LINUX_SIOCGPGRP: 2137 case LINUX_SIOCSPGRP: 2138 /* these ioctls don't take an interface name */ 2139#ifdef DEBUG 2140 printf("%s(): ioctl %d\n", __func__, 2141 args->cmd & 0xffff); 2142#endif 2143 break;
|
2144
| 2144
|
2145 case LINUX_SIOCGIFFLAGS: 2146 case LINUX_SIOCGIFADDR: 2147 case LINUX_SIOCSIFADDR: 2148 case LINUX_SIOCGIFDSTADDR: 2149 case LINUX_SIOCGIFBRDADDR: 2150 case LINUX_SIOCGIFNETMASK: 2151 case LINUX_SIOCSIFNETMASK: 2152 case LINUX_SIOCGIFMTU: 2153 case LINUX_SIOCSIFMTU: 2154 case LINUX_SIOCSIFNAME: 2155 case LINUX_SIOCGIFHWADDR: 2156 case LINUX_SIOCSIFHWADDR: 2157 case LINUX_SIOCDEVPRIVATE: 2158 case LINUX_SIOCDEVPRIVATE+1: 2159 /* copy in the interface name and translate it. */ 2160 error = copyin((char *)args->arg, lifname, LINUX_IFNAMSIZ); 2161 if (error != 0) 2162 return (error); 2163#ifdef DEBUG 2164 printf("%s(): ioctl %d on %.*s\n", __func__, 2165 args->cmd & 0xffff, LINUX_IFNAMSIZ, lifname); 2166#endif 2167 ifp = ifname_linux_to_bsd(lifname, ifname); 2168 if (ifp == NULL) 2169 return (EINVAL); 2170 /* 2171 * We need to copy it back out in case we pass the 2172 * request on to our native ioctl(), which will expect 2173 * the ifreq to be in user space and have the correct 2174 * interface name. 2175 */ 2176 error = copyout(ifname, (char *)args->arg, IFNAMSIZ); 2177 if (error != 0) 2178 return (error); 2179#ifdef DEBUG 2180 printf("%s(): %s translated to %s\n", __func__, 2181 lifname, ifname); 2182#endif 2183 break;
| 2145 case LINUX_SIOCGIFFLAGS: 2146 case LINUX_SIOCGIFADDR: 2147 case LINUX_SIOCSIFADDR: 2148 case LINUX_SIOCGIFDSTADDR: 2149 case LINUX_SIOCGIFBRDADDR: 2150 case LINUX_SIOCGIFNETMASK: 2151 case LINUX_SIOCSIFNETMASK: 2152 case LINUX_SIOCGIFMTU: 2153 case LINUX_SIOCSIFMTU: 2154 case LINUX_SIOCSIFNAME: 2155 case LINUX_SIOCGIFHWADDR: 2156 case LINUX_SIOCSIFHWADDR: 2157 case LINUX_SIOCDEVPRIVATE: 2158 case LINUX_SIOCDEVPRIVATE+1: 2159 /* copy in the interface name and translate it. */ 2160 error = copyin((char *)args->arg, lifname, LINUX_IFNAMSIZ); 2161 if (error != 0) 2162 return (error); 2163#ifdef DEBUG 2164 printf("%s(): ioctl %d on %.*s\n", __func__, 2165 args->cmd & 0xffff, LINUX_IFNAMSIZ, lifname); 2166#endif 2167 ifp = ifname_linux_to_bsd(lifname, ifname); 2168 if (ifp == NULL) 2169 return (EINVAL); 2170 /* 2171 * We need to copy it back out in case we pass the 2172 * request on to our native ioctl(), which will expect 2173 * the ifreq to be in user space and have the correct 2174 * interface name. 2175 */ 2176 error = copyout(ifname, (char *)args->arg, IFNAMSIZ); 2177 if (error != 0) 2178 return (error); 2179#ifdef DEBUG 2180 printf("%s(): %s translated to %s\n", __func__, 2181 lifname, ifname); 2182#endif 2183 break;
|
2184
| 2184
|
2185 default: 2186 return (ENOIOCTL); 2187 } 2188 2189 switch (args->cmd & 0xffff) { 2190 2191 case LINUX_FIOSETOWN: 2192 args->cmd = FIOSETOWN; 2193 error = ioctl(td, (struct ioctl_args *)args); 2194 break; 2195 2196 case LINUX_SIOCSPGRP: 2197 args->cmd = SIOCSPGRP; 2198 error = ioctl(td, (struct ioctl_args *)args); 2199 break; 2200 2201 case LINUX_FIOGETOWN: 2202 args->cmd = FIOGETOWN; 2203 error = ioctl(td, (struct ioctl_args *)args); 2204 break; 2205 2206 case LINUX_SIOCGPGRP: 2207 args->cmd = SIOCGPGRP; 2208 error = ioctl(td, (struct ioctl_args *)args); 2209 break; 2210 2211 case LINUX_SIOCATMARK: 2212 args->cmd = SIOCATMARK; 2213 error = ioctl(td, (struct ioctl_args *)args); 2214 break; 2215 2216 /* LINUX_SIOCGSTAMP */ 2217 2218 case LINUX_SIOCGIFCONF: 2219 error = linux_ifconf(td, (struct ifconf *)args->arg); 2220 break; 2221 2222 case LINUX_SIOCGIFFLAGS: 2223 args->cmd = SIOCGIFFLAGS; 2224 error = linux_gifflags(td, ifp, (struct l_ifreq *)args->arg); 2225 break; 2226 2227 case LINUX_SIOCGIFADDR: 2228 args->cmd = OSIOCGIFADDR; 2229 error = ioctl(td, (struct ioctl_args *)args); 2230 break; 2231 2232 case LINUX_SIOCSIFADDR: 2233 /* XXX probably doesn't work, included for completeness */ 2234 args->cmd = SIOCSIFADDR; 2235 error = ioctl(td, (struct ioctl_args *)args); 2236 break; 2237 2238 case LINUX_SIOCGIFDSTADDR: 2239 args->cmd = OSIOCGIFDSTADDR; 2240 error = ioctl(td, (struct ioctl_args *)args); 2241 break; 2242 2243 case LINUX_SIOCGIFBRDADDR: 2244 args->cmd = OSIOCGIFBRDADDR; 2245 error = ioctl(td, (struct ioctl_args *)args); 2246 break; 2247 2248 case LINUX_SIOCGIFNETMASK: 2249 args->cmd = OSIOCGIFNETMASK; 2250 error = ioctl(td, (struct ioctl_args *)args); 2251 break; 2252 2253 case LINUX_SIOCSIFNETMASK: 2254 error = ENOIOCTL; 2255 break;
| 2185 default: 2186 return (ENOIOCTL); 2187 } 2188 2189 switch (args->cmd & 0xffff) { 2190 2191 case LINUX_FIOSETOWN: 2192 args->cmd = FIOSETOWN; 2193 error = ioctl(td, (struct ioctl_args *)args); 2194 break; 2195 2196 case LINUX_SIOCSPGRP: 2197 args->cmd = SIOCSPGRP; 2198 error = ioctl(td, (struct ioctl_args *)args); 2199 break; 2200 2201 case LINUX_FIOGETOWN: 2202 args->cmd = FIOGETOWN; 2203 error = ioctl(td, (struct ioctl_args *)args); 2204 break; 2205 2206 case LINUX_SIOCGPGRP: 2207 args->cmd = SIOCGPGRP; 2208 error = ioctl(td, (struct ioctl_args *)args); 2209 break; 2210 2211 case LINUX_SIOCATMARK: 2212 args->cmd = SIOCATMARK; 2213 error = ioctl(td, (struct ioctl_args *)args); 2214 break; 2215 2216 /* LINUX_SIOCGSTAMP */ 2217 2218 case LINUX_SIOCGIFCONF: 2219 error = linux_ifconf(td, (struct ifconf *)args->arg); 2220 break; 2221 2222 case LINUX_SIOCGIFFLAGS: 2223 args->cmd = SIOCGIFFLAGS; 2224 error = linux_gifflags(td, ifp, (struct l_ifreq *)args->arg); 2225 break; 2226 2227 case LINUX_SIOCGIFADDR: 2228 args->cmd = OSIOCGIFADDR; 2229 error = ioctl(td, (struct ioctl_args *)args); 2230 break; 2231 2232 case LINUX_SIOCSIFADDR: 2233 /* XXX probably doesn't work, included for completeness */ 2234 args->cmd = SIOCSIFADDR; 2235 error = ioctl(td, (struct ioctl_args *)args); 2236 break; 2237 2238 case LINUX_SIOCGIFDSTADDR: 2239 args->cmd = OSIOCGIFDSTADDR; 2240 error = ioctl(td, (struct ioctl_args *)args); 2241 break; 2242 2243 case LINUX_SIOCGIFBRDADDR: 2244 args->cmd = OSIOCGIFBRDADDR; 2245 error = ioctl(td, (struct ioctl_args *)args); 2246 break; 2247 2248 case LINUX_SIOCGIFNETMASK: 2249 args->cmd = OSIOCGIFNETMASK; 2250 error = ioctl(td, (struct ioctl_args *)args); 2251 break; 2252 2253 case LINUX_SIOCSIFNETMASK: 2254 error = ENOIOCTL; 2255 break;
|
2256
| 2256
|
2257 case LINUX_SIOCGIFMTU: 2258 args->cmd = SIOCGIFMTU; 2259 error = ioctl(td, (struct ioctl_args *)args); 2260 break;
| 2257 case LINUX_SIOCGIFMTU: 2258 args->cmd = SIOCGIFMTU; 2259 error = ioctl(td, (struct ioctl_args *)args); 2260 break;
|
2261
| 2261
|
2262 case LINUX_SIOCSIFMTU: 2263 args->cmd = SIOCSIFMTU; 2264 error = ioctl(td, (struct ioctl_args *)args); 2265 break;
| 2262 case LINUX_SIOCSIFMTU: 2263 args->cmd = SIOCSIFMTU; 2264 error = ioctl(td, (struct ioctl_args *)args); 2265 break;
|
2266
| 2266
|
2267 case LINUX_SIOCSIFNAME: 2268 error = ENOIOCTL; 2269 break;
| 2267 case LINUX_SIOCSIFNAME: 2268 error = ENOIOCTL; 2269 break;
|
2270
| 2270
|
2271 case LINUX_SIOCGIFHWADDR: 2272 error = linux_gifhwaddr(ifp, (struct l_ifreq *)args->arg); 2273 break; 2274 2275 case LINUX_SIOCSIFHWADDR: 2276 error = ENOIOCTL; 2277 break;
| 2271 case LINUX_SIOCGIFHWADDR: 2272 error = linux_gifhwaddr(ifp, (struct l_ifreq *)args->arg); 2273 break; 2274 2275 case LINUX_SIOCSIFHWADDR: 2276 error = ENOIOCTL; 2277 break;
|
2278
| 2278
|
2279 case LINUX_SIOCADDMULTI: 2280 args->cmd = SIOCADDMULTI; 2281 error = ioctl(td, (struct ioctl_args *)args); 2282 break; 2283 2284 case LINUX_SIOCDELMULTI: 2285 args->cmd = SIOCDELMULTI; 2286 error = ioctl(td, (struct ioctl_args *)args); 2287 break; 2288 2289 /* 2290 * XXX This is slightly bogus, but these ioctls are currently 2291 * XXX only used by the aironet (if_an) network driver. 2292 */ 2293 case LINUX_SIOCDEVPRIVATE: 2294 args->cmd = SIOCGPRIVATE_0; 2295 error = ioctl(td, (struct ioctl_args *)args); 2296 break;
| 2279 case LINUX_SIOCADDMULTI: 2280 args->cmd = SIOCADDMULTI; 2281 error = ioctl(td, (struct ioctl_args *)args); 2282 break; 2283 2284 case LINUX_SIOCDELMULTI: 2285 args->cmd = SIOCDELMULTI; 2286 error = ioctl(td, (struct ioctl_args *)args); 2287 break; 2288 2289 /* 2290 * XXX This is slightly bogus, but these ioctls are currently 2291 * XXX only used by the aironet (if_an) network driver. 2292 */ 2293 case LINUX_SIOCDEVPRIVATE: 2294 args->cmd = SIOCGPRIVATE_0; 2295 error = ioctl(td, (struct ioctl_args *)args); 2296 break;
|
2297
| 2297
|
2298 case LINUX_SIOCDEVPRIVATE+1: 2299 args->cmd = SIOCGPRIVATE_1; 2300 error = ioctl(td, (struct ioctl_args *)args); 2301 break; 2302 } 2303 2304 if (ifp != NULL) 2305 /* restore the original interface name */ 2306 copyout(lifname, (char *)args->arg, LINUX_IFNAMSIZ); 2307 2308#ifdef DEBUG 2309 printf("%s(): returning %d\n", __func__, error); 2310#endif 2311 return (error); 2312} 2313 2314/* 2315 * Device private ioctl handler 2316 */ 2317static int 2318linux_ioctl_private(struct thread *td, struct linux_ioctl_args *args) 2319{ 2320 struct file *fp; 2321 int error, type; 2322 2323 if ((error = fget(td, args->fd, &fp)) != 0) 2324 return (error); 2325 type = fp->f_type; 2326 fdrop(fp, td); 2327 if (type == DTYPE_SOCKET) 2328 return (linux_ioctl_socket(td, args)); 2329 return (ENOIOCTL); 2330} 2331 2332/* 2333 * Special ioctl handler 2334 */ 2335static int 2336linux_ioctl_special(struct thread *td, struct linux_ioctl_args *args) 2337{ 2338 int error; 2339 2340 switch (args->cmd) { 2341 case LINUX_SIOCGIFADDR: 2342 args->cmd = SIOCGIFADDR; 2343 error = ioctl(td, (struct ioctl_args *)args); 2344 break; 2345 case LINUX_SIOCSIFADDR: 2346 args->cmd = SIOCSIFADDR; 2347 error = ioctl(td, (struct ioctl_args *)args); 2348 break; 2349 case LINUX_SIOCGIFFLAGS: 2350 args->cmd = SIOCGIFFLAGS; 2351 error = ioctl(td, (struct ioctl_args *)args); 2352 break; 2353 default: 2354 error = ENOIOCTL; 2355 } 2356 2357 return (error); 2358} 2359 2360/* 2361 * main ioctl syscall function 2362 */ 2363 2364int 2365linux_ioctl(struct thread *td, struct linux_ioctl_args *args) 2366{ 2367 struct file *fp; 2368 struct handler_element *he; 2369 int error, cmd; 2370 2371#ifdef DEBUG 2372 if (ldebug(ioctl)) 2373 printf(ARGS(ioctl, "%d, %04lx, *"), args->fd, 2374 (unsigned long)args->cmd); 2375#endif 2376 2377 if ((error = fget(td, args->fd, &fp)) != 0) 2378 return (error); 2379 if ((fp->f_flag & (FREAD|FWRITE)) == 0) { 2380 fdrop(fp, td); 2381 return (EBADF); 2382 } 2383 2384 /* Iterate over the ioctl handlers */ 2385 cmd = args->cmd & 0xffff; 2386 TAILQ_FOREACH(he, &handlers, list) { 2387 if (cmd >= he->low && cmd <= he->high) { 2388 error = (*he->func)(td, args); 2389 if (error != ENOIOCTL) { 2390 fdrop(fp, td); 2391 return (error); 2392 } 2393 } 2394 } 2395 fdrop(fp, td); 2396 2397 linux_msg(td, "ioctl fd=%d, cmd=0x%x ('%c',%d) is not implemented", 2398 args->fd, (int)(args->cmd & 0xffff), 2399 (int)(args->cmd & 0xff00) >> 8, (int)(args->cmd & 0xff)); 2400 2401 return (EINVAL); 2402} 2403 2404int 2405linux_ioctl_register_handler(struct linux_ioctl_handler *h) 2406{ 2407 struct handler_element *he, *cur; 2408 2409 if (h == NULL || h->func == NULL) 2410 return (EINVAL); 2411 2412 /* 2413 * Reuse the element if the handler is already on the list, otherwise 2414 * create a new element. 2415 */ 2416 TAILQ_FOREACH(he, &handlers, list) { 2417 if (he->func == h->func) 2418 break; 2419 } 2420 if (he == NULL) { 2421 MALLOC(he, struct handler_element *, sizeof(*he), 2422 M_LINUX, M_WAITOK); 2423 he->func = h->func; 2424 } else 2425 TAILQ_REMOVE(&handlers, he, list);
| 2298 case LINUX_SIOCDEVPRIVATE+1: 2299 args->cmd = SIOCGPRIVATE_1; 2300 error = ioctl(td, (struct ioctl_args *)args); 2301 break; 2302 } 2303 2304 if (ifp != NULL) 2305 /* restore the original interface name */ 2306 copyout(lifname, (char *)args->arg, LINUX_IFNAMSIZ); 2307 2308#ifdef DEBUG 2309 printf("%s(): returning %d\n", __func__, error); 2310#endif 2311 return (error); 2312} 2313 2314/* 2315 * Device private ioctl handler 2316 */ 2317static int 2318linux_ioctl_private(struct thread *td, struct linux_ioctl_args *args) 2319{ 2320 struct file *fp; 2321 int error, type; 2322 2323 if ((error = fget(td, args->fd, &fp)) != 0) 2324 return (error); 2325 type = fp->f_type; 2326 fdrop(fp, td); 2327 if (type == DTYPE_SOCKET) 2328 return (linux_ioctl_socket(td, args)); 2329 return (ENOIOCTL); 2330} 2331 2332/* 2333 * Special ioctl handler 2334 */ 2335static int 2336linux_ioctl_special(struct thread *td, struct linux_ioctl_args *args) 2337{ 2338 int error; 2339 2340 switch (args->cmd) { 2341 case LINUX_SIOCGIFADDR: 2342 args->cmd = SIOCGIFADDR; 2343 error = ioctl(td, (struct ioctl_args *)args); 2344 break; 2345 case LINUX_SIOCSIFADDR: 2346 args->cmd = SIOCSIFADDR; 2347 error = ioctl(td, (struct ioctl_args *)args); 2348 break; 2349 case LINUX_SIOCGIFFLAGS: 2350 args->cmd = SIOCGIFFLAGS; 2351 error = ioctl(td, (struct ioctl_args *)args); 2352 break; 2353 default: 2354 error = ENOIOCTL; 2355 } 2356 2357 return (error); 2358} 2359 2360/* 2361 * main ioctl syscall function 2362 */ 2363 2364int 2365linux_ioctl(struct thread *td, struct linux_ioctl_args *args) 2366{ 2367 struct file *fp; 2368 struct handler_element *he; 2369 int error, cmd; 2370 2371#ifdef DEBUG 2372 if (ldebug(ioctl)) 2373 printf(ARGS(ioctl, "%d, %04lx, *"), args->fd, 2374 (unsigned long)args->cmd); 2375#endif 2376 2377 if ((error = fget(td, args->fd, &fp)) != 0) 2378 return (error); 2379 if ((fp->f_flag & (FREAD|FWRITE)) == 0) { 2380 fdrop(fp, td); 2381 return (EBADF); 2382 } 2383 2384 /* Iterate over the ioctl handlers */ 2385 cmd = args->cmd & 0xffff; 2386 TAILQ_FOREACH(he, &handlers, list) { 2387 if (cmd >= he->low && cmd <= he->high) { 2388 error = (*he->func)(td, args); 2389 if (error != ENOIOCTL) { 2390 fdrop(fp, td); 2391 return (error); 2392 } 2393 } 2394 } 2395 fdrop(fp, td); 2396 2397 linux_msg(td, "ioctl fd=%d, cmd=0x%x ('%c',%d) is not implemented", 2398 args->fd, (int)(args->cmd & 0xffff), 2399 (int)(args->cmd & 0xff00) >> 8, (int)(args->cmd & 0xff)); 2400 2401 return (EINVAL); 2402} 2403 2404int 2405linux_ioctl_register_handler(struct linux_ioctl_handler *h) 2406{ 2407 struct handler_element *he, *cur; 2408 2409 if (h == NULL || h->func == NULL) 2410 return (EINVAL); 2411 2412 /* 2413 * Reuse the element if the handler is already on the list, otherwise 2414 * create a new element. 2415 */ 2416 TAILQ_FOREACH(he, &handlers, list) { 2417 if (he->func == h->func) 2418 break; 2419 } 2420 if (he == NULL) { 2421 MALLOC(he, struct handler_element *, sizeof(*he), 2422 M_LINUX, M_WAITOK); 2423 he->func = h->func; 2424 } else 2425 TAILQ_REMOVE(&handlers, he, list);
|
2426
| 2426
|
2427 /* Initialize range information. */ 2428 he->low = h->low; 2429 he->high = h->high; 2430 he->span = h->high - h->low + 1; 2431 2432 /* Add the element to the list, sorted on span. */ 2433 TAILQ_FOREACH(cur, &handlers, list) { 2434 if (cur->span > he->span) { 2435 TAILQ_INSERT_BEFORE(cur, he, list); 2436 return (0); 2437 } 2438 } 2439 TAILQ_INSERT_TAIL(&handlers, he, list); 2440 2441 return (0); 2442} 2443 2444int 2445linux_ioctl_unregister_handler(struct linux_ioctl_handler *h) 2446{ 2447 struct handler_element *he; 2448 2449 if (h == NULL || h->func == NULL) 2450 return (EINVAL); 2451 2452 TAILQ_FOREACH(he, &handlers, list) { 2453 if (he->func == h->func) { 2454 TAILQ_REMOVE(&handlers, he, list); 2455 FREE(he, M_LINUX); 2456 return (0); 2457 } 2458 } 2459 2460 return (EINVAL); 2461}
| 2427 /* Initialize range information. */ 2428 he->low = h->low; 2429 he->high = h->high; 2430 he->span = h->high - h->low + 1; 2431 2432 /* Add the element to the list, sorted on span. */ 2433 TAILQ_FOREACH(cur, &handlers, list) { 2434 if (cur->span > he->span) { 2435 TAILQ_INSERT_BEFORE(cur, he, list); 2436 return (0); 2437 } 2438 } 2439 TAILQ_INSERT_TAIL(&handlers, he, list); 2440 2441 return (0); 2442} 2443 2444int 2445linux_ioctl_unregister_handler(struct linux_ioctl_handler *h) 2446{ 2447 struct handler_element *he; 2448 2449 if (h == NULL || h->func == NULL) 2450 return (EINVAL); 2451 2452 TAILQ_FOREACH(he, &handlers, list) { 2453 if (he->func == h->func) { 2454 TAILQ_REMOVE(&handlers, he, list); 2455 FREE(he, M_LINUX); 2456 return (0); 2457 } 2458 } 2459 2460 return (EINVAL); 2461}
|