| File: | compat/linux/linux_ioctl.c |
| Warning: | line 771, column 12 Copies out a struct with uncleared padding (>= 1 bytes) |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /*- | |||
| 2 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | |||
| 3 | * | |||
| 4 | * Copyright (c) 1994-1995 Søren Schmidt | |||
| 5 | * All rights reserved. | |||
| 6 | * | |||
| 7 | * Redistribution and use in source and binary forms, with or without | |||
| 8 | * modification, are permitted provided that the following conditions | |||
| 9 | * are met: | |||
| 10 | * 1. Redistributions of source code must retain the above copyright | |||
| 11 | * notice, this list of conditions and the following disclaimer. | |||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | |||
| 13 | * notice, this list of conditions and the following disclaimer in the | |||
| 14 | * documentation and/or other materials provided with the distribution. | |||
| 15 | * | |||
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |||
| 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |||
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |||
| 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |||
| 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |||
| 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |||
| 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |||
| 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |||
| 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| 26 | * SUCH DAMAGE. | |||
| 27 | */ | |||
| 28 | ||||
| 29 | #include "opt_compat.h" | |||
| 30 | ||||
| 31 | #include <sys/cdefs.h> | |||
| 32 | __FBSDID("$FreeBSD$")__asm__(".ident\t\"" "$FreeBSD$" "\""); | |||
| 33 | ||||
| 34 | #include <sys/param.h> | |||
| 35 | #include <sys/systm.h> | |||
| 36 | #include <sys/sysproto.h> | |||
| 37 | #include <sys/capsicum.h> | |||
| 38 | #include <sys/cdio.h> | |||
| 39 | #include <sys/dvdio.h> | |||
| 40 | #include <sys/conf.h> | |||
| 41 | #include <sys/disk.h> | |||
| 42 | #include <sys/consio.h> | |||
| 43 | #include <sys/ctype.h> | |||
| 44 | #include <sys/fcntl.h> | |||
| 45 | #include <sys/file.h> | |||
| 46 | #include <sys/filedesc.h> | |||
| 47 | #include <sys/filio.h> | |||
| 48 | #include <sys/jail.h> | |||
| 49 | #include <sys/kbio.h> | |||
| 50 | #include <sys/kernel.h> | |||
| 51 | #include <sys/linker_set.h> | |||
| 52 | #include <sys/lock.h> | |||
| 53 | #include <sys/malloc.h> | |||
| 54 | #include <sys/proc.h> | |||
| 55 | #include <sys/sbuf.h> | |||
| 56 | #include <sys/socket.h> | |||
| 57 | #include <sys/sockio.h> | |||
| 58 | #include <sys/soundcard.h> | |||
| 59 | #include <sys/stdint.h> | |||
| 60 | #include <sys/sx.h> | |||
| 61 | #include <sys/sysctl.h> | |||
| 62 | #include <sys/tty.h> | |||
| 63 | #include <sys/uio.h> | |||
| 64 | #include <sys/types.h> | |||
| 65 | #include <sys/mman.h> | |||
| 66 | #include <sys/resourcevar.h> | |||
| 67 | ||||
| 68 | #include <net/if.h> | |||
| 69 | #include <net/if_var.h> | |||
| 70 | #include <net/if_dl.h> | |||
| 71 | #include <net/if_types.h> | |||
| 72 | ||||
| 73 | #include <dev/evdev/input.h> | |||
| 74 | #include <dev/usb/usb_ioctl.h> | |||
| 75 | ||||
| 76 | #ifdef COMPAT_LINUX32 | |||
| 77 | #include <machine/../linux32/linux.h> | |||
| 78 | #include <machine/../linux32/linux32_proto.h> | |||
| 79 | #else | |||
| 80 | #include <machine/../linux/linux.h> | |||
| 81 | #include <machine/../linux/linux_proto.h> | |||
| 82 | #endif | |||
| 83 | ||||
| 84 | #include <compat/linux/linux_ioctl.h> | |||
| 85 | #include <compat/linux/linux_mib.h> | |||
| 86 | #include <compat/linux/linux_socket.h> | |||
| 87 | #include <compat/linux/linux_timer.h> | |||
| 88 | #include <compat/linux/linux_util.h> | |||
| 89 | ||||
| 90 | #include <contrib/v4l/videodev.h> | |||
| 91 | #include <compat/linux/linux_videodev_compat.h> | |||
| 92 | ||||
| 93 | #include <contrib/v4l/videodev2.h> | |||
| 94 | #include <compat/linux/linux_videodev2_compat.h> | |||
| 95 | ||||
| 96 | #include <cam/scsi/scsi_sg.h> | |||
| 97 | ||||
| 98 | CTASSERT(LINUX_IFNAMSIZ == IFNAMSIZ)_Static_assert(16 == 16, "compile-time assertion failed"); | |||
| 99 | ||||
| 100 | static linux_ioctl_function_t linux_ioctl_cdrom; | |||
| 101 | static linux_ioctl_function_t linux_ioctl_vfat; | |||
| 102 | static linux_ioctl_function_t linux_ioctl_console; | |||
| 103 | static linux_ioctl_function_t linux_ioctl_hdio; | |||
| 104 | static linux_ioctl_function_t linux_ioctl_disk; | |||
| 105 | static linux_ioctl_function_t linux_ioctl_socket; | |||
| 106 | static linux_ioctl_function_t linux_ioctl_sound; | |||
| 107 | static linux_ioctl_function_t linux_ioctl_termio; | |||
| 108 | static linux_ioctl_function_t linux_ioctl_private; | |||
| 109 | static linux_ioctl_function_t linux_ioctl_drm; | |||
| 110 | static linux_ioctl_function_t linux_ioctl_sg; | |||
| 111 | static linux_ioctl_function_t linux_ioctl_v4l; | |||
| 112 | static linux_ioctl_function_t linux_ioctl_v4l2; | |||
| 113 | static linux_ioctl_function_t linux_ioctl_special; | |||
| 114 | static linux_ioctl_function_t linux_ioctl_fbsd_usb; | |||
| 115 | static linux_ioctl_function_t linux_ioctl_evdev; | |||
| 116 | ||||
| 117 | static struct linux_ioctl_handler cdrom_handler = | |||
| 118 | { linux_ioctl_cdrom, LINUX_IOCTL_CDROM_MIN0x5301, LINUX_IOCTL_CDROM_MAX0x5395 }; | |||
| 119 | static struct linux_ioctl_handler vfat_handler = | |||
| 120 | { linux_ioctl_vfat, LINUX_IOCTL_VFAT_MIN0x7201, LINUX_IOCTL_VFAT_MAX0x7201 }; | |||
| 121 | static struct linux_ioctl_handler console_handler = | |||
| 122 | { linux_ioctl_console, LINUX_IOCTL_CONSOLE_MIN0x4B2F, LINUX_IOCTL_CONSOLE_MAX0x5607 }; | |||
| 123 | static struct linux_ioctl_handler hdio_handler = | |||
| 124 | { linux_ioctl_hdio, LINUX_IOCTL_HDIO_MIN0x0301, LINUX_IOCTL_HDIO_MAX0x0330 }; | |||
| 125 | static struct linux_ioctl_handler disk_handler = | |||
| 126 | { linux_ioctl_disk, LINUX_IOCTL_DISK_MIN0x125d, LINUX_IOCTL_DISK_MAX0x1268 }; | |||
| 127 | static struct linux_ioctl_handler socket_handler = | |||
| 128 | { linux_ioctl_socket, LINUX_IOCTL_SOCKET_MIN0x8901, LINUX_IOCTL_SOCKET_MAX0x8938 }; | |||
| 129 | static struct linux_ioctl_handler sound_handler = | |||
| 130 | { linux_ioctl_sound, LINUX_IOCTL_SOUND_MIN0x4d00, LINUX_IOCTL_SOUND_MAX0x510E }; | |||
| 131 | static struct linux_ioctl_handler termio_handler = | |||
| 132 | { linux_ioctl_termio, LINUX_IOCTL_TERMIO_MIN0x5401, LINUX_IOCTL_TERMIO_MAX0x5457 }; | |||
| 133 | static struct linux_ioctl_handler private_handler = | |||
| 134 | { linux_ioctl_private, LINUX_IOCTL_PRIVATE_MIN0x89F0, LINUX_IOCTL_PRIVATE_MAX0x89F0 +0xf }; | |||
| 135 | static struct linux_ioctl_handler drm_handler = | |||
| 136 | { linux_ioctl_drm, LINUX_IOCTL_DRM_MIN0x6400, LINUX_IOCTL_DRM_MAX0x64ff }; | |||
| 137 | static struct linux_ioctl_handler sg_handler = | |||
| 138 | { linux_ioctl_sg, LINUX_IOCTL_SG_MIN0x2200, LINUX_IOCTL_SG_MAX0x22ff }; | |||
| 139 | static struct linux_ioctl_handler video_handler = | |||
| 140 | { linux_ioctl_v4l, LINUX_IOCTL_VIDEO_MIN0x7601, LINUX_IOCTL_VIDEO_MAX0x761d }; | |||
| 141 | static struct linux_ioctl_handler video2_handler = | |||
| 142 | { linux_ioctl_v4l2, LINUX_IOCTL_VIDEO2_MIN0x5600, LINUX_IOCTL_VIDEO2_MAX0x565b }; | |||
| 143 | static struct linux_ioctl_handler fbsd_usb = | |||
| 144 | { linux_ioctl_fbsd_usb, FBSD_LUSB_MIN0xffdd, FBSD_LUSB_MAX0xffff }; | |||
| 145 | static struct linux_ioctl_handler evdev_handler = | |||
| 146 | { linux_ioctl_evdev, LINUX_IOCTL_EVDEV_MIN0x4500, LINUX_IOCTL_EVDEV_MAX0x45ff }; | |||
| 147 | ||||
| 148 | DATA_SET(linux_ioctl_handler_set, cdrom_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_cdrom_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(cdrom_handler); | |||
| 149 | DATA_SET(linux_ioctl_handler_set, vfat_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_vfat_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(vfat_handler); | |||
| 150 | DATA_SET(linux_ioctl_handler_set, console_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_console_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(console_handler); | |||
| 151 | DATA_SET(linux_ioctl_handler_set, hdio_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_hdio_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(hdio_handler); | |||
| 152 | DATA_SET(linux_ioctl_handler_set, disk_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_disk_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(disk_handler); | |||
| 153 | DATA_SET(linux_ioctl_handler_set, socket_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_socket_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(socket_handler); | |||
| 154 | DATA_SET(linux_ioctl_handler_set, sound_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_sound_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(sound_handler); | |||
| 155 | DATA_SET(linux_ioctl_handler_set, termio_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_termio_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(termio_handler); | |||
| 156 | DATA_SET(linux_ioctl_handler_set, private_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_private_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(private_handler); | |||
| 157 | DATA_SET(linux_ioctl_handler_set, drm_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_drm_handler __attribute__ ((__section__("set_" "linux_ioctl_handler_set"))) __attribute__ ((__used__)) = &(drm_handler); | |||
| 158 | DATA_SET(linux_ioctl_handler_set, sg_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_sg_handler __attribute__ ((__section__("set_" "linux_ioctl_handler_set"))) __attribute__ ((__used__)) = &(sg_handler); | |||
| 159 | DATA_SET(linux_ioctl_handler_set, video_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_video_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(video_handler); | |||
| 160 | DATA_SET(linux_ioctl_handler_set, video2_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_video2_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(video2_handler); | |||
| 161 | DATA_SET(linux_ioctl_handler_set, fbsd_usb)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_fbsd_usb __attribute__ ((__section__("set_" "linux_ioctl_handler_set"))) __attribute__ ((__used__)) = &(fbsd_usb); | |||
| 162 | DATA_SET(linux_ioctl_handler_set, evdev_handler)__asm__(".globl " "__start_set_linux_ioctl_handler_set"); __asm__ (".globl " "__stop_set_linux_ioctl_handler_set"); static void const * const __set_linux_ioctl_handler_set_sym_evdev_handler __attribute__((__section__("set_" "linux_ioctl_handler_set") )) __attribute__((__used__)) = &(evdev_handler); | |||
| 163 | ||||
| 164 | #ifdef __i386__ | |||
| 165 | static TAILQ_HEAD(, linux_ioctl_handler_element)struct { struct linux_ioctl_handler_element *tqh_first; struct linux_ioctl_handler_element **tqh_last; } linux_ioctl_handlers = | |||
| 166 | TAILQ_HEAD_INITIALIZER(linux_ioctl_handlers){ ((void *)0), &(linux_ioctl_handlers).tqh_first, }; | |||
| 167 | static struct sx linux_ioctl_sx; | |||
| 168 | SX_SYSINIT(linux_ioctl, &linux_ioctl_sx, "Linux ioctl handlers")static struct sx_args linux_ioctl_args = { (&linux_ioctl_sx ), ("Linux ioctl handlers"), (0) }; static struct sysinit linux_ioctl_sx_sysinit_sys_init = { SI_SUB_LOCK, SI_ORDER_MIDDLE, (sysinit_cfunc_t)(sysinit_nfunc_t )sx_sysinit, ((void *)(&linux_ioctl_args)) }; __asm__(".globl " "__start_set_sysinit_set"); __asm__(".globl " "__stop_set_sysinit_set" ); static void const * __set_sysinit_set_sym_linux_ioctl_sx_sysinit_sys_init __attribute__((__section__("set_" "sysinit_set"))) __attribute__ ((__used__)) = &(linux_ioctl_sx_sysinit_sys_init); static struct sysinit linux_ioctl_sx_sysuninit_sys_uninit = { SI_SUB_LOCK , SI_ORDER_MIDDLE, (sysinit_cfunc_t)(sysinit_nfunc_t)sx_destroy , ((void *)((&linux_ioctl_sx))) }; __asm__(".globl " "__start_set_sysuninit_set" ); __asm__(".globl " "__stop_set_sysuninit_set"); static void const * __set_sysuninit_set_sym_linux_ioctl_sx_sysuninit_sys_uninit __attribute__((__section__("set_" "sysuninit_set"))) __attribute__ ((__used__)) = &(linux_ioctl_sx_sysuninit_sys_uninit); | |||
| 169 | #else | |||
| 170 | extern TAILQ_HEAD(, linux_ioctl_handler_element)struct { struct linux_ioctl_handler_element *tqh_first; struct linux_ioctl_handler_element **tqh_last; } linux_ioctl_handlers; | |||
| 171 | extern struct sx linux_ioctl_sx; | |||
| 172 | #endif | |||
| 173 | #ifdef COMPAT_LINUX32 | |||
| 174 | static TAILQ_HEAD(, linux_ioctl_handler_element)struct { struct linux_ioctl_handler_element *tqh_first; struct linux_ioctl_handler_element **tqh_last; } linux32_ioctl_handlers = | |||
| 175 | TAILQ_HEAD_INITIALIZER(linux32_ioctl_handlers){ ((void *)0), &(linux32_ioctl_handlers).tqh_first, }; | |||
| 176 | #endif | |||
| 177 | ||||
| 178 | /* | |||
| 179 | * hdio related ioctls for VMWare support | |||
| 180 | */ | |||
| 181 | ||||
| 182 | struct linux_hd_geometry { | |||
| 183 | u_int8_t heads; | |||
| 184 | u_int8_t sectors; | |||
| 185 | u_int16_t cylinders; | |||
| 186 | u_int32_t start; | |||
| 187 | }; | |||
| 188 | ||||
| 189 | struct linux_hd_big_geometry { | |||
| 190 | u_int8_t heads; | |||
| 191 | u_int8_t sectors; | |||
| 192 | u_int32_t cylinders; | |||
| 193 | u_int32_t start; | |||
| 194 | }; | |||
| 195 | ||||
| 196 | static int | |||
| 197 | linux_ioctl_hdio(struct thread *td, struct linux_ioctl_args *args) | |||
| 198 | { | |||
| 199 | struct file *fp; | |||
| 200 | int error; | |||
| 201 | u_int sectorsize, fwcylinders, fwheads, fwsectors; | |||
| 202 | off_t mediasize, bytespercyl; | |||
| 203 | ||||
| 204 | error = fget(td, args->fd, &cap_ioctl_rights, &fp); | |||
| 205 | if (error != 0) | |||
| 206 | return (error); | |||
| 207 | switch (args->cmd & 0xffff) { | |||
| 208 | case LINUX_HDIO_GET_GEO0x0301: | |||
| 209 | case LINUX_HDIO_GET_GEO_BIG0x0330: | |||
| 210 | error = fo_ioctl(fp, DIOCGMEDIASIZE((unsigned long) ((0x40000000) | (((sizeof(off_t)) & ((1 << 13) - 1)) << 16) | ((('d')) << 8) | ((129)))), | |||
| 211 | (caddr_t)&mediasize, td->td_ucred, td); | |||
| 212 | if (!error) | |||
| 213 | error = fo_ioctl(fp, DIOCGSECTORSIZE((unsigned long) ((0x40000000) | (((sizeof(u_int)) & ((1 << 13) - 1)) << 16) | ((('d')) << 8) | ((128)))), | |||
| 214 | (caddr_t)§orsize, td->td_ucred, td); | |||
| 215 | if (!error) | |||
| 216 | error = fo_ioctl(fp, DIOCGFWHEADS((unsigned long) ((0x40000000) | (((sizeof(u_int)) & ((1 << 13) - 1)) << 16) | ((('d')) << 8) | ((131)))), | |||
| 217 | (caddr_t)&fwheads, td->td_ucred, td); | |||
| 218 | if (!error) | |||
| 219 | error = fo_ioctl(fp, DIOCGFWSECTORS((unsigned long) ((0x40000000) | (((sizeof(u_int)) & ((1 << 13) - 1)) << 16) | ((('d')) << 8) | ((130)))), | |||
| 220 | (caddr_t)&fwsectors, td->td_ucred, td); | |||
| 221 | /* | |||
| 222 | * XXX: DIOCGFIRSTOFFSET is not yet implemented, so | |||
| 223 | * so pretend that GEOM always says 0. This is NOT VALID | |||
| 224 | * for slices or partitions, only the per-disk raw devices. | |||
| 225 | */ | |||
| 226 | ||||
| 227 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 228 | if (error) | |||
| 229 | return (error); | |||
| 230 | /* | |||
| 231 | * 1. Calculate the number of bytes in a cylinder, | |||
| 232 | * given the firmware's notion of heads and sectors | |||
| 233 | * per cylinder. | |||
| 234 | * 2. Calculate the number of cylinders, given the total | |||
| 235 | * size of the media. | |||
| 236 | * All internal calculations should have 64-bit precision. | |||
| 237 | */ | |||
| 238 | bytespercyl = (off_t) sectorsize * fwheads * fwsectors; | |||
| 239 | fwcylinders = mediasize / bytespercyl; | |||
| 240 | #if defined(DEBUG) | |||
| 241 | linux_msg(td, "HDIO_GET_GEO: mediasize %jd, c/h/s %d/%d/%d, " | |||
| 242 | "bpc %jd", | |||
| 243 | (intmax_t)mediasize, fwcylinders, fwheads, fwsectors, | |||
| 244 | (intmax_t)bytespercyl); | |||
| 245 | #endif | |||
| 246 | if ((args->cmd & 0xffff) == LINUX_HDIO_GET_GEO0x0301) { | |||
| 247 | struct linux_hd_geometry hdg; | |||
| 248 | ||||
| 249 | hdg.cylinders = fwcylinders; | |||
| 250 | hdg.heads = fwheads; | |||
| 251 | hdg.sectors = fwsectors; | |||
| 252 | hdg.start = 0; | |||
| 253 | error = copyout(&hdg, (void *)args->arg, sizeof(hdg)); | |||
| 254 | } else if ((args->cmd & 0xffff) == LINUX_HDIO_GET_GEO_BIG0x0330) { | |||
| 255 | struct linux_hd_big_geometry hdbg; | |||
| 256 | ||||
| 257 | memset(&hdbg, 0, sizeof(hdbg))__builtin_memset((&hdbg), (0), (sizeof(hdbg))); | |||
| 258 | hdbg.cylinders = fwcylinders; | |||
| 259 | hdbg.heads = fwheads; | |||
| 260 | hdbg.sectors = fwsectors; | |||
| 261 | hdbg.start = 0; | |||
| 262 | error = copyout(&hdbg, (void *)args->arg, sizeof(hdbg)); | |||
| 263 | } | |||
| 264 | return (error); | |||
| 265 | break; | |||
| 266 | default: | |||
| 267 | /* XXX */ | |||
| 268 | linux_msg(td, | |||
| 269 | "ioctl fd=%d, cmd=0x%x ('%c',%d) is not implemented", | |||
| 270 | args->fd, (int)(args->cmd & 0xffff), | |||
| 271 | (int)(args->cmd & 0xff00) >> 8, | |||
| 272 | (int)(args->cmd & 0xff)); | |||
| 273 | break; | |||
| 274 | } | |||
| 275 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 276 | return (ENOIOCTL(-3)); | |||
| 277 | } | |||
| 278 | ||||
| 279 | static int | |||
| 280 | linux_ioctl_disk(struct thread *td, struct linux_ioctl_args *args) | |||
| 281 | { | |||
| 282 | struct file *fp; | |||
| 283 | int error; | |||
| 284 | u_int sectorsize; | |||
| 285 | off_t mediasize; | |||
| 286 | ||||
| 287 | error = fget(td, args->fd, &cap_ioctl_rights, &fp); | |||
| 288 | if (error != 0) | |||
| 289 | return (error); | |||
| 290 | switch (args->cmd & 0xffff) { | |||
| 291 | case LINUX_BLKGETSIZE0x1260: | |||
| 292 | error = fo_ioctl(fp, DIOCGSECTORSIZE((unsigned long) ((0x40000000) | (((sizeof(u_int)) & ((1 << 13) - 1)) << 16) | ((('d')) << 8) | ((128)))), | |||
| 293 | (caddr_t)§orsize, td->td_ucred, td); | |||
| 294 | if (!error) | |||
| 295 | error = fo_ioctl(fp, DIOCGMEDIASIZE((unsigned long) ((0x40000000) | (((sizeof(off_t)) & ((1 << 13) - 1)) << 16) | ((('d')) << 8) | ((129)))), | |||
| 296 | (caddr_t)&mediasize, td->td_ucred, td); | |||
| 297 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 298 | if (error) | |||
| 299 | return (error); | |||
| 300 | sectorsize = mediasize / sectorsize; | |||
| 301 | /* | |||
| 302 | * XXX: How do we know we return the right size of integer ? | |||
| 303 | */ | |||
| 304 | return (copyout(§orsize, (void *)args->arg, | |||
| 305 | sizeof(sectorsize))); | |||
| 306 | break; | |||
| 307 | case LINUX_BLKSSZGET0x1268: | |||
| 308 | error = fo_ioctl(fp, DIOCGSECTORSIZE((unsigned long) ((0x40000000) | (((sizeof(u_int)) & ((1 << 13) - 1)) << 16) | ((('d')) << 8) | ((128)))), | |||
| 309 | (caddr_t)§orsize, td->td_ucred, td); | |||
| 310 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 311 | if (error) | |||
| 312 | return (error); | |||
| 313 | return (copyout(§orsize, (void *)args->arg, | |||
| 314 | sizeof(sectorsize))); | |||
| 315 | break; | |||
| 316 | } | |||
| 317 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 318 | return (ENOIOCTL(-3)); | |||
| 319 | } | |||
| 320 | ||||
| 321 | /* | |||
| 322 | * termio related ioctls | |||
| 323 | */ | |||
| 324 | ||||
| 325 | struct linux_termio { | |||
| 326 | unsigned short c_iflag; | |||
| 327 | unsigned short c_oflag; | |||
| 328 | unsigned short c_cflag; | |||
| 329 | unsigned short c_lflag; | |||
| 330 | unsigned char c_line; | |||
| 331 | unsigned char c_cc[LINUX_NCC8]; | |||
| 332 | }; | |||
| 333 | ||||
| 334 | struct linux_termios { | |||
| 335 | unsigned int c_iflag; | |||
| 336 | unsigned int c_oflag; | |||
| 337 | unsigned int c_cflag; | |||
| 338 | unsigned int c_lflag; | |||
| 339 | unsigned char c_line; | |||
| 340 | unsigned char c_cc[LINUX_NCCS19]; | |||
| 341 | }; | |||
| 342 | ||||
| 343 | struct linux_winsize { | |||
| 344 | unsigned short ws_row, ws_col; | |||
| 345 | unsigned short ws_xpixel, ws_ypixel; | |||
| 346 | }; | |||
| 347 | ||||
| 348 | struct speedtab { | |||
| 349 | int sp_speed; /* Speed. */ | |||
| 350 | int sp_code; /* Code. */ | |||
| 351 | }; | |||
| 352 | ||||
| 353 | static struct speedtab sptab[] = { | |||
| 354 | { B00, LINUX_B00x00000000 }, { B5050, LINUX_B500x00000001 }, | |||
| 355 | { B7575, LINUX_B750x00000002 }, { B110110, LINUX_B1100x00000003 }, | |||
| 356 | { B134134, LINUX_B1340x00000004 }, { B150150, LINUX_B1500x00000005 }, | |||
| 357 | { B200200, LINUX_B2000x00000006 }, { B300300, LINUX_B3000x00000007 }, | |||
| 358 | { B600600, LINUX_B6000x00000008 }, { B12001200, LINUX_B12000x00000009 }, | |||
| 359 | { B18001800, LINUX_B18000x0000000a }, { B24002400, LINUX_B24000x0000000b }, | |||
| 360 | { B48004800, LINUX_B48000x0000000c }, { B96009600, LINUX_B96000x0000000d }, | |||
| 361 | { B1920019200, LINUX_B192000x0000000e }, { B3840038400, LINUX_B384000x0000000f }, | |||
| 362 | { B5760057600, LINUX_B576000x00001001 }, { B115200115200, LINUX_B1152000x00001002 }, | |||
| 363 | {-1, -1 } | |||
| 364 | }; | |||
| 365 | ||||
| 366 | struct linux_serial_struct { | |||
| 367 | int type; | |||
| 368 | int line; | |||
| 369 | int port; | |||
| 370 | int irq; | |||
| 371 | int flags; | |||
| 372 | int xmit_fifo_size; | |||
| 373 | int custom_divisor; | |||
| 374 | int baud_base; | |||
| 375 | unsigned short close_delay; | |||
| 376 | char reserved_char[2]; | |||
| 377 | int hub6; | |||
| 378 | unsigned short closing_wait; | |||
| 379 | unsigned short closing_wait2; | |||
| 380 | int reserved[4]; | |||
| 381 | }; | |||
| 382 | ||||
| 383 | static int | |||
| 384 | linux_to_bsd_speed(int code, struct speedtab *table) | |||
| 385 | { | |||
| 386 | for ( ; table->sp_code != -1; table++) | |||
| 387 | if (table->sp_code == code) | |||
| 388 | return (table->sp_speed); | |||
| 389 | return (-1); | |||
| 390 | } | |||
| 391 | ||||
| 392 | static int | |||
| 393 | bsd_to_linux_speed(int speed, struct speedtab *table) | |||
| 394 | { | |||
| 395 | for ( ; table->sp_speed != -1; table++) | |||
| 396 | if (table->sp_speed == speed) | |||
| 397 | return (table->sp_code); | |||
| 398 | return (-1); | |||
| 399 | } | |||
| 400 | ||||
| 401 | static void | |||
| 402 | bsd_to_linux_termios(struct termios *bios, struct linux_termios *lios) | |||
| 403 | { | |||
| 404 | int i; | |||
| 405 | ||||
| 406 | #ifdef DEBUG | |||
| 407 | if (ldebug(ioctl)((((const unsigned char *)(linux_debug_map))[(16)/8] & (1 <<((16)%8))) == 0)) { | |||
| 408 | printf("LINUX: BSD termios structure (input):\n"); | |||
| 409 | printf("i=%08x o=%08x c=%08x l=%08x ispeed=%d ospeed=%d\n", | |||
| 410 | bios->c_iflag, bios->c_oflag, bios->c_cflag, bios->c_lflag, | |||
| 411 | bios->c_ispeed, bios->c_ospeed); | |||
| 412 | printf("c_cc "); | |||
| 413 | for (i=0; i<NCCS20; i++) | |||
| 414 | printf("%02x ", bios->c_cc[i]); | |||
| 415 | printf("\n"); | |||
| 416 | } | |||
| 417 | #endif | |||
| 418 | ||||
| 419 | lios->c_iflag = 0; | |||
| 420 | if (bios->c_iflag & IGNBRK0x00000001) | |||
| 421 | lios->c_iflag |= LINUX_IGNBRK0x0000001; | |||
| 422 | if (bios->c_iflag & BRKINT0x00000002) | |||
| 423 | lios->c_iflag |= LINUX_BRKINT0x0000002; | |||
| 424 | if (bios->c_iflag & IGNPAR0x00000004) | |||
| 425 | lios->c_iflag |= LINUX_IGNPAR0x0000004; | |||
| 426 | if (bios->c_iflag & PARMRK0x00000008) | |||
| 427 | lios->c_iflag |= LINUX_PARMRK0x0000008; | |||
| 428 | if (bios->c_iflag & INPCK0x00000010) | |||
| 429 | lios->c_iflag |= LINUX_INPCK0x0000010; | |||
| 430 | if (bios->c_iflag & ISTRIP0x00000020) | |||
| 431 | lios->c_iflag |= LINUX_ISTRIP0x0000020; | |||
| 432 | if (bios->c_iflag & INLCR0x00000040) | |||
| 433 | lios->c_iflag |= LINUX_INLCR0x0000040; | |||
| 434 | if (bios->c_iflag & IGNCR0x00000080) | |||
| 435 | lios->c_iflag |= LINUX_IGNCR0x0000080; | |||
| 436 | if (bios->c_iflag & ICRNL0x00000100) | |||
| 437 | lios->c_iflag |= LINUX_ICRNL0x0000100; | |||
| 438 | if (bios->c_iflag & IXON0x00000200) | |||
| 439 | lios->c_iflag |= LINUX_IXON0x0000400; | |||
| 440 | if (bios->c_iflag & IXANY0x00000800) | |||
| 441 | lios->c_iflag |= LINUX_IXANY0x0000800; | |||
| 442 | if (bios->c_iflag & IXOFF0x00000400) | |||
| 443 | lios->c_iflag |= LINUX_IXOFF0x0001000; | |||
| 444 | if (bios->c_iflag & IMAXBEL0x00002000) | |||
| 445 | lios->c_iflag |= LINUX_IMAXBEL0x0002000; | |||
| 446 | ||||
| 447 | lios->c_oflag = 0; | |||
| 448 | if (bios->c_oflag & OPOST0x00000001) | |||
| 449 | lios->c_oflag |= LINUX_OPOST0x0000001; | |||
| 450 | if (bios->c_oflag & ONLCR0x00000002) | |||
| 451 | lios->c_oflag |= LINUX_ONLCR0x0000004; | |||
| 452 | if (bios->c_oflag & TAB30x00000004) | |||
| 453 | lios->c_oflag |= LINUX_XTABS0x0001800; | |||
| 454 | ||||
| 455 | lios->c_cflag = bsd_to_linux_speed(bios->c_ispeed, sptab); | |||
| 456 | lios->c_cflag |= (bios->c_cflag & CSIZE0x00000300) >> 4; | |||
| 457 | if (bios->c_cflag & CSTOPB0x00000400) | |||
| 458 | lios->c_cflag |= LINUX_CSTOPB0x00000040; | |||
| 459 | if (bios->c_cflag & CREAD0x00000800) | |||
| 460 | lios->c_cflag |= LINUX_CREAD0x00000080; | |||
| 461 | if (bios->c_cflag & PARENB0x00001000) | |||
| 462 | lios->c_cflag |= LINUX_PARENB0x00000100; | |||
| 463 | if (bios->c_cflag & PARODD0x00002000) | |||
| 464 | lios->c_cflag |= LINUX_PARODD0x00000200; | |||
| 465 | if (bios->c_cflag & HUPCL0x00004000) | |||
| 466 | lios->c_cflag |= LINUX_HUPCL0x00000400; | |||
| 467 | if (bios->c_cflag & CLOCAL0x00008000) | |||
| 468 | lios->c_cflag |= LINUX_CLOCAL0x00000800; | |||
| 469 | if (bios->c_cflag & CRTSCTS(0x00010000 | 0x00020000)) | |||
| 470 | lios->c_cflag |= LINUX_CRTSCTS0x80000000; | |||
| 471 | ||||
| 472 | lios->c_lflag = 0; | |||
| 473 | if (bios->c_lflag & ISIG0x00000080) | |||
| 474 | lios->c_lflag |= LINUX_ISIG0x00000001; | |||
| 475 | if (bios->c_lflag & ICANON0x00000100) | |||
| 476 | lios->c_lflag |= LINUX_ICANON0x00000002; | |||
| 477 | if (bios->c_lflag & ECHO0x00000008) | |||
| 478 | lios->c_lflag |= LINUX_ECHO0x00000008; | |||
| 479 | if (bios->c_lflag & ECHOE0x00000002) | |||
| 480 | lios->c_lflag |= LINUX_ECHOE0x00000010; | |||
| 481 | if (bios->c_lflag & ECHOK0x00000004) | |||
| 482 | lios->c_lflag |= LINUX_ECHOK0x00000020; | |||
| 483 | if (bios->c_lflag & ECHONL0x00000010) | |||
| 484 | lios->c_lflag |= LINUX_ECHONL0x00000040; | |||
| 485 | if (bios->c_lflag & NOFLSH0x80000000) | |||
| 486 | lios->c_lflag |= LINUX_NOFLSH0x00000080; | |||
| 487 | if (bios->c_lflag & TOSTOP0x00400000) | |||
| 488 | lios->c_lflag |= LINUX_TOSTOP0x00000100; | |||
| 489 | if (bios->c_lflag & ECHOCTL0x00000040) | |||
| 490 | lios->c_lflag |= LINUX_ECHOCTL0x00000200; | |||
| 491 | if (bios->c_lflag & ECHOPRT0x00000020) | |||
| 492 | lios->c_lflag |= LINUX_ECHOPRT0x00000400; | |||
| 493 | if (bios->c_lflag & ECHOKE0x00000001) | |||
| 494 | lios->c_lflag |= LINUX_ECHOKE0x00000800; | |||
| 495 | if (bios->c_lflag & FLUSHO0x00800000) | |||
| 496 | lios->c_lflag |= LINUX_FLUSHO0x00001000; | |||
| 497 | if (bios->c_lflag & PENDIN0x20000000) | |||
| 498 | lios->c_lflag |= LINUX_PENDIN0x00002000; | |||
| 499 | if (bios->c_lflag & IEXTEN0x00000400) | |||
| 500 | lios->c_lflag |= LINUX_IEXTEN0x00008000; | |||
| 501 | ||||
| 502 | for (i=0; i<LINUX_NCCS19; i++) | |||
| 503 | lios->c_cc[i] = LINUX_POSIX_VDISABLE'\0'; | |||
| 504 | lios->c_cc[LINUX_VINTR0] = bios->c_cc[VINTR8]; | |||
| 505 | lios->c_cc[LINUX_VQUIT1] = bios->c_cc[VQUIT9]; | |||
| 506 | lios->c_cc[LINUX_VERASE2] = bios->c_cc[VERASE3]; | |||
| 507 | lios->c_cc[LINUX_VKILL3] = bios->c_cc[VKILL5]; | |||
| 508 | lios->c_cc[LINUX_VEOF4] = bios->c_cc[VEOF0]; | |||
| 509 | lios->c_cc[LINUX_VEOL11] = bios->c_cc[VEOL1]; | |||
| 510 | lios->c_cc[LINUX_VMIN6] = bios->c_cc[VMIN16]; | |||
| 511 | lios->c_cc[LINUX_VTIME5] = bios->c_cc[VTIME17]; | |||
| 512 | lios->c_cc[LINUX_VEOL216] = bios->c_cc[VEOL22]; | |||
| 513 | lios->c_cc[LINUX_VSUSP10] = bios->c_cc[VSUSP10]; | |||
| 514 | lios->c_cc[LINUX_VSTART8] = bios->c_cc[VSTART12]; | |||
| 515 | lios->c_cc[LINUX_VSTOP9] = bios->c_cc[VSTOP13]; | |||
| 516 | lios->c_cc[LINUX_VREPRINT12] = bios->c_cc[VREPRINT6]; | |||
| 517 | lios->c_cc[LINUX_VDISCARD13] = bios->c_cc[VDISCARD15]; | |||
| 518 | lios->c_cc[LINUX_VWERASE14] = bios->c_cc[VWERASE4]; | |||
| 519 | lios->c_cc[LINUX_VLNEXT15] = bios->c_cc[VLNEXT14]; | |||
| 520 | ||||
| 521 | for (i=0; i<LINUX_NCCS19; i++) { | |||
| 522 | if (i != LINUX_VMIN6 && i != LINUX_VTIME5 && | |||
| 523 | lios->c_cc[i] == _POSIX_VDISABLE0xff) | |||
| 524 | lios->c_cc[i] = LINUX_POSIX_VDISABLE'\0'; | |||
| 525 | } | |||
| 526 | lios->c_line = 0; | |||
| 527 | ||||
| 528 | #ifdef DEBUG | |||
| 529 | if (ldebug(ioctl)((((const unsigned char *)(linux_debug_map))[(16)/8] & (1 <<((16)%8))) == 0)) { | |||
| 530 | printf("LINUX: LINUX termios structure (output):\n"); | |||
| 531 | printf("i=%08x o=%08x c=%08x l=%08x line=%d\n", | |||
| 532 | lios->c_iflag, lios->c_oflag, lios->c_cflag, | |||
| 533 | lios->c_lflag, (int)lios->c_line); | |||
| 534 | printf("c_cc "); | |||
| 535 | for (i=0; i<LINUX_NCCS19; i++) | |||
| 536 | printf("%02x ", lios->c_cc[i]); | |||
| 537 | printf("\n"); | |||
| 538 | } | |||
| 539 | #endif | |||
| 540 | } | |||
| 541 | ||||
| 542 | static void | |||
| 543 | linux_to_bsd_termios(struct linux_termios *lios, struct termios *bios) | |||
| 544 | { | |||
| 545 | int i; | |||
| 546 | ||||
| 547 | #ifdef DEBUG | |||
| 548 | if (ldebug(ioctl)((((const unsigned char *)(linux_debug_map))[(16)/8] & (1 <<((16)%8))) == 0)) { | |||
| 549 | printf("LINUX: LINUX termios structure (input):\n"); | |||
| 550 | printf("i=%08x o=%08x c=%08x l=%08x line=%d\n", | |||
| 551 | lios->c_iflag, lios->c_oflag, lios->c_cflag, | |||
| 552 | lios->c_lflag, (int)lios->c_line); | |||
| 553 | printf("c_cc "); | |||
| 554 | for (i=0; i<LINUX_NCCS19; i++) | |||
| 555 | printf("%02x ", lios->c_cc[i]); | |||
| 556 | printf("\n"); | |||
| 557 | } | |||
| 558 | #endif | |||
| 559 | ||||
| 560 | bios->c_iflag = 0; | |||
| 561 | if (lios->c_iflag & LINUX_IGNBRK0x0000001) | |||
| 562 | bios->c_iflag |= IGNBRK0x00000001; | |||
| 563 | if (lios->c_iflag & LINUX_BRKINT0x0000002) | |||
| 564 | bios->c_iflag |= BRKINT0x00000002; | |||
| 565 | if (lios->c_iflag & LINUX_IGNPAR0x0000004) | |||
| 566 | bios->c_iflag |= IGNPAR0x00000004; | |||
| 567 | if (lios->c_iflag & LINUX_PARMRK0x0000008) | |||
| 568 | bios->c_iflag |= PARMRK0x00000008; | |||
| 569 | if (lios->c_iflag & LINUX_INPCK0x0000010) | |||
| 570 | bios->c_iflag |= INPCK0x00000010; | |||
| 571 | if (lios->c_iflag & LINUX_ISTRIP0x0000020) | |||
| 572 | bios->c_iflag |= ISTRIP0x00000020; | |||
| 573 | if (lios->c_iflag & LINUX_INLCR0x0000040) | |||
| 574 | bios->c_iflag |= INLCR0x00000040; | |||
| 575 | if (lios->c_iflag & LINUX_IGNCR0x0000080) | |||
| 576 | bios->c_iflag |= IGNCR0x00000080; | |||
| 577 | if (lios->c_iflag & LINUX_ICRNL0x0000100) | |||
| 578 | bios->c_iflag |= ICRNL0x00000100; | |||
| 579 | if (lios->c_iflag & LINUX_IXON0x0000400) | |||
| 580 | bios->c_iflag |= IXON0x00000200; | |||
| 581 | if (lios->c_iflag & LINUX_IXANY0x0000800) | |||
| 582 | bios->c_iflag |= IXANY0x00000800; | |||
| 583 | if (lios->c_iflag & LINUX_IXOFF0x0001000) | |||
| 584 | bios->c_iflag |= IXOFF0x00000400; | |||
| 585 | if (lios->c_iflag & LINUX_IMAXBEL0x0002000) | |||
| 586 | bios->c_iflag |= IMAXBEL0x00002000; | |||
| 587 | ||||
| 588 | bios->c_oflag = 0; | |||
| 589 | if (lios->c_oflag & LINUX_OPOST0x0000001) | |||
| 590 | bios->c_oflag |= OPOST0x00000001; | |||
| 591 | if (lios->c_oflag & LINUX_ONLCR0x0000004) | |||
| 592 | bios->c_oflag |= ONLCR0x00000002; | |||
| 593 | if (lios->c_oflag & LINUX_XTABS0x0001800) | |||
| 594 | bios->c_oflag |= TAB30x00000004; | |||
| 595 | ||||
| 596 | bios->c_cflag = (lios->c_cflag & LINUX_CSIZE0x00000030) << 4; | |||
| 597 | if (lios->c_cflag & LINUX_CSTOPB0x00000040) | |||
| 598 | bios->c_cflag |= CSTOPB0x00000400; | |||
| 599 | if (lios->c_cflag & LINUX_CREAD0x00000080) | |||
| 600 | bios->c_cflag |= CREAD0x00000800; | |||
| 601 | if (lios->c_cflag & LINUX_PARENB0x00000100) | |||
| 602 | bios->c_cflag |= PARENB0x00001000; | |||
| 603 | if (lios->c_cflag & LINUX_PARODD0x00000200) | |||
| 604 | bios->c_cflag |= PARODD0x00002000; | |||
| 605 | if (lios->c_cflag & LINUX_HUPCL0x00000400) | |||
| 606 | bios->c_cflag |= HUPCL0x00004000; | |||
| 607 | if (lios->c_cflag & LINUX_CLOCAL0x00000800) | |||
| 608 | bios->c_cflag |= CLOCAL0x00008000; | |||
| 609 | if (lios->c_cflag & LINUX_CRTSCTS0x80000000) | |||
| 610 | bios->c_cflag |= CRTSCTS(0x00010000 | 0x00020000); | |||
| 611 | ||||
| 612 | bios->c_lflag = 0; | |||
| 613 | if (lios->c_lflag & LINUX_ISIG0x00000001) | |||
| 614 | bios->c_lflag |= ISIG0x00000080; | |||
| 615 | if (lios->c_lflag & LINUX_ICANON0x00000002) | |||
| 616 | bios->c_lflag |= ICANON0x00000100; | |||
| 617 | if (lios->c_lflag & LINUX_ECHO0x00000008) | |||
| 618 | bios->c_lflag |= ECHO0x00000008; | |||
| 619 | if (lios->c_lflag & LINUX_ECHOE0x00000010) | |||
| 620 | bios->c_lflag |= ECHOE0x00000002; | |||
| 621 | if (lios->c_lflag & LINUX_ECHOK0x00000020) | |||
| 622 | bios->c_lflag |= ECHOK0x00000004; | |||
| 623 | if (lios->c_lflag & LINUX_ECHONL0x00000040) | |||
| 624 | bios->c_lflag |= ECHONL0x00000010; | |||
| 625 | if (lios->c_lflag & LINUX_NOFLSH0x00000080) | |||
| 626 | bios->c_lflag |= NOFLSH0x80000000; | |||
| 627 | if (lios->c_lflag & LINUX_TOSTOP0x00000100) | |||
| 628 | bios->c_lflag |= TOSTOP0x00400000; | |||
| 629 | if (lios->c_lflag & LINUX_ECHOCTL0x00000200) | |||
| 630 | bios->c_lflag |= ECHOCTL0x00000040; | |||
| 631 | if (lios->c_lflag & LINUX_ECHOPRT0x00000400) | |||
| 632 | bios->c_lflag |= ECHOPRT0x00000020; | |||
| 633 | if (lios->c_lflag & LINUX_ECHOKE0x00000800) | |||
| 634 | bios->c_lflag |= ECHOKE0x00000001; | |||
| 635 | if (lios->c_lflag & LINUX_FLUSHO0x00001000) | |||
| 636 | bios->c_lflag |= FLUSHO0x00800000; | |||
| 637 | if (lios->c_lflag & LINUX_PENDIN0x00002000) | |||
| 638 | bios->c_lflag |= PENDIN0x20000000; | |||
| 639 | if (lios->c_lflag & LINUX_IEXTEN0x00008000) | |||
| 640 | bios->c_lflag |= IEXTEN0x00000400; | |||
| 641 | ||||
| 642 | for (i=0; i<NCCS20; i++) | |||
| 643 | bios->c_cc[i] = _POSIX_VDISABLE0xff; | |||
| 644 | bios->c_cc[VINTR8] = lios->c_cc[LINUX_VINTR0]; | |||
| 645 | bios->c_cc[VQUIT9] = lios->c_cc[LINUX_VQUIT1]; | |||
| 646 | bios->c_cc[VERASE3] = lios->c_cc[LINUX_VERASE2]; | |||
| 647 | bios->c_cc[VKILL5] = lios->c_cc[LINUX_VKILL3]; | |||
| 648 | bios->c_cc[VEOF0] = lios->c_cc[LINUX_VEOF4]; | |||
| 649 | bios->c_cc[VEOL1] = lios->c_cc[LINUX_VEOL11]; | |||
| 650 | bios->c_cc[VMIN16] = lios->c_cc[LINUX_VMIN6]; | |||
| 651 | bios->c_cc[VTIME17] = lios->c_cc[LINUX_VTIME5]; | |||
| 652 | bios->c_cc[VEOL22] = lios->c_cc[LINUX_VEOL216]; | |||
| 653 | bios->c_cc[VSUSP10] = lios->c_cc[LINUX_VSUSP10]; | |||
| 654 | bios->c_cc[VSTART12] = lios->c_cc[LINUX_VSTART8]; | |||
| 655 | bios->c_cc[VSTOP13] = lios->c_cc[LINUX_VSTOP9]; | |||
| 656 | bios->c_cc[VREPRINT6] = lios->c_cc[LINUX_VREPRINT12]; | |||
| 657 | bios->c_cc[VDISCARD15] = lios->c_cc[LINUX_VDISCARD13]; | |||
| 658 | bios->c_cc[VWERASE4] = lios->c_cc[LINUX_VWERASE14]; | |||
| 659 | bios->c_cc[VLNEXT14] = lios->c_cc[LINUX_VLNEXT15]; | |||
| 660 | ||||
| 661 | for (i=0; i<NCCS20; i++) { | |||
| 662 | if (i != VMIN16 && i != VTIME17 && | |||
| 663 | bios->c_cc[i] == LINUX_POSIX_VDISABLE'\0') | |||
| 664 | bios->c_cc[i] = _POSIX_VDISABLE0xff; | |||
| 665 | } | |||
| 666 | ||||
| 667 | bios->c_ispeed = bios->c_ospeed = | |||
| 668 | linux_to_bsd_speed(lios->c_cflag & LINUX_CBAUD0x0000100f, sptab); | |||
| 669 | ||||
| 670 | #ifdef DEBUG | |||
| 671 | if (ldebug(ioctl)((((const unsigned char *)(linux_debug_map))[(16)/8] & (1 <<((16)%8))) == 0)) { | |||
| 672 | printf("LINUX: BSD termios structure (output):\n"); | |||
| 673 | printf("i=%08x o=%08x c=%08x l=%08x ispeed=%d ospeed=%d\n", | |||
| 674 | bios->c_iflag, bios->c_oflag, bios->c_cflag, bios->c_lflag, | |||
| 675 | bios->c_ispeed, bios->c_ospeed); | |||
| 676 | printf("c_cc "); | |||
| 677 | for (i=0; i<NCCS20; i++) | |||
| 678 | printf("%02x ", bios->c_cc[i]); | |||
| 679 | printf("\n"); | |||
| 680 | } | |||
| 681 | #endif | |||
| 682 | } | |||
| 683 | ||||
| 684 | static void | |||
| 685 | bsd_to_linux_termio(struct termios *bios, struct linux_termio *lio) | |||
| 686 | { | |||
| 687 | struct linux_termios lios; | |||
| 688 | ||||
| 689 | bsd_to_linux_termios(bios, &lios); | |||
| 690 | lio->c_iflag = lios.c_iflag; | |||
| 691 | lio->c_oflag = lios.c_oflag; | |||
| 692 | lio->c_cflag = lios.c_cflag; | |||
| 693 | lio->c_lflag = lios.c_lflag; | |||
| 694 | lio->c_line = lios.c_line; | |||
| 695 | memcpy(lio->c_cc, lios.c_cc, LINUX_NCC)__builtin_memcpy((lio->c_cc), (lios.c_cc), (8)); | |||
| 696 | } | |||
| 697 | ||||
| 698 | static void | |||
| 699 | linux_to_bsd_termio(struct linux_termio *lio, struct termios *bios) | |||
| 700 | { | |||
| 701 | struct linux_termios lios; | |||
| 702 | int i; | |||
| 703 | ||||
| 704 | lios.c_iflag = lio->c_iflag; | |||
| 705 | lios.c_oflag = lio->c_oflag; | |||
| 706 | lios.c_cflag = lio->c_cflag; | |||
| 707 | lios.c_lflag = lio->c_lflag; | |||
| 708 | for (i=LINUX_NCC8; i<LINUX_NCCS19; i++) | |||
| 709 | lios.c_cc[i] = LINUX_POSIX_VDISABLE'\0'; | |||
| 710 | memcpy(lios.c_cc, lio->c_cc, LINUX_NCC)__builtin_memcpy((lios.c_cc), (lio->c_cc), (8)); | |||
| 711 | linux_to_bsd_termios(&lios, bios); | |||
| 712 | } | |||
| 713 | ||||
| 714 | static int | |||
| 715 | linux_ioctl_termio(struct thread *td, struct linux_ioctl_args *args) | |||
| 716 | { | |||
| 717 | struct termios bios; | |||
| 718 | struct linux_termios lios; | |||
| 719 | struct linux_termio lio; | |||
| 720 | struct file *fp; | |||
| 721 | int error; | |||
| 722 | ||||
| 723 | error = fget(td, args->fd, &cap_ioctl_rights, &fp); | |||
| 724 | if (error != 0) | |||
| ||||
| 725 | return (error); | |||
| 726 | ||||
| 727 | switch (args->cmd & 0xffff) { | |||
| 728 | ||||
| 729 | case LINUX_TCGETS0x5401: | |||
| 730 | error = fo_ioctl(fp, TIOCGETA((unsigned long) ((0x40000000) | (((sizeof(struct termios)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((19)))), (caddr_t)&bios, td->td_ucred, | |||
| 731 | td); | |||
| 732 | if (error) | |||
| 733 | break; | |||
| 734 | bsd_to_linux_termios(&bios, &lios); | |||
| 735 | error = copyout(&lios, (void *)args->arg, sizeof(lios)); | |||
| 736 | break; | |||
| 737 | ||||
| 738 | case LINUX_TCSETS0x5402: | |||
| 739 | error = copyin((void *)args->arg, &lios, sizeof(lios)); | |||
| 740 | if (error) | |||
| 741 | break; | |||
| 742 | linux_to_bsd_termios(&lios, &bios); | |||
| 743 | error = (fo_ioctl(fp, TIOCSETA((unsigned long) ((0x80000000) | (((sizeof(struct termios)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((20)))), (caddr_t)&bios, td->td_ucred, | |||
| 744 | td)); | |||
| 745 | break; | |||
| 746 | ||||
| 747 | case LINUX_TCSETSW0x5403: | |||
| 748 | error = copyin((void *)args->arg, &lios, sizeof(lios)); | |||
| 749 | if (error) | |||
| 750 | break; | |||
| 751 | linux_to_bsd_termios(&lios, &bios); | |||
| 752 | error = (fo_ioctl(fp, TIOCSETAW((unsigned long) ((0x80000000) | (((sizeof(struct termios)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((21)))), (caddr_t)&bios, td->td_ucred, | |||
| 753 | td)); | |||
| 754 | break; | |||
| 755 | ||||
| 756 | case LINUX_TCSETSF0x5404: | |||
| 757 | error = copyin((void *)args->arg, &lios, sizeof(lios)); | |||
| 758 | if (error) | |||
| 759 | break; | |||
| 760 | linux_to_bsd_termios(&lios, &bios); | |||
| 761 | error = (fo_ioctl(fp, TIOCSETAF((unsigned long) ((0x80000000) | (((sizeof(struct termios)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((22)))), (caddr_t)&bios, td->td_ucred, | |||
| 762 | td)); | |||
| 763 | break; | |||
| 764 | ||||
| 765 | case LINUX_TCGETA0x5405: | |||
| 766 | error = fo_ioctl(fp, TIOCGETA((unsigned long) ((0x40000000) | (((sizeof(struct termios)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((19)))), (caddr_t)&bios, td->td_ucred, | |||
| 767 | td); | |||
| 768 | if (error) | |||
| 769 | break; | |||
| 770 | bsd_to_linux_termio(&bios, &lio); | |||
| 771 | error = (copyout(&lio, (void *)args->arg, sizeof(lio))); | |||
| ||||
| 772 | break; | |||
| 773 | ||||
| 774 | case LINUX_TCSETA0x5406: | |||
| 775 | error = copyin((void *)args->arg, &lio, sizeof(lio)); | |||
| 776 | if (error) | |||
| 777 | break; | |||
| 778 | linux_to_bsd_termio(&lio, &bios); | |||
| 779 | error = (fo_ioctl(fp, TIOCSETA((unsigned long) ((0x80000000) | (((sizeof(struct termios)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((20)))), (caddr_t)&bios, td->td_ucred, | |||
| 780 | td)); | |||
| 781 | break; | |||
| 782 | ||||
| 783 | case LINUX_TCSETAW0x5407: | |||
| 784 | error = copyin((void *)args->arg, &lio, sizeof(lio)); | |||
| 785 | if (error) | |||
| 786 | break; | |||
| 787 | linux_to_bsd_termio(&lio, &bios); | |||
| 788 | error = (fo_ioctl(fp, TIOCSETAW((unsigned long) ((0x80000000) | (((sizeof(struct termios)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((21)))), (caddr_t)&bios, td->td_ucred, | |||
| 789 | td)); | |||
| 790 | break; | |||
| 791 | ||||
| 792 | case LINUX_TCSETAF0x5408: | |||
| 793 | error = copyin((void *)args->arg, &lio, sizeof(lio)); | |||
| 794 | if (error) | |||
| 795 | break; | |||
| 796 | linux_to_bsd_termio(&lio, &bios); | |||
| 797 | error = (fo_ioctl(fp, TIOCSETAF((unsigned long) ((0x80000000) | (((sizeof(struct termios)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((22)))), (caddr_t)&bios, td->td_ucred, | |||
| 798 | td)); | |||
| 799 | break; | |||
| 800 | ||||
| 801 | /* LINUX_TCSBRK */ | |||
| 802 | ||||
| 803 | case LINUX_TCXONC0x540A: { | |||
| 804 | switch (args->arg) { | |||
| 805 | case LINUX_TCOOFF0: | |||
| 806 | args->cmd = TIOCSTOP((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((111)))); | |||
| 807 | break; | |||
| 808 | case LINUX_TCOON1: | |||
| 809 | args->cmd = TIOCSTART((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((110)))); | |||
| 810 | break; | |||
| 811 | case LINUX_TCIOFF2: | |||
| 812 | case LINUX_TCION3: { | |||
| 813 | int c; | |||
| 814 | struct write_args wr; | |||
| 815 | error = fo_ioctl(fp, TIOCGETA((unsigned long) ((0x40000000) | (((sizeof(struct termios)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((19)))), (caddr_t)&bios, | |||
| 816 | td->td_ucred, td); | |||
| 817 | if (error) | |||
| 818 | break; | |||
| 819 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 820 | c = (args->arg == LINUX_TCIOFF2) ? VSTOP13 : VSTART12; | |||
| 821 | c = bios.c_cc[c]; | |||
| 822 | if (c != _POSIX_VDISABLE0xff) { | |||
| 823 | wr.fd = args->fd; | |||
| 824 | wr.buf = &c; | |||
| 825 | wr.nbyte = sizeof(c); | |||
| 826 | return (sys_write(td, &wr)); | |||
| 827 | } else | |||
| 828 | return (0); | |||
| 829 | } | |||
| 830 | default: | |||
| 831 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 832 | return (EINVAL22); | |||
| 833 | } | |||
| 834 | args->arg = 0; | |||
| 835 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 836 | break; | |||
| 837 | } | |||
| 838 | ||||
| 839 | case LINUX_TCFLSH0x540B: { | |||
| 840 | int val; | |||
| 841 | switch (args->arg) { | |||
| 842 | case LINUX_TCIFLUSH0: | |||
| 843 | val = FREAD0x0001; | |||
| 844 | break; | |||
| 845 | case LINUX_TCOFLUSH1: | |||
| 846 | val = FWRITE0x0002; | |||
| 847 | break; | |||
| 848 | case LINUX_TCIOFLUSH2: | |||
| 849 | val = FREAD0x0001 | FWRITE0x0002; | |||
| 850 | break; | |||
| 851 | default: | |||
| 852 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 853 | return (EINVAL22); | |||
| 854 | } | |||
| 855 | error = (fo_ioctl(fp,TIOCFLUSH((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((16)))),(caddr_t)&val,td->td_ucred,td)); | |||
| 856 | break; | |||
| 857 | } | |||
| 858 | ||||
| 859 | case LINUX_TIOCEXCL0x540C: | |||
| 860 | args->cmd = TIOCEXCL((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((13)))); | |||
| 861 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 862 | break; | |||
| 863 | ||||
| 864 | case LINUX_TIOCNXCL0x540D: | |||
| 865 | args->cmd = TIOCNXCL((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((14)))); | |||
| 866 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 867 | break; | |||
| 868 | ||||
| 869 | case LINUX_TIOCSCTTY0x540E: | |||
| 870 | args->cmd = TIOCSCTTY((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((97)))); | |||
| 871 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 872 | break; | |||
| 873 | ||||
| 874 | case LINUX_TIOCGPGRP0x540F: | |||
| 875 | args->cmd = TIOCGPGRP((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((119)))); | |||
| 876 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 877 | break; | |||
| 878 | ||||
| 879 | case LINUX_TIOCSPGRP0x5410: | |||
| 880 | args->cmd = TIOCSPGRP((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((118)))); | |||
| 881 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 882 | break; | |||
| 883 | ||||
| 884 | /* LINUX_TIOCOUTQ */ | |||
| 885 | /* LINUX_TIOCSTI */ | |||
| 886 | ||||
| 887 | case LINUX_TIOCGWINSZ0x5413: | |||
| 888 | args->cmd = TIOCGWINSZ((unsigned long) ((0x40000000) | (((sizeof(struct winsize)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((104)))); | |||
| 889 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 890 | break; | |||
| 891 | ||||
| 892 | case LINUX_TIOCSWINSZ0x5414: | |||
| 893 | args->cmd = TIOCSWINSZ((unsigned long) ((0x80000000) | (((sizeof(struct winsize)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((103)))); | |||
| 894 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 895 | break; | |||
| 896 | ||||
| 897 | case LINUX_TIOCMGET0x5415: | |||
| 898 | args->cmd = TIOCMGET((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((106)))); | |||
| 899 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 900 | break; | |||
| 901 | ||||
| 902 | case LINUX_TIOCMBIS0x5416: | |||
| 903 | args->cmd = TIOCMBIS((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((108)))); | |||
| 904 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 905 | break; | |||
| 906 | ||||
| 907 | case LINUX_TIOCMBIC0x5417: | |||
| 908 | args->cmd = TIOCMBIC((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((107)))); | |||
| 909 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 910 | break; | |||
| 911 | ||||
| 912 | case LINUX_TIOCMSET0x5418: | |||
| 913 | args->cmd = TIOCMSET((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((109)))); | |||
| 914 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 915 | break; | |||
| 916 | ||||
| 917 | /* TIOCGSOFTCAR */ | |||
| 918 | /* TIOCSSOFTCAR */ | |||
| 919 | ||||
| 920 | case LINUX_FIONREAD0x541B: /* LINUX_TIOCINQ */ | |||
| 921 | args->cmd = FIONREAD((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('f')) << 8) | ((127)))); | |||
| 922 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 923 | break; | |||
| 924 | ||||
| 925 | /* LINUX_TIOCLINUX */ | |||
| 926 | ||||
| 927 | case LINUX_TIOCCONS0x541D: | |||
| 928 | args->cmd = TIOCCONS((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((98)))); | |||
| 929 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 930 | break; | |||
| 931 | ||||
| 932 | case LINUX_TIOCGSERIAL0x541E: { | |||
| 933 | struct linux_serial_struct lss; | |||
| 934 | ||||
| 935 | bzero(&lss, sizeof(lss))__builtin_memset((&lss), 0, (sizeof(lss))); | |||
| 936 | lss.type = LINUX_PORT_16550A4; | |||
| 937 | lss.flags = 0; | |||
| 938 | lss.close_delay = 0; | |||
| 939 | error = copyout(&lss, (void *)args->arg, sizeof(lss)); | |||
| 940 | break; | |||
| 941 | } | |||
| 942 | ||||
| 943 | case LINUX_TIOCSSERIAL0x541F: { | |||
| 944 | struct linux_serial_struct lss; | |||
| 945 | error = copyin((void *)args->arg, &lss, sizeof(lss)); | |||
| 946 | if (error) | |||
| 947 | break; | |||
| 948 | /* XXX - It really helps to have an implementation that | |||
| 949 | * does nothing. NOT! | |||
| 950 | */ | |||
| 951 | error = 0; | |||
| 952 | break; | |||
| 953 | } | |||
| 954 | ||||
| 955 | case LINUX_TIOCPKT0x5420: | |||
| 956 | args->cmd = TIOCPKT((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((112)))); | |||
| 957 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 958 | break; | |||
| 959 | ||||
| 960 | case LINUX_FIONBIO0x5421: | |||
| 961 | args->cmd = FIONBIO((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('f')) << 8) | ((126)))); | |||
| 962 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 963 | break; | |||
| 964 | ||||
| 965 | case LINUX_TIOCNOTTY0x5422: | |||
| 966 | args->cmd = TIOCNOTTY((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((113)))); | |||
| 967 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 968 | break; | |||
| 969 | ||||
| 970 | case LINUX_TIOCSETD0x5423: { | |||
| 971 | int line; | |||
| 972 | switch (args->arg) { | |||
| 973 | case LINUX_N_TTY0: | |||
| 974 | line = TTYDISC0; | |||
| 975 | break; | |||
| 976 | case LINUX_N_SLIP1: | |||
| 977 | line = SLIPDISC4; | |||
| 978 | break; | |||
| 979 | case LINUX_N_PPP3: | |||
| 980 | line = PPPDISC5; | |||
| 981 | break; | |||
| 982 | default: | |||
| 983 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 984 | return (EINVAL22); | |||
| 985 | } | |||
| 986 | error = (fo_ioctl(fp, TIOCSETD((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((27)))), (caddr_t)&line, td->td_ucred, | |||
| 987 | td)); | |||
| 988 | break; | |||
| 989 | } | |||
| 990 | ||||
| 991 | case LINUX_TIOCGETD0x5424: { | |||
| 992 | int linux_line; | |||
| 993 | int bsd_line = TTYDISC0; | |||
| 994 | error = fo_ioctl(fp, TIOCGETD((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((26)))), (caddr_t)&bsd_line, | |||
| 995 | td->td_ucred, td); | |||
| 996 | if (error) | |||
| 997 | break; | |||
| 998 | switch (bsd_line) { | |||
| 999 | case TTYDISC0: | |||
| 1000 | linux_line = LINUX_N_TTY0; | |||
| 1001 | break; | |||
| 1002 | case SLIPDISC4: | |||
| 1003 | linux_line = LINUX_N_SLIP1; | |||
| 1004 | break; | |||
| 1005 | case PPPDISC5: | |||
| 1006 | linux_line = LINUX_N_PPP3; | |||
| 1007 | break; | |||
| 1008 | default: | |||
| 1009 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 1010 | return (EINVAL22); | |||
| 1011 | } | |||
| 1012 | error = (copyout(&linux_line, (void *)args->arg, sizeof(int))); | |||
| 1013 | break; | |||
| 1014 | } | |||
| 1015 | ||||
| 1016 | /* LINUX_TCSBRKP */ | |||
| 1017 | /* LINUX_TIOCTTYGSTRUCT */ | |||
| 1018 | ||||
| 1019 | case LINUX_FIONCLEX0x5450: | |||
| 1020 | args->cmd = FIONCLEX((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('f')) << 8) | ((2)))); | |||
| 1021 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1022 | break; | |||
| 1023 | ||||
| 1024 | case LINUX_FIOCLEX0x5451: | |||
| 1025 | args->cmd = FIOCLEX((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('f')) << 8) | ((1)))); | |||
| 1026 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1027 | break; | |||
| 1028 | ||||
| 1029 | case LINUX_FIOASYNC0x5452: | |||
| 1030 | args->cmd = FIOASYNC((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('f')) << 8) | ((125)))); | |||
| 1031 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1032 | break; | |||
| 1033 | ||||
| 1034 | /* LINUX_TIOCSERCONFIG */ | |||
| 1035 | /* LINUX_TIOCSERGWILD */ | |||
| 1036 | /* LINUX_TIOCSERSWILD */ | |||
| 1037 | /* LINUX_TIOCGLCKTRMIOS */ | |||
| 1038 | /* LINUX_TIOCSLCKTRMIOS */ | |||
| 1039 | ||||
| 1040 | case LINUX_TIOCSBRK0x5427: | |||
| 1041 | args->cmd = TIOCSBRK((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((123)))); | |||
| 1042 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1043 | break; | |||
| 1044 | ||||
| 1045 | case LINUX_TIOCCBRK0x5428: | |||
| 1046 | args->cmd = TIOCCBRK((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((122)))); | |||
| 1047 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1048 | break; | |||
| 1049 | case LINUX_TIOCGPTN0x5430: { | |||
| 1050 | int nb; | |||
| 1051 | ||||
| 1052 | error = fo_ioctl(fp, TIOCGPTN((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('t')) << 8) | ((15)))), (caddr_t)&nb, td->td_ucred, td); | |||
| 1053 | if (!error) | |||
| 1054 | error = copyout(&nb, (void *)args->arg, | |||
| 1055 | sizeof(int)); | |||
| 1056 | break; | |||
| 1057 | } | |||
| 1058 | case LINUX_TIOCSPTLCK0x5431: | |||
| 1059 | /* Our unlockpt() does nothing. */ | |||
| 1060 | error = 0; | |||
| 1061 | break; | |||
| 1062 | default: | |||
| 1063 | error = ENOIOCTL(-3); | |||
| 1064 | break; | |||
| 1065 | } | |||
| 1066 | ||||
| 1067 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 1068 | return (error); | |||
| 1069 | } | |||
| 1070 | ||||
| 1071 | /* | |||
| 1072 | * CDROM related ioctls | |||
| 1073 | */ | |||
| 1074 | ||||
| 1075 | struct linux_cdrom_msf | |||
| 1076 | { | |||
| 1077 | u_char cdmsf_min0; | |||
| 1078 | u_char cdmsf_sec0; | |||
| 1079 | u_char cdmsf_frame0; | |||
| 1080 | u_char cdmsf_min1; | |||
| 1081 | u_char cdmsf_sec1; | |||
| 1082 | u_char cdmsf_frame1; | |||
| 1083 | }; | |||
| 1084 | ||||
| 1085 | struct linux_cdrom_tochdr | |||
| 1086 | { | |||
| 1087 | u_char cdth_trk0; | |||
| 1088 | u_char cdth_trk1; | |||
| 1089 | }; | |||
| 1090 | ||||
| 1091 | union linux_cdrom_addr | |||
| 1092 | { | |||
| 1093 | struct { | |||
| 1094 | u_char minute; | |||
| 1095 | u_char second; | |||
| 1096 | u_char frame; | |||
| 1097 | } msf; | |||
| 1098 | int lba; | |||
| 1099 | }; | |||
| 1100 | ||||
| 1101 | struct linux_cdrom_tocentry | |||
| 1102 | { | |||
| 1103 | u_char cdte_track; | |||
| 1104 | u_char cdte_adr:4; | |||
| 1105 | u_char cdte_ctrl:4; | |||
| 1106 | u_char cdte_format; | |||
| 1107 | union linux_cdrom_addr cdte_addr; | |||
| 1108 | u_char cdte_datamode; | |||
| 1109 | }; | |||
| 1110 | ||||
| 1111 | struct linux_cdrom_subchnl | |||
| 1112 | { | |||
| 1113 | u_char cdsc_format; | |||
| 1114 | u_char cdsc_audiostatus; | |||
| 1115 | u_char cdsc_adr:4; | |||
| 1116 | u_char cdsc_ctrl:4; | |||
| 1117 | u_char cdsc_trk; | |||
| 1118 | u_char cdsc_ind; | |||
| 1119 | union linux_cdrom_addr cdsc_absaddr; | |||
| 1120 | union linux_cdrom_addr cdsc_reladdr; | |||
| 1121 | }; | |||
| 1122 | ||||
| 1123 | struct l_cdrom_read_audio { | |||
| 1124 | union linux_cdrom_addr addr; | |||
| 1125 | u_char addr_format; | |||
| 1126 | l_int nframes; | |||
| 1127 | u_char *buf; | |||
| 1128 | }; | |||
| 1129 | ||||
| 1130 | struct l_dvd_layer { | |||
| 1131 | u_char book_version:4; | |||
| 1132 | u_char book_type:4; | |||
| 1133 | u_char min_rate:4; | |||
| 1134 | u_char disc_size:4; | |||
| 1135 | u_char layer_type:4; | |||
| 1136 | u_char track_path:1; | |||
| 1137 | u_char nlayers:2; | |||
| 1138 | u_char track_density:4; | |||
| 1139 | u_char linear_density:4; | |||
| 1140 | u_char bca:1; | |||
| 1141 | u_int32_t start_sector; | |||
| 1142 | u_int32_t end_sector; | |||
| 1143 | u_int32_t end_sector_l0; | |||
| 1144 | }; | |||
| 1145 | ||||
| 1146 | struct l_dvd_physical { | |||
| 1147 | u_char type; | |||
| 1148 | u_char layer_num; | |||
| 1149 | struct l_dvd_layer layer[4]; | |||
| 1150 | }; | |||
| 1151 | ||||
| 1152 | struct l_dvd_copyright { | |||
| 1153 | u_char type; | |||
| 1154 | u_char layer_num; | |||
| 1155 | u_char cpst; | |||
| 1156 | u_char rmi; | |||
| 1157 | }; | |||
| 1158 | ||||
| 1159 | struct l_dvd_disckey { | |||
| 1160 | u_char type; | |||
| 1161 | l_uint agid:2; | |||
| 1162 | u_char value[2048]; | |||
| 1163 | }; | |||
| 1164 | ||||
| 1165 | struct l_dvd_bca { | |||
| 1166 | u_char type; | |||
| 1167 | l_int len; | |||
| 1168 | u_char value[188]; | |||
| 1169 | }; | |||
| 1170 | ||||
| 1171 | struct l_dvd_manufact { | |||
| 1172 | u_char type; | |||
| 1173 | u_char layer_num; | |||
| 1174 | l_int len; | |||
| 1175 | u_char value[2048]; | |||
| 1176 | }; | |||
| 1177 | ||||
| 1178 | typedef union { | |||
| 1179 | u_char type; | |||
| 1180 | struct l_dvd_physical physical; | |||
| 1181 | struct l_dvd_copyright copyright; | |||
| 1182 | struct l_dvd_disckey disckey; | |||
| 1183 | struct l_dvd_bca bca; | |||
| 1184 | struct l_dvd_manufact manufact; | |||
| 1185 | } l_dvd_struct; | |||
| 1186 | ||||
| 1187 | typedef u_char l_dvd_key[5]; | |||
| 1188 | typedef u_char l_dvd_challenge[10]; | |||
| 1189 | ||||
| 1190 | struct l_dvd_lu_send_agid { | |||
| 1191 | u_char type; | |||
| 1192 | l_uint agid:2; | |||
| 1193 | }; | |||
| 1194 | ||||
| 1195 | struct l_dvd_host_send_challenge { | |||
| 1196 | u_char type; | |||
| 1197 | l_uint agid:2; | |||
| 1198 | l_dvd_challenge chal; | |||
| 1199 | }; | |||
| 1200 | ||||
| 1201 | struct l_dvd_send_key { | |||
| 1202 | u_char type; | |||
| 1203 | l_uint agid:2; | |||
| 1204 | l_dvd_key key; | |||
| 1205 | }; | |||
| 1206 | ||||
| 1207 | struct l_dvd_lu_send_challenge { | |||
| 1208 | u_char type; | |||
| 1209 | l_uint agid:2; | |||
| 1210 | l_dvd_challenge chal; | |||
| 1211 | }; | |||
| 1212 | ||||
| 1213 | struct l_dvd_lu_send_title_key { | |||
| 1214 | u_char type; | |||
| 1215 | l_uint agid:2; | |||
| 1216 | l_dvd_key title_key; | |||
| 1217 | l_int lba; | |||
| 1218 | l_uint cpm:1; | |||
| 1219 | l_uint cp_sec:1; | |||
| 1220 | l_uint cgms:2; | |||
| 1221 | }; | |||
| 1222 | ||||
| 1223 | struct l_dvd_lu_send_asf { | |||
| 1224 | u_char type; | |||
| 1225 | l_uint agid:2; | |||
| 1226 | l_uint asf:1; | |||
| 1227 | }; | |||
| 1228 | ||||
| 1229 | struct l_dvd_host_send_rpcstate { | |||
| 1230 | u_char type; | |||
| 1231 | u_char pdrc; | |||
| 1232 | }; | |||
| 1233 | ||||
| 1234 | struct l_dvd_lu_send_rpcstate { | |||
| 1235 | u_char type:2; | |||
| 1236 | u_char vra:3; | |||
| 1237 | u_char ucca:3; | |||
| 1238 | u_char region_mask; | |||
| 1239 | u_char rpc_scheme; | |||
| 1240 | }; | |||
| 1241 | ||||
| 1242 | typedef union { | |||
| 1243 | u_char type; | |||
| 1244 | struct l_dvd_lu_send_agid lsa; | |||
| 1245 | struct l_dvd_host_send_challenge hsc; | |||
| 1246 | struct l_dvd_send_key lsk; | |||
| 1247 | struct l_dvd_lu_send_challenge lsc; | |||
| 1248 | struct l_dvd_send_key hsk; | |||
| 1249 | struct l_dvd_lu_send_title_key lstk; | |||
| 1250 | struct l_dvd_lu_send_asf lsasf; | |||
| 1251 | struct l_dvd_host_send_rpcstate hrpcs; | |||
| 1252 | struct l_dvd_lu_send_rpcstate lrpcs; | |||
| 1253 | } l_dvd_authinfo; | |||
| 1254 | ||||
| 1255 | static void | |||
| 1256 | bsd_to_linux_msf_lba(u_char af, union msf_lba *bp, union linux_cdrom_addr *lp) | |||
| 1257 | { | |||
| 1258 | if (af == CD_LBA_FORMAT1) | |||
| 1259 | lp->lba = bp->lba; | |||
| 1260 | else { | |||
| 1261 | lp->msf.minute = bp->msf.minute; | |||
| 1262 | lp->msf.second = bp->msf.second; | |||
| 1263 | lp->msf.frame = bp->msf.frame; | |||
| 1264 | } | |||
| 1265 | } | |||
| 1266 | ||||
| 1267 | static void | |||
| 1268 | set_linux_cdrom_addr(union linux_cdrom_addr *addr, int format, int lba) | |||
| 1269 | { | |||
| 1270 | if (format == LINUX_CDROM_MSF0x02) { | |||
| 1271 | addr->msf.frame = lba % 75; | |||
| 1272 | lba /= 75; | |||
| 1273 | lba += 2; | |||
| 1274 | addr->msf.second = lba % 60; | |||
| 1275 | addr->msf.minute = lba / 60; | |||
| 1276 | } else | |||
| 1277 | addr->lba = lba; | |||
| 1278 | } | |||
| 1279 | ||||
| 1280 | static int | |||
| 1281 | linux_to_bsd_dvd_struct(l_dvd_struct *lp, struct dvd_struct *bp) | |||
| 1282 | { | |||
| 1283 | bp->format = lp->type; | |||
| 1284 | switch (bp->format) { | |||
| 1285 | case DVD_STRUCT_PHYSICAL0x00: | |||
| 1286 | if (bp->layer_num >= 4) | |||
| 1287 | return (EINVAL22); | |||
| 1288 | bp->layer_num = lp->physical.layer_num; | |||
| 1289 | break; | |||
| 1290 | case DVD_STRUCT_COPYRIGHT0x01: | |||
| 1291 | bp->layer_num = lp->copyright.layer_num; | |||
| 1292 | break; | |||
| 1293 | case DVD_STRUCT_DISCKEY0x02: | |||
| 1294 | bp->agid = lp->disckey.agid; | |||
| 1295 | break; | |||
| 1296 | case DVD_STRUCT_BCA0x03: | |||
| 1297 | case DVD_STRUCT_MANUFACT0x04: | |||
| 1298 | break; | |||
| 1299 | default: | |||
| 1300 | return (EINVAL22); | |||
| 1301 | } | |||
| 1302 | return (0); | |||
| 1303 | } | |||
| 1304 | ||||
| 1305 | static int | |||
| 1306 | bsd_to_linux_dvd_struct(struct dvd_struct *bp, l_dvd_struct *lp) | |||
| 1307 | { | |||
| 1308 | switch (bp->format) { | |||
| 1309 | case DVD_STRUCT_PHYSICAL0x00: { | |||
| 1310 | struct dvd_layer *blp = (struct dvd_layer *)bp->data; | |||
| 1311 | struct l_dvd_layer *llp = &lp->physical.layer[bp->layer_num]; | |||
| 1312 | memset(llp, 0, sizeof(*llp))__builtin_memset((llp), (0), (sizeof(*llp))); | |||
| 1313 | llp->book_version = blp->book_version; | |||
| 1314 | llp->book_type = blp->book_type; | |||
| 1315 | llp->min_rate = blp->max_rate; | |||
| 1316 | llp->disc_size = blp->disc_size; | |||
| 1317 | llp->layer_type = blp->layer_type; | |||
| 1318 | llp->track_path = blp->track_path; | |||
| 1319 | llp->nlayers = blp->nlayers; | |||
| 1320 | llp->track_density = blp->track_density; | |||
| 1321 | llp->linear_density = blp->linear_density; | |||
| 1322 | llp->bca = blp->bca; | |||
| 1323 | llp->start_sector = blp->start_sector; | |||
| 1324 | llp->end_sector = blp->end_sector; | |||
| 1325 | llp->end_sector_l0 = blp->end_sector_l0; | |||
| 1326 | break; | |||
| 1327 | } | |||
| 1328 | case DVD_STRUCT_COPYRIGHT0x01: | |||
| 1329 | lp->copyright.cpst = bp->cpst; | |||
| 1330 | lp->copyright.rmi = bp->rmi; | |||
| 1331 | break; | |||
| 1332 | case DVD_STRUCT_DISCKEY0x02: | |||
| 1333 | memcpy(lp->disckey.value, bp->data, sizeof(lp->disckey.value))__builtin_memcpy((lp->disckey.value), (bp->data), (sizeof (lp->disckey.value))); | |||
| 1334 | break; | |||
| 1335 | case DVD_STRUCT_BCA0x03: | |||
| 1336 | lp->bca.len = bp->length; | |||
| 1337 | memcpy(lp->bca.value, bp->data, sizeof(lp->bca.value))__builtin_memcpy((lp->bca.value), (bp->data), (sizeof(lp ->bca.value))); | |||
| 1338 | break; | |||
| 1339 | case DVD_STRUCT_MANUFACT0x04: | |||
| 1340 | lp->manufact.len = bp->length; | |||
| 1341 | memcpy(lp->manufact.value, bp->data,__builtin_memcpy((lp->manufact.value), (bp->data), (sizeof (lp->manufact.value))) | |||
| 1342 | sizeof(lp->manufact.value))__builtin_memcpy((lp->manufact.value), (bp->data), (sizeof (lp->manufact.value))); | |||
| 1343 | /* lp->manufact.layer_num is unused in Linux (redhat 7.0). */ | |||
| 1344 | break; | |||
| 1345 | default: | |||
| 1346 | return (EINVAL22); | |||
| 1347 | } | |||
| 1348 | return (0); | |||
| 1349 | } | |||
| 1350 | ||||
| 1351 | static int | |||
| 1352 | linux_to_bsd_dvd_authinfo(l_dvd_authinfo *lp, int *bcode, | |||
| 1353 | struct dvd_authinfo *bp) | |||
| 1354 | { | |||
| 1355 | switch (lp->type) { | |||
| 1356 | case LINUX_DVD_LU_SEND_AGID0: | |||
| 1357 | *bcode = DVDIOCREPORTKEY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_authinfo)) & ((1 << 13) - 1)) << 16) | ( (('c')) << 8) | ((200)))); | |||
| 1358 | bp->format = DVD_REPORT_AGID0; | |||
| 1359 | bp->agid = lp->lsa.agid; | |||
| 1360 | break; | |||
| 1361 | case LINUX_DVD_HOST_SEND_CHALLENGE1: | |||
| 1362 | *bcode = DVDIOCSENDKEY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_authinfo)) & ((1 << 13) - 1)) << 16) | ( (('c')) << 8) | ((201)))); | |||
| 1363 | bp->format = DVD_SEND_CHALLENGE1; | |||
| 1364 | bp->agid = lp->hsc.agid; | |||
| 1365 | memcpy(bp->keychal, lp->hsc.chal, 10)__builtin_memcpy((bp->keychal), (lp->hsc.chal), (10)); | |||
| 1366 | break; | |||
| 1367 | case LINUX_DVD_LU_SEND_KEY12: | |||
| 1368 | *bcode = DVDIOCREPORTKEY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_authinfo)) & ((1 << 13) - 1)) << 16) | ( (('c')) << 8) | ((200)))); | |||
| 1369 | bp->format = DVD_REPORT_KEY12; | |||
| 1370 | bp->agid = lp->lsk.agid; | |||
| 1371 | break; | |||
| 1372 | case LINUX_DVD_LU_SEND_CHALLENGE3: | |||
| 1373 | *bcode = DVDIOCREPORTKEY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_authinfo)) & ((1 << 13) - 1)) << 16) | ( (('c')) << 8) | ((200)))); | |||
| 1374 | bp->format = DVD_REPORT_CHALLENGE1; | |||
| 1375 | bp->agid = lp->lsc.agid; | |||
| 1376 | break; | |||
| 1377 | case LINUX_DVD_HOST_SEND_KEY24: | |||
| 1378 | *bcode = DVDIOCSENDKEY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_authinfo)) & ((1 << 13) - 1)) << 16) | ( (('c')) << 8) | ((201)))); | |||
| 1379 | bp->format = DVD_SEND_KEY23; | |||
| 1380 | bp->agid = lp->hsk.agid; | |||
| 1381 | memcpy(bp->keychal, lp->hsk.key, 5)__builtin_memcpy((bp->keychal), (lp->hsk.key), (5)); | |||
| 1382 | break; | |||
| 1383 | case LINUX_DVD_LU_SEND_TITLE_KEY7: | |||
| 1384 | *bcode = DVDIOCREPORTKEY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_authinfo)) & ((1 << 13) - 1)) << 16) | ( (('c')) << 8) | ((200)))); | |||
| 1385 | bp->format = DVD_REPORT_TITLE_KEY4; | |||
| 1386 | bp->agid = lp->lstk.agid; | |||
| 1387 | bp->lba = lp->lstk.lba; | |||
| 1388 | break; | |||
| 1389 | case LINUX_DVD_LU_SEND_ASF8: | |||
| 1390 | *bcode = DVDIOCREPORTKEY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_authinfo)) & ((1 << 13) - 1)) << 16) | ( (('c')) << 8) | ((200)))); | |||
| 1391 | bp->format = DVD_REPORT_ASF5; | |||
| 1392 | bp->agid = lp->lsasf.agid; | |||
| 1393 | break; | |||
| 1394 | case LINUX_DVD_INVALIDATE_AGID9: | |||
| 1395 | *bcode = DVDIOCREPORTKEY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_authinfo)) & ((1 << 13) - 1)) << 16) | ( (('c')) << 8) | ((200)))); | |||
| 1396 | bp->format = DVD_INVALIDATE_AGID0x3f; | |||
| 1397 | bp->agid = lp->lsa.agid; | |||
| 1398 | break; | |||
| 1399 | case LINUX_DVD_LU_SEND_RPC_STATE10: | |||
| 1400 | *bcode = DVDIOCREPORTKEY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_authinfo)) & ((1 << 13) - 1)) << 16) | ( (('c')) << 8) | ((200)))); | |||
| 1401 | bp->format = DVD_REPORT_RPC8; | |||
| 1402 | break; | |||
| 1403 | case LINUX_DVD_HOST_SEND_RPC_STATE11: | |||
| 1404 | *bcode = DVDIOCSENDKEY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_authinfo)) & ((1 << 13) - 1)) << 16) | ( (('c')) << 8) | ((201)))); | |||
| 1405 | bp->format = DVD_SEND_RPC6; | |||
| 1406 | bp->region = lp->hrpcs.pdrc; | |||
| 1407 | break; | |||
| 1408 | default: | |||
| 1409 | return (EINVAL22); | |||
| 1410 | } | |||
| 1411 | return (0); | |||
| 1412 | } | |||
| 1413 | ||||
| 1414 | static int | |||
| 1415 | bsd_to_linux_dvd_authinfo(struct dvd_authinfo *bp, l_dvd_authinfo *lp) | |||
| 1416 | { | |||
| 1417 | switch (lp->type) { | |||
| 1418 | case LINUX_DVD_LU_SEND_AGID0: | |||
| 1419 | lp->lsa.agid = bp->agid; | |||
| 1420 | break; | |||
| 1421 | case LINUX_DVD_HOST_SEND_CHALLENGE1: | |||
| 1422 | lp->type = LINUX_DVD_LU_SEND_KEY12; | |||
| 1423 | break; | |||
| 1424 | case LINUX_DVD_LU_SEND_KEY12: | |||
| 1425 | memcpy(lp->lsk.key, bp->keychal, sizeof(lp->lsk.key))__builtin_memcpy((lp->lsk.key), (bp->keychal), (sizeof( lp->lsk.key))); | |||
| 1426 | break; | |||
| 1427 | case LINUX_DVD_LU_SEND_CHALLENGE3: | |||
| 1428 | memcpy(lp->lsc.chal, bp->keychal, sizeof(lp->lsc.chal))__builtin_memcpy((lp->lsc.chal), (bp->keychal), (sizeof (lp->lsc.chal))); | |||
| 1429 | break; | |||
| 1430 | case LINUX_DVD_HOST_SEND_KEY24: | |||
| 1431 | lp->type = LINUX_DVD_AUTH_ESTABLISHED5; | |||
| 1432 | break; | |||
| 1433 | case LINUX_DVD_LU_SEND_TITLE_KEY7: | |||
| 1434 | memcpy(lp->lstk.title_key, bp->keychal,__builtin_memcpy((lp->lstk.title_key), (bp->keychal), ( sizeof(lp->lstk.title_key))) | |||
| 1435 | sizeof(lp->lstk.title_key))__builtin_memcpy((lp->lstk.title_key), (bp->keychal), ( sizeof(lp->lstk.title_key))); | |||
| 1436 | lp->lstk.cpm = bp->cpm; | |||
| 1437 | lp->lstk.cp_sec = bp->cp_sec; | |||
| 1438 | lp->lstk.cgms = bp->cgms; | |||
| 1439 | break; | |||
| 1440 | case LINUX_DVD_LU_SEND_ASF8: | |||
| 1441 | lp->lsasf.asf = bp->asf; | |||
| 1442 | break; | |||
| 1443 | case LINUX_DVD_INVALIDATE_AGID9: | |||
| 1444 | break; | |||
| 1445 | case LINUX_DVD_LU_SEND_RPC_STATE10: | |||
| 1446 | lp->lrpcs.type = bp->reg_type; | |||
| 1447 | lp->lrpcs.vra = bp->vend_rsts; | |||
| 1448 | lp->lrpcs.ucca = bp->user_rsts; | |||
| 1449 | lp->lrpcs.region_mask = bp->region; | |||
| 1450 | lp->lrpcs.rpc_scheme = bp->rpc_scheme; | |||
| 1451 | break; | |||
| 1452 | case LINUX_DVD_HOST_SEND_RPC_STATE11: | |||
| 1453 | break; | |||
| 1454 | default: | |||
| 1455 | return (EINVAL22); | |||
| 1456 | } | |||
| 1457 | return (0); | |||
| 1458 | } | |||
| 1459 | ||||
| 1460 | static int | |||
| 1461 | linux_ioctl_cdrom(struct thread *td, struct linux_ioctl_args *args) | |||
| 1462 | { | |||
| 1463 | struct file *fp; | |||
| 1464 | int error; | |||
| 1465 | ||||
| 1466 | error = fget(td, args->fd, &cap_ioctl_rights, &fp); | |||
| 1467 | if (error != 0) | |||
| 1468 | return (error); | |||
| 1469 | switch (args->cmd & 0xffff) { | |||
| 1470 | ||||
| 1471 | case LINUX_CDROMPAUSE0x5301: | |||
| 1472 | args->cmd = CDIOCPAUSE((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('c')) << 8) | ((19)))); | |||
| 1473 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1474 | break; | |||
| 1475 | ||||
| 1476 | case LINUX_CDROMRESUME0x5302: | |||
| 1477 | args->cmd = CDIOCRESUME((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('c')) << 8) | ((20)))); | |||
| 1478 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1479 | break; | |||
| 1480 | ||||
| 1481 | case LINUX_CDROMPLAYMSF0x5303: | |||
| 1482 | args->cmd = CDIOCPLAYMSF((unsigned long) ((0x80000000) | (((sizeof(struct ioc_play_msf )) & ((1 << 13) - 1)) << 16) | ((('c')) << 8) | ((25)))); | |||
| 1483 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1484 | break; | |||
| 1485 | ||||
| 1486 | case LINUX_CDROMPLAYTRKIND0x5304: | |||
| 1487 | args->cmd = CDIOCPLAYTRACKS((unsigned long) ((0x80000000) | (((sizeof(struct ioc_play_track )) & ((1 << 13) - 1)) << 16) | ((('c')) << 8) | ((1)))); | |||
| 1488 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1489 | break; | |||
| 1490 | ||||
| 1491 | case LINUX_CDROMREADTOCHDR0x5305: { | |||
| 1492 | struct ioc_toc_header th; | |||
| 1493 | struct linux_cdrom_tochdr lth; | |||
| 1494 | error = fo_ioctl(fp, CDIOREADTOCHEADER((unsigned long) ((0x40000000) | (((sizeof(struct ioc_toc_header )) & ((1 << 13) - 1)) << 16) | ((('c')) << 8) | ((4)))), (caddr_t)&th, | |||
| 1495 | td->td_ucred, td); | |||
| 1496 | if (!error) { | |||
| 1497 | lth.cdth_trk0 = th.starting_track; | |||
| 1498 | lth.cdth_trk1 = th.ending_track; | |||
| 1499 | copyout(<h, (void *)args->arg, sizeof(lth)); | |||
| 1500 | } | |||
| 1501 | break; | |||
| 1502 | } | |||
| 1503 | ||||
| 1504 | case LINUX_CDROMREADTOCENTRY0x5306: { | |||
| 1505 | struct linux_cdrom_tocentry lte; | |||
| 1506 | struct ioc_read_toc_single_entry irtse; | |||
| 1507 | ||||
| 1508 | error = copyin((void *)args->arg, <e, sizeof(lte)); | |||
| 1509 | if (error) | |||
| 1510 | break; | |||
| 1511 | irtse.address_format = lte.cdte_format; | |||
| 1512 | irtse.track = lte.cdte_track; | |||
| 1513 | error = fo_ioctl(fp, CDIOREADTOCENTRY((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ioc_read_toc_single_entry)) & ((1 << 13) - 1)) << 16) | ((('c')) << 8) | ((6)))), (caddr_t)&irtse, | |||
| 1514 | td->td_ucred, td); | |||
| 1515 | if (!error) { | |||
| 1516 | lte.cdte_ctrl = irtse.entry.control; | |||
| 1517 | lte.cdte_adr = irtse.entry.addr_type; | |||
| 1518 | bsd_to_linux_msf_lba(irtse.address_format, | |||
| 1519 | &irtse.entry.addr, <e.cdte_addr); | |||
| 1520 | error = copyout(<e, (void *)args->arg, sizeof(lte)); | |||
| 1521 | } | |||
| 1522 | break; | |||
| 1523 | } | |||
| 1524 | ||||
| 1525 | case LINUX_CDROMSTOP0x5307: | |||
| 1526 | args->cmd = CDIOCSTOP((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('c')) << 8) | ((23)))); | |||
| 1527 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1528 | break; | |||
| 1529 | ||||
| 1530 | case LINUX_CDROMSTART0x5308: | |||
| 1531 | args->cmd = CDIOCSTART((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('c')) << 8) | ((22)))); | |||
| 1532 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1533 | break; | |||
| 1534 | ||||
| 1535 | case LINUX_CDROMEJECT0x5309: | |||
| 1536 | args->cmd = CDIOCEJECT((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('c')) << 8) | ((24)))); | |||
| 1537 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1538 | break; | |||
| 1539 | ||||
| 1540 | /* LINUX_CDROMVOLCTRL */ | |||
| 1541 | ||||
| 1542 | case LINUX_CDROMSUBCHNL0x530b: { | |||
| 1543 | struct linux_cdrom_subchnl sc; | |||
| 1544 | struct ioc_read_subchannel bsdsc; | |||
| 1545 | struct cd_sub_channel_info bsdinfo; | |||
| 1546 | ||||
| 1547 | bsdsc.address_format = CD_LBA_FORMAT1; | |||
| 1548 | bsdsc.data_format = CD_CURRENT_POSITION1; | |||
| 1549 | bsdsc.track = 0; | |||
| 1550 | bsdsc.data_len = sizeof(bsdinfo); | |||
| 1551 | bsdsc.data = &bsdinfo; | |||
| 1552 | error = fo_ioctl(fp, CDIOCREADSUBCHANNEL_SYSSPACE((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ioc_read_subchannel)) & ((1 << 13) - 1)) << 16 ) | ((('c')) << 8) | ((31)))), | |||
| 1553 | (caddr_t)&bsdsc, td->td_ucred, td); | |||
| 1554 | if (error) | |||
| 1555 | break; | |||
| 1556 | error = copyin((void *)args->arg, &sc, sizeof(sc)); | |||
| 1557 | if (error) | |||
| 1558 | break; | |||
| 1559 | sc.cdsc_audiostatus = bsdinfo.header.audio_status; | |||
| 1560 | sc.cdsc_adr = bsdinfo.what.position.addr_type; | |||
| 1561 | sc.cdsc_ctrl = bsdinfo.what.position.control; | |||
| 1562 | sc.cdsc_trk = bsdinfo.what.position.track_number; | |||
| 1563 | sc.cdsc_ind = bsdinfo.what.position.index_number; | |||
| 1564 | set_linux_cdrom_addr(&sc.cdsc_absaddr, sc.cdsc_format, | |||
| 1565 | bsdinfo.what.position.absaddr.lba); | |||
| 1566 | set_linux_cdrom_addr(&sc.cdsc_reladdr, sc.cdsc_format, | |||
| 1567 | bsdinfo.what.position.reladdr.lba); | |||
| 1568 | error = copyout(&sc, (void *)args->arg, sizeof(sc)); | |||
| 1569 | break; | |||
| 1570 | } | |||
| 1571 | ||||
| 1572 | /* LINUX_CDROMREADMODE2 */ | |||
| 1573 | /* LINUX_CDROMREADMODE1 */ | |||
| 1574 | /* LINUX_CDROMREADAUDIO */ | |||
| 1575 | /* LINUX_CDROMEJECT_SW */ | |||
| 1576 | /* LINUX_CDROMMULTISESSION */ | |||
| 1577 | /* LINUX_CDROM_GET_UPC */ | |||
| 1578 | ||||
| 1579 | case LINUX_CDROMRESET0x5312: | |||
| 1580 | args->cmd = CDIOCRESET((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('c')) << 8) | ((21)))); | |||
| 1581 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1582 | break; | |||
| 1583 | ||||
| 1584 | /* LINUX_CDROMVOLREAD */ | |||
| 1585 | /* LINUX_CDROMREADRAW */ | |||
| 1586 | /* LINUX_CDROMREADCOOKED */ | |||
| 1587 | /* LINUX_CDROMSEEK */ | |||
| 1588 | /* LINUX_CDROMPLAYBLK */ | |||
| 1589 | /* LINUX_CDROMREADALL */ | |||
| 1590 | /* LINUX_CDROMCLOSETRAY */ | |||
| 1591 | /* LINUX_CDROMLOADFROMSLOT */ | |||
| 1592 | /* LINUX_CDROMGETSPINDOWN */ | |||
| 1593 | /* LINUX_CDROMSETSPINDOWN */ | |||
| 1594 | /* LINUX_CDROM_SET_OPTIONS */ | |||
| 1595 | /* LINUX_CDROM_CLEAR_OPTIONS */ | |||
| 1596 | /* LINUX_CDROM_SELECT_SPEED */ | |||
| 1597 | /* LINUX_CDROM_SELECT_DISC */ | |||
| 1598 | /* LINUX_CDROM_MEDIA_CHANGED */ | |||
| 1599 | /* LINUX_CDROM_DRIVE_STATUS */ | |||
| 1600 | /* LINUX_CDROM_DISC_STATUS */ | |||
| 1601 | /* LINUX_CDROM_CHANGER_NSLOTS */ | |||
| 1602 | /* LINUX_CDROM_LOCKDOOR */ | |||
| 1603 | /* LINUX_CDROM_DEBUG */ | |||
| 1604 | /* LINUX_CDROM_GET_CAPABILITY */ | |||
| 1605 | /* LINUX_CDROMAUDIOBUFSIZ */ | |||
| 1606 | ||||
| 1607 | case LINUX_DVD_READ_STRUCT0x5390: { | |||
| 1608 | l_dvd_struct *lds; | |||
| 1609 | struct dvd_struct *bds; | |||
| 1610 | ||||
| 1611 | lds = malloc(sizeof(*lds), M_LINUX, M_WAITOK0x0002); | |||
| 1612 | bds = malloc(sizeof(*bds), M_LINUX, M_WAITOK0x0002); | |||
| 1613 | error = copyin((void *)args->arg, lds, sizeof(*lds)); | |||
| 1614 | if (error) | |||
| 1615 | goto out; | |||
| 1616 | error = linux_to_bsd_dvd_struct(lds, bds); | |||
| 1617 | if (error) | |||
| 1618 | goto out; | |||
| 1619 | error = fo_ioctl(fp, DVDIOCREADSTRUCTURE((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct dvd_struct)) & ((1 << 13) - 1)) << 16) | ((( 'c')) << 8) | ((202)))), (caddr_t)bds, | |||
| 1620 | td->td_ucred, td); | |||
| 1621 | if (error) | |||
| 1622 | goto out; | |||
| 1623 | error = bsd_to_linux_dvd_struct(bds, lds); | |||
| 1624 | if (error) | |||
| 1625 | goto out; | |||
| 1626 | error = copyout(lds, (void *)args->arg, sizeof(*lds)); | |||
| 1627 | out: | |||
| 1628 | free(bds, M_LINUX); | |||
| 1629 | free(lds, M_LINUX); | |||
| 1630 | break; | |||
| 1631 | } | |||
| 1632 | ||||
| 1633 | /* LINUX_DVD_WRITE_STRUCT */ | |||
| 1634 | ||||
| 1635 | case LINUX_DVD_AUTH0x5392: { | |||
| 1636 | l_dvd_authinfo lda; | |||
| 1637 | struct dvd_authinfo bda; | |||
| 1638 | int bcode; | |||
| 1639 | ||||
| 1640 | error = copyin((void *)args->arg, &lda, sizeof(lda)); | |||
| 1641 | if (error) | |||
| 1642 | break; | |||
| 1643 | error = linux_to_bsd_dvd_authinfo(&lda, &bcode, &bda); | |||
| 1644 | if (error) | |||
| 1645 | break; | |||
| 1646 | error = fo_ioctl(fp, bcode, (caddr_t)&bda, td->td_ucred, | |||
| 1647 | td); | |||
| 1648 | if (error) { | |||
| 1649 | if (lda.type == LINUX_DVD_HOST_SEND_KEY24) { | |||
| 1650 | lda.type = LINUX_DVD_AUTH_FAILURE6; | |||
| 1651 | copyout(&lda, (void *)args->arg, sizeof(lda)); | |||
| 1652 | } | |||
| 1653 | break; | |||
| 1654 | } | |||
| 1655 | error = bsd_to_linux_dvd_authinfo(&bda, &lda); | |||
| 1656 | if (error) | |||
| 1657 | break; | |||
| 1658 | error = copyout(&lda, (void *)args->arg, sizeof(lda)); | |||
| 1659 | break; | |||
| 1660 | } | |||
| 1661 | ||||
| 1662 | case LINUX_SCSI_GET_BUS_NUMBER0x5386: | |||
| 1663 | { | |||
| 1664 | struct sg_scsi_id id; | |||
| 1665 | ||||
| 1666 | error = fo_ioctl(fp, SG_GET_SCSI_ID((unsigned long) ((0x40000000) | (((sizeof(struct sg_scsi_id) ) & ((1 << 13) - 1)) << 16) | ((('"')) << 8) | ((0x76)))), (caddr_t)&id, | |||
| 1667 | td->td_ucred, td); | |||
| 1668 | if (error) | |||
| 1669 | break; | |||
| 1670 | error = copyout(&id.channel, (void *)args->arg, sizeof(int)); | |||
| 1671 | break; | |||
| 1672 | } | |||
| 1673 | ||||
| 1674 | case LINUX_SCSI_GET_IDLUN0x5382: | |||
| 1675 | { | |||
| 1676 | struct sg_scsi_id id; | |||
| 1677 | struct scsi_idlun idl; | |||
| 1678 | ||||
| 1679 | error = fo_ioctl(fp, SG_GET_SCSI_ID((unsigned long) ((0x40000000) | (((sizeof(struct sg_scsi_id) ) & ((1 << 13) - 1)) << 16) | ((('"')) << 8) | ((0x76)))), (caddr_t)&id, | |||
| 1680 | td->td_ucred, td); | |||
| 1681 | if (error) | |||
| 1682 | break; | |||
| 1683 | idl.dev_id = (id.scsi_id & 0xff) + ((id.lun & 0xff) << 8) + | |||
| 1684 | ((id.channel & 0xff) << 16) + ((id.host_no & 0xff) << 24); | |||
| 1685 | idl.host_unique_id = id.host_no; | |||
| 1686 | error = copyout(&idl, (void *)args->arg, sizeof(idl)); | |||
| 1687 | break; | |||
| 1688 | } | |||
| 1689 | ||||
| 1690 | /* LINUX_CDROM_SEND_PACKET */ | |||
| 1691 | /* LINUX_CDROM_NEXT_WRITABLE */ | |||
| 1692 | /* LINUX_CDROM_LAST_WRITTEN */ | |||
| 1693 | ||||
| 1694 | default: | |||
| 1695 | error = ENOIOCTL(-3); | |||
| 1696 | break; | |||
| 1697 | } | |||
| 1698 | ||||
| 1699 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 1700 | return (error); | |||
| 1701 | } | |||
| 1702 | ||||
| 1703 | static int | |||
| 1704 | linux_ioctl_vfat(struct thread *td, struct linux_ioctl_args *args) | |||
| 1705 | { | |||
| 1706 | ||||
| 1707 | return (ENOTTY25); | |||
| 1708 | } | |||
| 1709 | ||||
| 1710 | /* | |||
| 1711 | * Sound related ioctls | |||
| 1712 | */ | |||
| 1713 | ||||
| 1714 | struct linux_old_mixer_info { | |||
| 1715 | char id[16]; | |||
| 1716 | char name[32]; | |||
| 1717 | }; | |||
| 1718 | ||||
| 1719 | static u_int32_t dirbits[4] = { IOC_VOID0x20000000, IOC_IN0x80000000, IOC_OUT0x40000000, IOC_INOUT(0x80000000|0x40000000) }; | |||
| 1720 | ||||
| 1721 | #define SETDIR(c)(((c) & ~(0x20000000|0x40000000|0x80000000)) | dirbits[args ->cmd >> 30]) (((c) & ~IOC_DIRMASK(0x20000000|0x40000000|0x80000000)) | dirbits[args->cmd >> 30]) | |||
| 1722 | ||||
| 1723 | static int | |||
| 1724 | linux_ioctl_sound(struct thread *td, struct linux_ioctl_args *args) | |||
| 1725 | { | |||
| 1726 | ||||
| 1727 | switch (args->cmd & 0xffff) { | |||
| 1728 | ||||
| 1729 | case LINUX_SOUND_MIXER_WRITE_VOLUME0x4d00: | |||
| 1730 | args->cmd = SETDIR(SOUND_MIXER_WRITE_VOLUME)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((0))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1731 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1732 | ||||
| 1733 | case LINUX_SOUND_MIXER_WRITE_BASS0x4d01: | |||
| 1734 | args->cmd = SETDIR(SOUND_MIXER_WRITE_BASS)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((1))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1735 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1736 | ||||
| 1737 | case LINUX_SOUND_MIXER_WRITE_TREBLE0x4d02: | |||
| 1738 | args->cmd = SETDIR(SOUND_MIXER_WRITE_TREBLE)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((2))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1739 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1740 | ||||
| 1741 | case LINUX_SOUND_MIXER_WRITE_SYNTH0x4d03: | |||
| 1742 | args->cmd = SETDIR(SOUND_MIXER_WRITE_SYNTH)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((3))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1743 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1744 | ||||
| 1745 | case LINUX_SOUND_MIXER_WRITE_PCM0x4d04: | |||
| 1746 | args->cmd = SETDIR(SOUND_MIXER_WRITE_PCM)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((4))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1747 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1748 | ||||
| 1749 | case LINUX_SOUND_MIXER_WRITE_SPEAKER0x4d05: | |||
| 1750 | args->cmd = SETDIR(SOUND_MIXER_WRITE_SPEAKER)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((5))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1751 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1752 | ||||
| 1753 | case LINUX_SOUND_MIXER_WRITE_LINE0x4d06: | |||
| 1754 | args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((6))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1755 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1756 | ||||
| 1757 | case LINUX_SOUND_MIXER_WRITE_MIC0x4d07: | |||
| 1758 | args->cmd = SETDIR(SOUND_MIXER_WRITE_MIC)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((7))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1759 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1760 | ||||
| 1761 | case LINUX_SOUND_MIXER_WRITE_CD0x4d08: | |||
| 1762 | args->cmd = SETDIR(SOUND_MIXER_WRITE_CD)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((8))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1763 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1764 | ||||
| 1765 | case LINUX_SOUND_MIXER_WRITE_IMIX0x4d09: | |||
| 1766 | args->cmd = SETDIR(SOUND_MIXER_WRITE_IMIX)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((9))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1767 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1768 | ||||
| 1769 | case LINUX_SOUND_MIXER_WRITE_ALTPCM0x4d0A: | |||
| 1770 | args->cmd = SETDIR(SOUND_MIXER_WRITE_ALTPCM)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((10))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1771 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1772 | ||||
| 1773 | case LINUX_SOUND_MIXER_WRITE_RECLEV0x4d0B: | |||
| 1774 | args->cmd = SETDIR(SOUND_MIXER_WRITE_RECLEV)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((11))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1775 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1776 | ||||
| 1777 | case LINUX_SOUND_MIXER_WRITE_IGAIN0x4d0C: | |||
| 1778 | args->cmd = SETDIR(SOUND_MIXER_WRITE_IGAIN)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((12))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1779 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1780 | ||||
| 1781 | case LINUX_SOUND_MIXER_WRITE_OGAIN0x4d0D: | |||
| 1782 | args->cmd = SETDIR(SOUND_MIXER_WRITE_OGAIN)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((13))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1783 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1784 | ||||
| 1785 | case LINUX_SOUND_MIXER_WRITE_LINE10x4d0E: | |||
| 1786 | args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE1)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((14))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1787 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1788 | ||||
| 1789 | case LINUX_SOUND_MIXER_WRITE_LINE20x4d0F: | |||
| 1790 | args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE2)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((15))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1791 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1792 | ||||
| 1793 | case LINUX_SOUND_MIXER_WRITE_LINE30x4d10: | |||
| 1794 | args->cmd = SETDIR(SOUND_MIXER_WRITE_LINE3)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((16))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits [args->cmd >> 30]); | |||
| 1795 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1796 | ||||
| 1797 | case LINUX_SOUND_MIXER_INFO0x4d65: { | |||
| 1798 | /* Key on encoded length */ | |||
| 1799 | switch ((args->cmd >> 16) & 0x1fff) { | |||
| 1800 | case 0x005c: { /* SOUND_MIXER_INFO */ | |||
| 1801 | args->cmd = SOUND_MIXER_INFO((unsigned long) ((0x40000000) | (((sizeof(mixer_info)) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((101)))); | |||
| 1802 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1803 | } | |||
| 1804 | case 0x0030: { /* SOUND_OLD_MIXER_INFO */ | |||
| 1805 | struct linux_old_mixer_info info; | |||
| 1806 | bzero(&info, sizeof(info))__builtin_memset((&info), 0, (sizeof(info))); | |||
| 1807 | strncpy(info.id, "OSS", sizeof(info.id) - 1); | |||
| 1808 | strncpy(info.name, "FreeBSD OSS Mixer", sizeof(info.name) - 1); | |||
| 1809 | copyout(&info, (void *)args->arg, sizeof(info)); | |||
| 1810 | return (0); | |||
| 1811 | } | |||
| 1812 | default: | |||
| 1813 | return (ENOIOCTL(-3)); | |||
| 1814 | } | |||
| 1815 | break; | |||
| 1816 | } | |||
| 1817 | ||||
| 1818 | case LINUX_OSS_GETVERSION0x4d76: { | |||
| 1819 | int version = linux_get_oss_version(td); | |||
| 1820 | return (copyout(&version, (void *)args->arg, sizeof(int))); | |||
| 1821 | } | |||
| 1822 | ||||
| 1823 | case LINUX_SOUND_MIXER_READ_STEREODEVS0x4dfb: | |||
| 1824 | args->cmd = SOUND_MIXER_READ_STEREODEVS((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((0xfb)))); | |||
| 1825 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1826 | ||||
| 1827 | case LINUX_SOUND_MIXER_READ_CAPS0x4dfc: | |||
| 1828 | args->cmd = SOUND_MIXER_READ_CAPS((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((0xfc)))); | |||
| 1829 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1830 | ||||
| 1831 | case LINUX_SOUND_MIXER_READ_RECMASK0x4dfd: | |||
| 1832 | args->cmd = SOUND_MIXER_READ_RECMASK((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((0xfd)))); | |||
| 1833 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1834 | ||||
| 1835 | case LINUX_SOUND_MIXER_READ_DEVMASK0x4dfe: | |||
| 1836 | args->cmd = SOUND_MIXER_READ_DEVMASK((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((0xfe)))); | |||
| 1837 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1838 | ||||
| 1839 | case LINUX_SOUND_MIXER_WRITE_RECSRC0x4dff: | |||
| 1840 | args->cmd = SETDIR(SOUND_MIXER_WRITE_RECSRC)(((((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int )) & ((1 << 13) - 1)) << 16) | ((('M')) << 8) | ((0xff))))) & ~(0x20000000|0x40000000|0x80000000)) | dirbits[args->cmd >> 30]); | |||
| 1841 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1842 | ||||
| 1843 | case LINUX_SNDCTL_DSP_RESET0x5000: | |||
| 1844 | args->cmd = SNDCTL_DSP_RESET((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((0)))); | |||
| 1845 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1846 | ||||
| 1847 | case LINUX_SNDCTL_DSP_SYNC0x5001: | |||
| 1848 | args->cmd = SNDCTL_DSP_SYNC((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((1)))); | |||
| 1849 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1850 | ||||
| 1851 | case LINUX_SNDCTL_DSP_SPEED0x5002: | |||
| 1852 | args->cmd = SNDCTL_DSP_SPEED((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((2)))); | |||
| 1853 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1854 | ||||
| 1855 | case LINUX_SNDCTL_DSP_STEREO0x5003: | |||
| 1856 | args->cmd = SNDCTL_DSP_STEREO((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((3)))); | |||
| 1857 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1858 | ||||
| 1859 | case LINUX_SNDCTL_DSP_GETBLKSIZE0x5004: /* LINUX_SNDCTL_DSP_SETBLKSIZE */ | |||
| 1860 | args->cmd = SNDCTL_DSP_GETBLKSIZE((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((4)))); | |||
| 1861 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1862 | ||||
| 1863 | case LINUX_SNDCTL_DSP_SETFMT0x5005: | |||
| 1864 | args->cmd = SNDCTL_DSP_SETFMT((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((5)))); | |||
| 1865 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1866 | ||||
| 1867 | case LINUX_SOUND_PCM_WRITE_CHANNELS0x5006: | |||
| 1868 | args->cmd = SOUND_PCM_WRITE_CHANNELS((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((6)))); | |||
| 1869 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1870 | ||||
| 1871 | case LINUX_SOUND_PCM_WRITE_FILTER0x5007: | |||
| 1872 | args->cmd = SOUND_PCM_WRITE_FILTER((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((7)))); | |||
| 1873 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1874 | ||||
| 1875 | case LINUX_SNDCTL_DSP_POST0x5008: | |||
| 1876 | args->cmd = SNDCTL_DSP_POST((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((8)))); | |||
| 1877 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1878 | ||||
| 1879 | case LINUX_SNDCTL_DSP_SUBDIVIDE0x5009: | |||
| 1880 | args->cmd = SNDCTL_DSP_SUBDIVIDE((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((9)))); | |||
| 1881 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1882 | ||||
| 1883 | case LINUX_SNDCTL_DSP_SETFRAGMENT0x500A: | |||
| 1884 | args->cmd = SNDCTL_DSP_SETFRAGMENT((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((10)))); | |||
| 1885 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1886 | ||||
| 1887 | case LINUX_SNDCTL_DSP_GETFMTS0x500B: | |||
| 1888 | args->cmd = SNDCTL_DSP_GETFMTS((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((11)))); | |||
| 1889 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1890 | ||||
| 1891 | case LINUX_SNDCTL_DSP_GETOSPACE0x500C: | |||
| 1892 | args->cmd = SNDCTL_DSP_GETOSPACE((unsigned long) ((0x40000000) | (((sizeof(audio_buf_info)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((12)))); | |||
| 1893 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1894 | ||||
| 1895 | case LINUX_SNDCTL_DSP_GETISPACE0x500D: | |||
| 1896 | args->cmd = SNDCTL_DSP_GETISPACE((unsigned long) ((0x40000000) | (((sizeof(audio_buf_info)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((13)))); | |||
| 1897 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1898 | ||||
| 1899 | case LINUX_SNDCTL_DSP_NONBLOCK0x500E: | |||
| 1900 | args->cmd = SNDCTL_DSP_NONBLOCK((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((14)))); | |||
| 1901 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1902 | ||||
| 1903 | case LINUX_SNDCTL_DSP_GETCAPS0x500F: | |||
| 1904 | args->cmd = SNDCTL_DSP_GETCAPS((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((15)))); | |||
| 1905 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1906 | ||||
| 1907 | case LINUX_SNDCTL_DSP_SETTRIGGER0x5010: /* LINUX_SNDCTL_GETTRIGGER */ | |||
| 1908 | args->cmd = SNDCTL_DSP_SETTRIGGER((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((16)))); | |||
| 1909 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1910 | ||||
| 1911 | case LINUX_SNDCTL_DSP_GETIPTR0x5011: | |||
| 1912 | args->cmd = SNDCTL_DSP_GETIPTR((unsigned long) ((0x40000000) | (((sizeof(count_info)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((17)))); | |||
| 1913 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1914 | ||||
| 1915 | case LINUX_SNDCTL_DSP_GETOPTR0x5012: | |||
| 1916 | args->cmd = SNDCTL_DSP_GETOPTR((unsigned long) ((0x40000000) | (((sizeof(count_info)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((18)))); | |||
| 1917 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1918 | ||||
| 1919 | case LINUX_SNDCTL_DSP_SETDUPLEX0x5016: | |||
| 1920 | args->cmd = SNDCTL_DSP_SETDUPLEX((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((22)))); | |||
| 1921 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1922 | ||||
| 1923 | case LINUX_SNDCTL_DSP_GETODELAY0x5017: | |||
| 1924 | args->cmd = SNDCTL_DSP_GETODELAY((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('P')) << 8) | ((23)))); | |||
| 1925 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1926 | ||||
| 1927 | case LINUX_SNDCTL_SEQ_RESET0x5100: | |||
| 1928 | args->cmd = SNDCTL_SEQ_RESET((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((0)))); | |||
| 1929 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1930 | ||||
| 1931 | case LINUX_SNDCTL_SEQ_SYNC0x5101: | |||
| 1932 | args->cmd = SNDCTL_SEQ_SYNC((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((1)))); | |||
| 1933 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1934 | ||||
| 1935 | case LINUX_SNDCTL_SYNTH_INFO0x5102: | |||
| 1936 | args->cmd = SNDCTL_SYNTH_INFO((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct synth_info)) & ((1 << 13) - 1)) << 16) | ((( 'Q')) << 8) | ((2)))); | |||
| 1937 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1938 | ||||
| 1939 | case LINUX_SNDCTL_SEQ_CTRLRATE0x5103: | |||
| 1940 | args->cmd = SNDCTL_SEQ_CTRLRATE((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((3)))); | |||
| 1941 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1942 | ||||
| 1943 | case LINUX_SNDCTL_SEQ_GETOUTCOUNT0x5104: | |||
| 1944 | args->cmd = SNDCTL_SEQ_GETOUTCOUNT((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((4)))); | |||
| 1945 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1946 | ||||
| 1947 | case LINUX_SNDCTL_SEQ_GETINCOUNT0x5105: | |||
| 1948 | args->cmd = SNDCTL_SEQ_GETINCOUNT((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((5)))); | |||
| 1949 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1950 | ||||
| 1951 | case LINUX_SNDCTL_SEQ_PERCMODE0x5106: | |||
| 1952 | args->cmd = SNDCTL_SEQ_PERCMODE((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((6)))); | |||
| 1953 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1954 | ||||
| 1955 | case LINUX_SNDCTL_FM_LOAD_INSTR0x5107: | |||
| 1956 | args->cmd = SNDCTL_FM_LOAD_INSTR((unsigned long) ((0x80000000) | (((sizeof(struct sbi_instrument )) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((7)))); | |||
| 1957 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1958 | ||||
| 1959 | case LINUX_SNDCTL_SEQ_TESTMIDI0x5108: | |||
| 1960 | args->cmd = SNDCTL_SEQ_TESTMIDI((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((8)))); | |||
| 1961 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1962 | ||||
| 1963 | case LINUX_SNDCTL_SEQ_RESETSAMPLES0x5109: | |||
| 1964 | args->cmd = SNDCTL_SEQ_RESETSAMPLES((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((9)))); | |||
| 1965 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1966 | ||||
| 1967 | case LINUX_SNDCTL_SEQ_NRSYNTHS0x510A: | |||
| 1968 | args->cmd = SNDCTL_SEQ_NRSYNTHS((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((10)))); | |||
| 1969 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1970 | ||||
| 1971 | case LINUX_SNDCTL_SEQ_NRMIDIS0x510B: | |||
| 1972 | args->cmd = SNDCTL_SEQ_NRMIDIS((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((11)))); | |||
| 1973 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1974 | ||||
| 1975 | case LINUX_SNDCTL_MIDI_INFO0x510C: | |||
| 1976 | args->cmd = SNDCTL_MIDI_INFO((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct midi_info)) & ((1 << 13) - 1)) << 16) | ((('Q' )) << 8) | ((12)))); | |||
| 1977 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1978 | ||||
| 1979 | case LINUX_SNDCTL_SEQ_TRESHOLD0x510D: | |||
| 1980 | args->cmd = SNDCTL_SEQ_TRESHOLD((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((13)))); | |||
| 1981 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1982 | ||||
| 1983 | case LINUX_SNDCTL_SYNTH_MEMAVL0x510E: | |||
| 1984 | args->cmd = SNDCTL_SYNTH_MEMAVL((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((14)))); | |||
| 1985 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 1986 | ||||
| 1987 | } | |||
| 1988 | ||||
| 1989 | return (ENOIOCTL(-3)); | |||
| 1990 | } | |||
| 1991 | ||||
| 1992 | /* | |||
| 1993 | * Console related ioctls | |||
| 1994 | */ | |||
| 1995 | ||||
| 1996 | static int | |||
| 1997 | linux_ioctl_console(struct thread *td, struct linux_ioctl_args *args) | |||
| 1998 | { | |||
| 1999 | struct file *fp; | |||
| 2000 | int error; | |||
| 2001 | ||||
| 2002 | error = fget(td, args->fd, &cap_ioctl_rights, &fp); | |||
| 2003 | if (error != 0) | |||
| 2004 | return (error); | |||
| 2005 | switch (args->cmd & 0xffff) { | |||
| 2006 | ||||
| 2007 | case LINUX_KIOCSOUND0x4B2F: | |||
| 2008 | args->cmd = KIOCSOUND((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('K')) << 8) | ((63)))); | |||
| 2009 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2010 | break; | |||
| 2011 | ||||
| 2012 | case LINUX_KDMKTONE0x4B30: | |||
| 2013 | args->cmd = KDMKTONE((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('K')) << 8) | ((8)))); | |||
| 2014 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2015 | break; | |||
| 2016 | ||||
| 2017 | case LINUX_KDGETLED0x4B31: | |||
| 2018 | args->cmd = KDGETLED((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('K')) << 8) | ((65)))); | |||
| 2019 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2020 | break; | |||
| 2021 | ||||
| 2022 | case LINUX_KDSETLED0x4B32: | |||
| 2023 | args->cmd = KDSETLED((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('K')) << 8) | ((66)))); | |||
| 2024 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2025 | break; | |||
| 2026 | ||||
| 2027 | case LINUX_KDSETMODE0x4B3A: | |||
| 2028 | args->cmd = KDSETMODE((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('K')) << 8) | ((10)))); | |||
| 2029 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2030 | break; | |||
| 2031 | ||||
| 2032 | case LINUX_KDGETMODE0x4B3B: | |||
| 2033 | args->cmd = KDGETMODE((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('K')) << 8) | ((9)))); | |||
| 2034 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2035 | break; | |||
| 2036 | ||||
| 2037 | case LINUX_KDGKBMODE0x4B44: | |||
| 2038 | args->cmd = KDGKBMODE((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('K')) << 8) | ((6)))); | |||
| 2039 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2040 | break; | |||
| 2041 | ||||
| 2042 | case LINUX_KDSKBMODE0x4B45: { | |||
| 2043 | int kbdmode; | |||
| 2044 | switch (args->arg) { | |||
| 2045 | case LINUX_KBD_RAW0: | |||
| 2046 | kbdmode = K_RAW0; | |||
| 2047 | break; | |||
| 2048 | case LINUX_KBD_XLATE1: | |||
| 2049 | kbdmode = K_XLATE1; | |||
| 2050 | break; | |||
| 2051 | case LINUX_KBD_MEDIUMRAW2: | |||
| 2052 | kbdmode = K_RAW0; | |||
| 2053 | break; | |||
| 2054 | default: | |||
| 2055 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 2056 | return (EINVAL22); | |||
| 2057 | } | |||
| 2058 | error = (fo_ioctl(fp, KDSKBMODE((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('K')) << 8) | ((7)))), (caddr_t)&kbdmode, | |||
| 2059 | td->td_ucred, td)); | |||
| 2060 | break; | |||
| 2061 | } | |||
| 2062 | ||||
| 2063 | case LINUX_VT_OPENQRY0x5600: | |||
| 2064 | args->cmd = VT_OPENQRY((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((1)))); | |||
| 2065 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2066 | break; | |||
| 2067 | ||||
| 2068 | case LINUX_VT_GETMODE0x5601: | |||
| 2069 | args->cmd = VT_GETMODE((unsigned long) ((0x40000000) | (((sizeof(vtmode_t)) & ( (1 << 13) - 1)) << 16) | ((('v')) << 8) | ( (3)))); | |||
| 2070 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2071 | break; | |||
| 2072 | ||||
| 2073 | case LINUX_VT_SETMODE0x5602: { | |||
| 2074 | struct vt_mode mode; | |||
| 2075 | if ((error = copyin((void *)args->arg, &mode, sizeof(mode)))) | |||
| 2076 | break; | |||
| 2077 | if (LINUX_SIG_VALID(mode.relsig)((mode.relsig) <= 64 && (mode.relsig) > 0)) | |||
| 2078 | mode.relsig = linux_to_bsd_signal(mode.relsig); | |||
| 2079 | else | |||
| 2080 | mode.relsig = 0; | |||
| 2081 | if (LINUX_SIG_VALID(mode.acqsig)((mode.acqsig) <= 64 && (mode.acqsig) > 0)) | |||
| 2082 | mode.acqsig = linux_to_bsd_signal(mode.acqsig); | |||
| 2083 | else | |||
| 2084 | mode.acqsig = 0; | |||
| 2085 | /* XXX. Linux ignores frsig and set it to 0. */ | |||
| 2086 | mode.frsig = 0; | |||
| 2087 | if ((error = copyout(&mode, (void *)args->arg, sizeof(mode)))) | |||
| 2088 | break; | |||
| 2089 | args->cmd = VT_SETMODE((unsigned long) ((0x80000000) | (((sizeof(vtmode_t)) & ( (1 << 13) - 1)) << 16) | ((('v')) << 8) | ( (2)))); | |||
| 2090 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2091 | break; | |||
| 2092 | } | |||
| 2093 | ||||
| 2094 | case LINUX_VT_GETSTATE0x5603: | |||
| 2095 | args->cmd = VT_GETACTIVE((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((7)))); | |||
| 2096 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2097 | break; | |||
| 2098 | ||||
| 2099 | case LINUX_VT_RELDISP0x5605: | |||
| 2100 | args->cmd = VT_RELDISP((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((4)))); | |||
| 2101 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2102 | break; | |||
| 2103 | ||||
| 2104 | case LINUX_VT_ACTIVATE0x5606: | |||
| 2105 | args->cmd = VT_ACTIVATE((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((5)))); | |||
| 2106 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2107 | break; | |||
| 2108 | ||||
| 2109 | case LINUX_VT_WAITACTIVE0x5607: | |||
| 2110 | args->cmd = VT_WAITACTIVE((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((6)))); | |||
| 2111 | error = (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2112 | break; | |||
| 2113 | ||||
| 2114 | default: | |||
| 2115 | error = ENOIOCTL(-3); | |||
| 2116 | break; | |||
| 2117 | } | |||
| 2118 | ||||
| 2119 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 2120 | return (error); | |||
| 2121 | } | |||
| 2122 | ||||
| 2123 | /* | |||
| 2124 | * Criteria for interface name translation | |||
| 2125 | */ | |||
| 2126 | #define IFP_IS_ETH(ifp)(ifp->if_type == IFT_ETHER) (ifp->if_type == IFT_ETHER) | |||
| 2127 | ||||
| 2128 | /* | |||
| 2129 | * Translate a Linux interface name to a FreeBSD interface name, | |||
| 2130 | * and return the associated ifnet structure | |||
| 2131 | * bsdname and lxname need to be least IFNAMSIZ bytes long, but | |||
| 2132 | * can point to the same buffer. | |||
| 2133 | */ | |||
| 2134 | ||||
| 2135 | static struct ifnet * | |||
| 2136 | ifname_linux_to_bsd(struct thread *td, const char *lxname, char *bsdname) | |||
| 2137 | { | |||
| 2138 | struct ifnet *ifp; | |||
| 2139 | int len, unit; | |||
| 2140 | char *ep; | |||
| 2141 | int is_eth, index; | |||
| 2142 | ||||
| 2143 | for (len = 0; len < LINUX_IFNAMSIZ16; ++len) | |||
| 2144 | if (!isalpha(lxname[len])(((lxname[len]) >= 'A' && (lxname[len]) <= 'Z') || ((lxname[len]) >= 'a' && (lxname[len]) <= 'z' ))) | |||
| 2145 | break; | |||
| 2146 | if (len == 0 || len == LINUX_IFNAMSIZ16) | |||
| 2147 | return (NULL((void *)0)); | |||
| 2148 | unit = (int)strtoul(lxname + len, &ep, 10); | |||
| 2149 | if (ep == NULL((void *)0) || ep == lxname + len || ep >= lxname + LINUX_IFNAMSIZ16) | |||
| 2150 | return (NULL((void *)0)); | |||
| 2151 | index = 0; | |||
| 2152 | is_eth = (len == 3 && !strncmp(lxname, "eth", len)) ? 1 : 0; | |||
| 2153 | CURVNET_SET(TD_TO_VNET(td))do { if (!((((td)->td_ucred)->cr_prison->pr_vnet) != ((void *)0) && (((td)->td_ucred)->cr_prison-> pr_vnet)->vnet_magic_n == 0x3e0d8f29)) panic ("CURVNET_SET at %s:%d %s() curvnet=%p vnet=%p" , "/root/freebsd/sys/compat/linux/linux_ioctl.c", 2153, __func__ , (__curthread())->td_vnet, (((td)->td_ucred)->cr_prison ->pr_vnet)); } while (0); struct vnet *saved_vnet = (__curthread ())->td_vnet; (__curthread())->td_vnet = ((td)->td_ucred )->cr_prison->pr_vnet;; | |||
| 2154 | IFNET_RLOCK()(void)_sx_slock(((&ifnet_sxlock)), 0, ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (2154)); | |||
| 2155 | CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link)for((ifp) = ((__typeof__(*((&((&(*(__typeof(vnet_entry_ifnet )*) (((((__curthread())->td_vnet))->vnet_data_base) + ( uintptr_t)&vnet_entry_ifnet))))->cstqh_first))))ck_pr_md_load_ptr (((&((&(*(__typeof(vnet_entry_ifnet)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ifnet ))))->cstqh_first)))); (ifp) && (ck_pr_fence_load( ), 1); (ifp) = ((__typeof__(*((&((ifp))->if_link.cstqe_next ))))ck_pr_md_load_ptr(((&((ifp))->if_link.cstqe_next)) ))) { | |||
| 2156 | /* | |||
| 2157 | * Allow Linux programs to use FreeBSD names. Don't presume | |||
| 2158 | * we never have an interface named "eth", so don't make | |||
| 2159 | * the test optional based on is_eth. | |||
| 2160 | */ | |||
| 2161 | if (strncmp(ifp->if_xname, lxname, LINUX_IFNAMSIZ16) == 0) | |||
| 2162 | break; | |||
| 2163 | if (is_eth && IFP_IS_ETH(ifp)(ifp->if_type == IFT_ETHER) && unit == index++) | |||
| 2164 | break; | |||
| 2165 | } | |||
| 2166 | IFNET_RUNLOCK()_sx_sunlock(((&ifnet_sxlock)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (2166)); | |||
| 2167 | CURVNET_RESTORE()do { if (!((__curthread())->td_vnet != ((void *)0) && (saved_vnet == ((void *)0) || saved_vnet->vnet_magic_n == 0x3e0d8f29))) panic ("CURVNET_RESTORE at %s:%d %s() curvnet=%p saved_vnet=%p" , "/root/freebsd/sys/compat/linux/linux_ioctl.c", 2167, __func__ , (__curthread())->td_vnet, saved_vnet); } while (0); (__curthread ())->td_vnet = saved_vnet;; | |||
| 2168 | if (ifp != NULL((void *)0)) | |||
| 2169 | strlcpy(bsdname, ifp->if_xname, IFNAMSIZ16); | |||
| 2170 | return (ifp); | |||
| 2171 | } | |||
| 2172 | ||||
| 2173 | /* | |||
| 2174 | * Implement the SIOCGIFNAME ioctl | |||
| 2175 | */ | |||
| 2176 | ||||
| 2177 | static int | |||
| 2178 | linux_ioctl_ifname(struct thread *td, struct l_ifreq *uifr) | |||
| 2179 | { | |||
| 2180 | struct l_ifreq ifr; | |||
| 2181 | struct ifnet *ifp; | |||
| 2182 | int error, ethno, index; | |||
| 2183 | ||||
| 2184 | error = copyin(uifr, &ifr, sizeof(ifr)); | |||
| 2185 | if (error != 0) | |||
| 2186 | return (error); | |||
| 2187 | ||||
| 2188 | CURVNET_SET(TD_TO_VNET(curthread))do { if (!(((((__curthread()))->td_ucred)->cr_prison-> pr_vnet) != ((void *)0) && ((((__curthread()))->td_ucred )->cr_prison->pr_vnet)->vnet_magic_n == 0x3e0d8f29)) panic ("CURVNET_SET at %s:%d %s() curvnet=%p vnet=%p", "/root/freebsd/sys/compat/linux/linux_ioctl.c" , 2188, __func__, (__curthread())->td_vnet, ((((__curthread ()))->td_ucred)->cr_prison->pr_vnet)); } while (0); struct vnet *saved_vnet = (__curthread())->td_vnet; (__curthread ())->td_vnet = (((__curthread()))->td_ucred)->cr_prison ->pr_vnet;; | |||
| 2189 | IFNET_RLOCK()(void)_sx_slock(((&ifnet_sxlock)), 0, ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (2189)); | |||
| 2190 | index = 1; /* ifr.ifr_ifindex starts from 1 */ | |||
| 2191 | ethno = 0; | |||
| 2192 | error = ENODEV19; | |||
| 2193 | CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link)for((ifp) = ((__typeof__(*((&((&(*(__typeof(vnet_entry_ifnet )*) (((((__curthread())->td_vnet))->vnet_data_base) + ( uintptr_t)&vnet_entry_ifnet))))->cstqh_first))))ck_pr_md_load_ptr (((&((&(*(__typeof(vnet_entry_ifnet)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ifnet ))))->cstqh_first)))); (ifp) && (ck_pr_fence_load( ), 1); (ifp) = ((__typeof__(*((&((ifp))->if_link.cstqe_next ))))ck_pr_md_load_ptr(((&((ifp))->if_link.cstqe_next)) ))) { | |||
| 2194 | if (ifr.ifr_ifindexifr_ifru.ifru_ivalue == index) { | |||
| 2195 | if (IFP_IS_ETH(ifp)(ifp->if_type == IFT_ETHER)) | |||
| 2196 | snprintf(ifr.ifr_nameifr_ifrn.ifrn_name, LINUX_IFNAMSIZ16, | |||
| 2197 | "eth%d", ethno); | |||
| 2198 | else | |||
| 2199 | strlcpy(ifr.ifr_nameifr_ifrn.ifrn_name, ifp->if_xname, | |||
| 2200 | LINUX_IFNAMSIZ16); | |||
| 2201 | error = 0; | |||
| 2202 | break; | |||
| 2203 | } | |||
| 2204 | if (IFP_IS_ETH(ifp)(ifp->if_type == IFT_ETHER)) | |||
| 2205 | ethno++; | |||
| 2206 | index++; | |||
| 2207 | } | |||
| 2208 | IFNET_RUNLOCK()_sx_sunlock(((&ifnet_sxlock)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (2208)); | |||
| 2209 | if (error == 0) | |||
| 2210 | error = copyout(&ifr, uifr, sizeof(ifr)); | |||
| 2211 | CURVNET_RESTORE()do { if (!((__curthread())->td_vnet != ((void *)0) && (saved_vnet == ((void *)0) || saved_vnet->vnet_magic_n == 0x3e0d8f29))) panic ("CURVNET_RESTORE at %s:%d %s() curvnet=%p saved_vnet=%p" , "/root/freebsd/sys/compat/linux/linux_ioctl.c", 2211, __func__ , (__curthread())->td_vnet, saved_vnet); } while (0); (__curthread ())->td_vnet = saved_vnet;; | |||
| 2212 | ||||
| 2213 | return (error); | |||
| 2214 | } | |||
| 2215 | ||||
| 2216 | /* | |||
| 2217 | * Implement the SIOCGIFCONF ioctl | |||
| 2218 | */ | |||
| 2219 | ||||
| 2220 | static int | |||
| 2221 | linux_ifconf(struct thread *td, struct ifconf *uifc) | |||
| 2222 | { | |||
| 2223 | #ifdef COMPAT_LINUX32 | |||
| 2224 | struct l_ifconf ifc; | |||
| 2225 | #else | |||
| 2226 | struct ifconf ifc; | |||
| 2227 | #endif | |||
| 2228 | struct l_ifreq ifr; | |||
| 2229 | struct ifnet *ifp; | |||
| 2230 | struct ifaddr *ifa; | |||
| 2231 | struct sbuf *sb; | |||
| 2232 | int error, ethno, full = 0, valid_len, max_len; | |||
| 2233 | ||||
| 2234 | error = copyin(uifc, &ifc, sizeof(ifc)); | |||
| 2235 | if (error != 0) | |||
| 2236 | return (error); | |||
| 2237 | ||||
| 2238 | max_len = MAXPHYS(128 * 1024) - 1; | |||
| 2239 | ||||
| 2240 | CURVNET_SET(TD_TO_VNET(td))do { if (!((((td)->td_ucred)->cr_prison->pr_vnet) != ((void *)0) && (((td)->td_ucred)->cr_prison-> pr_vnet)->vnet_magic_n == 0x3e0d8f29)) panic ("CURVNET_SET at %s:%d %s() curvnet=%p vnet=%p" , "/root/freebsd/sys/compat/linux/linux_ioctl.c", 2240, __func__ , (__curthread())->td_vnet, (((td)->td_ucred)->cr_prison ->pr_vnet)); } while (0); struct vnet *saved_vnet = (__curthread ())->td_vnet; (__curthread())->td_vnet = ((td)->td_ucred )->cr_prison->pr_vnet;; | |||
| 2241 | /* handle the 'request buffer size' case */ | |||
| 2242 | if ((l_uintptr_t)ifc.ifc_bufifc_ifcu.ifcu_buf == PTROUT(NULL)(uintptr_t)(((void *)0))) { | |||
| 2243 | ifc.ifc_len = 0; | |||
| 2244 | IFNET_RLOCK()(void)_sx_slock(((&ifnet_sxlock)), 0, ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (2244)); | |||
| 2245 | CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link)for((ifp) = ((__typeof__(*((&((&(*(__typeof(vnet_entry_ifnet )*) (((((__curthread())->td_vnet))->vnet_data_base) + ( uintptr_t)&vnet_entry_ifnet))))->cstqh_first))))ck_pr_md_load_ptr (((&((&(*(__typeof(vnet_entry_ifnet)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ifnet ))))->cstqh_first)))); (ifp) && (ck_pr_fence_load( ), 1); (ifp) = ((__typeof__(*((&((ifp))->if_link.cstqe_next ))))ck_pr_md_load_ptr(((&((ifp))->if_link.cstqe_next)) ))) { | |||
| 2246 | CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)for((ifa) = ((__typeof__(*((&((&ifp->if_addrhead)) ->cstqh_first))))ck_pr_md_load_ptr(((&((&ifp->if_addrhead ))->cstqh_first)))); (ifa) && (ck_pr_fence_load(), 1); (ifa) = ((__typeof__(*((&((ifa))->ifa_link.cstqe_next ))))ck_pr_md_load_ptr(((&((ifa))->ifa_link.cstqe_next) )))) { | |||
| 2247 | struct sockaddr *sa = ifa->ifa_addr; | |||
| 2248 | if (sa->sa_family == AF_INET2) | |||
| 2249 | ifc.ifc_len += sizeof(ifr); | |||
| 2250 | } | |||
| 2251 | } | |||
| 2252 | IFNET_RUNLOCK()_sx_sunlock(((&ifnet_sxlock)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (2252)); | |||
| 2253 | error = copyout(&ifc, uifc, sizeof(ifc)); | |||
| 2254 | CURVNET_RESTORE()do { if (!((__curthread())->td_vnet != ((void *)0) && (saved_vnet == ((void *)0) || saved_vnet->vnet_magic_n == 0x3e0d8f29))) panic ("CURVNET_RESTORE at %s:%d %s() curvnet=%p saved_vnet=%p" , "/root/freebsd/sys/compat/linux/linux_ioctl.c", 2254, __func__ , (__curthread())->td_vnet, saved_vnet); } while (0); (__curthread ())->td_vnet = saved_vnet;; | |||
| 2255 | return (error); | |||
| 2256 | } | |||
| 2257 | ||||
| 2258 | if (ifc.ifc_len <= 0) { | |||
| 2259 | CURVNET_RESTORE()do { if (!((__curthread())->td_vnet != ((void *)0) && (saved_vnet == ((void *)0) || saved_vnet->vnet_magic_n == 0x3e0d8f29))) panic ("CURVNET_RESTORE at %s:%d %s() curvnet=%p saved_vnet=%p" , "/root/freebsd/sys/compat/linux/linux_ioctl.c", 2259, __func__ , (__curthread())->td_vnet, saved_vnet); } while (0); (__curthread ())->td_vnet = saved_vnet;; | |||
| 2260 | return (EINVAL22); | |||
| 2261 | } | |||
| 2262 | ||||
| 2263 | again: | |||
| 2264 | /* Keep track of eth interfaces */ | |||
| 2265 | ethno = 0; | |||
| 2266 | if (ifc.ifc_len <= max_len) { | |||
| 2267 | max_len = ifc.ifc_len; | |||
| 2268 | full = 1; | |||
| 2269 | } | |||
| 2270 | sb = sbuf_new(NULL((void *)0), NULL((void *)0), max_len + 1, SBUF_FIXEDLEN0x00000000); | |||
| 2271 | max_len = 0; | |||
| 2272 | valid_len = 0; | |||
| 2273 | ||||
| 2274 | /* Return all AF_INET addresses of all interfaces */ | |||
| 2275 | IFNET_RLOCK()(void)_sx_slock(((&ifnet_sxlock)), 0, ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (2275)); | |||
| 2276 | CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link)for((ifp) = ((__typeof__(*((&((&(*(__typeof(vnet_entry_ifnet )*) (((((__curthread())->td_vnet))->vnet_data_base) + ( uintptr_t)&vnet_entry_ifnet))))->cstqh_first))))ck_pr_md_load_ptr (((&((&(*(__typeof(vnet_entry_ifnet)*) (((((__curthread ())->td_vnet))->vnet_data_base) + (uintptr_t)&vnet_entry_ifnet ))))->cstqh_first)))); (ifp) && (ck_pr_fence_load( ), 1); (ifp) = ((__typeof__(*((&((ifp))->if_link.cstqe_next ))))ck_pr_md_load_ptr(((&((ifp))->if_link.cstqe_next)) ))) { | |||
| 2277 | int addrs = 0; | |||
| 2278 | ||||
| 2279 | bzero(&ifr, sizeof(ifr))__builtin_memset((&ifr), 0, (sizeof(ifr))); | |||
| 2280 | if (IFP_IS_ETH(ifp)(ifp->if_type == IFT_ETHER)) | |||
| 2281 | snprintf(ifr.ifr_nameifr_ifrn.ifrn_name, LINUX_IFNAMSIZ16, "eth%d", | |||
| 2282 | ethno++); | |||
| 2283 | else | |||
| 2284 | strlcpy(ifr.ifr_nameifr_ifrn.ifrn_name, ifp->if_xname, LINUX_IFNAMSIZ16); | |||
| 2285 | ||||
| 2286 | /* Walk the address list */ | |||
| 2287 | CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)for((ifa) = ((__typeof__(*((&((&ifp->if_addrhead)) ->cstqh_first))))ck_pr_md_load_ptr(((&((&ifp->if_addrhead ))->cstqh_first)))); (ifa) && (ck_pr_fence_load(), 1); (ifa) = ((__typeof__(*((&((ifa))->ifa_link.cstqe_next ))))ck_pr_md_load_ptr(((&((ifa))->ifa_link.cstqe_next) )))) { | |||
| 2288 | struct sockaddr *sa = ifa->ifa_addr; | |||
| 2289 | ||||
| 2290 | if (sa->sa_family == AF_INET2) { | |||
| 2291 | ifr.ifr_addrifr_ifru.ifru_addr.sa_family = LINUX_AF_INET2; | |||
| 2292 | memcpy(ifr.ifr_addr.sa_data, sa->sa_data,__builtin_memcpy((ifr.ifr_ifru.ifru_addr.sa_data), (sa->sa_data ), (sizeof(ifr.ifr_ifru.ifru_addr.sa_data))) | |||
| 2293 | sizeof(ifr.ifr_addr.sa_data))__builtin_memcpy((ifr.ifr_ifru.ifru_addr.sa_data), (sa->sa_data ), (sizeof(ifr.ifr_ifru.ifru_addr.sa_data))); | |||
| 2294 | sbuf_bcat(sb, &ifr, sizeof(ifr)); | |||
| 2295 | max_len += sizeof(ifr); | |||
| 2296 | addrs++; | |||
| 2297 | } | |||
| 2298 | ||||
| 2299 | if (sbuf_error(sb) == 0) | |||
| 2300 | valid_len = sbuf_len(sb); | |||
| 2301 | } | |||
| 2302 | if (addrs == 0) { | |||
| 2303 | bzero((caddr_t)&ifr.ifr_addr, sizeof(ifr.ifr_addr))__builtin_memset(((caddr_t)&ifr.ifr_ifru.ifru_addr), 0, ( sizeof(ifr.ifr_ifru.ifru_addr))); | |||
| 2304 | sbuf_bcat(sb, &ifr, sizeof(ifr)); | |||
| 2305 | max_len += sizeof(ifr); | |||
| 2306 | ||||
| 2307 | if (sbuf_error(sb) == 0) | |||
| 2308 | valid_len = sbuf_len(sb); | |||
| 2309 | } | |||
| 2310 | } | |||
| 2311 | IFNET_RUNLOCK()_sx_sunlock(((&ifnet_sxlock)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (2311)); | |||
| 2312 | ||||
| 2313 | if (valid_len != max_len && !full) { | |||
| 2314 | sbuf_delete(sb); | |||
| 2315 | goto again; | |||
| 2316 | } | |||
| 2317 | ||||
| 2318 | ifc.ifc_len = valid_len; | |||
| 2319 | sbuf_finish(sb); | |||
| 2320 | error = copyout(sbuf_data(sb), PTRIN(ifc.ifc_buf)(void *)(ifc.ifc_ifcu.ifcu_buf), ifc.ifc_len); | |||
| 2321 | if (error == 0) | |||
| 2322 | error = copyout(&ifc, uifc, sizeof(ifc)); | |||
| 2323 | sbuf_delete(sb); | |||
| 2324 | CURVNET_RESTORE()do { if (!((__curthread())->td_vnet != ((void *)0) && (saved_vnet == ((void *)0) || saved_vnet->vnet_magic_n == 0x3e0d8f29))) panic ("CURVNET_RESTORE at %s:%d %s() curvnet=%p saved_vnet=%p" , "/root/freebsd/sys/compat/linux/linux_ioctl.c", 2324, __func__ , (__curthread())->td_vnet, saved_vnet); } while (0); (__curthread ())->td_vnet = saved_vnet;; | |||
| 2325 | ||||
| 2326 | return (error); | |||
| 2327 | } | |||
| 2328 | ||||
| 2329 | static int | |||
| 2330 | linux_gifflags(struct thread *td, struct ifnet *ifp, struct l_ifreq *ifr) | |||
| 2331 | { | |||
| 2332 | l_short flags; | |||
| 2333 | ||||
| 2334 | flags = (ifp->if_flags | ifp->if_drv_flags) & 0xffff; | |||
| 2335 | /* these flags have no Linux equivalent */ | |||
| 2336 | flags &= ~(IFF_DRV_OACTIVE0x400|IFF_SIMPLEX0x800| | |||
| 2337 | IFF_LINK00x1000|IFF_LINK10x2000|IFF_LINK20x4000); | |||
| 2338 | /* Linux' multicast flag is in a different bit */ | |||
| 2339 | if (flags & IFF_MULTICAST0x8000) { | |||
| 2340 | flags &= ~IFF_MULTICAST0x8000; | |||
| 2341 | flags |= 0x1000; | |||
| 2342 | } | |||
| 2343 | ||||
| 2344 | return (copyout(&flags, &ifr->ifr_flagsifr_ifru.ifru_flags[0], sizeof(flags))); | |||
| 2345 | } | |||
| 2346 | ||||
| 2347 | #define ARPHRD_ETHER1 1 | |||
| 2348 | #define ARPHRD_LOOPBACK772 772 | |||
| 2349 | ||||
| 2350 | static int | |||
| 2351 | linux_gifhwaddr(struct ifnet *ifp, struct l_ifreq *ifr) | |||
| 2352 | { | |||
| 2353 | struct ifaddr *ifa; | |||
| 2354 | struct sockaddr_dl *sdl; | |||
| 2355 | struct l_sockaddr lsa; | |||
| 2356 | ||||
| 2357 | if (ifp->if_type == IFT_LOOP) { | |||
| 2358 | bzero(&lsa, sizeof(lsa))__builtin_memset((&lsa), 0, (sizeof(lsa))); | |||
| 2359 | lsa.sa_family = ARPHRD_LOOPBACK772; | |||
| 2360 | return (copyout(&lsa, &ifr->ifr_hwaddrifr_ifru.ifru_hwaddr, sizeof(lsa))); | |||
| 2361 | } | |||
| 2362 | ||||
| 2363 | if (ifp->if_type != IFT_ETHER) | |||
| 2364 | return (ENOENT2); | |||
| 2365 | ||||
| 2366 | CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link)for((ifa) = ((__typeof__(*((&((&ifp->if_addrhead)) ->cstqh_first))))ck_pr_md_load_ptr(((&((&ifp->if_addrhead ))->cstqh_first)))); (ifa) && (ck_pr_fence_load(), 1); (ifa) = ((__typeof__(*((&((ifa))->ifa_link.cstqe_next ))))ck_pr_md_load_ptr(((&((ifa))->ifa_link.cstqe_next) )))) { | |||
| 2367 | sdl = (struct sockaddr_dl*)ifa->ifa_addr; | |||
| 2368 | if (sdl != NULL((void *)0) && (sdl->sdl_family == AF_LINK18) && | |||
| 2369 | (sdl->sdl_type == IFT_ETHER)) { | |||
| 2370 | bzero(&lsa, sizeof(lsa))__builtin_memset((&lsa), 0, (sizeof(lsa))); | |||
| 2371 | lsa.sa_family = ARPHRD_ETHER1; | |||
| 2372 | bcopy(LLADDR(sdl), lsa.sa_data, LINUX_IFHWADDRLEN)__builtin_memmove((lsa.sa_data), (((caddr_t)((sdl)->sdl_data + (sdl)->sdl_nlen))), (6)); | |||
| 2373 | return (copyout(&lsa, &ifr->ifr_hwaddrifr_ifru.ifru_hwaddr, sizeof(lsa))); | |||
| 2374 | } | |||
| 2375 | } | |||
| 2376 | ||||
| 2377 | return (ENOENT2); | |||
| 2378 | } | |||
| 2379 | ||||
| 2380 | ||||
| 2381 | /* | |||
| 2382 | * If we fault in bsd_to_linux_ifreq() then we will fault when we call | |||
| 2383 | * the native ioctl(). Thus, we don't really need to check the return | |||
| 2384 | * value of this function. | |||
| 2385 | */ | |||
| 2386 | static int | |||
| 2387 | bsd_to_linux_ifreq(struct ifreq *arg) | |||
| 2388 | { | |||
| 2389 | struct ifreq ifr; | |||
| 2390 | size_t ifr_len = sizeof(struct ifreq); | |||
| 2391 | int error; | |||
| 2392 | ||||
| 2393 | if ((error = copyin(arg, &ifr, ifr_len))) | |||
| 2394 | return (error); | |||
| 2395 | ||||
| 2396 | *(u_short *)&ifr.ifr_addrifr_ifru.ifru_addr = ifr.ifr_addrifr_ifru.ifru_addr.sa_family; | |||
| 2397 | ||||
| 2398 | error = copyout(&ifr, arg, ifr_len); | |||
| 2399 | ||||
| 2400 | return (error); | |||
| 2401 | } | |||
| 2402 | ||||
| 2403 | /* | |||
| 2404 | * Socket related ioctls | |||
| 2405 | */ | |||
| 2406 | ||||
| 2407 | static int | |||
| 2408 | linux_ioctl_socket(struct thread *td, struct linux_ioctl_args *args) | |||
| 2409 | { | |||
| 2410 | char lifname[LINUX_IFNAMSIZ16], ifname[IFNAMSIZ16]; | |||
| 2411 | struct ifnet *ifp; | |||
| 2412 | struct file *fp; | |||
| 2413 | int error, type; | |||
| 2414 | ||||
| 2415 | ifp = NULL((void *)0); | |||
| 2416 | error = 0; | |||
| 2417 | ||||
| 2418 | error = fget(td, args->fd, &cap_ioctl_rights, &fp); | |||
| 2419 | if (error != 0) | |||
| 2420 | return (error); | |||
| 2421 | type = fp->f_type; | |||
| 2422 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 2423 | if (type != DTYPE_SOCKET2) { | |||
| 2424 | /* not a socket - probably a tap / vmnet device */ | |||
| 2425 | switch (args->cmd) { | |||
| 2426 | case LINUX_SIOCGIFADDR0x8915: | |||
| 2427 | case LINUX_SIOCSIFADDR0x8916: | |||
| 2428 | case LINUX_SIOCGIFFLAGS0x8913: | |||
| 2429 | return (linux_ioctl_special(td, args)); | |||
| 2430 | default: | |||
| 2431 | return (ENOIOCTL(-3)); | |||
| 2432 | } | |||
| 2433 | } | |||
| 2434 | ||||
| 2435 | switch (args->cmd & 0xffff) { | |||
| 2436 | ||||
| 2437 | case LINUX_FIOGETOWN0x8903: | |||
| 2438 | case LINUX_FIOSETOWN0x8901: | |||
| 2439 | case LINUX_SIOCADDMULTI0x8931: | |||
| 2440 | case LINUX_SIOCATMARK0x8905: | |||
| 2441 | case LINUX_SIOCDELMULTI0x8932: | |||
| 2442 | case LINUX_SIOCGIFNAME0x8910: | |||
| 2443 | case LINUX_SIOCGIFCONF0x8912: | |||
| 2444 | case LINUX_SIOCGPGRP0x8904: | |||
| 2445 | case LINUX_SIOCSPGRP0x8902: | |||
| 2446 | case LINUX_SIOCGIFCOUNT0x8938: | |||
| 2447 | /* these ioctls don't take an interface name */ | |||
| 2448 | #ifdef DEBUG | |||
| 2449 | printf("%s(): ioctl %d\n", __func__, | |||
| 2450 | args->cmd & 0xffff); | |||
| 2451 | #endif | |||
| 2452 | break; | |||
| 2453 | ||||
| 2454 | case LINUX_SIOCGIFFLAGS0x8913: | |||
| 2455 | case LINUX_SIOCGIFADDR0x8915: | |||
| 2456 | case LINUX_SIOCSIFADDR0x8916: | |||
| 2457 | case LINUX_SIOCGIFDSTADDR0x8917: | |||
| 2458 | case LINUX_SIOCGIFBRDADDR0x8919: | |||
| 2459 | case LINUX_SIOCGIFNETMASK0x891b: | |||
| 2460 | case LINUX_SIOCSIFNETMASK0x891c: | |||
| 2461 | case LINUX_SIOCGIFMTU0x8921: | |||
| 2462 | case LINUX_SIOCSIFMTU0x8922: | |||
| 2463 | case LINUX_SIOCSIFNAME0x8923: | |||
| 2464 | case LINUX_SIOCGIFHWADDR0x8927: | |||
| 2465 | case LINUX_SIOCSIFHWADDR0x8924: | |||
| 2466 | case LINUX_SIOCDEVPRIVATE0x89F0: | |||
| 2467 | case LINUX_SIOCDEVPRIVATE0x89F0+1: | |||
| 2468 | case LINUX_SIOCGIFINDEX0x8933: | |||
| 2469 | /* copy in the interface name and translate it. */ | |||
| 2470 | error = copyin((void *)args->arg, lifname, LINUX_IFNAMSIZ16); | |||
| 2471 | if (error != 0) | |||
| 2472 | return (error); | |||
| 2473 | #ifdef DEBUG | |||
| 2474 | printf("%s(): ioctl %d on %.*s\n", __func__, | |||
| 2475 | args->cmd & 0xffff, LINUX_IFNAMSIZ16, lifname); | |||
| 2476 | #endif | |||
| 2477 | memset(ifname, 0, sizeof(ifname))__builtin_memset((ifname), (0), (sizeof(ifname))); | |||
| 2478 | ifp = ifname_linux_to_bsd(td, lifname, ifname); | |||
| 2479 | if (ifp == NULL((void *)0)) | |||
| 2480 | return (EINVAL22); | |||
| 2481 | /* | |||
| 2482 | * We need to copy it back out in case we pass the | |||
| 2483 | * request on to our native ioctl(), which will expect | |||
| 2484 | * the ifreq to be in user space and have the correct | |||
| 2485 | * interface name. | |||
| 2486 | */ | |||
| 2487 | error = copyout(ifname, (void *)args->arg, IFNAMSIZ16); | |||
| 2488 | if (error != 0) | |||
| 2489 | return (error); | |||
| 2490 | #ifdef DEBUG | |||
| 2491 | printf("%s(): %s translated to %s\n", __func__, | |||
| 2492 | lifname, ifname); | |||
| 2493 | #endif | |||
| 2494 | break; | |||
| 2495 | ||||
| 2496 | default: | |||
| 2497 | return (ENOIOCTL(-3)); | |||
| 2498 | } | |||
| 2499 | ||||
| 2500 | switch (args->cmd & 0xffff) { | |||
| 2501 | ||||
| 2502 | case LINUX_FIOSETOWN0x8901: | |||
| 2503 | args->cmd = FIOSETOWN((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('f')) << 8) | ((124)))); | |||
| 2504 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2505 | break; | |||
| 2506 | ||||
| 2507 | case LINUX_SIOCSPGRP0x8902: | |||
| 2508 | args->cmd = SIOCSPGRP((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('s')) << 8) | ((8)))); | |||
| 2509 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2510 | break; | |||
| 2511 | ||||
| 2512 | case LINUX_FIOGETOWN0x8903: | |||
| 2513 | args->cmd = FIOGETOWN((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('f')) << 8) | ((123)))); | |||
| 2514 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2515 | break; | |||
| 2516 | ||||
| 2517 | case LINUX_SIOCGPGRP0x8904: | |||
| 2518 | args->cmd = SIOCGPGRP((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('s')) << 8) | ((9)))); | |||
| 2519 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2520 | break; | |||
| 2521 | ||||
| 2522 | case LINUX_SIOCATMARK0x8905: | |||
| 2523 | args->cmd = SIOCATMARK((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('s')) << 8) | ((7)))); | |||
| 2524 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2525 | break; | |||
| 2526 | ||||
| 2527 | /* LINUX_SIOCGSTAMP */ | |||
| 2528 | ||||
| 2529 | case LINUX_SIOCGIFNAME0x8910: | |||
| 2530 | error = linux_ioctl_ifname(td, (struct l_ifreq *)args->arg); | |||
| 2531 | break; | |||
| 2532 | ||||
| 2533 | case LINUX_SIOCGIFCONF0x8912: | |||
| 2534 | error = linux_ifconf(td, (struct ifconf *)args->arg); | |||
| 2535 | break; | |||
| 2536 | ||||
| 2537 | case LINUX_SIOCGIFFLAGS0x8913: | |||
| 2538 | args->cmd = SIOCGIFFLAGS((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((17)))); | |||
| 2539 | error = linux_gifflags(td, ifp, (struct l_ifreq *)args->arg); | |||
| 2540 | break; | |||
| 2541 | ||||
| 2542 | case LINUX_SIOCGIFADDR0x8915: | |||
| 2543 | args->cmd = SIOCGIFADDR((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((33)))); | |||
| 2544 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2545 | bsd_to_linux_ifreq((struct ifreq *)args->arg); | |||
| 2546 | break; | |||
| 2547 | ||||
| 2548 | case LINUX_SIOCSIFADDR0x8916: | |||
| 2549 | /* XXX probably doesn't work, included for completeness */ | |||
| 2550 | args->cmd = SIOCSIFADDR((unsigned long) ((0x80000000) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((12)))); | |||
| 2551 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2552 | break; | |||
| 2553 | ||||
| 2554 | case LINUX_SIOCGIFDSTADDR0x8917: | |||
| 2555 | args->cmd = SIOCGIFDSTADDR((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((34)))); | |||
| 2556 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2557 | bsd_to_linux_ifreq((struct ifreq *)args->arg); | |||
| 2558 | break; | |||
| 2559 | ||||
| 2560 | case LINUX_SIOCGIFBRDADDR0x8919: | |||
| 2561 | args->cmd = SIOCGIFBRDADDR((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((35)))); | |||
| 2562 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2563 | bsd_to_linux_ifreq((struct ifreq *)args->arg); | |||
| 2564 | break; | |||
| 2565 | ||||
| 2566 | case LINUX_SIOCGIFNETMASK0x891b: | |||
| 2567 | args->cmd = SIOCGIFNETMASK((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((37)))); | |||
| 2568 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2569 | bsd_to_linux_ifreq((struct ifreq *)args->arg); | |||
| 2570 | break; | |||
| 2571 | ||||
| 2572 | case LINUX_SIOCSIFNETMASK0x891c: | |||
| 2573 | error = ENOIOCTL(-3); | |||
| 2574 | break; | |||
| 2575 | ||||
| 2576 | case LINUX_SIOCGIFMTU0x8921: | |||
| 2577 | args->cmd = SIOCGIFMTU((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((51)))); | |||
| 2578 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2579 | break; | |||
| 2580 | ||||
| 2581 | case LINUX_SIOCSIFMTU0x8922: | |||
| 2582 | args->cmd = SIOCSIFMTU((unsigned long) ((0x80000000) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((52)))); | |||
| 2583 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2584 | break; | |||
| 2585 | ||||
| 2586 | case LINUX_SIOCSIFNAME0x8923: | |||
| 2587 | error = ENOIOCTL(-3); | |||
| 2588 | break; | |||
| 2589 | ||||
| 2590 | case LINUX_SIOCGIFHWADDR0x8927: | |||
| 2591 | error = linux_gifhwaddr(ifp, (struct l_ifreq *)args->arg); | |||
| 2592 | break; | |||
| 2593 | ||||
| 2594 | case LINUX_SIOCSIFHWADDR0x8924: | |||
| 2595 | error = ENOIOCTL(-3); | |||
| 2596 | break; | |||
| 2597 | ||||
| 2598 | case LINUX_SIOCADDMULTI0x8931: | |||
| 2599 | args->cmd = SIOCADDMULTI((unsigned long) ((0x80000000) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((49)))); | |||
| 2600 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2601 | break; | |||
| 2602 | ||||
| 2603 | case LINUX_SIOCDELMULTI0x8932: | |||
| 2604 | args->cmd = SIOCDELMULTI((unsigned long) ((0x80000000) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((50)))); | |||
| 2605 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2606 | break; | |||
| 2607 | ||||
| 2608 | case LINUX_SIOCGIFINDEX0x8933: | |||
| 2609 | args->cmd = SIOCGIFINDEX((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((32)))); | |||
| 2610 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2611 | break; | |||
| 2612 | ||||
| 2613 | case LINUX_SIOCGIFCOUNT0x8938: | |||
| 2614 | error = 0; | |||
| 2615 | break; | |||
| 2616 | ||||
| 2617 | /* | |||
| 2618 | * XXX This is slightly bogus, but these ioctls are currently | |||
| 2619 | * XXX only used by the aironet (if_an) network driver. | |||
| 2620 | */ | |||
| 2621 | case LINUX_SIOCDEVPRIVATE0x89F0: | |||
| 2622 | args->cmd = SIOCGPRIVATE_0((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((80)))); | |||
| 2623 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2624 | break; | |||
| 2625 | ||||
| 2626 | case LINUX_SIOCDEVPRIVATE0x89F0+1: | |||
| 2627 | args->cmd = SIOCGPRIVATE_1((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((81)))); | |||
| 2628 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 2629 | break; | |||
| 2630 | } | |||
| 2631 | ||||
| 2632 | if (ifp != NULL((void *)0)) | |||
| 2633 | /* restore the original interface name */ | |||
| 2634 | copyout(lifname, (void *)args->arg, LINUX_IFNAMSIZ16); | |||
| 2635 | ||||
| 2636 | #ifdef DEBUG | |||
| 2637 | printf("%s(): returning %d\n", __func__, error); | |||
| 2638 | #endif | |||
| 2639 | return (error); | |||
| 2640 | } | |||
| 2641 | ||||
| 2642 | /* | |||
| 2643 | * Device private ioctl handler | |||
| 2644 | */ | |||
| 2645 | static int | |||
| 2646 | linux_ioctl_private(struct thread *td, struct linux_ioctl_args *args) | |||
| 2647 | { | |||
| 2648 | struct file *fp; | |||
| 2649 | int error, type; | |||
| 2650 | ||||
| 2651 | error = fget(td, args->fd, &cap_ioctl_rights, &fp); | |||
| 2652 | if (error != 0) | |||
| 2653 | return (error); | |||
| 2654 | type = fp->f_type; | |||
| 2655 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 2656 | if (type == DTYPE_SOCKET2) | |||
| 2657 | return (linux_ioctl_socket(td, args)); | |||
| 2658 | return (ENOIOCTL(-3)); | |||
| 2659 | } | |||
| 2660 | ||||
| 2661 | /* | |||
| 2662 | * DRM ioctl handler (sys/dev/drm) | |||
| 2663 | */ | |||
| 2664 | static int | |||
| 2665 | linux_ioctl_drm(struct thread *td, struct linux_ioctl_args *args) | |||
| 2666 | { | |||
| 2667 | args->cmd = SETDIR(args->cmd)(((args->cmd) & ~(0x20000000|0x40000000|0x80000000)) | dirbits[args->cmd >> 30]); | |||
| 2668 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2669 | } | |||
| 2670 | ||||
| 2671 | #ifdef COMPAT_LINUX32 | |||
| 2672 | #define CP(src,dst,fld)do { (dst).fld = (src).fld; } while (0) do { (dst).fld = (src).fld; } while (0) | |||
| 2673 | #define PTRIN_CP(src,dst,fld)do { (dst).fld = (void *)((src).fld); } while (0) \ | |||
| 2674 | do { (dst).fld = PTRIN((src).fld)(void *)((src).fld); } while (0) | |||
| 2675 | #define PTROUT_CP(src,dst,fld) \ | |||
| 2676 | do { (dst).fld = PTROUT((src).fld)(uintptr_t)((src).fld); } while (0) | |||
| 2677 | ||||
| 2678 | static int | |||
| 2679 | linux_ioctl_sg_io(struct thread *td, struct linux_ioctl_args *args) | |||
| 2680 | { | |||
| 2681 | struct sg_io_hdr io; | |||
| 2682 | struct sg_io_hdr32 io32; | |||
| 2683 | struct file *fp; | |||
| 2684 | int error; | |||
| 2685 | ||||
| 2686 | error = fget(td, args->fd, &cap_ioctl_rights, &fp); | |||
| 2687 | if (error != 0) { | |||
| 2688 | printf("sg_linux_ioctl: fget returned %d\n", error); | |||
| 2689 | return (error); | |||
| 2690 | } | |||
| 2691 | ||||
| 2692 | if ((error = copyin((void *)args->arg, &io32, sizeof(io32))) != 0) | |||
| 2693 | goto out; | |||
| 2694 | ||||
| 2695 | CP(io32, io, interface_id)do { (io).interface_id = (io32).interface_id; } while (0); | |||
| 2696 | CP(io32, io, dxfer_direction)do { (io).dxfer_direction = (io32).dxfer_direction; } while ( 0); | |||
| 2697 | CP(io32, io, cmd_len)do { (io).cmd_len = (io32).cmd_len; } while (0); | |||
| 2698 | CP(io32, io, mx_sb_len)do { (io).mx_sb_len = (io32).mx_sb_len; } while (0); | |||
| 2699 | CP(io32, io, iovec_count)do { (io).iovec_count = (io32).iovec_count; } while (0); | |||
| 2700 | CP(io32, io, dxfer_len)do { (io).dxfer_len = (io32).dxfer_len; } while (0); | |||
| 2701 | PTRIN_CP(io32, io, dxferp)do { (io).dxferp = (void *)((io32).dxferp); } while (0); | |||
| 2702 | PTRIN_CP(io32, io, cmdp)do { (io).cmdp = (void *)((io32).cmdp); } while (0); | |||
| 2703 | PTRIN_CP(io32, io, sbp)do { (io).sbp = (void *)((io32).sbp); } while (0); | |||
| 2704 | CP(io32, io, timeout)do { (io).timeout = (io32).timeout; } while (0); | |||
| 2705 | CP(io32, io, flags)do { (io).flags = (io32).flags; } while (0); | |||
| 2706 | CP(io32, io, pack_id)do { (io).pack_id = (io32).pack_id; } while (0); | |||
| 2707 | PTRIN_CP(io32, io, usr_ptr)do { (io).usr_ptr = (void *)((io32).usr_ptr); } while (0); | |||
| 2708 | CP(io32, io, status)do { (io).status = (io32).status; } while (0); | |||
| 2709 | CP(io32, io, masked_status)do { (io).masked_status = (io32).masked_status; } while (0); | |||
| 2710 | CP(io32, io, msg_status)do { (io).msg_status = (io32).msg_status; } while (0); | |||
| 2711 | CP(io32, io, sb_len_wr)do { (io).sb_len_wr = (io32).sb_len_wr; } while (0); | |||
| 2712 | CP(io32, io, host_status)do { (io).host_status = (io32).host_status; } while (0); | |||
| 2713 | CP(io32, io, driver_status)do { (io).driver_status = (io32).driver_status; } while (0); | |||
| 2714 | CP(io32, io, resid)do { (io).resid = (io32).resid; } while (0); | |||
| 2715 | CP(io32, io, duration)do { (io).duration = (io32).duration; } while (0); | |||
| 2716 | CP(io32, io, info)do { (io).info = (io32).info; } while (0); | |||
| 2717 | ||||
| 2718 | if ((error = fo_ioctl(fp, SG_IO((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct sg_io_hdr)) & ((1 << 13) - 1)) << 16) | ((('"' )) << 8) | ((0x85)))), (caddr_t)&io, td->td_ucred, td)) != 0) | |||
| 2719 | goto out; | |||
| 2720 | ||||
| 2721 | CP(io, io32, interface_id)do { (io32).interface_id = (io).interface_id; } while (0); | |||
| 2722 | CP(io, io32, dxfer_direction)do { (io32).dxfer_direction = (io).dxfer_direction; } while ( 0); | |||
| 2723 | CP(io, io32, cmd_len)do { (io32).cmd_len = (io).cmd_len; } while (0); | |||
| 2724 | CP(io, io32, mx_sb_len)do { (io32).mx_sb_len = (io).mx_sb_len; } while (0); | |||
| 2725 | CP(io, io32, iovec_count)do { (io32).iovec_count = (io).iovec_count; } while (0); | |||
| 2726 | CP(io, io32, dxfer_len)do { (io32).dxfer_len = (io).dxfer_len; } while (0); | |||
| 2727 | PTROUT_CP(io, io32, dxferp); | |||
| 2728 | PTROUT_CP(io, io32, cmdp); | |||
| 2729 | PTROUT_CP(io, io32, sbp); | |||
| 2730 | CP(io, io32, timeout)do { (io32).timeout = (io).timeout; } while (0); | |||
| 2731 | CP(io, io32, flags)do { (io32).flags = (io).flags; } while (0); | |||
| 2732 | CP(io, io32, pack_id)do { (io32).pack_id = (io).pack_id; } while (0); | |||
| 2733 | PTROUT_CP(io, io32, usr_ptr); | |||
| 2734 | CP(io, io32, status)do { (io32).status = (io).status; } while (0); | |||
| 2735 | CP(io, io32, masked_status)do { (io32).masked_status = (io).masked_status; } while (0); | |||
| 2736 | CP(io, io32, msg_status)do { (io32).msg_status = (io).msg_status; } while (0); | |||
| 2737 | CP(io, io32, sb_len_wr)do { (io32).sb_len_wr = (io).sb_len_wr; } while (0); | |||
| 2738 | CP(io, io32, host_status)do { (io32).host_status = (io).host_status; } while (0); | |||
| 2739 | CP(io, io32, driver_status)do { (io32).driver_status = (io).driver_status; } while (0); | |||
| 2740 | CP(io, io32, resid)do { (io32).resid = (io).resid; } while (0); | |||
| 2741 | CP(io, io32, duration)do { (io32).duration = (io).duration; } while (0); | |||
| 2742 | CP(io, io32, info)do { (io32).info = (io).info; } while (0); | |||
| 2743 | ||||
| 2744 | error = copyout(&io32, (void *)args->arg, sizeof(io32)); | |||
| 2745 | ||||
| 2746 | out: | |||
| 2747 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 2748 | return (error); | |||
| 2749 | } | |||
| 2750 | #endif | |||
| 2751 | ||||
| 2752 | static int | |||
| 2753 | linux_ioctl_sg(struct thread *td, struct linux_ioctl_args *args) | |||
| 2754 | { | |||
| 2755 | ||||
| 2756 | switch (args->cmd) { | |||
| 2757 | case LINUX_SG_GET_VERSION_NUM0x2282: | |||
| 2758 | args->cmd = SG_GET_VERSION_NUM((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('"')) << 8) | ((0x82)))); | |||
| 2759 | break; | |||
| 2760 | case LINUX_SG_SET_TIMEOUT0x2201: | |||
| 2761 | args->cmd = SG_SET_TIMEOUT((unsigned long) ((0x80000000) | (((sizeof(u_int)) & ((1 << 13) - 1)) << 16) | ((('"')) << 8) | ((0x01)))); | |||
| 2762 | break; | |||
| 2763 | case LINUX_SG_GET_TIMEOUT0x2202: | |||
| 2764 | args->cmd = SG_GET_TIMEOUT((unsigned long) ((0x20000000) | (((0) & ((1 << 13) - 1)) << 16) | ((('"')) << 8) | ((0x02)))); | |||
| 2765 | break; | |||
| 2766 | case LINUX_SG_IO0x2285: | |||
| 2767 | args->cmd = SG_IO((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct sg_io_hdr)) & ((1 << 13) - 1)) << 16) | ((('"' )) << 8) | ((0x85)))); | |||
| 2768 | #ifdef COMPAT_LINUX32 | |||
| 2769 | return (linux_ioctl_sg_io(td, args)); | |||
| 2770 | #endif | |||
| 2771 | break; | |||
| 2772 | case LINUX_SG_GET_RESERVED_SIZE0x2272: | |||
| 2773 | args->cmd = SG_GET_RESERVED_SIZE((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('"')) << 8) | ((0x72)))); | |||
| 2774 | break; | |||
| 2775 | case LINUX_SG_GET_SCSI_ID0x2276: | |||
| 2776 | args->cmd = SG_GET_SCSI_ID((unsigned long) ((0x40000000) | (((sizeof(struct sg_scsi_id) ) & ((1 << 13) - 1)) << 16) | ((('"')) << 8) | ((0x76)))); | |||
| 2777 | break; | |||
| 2778 | case LINUX_SG_GET_SG_TABLESIZE0x227f: | |||
| 2779 | args->cmd = SG_GET_SG_TABLESIZE((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('"')) << 8) | ((0x7f)))); | |||
| 2780 | break; | |||
| 2781 | default: | |||
| 2782 | return (ENODEV19); | |||
| 2783 | } | |||
| 2784 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 2785 | } | |||
| 2786 | ||||
| 2787 | /* | |||
| 2788 | * Video4Linux (V4L) ioctl handler | |||
| 2789 | */ | |||
| 2790 | static int | |||
| 2791 | linux_to_bsd_v4l_tuner(struct l_video_tuner *lvt, struct video_tuner *vt) | |||
| 2792 | { | |||
| 2793 | vt->tuner = lvt->tuner; | |||
| 2794 | strlcpy(vt->name, lvt->name, LINUX_VIDEO_TUNER_NAME_SIZE32); | |||
| 2795 | vt->rangelow = lvt->rangelow; /* possible long size conversion */ | |||
| 2796 | vt->rangehigh = lvt->rangehigh; /* possible long size conversion */ | |||
| 2797 | vt->flags = lvt->flags; | |||
| 2798 | vt->mode = lvt->mode; | |||
| 2799 | vt->signal = lvt->signal; | |||
| 2800 | return (0); | |||
| 2801 | } | |||
| 2802 | ||||
| 2803 | static int | |||
| 2804 | bsd_to_linux_v4l_tuner(struct video_tuner *vt, struct l_video_tuner *lvt) | |||
| 2805 | { | |||
| 2806 | lvt->tuner = vt->tuner; | |||
| 2807 | strlcpy(lvt->name, vt->name, LINUX_VIDEO_TUNER_NAME_SIZE32); | |||
| 2808 | lvt->rangelow = vt->rangelow; /* possible long size conversion */ | |||
| 2809 | lvt->rangehigh = vt->rangehigh; /* possible long size conversion */ | |||
| 2810 | lvt->flags = vt->flags; | |||
| 2811 | lvt->mode = vt->mode; | |||
| 2812 | lvt->signal = vt->signal; | |||
| 2813 | return (0); | |||
| 2814 | } | |||
| 2815 | ||||
| 2816 | #ifdef COMPAT_LINUX_V4L_CLIPLIST | |||
| 2817 | static int | |||
| 2818 | linux_to_bsd_v4l_clip(struct l_video_clip *lvc, struct video_clip *vc) | |||
| 2819 | { | |||
| 2820 | vc->x = lvc->x; | |||
| 2821 | vc->y = lvc->y; | |||
| 2822 | vc->width = lvc->width; | |||
| 2823 | vc->height = lvc->height; | |||
| 2824 | vc->next = PTRIN(lvc->next)(void *)(lvc->next); /* possible pointer size conversion */ | |||
| 2825 | return (0); | |||
| 2826 | } | |||
| 2827 | #endif | |||
| 2828 | ||||
| 2829 | static int | |||
| 2830 | linux_to_bsd_v4l_window(struct l_video_window *lvw, struct video_window *vw) | |||
| 2831 | { | |||
| 2832 | vw->x = lvw->x; | |||
| 2833 | vw->y = lvw->y; | |||
| 2834 | vw->width = lvw->width; | |||
| 2835 | vw->height = lvw->height; | |||
| 2836 | vw->chromakey = lvw->chromakey; | |||
| 2837 | vw->flags = lvw->flags; | |||
| 2838 | vw->clips = PTRIN(lvw->clips)(void *)(lvw->clips); /* possible pointer size conversion */ | |||
| 2839 | vw->clipcount = lvw->clipcount; | |||
| 2840 | return (0); | |||
| 2841 | } | |||
| 2842 | ||||
| 2843 | static int | |||
| 2844 | bsd_to_linux_v4l_window(struct video_window *vw, struct l_video_window *lvw) | |||
| 2845 | { | |||
| 2846 | lvw->x = vw->x; | |||
| 2847 | lvw->y = vw->y; | |||
| 2848 | lvw->width = vw->width; | |||
| 2849 | lvw->height = vw->height; | |||
| 2850 | lvw->chromakey = vw->chromakey; | |||
| 2851 | lvw->flags = vw->flags; | |||
| 2852 | lvw->clips = PTROUT(vw->clips)(uintptr_t)(vw->clips); /* possible pointer size conversion */ | |||
| 2853 | lvw->clipcount = vw->clipcount; | |||
| 2854 | return (0); | |||
| 2855 | } | |||
| 2856 | ||||
| 2857 | static int | |||
| 2858 | linux_to_bsd_v4l_buffer(struct l_video_buffer *lvb, struct video_buffer *vb) | |||
| 2859 | { | |||
| 2860 | vb->base = PTRIN(lvb->base)(void *)(lvb->base); /* possible pointer size conversion */ | |||
| 2861 | vb->height = lvb->height; | |||
| 2862 | vb->width = lvb->width; | |||
| 2863 | vb->depth = lvb->depth; | |||
| 2864 | vb->bytesperline = lvb->bytesperline; | |||
| 2865 | return (0); | |||
| 2866 | } | |||
| 2867 | ||||
| 2868 | static int | |||
| 2869 | bsd_to_linux_v4l_buffer(struct video_buffer *vb, struct l_video_buffer *lvb) | |||
| 2870 | { | |||
| 2871 | lvb->base = PTROUT(vb->base)(uintptr_t)(vb->base); /* possible pointer size conversion */ | |||
| 2872 | lvb->height = vb->height; | |||
| 2873 | lvb->width = vb->width; | |||
| 2874 | lvb->depth = vb->depth; | |||
| 2875 | lvb->bytesperline = vb->bytesperline; | |||
| 2876 | return (0); | |||
| 2877 | } | |||
| 2878 | ||||
| 2879 | static int | |||
| 2880 | linux_to_bsd_v4l_code(struct l_video_code *lvc, struct video_code *vc) | |||
| 2881 | { | |||
| 2882 | strlcpy(vc->loadwhat, lvc->loadwhat, LINUX_VIDEO_CODE_LOADWHAT_SIZE16); | |||
| 2883 | vc->datasize = lvc->datasize; | |||
| 2884 | vc->data = PTRIN(lvc->data)(void *)(lvc->data); /* possible pointer size conversion */ | |||
| 2885 | return (0); | |||
| 2886 | } | |||
| 2887 | ||||
| 2888 | #ifdef COMPAT_LINUX_V4L_CLIPLIST | |||
| 2889 | static int | |||
| 2890 | linux_v4l_clip_copy(void *lvc, struct video_clip **ppvc) | |||
| 2891 | { | |||
| 2892 | int error; | |||
| 2893 | struct video_clip vclip; | |||
| 2894 | struct l_video_clip l_vclip; | |||
| 2895 | ||||
| 2896 | error = copyin(lvc, &l_vclip, sizeof(l_vclip)); | |||
| 2897 | if (error) return (error); | |||
| 2898 | linux_to_bsd_v4l_clip(&l_vclip, &vclip); | |||
| 2899 | /* XXX: If there can be no concurrency: s/M_NOWAIT/M_WAITOK/ */ | |||
| 2900 | if ((*ppvc = malloc(sizeof(**ppvc), M_LINUX, M_NOWAIT0x0001)) == NULL((void *)0)) | |||
| 2901 | return (ENOMEM12); /* XXX: Linux has no ENOMEM here. */ | |||
| 2902 | memcpy(*ppvc, &vclip, sizeof(vclip))__builtin_memcpy((*ppvc), (&vclip), (sizeof(vclip))); | |||
| 2903 | (*ppvc)->next = NULL((void *)0); | |||
| 2904 | return (0); | |||
| 2905 | } | |||
| 2906 | ||||
| 2907 | static int | |||
| 2908 | linux_v4l_cliplist_free(struct video_window *vw) | |||
| 2909 | { | |||
| 2910 | struct video_clip **ppvc; | |||
| 2911 | struct video_clip **ppvc_next; | |||
| 2912 | ||||
| 2913 | for (ppvc = &(vw->clips); *ppvc != NULL((void *)0); ppvc = ppvc_next) { | |||
| 2914 | ppvc_next = &((*ppvc)->next); | |||
| 2915 | free(*ppvc, M_LINUX); | |||
| 2916 | } | |||
| 2917 | vw->clips = NULL((void *)0); | |||
| 2918 | ||||
| 2919 | return (0); | |||
| 2920 | } | |||
| 2921 | ||||
| 2922 | static int | |||
| 2923 | linux_v4l_cliplist_copy(struct l_video_window *lvw, struct video_window *vw) | |||
| 2924 | { | |||
| 2925 | int error; | |||
| 2926 | int clipcount; | |||
| 2927 | void *plvc; | |||
| 2928 | struct video_clip **ppvc; | |||
| 2929 | ||||
| 2930 | /* | |||
| 2931 | * XXX: The cliplist is used to pass in a list of clipping | |||
| 2932 | * rectangles or, if clipcount == VIDEO_CLIP_BITMAP, a | |||
| 2933 | * clipping bitmap. Some Linux apps, however, appear to | |||
| 2934 | * leave cliplist and clips uninitialized. In any case, | |||
| 2935 | * the cliplist is not used by pwc(4), at the time of | |||
| 2936 | * writing, FreeBSD's only V4L driver. When a driver | |||
| 2937 | * that uses the cliplist is developed, this code may | |||
| 2938 | * need re-examiniation. | |||
| 2939 | */ | |||
| 2940 | error = 0; | |||
| 2941 | clipcount = vw->clipcount; | |||
| 2942 | if (clipcount == VIDEO_CLIP_BITMAP-1) { | |||
| 2943 | /* | |||
| 2944 | * In this case, the pointer (clips) is overloaded | |||
| 2945 | * to be a "void *" to a bitmap, therefore there | |||
| 2946 | * is no struct video_clip to copy now. | |||
| 2947 | */ | |||
| 2948 | } else if (clipcount > 0 && clipcount <= 16384) { | |||
| 2949 | /* | |||
| 2950 | * Clips points to list of clip rectangles, so | |||
| 2951 | * copy the list. | |||
| 2952 | * | |||
| 2953 | * XXX: Upper limit of 16384 was used here to try to | |||
| 2954 | * avoid cases when clipcount and clips pointer | |||
| 2955 | * are uninitialized and therefore have high random | |||
| 2956 | * values, as is the case in the Linux Skype | |||
| 2957 | * application. The value 16384 was chosen as that | |||
| 2958 | * is what is used in the Linux stradis(4) MPEG | |||
| 2959 | * decoder driver, the only place we found an | |||
| 2960 | * example of cliplist use. | |||
| 2961 | */ | |||
| 2962 | plvc = PTRIN(lvw->clips)(void *)(lvw->clips); | |||
| 2963 | vw->clips = NULL((void *)0); | |||
| 2964 | ppvc = &(vw->clips); | |||
| 2965 | while (clipcount-- > 0) { | |||
| 2966 | if (plvc == NULL((void *)0)) { | |||
| 2967 | error = EFAULT14; | |||
| 2968 | break; | |||
| 2969 | } else { | |||
| 2970 | error = linux_v4l_clip_copy(plvc, ppvc); | |||
| 2971 | if (error) { | |||
| 2972 | linux_v4l_cliplist_free(vw); | |||
| 2973 | break; | |||
| 2974 | } | |||
| 2975 | } | |||
| 2976 | ppvc = &((*ppvc)->next); | |||
| 2977 | plvc = PTRIN(((struct l_video_clip *) plvc)->next)(void *)(((struct l_video_clip *) plvc)->next); | |||
| 2978 | } | |||
| 2979 | } else { | |||
| 2980 | /* | |||
| 2981 | * clipcount == 0 or negative (but not VIDEO_CLIP_BITMAP) | |||
| 2982 | * Force cliplist to null. | |||
| 2983 | */ | |||
| 2984 | vw->clipcount = 0; | |||
| 2985 | vw->clips = NULL((void *)0); | |||
| 2986 | } | |||
| 2987 | return (error); | |||
| 2988 | } | |||
| 2989 | #endif | |||
| 2990 | ||||
| 2991 | static int | |||
| 2992 | linux_ioctl_v4l(struct thread *td, struct linux_ioctl_args *args) | |||
| 2993 | { | |||
| 2994 | struct file *fp; | |||
| 2995 | int error; | |||
| 2996 | struct video_tuner vtun; | |||
| 2997 | struct video_window vwin; | |||
| 2998 | struct video_buffer vbuf; | |||
| 2999 | struct video_code vcode; | |||
| 3000 | struct l_video_tuner l_vtun; | |||
| 3001 | struct l_video_window l_vwin; | |||
| 3002 | struct l_video_buffer l_vbuf; | |||
| 3003 | struct l_video_code l_vcode; | |||
| 3004 | ||||
| 3005 | switch (args->cmd & 0xffff) { | |||
| 3006 | case LINUX_VIDIOCGCAP0x7601: args->cmd = VIDIOCGCAP((unsigned long) ((0x40000000) | (((sizeof(struct video_capability )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((1)))); break; | |||
| 3007 | case LINUX_VIDIOCGCHAN0x7602: args->cmd = VIDIOCGCHAN((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct video_channel)) & ((1 << 13) - 1)) << 16) | ( (('v')) << 8) | ((2)))); break; | |||
| 3008 | case LINUX_VIDIOCSCHAN0x7603: args->cmd = VIDIOCSCHAN((unsigned long) ((0x80000000) | (((sizeof(struct video_channel )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((3)))); break; | |||
| 3009 | ||||
| 3010 | case LINUX_VIDIOCGTUNER0x7604: | |||
| 3011 | error = fget(td, args->fd, | |||
| 3012 | &cap_ioctl_rights, &fp); | |||
| 3013 | if (error != 0) | |||
| 3014 | return (error); | |||
| 3015 | error = copyin((void *) args->arg, &l_vtun, sizeof(l_vtun)); | |||
| 3016 | if (error) { | |||
| 3017 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3018 | return (error); | |||
| 3019 | } | |||
| 3020 | linux_to_bsd_v4l_tuner(&l_vtun, &vtun); | |||
| 3021 | error = fo_ioctl(fp, VIDIOCGTUNER((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct video_tuner)) & ((1 << 13) - 1)) << 16) | (( ('v')) << 8) | ((4)))), &vtun, td->td_ucred, td); | |||
| 3022 | if (!error) { | |||
| 3023 | bsd_to_linux_v4l_tuner(&vtun, &l_vtun); | |||
| 3024 | error = copyout(&l_vtun, (void *) args->arg, | |||
| 3025 | sizeof(l_vtun)); | |||
| 3026 | } | |||
| 3027 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3028 | return (error); | |||
| 3029 | ||||
| 3030 | case LINUX_VIDIOCSTUNER0x7605: | |||
| 3031 | error = fget(td, args->fd, | |||
| 3032 | &cap_ioctl_rights, &fp); | |||
| 3033 | if (error != 0) | |||
| 3034 | return (error); | |||
| 3035 | error = copyin((void *) args->arg, &l_vtun, sizeof(l_vtun)); | |||
| 3036 | if (error) { | |||
| 3037 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3038 | return (error); | |||
| 3039 | } | |||
| 3040 | linux_to_bsd_v4l_tuner(&l_vtun, &vtun); | |||
| 3041 | error = fo_ioctl(fp, VIDIOCSTUNER((unsigned long) ((0x80000000) | (((sizeof(struct video_tuner )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((5)))), &vtun, td->td_ucred, td); | |||
| 3042 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3043 | return (error); | |||
| 3044 | ||||
| 3045 | case LINUX_VIDIOCGPICT0x7606: args->cmd = VIDIOCGPICT((unsigned long) ((0x40000000) | (((sizeof(struct video_picture )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((6)))); break; | |||
| 3046 | case LINUX_VIDIOCSPICT0x7607: args->cmd = VIDIOCSPICT((unsigned long) ((0x80000000) | (((sizeof(struct video_picture )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((7)))); break; | |||
| 3047 | case LINUX_VIDIOCCAPTURE0x7608: args->cmd = VIDIOCCAPTURE((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((8)))); break; | |||
| 3048 | ||||
| 3049 | case LINUX_VIDIOCGWIN0x7609: | |||
| 3050 | error = fget(td, args->fd, | |||
| 3051 | &cap_ioctl_rights, &fp); | |||
| 3052 | if (error != 0) | |||
| 3053 | return (error); | |||
| 3054 | error = fo_ioctl(fp, VIDIOCGWIN((unsigned long) ((0x40000000) | (((sizeof(struct video_window )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((9)))), &vwin, td->td_ucred, td); | |||
| 3055 | if (!error) { | |||
| 3056 | bsd_to_linux_v4l_window(&vwin, &l_vwin); | |||
| 3057 | error = copyout(&l_vwin, (void *) args->arg, | |||
| 3058 | sizeof(l_vwin)); | |||
| 3059 | } | |||
| 3060 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3061 | return (error); | |||
| 3062 | ||||
| 3063 | case LINUX_VIDIOCSWIN0x760a: | |||
| 3064 | error = fget(td, args->fd, | |||
| 3065 | &cap_ioctl_rights, &fp); | |||
| 3066 | if (error != 0) | |||
| 3067 | return (error); | |||
| 3068 | error = copyin((void *) args->arg, &l_vwin, sizeof(l_vwin)); | |||
| 3069 | if (error) { | |||
| 3070 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3071 | return (error); | |||
| 3072 | } | |||
| 3073 | linux_to_bsd_v4l_window(&l_vwin, &vwin); | |||
| 3074 | #ifdef COMPAT_LINUX_V4L_CLIPLIST | |||
| 3075 | error = linux_v4l_cliplist_copy(&l_vwin, &vwin); | |||
| 3076 | if (error) { | |||
| 3077 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3078 | return (error); | |||
| 3079 | } | |||
| 3080 | #endif | |||
| 3081 | error = fo_ioctl(fp, VIDIOCSWIN((unsigned long) ((0x80000000) | (((sizeof(struct video_window )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((10)))), &vwin, td->td_ucred, td); | |||
| 3082 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3083 | #ifdef COMPAT_LINUX_V4L_CLIPLIST | |||
| 3084 | linux_v4l_cliplist_free(&vwin); | |||
| 3085 | #endif | |||
| 3086 | return (error); | |||
| 3087 | ||||
| 3088 | case LINUX_VIDIOCGFBUF0x760b: | |||
| 3089 | error = fget(td, args->fd, | |||
| 3090 | &cap_ioctl_rights, &fp); | |||
| 3091 | if (error != 0) | |||
| 3092 | return (error); | |||
| 3093 | error = fo_ioctl(fp, VIDIOCGFBUF((unsigned long) ((0x40000000) | (((sizeof(struct video_buffer )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((11)))), &vbuf, td->td_ucred, td); | |||
| 3094 | if (!error) { | |||
| 3095 | bsd_to_linux_v4l_buffer(&vbuf, &l_vbuf); | |||
| 3096 | error = copyout(&l_vbuf, (void *) args->arg, | |||
| 3097 | sizeof(l_vbuf)); | |||
| 3098 | } | |||
| 3099 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3100 | return (error); | |||
| 3101 | ||||
| 3102 | case LINUX_VIDIOCSFBUF0x760c: | |||
| 3103 | error = fget(td, args->fd, | |||
| 3104 | &cap_ioctl_rights, &fp); | |||
| 3105 | if (error != 0) | |||
| 3106 | return (error); | |||
| 3107 | error = copyin((void *) args->arg, &l_vbuf, sizeof(l_vbuf)); | |||
| 3108 | if (error) { | |||
| 3109 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3110 | return (error); | |||
| 3111 | } | |||
| 3112 | linux_to_bsd_v4l_buffer(&l_vbuf, &vbuf); | |||
| 3113 | error = fo_ioctl(fp, VIDIOCSFBUF((unsigned long) ((0x80000000) | (((sizeof(struct video_buffer )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((12)))), &vbuf, td->td_ucred, td); | |||
| 3114 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3115 | return (error); | |||
| 3116 | ||||
| 3117 | case LINUX_VIDIOCKEY0x760d: args->cmd = VIDIOCKEY((unsigned long) ((0x40000000) | (((sizeof(struct video_key)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((13)))); break; | |||
| 3118 | case LINUX_VIDIOCGFREQ0x760e: args->cmd = VIDIOCGFREQ((unsigned long) ((0x40000000) | (((sizeof(unsigned long)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((14)))); break; | |||
| 3119 | case LINUX_VIDIOCSFREQ0x760f: args->cmd = VIDIOCSFREQ((unsigned long) ((0x80000000) | (((sizeof(unsigned long)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((15)))); break; | |||
| 3120 | case LINUX_VIDIOCGAUDIO0x7610: args->cmd = VIDIOCGAUDIO((unsigned long) ((0x40000000) | (((sizeof(struct video_audio )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((16)))); break; | |||
| 3121 | case LINUX_VIDIOCSAUDIO0x7611: args->cmd = VIDIOCSAUDIO((unsigned long) ((0x80000000) | (((sizeof(struct video_audio )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((17)))); break; | |||
| 3122 | case LINUX_VIDIOCSYNC0x7623: args->cmd = VIDIOCSYNC((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((18)))); break; | |||
| 3123 | case LINUX_VIDIOCMCAPTURE0x7613: args->cmd = VIDIOCMCAPTURE((unsigned long) ((0x80000000) | (((sizeof(struct video_mmap) ) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((19)))); break; | |||
| 3124 | case LINUX_VIDIOCGMBUF0x7614: args->cmd = VIDIOCGMBUF((unsigned long) ((0x40000000) | (((sizeof(struct video_mbuf) ) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((20)))); break; | |||
| 3125 | case LINUX_VIDIOCGUNIT0x7615: args->cmd = VIDIOCGUNIT((unsigned long) ((0x40000000) | (((sizeof(struct video_unit) ) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((21)))); break; | |||
| 3126 | case LINUX_VIDIOCGCAPTURE0x7616: args->cmd = VIDIOCGCAPTURE((unsigned long) ((0x40000000) | (((sizeof(struct video_capture )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((22)))); break; | |||
| 3127 | case LINUX_VIDIOCSCAPTURE0x7617: args->cmd = VIDIOCSCAPTURE((unsigned long) ((0x80000000) | (((sizeof(struct video_capture )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((23)))); break; | |||
| 3128 | case LINUX_VIDIOCSPLAYMODE0x7618: args->cmd = VIDIOCSPLAYMODE((unsigned long) ((0x80000000) | (((sizeof(struct video_play_mode )) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((24)))); break; | |||
| 3129 | case LINUX_VIDIOCSWRITEMODE0x7619: args->cmd = VIDIOCSWRITEMODE((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((25)))); break; | |||
| 3130 | case LINUX_VIDIOCGPLAYINFO0x761a: args->cmd = VIDIOCGPLAYINFO((unsigned long) ((0x40000000) | (((sizeof(struct video_info) ) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((26)))); break; | |||
| 3131 | ||||
| 3132 | case LINUX_VIDIOCSMICROCODE0x761b: | |||
| 3133 | error = fget(td, args->fd, | |||
| 3134 | &cap_ioctl_rights, &fp); | |||
| 3135 | if (error != 0) | |||
| 3136 | return (error); | |||
| 3137 | error = copyin((void *) args->arg, &l_vcode, sizeof(l_vcode)); | |||
| 3138 | if (error) { | |||
| 3139 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3140 | return (error); | |||
| 3141 | } | |||
| 3142 | linux_to_bsd_v4l_code(&l_vcode, &vcode); | |||
| 3143 | error = fo_ioctl(fp, VIDIOCSMICROCODE((unsigned long) ((0x80000000) | (((sizeof(struct video_code) ) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((27)))), &vcode, td->td_ucred, td); | |||
| 3144 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3145 | return (error); | |||
| 3146 | ||||
| 3147 | case LINUX_VIDIOCGVBIFMT0x761c: args->cmd = VIDIOCGVBIFMT((unsigned long) ((0x40000000) | (((sizeof(struct vbi_format) ) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((28)))); break; | |||
| 3148 | case LINUX_VIDIOCSVBIFMT0x761d: args->cmd = VIDIOCSVBIFMT((unsigned long) ((0x80000000) | (((sizeof(struct vbi_format) ) & ((1 << 13) - 1)) << 16) | ((('v')) << 8) | ((29)))); break; | |||
| 3149 | default: return (ENOIOCTL(-3)); | |||
| 3150 | } | |||
| 3151 | ||||
| 3152 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 3153 | return (error); | |||
| 3154 | } | |||
| 3155 | ||||
| 3156 | /* | |||
| 3157 | * Special ioctl handler | |||
| 3158 | */ | |||
| 3159 | static int | |||
| 3160 | linux_ioctl_special(struct thread *td, struct linux_ioctl_args *args) | |||
| 3161 | { | |||
| 3162 | int error; | |||
| 3163 | ||||
| 3164 | switch (args->cmd) { | |||
| 3165 | case LINUX_SIOCGIFADDR0x8915: | |||
| 3166 | args->cmd = SIOCGIFADDR((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((33)))); | |||
| 3167 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 3168 | break; | |||
| 3169 | case LINUX_SIOCSIFADDR0x8916: | |||
| 3170 | args->cmd = SIOCSIFADDR((unsigned long) ((0x80000000) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((12)))); | |||
| 3171 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 3172 | break; | |||
| 3173 | case LINUX_SIOCGIFFLAGS0x8913: | |||
| 3174 | args->cmd = SIOCGIFFLAGS((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct ifreq)) & ((1 << 13) - 1)) << 16) | ((('i')) << 8) | ((17)))); | |||
| 3175 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 3176 | break; | |||
| 3177 | default: | |||
| 3178 | error = ENOIOCTL(-3); | |||
| 3179 | } | |||
| 3180 | ||||
| 3181 | return (error); | |||
| 3182 | } | |||
| 3183 | ||||
| 3184 | static int | |||
| 3185 | linux_to_bsd_v4l2_standard(struct l_v4l2_standard *lvstd, struct v4l2_standard *vstd) | |||
| 3186 | { | |||
| 3187 | vstd->index = lvstd->index; | |||
| 3188 | vstd->id = lvstd->id; | |||
| 3189 | CTASSERT(sizeof(vstd->name) == sizeof(lvstd->name))_Static_assert(sizeof(vstd->name) == sizeof(lvstd->name ), "compile-time assertion failed"); | |||
| 3190 | memcpy(vstd->name, lvstd->name, sizeof(vstd->name))__builtin_memcpy((vstd->name), (lvstd->name), (sizeof(vstd ->name))); | |||
| 3191 | vstd->frameperiod = lvstd->frameperiod; | |||
| 3192 | vstd->framelines = lvstd->framelines; | |||
| 3193 | CTASSERT(sizeof(vstd->reserved) == sizeof(lvstd->reserved))_Static_assert(sizeof(vstd->reserved) == sizeof(lvstd-> reserved), "compile-time assertion failed"); | |||
| 3194 | memcpy(vstd->reserved, lvstd->reserved, sizeof(vstd->reserved))__builtin_memcpy((vstd->reserved), (lvstd->reserved), ( sizeof(vstd->reserved))); | |||
| 3195 | return (0); | |||
| 3196 | } | |||
| 3197 | ||||
| 3198 | static int | |||
| 3199 | bsd_to_linux_v4l2_standard(struct v4l2_standard *vstd, struct l_v4l2_standard *lvstd) | |||
| 3200 | { | |||
| 3201 | lvstd->index = vstd->index; | |||
| 3202 | lvstd->id = vstd->id; | |||
| 3203 | CTASSERT(sizeof(vstd->name) == sizeof(lvstd->name))_Static_assert(sizeof(vstd->name) == sizeof(lvstd->name ), "compile-time assertion failed"); | |||
| 3204 | memcpy(lvstd->name, vstd->name, sizeof(lvstd->name))__builtin_memcpy((lvstd->name), (vstd->name), (sizeof(lvstd ->name))); | |||
| 3205 | lvstd->frameperiod = vstd->frameperiod; | |||
| 3206 | lvstd->framelines = vstd->framelines; | |||
| 3207 | CTASSERT(sizeof(vstd->reserved) == sizeof(lvstd->reserved))_Static_assert(sizeof(vstd->reserved) == sizeof(lvstd-> reserved), "compile-time assertion failed"); | |||
| 3208 | memcpy(lvstd->reserved, vstd->reserved, sizeof(lvstd->reserved))__builtin_memcpy((lvstd->reserved), (vstd->reserved), ( sizeof(lvstd->reserved))); | |||
| 3209 | return (0); | |||
| 3210 | } | |||
| 3211 | ||||
| 3212 | static int | |||
| 3213 | linux_to_bsd_v4l2_buffer(struct l_v4l2_buffer *lvb, struct v4l2_buffer *vb) | |||
| 3214 | { | |||
| 3215 | vb->index = lvb->index; | |||
| 3216 | vb->type = lvb->type; | |||
| 3217 | vb->bytesused = lvb->bytesused; | |||
| 3218 | vb->flags = lvb->flags; | |||
| 3219 | vb->field = lvb->field; | |||
| 3220 | vb->timestamp.tv_sec = lvb->timestamp.tv_sec; | |||
| 3221 | vb->timestamp.tv_usec = lvb->timestamp.tv_usec; | |||
| 3222 | memcpy(&vb->timecode, &lvb->timecode, sizeof (lvb->timecode))__builtin_memcpy((&vb->timecode), (&lvb->timecode ), (sizeof (lvb->timecode))); | |||
| 3223 | vb->sequence = lvb->sequence; | |||
| 3224 | vb->memory = lvb->memory; | |||
| 3225 | if (lvb->memory == V4L2_MEMORY_USERPTR) | |||
| 3226 | /* possible pointer size conversion */ | |||
| 3227 | vb->m.userptr = (unsigned long)PTRIN(lvb->m.userptr)(void *)(lvb->m.userptr); | |||
| 3228 | else | |||
| 3229 | vb->m.offset = lvb->m.offset; | |||
| 3230 | vb->length = lvb->length; | |||
| 3231 | vb->input = lvb->input; | |||
| 3232 | vb->reserved = lvb->reserved; | |||
| 3233 | return (0); | |||
| 3234 | } | |||
| 3235 | ||||
| 3236 | static int | |||
| 3237 | bsd_to_linux_v4l2_buffer(struct v4l2_buffer *vb, struct l_v4l2_buffer *lvb) | |||
| 3238 | { | |||
| 3239 | lvb->index = vb->index; | |||
| 3240 | lvb->type = vb->type; | |||
| 3241 | lvb->bytesused = vb->bytesused; | |||
| 3242 | lvb->flags = vb->flags; | |||
| 3243 | lvb->field = vb->field; | |||
| 3244 | lvb->timestamp.tv_sec = vb->timestamp.tv_sec; | |||
| 3245 | lvb->timestamp.tv_usec = vb->timestamp.tv_usec; | |||
| 3246 | memcpy(&lvb->timecode, &vb->timecode, sizeof (vb->timecode))__builtin_memcpy((&lvb->timecode), (&vb->timecode ), (sizeof (vb->timecode))); | |||
| 3247 | lvb->sequence = vb->sequence; | |||
| 3248 | lvb->memory = vb->memory; | |||
| 3249 | if (vb->memory == V4L2_MEMORY_USERPTR) | |||
| 3250 | /* possible pointer size conversion */ | |||
| 3251 | lvb->m.userptr = PTROUT(vb->m.userptr)(uintptr_t)(vb->m.userptr); | |||
| 3252 | else | |||
| 3253 | lvb->m.offset = vb->m.offset; | |||
| 3254 | lvb->length = vb->length; | |||
| 3255 | lvb->input = vb->input; | |||
| 3256 | lvb->reserved = vb->reserved; | |||
| 3257 | return (0); | |||
| 3258 | } | |||
| 3259 | ||||
| 3260 | static int | |||
| 3261 | linux_to_bsd_v4l2_format(struct l_v4l2_format *lvf, struct v4l2_format *vf) | |||
| 3262 | { | |||
| 3263 | vf->type = lvf->type; | |||
| 3264 | if (lvf->type == V4L2_BUF_TYPE_VIDEO_OVERLAY | |||
| 3265 | #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY | |||
| 3266 | || lvf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY | |||
| 3267 | #endif | |||
| 3268 | ) | |||
| 3269 | /* | |||
| 3270 | * XXX TODO - needs 32 -> 64 bit conversion: | |||
| 3271 | * (unused by webcams?) | |||
| 3272 | */ | |||
| 3273 | return (EINVAL22); | |||
| 3274 | memcpy(&vf->fmt, &lvf->fmt, sizeof(vf->fmt))__builtin_memcpy((&vf->fmt), (&lvf->fmt), (sizeof (vf->fmt))); | |||
| 3275 | return (0); | |||
| 3276 | } | |||
| 3277 | ||||
| 3278 | static int | |||
| 3279 | bsd_to_linux_v4l2_format(struct v4l2_format *vf, struct l_v4l2_format *lvf) | |||
| 3280 | { | |||
| 3281 | lvf->type = vf->type; | |||
| 3282 | if (vf->type == V4L2_BUF_TYPE_VIDEO_OVERLAY | |||
| 3283 | #ifdef V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY | |||
| 3284 | || vf->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY | |||
| 3285 | #endif | |||
| 3286 | ) | |||
| 3287 | /* | |||
| 3288 | * XXX TODO - needs 32 -> 64 bit conversion: | |||
| 3289 | * (unused by webcams?) | |||
| 3290 | */ | |||
| 3291 | return (EINVAL22); | |||
| 3292 | memcpy(&lvf->fmt, &vf->fmt, sizeof(vf->fmt))__builtin_memcpy((&lvf->fmt), (&vf->fmt), (sizeof (vf->fmt))); | |||
| 3293 | return (0); | |||
| 3294 | } | |||
| 3295 | static int | |||
| 3296 | linux_ioctl_v4l2(struct thread *td, struct linux_ioctl_args *args) | |||
| 3297 | { | |||
| 3298 | struct file *fp; | |||
| 3299 | int error; | |||
| 3300 | struct v4l2_format vformat; | |||
| 3301 | struct l_v4l2_format l_vformat; | |||
| 3302 | struct v4l2_standard vstd; | |||
| 3303 | struct l_v4l2_standard l_vstd; | |||
| 3304 | struct l_v4l2_buffer l_vbuf; | |||
| 3305 | struct v4l2_buffer vbuf; | |||
| 3306 | struct v4l2_input vinp; | |||
| 3307 | ||||
| 3308 | switch (args->cmd & 0xffff) { | |||
| 3309 | case LINUX_VIDIOC_RESERVED0x5601: | |||
| 3310 | case LINUX_VIDIOC_LOG_STATUS0x5646: | |||
| 3311 | if ((args->cmd & IOC_DIRMASK(0x20000000|0x40000000|0x80000000)) != LINUX_IOC_VOID0) | |||
| 3312 | return (ENOIOCTL(-3)); | |||
| 3313 | args->cmd = (args->cmd & 0xffff) | IOC_VOID0x20000000; | |||
| 3314 | break; | |||
| 3315 | ||||
| 3316 | case LINUX_VIDIOC_OVERLAY0x560e: | |||
| 3317 | case LINUX_VIDIOC_STREAMON0x5612: | |||
| 3318 | case LINUX_VIDIOC_STREAMOFF0x5613: | |||
| 3319 | case LINUX_VIDIOC_S_STD0x5618: | |||
| 3320 | case LINUX_VIDIOC_S_TUNER0x561e: | |||
| 3321 | case LINUX_VIDIOC_S_AUDIO0x5622: | |||
| 3322 | case LINUX_VIDIOC_S_AUDOUT0x5632: | |||
| 3323 | case LINUX_VIDIOC_S_MODULATOR0x5637: | |||
| 3324 | case LINUX_VIDIOC_S_FREQUENCY0x5639: | |||
| 3325 | case LINUX_VIDIOC_S_CROP0x563c: | |||
| 3326 | case LINUX_VIDIOC_S_JPEGCOMP0x563e: | |||
| 3327 | case LINUX_VIDIOC_S_PRIORITY0x5644: | |||
| 3328 | case LINUX_VIDIOC_DBG_S_REGISTER0x564f: | |||
| 3329 | case LINUX_VIDIOC_S_HW_FREQ_SEEK0x5652: | |||
| 3330 | case LINUX_VIDIOC_SUBSCRIBE_EVENT0x565a: | |||
| 3331 | case LINUX_VIDIOC_UNSUBSCRIBE_EVENT0x565b: | |||
| 3332 | args->cmd = (args->cmd & ~IOC_DIRMASK(0x20000000|0x40000000|0x80000000)) | IOC_IN0x80000000; | |||
| 3333 | break; | |||
| 3334 | ||||
| 3335 | case LINUX_VIDIOC_QUERYCAP0x5600: | |||
| 3336 | case LINUX_VIDIOC_G_STD0x5617: | |||
| 3337 | case LINUX_VIDIOC_G_AUDIO0x5621: | |||
| 3338 | case LINUX_VIDIOC_G_INPUT0x5626: | |||
| 3339 | case LINUX_VIDIOC_G_OUTPUT0x562e: | |||
| 3340 | case LINUX_VIDIOC_G_AUDOUT0x5631: | |||
| 3341 | case LINUX_VIDIOC_G_JPEGCOMP0x563d: | |||
| 3342 | case LINUX_VIDIOC_QUERYSTD0x563f: | |||
| 3343 | case LINUX_VIDIOC_G_PRIORITY0x5643: | |||
| 3344 | case LINUX_VIDIOC_QUERY_DV_PRESET0x5656: | |||
| 3345 | args->cmd = (args->cmd & ~IOC_DIRMASK(0x20000000|0x40000000|0x80000000)) | IOC_OUT0x40000000; | |||
| 3346 | break; | |||
| 3347 | ||||
| 3348 | case LINUX_VIDIOC_ENUM_FMT0x5602: | |||
| 3349 | case LINUX_VIDIOC_REQBUFS0x5608: | |||
| 3350 | case LINUX_VIDIOC_G_PARM0x5615: | |||
| 3351 | case LINUX_VIDIOC_S_PARM0x5616: | |||
| 3352 | case LINUX_VIDIOC_G_CTRL0x561b: | |||
| 3353 | case LINUX_VIDIOC_S_CTRL0x561c: | |||
| 3354 | case LINUX_VIDIOC_G_TUNER0x561d: | |||
| 3355 | case LINUX_VIDIOC_QUERYCTRL0x5624: | |||
| 3356 | case LINUX_VIDIOC_QUERYMENU0x5625: | |||
| 3357 | case LINUX_VIDIOC_S_INPUT0x5627: | |||
| 3358 | case LINUX_VIDIOC_S_OUTPUT0x562f: | |||
| 3359 | case LINUX_VIDIOC_ENUMOUTPUT0x5630: | |||
| 3360 | case LINUX_VIDIOC_G_MODULATOR0x5636: | |||
| 3361 | case LINUX_VIDIOC_G_FREQUENCY0x5638: | |||
| 3362 | case LINUX_VIDIOC_CROPCAP0x563a: | |||
| 3363 | case LINUX_VIDIOC_G_CROP0x563b: | |||
| 3364 | case LINUX_VIDIOC_ENUMAUDIO0x5641: | |||
| 3365 | case LINUX_VIDIOC_ENUMAUDOUT0x5642: | |||
| 3366 | case LINUX_VIDIOC_G_SLICED_VBI_CAP0x5645: | |||
| 3367 | #ifdef VIDIOC_ENUM_FRAMESIZES((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct v4l2_frmsizeenum)) & ((1 << 13) - 1)) << 16) | ((('V')) << 8) | ((74)))) | |||
| 3368 | case LINUX_VIDIOC_ENUM_FRAMESIZES0x564a: | |||
| 3369 | case LINUX_VIDIOC_ENUM_FRAMEINTERVALS0x564b: | |||
| 3370 | case LINUX_VIDIOC_ENCODER_CMD0x564d: | |||
| 3371 | case LINUX_VIDIOC_TRY_ENCODER_CMD0x564e: | |||
| 3372 | #endif | |||
| 3373 | case LINUX_VIDIOC_DBG_G_REGISTER0x5650: | |||
| 3374 | case LINUX_VIDIOC_DBG_G_CHIP_IDENT0x5651: | |||
| 3375 | case LINUX_VIDIOC_ENUM_DV_PRESETS0x5653: | |||
| 3376 | case LINUX_VIDIOC_S_DV_PRESET0x5654: | |||
| 3377 | case LINUX_VIDIOC_G_DV_PRESET0x5655: | |||
| 3378 | case LINUX_VIDIOC_S_DV_TIMINGS0x5657: | |||
| 3379 | case LINUX_VIDIOC_G_DV_TIMINGS0x5658: | |||
| 3380 | args->cmd = (args->cmd & ~IOC_DIRMASK(0x20000000|0x40000000|0x80000000)) | IOC_INOUT(0x80000000|0x40000000); | |||
| 3381 | break; | |||
| 3382 | ||||
| 3383 | case LINUX_VIDIOC_G_FMT0x5604: | |||
| 3384 | case LINUX_VIDIOC_S_FMT0x5605: | |||
| 3385 | case LINUX_VIDIOC_TRY_FMT0x5640: | |||
| 3386 | error = copyin((void *)args->arg, &l_vformat, sizeof(l_vformat)); | |||
| 3387 | if (error) | |||
| 3388 | return (error); | |||
| 3389 | error = fget(td, args->fd, | |||
| 3390 | &cap_ioctl_rights, &fp); | |||
| 3391 | if (error) | |||
| 3392 | return (error); | |||
| 3393 | if (linux_to_bsd_v4l2_format(&l_vformat, &vformat) != 0) | |||
| 3394 | error = EINVAL22; | |||
| 3395 | else if ((args->cmd & 0xffff) == LINUX_VIDIOC_G_FMT0x5604) | |||
| 3396 | error = fo_ioctl(fp, VIDIOC_G_FMT((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct v4l2_format)) & ((1 << 13) - 1)) << 16) | (( ('V')) << 8) | ((4)))), &vformat, | |||
| 3397 | td->td_ucred, td); | |||
| 3398 | else if ((args->cmd & 0xffff) == LINUX_VIDIOC_S_FMT0x5605) | |||
| 3399 | error = fo_ioctl(fp, VIDIOC_S_FMT((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct v4l2_format)) & ((1 << 13) - 1)) << 16) | (( ('V')) << 8) | ((5)))), &vformat, | |||
| 3400 | td->td_ucred, td); | |||
| 3401 | else | |||
| 3402 | error = fo_ioctl(fp, VIDIOC_TRY_FMT((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct v4l2_format)) & ((1 << 13) - 1)) << 16) | (( ('V')) << 8) | ((64)))), &vformat, | |||
| 3403 | td->td_ucred, td); | |||
| 3404 | bsd_to_linux_v4l2_format(&vformat, &l_vformat); | |||
| 3405 | copyout(&l_vformat, (void *)args->arg, sizeof(l_vformat)); | |||
| 3406 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3407 | return (error); | |||
| 3408 | ||||
| 3409 | case LINUX_VIDIOC_ENUMSTD0x5619: | |||
| 3410 | error = copyin((void *)args->arg, &l_vstd, sizeof(l_vstd)); | |||
| 3411 | if (error) | |||
| 3412 | return (error); | |||
| 3413 | linux_to_bsd_v4l2_standard(&l_vstd, &vstd); | |||
| 3414 | error = fget(td, args->fd, | |||
| 3415 | &cap_ioctl_rights, &fp); | |||
| 3416 | if (error) | |||
| 3417 | return (error); | |||
| 3418 | error = fo_ioctl(fp, VIDIOC_ENUMSTD((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct v4l2_standard)) & ((1 << 13) - 1)) << 16) | ( (('V')) << 8) | ((25)))), (caddr_t)&vstd, | |||
| 3419 | td->td_ucred, td); | |||
| 3420 | if (error) { | |||
| 3421 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3422 | return (error); | |||
| 3423 | } | |||
| 3424 | bsd_to_linux_v4l2_standard(&vstd, &l_vstd); | |||
| 3425 | error = copyout(&l_vstd, (void *)args->arg, sizeof(l_vstd)); | |||
| 3426 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3427 | return (error); | |||
| 3428 | ||||
| 3429 | case LINUX_VIDIOC_ENUMINPUT0x561a: | |||
| 3430 | /* | |||
| 3431 | * The Linux struct l_v4l2_input differs only in size, | |||
| 3432 | * it has no padding at the end. | |||
| 3433 | */ | |||
| 3434 | error = copyin((void *)args->arg, &vinp, | |||
| 3435 | sizeof(struct l_v4l2_input)); | |||
| 3436 | if (error != 0) | |||
| 3437 | return (error); | |||
| 3438 | error = fget(td, args->fd, | |||
| 3439 | &cap_ioctl_rights, &fp); | |||
| 3440 | if (error != 0) | |||
| 3441 | return (error); | |||
| 3442 | error = fo_ioctl(fp, VIDIOC_ENUMINPUT((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct v4l2_input)) & ((1 << 13) - 1)) << 16) | ((( 'V')) << 8) | ((26)))), (caddr_t)&vinp, | |||
| 3443 | td->td_ucred, td); | |||
| 3444 | if (error) { | |||
| 3445 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3446 | return (error); | |||
| 3447 | } | |||
| 3448 | error = copyout(&vinp, (void *)args->arg, | |||
| 3449 | sizeof(struct l_v4l2_input)); | |||
| 3450 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3451 | return (error); | |||
| 3452 | ||||
| 3453 | case LINUX_VIDIOC_QUERYBUF0x5609: | |||
| 3454 | case LINUX_VIDIOC_QBUF0x560f: | |||
| 3455 | case LINUX_VIDIOC_DQBUF0x5611: | |||
| 3456 | error = copyin((void *)args->arg, &l_vbuf, sizeof(l_vbuf)); | |||
| 3457 | if (error) | |||
| 3458 | return (error); | |||
| 3459 | error = fget(td, args->fd, | |||
| 3460 | &cap_ioctl_rights, &fp); | |||
| 3461 | if (error) | |||
| 3462 | return (error); | |||
| 3463 | linux_to_bsd_v4l2_buffer(&l_vbuf, &vbuf); | |||
| 3464 | if ((args->cmd & 0xffff) == LINUX_VIDIOC_QUERYBUF0x5609) | |||
| 3465 | error = fo_ioctl(fp, VIDIOC_QUERYBUF((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct v4l2_buffer)) & ((1 << 13) - 1)) << 16) | (( ('V')) << 8) | ((9)))), &vbuf, | |||
| 3466 | td->td_ucred, td); | |||
| 3467 | else if ((args->cmd & 0xffff) == LINUX_VIDIOC_QBUF0x560f) | |||
| 3468 | error = fo_ioctl(fp, VIDIOC_QBUF((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct v4l2_buffer)) & ((1 << 13) - 1)) << 16) | (( ('V')) << 8) | ((15)))), &vbuf, | |||
| 3469 | td->td_ucred, td); | |||
| 3470 | else | |||
| 3471 | error = fo_ioctl(fp, VIDIOC_DQBUF((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct v4l2_buffer)) & ((1 << 13) - 1)) << 16) | (( ('V')) << 8) | ((17)))), &vbuf, | |||
| 3472 | td->td_ucred, td); | |||
| 3473 | bsd_to_linux_v4l2_buffer(&vbuf, &l_vbuf); | |||
| 3474 | copyout(&l_vbuf, (void *)args->arg, sizeof(l_vbuf)); | |||
| 3475 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3476 | return (error); | |||
| 3477 | ||||
| 3478 | /* | |||
| 3479 | * XXX TODO - these need 32 -> 64 bit conversion: | |||
| 3480 | * (are any of them needed for webcams?) | |||
| 3481 | */ | |||
| 3482 | case LINUX_VIDIOC_G_FBUF0x560a: | |||
| 3483 | case LINUX_VIDIOC_S_FBUF0x560b: | |||
| 3484 | ||||
| 3485 | case LINUX_VIDIOC_G_EXT_CTRLS0x5647: | |||
| 3486 | case LINUX_VIDIOC_S_EXT_CTRLS0x5648: | |||
| 3487 | case LINUX_VIDIOC_TRY_EXT_CTRLS0x5649: | |||
| 3488 | ||||
| 3489 | case LINUX_VIDIOC_DQEVENT0x5659: | |||
| 3490 | ||||
| 3491 | default: return (ENOIOCTL(-3)); | |||
| 3492 | } | |||
| 3493 | ||||
| 3494 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 3495 | return (error); | |||
| 3496 | } | |||
| 3497 | ||||
| 3498 | /* | |||
| 3499 | * Support for emulators/linux-libusb. This port uses FBSD_LUSB* macros | |||
| 3500 | * instead of USB* ones. This lets us to provide correct values for cmd. | |||
| 3501 | * 0xffffffe0 -- 0xffffffff range seemed to be the least collision-prone. | |||
| 3502 | */ | |||
| 3503 | static int | |||
| 3504 | linux_ioctl_fbsd_usb(struct thread *td, struct linux_ioctl_args *args) | |||
| 3505 | { | |||
| 3506 | int error; | |||
| 3507 | ||||
| 3508 | error = 0; | |||
| 3509 | switch (args->cmd) { | |||
| 3510 | case FBSD_LUSB_DEVICEENUMERATE0xffff: | |||
| 3511 | args->cmd = USB_DEVICEENUMERATE((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((6)))); | |||
| 3512 | break; | |||
| 3513 | case FBSD_LUSB_DEV_QUIRK_ADD0xfffe: | |||
| 3514 | args->cmd = USB_DEV_QUIRK_ADD((unsigned long) ((0x80000000) | (((sizeof(struct usb_gen_quirk )) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((2)))); | |||
| 3515 | break; | |||
| 3516 | case FBSD_LUSB_DEV_QUIRK_GET0xfffd: | |||
| 3517 | args->cmd = USB_DEV_QUIRK_GET((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct usb_gen_quirk)) & ((1 << 13) - 1)) << 16) | ( (('Q')) << 8) | ((0)))); | |||
| 3518 | break; | |||
| 3519 | case FBSD_LUSB_DEV_QUIRK_REMOVE0xfffc: | |||
| 3520 | args->cmd = USB_DEV_QUIRK_REMOVE((unsigned long) ((0x80000000) | (((sizeof(struct usb_gen_quirk )) & ((1 << 13) - 1)) << 16) | ((('Q')) << 8) | ((3)))); | |||
| 3521 | break; | |||
| 3522 | case FBSD_LUSB_DO_REQUEST0xfffb: | |||
| 3523 | args->cmd = USB_DO_REQUEST((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct usb_ctl_request)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((111)))); | |||
| 3524 | break; | |||
| 3525 | case FBSD_LUSB_FS_CLEAR_STALL_SYNC0xfffa: | |||
| 3526 | args->cmd = USB_FS_CLEAR_STALL_SYNC((unsigned long) ((0x80000000) | (((sizeof(struct usb_fs_clear_stall_sync )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((199)))); | |||
| 3527 | break; | |||
| 3528 | case FBSD_LUSB_FS_CLOSE0xfff9: | |||
| 3529 | args->cmd = USB_FS_CLOSE((unsigned long) ((0x80000000) | (((sizeof(struct usb_fs_close )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((198)))); | |||
| 3530 | break; | |||
| 3531 | case FBSD_LUSB_FS_COMPLETE0xfff8: | |||
| 3532 | args->cmd = USB_FS_COMPLETE((unsigned long) ((0x40000000) | (((sizeof(struct usb_fs_complete )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((194)))); | |||
| 3533 | break; | |||
| 3534 | case FBSD_LUSB_FS_INIT0xfff7: | |||
| 3535 | args->cmd = USB_FS_INIT((unsigned long) ((0x80000000) | (((sizeof(struct usb_fs_init )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((195)))); | |||
| 3536 | break; | |||
| 3537 | case FBSD_LUSB_FS_OPEN0xfff6: | |||
| 3538 | args->cmd = USB_FS_OPEN((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct usb_fs_open)) & ((1 << 13) - 1)) << 16) | (( ('U')) << 8) | ((197)))); | |||
| 3539 | break; | |||
| 3540 | case FBSD_LUSB_FS_START0xfff5: | |||
| 3541 | args->cmd = USB_FS_START((unsigned long) ((0x80000000) | (((sizeof(struct usb_fs_start )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((192)))); | |||
| 3542 | break; | |||
| 3543 | case FBSD_LUSB_FS_STOP0xfff4: | |||
| 3544 | args->cmd = USB_FS_STOP((unsigned long) ((0x80000000) | (((sizeof(struct usb_fs_stop )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((193)))); | |||
| 3545 | break; | |||
| 3546 | case FBSD_LUSB_FS_UNINIT0xfff3: | |||
| 3547 | args->cmd = USB_FS_UNINIT((unsigned long) ((0x80000000) | (((sizeof(struct usb_fs_uninit )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((196)))); | |||
| 3548 | break; | |||
| 3549 | case FBSD_LUSB_GET_CONFIG0xfff2: | |||
| 3550 | args->cmd = USB_GET_CONFIG((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((100)))); | |||
| 3551 | break; | |||
| 3552 | case FBSD_LUSB_GET_DEVICEINFO0xfff1: | |||
| 3553 | args->cmd = USB_GET_DEVICEINFO((unsigned long) ((0x40000000) | (((sizeof(struct usb_device_info )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((112)))); | |||
| 3554 | break; | |||
| 3555 | case FBSD_LUSB_GET_DEVICE_DESC0xfff0: | |||
| 3556 | args->cmd = USB_GET_DEVICE_DESC((unsigned long) ((0x40000000) | (((sizeof(struct usb_device_descriptor )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((105)))); | |||
| 3557 | break; | |||
| 3558 | case FBSD_LUSB_GET_FULL_DESC0xffef: | |||
| 3559 | args->cmd = USB_GET_FULL_DESC((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct usb_gen_descriptor)) & ((1 << 13) - 1)) << 16 ) | ((('U')) << 8) | ((109)))); | |||
| 3560 | break; | |||
| 3561 | case FBSD_LUSB_GET_IFACE_DRIVER0xffee: | |||
| 3562 | args->cmd = USB_GET_IFACE_DRIVER((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct usb_gen_descriptor)) & ((1 << 13) - 1)) << 16 ) | ((('U')) << 8) | ((121)))); | |||
| 3563 | break; | |||
| 3564 | case FBSD_LUSB_GET_PLUGTIME0xffed: | |||
| 3565 | args->cmd = USB_GET_PLUGTIME((unsigned long) ((0x40000000) | (((sizeof(uint32_t)) & ( (1 << 13) - 1)) << 16) | ((('U')) << 8) | ( (126)))); | |||
| 3566 | break; | |||
| 3567 | case FBSD_LUSB_GET_POWER_MODE0xffec: | |||
| 3568 | args->cmd = USB_GET_POWER_MODE((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((146)))); | |||
| 3569 | break; | |||
| 3570 | case FBSD_LUSB_GET_REPORT_DESC0xffeb: | |||
| 3571 | args->cmd = USB_GET_REPORT_DESC((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct usb_gen_descriptor)) & ((1 << 13) - 1)) << 16 ) | ((('U')) << 8) | ((21)))); | |||
| 3572 | break; | |||
| 3573 | case FBSD_LUSB_GET_REPORT_ID0xffea: | |||
| 3574 | args->cmd = USB_GET_REPORT_ID((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((25)))); | |||
| 3575 | break; | |||
| 3576 | case FBSD_LUSB_GET_TEMPLATE0xffe9: | |||
| 3577 | args->cmd = USB_GET_TEMPLATE((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((148)))); | |||
| 3578 | break; | |||
| 3579 | case FBSD_LUSB_IFACE_DRIVER_ACTIVE0xffe8: | |||
| 3580 | args->cmd = USB_IFACE_DRIVER_ACTIVE((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((124)))); | |||
| 3581 | break; | |||
| 3582 | case FBSD_LUSB_IFACE_DRIVER_DETACH0xffe7: | |||
| 3583 | args->cmd = USB_IFACE_DRIVER_DETACH((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((125)))); | |||
| 3584 | break; | |||
| 3585 | case FBSD_LUSB_QUIRK_NAME_GET0xffe6: | |||
| 3586 | args->cmd = USB_QUIRK_NAME_GET((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct usb_gen_quirk)) & ((1 << 13) - 1)) << 16) | ( (('Q')) << 8) | ((1)))); | |||
| 3587 | break; | |||
| 3588 | case FBSD_LUSB_READ_DIR0xffe5: | |||
| 3589 | args->cmd = USB_READ_DIR((unsigned long) ((0x80000000) | (((sizeof(struct usb_read_dir )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((127)))); | |||
| 3590 | break; | |||
| 3591 | case FBSD_LUSB_SET_ALTINTERFACE0xffe4: | |||
| 3592 | args->cmd = USB_SET_ALTINTERFACE((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct usb_alt_interface)) & ((1 << 13) - 1)) << 16 ) | ((('U')) << 8) | ((103)))); | |||
| 3593 | break; | |||
| 3594 | case FBSD_LUSB_SET_CONFIG0xffe3: | |||
| 3595 | args->cmd = USB_SET_CONFIG((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((101)))); | |||
| 3596 | break; | |||
| 3597 | case FBSD_LUSB_SET_IMMED0xffe2: | |||
| 3598 | args->cmd = USB_SET_IMMED((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((22)))); | |||
| 3599 | break; | |||
| 3600 | case FBSD_LUSB_SET_POWER_MODE0xffe1: | |||
| 3601 | args->cmd = USB_SET_POWER_MODE((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((145)))); | |||
| 3602 | break; | |||
| 3603 | case FBSD_LUSB_SET_TEMPLATE0xffe0: | |||
| 3604 | args->cmd = USB_SET_TEMPLATE((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((147)))); | |||
| 3605 | break; | |||
| 3606 | case FBSD_LUSB_FS_OPEN_STREAM0xffdf: | |||
| 3607 | args->cmd = USB_FS_OPEN_STREAM((unsigned long) (((0x80000000|0x40000000)) | (((sizeof(struct usb_fs_open_stream)) & ((1 << 13) - 1)) << 16 ) | ((('U')) << 8) | ((200)))); | |||
| 3608 | break; | |||
| 3609 | case FBSD_LUSB_GET_DEV_PORT_PATH0xffde: | |||
| 3610 | args->cmd = USB_GET_DEV_PORT_PATH((unsigned long) ((0x40000000) | (((sizeof(struct usb_device_port_path )) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((134)))); | |||
| 3611 | break; | |||
| 3612 | case FBSD_LUSB_GET_POWER_USAGE0xffdd: | |||
| 3613 | args->cmd = USB_GET_POWER_USAGE((unsigned long) ((0x40000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('U')) << 8) | ((135)))); | |||
| 3614 | break; | |||
| 3615 | default: | |||
| 3616 | error = ENOIOCTL(-3); | |||
| 3617 | } | |||
| 3618 | if (error != ENOIOCTL(-3)) | |||
| 3619 | error = sys_ioctl(td, (struct ioctl_args *)args); | |||
| 3620 | return (error); | |||
| 3621 | } | |||
| 3622 | ||||
| 3623 | /* | |||
| 3624 | * Some evdev ioctls must be translated. | |||
| 3625 | * - EVIOCGMTSLOTS is a IOC_READ ioctl on Linux although it has input data | |||
| 3626 | * (must be IOC_INOUT on FreeBSD). | |||
| 3627 | * - On Linux, EVIOCGRAB, EVIOCREVOKE and EVIOCRMFF are defined as _IOW with | |||
| 3628 | * an int argument. You don't pass an int pointer to the ioctl(), however, | |||
| 3629 | * but just the int directly. On FreeBSD, they are defined as _IOWINT for | |||
| 3630 | * this to work. | |||
| 3631 | */ | |||
| 3632 | static int | |||
| 3633 | linux_ioctl_evdev(struct thread *td, struct linux_ioctl_args *args) | |||
| 3634 | { | |||
| 3635 | struct file *fp; | |||
| 3636 | clockid_t clock; | |||
| 3637 | int error; | |||
| 3638 | ||||
| 3639 | args->cmd = SETDIR(args->cmd)(((args->cmd) & ~(0x20000000|0x40000000|0x80000000)) | dirbits[args->cmd >> 30]); | |||
| 3640 | ||||
| 3641 | switch (args->cmd) { | |||
| 3642 | case (EVIOCGRAB((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('E')) << 8) | ((0x90)))) & ~IOC_DIRMASK(0x20000000|0x40000000|0x80000000)) | IOC_IN0x80000000: | |||
| 3643 | args->cmd = EVIOCGRAB((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('E')) << 8) | ((0x90)))); | |||
| 3644 | break; | |||
| 3645 | case (EVIOCREVOKE((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('E')) << 8) | ((0x91)))) & ~IOC_DIRMASK(0x20000000|0x40000000|0x80000000)) | IOC_IN0x80000000: | |||
| 3646 | args->cmd = EVIOCREVOKE((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('E')) << 8) | ((0x91)))); | |||
| 3647 | break; | |||
| 3648 | case (EVIOCRMFF((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('E')) << 8) | ((0x81)))) & ~IOC_DIRMASK(0x20000000|0x40000000|0x80000000)) | IOC_IN0x80000000: | |||
| 3649 | args->cmd = EVIOCRMFF((unsigned long) ((0x20000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('E')) << 8) | ((0x81)))); | |||
| 3650 | break; | |||
| 3651 | case EVIOCSCLOCKID((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('E')) << 8) | ((0xa0)))): { | |||
| 3652 | error = copyin(PTRIN(args->arg)(void *)(args->arg), &clock, sizeof(clock)); | |||
| 3653 | if (error != 0) | |||
| 3654 | return (error); | |||
| 3655 | if (clock & ~(LINUX_IOCTL_EVDEV_CLK0 | 1 |7)) | |||
| 3656 | return (EINVAL22); | |||
| 3657 | error = linux_to_native_clockid(&clock, clock); | |||
| 3658 | if (error != 0) | |||
| 3659 | return (error); | |||
| 3660 | ||||
| 3661 | error = fget(td, args->fd, | |||
| 3662 | &cap_ioctl_rights, &fp); | |||
| 3663 | if (error != 0) | |||
| 3664 | return (error); | |||
| 3665 | ||||
| 3666 | error = fo_ioctl(fp, EVIOCSCLOCKID((unsigned long) ((0x80000000) | (((sizeof(int)) & ((1 << 13) - 1)) << 16) | ((('E')) << 8) | ((0xa0)))), &clock, td->td_ucred, td); | |||
| 3667 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3668 | return (error); | |||
| 3669 | } | |||
| 3670 | default: | |||
| 3671 | break; | |||
| 3672 | } | |||
| 3673 | ||||
| 3674 | if (IOCBASECMD(args->cmd)((args->cmd) & ~(((1 << 13) - 1) << 16)) == | |||
| 3675 | ((EVIOCGMTSLOTS(0)((unsigned long) (((0x80000000|0x40000000)) | (((0) & ((1 << 13) - 1)) << 16) | (('E') << 8) | (0x0a ))) & ~IOC_DIRMASK(0x20000000|0x40000000|0x80000000)) | IOC_OUT0x40000000)) | |||
| 3676 | args->cmd = (args->cmd & ~IOC_DIRMASK(0x20000000|0x40000000|0x80000000)) | IOC_INOUT(0x80000000|0x40000000); | |||
| 3677 | ||||
| 3678 | return (sys_ioctl(td, (struct ioctl_args *)args)); | |||
| 3679 | } | |||
| 3680 | ||||
| 3681 | /* | |||
| 3682 | * main ioctl syscall function | |||
| 3683 | */ | |||
| 3684 | ||||
| 3685 | int | |||
| 3686 | linux_ioctl(struct thread *td, struct linux_ioctl_args *args) | |||
| 3687 | { | |||
| 3688 | struct file *fp; | |||
| 3689 | struct linux_ioctl_handler_element *he; | |||
| 3690 | int error, cmd; | |||
| 3691 | ||||
| 3692 | #ifdef DEBUG | |||
| 3693 | if (ldebug(ioctl)((((const unsigned char *)(linux_debug_map))[(16)/8] & (1 <<((16)%8))) == 0)) | |||
| 3694 | printf(ARGS(ioctl, "%d, %04lx, *")"linux(%ld/%ld): ""ioctl""(""%d, %04lx, *"")\n", (long)td-> td_proc->p_pid, (long)td->td_tid, args->fd, | |||
| 3695 | (unsigned long)args->cmd); | |||
| 3696 | #endif | |||
| 3697 | ||||
| 3698 | error = fget(td, args->fd, &cap_ioctl_rights, &fp); | |||
| 3699 | if (error != 0) | |||
| 3700 | return (error); | |||
| 3701 | if ((fp->f_flag & (FREAD0x0001|FWRITE0x0002)) == 0) { | |||
| 3702 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3703 | return (EBADF9); | |||
| 3704 | } | |||
| 3705 | ||||
| 3706 | /* Iterate over the ioctl handlers */ | |||
| 3707 | cmd = args->cmd & 0xffff; | |||
| 3708 | sx_slock(&linux_ioctl_sx)(void)_sx_slock(((&linux_ioctl_sx)), 0, ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3708)); | |||
| 3709 | mtx_lock(&Giant)__mtx_lock_flags(&((((&Giant))))->mtx_lock, ((0)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c"), (3709)); | |||
| 3710 | #ifdef COMPAT_LINUX32 | |||
| 3711 | TAILQ_FOREACH(he, &linux32_ioctl_handlers, list)for ((he) = (((&linux32_ioctl_handlers))->tqh_first); ( he); (he) = (((he))->list.tqe_next)) { | |||
| 3712 | if (cmd >= he->low && cmd <= he->high) { | |||
| 3713 | error = (*he->func)(td, args); | |||
| 3714 | if (error != ENOIOCTL(-3)) { | |||
| 3715 | mtx_unlock(&Giant)__mtx_unlock_flags(&((((&Giant))))->mtx_lock, ((0) ), ("/root/freebsd/sys/compat/linux/linux_ioctl.c"), (3715)); | |||
| 3716 | sx_sunlock(&linux_ioctl_sx)_sx_sunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3716)); | |||
| 3717 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3718 | return (error); | |||
| 3719 | } | |||
| 3720 | } | |||
| 3721 | } | |||
| 3722 | #endif | |||
| 3723 | TAILQ_FOREACH(he, &linux_ioctl_handlers, list)for ((he) = (((&linux_ioctl_handlers))->tqh_first); (he ); (he) = (((he))->list.tqe_next)) { | |||
| 3724 | if (cmd >= he->low && cmd <= he->high) { | |||
| 3725 | error = (*he->func)(td, args); | |||
| 3726 | if (error != ENOIOCTL(-3)) { | |||
| 3727 | mtx_unlock(&Giant)__mtx_unlock_flags(&((((&Giant))))->mtx_lock, ((0) ), ("/root/freebsd/sys/compat/linux/linux_ioctl.c"), (3727)); | |||
| 3728 | sx_sunlock(&linux_ioctl_sx)_sx_sunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3728)); | |||
| 3729 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3730 | return (error); | |||
| 3731 | } | |||
| 3732 | } | |||
| 3733 | } | |||
| 3734 | mtx_unlock(&Giant)__mtx_unlock_flags(&((((&Giant))))->mtx_lock, ((0) ), ("/root/freebsd/sys/compat/linux/linux_ioctl.c"), (3734)); | |||
| 3735 | sx_sunlock(&linux_ioctl_sx)_sx_sunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3735)); | |||
| 3736 | fdrop(fp, td)(refcount_release(&(fp)->f_count) ? _fdrop((fp), (td)) : _fnoop()); | |||
| 3737 | ||||
| 3738 | switch (args->cmd & 0xffff) { | |||
| 3739 | case LINUX_BTRFS_IOC_CLONE0x9409: | |||
| 3740 | return (ENOTSUP45); | |||
| 3741 | ||||
| 3742 | default: | |||
| 3743 | linux_msg(td, "ioctl fd=%d, cmd=0x%x ('%c',%d) is not implemented", | |||
| 3744 | args->fd, (int)(args->cmd & 0xffff), | |||
| 3745 | (int)(args->cmd & 0xff00) >> 8, (int)(args->cmd & 0xff)); | |||
| 3746 | break; | |||
| 3747 | } | |||
| 3748 | ||||
| 3749 | return (EINVAL22); | |||
| 3750 | } | |||
| 3751 | ||||
| 3752 | int | |||
| 3753 | linux_ioctl_register_handler(struct linux_ioctl_handler *h) | |||
| 3754 | { | |||
| 3755 | struct linux_ioctl_handler_element *he, *cur; | |||
| 3756 | ||||
| 3757 | if (h == NULL((void *)0) || h->func == NULL((void *)0)) | |||
| 3758 | return (EINVAL22); | |||
| 3759 | ||||
| 3760 | /* | |||
| 3761 | * Reuse the element if the handler is already on the list, otherwise | |||
| 3762 | * create a new element. | |||
| 3763 | */ | |||
| 3764 | sx_xlock(&linux_ioctl_sx)(void)_sx_xlock(((&linux_ioctl_sx)), 0, ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3764)); | |||
| 3765 | TAILQ_FOREACH(he, &linux_ioctl_handlers, list)for ((he) = (((&linux_ioctl_handlers))->tqh_first); (he ); (he) = (((he))->list.tqe_next)) { | |||
| 3766 | if (he->func == h->func) | |||
| 3767 | break; | |||
| 3768 | } | |||
| 3769 | if (he == NULL((void *)0)) { | |||
| 3770 | he = malloc(sizeof(*he), | |||
| 3771 | M_LINUX, M_WAITOK0x0002); | |||
| 3772 | he->func = h->func; | |||
| 3773 | } else | |||
| 3774 | TAILQ_REMOVE(&linux_ioctl_handlers, he, list)do { ; ; do { if ((((he))->list.tqe_next) != ((void *)0) && (((he))->list.tqe_next)->list.tqe_prev != &((he)-> list.tqe_next)) panic("Bad link elm %p next->prev != elm", (he)); } while (0); do { if (*(he)->list.tqe_prev != (he) ) panic("Bad link elm %p prev->next != elm", (he)); } while (0); if (((((he))->list.tqe_next)) != ((void *)0)) (((he) )->list.tqe_next)->list.tqe_prev = (he)->list.tqe_prev ; else { (&linux_ioctl_handlers)->tqh_last = (he)-> list.tqe_prev; ; } *(he)->list.tqe_prev = (((he))->list .tqe_next); ; ; ; } while (0); | |||
| 3775 | ||||
| 3776 | /* Initialize range information. */ | |||
| 3777 | he->low = h->low; | |||
| 3778 | he->high = h->high; | |||
| 3779 | he->span = h->high - h->low + 1; | |||
| 3780 | ||||
| 3781 | /* Add the element to the list, sorted on span. */ | |||
| 3782 | TAILQ_FOREACH(cur, &linux_ioctl_handlers, list)for ((cur) = (((&linux_ioctl_handlers))->tqh_first); ( cur); (cur) = (((cur))->list.tqe_next)) { | |||
| 3783 | if (cur->span > he->span) { | |||
| 3784 | TAILQ_INSERT_BEFORE(cur, he, list)do { do { if (*(cur)->list.tqe_prev != (cur)) panic("Bad link elm %p prev->next != elm" , (cur)); } while (0); (he)->list.tqe_prev = (cur)->list .tqe_prev; (((he))->list.tqe_next) = (cur); *(cur)->list .tqe_prev = (he); (cur)->list.tqe_prev = &(((he))-> list.tqe_next); ; ; } while (0); | |||
| 3785 | sx_xunlock(&linux_ioctl_sx)_sx_xunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3785)); | |||
| 3786 | return (0); | |||
| 3787 | } | |||
| 3788 | } | |||
| 3789 | TAILQ_INSERT_TAIL(&linux_ioctl_handlers, he, list)do { do { if (*(&linux_ioctl_handlers)->tqh_last != (( void *)0)) panic("Bad tailq NEXT(%p->tqh_last) != NULL", ( &linux_ioctl_handlers)); } while (0); (((he))->list.tqe_next ) = ((void *)0); (he)->list.tqe_prev = (&linux_ioctl_handlers )->tqh_last; *(&linux_ioctl_handlers)->tqh_last = ( he); (&linux_ioctl_handlers)->tqh_last = &(((he))-> list.tqe_next); ; ; } while (0); | |||
| 3790 | sx_xunlock(&linux_ioctl_sx)_sx_xunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3790)); | |||
| 3791 | ||||
| 3792 | return (0); | |||
| 3793 | } | |||
| 3794 | ||||
| 3795 | int | |||
| 3796 | linux_ioctl_unregister_handler(struct linux_ioctl_handler *h) | |||
| 3797 | { | |||
| 3798 | struct linux_ioctl_handler_element *he; | |||
| 3799 | ||||
| 3800 | if (h == NULL((void *)0) || h->func == NULL((void *)0)) | |||
| 3801 | return (EINVAL22); | |||
| 3802 | ||||
| 3803 | sx_xlock(&linux_ioctl_sx)(void)_sx_xlock(((&linux_ioctl_sx)), 0, ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3803)); | |||
| 3804 | TAILQ_FOREACH(he, &linux_ioctl_handlers, list)for ((he) = (((&linux_ioctl_handlers))->tqh_first); (he ); (he) = (((he))->list.tqe_next)) { | |||
| 3805 | if (he->func == h->func) { | |||
| 3806 | TAILQ_REMOVE(&linux_ioctl_handlers, he, list)do { ; ; do { if ((((he))->list.tqe_next) != ((void *)0) && (((he))->list.tqe_next)->list.tqe_prev != &((he)-> list.tqe_next)) panic("Bad link elm %p next->prev != elm", (he)); } while (0); do { if (*(he)->list.tqe_prev != (he) ) panic("Bad link elm %p prev->next != elm", (he)); } while (0); if (((((he))->list.tqe_next)) != ((void *)0)) (((he) )->list.tqe_next)->list.tqe_prev = (he)->list.tqe_prev ; else { (&linux_ioctl_handlers)->tqh_last = (he)-> list.tqe_prev; ; } *(he)->list.tqe_prev = (((he))->list .tqe_next); ; ; ; } while (0); | |||
| 3807 | sx_xunlock(&linux_ioctl_sx)_sx_xunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3807)); | |||
| 3808 | free(he, M_LINUX); | |||
| 3809 | return (0); | |||
| 3810 | } | |||
| 3811 | } | |||
| 3812 | sx_xunlock(&linux_ioctl_sx)_sx_xunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3812)); | |||
| 3813 | ||||
| 3814 | return (EINVAL22); | |||
| 3815 | } | |||
| 3816 | ||||
| 3817 | #ifdef COMPAT_LINUX32 | |||
| 3818 | int | |||
| 3819 | linux32_ioctl_register_handler(struct linux_ioctl_handler *h) | |||
| 3820 | { | |||
| 3821 | struct linux_ioctl_handler_element *he, *cur; | |||
| 3822 | ||||
| 3823 | if (h == NULL((void *)0) || h->func == NULL((void *)0)) | |||
| 3824 | return (EINVAL22); | |||
| 3825 | ||||
| 3826 | /* | |||
| 3827 | * Reuse the element if the handler is already on the list, otherwise | |||
| 3828 | * create a new element. | |||
| 3829 | */ | |||
| 3830 | sx_xlock(&linux_ioctl_sx)(void)_sx_xlock(((&linux_ioctl_sx)), 0, ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3830)); | |||
| 3831 | TAILQ_FOREACH(he, &linux32_ioctl_handlers, list)for ((he) = (((&linux32_ioctl_handlers))->tqh_first); ( he); (he) = (((he))->list.tqe_next)) { | |||
| 3832 | if (he->func == h->func) | |||
| 3833 | break; | |||
| 3834 | } | |||
| 3835 | if (he == NULL((void *)0)) { | |||
| 3836 | he = malloc(sizeof(*he), M_LINUX, M_WAITOK0x0002); | |||
| 3837 | he->func = h->func; | |||
| 3838 | } else | |||
| 3839 | TAILQ_REMOVE(&linux32_ioctl_handlers, he, list)do { ; ; do { if ((((he))->list.tqe_next) != ((void *)0) && (((he))->list.tqe_next)->list.tqe_prev != &((he)-> list.tqe_next)) panic("Bad link elm %p next->prev != elm", (he)); } while (0); do { if (*(he)->list.tqe_prev != (he) ) panic("Bad link elm %p prev->next != elm", (he)); } while (0); if (((((he))->list.tqe_next)) != ((void *)0)) (((he) )->list.tqe_next)->list.tqe_prev = (he)->list.tqe_prev ; else { (&linux32_ioctl_handlers)->tqh_last = (he)-> list.tqe_prev; ; } *(he)->list.tqe_prev = (((he))->list .tqe_next); ; ; ; } while (0); | |||
| 3840 | ||||
| 3841 | /* Initialize range information. */ | |||
| 3842 | he->low = h->low; | |||
| 3843 | he->high = h->high; | |||
| 3844 | he->span = h->high - h->low + 1; | |||
| 3845 | ||||
| 3846 | /* Add the element to the list, sorted on span. */ | |||
| 3847 | TAILQ_FOREACH(cur, &linux32_ioctl_handlers, list)for ((cur) = (((&linux32_ioctl_handlers))->tqh_first); (cur); (cur) = (((cur))->list.tqe_next)) { | |||
| 3848 | if (cur->span > he->span) { | |||
| 3849 | TAILQ_INSERT_BEFORE(cur, he, list)do { do { if (*(cur)->list.tqe_prev != (cur)) panic("Bad link elm %p prev->next != elm" , (cur)); } while (0); (he)->list.tqe_prev = (cur)->list .tqe_prev; (((he))->list.tqe_next) = (cur); *(cur)->list .tqe_prev = (he); (cur)->list.tqe_prev = &(((he))-> list.tqe_next); ; ; } while (0); | |||
| 3850 | sx_xunlock(&linux_ioctl_sx)_sx_xunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3850)); | |||
| 3851 | return (0); | |||
| 3852 | } | |||
| 3853 | } | |||
| 3854 | TAILQ_INSERT_TAIL(&linux32_ioctl_handlers, he, list)do { do { if (*(&linux32_ioctl_handlers)->tqh_last != ( (void *)0)) panic("Bad tailq NEXT(%p->tqh_last) != NULL", ( &linux32_ioctl_handlers)); } while (0); (((he))->list. tqe_next) = ((void *)0); (he)->list.tqe_prev = (&linux32_ioctl_handlers )->tqh_last; *(&linux32_ioctl_handlers)->tqh_last = (he); (&linux32_ioctl_handlers)->tqh_last = &(((he ))->list.tqe_next); ; ; } while (0); | |||
| 3855 | sx_xunlock(&linux_ioctl_sx)_sx_xunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3855)); | |||
| 3856 | ||||
| 3857 | return (0); | |||
| 3858 | } | |||
| 3859 | ||||
| 3860 | int | |||
| 3861 | linux32_ioctl_unregister_handler(struct linux_ioctl_handler *h) | |||
| 3862 | { | |||
| 3863 | struct linux_ioctl_handler_element *he; | |||
| 3864 | ||||
| 3865 | if (h == NULL((void *)0) || h->func == NULL((void *)0)) | |||
| 3866 | return (EINVAL22); | |||
| 3867 | ||||
| 3868 | sx_xlock(&linux_ioctl_sx)(void)_sx_xlock(((&linux_ioctl_sx)), 0, ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3868)); | |||
| 3869 | TAILQ_FOREACH(he, &linux32_ioctl_handlers, list)for ((he) = (((&linux32_ioctl_handlers))->tqh_first); ( he); (he) = (((he))->list.tqe_next)) { | |||
| 3870 | if (he->func == h->func) { | |||
| 3871 | TAILQ_REMOVE(&linux32_ioctl_handlers, he, list)do { ; ; do { if ((((he))->list.tqe_next) != ((void *)0) && (((he))->list.tqe_next)->list.tqe_prev != &((he)-> list.tqe_next)) panic("Bad link elm %p next->prev != elm", (he)); } while (0); do { if (*(he)->list.tqe_prev != (he) ) panic("Bad link elm %p prev->next != elm", (he)); } while (0); if (((((he))->list.tqe_next)) != ((void *)0)) (((he) )->list.tqe_next)->list.tqe_prev = (he)->list.tqe_prev ; else { (&linux32_ioctl_handlers)->tqh_last = (he)-> list.tqe_prev; ; } *(he)->list.tqe_prev = (((he))->list .tqe_next); ; ; ; } while (0); | |||
| 3872 | sx_xunlock(&linux_ioctl_sx)_sx_xunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3872)); | |||
| 3873 | free(he, M_LINUX); | |||
| 3874 | return (0); | |||
| 3875 | } | |||
| 3876 | } | |||
| 3877 | sx_xunlock(&linux_ioctl_sx)_sx_xunlock(((&linux_ioctl_sx)), ("/root/freebsd/sys/compat/linux/linux_ioctl.c" ), (3877)); | |||
| 3878 | ||||
| 3879 | return (EINVAL22); | |||
| 3880 | } | |||
| 3881 | #endif |