linux_ioctl.c revision 1.54.2.1 1 1.54.2.1 wrstuden /* $NetBSD: linux_ioctl.c,v 1.54.2.1 2008/05/10 23:48:56 wrstuden Exp $ */
2 1.19 erh
3 1.19 erh /*-
4 1.53 ad * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
5 1.19 erh * All rights reserved.
6 1.19 erh *
7 1.19 erh * This code is derived from software contributed to The NetBSD Foundation
8 1.21 fvdl * by Frank van der Linden and Eric Haszlakiewicz.
9 1.19 erh *
10 1.19 erh * Redistribution and use in source and binary forms, with or without
11 1.19 erh * modification, are permitted provided that the following conditions
12 1.19 erh * are met:
13 1.19 erh * 1. Redistributions of source code must retain the above copyright
14 1.19 erh * notice, this list of conditions and the following disclaimer.
15 1.19 erh * 2. Redistributions in binary form must reproduce the above copyright
16 1.19 erh * notice, this list of conditions and the following disclaimer in the
17 1.19 erh * documentation and/or other materials provided with the distribution.
18 1.19 erh *
19 1.19 erh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.19 erh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.19 erh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.19 erh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.19 erh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.19 erh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.19 erh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.19 erh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.19 erh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.19 erh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.19 erh * POSSIBILITY OF SUCH DAMAGE.
30 1.1 fvdl */
31 1.28 lukem
32 1.28 lukem #include <sys/cdefs.h>
33 1.54.2.1 wrstuden __KERNEL_RCSID(0, "$NetBSD: linux_ioctl.c,v 1.54.2.1 2008/05/10 23:48:56 wrstuden Exp $");
34 1.1 fvdl
35 1.26 mrg #if defined(_KERNEL_OPT)
36 1.18 augustss #include "sequencer.h"
37 1.23 jdolecek #endif
38 1.18 augustss
39 1.1 fvdl #include <sys/param.h>
40 1.1 fvdl #include <sys/proc.h>
41 1.1 fvdl #include <sys/systm.h>
42 1.18 augustss #include <sys/conf.h>
43 1.1 fvdl #include <sys/ioctl.h>
44 1.13 mycroft #include <sys/mount.h>
45 1.18 augustss #include <sys/file.h>
46 1.18 augustss #include <sys/vnode.h>
47 1.18 augustss #include <sys/filedesc.h>
48 1.13 mycroft
49 1.1 fvdl #include <sys/socket.h>
50 1.2 fvdl #include <net/if.h>
51 1.2 fvdl #include <sys/sockio.h>
52 1.1 fvdl
53 1.54.2.1 wrstuden #include <sys/sa.h>
54 1.1 fvdl #include <sys/syscallargs.h>
55 1.4 mycroft
56 1.20 christos #include <compat/linux/common/linux_types.h>
57 1.20 christos #include <compat/linux/common/linux_signal.h>
58 1.20 christos #include <compat/linux/common/linux_ioctl.h>
59 1.49 njoly #include <compat/linux/common/linux_ipc.h>
60 1.49 njoly #include <compat/linux/common/linux_sem.h>
61 1.20 christos
62 1.1 fvdl #include <compat/linux/linux_syscallargs.h>
63 1.1 fvdl
64 1.16 augustss #include <compat/ossaudio/ossaudio.h>
65 1.52 dsl #define LINUX_TO_OSS(v) ((const void *)(v)) /* do nothing, same ioctl() encoding */
66 1.16 augustss
67 1.1 fvdl /*
68 1.1 fvdl * Most ioctl command are just converted to their NetBSD values,
69 1.1 fvdl * and passed on. The ones that take structure pointers and (flag)
70 1.48 dsl * values need some massaging.
71 1.1 fvdl */
72 1.1 fvdl int
73 1.52 dsl linux_sys_ioctl(struct lwp *l, const struct linux_sys_ioctl_args *uap, register_t *retval)
74 1.7 thorpej {
75 1.52 dsl /* {
76 1.1 fvdl syscallarg(int) fd;
77 1.1 fvdl syscallarg(u_long) com;
78 1.47 christos syscallarg(void *) data;
79 1.52 dsl } */
80 1.39 yamt int error;
81 1.1 fvdl
82 1.13 mycroft switch (LINUX_IOCGROUP(SCARG(uap, com))) {
83 1.15 mycroft case 'M':
84 1.52 dsl error = oss_ioctl_mixer(l, LINUX_TO_OSS(uap), retval);
85 1.39 yamt break;
86 1.16 augustss case 'Q':
87 1.52 dsl error = oss_ioctl_sequencer(l, LINUX_TO_OSS(uap), retval);
88 1.39 yamt break;
89 1.13 mycroft case 'P':
90 1.52 dsl error = oss_ioctl_audio(l, LINUX_TO_OSS(uap), retval);
91 1.39 yamt break;
92 1.34 christos case 'r': /* VFAT ioctls; not yet supported */
93 1.39 yamt error = ENOSYS;
94 1.39 yamt break;
95 1.17 christos case 'S':
96 1.43 christos error = linux_ioctl_cdrom(l, uap, retval);
97 1.39 yamt break;
98 1.19 erh case 't':
99 1.19 erh case 'f':
100 1.43 christos error = linux_ioctl_termios(l, uap, retval);
101 1.39 yamt break;
102 1.42 soren case 'm':
103 1.43 christos error = linux_ioctl_mtio(l, uap, retval);
104 1.42 soren break;
105 1.22 augustss case 'T':
106 1.18 augustss {
107 1.18 augustss #if NSEQUENCER > 0
108 1.19 erh /* XXX XAX 2x check this. */
109 1.18 augustss /*
110 1.18 augustss * Both termios and the MIDI sequncer use 'T' to identify
111 1.22 augustss * the ioctl, so we have to differentiate them in another
112 1.18 augustss * way. We do it by indexing in the cdevsw with the major
113 1.18 augustss * device number and check if that is the sequencer entry.
114 1.18 augustss */
115 1.18 augustss struct file *fp;
116 1.18 augustss struct vnode *vp;
117 1.18 augustss struct vattr va;
118 1.29 gehenna extern const struct cdevsw sequencer_cdevsw;
119 1.18 augustss
120 1.53 ad if ((fp = fd_getfile(SCARG(uap, fd))) == NULL)
121 1.18 augustss return EBADF;
122 1.22 augustss if (fp->f_type == DTYPE_VNODE &&
123 1.22 augustss (vp = (struct vnode *)fp->f_data) != NULL &&
124 1.22 augustss vp->v_type == VCHR &&
125 1.50 pooka VOP_GETATTR(vp, &va, l->l_cred) == 0 &&
126 1.32 yamt cdevsw_lookup(va.va_rdev) == &sequencer_cdevsw) {
127 1.52 dsl error = oss_ioctl_sequencer(l, (const void *)LINUX_TO_OSS(uap),
128 1.38 fvdl retval);
129 1.32 yamt }
130 1.32 yamt else {
131 1.43 christos error = linux_ioctl_termios(l, uap, retval);
132 1.32 yamt }
133 1.53 ad fd_putfile(SCARG(uap, fd));
134 1.32 yamt #else
135 1.43 christos error = linux_ioctl_termios(l, uap, retval);
136 1.18 augustss #endif
137 1.18 augustss }
138 1.39 yamt break;
139 1.40 christos case '"':
140 1.43 christos error = linux_ioctl_sg(l, uap, retval);
141 1.40 christos break;
142 1.13 mycroft case 0x89:
143 1.43 christos error = linux_ioctl_socket(l, uap, retval);
144 1.39 yamt break;
145 1.24 fvdl case 0x03:
146 1.43 christos error = linux_ioctl_hdio(l, uap, retval);
147 1.39 yamt break;
148 1.24 fvdl case 0x02:
149 1.43 christos error = linux_ioctl_fdio(l, uap, retval);
150 1.39 yamt break;
151 1.25 fvdl case 0x12:
152 1.43 christos error = linux_ioctl_blkio(l, uap, retval);
153 1.39 yamt break;
154 1.1 fvdl default:
155 1.43 christos error = linux_machdepioctl(l, uap, retval);
156 1.39 yamt break;
157 1.1 fvdl }
158 1.39 yamt if (error == EPASSTHROUGH) {
159 1.39 yamt /*
160 1.39 yamt * linux returns EINVAL or ENOTTY for not supported ioctls.
161 1.42 soren */
162 1.39 yamt error = EINVAL;
163 1.39 yamt }
164 1.39 yamt
165 1.39 yamt return error;
166 1.1 fvdl }
167