linux_ioctl.c revision 1.25.2.3 1 /* $NetBSD: linux_ioctl.c,v 1.25.2.3 2001/11/14 19:13:10 nathanw Exp $ */
2
3 /*-
4 * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank van der Linden and 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 #include <sys/cdefs.h>
40 __KERNEL_RCSID(0, "$NetBSD: linux_ioctl.c,v 1.25.2.3 2001/11/14 19:13:10 nathanw Exp $");
41
42 #if defined(_KERNEL_OPT)
43 #include "sequencer.h"
44 #endif
45
46 #include <sys/param.h>
47 #include <sys/proc.h>
48 #include <sys/systm.h>
49 #include <sys/conf.h>
50 #include <sys/ioctl.h>
51 #include <sys/mount.h>
52 #include <sys/file.h>
53 #include <sys/vnode.h>
54 #include <sys/filedesc.h>
55
56 #include <sys/socket.h>
57 #include <net/if.h>
58 #include <sys/sockio.h>
59
60 #include <sys/syscallargs.h>
61
62 #include <compat/linux/common/linux_types.h>
63 #include <compat/linux/common/linux_signal.h>
64 #include <compat/linux/common/linux_ioctl.h>
65
66 #include <compat/linux/linux_syscallargs.h>
67
68 #include <compat/ossaudio/ossaudio.h>
69 #define LINUX_TO_OSS(v) (v) /* do nothing, same ioctl() encoding */
70
71 /*
72 * Most ioctl command are just converted to their NetBSD values,
73 * and passed on. The ones that take structure pointers and (flag)
74 * values need some massaging. This is done the usual way by
75 * allocating stackgap memory, letting the actual ioctl call do its
76 * work there and converting back the data afterwards.
77 */
78 int
79 linux_sys_ioctl(l, v, retval)
80 struct lwp *l;
81 void *v;
82 register_t *retval;
83 {
84 struct linux_sys_ioctl_args /* {
85 syscallarg(int) fd;
86 syscallarg(u_long) com;
87 syscallarg(caddr_t) data;
88 } */ *uap = v;
89 struct proc *p = l->l_proc;
90
91 switch (LINUX_IOCGROUP(SCARG(uap, com))) {
92 case 'M':
93 return oss_ioctl_mixer(p, LINUX_TO_OSS(v), retval);
94 case 'Q':
95 return oss_ioctl_sequencer(p, LINUX_TO_OSS(v), retval);
96 case 'P':
97 return oss_ioctl_audio(p, LINUX_TO_OSS(v), retval);
98 case 'S':
99 return linux_ioctl_cdrom(p, uap, retval);
100 case 't':
101 case 'f':
102 return linux_ioctl_termios(p, uap, retval);
103 case 'T':
104 {
105 #if NSEQUENCER > 0
106 /* XXX XAX 2x check this. */
107 /*
108 * Both termios and the MIDI sequncer use 'T' to identify
109 * the ioctl, so we have to differentiate them in another
110 * way. We do it by indexing in the cdevsw with the major
111 * device number and check if that is the sequencer entry.
112 */
113 struct file *fp;
114 struct filedesc *fdp;
115 struct vnode *vp;
116 struct vattr va;
117 extern int sequencerioctl
118 __P((dev_t, u_long, caddr_t, int, struct proc *));
119
120 fdp = p->p_fd;
121 if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
122 return EBADF;
123 if (fp->f_type == DTYPE_VNODE &&
124 (vp = (struct vnode *)fp->f_data) != NULL &&
125 vp->v_type == VCHR &&
126 VOP_GETATTR(vp, &va, p->p_ucred, p) == 0 &&
127 major(va.va_rdev) < nchrdev &&
128 cdevsw[major(va.va_rdev)].d_ioctl == &sequencerioctl)
129 return oss_ioctl_sequencer(p, (void*)LINUX_TO_OSS(uap),
130 retval);
131 else
132 #endif
133 return linux_ioctl_termios(p, uap, retval);
134 }
135 case 0x89:
136 return linux_ioctl_socket(p, uap, retval);
137 case 0x03:
138 return linux_ioctl_hdio(p, uap, retval);
139 case 0x02:
140 return linux_ioctl_fdio(p, uap, retval);
141 case 0x12:
142 return linux_ioctl_blkio(p, uap, retval);
143 default:
144 return linux_machdepioctl(p, uap, retval);
145 }
146 }
147