linux_ioctl.c revision 1.20 1 /* $NetBSD: linux_ioctl.c,v 1.20 1998/10/03 20:17:41 christos 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/common/linux_types.h>
89 #include <compat/linux/common/linux_signal.h>
90 #include <compat/linux/common/linux_ioctl.h>
91
92 #include <compat/linux/linux_syscallargs.h>
93
94 #include <compat/ossaudio/ossaudio.h>
95 #define LINUX_TO_OSS(v) (v) /* do nothing, same ioctl() encoding */
96
97 /*
98 * Most ioctl command are just converted to their NetBSD values,
99 * and passed on. The ones that take structure pointers and (flag)
100 * values need some massaging. This is done the usual way by
101 * allocating stackgap memory, letting the actual ioctl call do its
102 * work there and converting back the data afterwards.
103 */
104 int
105 linux_sys_ioctl(p, v, retval)
106 struct proc *p;
107 void *v;
108 register_t *retval;
109 {
110 struct linux_sys_ioctl_args /* {
111 syscallarg(int) fd;
112 syscallarg(u_long) com;
113 syscallarg(caddr_t) data;
114 } */ *uap = v;
115
116 switch (LINUX_IOCGROUP(SCARG(uap, com))) {
117 case 'M':
118 return oss_ioctl_mixer(p, LINUX_TO_OSS(v), retval);
119 case 'Q':
120 return oss_ioctl_sequencer(p, LINUX_TO_OSS(v), retval);
121 case 'P':
122 return oss_ioctl_audio(p, LINUX_TO_OSS(v), retval);
123 case 'S':
124 return linux_ioctl_cdrom(p, uap, retval);
125 case 'T':
126 case 't':
127 case 'f':
128 {
129 #if NSEQUENCER > 0
130 /* XXX XAX 2x check this. */
131 /*
132 * Both termios and the MIDI sequncer use 'T' to identify
133 * the ioctl, so we have to differntiate them in a different
134 * way. We do it by indexing in the cdevsw with the major
135 * device number and check if that is the sequencer entry.
136 */
137 struct file *fp;
138 struct filedesc *fdp;
139 struct vnode *vp;
140 struct vattr va;
141 extern int sequencerioctl
142 __P((dev_t, u_long, caddr_t, int, struct proc *));
143
144
145 fdp = p->p_fd;
146 if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
147 (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
148 return EBADF;
149 vp = (struct vnode *)fp->f_data;
150 if (vp->v_type == VCHR &&
151 VOP_GETATTR(vp, &va, p->p_ucred, p) == 0 &&
152 major(va.va_rdev) < nchrdev &&
153 cdevsw[major(va.va_rdev)].d_ioctl == &sequencerioctl)
154 return oss_ioctl_sequencer(p, (void*)LINUX_TO_OSS(uap),
155 retval);
156 else
157 #endif
158 return linux_ioctl_termios(p, uap, retval);
159 }
160 case 0x89:
161 return linux_ioctl_socket(p, uap, retval);
162 default:
163 return linux_machdepioctl(p, uap, retval);
164 }
165 }
166