Home | History | Annotate | Line # | Download | only in freebsd
freebsd_ioctl.c revision 1.12
      1 /*	$NetBSD: freebsd_ioctl.c,v 1.12 2007/03/04 06:01:15 christos 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.12 2007/03/04 06:01:15 christos 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/syscallargs.h>
     44 
     45 #include <net/if.h>
     46 
     47 #include <compat/freebsd/freebsd_syscallargs.h>
     48 #include <compat/common/compat_util.h>
     49 #include <compat/freebsd/freebsd_ioctl.h>
     50 
     51 #include <compat/ossaudio/ossaudio.h>
     52 #include <compat/ossaudio/ossaudiovar.h>
     53 
     54 /* The FreeBSD and OSS(Linux) encodings of ioctl R/W differ. */
     55 static void freebsd_to_oss(struct freebsd_sys_ioctl_args *,
     56 			   struct oss_sys_ioctl_args *);
     57 
     58 static void
     59 freebsd_to_oss(uap, rap)
     60 struct freebsd_sys_ioctl_args *uap;
     61 struct oss_sys_ioctl_args *rap;
     62 {
     63 	u_long ocmd, ncmd;
     64 
     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;
     72         }
     73         SCARG(rap, fd) = SCARG(uap, fd);
     74         SCARG(rap, com) = ncmd;
     75         SCARG(rap, data) = SCARG(uap, data);
     76 }
     77 
     78 
     79 static void freebsd_to_netbsd_ifioctl(struct freebsd_sys_ioctl_args *uap,
     80 				      struct sys_ioctl_args *nap);
     81 
     82 static void
     83 freebsd_to_netbsd_ifioctl(uap, nap)
     84 	struct freebsd_sys_ioctl_args *uap;
     85 	struct sys_ioctl_args *nap;
     86 {
     87 	u_long ocmd, ncmd;
     88 	ocmd = SCARG(uap, com);
     89 	switch (ocmd) {
     90 	case FREEBSD_SIOCALIFADDR:
     91 		ncmd =SIOCALIFADDR;
     92 		break;
     93 	case FREEBSD_SIOCGLIFADDR:
     94 		ncmd =SIOCGLIFADDR;
     95 		break;
     96 	case FREEBSD_SIOCDLIFADDR:
     97 		ncmd =SIOCDLIFADDR;
     98 		break;
     99 	case FREEBSD_SIOCGIFMTU:
    100 		ncmd = SIOCGIFMTU;
    101 		break;
    102 	case FREEBSD_SIOCSIFMTU:
    103 		ncmd = SIOCSIFMTU;
    104 		break;
    105 	default:
    106 		ncmd = ocmd;
    107 		break;
    108 	}
    109 	SCARG(nap, fd) = SCARG(uap, fd);
    110 	SCARG(nap, com) = ncmd;
    111 	SCARG(nap, data) = SCARG(uap, data);
    112 }
    113 
    114 int
    115 freebsd_sys_ioctl(l, v, retval)
    116 	struct lwp *l;
    117 	void *v;
    118 	register_t *retval;
    119 {
    120 	struct freebsd_sys_ioctl_args /* {
    121 		syscallarg(int) fd;
    122 		syscallarg(u_long) com;
    123 		syscallarg(void *) data;
    124 	} */ *uap = v;
    125         struct oss_sys_ioctl_args ap;
    126 	struct sys_ioctl_args nap;
    127 
    128 	/*
    129 	 * XXX - <sys/cdio.h>'s incompatibility
    130 	 *	_IO('c', 25..27, *):	incompatible
    131 	 *	_IO('c', 28... , *):	not exist
    132 	 */
    133 	/* XXX - <sys/mtio.h> */
    134 	/* XXX - <sys/scsiio.h> */
    135 	/* XXX - should convert machine dependent ioctl()s */
    136 
    137 	switch (FREEBSD_IOCGROUP(SCARG(uap, com))) {
    138 	case 'M':
    139         	freebsd_to_oss(uap, &ap);
    140 		return oss_ioctl_mixer(l, &ap, retval);
    141 	case 'Q':
    142         	freebsd_to_oss(uap, &ap);
    143 		return oss_ioctl_sequencer(l, &ap, retval);
    144 	case 'P':
    145         	freebsd_to_oss(uap, &ap);
    146 		return oss_ioctl_audio(l, &ap, retval);
    147 	case 'i':
    148 		freebsd_to_netbsd_ifioctl(uap, &nap);
    149 		return sys_ioctl(l, &nap, retval);
    150 	default:
    151 		return sys_ioctl(l, uap, retval);
    152 	}
    153 }
    154