Home | History | Annotate | Line # | Download | only in common
linux_ioctl.c revision 1.25.2.2
      1 /*	$NetBSD: linux_ioctl.c,v 1.25.2.2 2001/06/21 19:59:50 nathanw Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Frank van der Linden and Eric Haszlakiewicz.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #if defined(_KERNEL_OPT)
     40 #include "sequencer.h"
     41 #endif
     42 
     43 #include <sys/param.h>
     44 #include <sys/proc.h>
     45 #include <sys/systm.h>
     46 #include <sys/conf.h>
     47 #include <sys/ioctl.h>
     48 #include <sys/mount.h>
     49 #include <sys/file.h>
     50 #include <sys/vnode.h>
     51 #include <sys/filedesc.h>
     52 
     53 #include <sys/socket.h>
     54 #include <net/if.h>
     55 #include <sys/sockio.h>
     56 
     57 #include <sys/syscallargs.h>
     58 
     59 #include <compat/linux/common/linux_types.h>
     60 #include <compat/linux/common/linux_signal.h>
     61 #include <compat/linux/common/linux_ioctl.h>
     62 
     63 #include <compat/linux/linux_syscallargs.h>
     64 
     65 #include <compat/ossaudio/ossaudio.h>
     66 #define LINUX_TO_OSS(v) (v)	/* do nothing, same ioctl() encoding */
     67 
     68 /*
     69  * Most ioctl command are just converted to their NetBSD values,
     70  * and passed on. The ones that take structure pointers and (flag)
     71  * values need some massaging. This is done the usual way by
     72  * allocating stackgap memory, letting the actual ioctl call do its
     73  * work there and converting back the data afterwards.
     74  */
     75 int
     76 linux_sys_ioctl(l, v, retval)
     77 	struct lwp *l;
     78 	void *v;
     79 	register_t *retval;
     80 {
     81 	struct linux_sys_ioctl_args /* {
     82 		syscallarg(int) fd;
     83 		syscallarg(u_long) com;
     84 		syscallarg(caddr_t) data;
     85 	} */ *uap = v;
     86 	struct proc *p = l->l_proc;
     87 
     88 	switch (LINUX_IOCGROUP(SCARG(uap, com))) {
     89 	case 'M':
     90 		return oss_ioctl_mixer(p, LINUX_TO_OSS(v), retval);
     91 	case 'Q':
     92 		return oss_ioctl_sequencer(p, LINUX_TO_OSS(v), retval);
     93 	case 'P':
     94 		return oss_ioctl_audio(p, LINUX_TO_OSS(v), retval);
     95 	case 'S':
     96 		return linux_ioctl_cdrom(p, uap, retval);
     97 	case 't':
     98 	case 'f':
     99 		return linux_ioctl_termios(p, uap, retval);
    100 	case 'T':
    101 	{
    102 #if NSEQUENCER > 0
    103 /* XXX XAX 2x check this. */
    104 		/*
    105 		 * Both termios and the MIDI sequncer use 'T' to identify
    106 		 * the ioctl, so we have to differentiate them in another
    107 		 * way.  We do it by indexing in the cdevsw with the major
    108 		 * device number and check if that is the sequencer entry.
    109 		 */
    110 		struct file *fp;
    111 		struct filedesc *fdp;
    112 		struct vnode *vp;
    113 		struct vattr va;
    114 		extern int sequencerioctl
    115 			__P((dev_t, u_long, caddr_t, int, struct proc *));
    116 
    117 		fdp = p->p_fd;
    118 		if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
    119 			return EBADF;
    120 		if (fp->f_type == DTYPE_VNODE &&
    121 		    (vp = (struct vnode *)fp->f_data) != NULL &&
    122 		    vp->v_type == VCHR &&
    123 		    VOP_GETATTR(vp, &va, p->p_ucred, p) == 0 &&
    124 		    major(va.va_rdev) < nchrdev &&
    125 		    cdevsw[major(va.va_rdev)].d_ioctl == &sequencerioctl)
    126 			return oss_ioctl_sequencer(p, (void*)LINUX_TO_OSS(uap),
    127 						   retval);
    128 		else
    129 #endif
    130 			return linux_ioctl_termios(p, uap, retval);
    131 	}
    132 	case 0x89:
    133 		return linux_ioctl_socket(p, uap, retval);
    134 	case 0x03:
    135 		return linux_ioctl_hdio(p, uap, retval);
    136 	case 0x02:
    137 		return linux_ioctl_fdio(p, uap, retval);
    138 	case 0x12:
    139 		return linux_ioctl_blkio(p, uap, retval);
    140 	default:
    141 		return linux_machdepioctl(p, uap, retval);
    142 	}
    143 }
    144