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