1 /* $NetBSD: freebsd_ioctl.c,v 1.14 2007/12/08 18:35:58 dsl Exp $ */
4 * Copyright (c) 1995 Frank van der Linden
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: freebsd_ioctl.c,v 1.14 2007/12/08 18:35:58 dsl Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
40 #include <sys/mount.h>
41 #include <sys/sockio.h>
43 #include <sys/syscallargs.h>
47 #include <compat/sys/sockio.h>
49 #include <compat/freebsd/freebsd_syscallargs.h>
50 #include <compat/common/compat_util.h>
51 #include <compat/freebsd/freebsd_ioctl.h>
53 #include <compat/ossaudio/ossaudio.h>
54 #include <compat/ossaudio/ossaudiovar.h>
56 /* The FreeBSD and OSS(Linux) encodings of ioctl R/W differ. */
57 static void freebsd_to_oss(const struct freebsd_sys_ioctl_args
*,
58 struct oss_sys_ioctl_args
*);
61 freebsd_to_oss(const struct freebsd_sys_ioctl_args
*uap
, struct oss_sys_ioctl_args
*rap
)
65 ocmd
= SCARG(uap
, com
);
66 ncmd
= ocmd
&~ FREEBSD_IOC_DIRMASK
;
67 switch(ocmd
& FREEBSD_IOC_DIRMASK
) {
68 case FREEBSD_IOC_VOID
: ncmd
|= OSS_IOC_VOID
; break;
69 case FREEBSD_IOC_OUT
: ncmd
|= OSS_IOC_OUT
; break;
70 case FREEBSD_IOC_IN
: ncmd
|= OSS_IOC_IN
; break;
71 case FREEBSD_IOC_INOUT
: ncmd
|= OSS_IOC_INOUT
; break;
73 SCARG(rap
, fd
) = SCARG(uap
, fd
);
74 SCARG(rap
, com
) = ncmd
;
75 SCARG(rap
, data
) = SCARG(uap
, data
);
79 static void freebsd_to_netbsd_ifioctl(const struct freebsd_sys_ioctl_args
*uap
,
80 struct sys_ioctl_args
*nap
);
83 freebsd_to_netbsd_ifioctl(const struct freebsd_sys_ioctl_args
*uap
, struct sys_ioctl_args
*nap
)
86 ocmd
= SCARG(uap
, com
);
88 case FREEBSD_SIOCALIFADDR
:
91 case FREEBSD_SIOCGLIFADDR
:
94 case FREEBSD_SIOCDLIFADDR
:
97 case FREEBSD_SIOCGIFMTU
:
100 case FREEBSD_SIOCSIFMTU
:
107 SCARG(nap
, fd
) = SCARG(uap
, fd
);
108 SCARG(nap
, com
) = ncmd
;
109 SCARG(nap
, data
) = SCARG(uap
, data
);
113 freebsd_sys_ioctl(struct lwp
*l
, const struct freebsd_sys_ioctl_args
*uap
, register_t
*retval
)
117 syscallarg(u_long) com;
118 syscallarg(void *) data;
120 struct oss_sys_ioctl_args ap
;
121 struct sys_ioctl_args nap
;
124 * XXX - <sys/cdio.h>'s incompatibility
125 * _IO('c', 25..27, *): incompatible
126 * _IO('c', 28... , *): not exist
128 /* XXX - <sys/mtio.h> */
129 /* XXX - <sys/scsiio.h> */
130 /* XXX - should convert machine dependent ioctl()s */
132 switch (FREEBSD_IOCGROUP(SCARG(uap
, com
))) {
134 freebsd_to_oss(uap
, &ap
);
135 return oss_ioctl_mixer(l
, &ap
, retval
);
137 freebsd_to_oss(uap
, &ap
);
138 return oss_ioctl_sequencer(l
, &ap
, retval
);
140 freebsd_to_oss(uap
, &ap
);
141 return oss_ioctl_audio(l
, &ap
, retval
);
143 freebsd_to_netbsd_ifioctl(uap
, &nap
);
144 return sys_ioctl(l
, &nap
, retval
);
146 return sys_ioctl(l
, (const void *)uap
, retval
);