freebsd_ioctl.c revision 1.7 1 /* $NetBSD: freebsd_ioctl.c,v 1.7 2003/01/18 07:33:16 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1995 Frank van der Linden
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed for the NetBSD Project
18 * by Frank van der Linden
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: freebsd_ioctl.c,v 1.7 2003/01/18 07:33:16 thorpej Exp $");
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/proc.h>
40 #include <sys/mount.h>
41 #include <sys/sockio.h>
42
43 #include <sys/sa.h>
44 #include <sys/syscallargs.h>
45
46 #include <net/if.h>
47
48 #include <compat/freebsd/freebsd_syscallargs.h>
49 #include <compat/common/compat_util.h>
50 #include <compat/freebsd/freebsd_ioctl.h>
51
52 #include <compat/ossaudio/ossaudio.h>
53 #include <compat/ossaudio/ossaudiovar.h>
54
55 /* The FreeBSD and OSS(Linux) encodings of ioctl R/W differ. */
56 static void freebsd_to_oss(struct freebsd_sys_ioctl_args *,
57 struct oss_sys_ioctl_args *);
58
59 static void
60 freebsd_to_oss(uap, rap)
61 struct freebsd_sys_ioctl_args *uap;
62 struct oss_sys_ioctl_args *rap;
63 {
64 u_long ocmd, ncmd;
65
66 ocmd = SCARG(uap, com);
67 ncmd = ocmd &~ FREEBSD_IOC_DIRMASK;
68 switch(ocmd & FREEBSD_IOC_DIRMASK) {
69 case FREEBSD_IOC_VOID: ncmd |= OSS_IOC_VOID; break;
70 case FREEBSD_IOC_OUT: ncmd |= OSS_IOC_OUT; break;
71 case FREEBSD_IOC_IN: ncmd |= OSS_IOC_IN; break;
72 case FREEBSD_IOC_INOUT: ncmd |= OSS_IOC_INOUT; break;
73 }
74 SCARG(rap, fd) = SCARG(uap, fd);
75 SCARG(rap, com) = ncmd;
76 SCARG(rap, data) = SCARG(uap, data);
77 }
78
79
80 static void freebsd_to_netbsd_ifioctl(struct freebsd_sys_ioctl_args *uap,
81 struct sys_ioctl_args *nap);
82
83 static void
84 freebsd_to_netbsd_ifioctl(uap, nap)
85 struct freebsd_sys_ioctl_args *uap;
86 struct sys_ioctl_args *nap;
87 {
88 u_long ocmd, ncmd;
89 ocmd = SCARG(uap, com);
90 switch (ocmd) {
91 case FREEBSD_SIOCALIFADDR:
92 ncmd =SIOCALIFADDR;
93 break;
94 case FREEBSD_SIOCGLIFADDR:
95 ncmd =SIOCGLIFADDR;
96 break;
97 case FREEBSD_SIOCDLIFADDR:
98 ncmd =SIOCDLIFADDR;
99 break;
100 case FREEBSD_SIOCGIFMTU:
101 ncmd = SIOCGIFMTU;
102 break;
103 case FREEBSD_SIOCSIFMTU:
104 ncmd = SIOCSIFMTU;
105 break;
106 default:
107 ncmd = ocmd;
108 break;
109 }
110 SCARG(nap, fd) = SCARG(uap, fd);
111 SCARG(nap, com) = ncmd;
112 SCARG(nap, data) = SCARG(uap, data);
113 }
114
115 int
116 freebsd_sys_ioctl(l, v, retval)
117 struct lwp *l;
118 void *v;
119 register_t *retval;
120 {
121 struct freebsd_sys_ioctl_args /* {
122 syscallarg(int) fd;
123 syscallarg(u_long) com;
124 syscallarg(caddr_t) data;
125 } */ *uap = v;
126 struct proc *p = l->l_proc;
127 struct oss_sys_ioctl_args ap;
128 struct sys_ioctl_args nap;
129
130 /*
131 * XXX - <sys/cdio.h>'s incompatibility
132 * _IO('c', 25..27, *): incompatible
133 * _IO('c', 28... , *): not exist
134 */
135 /* XXX - <sys/mtio.h> */
136 /* XXX - <sys/scsiio.h> */
137 /* XXX - should convert machine dependent ioctl()s */
138
139 switch (FREEBSD_IOCGROUP(SCARG(uap, com))) {
140 case 'M':
141 freebsd_to_oss(uap, &ap);
142 return oss_ioctl_mixer(p, &ap, retval);
143 case 'Q':
144 freebsd_to_oss(uap, &ap);
145 return oss_ioctl_sequencer(p, &ap, retval);
146 case 'P':
147 freebsd_to_oss(uap, &ap);
148 return oss_ioctl_audio(p, &ap, retval);
149 case 'i':
150 freebsd_to_netbsd_ifioctl(uap, &nap);
151 return sys_ioctl(l, &nap, retval);
152 default:
153 return sys_ioctl(l, uap, retval);
154 }
155 }
156