1 /* $NetBSD: linux_ioctl.c,v 1.54 2008/04/28 20:23:43 martin Exp $ */
4 * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank van der Linden and Eric Haszlakiewicz.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: linux_ioctl.c,v 1.54 2008/04/28 20:23:43 martin Exp $");
35 #if defined(_KERNEL_OPT)
36 #include "sequencer.h"
39 #include <sys/param.h>
41 #include <sys/systm.h>
43 #include <sys/ioctl.h>
44 #include <sys/mount.h>
46 #include <sys/vnode.h>
47 #include <sys/filedesc.h>
49 #include <sys/socket.h>
51 #include <sys/sockio.h>
53 #include <sys/syscallargs.h>
55 #include <compat/linux/common/linux_types.h>
56 #include <compat/linux/common/linux_signal.h>
57 #include <compat/linux/common/linux_ioctl.h>
58 #include <compat/linux/common/linux_ipc.h>
59 #include <compat/linux/common/linux_sem.h>
61 #include <compat/linux/linux_syscallargs.h>
63 #include <compat/ossaudio/ossaudio.h>
64 #define LINUX_TO_OSS(v) ((const void *)(v)) /* do nothing, same ioctl() encoding */
67 * Most ioctl command are just converted to their NetBSD values,
68 * and passed on. The ones that take structure pointers and (flag)
69 * values need some massaging.
72 linux_sys_ioctl(struct lwp
*l
, const struct linux_sys_ioctl_args
*uap
, register_t
*retval
)
76 syscallarg(u_long) com;
77 syscallarg(void *) data;
81 switch (LINUX_IOCGROUP(SCARG(uap
, com
))) {
83 error
= oss_ioctl_mixer(l
, LINUX_TO_OSS(uap
), retval
);
86 error
= oss_ioctl_sequencer(l
, LINUX_TO_OSS(uap
), retval
);
89 error
= oss_ioctl_audio(l
, LINUX_TO_OSS(uap
), retval
);
91 case 'V': /* video4linux2 */
94 struct sys_ioctl_args ua
;
96 if (SCARG(uap
, com
) & IOC_IN
)
98 if (SCARG(uap
, com
) & IOC_OUT
)
100 SCARG(&ua
, fd
) = SCARG(uap
, fd
);
101 SCARG(&ua
, com
) = SCARG(uap
, com
);
102 SCARG(&ua
, com
) &= ~IOC_DIRMASK
;
103 SCARG(&ua
, com
) |= com
;
104 SCARG(&ua
, data
) = SCARG(uap
, data
);
105 error
= sys_ioctl(l
, (const void *)&ua
, retval
);
108 case 'r': /* VFAT ioctls; not yet supported */
112 error
= linux_ioctl_cdrom(l
, uap
, retval
);
116 error
= linux_ioctl_termios(l
, uap
, retval
);
119 error
= linux_ioctl_mtio(l
, uap
, retval
);
124 /* XXX XAX 2x check this. */
126 * Both termios and the MIDI sequncer use 'T' to identify
127 * the ioctl, so we have to differentiate them in another
128 * way. We do it by indexing in the cdevsw with the major
129 * device number and check if that is the sequencer entry.
134 extern const struct cdevsw sequencer_cdevsw
;
136 if ((fp
= fd_getfile(SCARG(uap
, fd
))) == NULL
)
138 if (fp
->f_type
== DTYPE_VNODE
&&
139 (vp
= (struct vnode
*)fp
->f_data
) != NULL
&&
140 vp
->v_type
== VCHR
&&
141 VOP_GETATTR(vp
, &va
, l
->l_cred
) == 0 &&
142 cdevsw_lookup(va
.va_rdev
) == &sequencer_cdevsw
) {
143 error
= oss_ioctl_sequencer(l
, (const void *)LINUX_TO_OSS(uap
),
147 error
= linux_ioctl_termios(l
, uap
, retval
);
149 fd_putfile(SCARG(uap
, fd
));
151 error
= linux_ioctl_termios(l
, uap
, retval
);
156 error
= linux_ioctl_sg(l
, uap
, retval
);
159 error
= linux_ioctl_socket(l
, uap
, retval
);
162 error
= linux_ioctl_hdio(l
, uap
, retval
);
165 error
= linux_ioctl_fdio(l
, uap
, retval
);
168 error
= linux_ioctl_blkio(l
, uap
, retval
);
171 error
= linux_machdepioctl(l
, uap
, retval
);
174 if (error
== EPASSTHROUGH
) {
176 * linux returns EINVAL or ENOTTY for not supported ioctls.