2 * Copyright (c) 1994-1995 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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
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.
29 #include "opt_compat.h"
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/sysproto.h>
37 #include <sys/capsicum.h>
39 #include <sys/dvdio.h>
42 #include <sys/consio.h>
43 #include <sys/ctype.h>
44 #include <sys/fcntl.h>
46 #include <sys/filedesc.h>
47 #include <sys/filio.h>
50 #include <sys/kernel.h>
51 #include <sys/linker_set.h>
53 #include <sys/malloc.h>
56 #include <sys/socket.h>
57 #include <sys/sockio.h>
58 #include <sys/soundcard.h>
59 #include <sys/stdint.h>
61 #include <sys/sysctl.h>
64 #include <sys/types.h>
66 #include <sys/resourcevar.h>
69 #include <net/if_dl.h>
70 #include <net/if_types.h>
72 #include <dev/usb/usb_ioctl.h>
75 #include <machine/../linux32/linux.h>
76 #include <machine/../linux32/linux32_proto.h>
78 #include <machine/../linux/linux.h>
79 #include <machine/../linux/linux_proto.h>
82 #include <compat/linux/linux_ioctl.h>
83 #include <compat/linux/linux_mib.h>
84 #include <compat/linux/linux_socket.h>
85 #include <compat/linux/linux_util.h>
87 #include <contrib/v4l/videodev.h>
88 #include <compat/linux/linux_videodev_compat.h>
90 #include <contrib/v4l/videodev2.h>
91 #include <compat/linux/linux_videodev2_compat.h>
93 #include <cam/scsi/scsi_sg.h>
95 CTASSERT(LINUX_IFNAMSIZ == IFNAMSIZ);
97 static linux_ioctl_function_t linux_ioctl_cdrom;
98 static linux_ioctl_function_t linux_ioctl_vfat;
99 static linux_ioctl_function_t linux_ioctl_console;
100 static linux_ioctl_function_t linux_ioctl_hdio;
101 static linux_ioctl_function_t linux_ioctl_disk;
102 static linux_ioctl_function_t linux_ioctl_socket;
103 static linux_ioctl_function_t linux_ioctl_sound;
104 static linux_ioctl_function_t linux_ioctl_termio;
105 static linux_ioctl_function_t linux_ioctl_private;
106 static linux_ioctl_function_t linux_ioctl_drm;
107 static linux_ioctl_function_t linux_ioctl_sg;
108 static linux_ioctl_function_t linux_ioctl_v4l;
109 static linux_ioctl_function_t linux_ioctl_v4l2;
110 static linux_ioctl_function_t linux_ioctl_special;
111 static linux_ioctl_function_t linux_ioctl_fbsd_usb;
113 static struct linux_ioctl_handler cdrom_handler =
114 { linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN, LINUX_IOCTL_CDROM_MAX };
115 static struct linux_ioctl_handler vfat_handler =
116 { linux_ioctl_vfat, LINUX_IOCTL_VFAT_MIN, LINUX_IOCTL_VFAT_MAX };
117 static struct linux_ioctl_handler console_handler =
118 { linux_ioctl_console, LINUX_IOCTL_CONSOLE_MIN, LINUX_IOCTL_CONSOLE_MAX };
119 static struct linux_ioctl_handler hdio_handler =
120 { linux_ioctl_hdio, LINUX_IOCTL_HDIO_MIN, LINUX_IOCTL_HDIO_MAX };
121 static struct linux_ioctl_handler disk_handler =
122 { linux_ioctl_disk, LINUX_IOCTL_DISK_MIN, LINUX_IOCTL_DISK_MAX };
123 static struct linux_ioctl_handler socket_handler =
124 { linux_ioctl_socket, LINUX_IOCTL_SOCKET_MIN, LINUX_IOCTL_SOCKET_MAX };
125 static struct linux_ioctl_handler sound_handler =
126 { linux_ioctl_sound, LINUX_IOCTL_SOUND_MIN, LINUX_IOCTL_SOUND_MAX };
127 static struct linux_ioctl_handler termio_handler =
128 { linux_ioctl_termio, LINUX_IOCTL_TERMIO_MIN, LINUX_IOCTL_TERMIO_MAX };
129 static struct linux_ioctl_handler private_handler =
130 { linux_ioctl_private, LINUX_IOCTL_PRIVATE_MIN, LINUX_IOCTL_PRIVATE_MAX };
131 static struct linux_ioctl_handler drm_handler =
132 { linux_ioctl_drm, LINUX_IOCTL_DRM_MIN, LINUX_IOCTL_DRM_MAX };
133 static struct linux_ioctl_handler sg_handler =
134 { linux_ioctl_sg, LINUX_IOCTL_SG_MIN, LINUX_IOCTL_SG_MAX };
135 static struct linux_ioctl_handler video_handler =
136 { linux_ioctl_v4l, LINUX_IOCTL_VIDEO_MIN, LINUX_IOCTL_VIDEO_MAX };
137 static struct linux_ioctl_handler video2_handler =
138 { linux_ioctl_v4l2, LINUX_IOCTL_VIDEO2_MIN, LINUX_IOCTL_VIDEO2_MAX };
139 static struct linux_ioctl_handler fbsd_usb =
140 { linux_ioctl_fbsd_usb, FBSD_LUSB_MIN, FBSD_LUSB_MAX };
142 DATA_SET(linux_ioctl_handler_set, cdrom_handler);
143 DATA_SET(linux_ioctl_handler_set, vfat_handler);
144 DATA_SET(linux_ioctl_handler_set, console_handler);
145 DATA_SET(linux_ioctl_handler_set, hdio_handler);
146 DATA_SET(linux_ioctl_handler_set, disk_handler);
147 DATA_SET(linux_ioctl_handler_set, socket_handler);
148 DATA_SET(linux_ioctl_handler_set, sound_handler);
149 DATA_SET(linux_ioctl_handler_set, termio_handler);
150 DATA_SET(linux_ioctl_handler_set, private_handler);
151 DATA_SET(linux_ioctl_handler_set, drm_handler);
152 DATA_SET(linux_ioctl_handler_set, sg_handler);
153 DATA_SET(linux_ioctl_handler_set, video_handler);
154 DATA_SET(linux_ioctl_handler_set, video2_handler);
155 DATA_SET(linux_ioctl_handler_set, fbsd_usb);
157 struct handler_element
159 TAILQ_ENTRY(handler_element) list;
160 int (*func)(struct thread *, struct linux_ioctl_args *);
164 static TAILQ_HEAD(, handler_element) handlers =
165 TAILQ_HEAD_INITIALIZER(handlers);
166 static struct sx linux_ioctl_sx;
167 SX_SYSINIT(linux_ioctl, &linux_ioctl_sx, "linux ioctl handlers");
170 * hdio related ioctls for VMWare support
173 struct linux_hd_geometry {
180 struct linux_hd_big_geometry {
188 linux_ioctl_hdio(struct thread *td, struct linux_ioctl_args *args)
193 u_int sectorsize, fwcylinders, fwheads, fwsectors;
194 off_t mediasize, bytespercyl;
196 error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
199 switch (args->cmd & 0xffff) {
200 case LINUX_HDIO_GET_GEO:
201 case LINUX_HDIO_GET_GEO_BIG:
202 error = fo_ioctl(fp, DIOCGMEDIASIZE,
203 (caddr_t)&mediasize, td->td_ucred, td);
205 error = fo_ioctl(fp, DIOCGSECTORSIZE,
206 (caddr_t)§orsize, td->td_ucred, td);
208 error = fo_ioctl(fp, DIOCGFWHEADS,
209 (caddr_t)&fwheads, td->td_ucred, td);
211 error = fo_ioctl(fp, DIOCGFWSECTORS,
212 (caddr_t)&fwsectors, td->td_ucred, td);
214 * XXX: DIOCGFIRSTOFFSET is not yet implemented, so
215 * so pretend that GEOM always says 0. This is NOT VALID
216 * for slices or partitions, only the per-disk raw devices.
223 * 1. Calculate the number of bytes in a cylinder,
224 * given the firmware's notion of heads and sectors
226 * 2. Calculate the number of cylinders, given the total
228 * All internal calculations should have 64-bit precision.
230 bytespercyl = (off_t) sectorsize * fwheads * fwsectors;
231 fwcylinders = mediasize / bytespercyl;
233 linux_msg(td, "HDIO_GET_GEO: mediasize %jd, c/h/s %d/%d/%d, "
235 (intmax_t)mediasize, fwcylinders, fwheads, fwsectors,
236 (intmax_t)bytespercyl);
238 if ((args->cmd & 0xffff) == LINUX_HDIO_GET_GEO) {
239 struct linux_hd_geometry hdg;
241 hdg.cylinders = fwcylinders;
243 hdg.sectors = fwsectors;
245 error = copyout(&hdg, (void *)args->arg, sizeof(hdg));
246 } else if ((args->cmd & 0xffff) == LINUX_HDIO_GET_GEO_BIG) {
247 struct linux_hd_big_geometry hdbg;
249 memset(&hdbg, 0, sizeof(hdbg));
250 hdbg.cylinders = fwcylinders;
251 hdbg.heads = fwheads;
252 hdbg.sectors = fwsectors;
254 error = copyout(&hdbg, (void *)args->arg, sizeof(hdbg));
261 "ioctl fd=%d, cmd=0x%x ('%c',%d) is not implemented",
262 args->fd, (int)(args->cmd & 0xffff),
263 (int)(args->cmd & 0xff00) >> 8,
264 (int)(args->cmd & 0xff));
272 linux_ioctl_disk(struct thread *td, struct linux_ioctl_args *args)
280 error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
283 switch (args->cmd & 0xffff) {
284 case LINUX_BLKGETSIZE:
285 error = fo_ioctl(fp, DIOCGSECTORSIZE,
286 (caddr_t)§orsize, td->td_ucred, td);
288 error = fo_ioctl(fp, DIOCGMEDIASIZE,
289 (caddr_t)&mediasize, td->td_ucred, td);
293 sectorsize = mediasize / sectorsize;
295 * XXX: How do we know we return the right size of integer ?
297 return (copyout(§orsize, (void *)args->arg,
298 sizeof(sectorsize)));
300 case LINUX_BLKSSZGET:
301 error = fo_ioctl(fp, DIOCGSECTORSIZE,
302 (caddr_t)§orsize, td->td_ucred, td);
306 return (copyout(§orsize, (void *)args->arg,
307 sizeof(sectorsize)));
315 * termio related ioctls
318 struct linux_termio {
319 unsigned short c_iflag;
320 unsigned short c_oflag;
321 unsigned short c_cflag;
322 unsigned short c_lflag;
323 unsigned char c_line;
324 unsigned char c_cc[LINUX_NCC];
327 struct linux_termios {
328 unsigned int c_iflag;
329 unsigned int c_oflag;
330 unsigned int c_cflag;
331 unsigned int c_lflag;
332 unsigned char c_line;
333 unsigned char c_cc[LINUX_NCCS];
336 struct linux_winsize {
337 unsigned short ws_row, ws_col;
338 unsigned short ws_xpixel, ws_ypixel;
342 int sp_speed; /* Speed. */
343 int sp_code; /* Code. */
346 static struct speedtab sptab[] = {
347 { B0, LINUX_B0 }, { B50, LINUX_B50 },
348 { B75, LINUX_B75 }, { B110, LINUX_B110 },
349 { B134, LINUX_B134 }, { B150, LINUX_B150 },
350 { B200, LINUX_B200 }, { B300, LINUX_B300 },
351 { B600, LINUX_B600 }, { B1200, LINUX_B1200 },
352 { B1800, LINUX_B1800 }, { B2400, LINUX_B2400 },
353 { B4800, LINUX_B4800 }, { B9600, LINUX_B9600 },
354 { B19200, LINUX_B19200 }, { B38400, LINUX_B38400 },
355 { B57600, LINUX_B57600 }, { B115200, LINUX_B115200 },
359 struct linux_serial_struct {
368 unsigned short close_delay;
369 char reserved_char[2];
371 unsigned short closing_wait;
372 unsigned short closing_wait2;
377 linux_to_bsd_speed(int code, struct speedtab *table)
379 for ( ; table->sp_code != -1; table++)
380 if (table->sp_code == code)
381 return (table->sp_speed);
386 bsd_to_linux_speed(int speed, struct speedtab *table)
388 for ( ; table->sp_speed != -1; table++)
389 if (table->sp_speed == speed)
390 return (table->sp_code);
395 bsd_to_linux_termios(struct termios *bios, struct linux_termios *lios)
401 printf("LINUX: BSD termios structure (input):\n");
402 printf("i=%08x o=%08x c=%08x l=%08x ispeed=%d ospeed=%d\n",
403 bios->c_iflag, bios->c_oflag, bios->c_cflag, bios->c_lflag,
404 bios->c_ispeed, bios->c_ospeed);
406 for (i=0; i<NCCS; i++)
407 printf("%02x ", bios->c_cc[i]);
413 if (bios->c_iflag & IGNBRK)
414 lios->c_iflag |= LINUX_IGNBRK;
415 if (bios->c_iflag & BRKINT)
416 lios->c_iflag |= LINUX_BRKINT;
417 if (bios->c_iflag & IGNPAR)
418 lios->c_iflag |= LINUX_IGNPAR;
419 if (bios->c_iflag & PARMRK)
420 lios->c_iflag |= LINUX_PARMRK;
421 if (bios->c_iflag & INPCK)
422 lios->c_iflag |= LINUX_INPCK;
423 if (bios->c_iflag & ISTRIP)
424 lios->c_iflag |= LINUX_ISTRIP;
425 if (bios->c_iflag & INLCR)
426 lios->c_iflag |= LINUX_INLCR;
427 if (bios->c_iflag & IGNCR)
428 lios->c_iflag |= LINUX_IGNCR;
429 if (bios->c_iflag & ICRNL)
430 lios->c_iflag |= LINUX_ICRNL;
431 if (bios->c_iflag & IXON)
432 lios->c_iflag |= LINUX_IXON;
433 if (bios->c_iflag & IXANY)
434 lios->c_iflag |= LINUX_IXANY;
435 if (bios->c_iflag & IXOFF)
436 lios->c_iflag |= LINUX_IXOFF;
437 if (bios->c_iflag & IMAXBEL)
438 lios->c_iflag |= LINUX_IMAXBEL;
441 if (bios->c_oflag & OPOST)
442 lios->c_oflag |= LINUX_OPOST;
443 if (bios->c_oflag & ONLCR)
444 lios->c_oflag |= LINUX_ONLCR;
445 if (bios->c_oflag & TAB3)
446 lios->c_oflag |= LINUX_XTABS;
448 lios->c_cflag = bsd_to_linux_speed(bios->c_ispeed, sptab);
449 lios->c_cflag |= (bios->c_cflag & CSIZE) >> 4;
450 if (bios->c_cflag & CSTOPB)
451 lios->c_cflag |= LINUX_CSTOPB;
452 if (bios->c_cflag & CREAD)
453 lios->c_cflag |= LINUX_CREAD;
454 if (bios->c_cflag & PARENB)
455 lios->c_cflag |= LINUX_PARENB;
456 if (bios->c_cflag & PARODD)
457 lios->c_cflag |= LINUX_PARODD;
458 if (bios->c_cflag & HUPCL)
459 lios->c_cflag |= LINUX_HUPCL;
460 if (bios->c_cflag & CLOCAL)
461 lios->c_cflag |= LINUX_CLOCAL;
462 if (bios->c_cflag & CRTSCTS)
463 lios->c_cflag |= LINUX_CRTSCTS;
466 if (bios->c_lflag & ISIG)
467 lios->c_lflag |= LINUX_ISIG;
468 if (bios->c_lflag & ICANON)
469 lios->c_lflag |= LINUX_ICANON;
470 if (bios->c_lflag & ECHO)
471 lios->c_lflag |= LINUX_ECHO;
472 if (bios->c_lflag & ECHOE)
473 lios->c_lflag |= LINUX_ECHOE;
474 if (bios->c_lflag & ECHOK)
475 lios->c_lflag |= LINUX_ECHOK;
476 if (bios->c_lflag & ECHONL)
477 lios->c_lflag |= LINUX_ECHONL;
478 if (bios->c_lflag & NOFLSH)
479 lios->c_lflag |= LINUX_NOFLSH;
480 if (bios->c_lflag & TOSTOP)
481 lios->c_lflag |= LINUX_TOSTOP;
482 if (bios->c_lflag & ECHOCTL)
483 lios->c_lflag |= LINUX_ECHOCTL;
484 if (bios->c_lflag & ECHOPRT)
485 lios->c_lflag |= LINUX_ECHOPRT;
486 if (bios->c_lflag & ECHOKE)
487 lios->c_lflag |= LINUX_ECHOKE;
488 if (bios->c_lflag & FLUSHO)
489 lios->c_lflag |= LINUX_FLUSHO;
490 if (bios->c_lflag & PENDIN)
491 lios->c_lflag |= LINUX_PENDIN;
492 if (bios->c_lflag & IEXTEN)
493 lios->c_lflag |= LINUX_IEXTEN;
495 for (i=0; i<LINUX_NCCS; i++)
496 lios->c_cc[i] = LINUX_POSIX_VDISABLE;
497 lios->c_cc[LINUX_VINTR] = bios->c_cc[VINTR];
498 lios->c_cc[LINUX_VQUIT] = bios->c_cc[VQUIT];
499 lios->c_cc[LINUX_VERASE] = bios->c_cc[VERASE];
500 lios->c_cc[LINUX_VKILL] = bios->c_cc[VKILL];
501 lios->c_cc[LINUX_VEOF] = bios->c_cc[VEOF];
502 lios->c_cc[LINUX_VEOL] = bios->c_cc[VEOL];
503 lios->c_cc[LINUX_VMIN] = bios->c_cc[VMIN];
504 lios->c_cc[LINUX_VTIME] = bios->c_cc[VTIME];
505 lios->c_cc[LINUX_VEOL2] = bios->c_cc[VEOL2];
506 lios->c_cc[LINUX_VSUSP] = bios->c_cc[VSUSP];
507 lios->c_cc[LINUX_VSTART] = bios->c_cc[VSTART];
508 lios->c_cc[LINUX_VSTOP] = bios->c_cc[VSTOP];
509 lios->c_cc[LINUX_VREPRINT] = bios->c_cc[VREPRINT];
510 lios->c_cc[LINUX_VDISCARD] = bios->c_cc[VDISCARD];
511 lios->c_cc[LINUX_VWERASE] = bios->c_cc[VWERASE];
512 lios->c_cc[LINUX_VLNEXT] = bios->c_cc[VLNEXT];
514 for (i=0; i<LINUX_NCCS; i++) {
515 if (i != LINUX_VMIN && i != LINUX_VTIME &&
516 lios->c_cc[i] == _POSIX_VDISABLE)
517 lios->c_cc[i] = LINUX_POSIX_VDISABLE;
523 printf("LINUX: LINUX termios structure (output):\n");
524 printf("i=%08x o=%08x c=%08x l=%08x line=%d\n",
525 lios->c_iflag, lios->c_oflag, lios->c_cflag,
526 lios->c_lflag, (int)lios->c_line);
528 for (i=0; i<LINUX_NCCS; i++)
529 printf("%02x ", lios->c_cc[i]);
536 linux_to_bsd_termios(struct linux_termios *lios, struct termios *bios)
542 printf("LINUX: LINUX termios structure (input):\n");
543 printf("i=%08x o=%08x c=%08x l=%08x line=%d\n",
544 lios->c_iflag, lios->c_oflag, lios->c_cflag,
545 lios->c_lflag, (int)lios->c_line);
547 for (i=0; i<LINUX_NCCS; i++)
548 printf("%02x ", lios->c_cc[i]);
554 if (lios->c_iflag & LINUX_IGNBRK)
555 bios->c_iflag |= IGNBRK;
556 if (lios->c_iflag & LINUX_BRKINT)
557 bios->c_iflag |= BRKINT;
558 if (lios->c_iflag & LINUX_IGNPAR)
559 bios->c_iflag |= IGNPAR;
560 if (lios->c_iflag & LINUX_PARMRK)
561 bios->c_iflag |= PARMRK;
562 if (lios->c_iflag & LINUX_INPCK)
563 bios->c_iflag |= INPCK;
564 if (lios->c_iflag & LINUX_ISTRIP)
565 bios->c_iflag |= ISTRIP;
566 if (lios->c_iflag & LINUX_INLCR)
567 bios->c_iflag |= INLCR;
568 if (lios->c_iflag & LINUX_IGNCR)
569 bios->c_iflag |= IGNCR;
570 if (lios->c_iflag & LINUX_ICRNL)
571 bios->c_iflag |= ICRNL;
572 if (lios->c_iflag & LINUX_IXON)
573 bios->c_iflag |= IXON;
574 if (lios->c_iflag & LINUX_IXANY)
575 bios->c_iflag |= IXANY;
576 if (lios->c_iflag & LINUX_IXOFF)
577 bios->c_iflag |= IXOFF;
578 if (lios->c_iflag & LINUX_IMAXBEL)
579 bios->c_iflag |= IMAXBEL;
582 if (lios->c_oflag & LINUX_OPOST)
583 bios->c_oflag |= OPOST;
584 if (lios->c_oflag & LINUX_ONLCR)
585 bios->c_oflag |= ONLCR;
586 if (lios->c_oflag & LINUX_XTABS)
587 bios->c_oflag |= TAB3;
589 bios->c_cflag = (lios->c_cflag & LINUX_CSIZE) << 4;
590 if (lios->c_cflag & LINUX_CSTOPB)
591 bios->c_cflag |= CSTOPB;
592 if (lios->c_cflag & LINUX_CREAD)
593 bios->c_cflag |= CREAD;
594 if (lios->c_cflag & LINUX_PARENB)
595 bios->c_cflag |= PARENB;
596 if (lios->c_cflag & LINUX_PARODD)
597 bios->c_cflag |= PARODD;
598 if (lios->c_cflag & LINUX_HUPCL)
599 bios->c_cflag |= HUPCL;
600 if (lios->c_cflag & LINUX_CLOCAL)
601 bios->c_cflag |= CLOCAL;
602 if (lios->c_cflag & LINUX_CRTSCTS)
603 bios->c_cflag |= CRTSCTS;
606 if (lios->c_lflag & LINUX_ISIG)
607 bios->c_lflag |= ISIG;
608 if (lios->c_lflag & LINUX_ICANON)
609 bios->c_lflag |= ICANON;
610 if (lios->c_lflag & LINUX_ECHO)
611 bios->c_lflag |= ECHO;
612 if (lios->c_lflag & LINUX_ECHOE)
613 bios->c_lflag |= ECHOE;
614 if (lios->c_lflag & LINUX_ECHOK)
615 bios->c_lflag |= ECHOK;
616 if (lios->c_lflag & LINUX_ECHONL)
617 bios->c_lflag |= ECHONL;
618 if (lios->c_lflag & LINUX_NOFLSH)
619 bios->c_lflag |= NOFLSH;
620 if (lios->c_lflag & LINUX_TOSTOP)
621 bios->c_lflag |= TOSTOP;
622 if (lios->c_lflag & LINUX_ECHOCTL)
623 bios->c_lflag |= ECHOCTL;
624 if (lios->c_lflag & LINUX_ECHOPRT)
625 bios->c_lflag |= ECHOPRT;
626 if (lios->c_lflag & LINUX_ECHOKE)
627 bios->c_lflag |= ECHOKE;
628 if (lios->c_lflag & LINUX_FLUSHO)
629 bios->c_lflag |= FLUSHO;
630 if (lios->c_lflag & LINUX_PENDIN)
631 bios->c_lflag |= PENDIN;
632 if (lios->c_lflag & LINUX_IEXTEN)
633 bios->c_lflag |= IEXTEN;
635 for (i=0; i<NCCS; i++)
636 bios->c_cc[i] = _POSIX_VDISABLE;
637 bios->c_cc[VINTR] = lios->c_cc[LINUX_VINTR];
638 bios->c_cc[VQUIT] = lios->c_cc[LINUX_VQUIT];
639 bios->c_cc[VERASE] = lios->c_cc[LINUX_VERASE];
640 bios->c_cc[VKILL] = lios->c_cc[LINUX_VKILL];
641 bios->c_cc[VEOF] = lios->c_cc[LINUX_VEOF];
642 bios->c_cc[VEOL] = lios->c_cc[LINUX_VEOL];
643 bios->c_cc[VMIN] = lios->c_cc[LINUX_VMIN];
644 bios->c_cc[VTIME] = lios->c_cc[LINUX_VTIME];
645 bios->c_cc[VEOL2] = lios->c_cc[LINUX_VEOL2];
646 bios->c_cc[VSUSP] = lios->c_cc[LINUX_VSUSP];
647 bios->c_cc[VSTART] = lios->c_cc[LINUX_VSTART];
648 bios->c_cc[VSTOP] = lios->c_cc[LINUX_VSTOP];
649 bios->c_cc[VREPRINT] = lios->c_cc[LINUX_VREPRINT];
650 bios->c_cc[VDISCARD] = lios->c_cc[LINUX_VDISCARD];
651 bios->c_cc[VWERASE] = lios->c_cc[LINUX_VWERASE];
652 bios->c_cc[VLNEXT] = lios->c_cc[LINUX_VLNEXT];
654 for (i=0; i<NCCS; i++) {
655 if (i != VMIN && i != VTIME &&
656 bios->c_cc[i] == LINUX_POSIX_VDISABLE)
657 bios->c_cc[i] = _POSIX_VDISABLE;
660 bios->c_ispeed = bios->c_ospeed =
661 linux_to_bsd_speed(lios->c_cflag & LINUX_CBAUD, sptab);
665 printf("LINUX: BSD termios structure (output):\n");
666 printf("i=%08x o=%08x c=%08x l=%08x ispeed=%d ospeed=%d\n",
667 bios->c_iflag, bios->c_oflag, bios->c_cflag, bios->c_lflag,
668 bios->c_ispeed, bios->c_ospeed);
670 for (i=0; i<NCCS; i++)
671 printf("%02x ", bios->c_cc[i]);
678 bsd_to_linux_termio(struct termios *bios, struct linux_termio *lio)
680 struct linux_termios lios;
682 bsd_to_linux_termios(bios, &lios);
683 lio->c_iflag = lios.c_iflag;
684 lio->c_oflag = lios.c_oflag;
685 lio->c_cflag = lios.c_cflag;
686 lio->c_lflag = lios.c_lflag;
687 lio->c_line = lios.c_line;
688 memcpy(lio->c_cc, lios.c_cc, LINUX_NCC);
692 linux_to_bsd_termio(struct linux_termio *lio, struct termios *bios)
694 struct linux_termios lios;
697 lios.c_iflag = lio->c_iflag;
698 lios.c_oflag = lio->c_oflag;
699 lios.c_cflag = lio->c_cflag;
700 lios.c_lflag = lio->c_lflag;
701 for (i=LINUX_NCC; i<LINUX_NCCS; i++)
702 lios.c_cc[i] = LINUX_POSIX_VDISABLE;
703 memcpy(lios.c_cc, lio->c_cc, LINUX_NCC);
704 linux_to_bsd_termios(&lios, bios);
708 linux_ioctl_termio(struct thread *td, struct linux_ioctl_args *args)
711 struct linux_termios lios;
712 struct linux_termio lio;
717 error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
721 switch (args->cmd & 0xffff) {
724 error = fo_ioctl(fp, TIOCGETA, (caddr_t)&bios, td->td_ucred,
728 bsd_to_linux_termios(&bios, &lios);
729 error = copyout(&lios, (void *)args->arg, sizeof(lios));
733 error = copyin((void *)args->arg, &lios, sizeof(lios));
736 linux_to_bsd_termios(&lios, &bios);
737 error = (fo_ioctl(fp, TIOCSETA, (caddr_t)&bios, td->td_ucred,
742 error = copyin((void *)args->arg, &lios, sizeof(lios));
745 linux_to_bsd_termios(&lios, &bios);
746 error = (fo_ioctl(fp, TIOCSETAW, (caddr_t)&bios, td->td_ucred,
751 error = copyin((void *)args->arg, &lios, sizeof(lios));
754 linux_to_bsd_termios(&lios, &bios);
755 error = (fo_ioctl(fp, TIOCSETAF, (caddr_t)&bios, td->td_ucred,
760 error = fo_ioctl(fp, TIOCGETA, (caddr_t)&bios, td->td_ucred,
764 bsd_to_linux_termio(&bios, &lio);
765 error = (copyout(&lio, (void *)args->arg, sizeof(lio)));
769 error = copyin((void *)args->arg, &lio, sizeof(lio));
772 linux_to_bsd_termio(&lio, &bios);
773 error = (fo_ioctl(fp, TIOCSETA, (caddr_t)&bios, td->td_ucred,
778 error = copyin((void *)args->arg, &lio, sizeof(lio));
781 linux_to_bsd_termio(&lio, &bios);
782 error = (fo_ioctl(fp, TIOCSETAW, (caddr_t)&bios, td->td_ucred,
787 error = copyin((void *)args->arg, &lio, sizeof(lio));
790 linux_to_bsd_termio(&lio, &bios);
791 error = (fo_ioctl(fp, TIOCSETAF, (caddr_t)&bios, td->td_ucred,
800 args->cmd = TIOCSTOP;
803 args->cmd = TIOCSTART;
808 struct write_args wr;
809 error = fo_ioctl(fp, TIOCGETA, (caddr_t)&bios,
814 c = (args->arg == LINUX_TCIOFF) ? VSTOP : VSTART;
816 if (c != _POSIX_VDISABLE) {
819 wr.nbyte = sizeof(c);
820 return (sys_write(td, &wr));
829 error = (sys_ioctl(td, (struct ioctl_args *)args));
842 case LINUX_TCIOFLUSH:
843 val = FREAD | FWRITE;
849 error = (fo_ioctl(fp,TIOCFLUSH,(caddr_t)&val,td->td_ucred,td));
854 args->cmd = TIOCEXCL;
855 error = (sys_ioctl(td, (struct ioctl_args *)args));
859 args->cmd = TIOCNXCL;
860 error = (sys_ioctl(td, (struct ioctl_args *)args));
863 case LINUX_TIOCSCTTY:
864 args->cmd = TIOCSCTTY;
865 error = (sys_ioctl(td, (struct ioctl_args *)args));
868 case LINUX_TIOCGPGRP:
869 args->cmd = TIOCGPGRP;
870 error = (sys_ioctl(td, (struct ioctl_args *)args));
873 case LINUX_TIOCSPGRP:
874 args->cmd = TIOCSPGRP;
875 error = (sys_ioctl(td, (struct ioctl_args *)args));
881 case LINUX_TIOCGWINSZ:
882 args->cmd = TIOCGWINSZ;
883 error = (sys_ioctl(td, (struct ioctl_args *)args));
886 case LINUX_TIOCSWINSZ:
887 args->cmd = TIOCSWINSZ;
888 error = (sys_ioctl(td, (struct ioctl_args *)args));
892 args->cmd = TIOCMGET;
893 error = (sys_ioctl(td, (struct ioctl_args *)args));
897 args->cmd = TIOCMBIS;
898 error = (sys_ioctl(td, (struct ioctl_args *)args));
902 args->cmd = TIOCMBIC;
903 error = (sys_ioctl(td, (struct ioctl_args *)args));
907 args->cmd = TIOCMSET;
908 error = (sys_ioctl(td, (struct ioctl_args *)args));
914 case LINUX_FIONREAD: /* LINUX_TIOCINQ */
915 args->cmd = FIONREAD;
916 error = (sys_ioctl(td, (struct ioctl_args *)args));
919 /* LINUX_TIOCLINUX */
922 args->cmd = TIOCCONS;
923 error = (sys_ioctl(td, (struct ioctl_args *)args));
926 case LINUX_TIOCGSERIAL: {
927 struct linux_serial_struct lss;
929 bzero(&lss, sizeof(lss));
930 lss.type = LINUX_PORT_16550A;
933 error = copyout(&lss, (void *)args->arg, sizeof(lss));
937 case LINUX_TIOCSSERIAL: {
938 struct linux_serial_struct lss;
939 error = copyin((void *)args->arg, &lss, sizeof(lss));
942 /* XXX - It really helps to have an implementation that
951 error = (sys_ioctl(td, (struct ioctl_args *)args));
956 error = (sys_ioctl(td, (struct ioctl_args *)args));
959 case LINUX_TIOCNOTTY:
960 args->cmd = TIOCNOTTY;
961 error = (sys_ioctl(td, (struct ioctl_args *)args));
964 case LINUX_TIOCSETD: {
980 error = (fo_ioctl(fp, TIOCSETD, (caddr_t)&line, td->td_ucred,
985 case LINUX_TIOCGETD: {
987 int bsd_line = TTYDISC;
988 error = fo_ioctl(fp, TIOCGETD, (caddr_t)&bsd_line,
994 linux_line = LINUX_N_TTY;
997 linux_line = LINUX_N_SLIP;
1000 linux_line = LINUX_N_PPP;
1006 error = (copyout(&linux_line, (void *)args->arg, sizeof(int)));
1011 /* LINUX_TIOCTTYGSTRUCT */
1013 case LINUX_FIONCLEX:
1014 args->cmd = FIONCLEX;
1015 error = (sys_ioctl(td, (struct ioctl_args *)args));
1019 args->cmd = FIOCLEX;
1020 error = (sys_ioctl(td, (struct ioctl_args *)args));
1023 case LINUX_FIOASYNC:
1024 args->cmd = FIOASYNC;
1025 error = (sys_ioctl(td, (struct ioctl_args *)args));
1028 /* LINUX_TIOCSERCONFIG */
1029 /* LINUX_TIOCSERGWILD */
1030 /* LINUX_TIOCSERSWILD */
1031 /* LINUX_TIOCGLCKTRMIOS */
1032 /* LINUX_TIOCSLCKTRMIOS */
1034 case LINUX_TIOCSBRK:
1035 args->cmd = TIOCSBRK;
1036 error = (sys_ioctl(td, (struct ioctl_args *)args));
1039 case LINUX_TIOCCBRK:
1040 args->cmd = TIOCCBRK;
1041 error = (sys_ioctl(td, (struct ioctl_args *)args));
1043 case LINUX_TIOCGPTN: {
1046 error = fo_ioctl(fp, TIOCGPTN, (caddr_t)&nb, td->td_ucred, td);
1048 error = copyout(&nb, (void *)args->arg,
1052 case LINUX_TIOCSPTLCK:
1053 /* Our unlockpt() does nothing. */
1066 * CDROM related ioctls
1069 struct linux_cdrom_msf
1073 u_char cdmsf_frame0;
1076 u_char cdmsf_frame1;
1079 struct linux_cdrom_tochdr
1085 union linux_cdrom_addr
1095 struct linux_cdrom_tocentry
1101 union linux_cdrom_addr cdte_addr;
1102 u_char cdte_datamode;
1105 struct linux_cdrom_subchnl
1108 u_char cdsc_audiostatus;
1113 union linux_cdrom_addr cdsc_absaddr;
1114 union linux_cdrom_addr cdsc_reladdr;
1117 struct l_cdrom_read_audio {
1118 union linux_cdrom_addr addr;
1124 struct l_dvd_layer {
1125 u_char book_version:4;
1129 u_char layer_type:4;
1130 u_char track_path:1;
1132 u_char track_density:4;
1133 u_char linear_density:4;
1135 u_int32_t start_sector;
1136 u_int32_t end_sector;
1137 u_int32_t end_sector_l0;
1140 struct l_dvd_physical {
1143 struct l_dvd_layer layer[4];
1146 struct l_dvd_copyright {
1153 struct l_dvd_disckey {
1165 struct l_dvd_manufact {
1174 struct l_dvd_physical physical;
1175 struct l_dvd_copyright copyright;
1176 struct l_dvd_disckey disckey;
1177 struct l_dvd_bca bca;
1178 struct l_dvd_manufact manufact;
1181 typedef u_char l_dvd_key[5];
1182 typedef u_char l_dvd_challenge[10];
1184 struct l_dvd_lu_send_agid {
1189 struct l_dvd_host_send_challenge {
1192 l_dvd_challenge chal;
1195 struct l_dvd_send_key {
1201 struct l_dvd_lu_send_challenge {
1204 l_dvd_challenge chal;
1207 struct l_dvd_lu_send_title_key {
1210 l_dvd_key title_key;
1217 struct l_dvd_lu_send_asf {
1223 struct l_dvd_host_send_rpcstate {
1228 struct l_dvd_lu_send_rpcstate {
1238 struct l_dvd_lu_send_agid lsa;
1239 struct l_dvd_host_send_challenge hsc;
1240 struct l_dvd_send_key lsk;
1241 struct l_dvd_lu_send_challenge lsc;
1242 struct l_dvd_send_key hsk;
1243 struct l_dvd_lu_send_title_key lstk;
1244 struct l_dvd_lu_send_asf lsasf;
1245 struct l_dvd_host_send_rpcstate hrpcs;
1246 struct l_dvd_lu_send_rpcstate lrpcs;
1250 bsd_to_linux_msf_lba(u_char af, union msf_lba *bp, union linux_cdrom_addr *lp)
1252 if (af == CD_LBA_FORMAT)
1255 lp->msf.minute = bp->msf.minute;
1256 lp->msf.second = bp->msf.second;
1257 lp->msf.frame = bp->msf.frame;
1262 set_linux_cdrom_addr(union linux_cdrom_addr *addr, int format, int lba)
1264 if (format == LINUX_CDROM_MSF) {
1265 addr->msf.frame = lba % 75;
1268 addr->msf.second = lba % 60;
1269 addr->msf.minute = lba / 60;
1275 linux_to_bsd_dvd_struct(l_dvd_struct *lp, struct dvd_struct *bp)
1277 bp->format = lp->type;
1278 switch (bp->format) {
1279 case DVD_STRUCT_PHYSICAL:
1280 if (bp->layer_num >= 4)
1282 bp->layer_num = lp->physical.layer_num;
1284 case DVD_STRUCT_COPYRIGHT:
1285 bp->layer_num = lp->copyright.layer_num;
1287 case DVD_STRUCT_DISCKEY:
1288 bp->agid = lp->disckey.agid;
1290 case DVD_STRUCT_BCA:
1291 case DVD_STRUCT_MANUFACT:
1300 bsd_to_linux_dvd_struct(struct dvd_struct *bp, l_dvd_struct *lp)
1302 switch (bp->format) {
1303 case DVD_STRUCT_PHYSICAL: {
1304 struct dvd_layer *blp = (struct dvd_layer *)bp->data;
1305 struct l_dvd_layer *llp = &lp->physical.layer[bp->layer_num];
1306 memset(llp, 0, sizeof(*llp));
1307 llp->book_version = blp->book_version;
1308 llp->book_type = blp->book_type;
1309 llp->min_rate = blp->max_rate;
1310 llp->disc_size = blp->disc_size;
1311 llp->layer_type = blp->layer_type;
1312 llp->track_path = blp->track_path;
1313 llp->nlayers = blp->nlayers;
1314 llp->track_density = blp->track_density;
1315 llp->linear_density = blp->linear_density;
1316 llp->bca = blp->bca;
1317 llp->start_sector = blp->start_sector;
1318 llp->end_sector = blp->end_sector;
1319 llp->end_sector_l0 = blp->end_sector_l0;
1322 case DVD_STRUCT_COPYRIGHT:
1323 lp->copyright.cpst = bp->cpst;
1324 lp->copyright.rmi = bp->rmi;
1326 case DVD_STRUCT_DISCKEY:
1327 memcpy(lp->disckey.value, bp->data, sizeof(lp->disckey.value));
1329 case DVD_STRUCT_BCA:
1330 lp->bca.len = bp->length;
1331 memcpy(lp->bca.value, bp->data, sizeof(lp->bca.value));
1333 case DVD_STRUCT_MANUFACT:
1334 lp->manufact.len = bp->length;
1335 memcpy(lp->manufact.value, bp->data,
1336 sizeof(lp->manufact.value));
1337 /* lp->manufact.layer_num is unused in linux (redhat 7.0) */
1346 linux_to_bsd_dvd_authinfo(l_dvd_authinfo *lp, int *bcode,
1347 struct dvd_authinfo *bp)
1350 case LINUX_DVD_LU_SEND_AGID:
1351 *bcode = DVDIOCREPORTKEY;
1352 bp->format = DVD_REPORT_AGID;
1353 bp->agid = lp->lsa.agid;
1355 case LINUX_DVD_HOST_SEND_CHALLENGE:
1356 *bcode = DVDIOCSENDKEY;
1357 bp->format = DVD_SEND_CHALLENGE;
1358 bp->agid = lp->hsc.agid;
1359 memcpy(bp->keychal, lp->hsc.chal, 10);
1361 case LINUX_DVD_LU_SEND_KEY1:
1362 *bcode = DVDIOCREPORTKEY;
1363 bp->format = DVD_REPORT_KEY1;
1364 bp->agid = lp->lsk.agid;
1366 case LINUX_DVD_LU_SEND_CHALLENGE:
1367 *bcode = DVDIOCREPORTKEY;
1368 bp->format = DVD_REPORT_CHALLENGE;
1369 bp->agid = lp->lsc.agid;
1371 case LINUX_DVD_HOST_SEND_KEY2:
1372 *bcode = DVDIOCSENDKEY;
1373 bp->format = DVD_SEND_KEY2;
1374 bp->agid = lp->hsk.agid;
1375 memcpy(bp->keychal, lp->hsk.key, 5);
1377 case LINUX_DVD_LU_SEND_TITLE_KEY:
1378 *bcode = DVDIOCREPORTKEY;
1379 bp->format = DVD_REPORT_TITLE_KEY;
1380 bp->agid = lp->lstk.agid;
1381 bp->lba = lp->lstk.lba;
1383 case LINUX_DVD_LU_SEND_ASF:
1384 *bcode = DVDIOCREPORTKEY;
1385 bp->format = DVD_REPORT_ASF;
1386 bp->agid = lp->lsasf.agid;
1388 case LINUX_DVD_INVALIDATE_AGID:
1389 *bcode = DVDIOCREPORTKEY;
1390 bp->format = DVD_INVALIDATE_AGID;
1391 bp->agid = lp->lsa.agid;
1393 case LINUX_DVD_LU_SEND_RPC_STATE:
1394 *bcode = DVDIOCREPORTKEY;
1395 bp->format = DVD_REPORT_RPC;
1397 case LINUX_DVD_HOST_SEND_RPC_STATE:
1398 *bcode = DVDIOCSENDKEY;
1399 bp->format = DVD_SEND_RPC;
1400 bp->region = lp->hrpcs.pdrc;
1409 bsd_to_linux_dvd_authinfo(struct dvd_authinfo *bp, l_dvd_authinfo *lp)
1412 case LINUX_DVD_LU_SEND_AGID:
1413 lp->lsa.agid = bp->agid;
1415 case LINUX_DVD_HOST_SEND_CHALLENGE:
1416 lp->type = LINUX_DVD_LU_SEND_KEY1;
1418 case LINUX_DVD_LU_SEND_KEY1:
1419 memcpy(lp->lsk.key, bp->keychal, sizeof(lp->lsk.key));
1421 case LINUX_DVD_LU_SEND_CHALLENGE:
1422 memcpy(lp->lsc.chal, bp->keychal, sizeof(lp->lsc.chal));
1424 case LINUX_DVD_HOST_SEND_KEY2:
1425 lp->type = LINUX_DVD_AUTH_ESTABLISHED;
1427 case LINUX_DVD_LU_SEND_TITLE_KEY:
1428 memcpy(lp->lstk.title_key, bp->keychal,
1429 sizeof(lp->lstk.title_key));
1430 lp->lstk.cpm = bp->cpm;
1431 lp->lstk.cp_sec = bp->cp_sec;
1432 lp->lstk.cgms = bp->cgms;
1434 case LINUX_DVD_LU_SEND_ASF:
1435 lp->lsasf.asf = bp->asf;
1437 case LINUX_DVD_INVALIDATE_AGID:
1439 case LINUX_DVD_LU_SEND_RPC_STATE:
1440 lp->lrpcs.type = bp->reg_type;
1441 lp->lrpcs.vra = bp->vend_rsts;
1442 lp->lrpcs.ucca = bp->user_rsts;
1443 lp->lrpcs.region_mask = bp->region;
1444 lp->lrpcs.rpc_scheme = bp->rpc_scheme;
1446 case LINUX_DVD_HOST_SEND_RPC_STATE:
1455 linux_ioctl_cdrom(struct thread *td, struct linux_ioctl_args *args)
1457 cap_rights_t rights;
1461 error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
1464 switch (args->cmd & 0xffff) {
1466 case LINUX_CDROMPAUSE:
1467 args->cmd = CDIOCPAUSE;
1468 error = (sys_ioctl(td, (struct ioctl_args *)args));
1471 case LINUX_CDROMRESUME:
1472 args->cmd = CDIOCRESUME;
1473 error = (sys_ioctl(td, (struct ioctl_args *)args));
1476 case LINUX_CDROMPLAYMSF:
1477 args->cmd = CDIOCPLAYMSF;
1478 error = (sys_ioctl(td, (struct ioctl_args *)args));
1481 case LINUX_CDROMPLAYTRKIND:
1482 args->cmd = CDIOCPLAYTRACKS;
1483 error = (sys_ioctl(td, (struct ioctl_args *)args));
1486 case LINUX_CDROMREADTOCHDR: {
1487 struct ioc_toc_header th;
1488 struct linux_cdrom_tochdr lth;
1489 error = fo_ioctl(fp, CDIOREADTOCHEADER, (caddr_t)&th,
1492 lth.cdth_trk0 = th.starting_track;
1493 lth.cdth_trk1 = th.ending_track;
1494 copyout(<h, (void *)args->arg, sizeof(lth));
1499 case LINUX_CDROMREADTOCENTRY: {
1500 struct linux_cdrom_tocentry lte;
1501 struct ioc_read_toc_single_entry irtse;
1503 error = copyin((void *)args->arg, <e, sizeof(lte));
1506 irtse.address_format = lte.cdte_format;
1507 irtse.track = lte.cdte_track;
1508 error = fo_ioctl(fp, CDIOREADTOCENTRY, (caddr_t)&irtse,
1511 lte.cdte_ctrl = irtse.entry.control;
1512 lte.cdte_adr = irtse.entry.addr_type;
1513 bsd_to_linux_msf_lba(irtse.address_format,
1514 &irtse.entry.addr, <e.cdte_addr);
1515 error = copyout(<e, (void *)args->arg, sizeof(lte));
1520 case LINUX_CDROMSTOP:
1521 args->cmd = CDIOCSTOP;
1522 error = (sys_ioctl(td, (struct ioctl_args *)args));
1525 case LINUX_CDROMSTART:
1526 args->cmd = CDIOCSTART;
1527 error = (sys_ioctl(td, (struct ioctl_args *)args));
1530 case LINUX_CDROMEJECT:
1531 args->cmd = CDIOCEJECT;
1532 error = (sys_ioctl(td, (struct ioctl_args *)args));
1535 /* LINUX_CDROMVOLCTRL */
1537 case LINUX_CDROMSUBCHNL: {
1538 struct linux_cdrom_subchnl sc;
1539 struct ioc_read_subchannel bsdsc;
1540 struct cd_sub_channel_info bsdinfo;
1542 bsdsc.address_format = CD_LBA_FORMAT;
1543 bsdsc.data_format = CD_CURRENT_POSITION;
1545 bsdsc.data_len = sizeof(bsdinfo);
1546 bsdsc.data = &bsdinfo;
1547 error = fo_ioctl(fp, CDIOCREADSUBCHANNEL_SYSSPACE,
1548 (caddr_t)&bsdsc, td->td_ucred, td);
1551 error = copyin((void *)args->arg, &sc, sizeof(sc));
1554 sc.cdsc_audiostatus = bsdinfo.header.audio_status;
1555 sc.cdsc_adr = bsdinfo.what.position.addr_type;
1556 sc.cdsc_ctrl = bsdinfo.what.position.control;
1557 sc.cdsc_trk = bsdinfo.what.position.track_number;
1558 sc.cdsc_ind = bsdinfo.what.position.index_number;
1559 set_linux_cdrom_addr(&sc.cdsc_absaddr, sc.cdsc_format,
1560 bsdinfo.what.position.absaddr.lba);
1561 set_linux_cdrom_addr(&sc.cdsc_reladdr, sc.cdsc_format,
1562 bsdinfo.what.position.reladdr.lba);
1563 error = copyout(&sc, (void *)args->arg, sizeof(sc));
1567 /* LINUX_CDROMREADMODE2 */
1568 /* LINUX_CDROMREADMODE1 */
1569 /* LINUX_CDROMREADAUDIO */
1570 /* LINUX_CDROMEJECT_SW */
1571 /* LINUX_CDROMMULTISESSION */
1572 /* LINUX_CDROM_GET_UPC */
1574 case LINUX_CDROMRESET:
1575 args->cmd = CDIOCRESET;
1576 error = (sys_ioctl(td, (struct ioctl_args *)args));
1579 /* LINUX_CDROMVOLREAD */
1580 /* LINUX_CDROMREADRAW */
1581 /* LINUX_CDROMREADCOOKED */
1582 /* LINUX_CDROMSEEK */
1583 /* LINUX_CDROMPLAYBLK */
1584 /* LINUX_CDROMREADALL */
1585 /* LINUX_CDROMCLOSETRAY */
1586 /* LINUX_CDROMLOADFROMSLOT */
1587 /* LINUX_CDROMGETSPINDOWN */
1588 /* LINUX_CDROMSETSPINDOWN */
1589 /* LINUX_CDROM_SET_OPTIONS */
1590 /* LINUX_CDROM_CLEAR_OPTIONS */
1591 /* LINUX_CDROM_SELECT_SPEED */
1592 /* LINUX_CDROM_SELECT_DISC */
1593 /* LINUX_CDROM_MEDIA_CHANGED */
1594 /* LINUX_CDROM_DRIVE_STATUS */
1595 /* LINUX_CDROM_DISC_STATUS */
1596 /* LINUX_CDROM_CHANGER_NSLOTS */
1597 /* LINUX_CDROM_LOCKDOOR */
1598 /* LINUX_CDROM_DEBUG */
1599 /* LINUX_CDROM_GET_CAPABILITY */
1600 /* LINUX_CDROMAUDIOBUFSIZ */
1602 case LINUX_DVD_READ_STRUCT: {
1604 struct dvd_struct *bds;
1606 lds = malloc(sizeof(*lds), M_LINUX, M_WAITOK);
1607 bds = malloc(sizeof(*bds), M_LINUX, M_WAITOK);
1608 error = copyin((void *)args->arg, lds, sizeof(*lds));
1611 error = linux_to_bsd_dvd_struct(lds, bds);
1614 error = fo_ioctl(fp, DVDIOCREADSTRUCTURE, (caddr_t)bds,
1618 error = bsd_to_linux_dvd_struct(bds, lds);
1621 error = copyout(lds, (void *)args->arg, sizeof(*lds));
1628 /* LINUX_DVD_WRITE_STRUCT */
1630 case LINUX_DVD_AUTH: {
1632 struct dvd_authinfo bda;
1635 error = copyin((void *)args->arg, &lda, sizeof(lda));
1638 error = linux_to_bsd_dvd_authinfo(&lda, &bcode, &bda);
1641 error = fo_ioctl(fp, bcode, (caddr_t)&bda, td->td_ucred,
1644 if (lda.type == LINUX_DVD_HOST_SEND_KEY2) {
1645 lda.type = LINUX_DVD_AUTH_FAILURE;
1646 copyout(&lda, (void *)args->arg, sizeof(lda));
1650 error = bsd_to_linux_dvd_authinfo(&bda, &lda);
1653 error = copyout(&lda, (void *)args->arg, sizeof(lda));
1657 case LINUX_SCSI_GET_BUS_NUMBER:
1659 struct sg_scsi_id id;
1661 error = fo_ioctl(fp, SG_GET_SCSI_ID, (caddr_t)&id,
1665 error = copyout(&id.channel, (void *)args->arg, sizeof(int));
1669 case LINUX_SCSI_GET_IDLUN:
1671 struct sg_scsi_id id;
1672 struct scsi_idlun idl;
1674 error = fo_ioctl(fp, SG_GET_SCSI_ID, (caddr_t)&id,
1678 idl.dev_id = (id.scsi_id & 0xff) + ((id.lun & 0xff) << 8) +
1679 ((id.channel & 0xff) << 16) + ((id.host_no & 0xff) << 24);
1680 idl.host_unique_id = id.host_no;
1681 error = copyout(&idl, (void *)args->arg, sizeof(idl));
1685 /* LINUX_CDROM_SEND_PACKET */
1686 /* LINUX_CDROM_NEXT_WRITABLE */
1687 /* LINUX_CDROM_LAST_WRITTEN */
1699 linux_ioctl_vfat(struct thread *td, struct linux_ioctl_args *args)
1706 * Sound related ioctls
1709 struct linux_old_mixer_info {
1714 static u_int32_t dirbits[4] = { IOC_VOID, IOC_IN, IOC_OUT, IOC_INOUT };
1716 #define SETDIR(c) (((c) & ~IOC_DIRMASK) | dirbits[args->cmd >> 30])
1719 linux_ioctl_sound(struct thread *td, struct linux_ioctl_args *args)
1722 switch (args->cmd & 0xffff) {
1724 case LINUX_SOUND_MIXER_WRITE_VOLUME:
1725 args->cmd = SETDIR(SOUND_MIXER_WRITE_VOLUME);
1726 return (sys_ioctl(td, (struct ioctl_args *)args));
1728 case LINUX_SOUND_MIXER_WRITE_BASS:
1729 args->cmd = SETDIR(SOUND_MIXER_WRITE_BASS);
1730 return (sys_ioctl(td, (struct ioctl_args *)args));
1732 case LINUX_SOUND_MIXER_WRITE_TREBLE:
1733 args->cmd = SETDIR(SOUND_MIXER_WRITE_TREBLE);
1734 return (sys_ioctl(td, (struct ioctl_args *)args));
1736 case LINUX_SOUND_MIXER_WRITE_SYNTH:
1737 args->cmd = SETDIR(SOUND_MIXER_WRITE_SYNTH);
1738 return (sys_ioctl(td, (struct ioctl_args *)args));
1740 case LINUX_SOUND_MIXER_WRITE_PCM:
1741 args->cmd = SETDIR(SOUND_MIXER_WRITE_PCM);
1742 return (sys_ioctl(td, (struct ioctl_args *)args));
1744 case LINUX_SOUND_MIXER_WRITE_SPEAKER:
1745 args->cmd = SETDIR(SOUND_MIXER_WRITE_SPEAKER);
1746 return (sys_ioctl(td, (struct ioctl_args *)args));
1748 case LINUX_SOUND_MIXER_WRITE_LINE:
1749 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE);
1750 return (sys_ioctl(td, (struct ioctl_args *)args));
1752 case LINUX_SOUND_MIXER_WRITE_MIC:
1753 args->cmd = SETDIR(SOUND_MIXER_WRITE_MIC);
1754 return (sys_ioctl(td, (struct ioctl_args *)args));
1756 case LINUX_SOUND_MIXER_WRITE_CD:
1757 args->cmd = SETDIR(SOUND_MIXER_WRITE_CD);
1758 return (sys_ioctl(td, (struct ioctl_args *)args));
1760 case LINUX_SOUND_MIXER_WRITE_IMIX:
1761 args->cmd = SETDIR(SOUND_MIXER_WRITE_IMIX);
1762 return (sys_ioctl(td, (struct ioctl_args *)args));
1764 case LINUX_SOUND_MIXER_WRITE_ALTPCM:
1765 args->cmd = SETDIR(SOUND_MIXER_WRITE_ALTPCM);
1766 return (sys_ioctl(td, (struct ioctl_args *)args));
1768 case LINUX_SOUND_MIXER_WRITE_RECLEV:
1769 args->cmd = SETDIR(SOUND_MIXER_WRITE_RECLEV);
1770 return (sys_ioctl(td, (struct ioctl_args *)args));
1772 case LINUX_SOUND_MIXER_WRITE_IGAIN:
1773 args->cmd = SETDIR(SOUND_MIXER_WRITE_IGAIN);
1774 return (sys_ioctl(td, (struct ioctl_args *)args));
1776 case LINUX_SOUND_MIXER_WRITE_OGAIN:
1777 args->cmd = SETDIR(SOUND_MIXER_WRITE_OGAIN);
1778 return (sys_ioctl(td, (struct ioctl_args *)args));
1780 case LINUX_SOUND_MIXER_WRITE_LINE1:
1781 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE1);
1782 return (sys_ioctl(td, (struct ioctl_args *)args));
1784 case LINUX_SOUND_MIXER_WRITE_LINE2:
1785 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE2);
1786 return (sys_ioctl(td, (struct ioctl_args *)args));
1788 case LINUX_SOUND_MIXER_WRITE_LINE3:
1789 args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE3);
1790 return (sys_ioctl(td, (struct ioctl_args *)args));
1792 case LINUX_SOUND_MIXER_INFO: {
1793 /* Key on encoded length */
1794 switch ((args->cmd >> 16) & 0x1fff) {
1795 case 0x005c: { /* SOUND_MIXER_INFO */
1796 args->cmd = SOUND_MIXER_INFO;
1797 return (sys_ioctl(td, (struct ioctl_args *)args));
1799 case 0x0030: { /* SOUND_OLD_MIXER_INFO */
1800 struct linux_old_mixer_info info;
1801 bzero(&info, sizeof(info));
1802 strncpy(info.id, "OSS", sizeof(info.id) - 1);
1803 strncpy(info.name, "FreeBSD OSS Mixer", sizeof(info.name) - 1);
1804 copyout(&info, (void *)args->arg, sizeof(info));
1813 case LINUX_OSS_GETVERSION: {
1814 int version = linux_get_oss_version(td);
1815 return (copyout(&version, (void *)args->arg, sizeof(int)));
1818 case LINUX_SOUND_MIXER_READ_STEREODEVS:
1819 args->cmd = SOUND_MIXER_READ_STEREODEVS;
1820 return (sys_ioctl(td, (struct ioctl_args *)args));
1822 case LINUX_SOUND_MIXER_READ_CAPS:
1823 args->cmd = SOUND_MIXER_READ_CAPS;
1824 return (sys_ioctl(td, (struct ioctl_args *)args));
1826 case LINUX_SOUND_MIXER_READ_RECMASK:
1827 args->cmd = SOUND_MIXER_READ_RECMASK;
1828 return (sys_ioctl(td, (struct ioctl_args *)args));
1830 case LINUX_SOUND_MIXER_READ_DEVMASK:
1831 args->cmd = SOUND_MIXER_READ_DEVMASK;
1832 return (sys_ioctl(td, (struct ioctl_args *)args));
1834 case LINUX_SOUND_MIXER_WRITE_RECSRC:
1835 args->cmd = SETDIR(SOUND_MIXER_WRITE_RECSRC);
1836 return (sys_ioctl(td, (struct ioctl_args *)args));
1838 case LINUX_SNDCTL_DSP_RESET:
1839 args->cmd = SNDCTL_DSP_RESET;
1840 return (sys_ioctl(td, (struct ioctl_args *)args));
1842 case LINUX_SNDCTL_DSP_SYNC:
1843 args->cmd = SNDCTL_DSP_SYNC;
1844 return (sys_ioctl(td, (struct ioctl_args *)args));
1846 case LINUX_SNDCTL_DSP_SPEED:
1847 args->cmd = SNDCTL_DSP_SPEED;
1848 return (sys_ioctl(td, (struct ioctl_args *)args));
1850 case LINUX_SNDCTL_DSP_STEREO:
1851 args->cmd = SNDCTL_DSP_STEREO;
1852 return (sys_ioctl(td, (struct ioctl_args *)args));
1854 case LINUX_SNDCTL_DSP_GETBLKSIZE: /* LINUX_SNDCTL_DSP_SETBLKSIZE */
1855 args->cmd = SNDCTL_DSP_GETBLKSIZE;
1856 return (sys_ioctl(td, (struct ioctl_args *)args));
1858 case LINUX_SNDCTL_DSP_SETFMT:
1859 args->cmd = SNDCTL_DSP_SETFMT;
1860 return (sys_ioctl(td, (struct ioctl_args *)args));
1862 case LINUX_SOUND_PCM_WRITE_CHANNELS:
1863 args->cmd = SOUND_PCM_WRITE_CHANNELS;
1864 return (sys_ioctl(td, (struct ioctl_args *)args));
1866 case LINUX_SOUND_PCM_WRITE_FILTER:
1867 args->cmd = SOUND_PCM_WRITE_FILTER;
1868 return (sys_ioctl(td, (struct ioctl_args *)args));
1870 case LINUX_SNDCTL_DSP_POST:
1871 args->cmd = SNDCTL_DSP_POST;
1872 return (sys_ioctl(td, (struct ioctl_args *)args));
1874 case LINUX_SNDCTL_DSP_SUBDIVIDE:
1875 args->cmd = SNDCTL_DSP_SUBDIVIDE;
1876 return (sys_ioctl(td, (struct ioctl_args *)args));
1878 case LINUX_SNDCTL_DSP_SETFRAGMENT:
1879 args->cmd = SNDCTL_DSP_SETFRAGMENT;
1880 return (sys_ioctl(td, (struct ioctl_args *)args));
1882 case LINUX_SNDCTL_DSP_GETFMTS:
1883 args->cmd = SNDCTL_DSP_GETFMTS;
1884 return (sys_ioctl(td, (struct ioctl_args *)args));
1886 case LINUX_SNDCTL_DSP_GETOSPACE:
1887 args->cmd = SNDCTL_DSP_GETOSPACE;
1888 return (sys_ioctl(td, (struct ioctl_args *)args));
1890 case LINUX_SNDCTL_DSP_GETISPACE:
1891 args->cmd = SNDCTL_DSP_GETISPACE;
1892 return (sys_ioctl(td, (struct ioctl_args *)args));
1894 case LINUX_SNDCTL_DSP_NONBLOCK:
1895 args->cmd = SNDCTL_DSP_NONBLOCK;
1896 return (sys_ioctl(td, (struct ioctl_args *)args));
1898 case LINUX_SNDCTL_DSP_GETCAPS:
1899 args->cmd = SNDCTL_DSP_GETCAPS;
1900 return (sys_ioctl(td, (struct ioctl_args *)args));
1902 case LINUX_SNDCTL_DSP_SETTRIGGER: /* LINUX_SNDCTL_GETTRIGGER */
1903 args->cmd = SNDCTL_DSP_SETTRIGGER;
1904 return (sys_ioctl(td, (struct ioctl_args *)args));
1906 case LINUX_SNDCTL_DSP_GETIPTR:
1907 args->cmd = SNDCTL_DSP_GETIPTR;
1908 return (sys_ioctl(td, (struct ioctl_args *)args));
1910 case LINUX_SNDCTL_DSP_GETOPTR:
1911 args->cmd = SNDCTL_DSP_GETOPTR;
1912 return (sys_ioctl(td, (struct ioctl_args *)args));
1914 case LINUX_SNDCTL_DSP_SETDUPLEX:
1915 args->cmd = SNDCTL_DSP_SETDUPLEX;
1916 return (sys_ioctl(td, (struct ioctl_args *)args));
1918 case LINUX_SNDCTL_DSP_GETODELAY:
1919 args->cmd = SNDCTL_DSP_GETODELAY;
1920 return (sys_ioctl(td, (struct ioctl_args *)args));
1922 case LINUX_SNDCTL_SEQ_RESET:
1923 args->cmd = SNDCTL_SEQ_RESET;
1924 return (sys_ioctl(td, (struct ioctl_args *)args));
1926 case LINUX_SNDCTL_SEQ_SYNC:
1927 args->cmd = SNDCTL_SEQ_SYNC;
1928 return (sys_ioctl(td, (struct ioctl_args *)args));
1930 case LINUX_SNDCTL_SYNTH_INFO:
1931 args->cmd = SNDCTL_SYNTH_INFO;
1932 return (sys_ioctl(td, (struct ioctl_args *)args));
1934 case LINUX_SNDCTL_SEQ_CTRLRATE:
1935 args->cmd = SNDCTL_SEQ_CTRLRATE;
1936 return (sys_ioctl(td, (struct ioctl_args *)args));
1938 case LINUX_SNDCTL_SEQ_GETOUTCOUNT:
1939 args->cmd = SNDCTL_SEQ_GETOUTCOUNT;
1940 return (sys_ioctl(td, (struct ioctl_args *)args));
1942 case LINUX_SNDCTL_SEQ_GETINCOUNT:
1943 args->cmd = SNDCTL_SEQ_GETINCOUNT;
1944 return (sys_ioctl(td, (struct ioctl_args *)args));
1946 case LINUX_SNDCTL_SEQ_PERCMODE:
1947 args->cmd = SNDCTL_SEQ_PERCMODE;
1948 return (sys_ioctl(td, (struct ioctl_args *)args));
1950 case LINUX_SNDCTL_FM_LOAD_INSTR:
1951 args->cmd = SNDCTL_FM_LOAD_INSTR;
1952 return (sys_ioctl(td, (struct ioctl_args *)args));
1954 case LINUX_SNDCTL_SEQ_TESTMIDI:
1955 args->cmd = SNDCTL_SEQ_TESTMIDI;
1956 return (sys_ioctl(td, (struct ioctl_args *)args));
1958 case LINUX_SNDCTL_SEQ_RESETSAMPLES:
1959 args->cmd = SNDCTL_SEQ_RESETSAMPLES;
1960 return (sys_ioctl(td, (struct ioctl_args *)args));
1962 case LINUX_SNDCTL_SEQ_NRSYNTHS:
1963 args->cmd = SNDCTL_SEQ_NRSYNTHS;
1964 return (sys_ioctl(td, (struct ioctl_args *)args));
1966 case LINUX_SNDCTL_SEQ_NRMIDIS:
1967 args->cmd = SNDCTL_SEQ_NRMIDIS;
1968 return (sys_ioctl(td, (struct ioctl_args *)args));
1970 case LINUX_SNDCTL_MIDI_INFO:
1971 args->cmd = SNDCTL_MIDI_INFO;
1972 return (sys_ioctl(td, (struct ioctl_args *)args));
1974 case LINUX_SNDCTL_SEQ_TRESHOLD:
1975 args->cmd = SNDCTL_SEQ_TRESHOLD;
1976 return (sys_ioctl(td, (struct ioctl_args *)args));
1978 case LINUX_SNDCTL_SYNTH_MEMAVL:
1979 args->cmd = SNDCTL_SYNTH_MEMAVL;
1980 return (sys_ioctl(td, (struct ioctl_args *)args));
1988 * Console related ioctls
1992 linux_ioctl_console(struct thread *td, struct linux_ioctl_args *args)
1994 cap_rights_t rights;
1998 error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
2001 switch (args->cmd & 0xffff) {
2003 case LINUX_KIOCSOUND:
2004 args->cmd = KIOCSOUND;
2005 error = (sys_ioctl(td, (struct ioctl_args *)args));
2008 case LINUX_KDMKTONE:
2009 args->cmd = KDMKTONE;
2010 error = (sys_ioctl(td, (struct ioctl_args *)args));
2013 case LINUX_KDGETLED:
2014 args->cmd = KDGETLED;
2015 error = (sys_ioctl(td, (struct ioctl_args *)args));
2018 case LINUX_KDSETLED:
2019 args->cmd = KDSETLED;
2020 error = (sys_ioctl(td, (struct ioctl_args *)args));
2023 case LINUX_KDSETMODE:
2024 args->cmd = KDSETMODE;
2025 error = (sys_ioctl(td, (struct ioctl_args *)args));
2028 case LINUX_KDGETMODE:
2029 args->cmd = KDGETMODE;
2030 error = (sys_ioctl(td, (struct ioctl_args *)args));
2033 case LINUX_KDGKBMODE:
2034 args->cmd = KDGKBMODE;
2035 error = (sys_ioctl(td, (struct ioctl_args *)args));
2038 case LINUX_KDSKBMODE: {
2040 switch (args->arg) {
2044 case LINUX_KBD_XLATE:
2047 case LINUX_KBD_MEDIUMRAW:
2054 error = (fo_ioctl(fp, KDSKBMODE, (caddr_t)&kbdmode,
2059 case LINUX_VT_OPENQRY:
2060 args->cmd = VT_OPENQRY;
2061 error = (sys_ioctl(td, (struct ioctl_args *)args));
2064 case LINUX_VT_GETMODE:
2065 args->cmd = VT_GETMODE;
2066 error = (sys_ioctl(td, (struct ioctl_args *)args));
2069 case LINUX_VT_SETMODE: {
2070 struct vt_mode mode;
2071 if ((error = copyin((void *)args->arg, &mode, sizeof(mode))))
2073 if (LINUX_SIG_VALID(mode.relsig))
2074 mode.relsig = linux_to_bsd_signal(mode.relsig);
2077 if (LINUX_SIG_VALID(mode.acqsig))
2078 mode.acqsig = linux_to_bsd_signal(mode.acqsig);
2081 /* XXX. Linux ignores frsig and set it to 0. */
2083 if ((error = copyout(&mode, (void *)args->arg, sizeof(mode))))
2085 args->cmd = VT_SETMODE;
2086 error = (sys_ioctl(td, (struct ioctl_args *)args));
2090 case LINUX_VT_GETSTATE:
2091 args->cmd = VT_GETACTIVE;
2092 error = (sys_ioctl(td, (struct ioctl_args *)args));
2095 case LINUX_VT_RELDISP:
2096 args->cmd = VT_RELDISP;
2097 error = (sys_ioctl(td, (struct ioctl_args *)args));
2100 case LINUX_VT_ACTIVATE:
2101 args->cmd = VT_ACTIVATE;
2102 error = (sys_ioctl(td, (struct ioctl_args *)args));
2105 case LINUX_VT_WAITACTIVE:
2106 args->cmd = VT_WAITACTIVE;
2107 error = (sys_ioctl(td, (struct ioctl_args *)args));
2120 * Criteria for interface name translation
2122 #define IFP_IS_ETH(ifp) (ifp->if_type == IFT_ETHER)
2125 * Translate a Linux interface name to a FreeBSD interface name,
2126 * and return the associated ifnet structure
2127 * bsdname and lxname need to be least IFNAMSIZ bytes long, but
2128 * can point to the same buffer.
2131 static struct ifnet *
2132 ifname_linux_to_bsd(struct thread *td, const char *lxname, char *bsdname)
2139 for (len = 0; len < LINUX_IFNAMSIZ; ++len)
2140 if (!isalpha(lxname[len]))
2142 if (len == 0 || len == LINUX_IFNAMSIZ)
2144 unit = (int)strtoul(lxname + len, &ep, 10);
2145 if (ep == NULL || ep == lxname + len || ep >= lxname + LINUX_IFNAMSIZ)
2148 is_eth = (len == 3 && !strncmp(lxname, "eth", len)) ? 1 : 0;
2149 CURVNET_SET(TD_TO_VNET(td));
2151 TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
2153 * Allow Linux programs to use FreeBSD names. Don't presume
2154 * we never have an interface named "eth", so don't make
2155 * the test optional based on is_eth.
2157 if (strncmp(ifp->if_xname, lxname, LINUX_IFNAMSIZ) == 0)
2159 if (is_eth && IFP_IS_ETH(ifp) && unit == index++)
2165 strlcpy(bsdname, ifp->if_xname, IFNAMSIZ);
2170 * Implement the SIOCGIFCONF ioctl
2174 linux_ifconf(struct thread *td, struct ifconf *uifc)
2176 #ifdef COMPAT_LINUX32
2177 struct l_ifconf ifc;
2185 int error, ethno, full = 0, valid_len, max_len;
2187 error = copyin(uifc, &ifc, sizeof(ifc));
2191 max_len = MAXPHYS - 1;
2193 CURVNET_SET(TD_TO_VNET(td));
2194 /* handle the 'request buffer size' case */
2195 if ((l_uintptr_t)ifc.ifc_buf == PTROUT(NULL)) {
2198 TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
2199 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
2200 struct sockaddr *sa = ifa->ifa_addr;
2201 if (sa->sa_family == AF_INET)
2202 ifc.ifc_len += sizeof(ifr);
2206 error = copyout(&ifc, uifc, sizeof(ifc));
2211 if (ifc.ifc_len <= 0) {
2217 /* Keep track of eth interfaces */
2219 if (ifc.ifc_len <= max_len) {
2220 max_len = ifc.ifc_len;
2223 sb = sbuf_new(NULL, NULL, max_len + 1, SBUF_FIXEDLEN);
2227 /* Return all AF_INET addresses of all interfaces */
2229 TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
2232 bzero(&ifr, sizeof(ifr));
2233 if (IFP_IS_ETH(ifp))
2234 snprintf(ifr.ifr_name, LINUX_IFNAMSIZ, "eth%d",
2237 strlcpy(ifr.ifr_name, ifp->if_xname, LINUX_IFNAMSIZ);
2239 /* Walk the address list */
2240 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
2241 struct sockaddr *sa = ifa->ifa_addr;
2243 if (sa->sa_family == AF_INET) {
2244 ifr.ifr_addr.sa_family = LINUX_AF_INET;
2245 memcpy(ifr.ifr_addr.sa_data, sa->sa_data,
2246 sizeof(ifr.ifr_addr.sa_data));
2247 sbuf_bcat(sb, &ifr, sizeof(ifr));
2248 max_len += sizeof(ifr);
2252 if (sbuf_error(sb) == 0)
2253 valid_len = sbuf_len(sb);
2256 bzero((caddr_t)&ifr.ifr_addr, sizeof(ifr.ifr_addr));
2257 sbuf_bcat(sb, &ifr, sizeof(ifr));
2258 max_len += sizeof(ifr);
2260 if (sbuf_error(sb) == 0)
2261 valid_len = sbuf_len(sb);
2266 if (valid_len != max_len && !full) {
2271 ifc.ifc_len = valid_len;
2273 error = copyout(sbuf_data(sb), PTRIN(ifc.ifc_buf), ifc.ifc_len);
2275 error = copyout(&ifc, uifc, sizeof(ifc));
2283 linux_gifflags(struct thread *td, struct ifnet *ifp, struct l_ifreq *ifr)
2287 flags = (ifp->if_flags | ifp->if_drv_flags) & 0xffff;
2288 /* these flags have no Linux equivalent */
2289 flags &= ~(IFF_SMART|IFF_DRV_OACTIVE|IFF_SIMPLEX|
2290 IFF_LINK0|IFF_LINK1|IFF_LINK2);
2291 /* Linux' multicast flag is in a different bit */
2292 if (flags & IFF_MULTICAST) {
2293 flags &= ~IFF_MULTICAST;
2297 return (copyout(&flags, &ifr->ifr_flags, sizeof(flags)));
2300 #define ARPHRD_ETHER 1
2301 #define ARPHRD_LOOPBACK 772
2304 linux_gifhwaddr(struct ifnet *ifp, struct l_ifreq *ifr)
2307 struct sockaddr_dl *sdl;
2308 struct l_sockaddr lsa;
2310 if (ifp->if_type == IFT_LOOP) {
2311 bzero(&lsa, sizeof(lsa));
2312 lsa.sa_family = ARPHRD_LOOPBACK;
2313 return (copyout(&lsa, &ifr->ifr_hwaddr, sizeof(lsa)));
2316 if (ifp->if_type != IFT_ETHER)
2319 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
2320 sdl = (struct sockaddr_dl*)ifa->ifa_addr;
2321 if (sdl != NULL && (sdl->sdl_family == AF_LINK) &&
2322 (sdl->sdl_type == IFT_ETHER)) {
2323 bzero(&lsa, sizeof(lsa));
2324 lsa.sa_family = ARPHRD_ETHER;
2325 bcopy(LLADDR(sdl), lsa.sa_data, LINUX_IFHWADDRLEN);
2326 return (copyout(&lsa, &ifr->ifr_hwaddr, sizeof(lsa)));
2335 * If we fault in bsd_to_linux_ifreq() then we will fault when we call
2336 * the native ioctl(). Thus, we don't really need to check the return
2337 * value of this function.
2340 bsd_to_linux_ifreq(struct ifreq *arg)
2343 size_t ifr_len = sizeof(struct ifreq);
2346 if ((error = copyin(arg, &ifr, ifr_len)))
2349 *(u_short *)&ifr.ifr_addr = ifr.ifr_addr.sa_family;
2351 error = copyout(&ifr, arg, ifr_len);
2357 * Socket related ioctls
2361 linux_ioctl_socket(struct thread *td, struct linux_ioctl_args *args)
2363 char lifname[LINUX_IFNAMSIZ], ifname[IFNAMSIZ];
2364 cap_rights_t rights;
2372 error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
2377 if (type != DTYPE_SOCKET) {
2378 /* not a socket - probably a tap / vmnet device */
2379 switch (args->cmd) {
2380 case LINUX_SIOCGIFADDR:
2381 case LINUX_SIOCSIFADDR:
2382 case LINUX_SIOCGIFFLAGS:
2383 return (linux_ioctl_special(td, args));
2389 switch (args->cmd & 0xffff) {
2391 case LINUX_FIOGETOWN:
2392 case LINUX_FIOSETOWN:
2393 case LINUX_SIOCADDMULTI:
2394 case LINUX_SIOCATMARK:
2395 case LINUX_SIOCDELMULTI:
2396 case LINUX_SIOCGIFCONF:
2397 case LINUX_SIOCGPGRP:
2398 case LINUX_SIOCSPGRP:
2399 case LINUX_SIOCGIFCOUNT:
2400 /* these ioctls don't take an interface name */
2402 printf("%s(): ioctl %d\n", __func__,
2403 args->cmd & 0xffff);
2407 case LINUX_SIOCGIFFLAGS:
2408 case LINUX_SIOCGIFADDR:
2409 case LINUX_SIOCSIFADDR:
2410 case LINUX_SIOCGIFDSTADDR:
2411 case LINUX_SIOCGIFBRDADDR:
2412 case LINUX_SIOCGIFNETMASK:
2413 case LINUX_SIOCSIFNETMASK:
2414 case LINUX_SIOCGIFMTU:
2415 case LINUX_SIOCSIFMTU:
2416 case LINUX_SIOCSIFNAME:
2417 case LINUX_SIOCGIFHWADDR:
2418 case LINUX_SIOCSIFHWADDR:
2419 case LINUX_SIOCDEVPRIVATE:
2420 case LINUX_SIOCDEVPRIVATE+1:
2421 case LINUX_SIOCGIFINDEX:
2422 /* copy in the interface name and translate it. */
2423 error = copyin((void *)args->arg, lifname, LINUX_IFNAMSIZ);
2427 printf("%s(): ioctl %d on %.*s\n", __func__,
2428 args->cmd & 0xffff, LINUX_IFNAMSIZ, lifname);
2430 memset(ifname, 0, sizeof(ifname));
2431 ifp = ifname_linux_to_bsd(td, lifname, ifname);
2435 * We need to copy it back out in case we pass the
2436 * request on to our native ioctl(), which will expect
2437 * the ifreq to be in user space and have the correct
2440 error = copyout(ifname, (void *)args->arg, IFNAMSIZ);
2444 printf("%s(): %s translated to %s\n", __func__,
2453 switch (args->cmd & 0xffff) {
2455 case LINUX_FIOSETOWN:
2456 args->cmd = FIOSETOWN;
2457 error = sys_ioctl(td, (struct ioctl_args *)args);
2460 case LINUX_SIOCSPGRP:
2461 args->cmd = SIOCSPGRP;
2462 error = sys_ioctl(td, (struct ioctl_args *)args);
2465 case LINUX_FIOGETOWN:
2466 args->cmd = FIOGETOWN;
2467 error = sys_ioctl(td, (struct ioctl_args *)args);
2470 case LINUX_SIOCGPGRP:
2471 args->cmd = SIOCGPGRP;
2472 error = sys_ioctl(td, (struct ioctl_args *)args);
2475 case LINUX_SIOCATMARK:
2476 args->cmd = SIOCATMARK;
2477 error = sys_ioctl(td, (struct ioctl_args *)args);
2480 /* LINUX_SIOCGSTAMP */
2482 case LINUX_SIOCGIFCONF:
2483 error = linux_ifconf(td, (struct ifconf *)args->arg);
2486 case LINUX_SIOCGIFFLAGS:
2487 args->cmd = SIOCGIFFLAGS;
2488 error = linux_gifflags(td, ifp, (struct l_ifreq *)args->arg);
2491 case LINUX_SIOCGIFADDR:
2492 args->cmd = SIOCGIFADDR;
2493 error = sys_ioctl(td, (struct ioctl_args *)args);
2494 bsd_to_linux_ifreq((struct ifreq *)args->arg);
2497 case LINUX_SIOCSIFADDR:
2498 /* XXX probably doesn't work, included for completeness */
2499 args->cmd = SIOCSIFADDR;
2500 error = sys_ioctl(td, (struct ioctl_args *)args);
2503 case LINUX_SIOCGIFDSTADDR:
2504 args->cmd = SIOCGIFDSTADDR;
2505 error = sys_ioctl(td, (struct ioctl_args *)args);
2506 bsd_to_linux_ifreq((struct ifreq *)args->arg);
2509 case LINUX_SIOCGIFBRDADDR:
2510 args->cmd = SIOCGIFBRDADDR;
2511 error = sys_ioctl(td, (struct ioctl_args *)args);
2512 bsd_to_linux_ifreq((struct ifreq *)args->arg);
2515 case LINUX_SIOCGIFNETMASK:
2516 args->cmd = SIOCGIFNETMASK;
2517 error = sys_ioctl(td, (struct ioctl_args *)args);
2518 bsd_to_linux_ifreq((struct ifreq *)args->arg);
2521 case LINUX_SIOCSIFNETMASK:
2525 case LINUX_SIOCGIFMTU:
2526 args->cmd = SIOCGIFMTU;
2527 error = sys_ioctl(td, (struct ioctl_args *)args);
2530 case LINUX_SIOCSIFMTU:
2531 args->cmd = SIOCSIFMTU;
2532 error = sys_ioctl(td, (struct ioctl_args *)args);
2535 case LINUX_SIOCSIFNAME:
2539 case LINUX_SIOCGIFHWADDR:
2540 error = linux_gifhwaddr(ifp, (struct l_ifreq *)args->arg);
2543 case LINUX_SIOCSIFHWADDR:
2547 case LINUX_SIOCADDMULTI:
2548 args->cmd = SIOCADDMULTI;
2549 error = sys_ioctl(td, (struct ioctl_args *)args);
2552 case LINUX_SIOCDELMULTI:
2553 args->cmd = SIOCDELMULTI;
2554 error = sys_ioctl(td, (struct ioctl_args *)args);
2557 case LINUX_SIOCGIFINDEX:
2558 args->cmd = SIOCGIFINDEX;
2559 error = sys_ioctl(td, (struct ioctl_args *)args);
2562 case LINUX_SIOCGIFCOUNT:
2567 * XXX This is slightly bogus, but these ioctls are currently
2568 * XXX only used by the aironet (if_an) network driver.
2570 case LINUX_SIOCDEVPRIVATE:
2571 args->cmd = SIOCGPRIVATE_0;
2572 error = sys_ioctl(td, (struct ioctl_args *)args);
2575 case LINUX_SIOCDEVPRIVATE+1:
2576 args->cmd = SIOCGPRIVATE_1;
2577 error = sys_ioctl(td, (struct ioctl_args *)args);
2582 /* restore the original interface name */
2583 copyout(lifname, (void *)args->arg, LINUX_IFNAMSIZ);
2586 printf("%s(): returning %d\n", __func__, error);
2592 * Device private ioctl handler
2595 linux_ioctl_private(struct thread *td, struct linux_ioctl_args *args)
2597 cap_rights_t rights;
2601 error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
2606 if (type == DTYPE_SOCKET)
2607 return (linux_ioctl_socket(td, args));
2612 * DRM ioctl handler (sys/dev/drm)
2615 linux_ioctl_drm(struct thread *td, struct linux_ioctl_args *args)
2617 args->cmd = SETDIR(args->cmd);
2618 return sys_ioctl(td, (struct ioctl_args *)args);
2621 #ifdef COMPAT_LINUX32
2622 #define CP(src,dst,fld) do { (dst).fld = (src).fld; } while (0)
2623 #define PTRIN_CP(src,dst,fld) \
2624 do { (dst).fld = PTRIN((src).fld); } while (0)
2625 #define PTROUT_CP(src,dst,fld) \
2626 do { (dst).fld = PTROUT((src).fld); } while (0)
2629 linux_ioctl_sg_io(struct thread *td, struct linux_ioctl_args *args)
2631 struct sg_io_hdr io;
2632 struct sg_io_hdr32 io32;
2633 cap_rights_t rights;
2637 error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
2639 printf("sg_linux_ioctl: fget returned %d\n", error);
2643 if ((error = copyin((void *)args->arg, &io32, sizeof(io32))) != 0)
2646 CP(io32, io, interface_id);
2647 CP(io32, io, dxfer_direction);
2648 CP(io32, io, cmd_len);
2649 CP(io32, io, mx_sb_len);
2650 CP(io32, io, iovec_count);
2651 CP(io32, io, dxfer_len);
2652 PTRIN_CP(io32, io, dxferp);
2653 PTRIN_CP(io32, io, cmdp);
2654 PTRIN_CP(io32, io, sbp);
2655 CP(io32, io, timeout);
2656 CP(io32, io, flags);
2657 CP(io32, io, pack_id);
2658 PTRIN_CP(io32, io, usr_ptr);
2659 CP(io32, io, status);
2660 CP(io32, io, masked_status);
2661 CP(io32, io, msg_status);
2662 CP(io32, io, sb_len_wr);
2663 CP(io32, io, host_status);
2664 CP(io32, io, driver_status);
2665 CP(io32, io, resid);
2666 CP(io32, io, duration);
2669 if ((error = fo_ioctl(fp, SG_IO, (caddr_t)&io, td->td_ucred, td)) != 0)
2672 CP(io, io32, interface_id);
2673 CP(io, io32, dxfer_direction);
2674 CP(io, io32, cmd_len);
2675 CP(io, io32, mx_sb_len);
2676 CP(io, io32, iovec_count);
2677 CP(io, io32, dxfer_len);
2678 PTROUT_CP(io, io32, dxferp);
2679 PTROUT_CP(io, io32, cmdp);
2680 PTROUT_CP(io, io32, sbp);
2681 CP(io, io32, timeout);
2682 CP(io, io32, flags);
2683 CP(io, io32, pack_id);
2684 PTROUT_CP(io, io32, usr_ptr);
2685 CP(io, io32, status);
2686 CP(io, io32, masked_status);
2687 CP(io, io32, msg_status);
2688 CP(io, io32, sb_len_wr);
2689 CP(io, io32, host_status);
2690 CP(io, io32, driver_status);
2691 CP(io, io32, resid);
2692 CP(io, io32, duration);
2695 error = copyout(&io32, (void *)args->arg, sizeof(io32));
2704 linux_ioctl_sg(struct thread *td, struct linux_ioctl_args *args)
2707 switch (args->cmd) {
2708 case LINUX_SG_GET_VERSION_NUM:
2709 args->cmd = SG_GET_VERSION_NUM;
2711 case LINUX_SG_SET_TIMEOUT:
2712 args->cmd = SG_SET_TIMEOUT;
2714 case LINUX_SG_GET_TIMEOUT:
2715 args->cmd = SG_GET_TIMEOUT;
2719 #ifdef COMPAT_LINUX32
2720 return (linux_ioctl_sg_io(td, args));
2723 case LINUX_SG_GET_RESERVED_SIZE:
2724 args->cmd = SG_GET_RESERVED_SIZE;
2726 case LINUX_SG_GET_SCSI_ID:
2727 args->cmd = SG_GET_SCSI_ID;
2729 case LINUX_SG_GET_SG_TABLESIZE:
2730 args->cmd = SG_GET_SG_TABLESIZE;
2735 return (sys_ioctl(td, (struct ioctl_args *)args));
2739 * Video4Linux (V4L) ioctl handler
2742 linux_to_bsd_v4l_tuner(struct l_video_tuner *lvt, struct video_tuner *vt)
2744 vt->tuner = lvt->tuner;
2745 strlcpy(vt->name, lvt->name, LINUX_VIDEO_TUNER_NAME_SIZE);
2746 vt->rangelow = lvt->rangelow; /* possible long size conversion */
2747 vt->rangehigh = lvt->rangehigh; /* possible long size conversion */
2748 vt->flags = lvt->flags;
2749 vt->mode = lvt->mode;
2750 vt->signal = lvt->signal;
2755 bsd_to_linux_v4l_tuner(struct video_tuner *vt, struct l_video_tuner *lvt)
2757 lvt->tuner = vt->tuner;
2758 strlcpy(lvt->name, vt->name, LINUX_VIDEO_TUNER_NAME_SIZE);
2759 lvt->rangelow = vt->rangelow; /* possible long size conversion */
2760 lvt->rangehigh = vt->rangehigh; /* possible long size conversion */
2761 lvt->flags = vt->flags;
2762 lvt->mode = vt->mode;
2763 lvt->signal = vt->signal;
2767 #ifdef COMPAT_LINUX_V4L_CLIPLIST
2769 linux_to_bsd_v4l_clip(struct l_video_clip *lvc, struct video_clip *vc)
2773 vc->width = lvc->width;
2774 vc->height = lvc->height;
2775 vc->next = PTRIN(lvc->next); /* possible pointer size conversion */
2781 linux_to_bsd_v4l_window(struct l_video_window *lvw, struct video_window *vw)
2785 vw->width = lvw->width;
2786 vw->height = lvw->height;
2787 vw->chromakey = lvw->chromakey;
2788 vw->flags = lvw->flags;
2789 vw->clips = PTRIN(lvw->clips); /* possible pointer size conversion */
2790 vw->clipcount = lvw->clipcount;
2795 bsd_to_linux_v4l_window(struct video_window *vw, struct l_video_window *lvw)
2799 lvw->width = vw->width;
2800 lvw->height = vw->height;
2801 lvw->chromakey = vw->chromakey;
2802 lvw->flags = vw->flags;
2803 lvw->clips = PTROUT(vw->clips); /* possible pointer size conversion */
2804 lvw->clipcount = vw->clipcount;
2809 linux_to_bsd_v4l_buffer(struct l_video_buffer *lvb, struct video_buffer *vb)
2811 vb->base = PTRIN(lvb->base); /* possible pointer size conversion */
2812 vb->height = lvb->height;
2813 vb->width = lvb->width;
2814 vb->depth = lvb->depth;
2815 vb->bytesperline = lvb->bytesperline;
2820 bsd_to_linux_v4l_buffer(struct video_buffer *vb, struct l_video_buffer *lvb)
2822 lvb->base = PTROUT(vb->base); /* possible pointer size conversion */
2823 lvb->height = vb->height;
2824 lvb->width = vb->width;
2825 lvb->depth = vb->depth;
2826 lvb->bytesperline = vb->bytesperline;
2831 linux_to_bsd_v4l_code(struct l_video_code *lvc, struct video_code *vc)
2833 strlcpy(vc->loadwhat, lvc->loadwhat, LINUX_VIDEO_CODE_LOADWHAT_SIZE);
2834 vc->datasize = lvc->datasize;
2835 vc->data = PTRIN(lvc->data); /* possible pointer size conversion */
2839 #ifdef COMPAT_LINUX_V4L_CLIPLIST
2841 linux_v4l_clip_copy(void *lvc, struct video_clip **ppvc)
2844 struct video_clip vclip;
2845 struct l_video_clip l_vclip;
2847 error = copyin(lvc, &l_vclip, sizeof(l_vclip));
2848 if (error) return (error);
2849 linux_to_bsd_v4l_clip(&l_vclip, &vclip);
2850 /* XXX: If there can be no concurrency: s/M_NOWAIT/M_WAITOK/ */
2851 if ((*ppvc = malloc(sizeof(**ppvc), M_LINUX, M_NOWAIT)) == NULL)
2852 return (ENOMEM); /* XXX: linux has no ENOMEM here */
2853 memcpy(*ppvc, &vclip, sizeof(vclip));
2854 (*ppvc)->next = NULL;
2859 linux_v4l_cliplist_free(struct video_window *vw)
2861 struct video_clip **ppvc;
2862 struct video_clip **ppvc_next;
2864 for (ppvc = &(vw->clips); *ppvc != NULL; ppvc = ppvc_next) {
2865 ppvc_next = &((*ppvc)->next);
2866 free(*ppvc, M_LINUX);
2874 linux_v4l_cliplist_copy(struct l_video_window *lvw, struct video_window *vw)
2879 struct video_clip **ppvc;
2882 * XXX: The cliplist is used to pass in a list of clipping
2883 * rectangles or, if clipcount == VIDEO_CLIP_BITMAP, a
2884 * clipping bitmap. Some Linux apps, however, appear to
2885 * leave cliplist and clips uninitialized. In any case,
2886 * the cliplist is not used by pwc(4), at the time of
2887 * writing, FreeBSD's only V4L driver. When a driver
2888 * that uses the cliplist is developed, this code may
2889 * need re-examiniation.
2892 clipcount = vw->clipcount;
2893 if (clipcount == VIDEO_CLIP_BITMAP) {
2895 * In this case, the pointer (clips) is overloaded
2896 * to be a "void *" to a bitmap, therefore there
2897 * is no struct video_clip to copy now.
2899 } else if (clipcount > 0 && clipcount <= 16384) {
2901 * Clips points to list of clip rectangles, so
2904 * XXX: Upper limit of 16384 was used here to try to
2905 * avoid cases when clipcount and clips pointer
2906 * are uninitialized and therefore have high random
2907 * values, as is the case in the Linux Skype
2908 * application. The value 16384 was chosen as that
2909 * is what is used in the Linux stradis(4) MPEG
2910 * decoder driver, the only place we found an
2911 * example of cliplist use.
2913 plvc = PTRIN(lvw->clips);
2915 ppvc = &(vw->clips);
2916 while (clipcount-- > 0) {
2921 error = linux_v4l_clip_copy(plvc, ppvc);
2923 linux_v4l_cliplist_free(vw);
2927 ppvc = &((*ppvc)->next);
2928 plvc = PTRIN(((struct l_video_clip *) plvc)->next);
2932 * clipcount == 0 or negative (but not VIDEO_CLIP_BITMAP)
2933 * Force cliplist to null.
2943 linux_ioctl_v4l(struct thread *td, struct linux_ioctl_args *args)
2945 cap_rights_t rights;
2948 struct video_tuner vtun;
2949 struct video_window vwin;
2950 struct video_buffer vbuf;
2951 struct video_code vcode;
2952 struct l_video_tuner l_vtun;
2953 struct l_video_window l_vwin;
2954 struct l_video_buffer l_vbuf;
2955 struct l_video_code l_vcode;
2957 switch (args->cmd & 0xffff) {
2958 case LINUX_VIDIOCGCAP: args->cmd = VIDIOCGCAP; break;
2959 case LINUX_VIDIOCGCHAN: args->cmd = VIDIOCGCHAN; break;
2960 case LINUX_VIDIOCSCHAN: args->cmd = VIDIOCSCHAN; break;
2962 case LINUX_VIDIOCGTUNER:
2963 error = fget(td, args->fd,
2964 cap_rights_init(&rights, CAP_IOCTL), &fp);
2967 error = copyin((void *) args->arg, &l_vtun, sizeof(l_vtun));
2972 linux_to_bsd_v4l_tuner(&l_vtun, &vtun);
2973 error = fo_ioctl(fp, VIDIOCGTUNER, &vtun, td->td_ucred, td);
2975 bsd_to_linux_v4l_tuner(&vtun, &l_vtun);
2976 error = copyout(&l_vtun, (void *) args->arg,
2982 case LINUX_VIDIOCSTUNER:
2983 error = fget(td, args->fd,
2984 cap_rights_init(&rights, CAP_IOCTL), &fp);
2987 error = copyin((void *) args->arg, &l_vtun, sizeof(l_vtun));
2992 linux_to_bsd_v4l_tuner(&l_vtun, &vtun);
2993 error = fo_ioctl(fp, VIDIOCSTUNER, &vtun, td->td_ucred, td);
2997 case LINUX_VIDIOCGPICT: args->cmd = VIDIOCGPICT; break;
2998 case LINUX_VIDIOCSPICT: args->cmd = VIDIOCSPICT; break;
2999 case LINUX_VIDIOCCAPTURE: args->cmd = VIDIOCCAPTURE; break;
3001 case LINUX_VIDIOCGWIN:
3002 error = fget(td, args->fd,
3003 cap_rights_init(&rights, CAP_IOCTL), &fp);
3006 error = fo_ioctl(fp, VIDIOCGWIN, &vwin, td->td_ucred, td);
3008 bsd_to_linux_v4l_window(&vwin, &l_vwin);
3009 error = copyout(&l_vwin, (void *) args->arg,
3015 case LINUX_VIDIOCSWIN:
3016 error = fget(td, args->fd,
3017 cap_rights_init(&rights, CAP_IOCTL), &fp);
3020 error = copyin((void *) args->arg, &l_vwin, sizeof(l_vwin));
3025 linux_to_bsd_v4l_window(&l_vwin, &vwin);
3026 #ifdef COMPAT_LINUX_V4L_CLIPLIST
3027 error = linux_v4l_cliplist_copy(&l_vwin, &vwin);
3033 error = fo_ioctl(fp, VIDIOCSWIN, &vwin, td->td_ucred, td);
3035 #ifdef COMPAT_LINUX_V4L_CLIPLIST
3036 linux_v4l_cliplist_free(&vwin);
3040 case LINUX_VIDIOCGFBUF:
3041 error = fget(td, args->fd,
3042 cap_rights_init(&rights, CAP_IOCTL), &fp);
3045 error = fo_ioctl(fp, VIDIOCGFBUF, &vbuf, td->td_ucred, td);
3047 bsd_to_linux_v4l_buffer(&vbuf, &l_vbuf);
3048 error = copyout(&l_vbuf, (void *) args->arg,
3054 case LINUX_VIDIOCSFBUF:
3055 error = fget(td, args->fd,
3056 cap_rights_init(&rights, CAP_IOCTL), &fp);
3059 error = copyin((void *) args->arg, &l_vbuf, sizeof(l_vbuf));
3064 linux_to_bsd_v4l_buffer(&l_vbuf, &vbuf);
3065 error = fo_ioctl(fp, VIDIOCSFBUF, &vbuf, td->td_ucred, td);
3069 case LINUX_VIDIOCKEY: args->cmd = VIDIOCKEY; break;
3070 case LINUX_VIDIOCGFREQ: args->cmd = VIDIOCGFREQ; break;
3071 case LINUX_VIDIOCSFREQ: args->cmd = VIDIOCSFREQ; break;
3072 case LINUX_VIDIOCGAUDIO: args->cmd = VIDIOCGAUDIO; break;
3073 case LINUX_VIDIOCSAUDIO: args->cmd = VIDIOCSAUDIO; break;
3074 case LINUX_VIDIOCSYNC: args->cmd = VIDIOCSYNC; break;
3075 case LINUX_VIDIOCMCAPTURE: args->cmd = VIDIOCMCAPTURE; break;
3076 case LINUX_VIDIOCGMBUF: args->cmd = VIDIOCGMBUF; break;
3077 case LINUX_VIDIOCGUNIT: args->cmd = VIDIOCGUNIT; break;
3078 case LINUX_VIDIOCGCAPTURE: args->cmd = VIDIOCGCAPTURE; break;
3079 case LINUX_VIDIOCSCAPTURE: args->cmd = VIDIOCSCAPTURE; break;
3080 case LINUX_VIDIOCSPLAYMODE: args->cmd = VIDIOCSPLAYMODE; break;
3081 case LINUX_VIDIOCSWRITEMODE: args->cmd = VIDIOCSWRITEMODE; break;
3082 case LINUX_VIDIOCGPLAYINFO: args->cmd = VIDIOCGPLAYINFO; break;
3084 case LINUX_VIDIOCSMICROCODE:
3085 error = fget(td, args->fd,
3086 cap_rights_init(&rights, CAP_IOCTL), &fp);
3089 error = copyin((void *) args->arg, &l_vcode, sizeof(l_vcode));
3094 linux_to_bsd_v4l_code(&l_vcode, &vcode);
3095 error = fo_ioctl(fp, VIDIOCSMICROCODE, &vcode, td->td_ucred, td);
3099 case LINUX_VIDIOCGVBIFMT: args->cmd = VIDIOCGVBIFMT; break;
3100 case LINUX_VIDIOCSVBIFMT: args->cmd = VIDIOCSVBIFMT; break;
3101 default: return (ENOIOCTL);
3104 error = sys_ioctl(td, (struct ioctl_args *)args);
3109 * Special ioctl handler
3112 linux_ioctl_special(struct thread *td, struct linux_ioctl_args *args)
3116 switch (args->cmd) {
3117 case LINUX_SIOCGIFADDR:
3118 args->cmd = SIOCGIFADDR;
3119 error = sys_ioctl(td, (struct ioctl_args *)args);
3121 case LINUX_SIOCSIFADDR:
3122 args->cmd = SIOCSIFADDR;
3123 error = sys_ioctl(td, (struct ioctl_args *)args);
3125 case LINUX_SIOCGIFFLAGS:
3126 args->cmd = SIOCGIFFLAGS;
3127 error = sys_ioctl(td, (struct ioctl_args *)args);
3137 linux_to_bsd_v4l2_standard(struct l_v4l2_standard *lvstd, struct v4l2_standard *vstd)
3139 vstd->index = lvstd->index;
3140 vstd->id = lvstd->id;
3141 memcpy(&vstd->name, &lvstd->name, sizeof(*lvstd) - offsetof(struct l_v4l2_standard, name));
3146 bsd_to_linux_v4l2_standard(struct v4l2_standard *vstd, struct l_v4l2_standard *lvstd)
3148 lvstd->index = vstd->index;
3149 lvstd->id = vstd->id;
3150 memcpy(&lvstd->name, &vstd->name, sizeof(*lvstd) - offsetof(struct l_v4l2_standard, name));
3155 linux_to_bsd_v4l2_buffer(struct l_v4l2_buffer *lvb, struct v4l2_buffer *vb)
3157 vb->index = lvb->index;
3158 vb->type = lvb->type;
3159 vb->bytesused = lvb->bytesused;
3160 vb->flags = lvb->flags;
3161 vb->field = lvb->field;
3162 vb->timestamp.tv_sec = lvb->timestamp.tv_sec;
3163 vb->timestamp.tv_usec = lvb->timestamp.tv_usec;
3164 memcpy(&vb->timecode, &lvb->timecode, sizeof (lvb->timecode));
3165 vb->sequence = lvb->sequence;
3166 vb->memory = lvb->memory;
3167 if (lvb->memory == V4L2_MEMORY_USERPTR)
3168 /* possible pointer size conversion */
3169 vb->m.userptr = (unsigned long)PTRIN(lvb->m.userptr);
3171 vb->m.offset = lvb->m.offset;
3172 vb->length = lvb->length;
3173 vb->input = lvb->input;
3174 vb->reserved = lvb->reserved;
3179 bsd_to_linux_v4l2_buffer(struct v4l2_buffer *vb, struct l_v4l2_buffer *lvb)
3181 lvb->index = vb->index;
3182 lvb->type = vb->type;
3183 lvb->bytesused = vb->bytesused;
3184 lvb->flags = vb->flags;
3185 lvb->field = vb->field;
3186 lvb->timestamp.tv_sec = vb->timestamp.tv_sec;
3187 lvb->timestamp.tv_usec = vb->timestamp.tv_usec;
3188 memcpy(&lvb->timecode, &vb->timecode, sizeof (vb->timecode));
3189 lvb->sequence = vb->sequence;
3190 lvb->memory = vb->memory;
3191 if (vb->memory == V4L2_MEMORY_USERPTR)
3192 /* possible pointer size conversion */
3193 lvb->m.userptr = PTROUT(vb->m.userptr);
3195 lvb->m.offset = vb->m.offset;
3196 lvb->length = vb->length;
3197 lvb->input = vb->input;
3198 lvb->reserved = vb->reserved;
3203 linux_to_bsd_v4l2_format(struct l_v4l2_format *lvf, struct v4l2_format *vf)
3205 vf->type = lvf->type;
3206 if (lvf->type == V4L2_BUF_TYPE_VIDEO_OVERLAY
3207 #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
3208 || lvf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
3212 * XXX TODO - needs 32 -> 64 bit conversion:
3213 * (unused by webcams?)
3216 memcpy(&vf->fmt, &lvf->fmt, sizeof(vf->fmt));
3221 bsd_to_linux_v4l2_format(struct v4l2_format *vf, struct l_v4l2_format *lvf)
3223 lvf->type = vf->type;
3224 if (vf->type == V4L2_BUF_TYPE_VIDEO_OVERLAY
3225 #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
3226 || vf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY
3230 * XXX TODO - needs 32 -> 64 bit conversion:
3231 * (unused by webcams?)
3234 memcpy(&lvf->fmt, &vf->fmt, sizeof(vf->fmt));
3238 linux_ioctl_v4l2(struct thread *td, struct linux_ioctl_args *args)
3240 cap_rights_t rights;
3243 struct v4l2_format vformat;
3244 struct l_v4l2_format l_vformat;
3245 struct v4l2_standard vstd;
3246 struct l_v4l2_standard l_vstd;
3247 struct l_v4l2_buffer l_vbuf;
3248 struct v4l2_buffer vbuf;
3249 struct v4l2_input vinp;
3251 switch (args->cmd & 0xffff) {
3252 case LINUX_VIDIOC_RESERVED:
3253 case LINUX_VIDIOC_LOG_STATUS:
3254 if ((args->cmd & IOC_DIRMASK) != LINUX_IOC_VOID)
3256 args->cmd = (args->cmd & 0xffff) | IOC_VOID;
3259 case LINUX_VIDIOC_OVERLAY:
3260 case LINUX_VIDIOC_STREAMON:
3261 case LINUX_VIDIOC_STREAMOFF:
3262 case LINUX_VIDIOC_S_STD:
3263 case LINUX_VIDIOC_S_TUNER:
3264 case LINUX_VIDIOC_S_AUDIO:
3265 case LINUX_VIDIOC_S_AUDOUT:
3266 case LINUX_VIDIOC_S_MODULATOR:
3267 case LINUX_VIDIOC_S_FREQUENCY:
3268 case LINUX_VIDIOC_S_CROP:
3269 case LINUX_VIDIOC_S_JPEGCOMP:
3270 case LINUX_VIDIOC_S_PRIORITY:
3271 case LINUX_VIDIOC_DBG_S_REGISTER:
3272 case LINUX_VIDIOC_S_HW_FREQ_SEEK:
3273 case LINUX_VIDIOC_SUBSCRIBE_EVENT:
3274 case LINUX_VIDIOC_UNSUBSCRIBE_EVENT:
3275 args->cmd = (args->cmd & ~IOC_DIRMASK) | IOC_IN;
3278 case LINUX_VIDIOC_QUERYCAP:
3279 case LINUX_VIDIOC_G_STD:
3280 case LINUX_VIDIOC_G_AUDIO:
3281 case LINUX_VIDIOC_G_INPUT:
3282 case LINUX_VIDIOC_G_OUTPUT:
3283 case LINUX_VIDIOC_G_AUDOUT:
3284 case LINUX_VIDIOC_G_JPEGCOMP:
3285 case LINUX_VIDIOC_QUERYSTD:
3286 case LINUX_VIDIOC_G_PRIORITY:
3287 case LINUX_VIDIOC_QUERY_DV_PRESET:
3288 args->cmd = (args->cmd & ~IOC_DIRMASK) | IOC_OUT;
3291 case LINUX_VIDIOC_ENUM_FMT:
3292 case LINUX_VIDIOC_REQBUFS:
3293 case LINUX_VIDIOC_G_PARM:
3294 case LINUX_VIDIOC_S_PARM:
3295 case LINUX_VIDIOC_G_CTRL:
3296 case LINUX_VIDIOC_S_CTRL:
3297 case LINUX_VIDIOC_G_TUNER:
3298 case LINUX_VIDIOC_QUERYCTRL:
3299 case LINUX_VIDIOC_QUERYMENU:
3300 case LINUX_VIDIOC_S_INPUT:
3301 case LINUX_VIDIOC_S_OUTPUT:
3302 case LINUX_VIDIOC_ENUMOUTPUT:
3303 case LINUX_VIDIOC_G_MODULATOR:
3304 case LINUX_VIDIOC_G_FREQUENCY:
3305 case LINUX_VIDIOC_CROPCAP:
3306 case LINUX_VIDIOC_G_CROP:
3307 case LINUX_VIDIOC_ENUMAUDIO:
3308 case LINUX_VIDIOC_ENUMAUDOUT:
3309 case LINUX_VIDIOC_G_SLICED_VBI_CAP:
3310 #ifdef VIDIOC_ENUM_FRAMESIZES
3311 case LINUX_VIDIOC_ENUM_FRAMESIZES:
3312 case LINUX_VIDIOC_ENUM_FRAMEINTERVALS:
3313 case LINUX_VIDIOC_ENCODER_CMD:
3314 case LINUX_VIDIOC_TRY_ENCODER_CMD:
3316 case LINUX_VIDIOC_DBG_G_REGISTER:
3317 case LINUX_VIDIOC_DBG_G_CHIP_IDENT:
3318 case LINUX_VIDIOC_ENUM_DV_PRESETS:
3319 case LINUX_VIDIOC_S_DV_PRESET:
3320 case LINUX_VIDIOC_G_DV_PRESET:
3321 case LINUX_VIDIOC_S_DV_TIMINGS:
3322 case LINUX_VIDIOC_G_DV_TIMINGS:
3323 args->cmd = (args->cmd & ~IOC_DIRMASK) | IOC_INOUT;
3326 case LINUX_VIDIOC_G_FMT:
3327 case LINUX_VIDIOC_S_FMT:
3328 case LINUX_VIDIOC_TRY_FMT:
3329 error = copyin((void *)args->arg, &l_vformat, sizeof(l_vformat));
3332 error = fget(td, args->fd,
3333 cap_rights_init(&rights, CAP_IOCTL), &fp);
3336 if (linux_to_bsd_v4l2_format(&l_vformat, &vformat) != 0)
3338 else if ((args->cmd & 0xffff) == LINUX_VIDIOC_G_FMT)
3339 error = fo_ioctl(fp, VIDIOC_G_FMT, &vformat,
3341 else if ((args->cmd & 0xffff) == LINUX_VIDIOC_S_FMT)
3342 error = fo_ioctl(fp, VIDIOC_S_FMT, &vformat,
3345 error = fo_ioctl(fp, VIDIOC_TRY_FMT, &vformat,
3347 bsd_to_linux_v4l2_format(&vformat, &l_vformat);
3348 copyout(&l_vformat, (void *)args->arg, sizeof(l_vformat));
3352 case LINUX_VIDIOC_ENUMSTD:
3353 error = copyin((void *)args->arg, &l_vstd, sizeof(l_vstd));
3356 linux_to_bsd_v4l2_standard(&l_vstd, &vstd);
3357 error = fget(td, args->fd,
3358 cap_rights_init(&rights, CAP_IOCTL), &fp);
3361 error = fo_ioctl(fp, VIDIOC_ENUMSTD, (caddr_t)&vstd,
3367 bsd_to_linux_v4l2_standard(&vstd, &l_vstd);
3368 error = copyout(&l_vstd, (void *)args->arg, sizeof(l_vstd));
3372 case LINUX_VIDIOC_ENUMINPUT:
3374 * The Linux struct l_v4l2_input differs only in size,
3375 * it has no padding at the end.
3377 error = copyin((void *)args->arg, &vinp,
3378 sizeof(struct l_v4l2_input));
3381 error = fget(td, args->fd,
3382 cap_rights_init(&rights, CAP_IOCTL), &fp);
3385 error = fo_ioctl(fp, VIDIOC_ENUMINPUT, (caddr_t)&vinp,
3391 error = copyout(&vinp, (void *)args->arg,
3392 sizeof(struct l_v4l2_input));
3396 case LINUX_VIDIOC_QUERYBUF:
3397 case LINUX_VIDIOC_QBUF:
3398 case LINUX_VIDIOC_DQBUF:
3399 error = copyin((void *)args->arg, &l_vbuf, sizeof(l_vbuf));
3402 error = fget(td, args->fd,
3403 cap_rights_init(&rights, CAP_IOCTL), &fp);
3406 linux_to_bsd_v4l2_buffer(&l_vbuf, &vbuf);
3407 if ((args->cmd & 0xffff) == LINUX_VIDIOC_QUERYBUF)
3408 error = fo_ioctl(fp, VIDIOC_QUERYBUF, &vbuf,
3410 else if ((args->cmd & 0xffff) == LINUX_VIDIOC_QBUF)
3411 error = fo_ioctl(fp, VIDIOC_QBUF, &vbuf,
3414 error = fo_ioctl(fp, VIDIOC_DQBUF, &vbuf,
3416 bsd_to_linux_v4l2_buffer(&vbuf, &l_vbuf);
3417 copyout(&l_vbuf, (void *)args->arg, sizeof(l_vbuf));
3422 * XXX TODO - these need 32 -> 64 bit conversion:
3423 * (are any of them needed for webcams?)
3425 case LINUX_VIDIOC_G_FBUF:
3426 case LINUX_VIDIOC_S_FBUF:
3428 case LINUX_VIDIOC_G_EXT_CTRLS:
3429 case LINUX_VIDIOC_S_EXT_CTRLS:
3430 case LINUX_VIDIOC_TRY_EXT_CTRLS:
3432 case LINUX_VIDIOC_DQEVENT:
3434 default: return (ENOIOCTL);
3437 error = sys_ioctl(td, (struct ioctl_args *)args);
3442 * Support for emulators/linux-libusb. This port uses FBSD_LUSB* macros
3443 * instead of USB* ones. This lets us to provide correct values for cmd.
3444 * 0xffffffe0 -- 0xffffffff range seemed to be the least collision-prone.
3447 linux_ioctl_fbsd_usb(struct thread *td, struct linux_ioctl_args *args)
3452 switch (args->cmd) {
3453 case FBSD_LUSB_DEVICEENUMERATE:
3454 args->cmd = USB_DEVICEENUMERATE;
3456 case FBSD_LUSB_DEV_QUIRK_ADD:
3457 args->cmd = USB_DEV_QUIRK_ADD;
3459 case FBSD_LUSB_DEV_QUIRK_GET:
3460 args->cmd = USB_DEV_QUIRK_GET;
3462 case FBSD_LUSB_DEV_QUIRK_REMOVE:
3463 args->cmd = USB_DEV_QUIRK_REMOVE;
3465 case FBSD_LUSB_DO_REQUEST:
3466 args->cmd = USB_DO_REQUEST;
3468 case FBSD_LUSB_FS_CLEAR_STALL_SYNC:
3469 args->cmd = USB_FS_CLEAR_STALL_SYNC;
3471 case FBSD_LUSB_FS_CLOSE:
3472 args->cmd = USB_FS_CLOSE;
3474 case FBSD_LUSB_FS_COMPLETE:
3475 args->cmd = USB_FS_COMPLETE;
3477 case FBSD_LUSB_FS_INIT:
3478 args->cmd = USB_FS_INIT;
3480 case FBSD_LUSB_FS_OPEN:
3481 args->cmd = USB_FS_OPEN;
3483 case FBSD_LUSB_FS_START:
3484 args->cmd = USB_FS_START;
3486 case FBSD_LUSB_FS_STOP:
3487 args->cmd = USB_FS_STOP;
3489 case FBSD_LUSB_FS_UNINIT:
3490 args->cmd = USB_FS_UNINIT;
3492 case FBSD_LUSB_GET_CONFIG:
3493 args->cmd = USB_GET_CONFIG;
3495 case FBSD_LUSB_GET_DEVICEINFO:
3496 args->cmd = USB_GET_DEVICEINFO;
3498 case FBSD_LUSB_GET_DEVICE_DESC:
3499 args->cmd = USB_GET_DEVICE_DESC;
3501 case FBSD_LUSB_GET_FULL_DESC:
3502 args->cmd = USB_GET_FULL_DESC;
3504 case FBSD_LUSB_GET_IFACE_DRIVER:
3505 args->cmd = USB_GET_IFACE_DRIVER;
3507 case FBSD_LUSB_GET_PLUGTIME:
3508 args->cmd = USB_GET_PLUGTIME;
3510 case FBSD_LUSB_GET_POWER_MODE:
3511 args->cmd = USB_GET_POWER_MODE;
3513 case FBSD_LUSB_GET_REPORT_DESC:
3514 args->cmd = USB_GET_REPORT_DESC;
3516 case FBSD_LUSB_GET_REPORT_ID:
3517 args->cmd = USB_GET_REPORT_ID;
3519 case FBSD_LUSB_GET_TEMPLATE:
3520 args->cmd = USB_GET_TEMPLATE;
3522 case FBSD_LUSB_IFACE_DRIVER_ACTIVE:
3523 args->cmd = USB_IFACE_DRIVER_ACTIVE;
3525 case FBSD_LUSB_IFACE_DRIVER_DETACH:
3526 args->cmd = USB_IFACE_DRIVER_DETACH;
3528 case FBSD_LUSB_QUIRK_NAME_GET:
3529 args->cmd = USB_QUIRK_NAME_GET;
3531 case FBSD_LUSB_READ_DIR:
3532 args->cmd = USB_READ_DIR;
3534 case FBSD_LUSB_SET_ALTINTERFACE:
3535 args->cmd = USB_SET_ALTINTERFACE;
3537 case FBSD_LUSB_SET_CONFIG:
3538 args->cmd = USB_SET_CONFIG;
3540 case FBSD_LUSB_SET_IMMED:
3541 args->cmd = USB_SET_IMMED;
3543 case FBSD_LUSB_SET_POWER_MODE:
3544 args->cmd = USB_SET_POWER_MODE;
3546 case FBSD_LUSB_SET_TEMPLATE:
3547 args->cmd = USB_SET_TEMPLATE;
3549 case FBSD_LUSB_FS_OPEN_STREAM:
3550 args->cmd = USB_FS_OPEN_STREAM;
3552 case FBSD_LUSB_GET_DEV_PORT_PATH:
3553 args->cmd = USB_GET_DEV_PORT_PATH;
3555 case FBSD_LUSB_GET_POWER_USAGE:
3556 args->cmd = USB_GET_POWER_USAGE;
3561 if (error != ENOIOCTL)
3562 error = sys_ioctl(td, (struct ioctl_args *)args);
3567 * main ioctl syscall function
3571 linux_ioctl(struct thread *td, struct linux_ioctl_args *args)
3573 cap_rights_t rights;
3575 struct handler_element *he;
3580 printf(ARGS(ioctl, "%d, %04lx, *"), args->fd,
3581 (unsigned long)args->cmd);
3584 error = fget(td, args->fd, cap_rights_init(&rights, CAP_IOCTL), &fp);
3587 if ((fp->f_flag & (FREAD|FWRITE)) == 0) {
3592 /* Iterate over the ioctl handlers */
3593 cmd = args->cmd & 0xffff;
3594 sx_slock(&linux_ioctl_sx);
3596 TAILQ_FOREACH(he, &handlers, list) {
3597 if (cmd >= he->low && cmd <= he->high) {
3598 error = (*he->func)(td, args);
3599 if (error != ENOIOCTL) {
3601 sx_sunlock(&linux_ioctl_sx);
3608 sx_sunlock(&linux_ioctl_sx);
3611 switch (args->cmd & 0xffff) {
3612 case LINUX_BTRFS_IOC_CLONE:
3616 linux_msg(td, "ioctl fd=%d, cmd=0x%x ('%c',%d) is not implemented",
3617 args->fd, (int)(args->cmd & 0xffff),
3618 (int)(args->cmd & 0xff00) >> 8, (int)(args->cmd & 0xff));
3626 linux_ioctl_register_handler(struct linux_ioctl_handler *h)
3628 struct handler_element *he, *cur;
3630 if (h == NULL || h->func == NULL)
3634 * Reuse the element if the handler is already on the list, otherwise
3635 * create a new element.
3637 sx_xlock(&linux_ioctl_sx);
3638 TAILQ_FOREACH(he, &handlers, list) {
3639 if (he->func == h->func)
3643 he = malloc(sizeof(*he),
3647 TAILQ_REMOVE(&handlers, he, list);
3649 /* Initialize range information. */
3652 he->span = h->high - h->low + 1;
3654 /* Add the element to the list, sorted on span. */
3655 TAILQ_FOREACH(cur, &handlers, list) {
3656 if (cur->span > he->span) {
3657 TAILQ_INSERT_BEFORE(cur, he, list);
3658 sx_xunlock(&linux_ioctl_sx);
3662 TAILQ_INSERT_TAIL(&handlers, he, list);
3663 sx_xunlock(&linux_ioctl_sx);
3669 linux_ioctl_unregister_handler(struct linux_ioctl_handler *h)
3671 struct handler_element *he;
3673 if (h == NULL || h->func == NULL)
3676 sx_xlock(&linux_ioctl_sx);
3677 TAILQ_FOREACH(he, &handlers, list) {
3678 if (he->func == h->func) {
3679 TAILQ_REMOVE(&handlers, he, list);
3680 sx_xunlock(&linux_ioctl_sx);
3685 sx_xunlock(&linux_ioctl_sx);