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