linux_ioctl.c revision 1.19 1 /* $NetBSD: linux_ioctl.c,v 1.19 1998/10/01 03:24:28 erh Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Eric Haszlakiewicz.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1995 Frank van der Linden
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed for the NetBSD Project
54 * by Frank van der Linden
55 * 4. The name of the author may not be used to endorse or promote products
56 * derived from this software without specific prior written permission
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 */
69
70 #include "sequencer.h"
71
72 #include <sys/param.h>
73 #include <sys/proc.h>
74 #include <sys/systm.h>
75 #include <sys/conf.h>
76 #include <sys/ioctl.h>
77 #include <sys/mount.h>
78 #include <sys/file.h>
79 #include <sys/vnode.h>
80 #include <sys/filedesc.h>
81
82 #include <sys/socket.h>
83 #include <net/if.h>
84 #include <sys/sockio.h>
85
86 #include <sys/syscallargs.h>
87
88 #include <compat/linux/linux_types.h>
89 #include <compat/linux/linux_signal.h>
90 #include <compat/linux/linux_syscallargs.h>
91 #include <compat/linux/linux_ioctl.h>
92
93 #include <compat/ossaudio/ossaudio.h>
94 #define LINUX_TO_OSS(v) (v) /* do nothing, same ioctl() encoding */
95
96 /*
97 * Most ioctl command are just converted to their NetBSD values,
98 * and passed on. The ones that take structure pointers and (flag)
99 * values need some massaging. This is done the usual way by
100 * allocating stackgap memory, letting the actual ioctl call do its
101 * work there and converting back the data afterwards.
102 */
103 int
104 linux_sys_ioctl(p, v, retval)
105 struct proc *p;
106 void *v;
107 register_t *retval;
108 {
109 struct linux_sys_ioctl_args /* {
110 syscallarg(int) fd;
111 syscallarg(u_long) com;
112 syscallarg(caddr_t) data;
113 } */ *uap = v;
114
115 switch (LINUX_IOCGROUP(SCARG(uap, com))) {
116 case 'M':
117 return oss_ioctl_mixer(p, LINUX_TO_OSS(v), retval);
118 case 'Q':
119 return oss_ioctl_sequencer(p, LINUX_TO_OSS(v), retval);
120 case 'P':
121 return oss_ioctl_audio(p, LINUX_TO_OSS(v), retval);
122 case 'S':
123 return linux_ioctl_cdrom(p, uap, retval);
124 case 'T':
125 case 't':
126 case 'f':
127 {
128 #if NSEQUENCER > 0
129 /* XXX XAX 2x check this. */
130 /*
131 * Both termios and the MIDI sequncer use 'T' to identify
132 * the ioctl, so we have to differntiate them in a different
133 * way. We do it by indexing in the cdevsw with the major
134 * device number and check if that is the sequencer entry.
135 */
136 struct file *fp;
137 struct filedesc *fdp;
138 struct vnode *vp;
139 struct vattr va;
140 extern int sequencerioctl
141 __P((dev_t, u_long, caddr_t, int, struct proc *));
142
143
144 fdp = p->p_fd;
145 if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
146 (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
147 return EBADF;
148 vp = (struct vnode *)fp->f_data;
149 if (vp->v_type == VCHR &&
150 VOP_GETATTR(vp, &va, p->p_ucred, p) == 0 &&
151 major(va.va_rdev) < nchrdev &&
152 cdevsw[major(va.va_rdev)].d_ioctl == &sequencerioctl)
153 return oss_ioctl_sequencer(p, (void*)LINUX_TO_OSS(uap),
154 retval);
155 else
156 #endif
157 return linux_ioctl_termios(p, uap, retval);
158 }
159 case 0x89:
160 return linux_ioctl_socket(p, uap, retval);
161 default:
162 return linux_machdepioctl(p, uap, retval);
163 }
164 }
165