Home | History | Annotate | Line # | Download | only in freebsd
freebsd_ioctl.c revision 1.3
      1 /*	$NetBSD: freebsd_ioctl.c,v 1.3 1997/05/06 23:56:43 augustss 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/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/proc.h>
     37 #include <sys/mount.h>
     38 
     39 #include <sys/syscallargs.h>
     40 
     41 #include <compat/freebsd/freebsd_syscallargs.h>
     42 #include <compat/freebsd/freebsd_util.h>
     43 #include <compat/freebsd/freebsd_ioctl.h>
     44 
     45 #include <compat/ossaudio/ossaudio.h>
     46 #include <compat/ossaudio/ossaudiovar.h>
     47 
     48 /* The FreeBSD and OSS(Linux) encodings of ioctl R/W differ. */
     49 static void freebsd_to_oss(struct freebsd_sys_ioctl_args *,
     50 			   struct oss_sys_ioctl_args *);
     51 
     52 static void
     53 freebsd_to_oss(uap, rap)
     54 struct freebsd_sys_ioctl_args *uap;
     55 struct oss_sys_ioctl_args *rap;
     56 {
     57 	u_long ocmd, ncmd;
     58 
     59         ocmd = SCARG(uap, com);
     60         ncmd = ocmd &~ FREEBSD_IOC_DIRMASK;
     61 	switch(ocmd & FREEBSD_IOC_DIRMASK) {
     62         case FREEBSD_IOC_VOID:  ncmd |= OSS_IOC_VOID;  break;
     63         case FREEBSD_IOC_OUT:   ncmd |= OSS_IOC_OUT;   break;
     64         case FREEBSD_IOC_IN:    ncmd |= OSS_IOC_IN;    break;
     65         case FREEBSD_IOC_INOUT: ncmd |= OSS_IOC_INOUT; break;
     66         }
     67         SCARG(rap, fd) = SCARG(uap, fd);
     68         SCARG(rap, com) = ncmd;
     69         SCARG(rap, data) = SCARG(uap, data);
     70 }
     71 
     72 int
     73 freebsd_sys_ioctl(p, v, retval)
     74 	struct proc *p;
     75 	void *v;
     76 	register_t *retval;
     77 {
     78 	struct freebsd_sys_ioctl_args /* {
     79 		syscallarg(int) fd;
     80 		syscallarg(u_long) com;
     81 		syscallarg(caddr_t) data;
     82 	} */ *uap = v;
     83         struct oss_sys_ioctl_args ap;
     84 
     85 	/*
     86 	 * XXX - <sys/cdio.h>'s incompatibility
     87 	 *	_IO('c', 25..27, *):	incompatible
     88 	 *	_IO('c', 28... , *):	not exist
     89 	 */
     90 	/* XXX - <sys/mtio.h> */
     91 	/* XXX - <sys/scsiio.h> */
     92 	/* XXX - should convert machine dependent ioctl()s */
     93 
     94 	switch (FREEBSD_IOCGROUP(SCARG(uap, com))) {
     95 	case 'M':
     96         	freebsd_to_oss(uap, &ap);
     97 		return oss_ioctl_mixer(p, &ap, retval);
     98 	case 'Q':
     99         	freebsd_to_oss(uap, &ap);
    100 		return oss_ioctl_sequencer(p, &ap, retval);
    101 	case 'P':
    102         	freebsd_to_oss(uap, &ap);
    103 		return oss_ioctl_audio(p, &ap, retval);
    104 	default:
    105 		return sys_ioctl(p, uap, retval);
    106 	}
    107 }
    108