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