Home | History | Annotate | Line # | Download | only in common
linux_ioctl.c revision 1.18
      1 /*	$NetBSD: linux_ioctl.c,v 1.18 1998/08/07 00:00:57 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 "sequencer.h"
     35 
     36 #include <sys/param.h>
     37 #include <sys/proc.h>
     38 #include <sys/systm.h>
     39 #include <sys/conf.h>
     40 #include <sys/ioctl.h>
     41 #include <sys/mount.h>
     42 #include <sys/file.h>
     43 #include <sys/vnode.h>
     44 #include <sys/filedesc.h>
     45 
     46 #include <sys/socket.h>
     47 #include <net/if.h>
     48 #include <sys/sockio.h>
     49 
     50 #include <sys/syscallargs.h>
     51 
     52 #include <compat/linux/linux_types.h>
     53 #include <compat/linux/linux_signal.h>
     54 #include <compat/linux/linux_syscallargs.h>
     55 #include <compat/linux/linux_ioctl.h>
     56 
     57 #include <compat/ossaudio/ossaudio.h>
     58 #define LINUX_TO_OSS(v) (v)	/* do nothing, same ioctl() encoding */
     59 
     60 /*
     61  * Most ioctl command are just converted to their NetBSD values,
     62  * and passed on. The ones that take structure pointers and (flag)
     63  * values need some massaging. This is done the usual way by
     64  * allocating stackgap memory, letting the actual ioctl call do its
     65  * work there and converting back the data afterwards.
     66  */
     67 int
     68 linux_sys_ioctl(p, v, retval)
     69 	struct proc *p;
     70 	void *v;
     71 	register_t *retval;
     72 {
     73 	struct linux_sys_ioctl_args /* {
     74 		syscallarg(int) fd;
     75 		syscallarg(u_long) com;
     76 		syscallarg(caddr_t) data;
     77 	} */ *uap = v;
     78 
     79 	switch (LINUX_IOCGROUP(SCARG(uap, com))) {
     80 	case 'M':
     81 		return oss_ioctl_mixer(p, LINUX_TO_OSS(v), retval);
     82 	case 'Q':
     83 		return oss_ioctl_sequencer(p, LINUX_TO_OSS(v), retval);
     84 	case 'P':
     85 		return oss_ioctl_audio(p, LINUX_TO_OSS(v), retval);
     86 	case 'S':
     87 		return linux_ioctl_cdrom(p, uap, retval);
     88 	case 'T':
     89 	{
     90 #if NSEQUENCER > 0
     91 		/*
     92 		 * Both termios and the MIDI sequncer use 'T' to identify
     93 		 * the ioctl, so we have to differntiate them in a different
     94 		 * way.  We do it by indexing in the cdevsw with the major
     95 		 * device number and check if that is the sequencer entry.
     96 		 */
     97 		struct file *fp;
     98 		struct filedesc *fdp;
     99 		struct vnode *vp;
    100 		struct vattr va;
    101 		extern int sequencerioctl
    102 			__P((dev_t, u_long, caddr_t, int, struct proc *));
    103 
    104 
    105 		fdp = p->p_fd;
    106 		if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
    107 		    (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
    108 			return EBADF;
    109 		vp = (struct vnode *)fp->f_data;
    110 		if (vp->v_type == VCHR &&
    111 		    VOP_GETATTR(vp, &va, p->p_ucred, p) == 0 &&
    112 		    major(va.va_rdev) < nchrdev &&
    113 		    cdevsw[major(va.va_rdev)].d_ioctl == &sequencerioctl)
    114 			return oss_ioctl_sequencer(p, (void*)LINUX_TO_OSS(uap),
    115 						   retval);
    116 		else
    117 #endif
    118 			return linux_ioctl_termios(p, uap, retval);
    119 	}
    120 	case 0x89:
    121 		return linux_ioctl_socket(p, uap, retval);
    122 	default:
    123 		return linux_machdepioctl(p, uap, retval);
    124 	}
    125 }
    126