Home | History | Annotate | Line # | Download | only in common
linux_ioctl.c revision 1.43.12.1
      1  1.43.12.1      tron /*	$NetBSD: linux_ioctl.c,v 1.43.12.1 2006/05/24 15:48:27 tron Exp $	*/
      2       1.19       erh 
      3       1.19       erh /*-
      4       1.21      fvdl  * Copyright (c) 1995, 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.21      fvdl  * by Frank van der Linden and 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.1      fvdl  */
     38       1.28     lukem 
     39       1.28     lukem #include <sys/cdefs.h>
     40  1.43.12.1      tron __KERNEL_RCSID(0, "$NetBSD: linux_ioctl.c,v 1.43.12.1 2006/05/24 15:48:27 tron Exp $");
     41        1.1      fvdl 
     42       1.26       mrg #if defined(_KERNEL_OPT)
     43       1.18  augustss #include "sequencer.h"
     44       1.23  jdolecek #endif
     45       1.18  augustss 
     46        1.1      fvdl #include <sys/param.h>
     47        1.1      fvdl #include <sys/proc.h>
     48        1.1      fvdl #include <sys/systm.h>
     49       1.18  augustss #include <sys/conf.h>
     50        1.1      fvdl #include <sys/ioctl.h>
     51       1.13   mycroft #include <sys/mount.h>
     52       1.18  augustss #include <sys/file.h>
     53       1.18  augustss #include <sys/vnode.h>
     54       1.18  augustss #include <sys/filedesc.h>
     55       1.13   mycroft 
     56        1.1      fvdl #include <sys/socket.h>
     57        1.2      fvdl #include <net/if.h>
     58        1.2      fvdl #include <sys/sockio.h>
     59        1.1      fvdl 
     60       1.31   thorpej #include <sys/sa.h>
     61        1.1      fvdl #include <sys/syscallargs.h>
     62        1.4   mycroft 
     63       1.20  christos #include <compat/linux/common/linux_types.h>
     64       1.20  christos #include <compat/linux/common/linux_signal.h>
     65       1.20  christos #include <compat/linux/common/linux_ioctl.h>
     66       1.20  christos 
     67        1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     68        1.1      fvdl 
     69       1.16  augustss #include <compat/ossaudio/ossaudio.h>
     70       1.16  augustss #define LINUX_TO_OSS(v) (v)	/* do nothing, same ioctl() encoding */
     71       1.16  augustss 
     72        1.1      fvdl /*
     73        1.1      fvdl  * Most ioctl command are just converted to their NetBSD values,
     74        1.1      fvdl  * and passed on. The ones that take structure pointers and (flag)
     75        1.1      fvdl  * values need some massaging. This is done the usual way by
     76        1.1      fvdl  * allocating stackgap memory, letting the actual ioctl call do its
     77       1.16  augustss  * work there and converting back the data afterwards.
     78        1.1      fvdl  */
     79        1.1      fvdl int
     80       1.31   thorpej linux_sys_ioctl(l, v, retval)
     81       1.31   thorpej 	struct lwp *l;
     82        1.7   thorpej 	void *v;
     83        1.7   thorpej 	register_t *retval;
     84        1.7   thorpej {
     85       1.18  augustss 	struct linux_sys_ioctl_args /* {
     86        1.1      fvdl 		syscallarg(int) fd;
     87        1.1      fvdl 		syscallarg(u_long) com;
     88        1.1      fvdl 		syscallarg(caddr_t) data;
     89        1.7   thorpej 	} */ *uap = v;
     90       1.39      yamt 	int error;
     91        1.1      fvdl 
     92       1.13   mycroft 	switch (LINUX_IOCGROUP(SCARG(uap, com))) {
     93       1.15   mycroft 	case 'M':
     94       1.43  christos 		error = oss_ioctl_mixer(l, LINUX_TO_OSS(v), retval);
     95       1.39      yamt 		break;
     96       1.16  augustss 	case 'Q':
     97       1.43  christos 		error = oss_ioctl_sequencer(l, LINUX_TO_OSS(v), retval);
     98       1.39      yamt 		break;
     99       1.13   mycroft 	case 'P':
    100       1.43  christos 		error = oss_ioctl_audio(l, LINUX_TO_OSS(v), retval);
    101       1.39      yamt 		break;
    102       1.34  christos 	case 'r': /* VFAT ioctls; not yet supported */
    103       1.39      yamt 		error = ENOSYS;
    104       1.39      yamt 		break;
    105       1.17  christos 	case 'S':
    106       1.43  christos 		error = linux_ioctl_cdrom(l, uap, retval);
    107       1.39      yamt 		break;
    108       1.19       erh 	case 't':
    109       1.19       erh 	case 'f':
    110       1.43  christos 		error = linux_ioctl_termios(l, uap, retval);
    111       1.39      yamt 		break;
    112       1.42     soren 	case 'm':
    113       1.43  christos 		error = linux_ioctl_mtio(l, uap, retval);
    114       1.42     soren 		break;
    115       1.22  augustss 	case 'T':
    116       1.18  augustss 	{
    117       1.18  augustss #if NSEQUENCER > 0
    118       1.19       erh /* XXX XAX 2x check this. */
    119       1.18  augustss 		/*
    120       1.18  augustss 		 * Both termios and the MIDI sequncer use 'T' to identify
    121       1.22  augustss 		 * the ioctl, so we have to differentiate them in another
    122       1.18  augustss 		 * way.  We do it by indexing in the cdevsw with the major
    123       1.18  augustss 		 * device number and check if that is the sequencer entry.
    124       1.18  augustss 		 */
    125       1.18  augustss 		struct file *fp;
    126       1.18  augustss 		struct filedesc *fdp;
    127       1.18  augustss 		struct vnode *vp;
    128       1.18  augustss 		struct vattr va;
    129       1.29   gehenna 		extern const struct cdevsw sequencer_cdevsw;
    130       1.43  christos 		struct proc *p = l->l_proc;
    131       1.18  augustss 
    132       1.18  augustss 		fdp = p->p_fd;
    133       1.27   thorpej 		if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
    134       1.18  augustss 			return EBADF;
    135       1.32      yamt 		FILE_USE(fp);
    136       1.22  augustss 		if (fp->f_type == DTYPE_VNODE &&
    137       1.22  augustss 		    (vp = (struct vnode *)fp->f_data) != NULL &&
    138       1.22  augustss 		    vp->v_type == VCHR &&
    139  1.43.12.1      tron 		    VOP_GETATTR(vp, &va, p->p_cred, l) == 0 &&
    140       1.32      yamt 		    cdevsw_lookup(va.va_rdev) == &sequencer_cdevsw) {
    141       1.43  christos 			error = oss_ioctl_sequencer(l, (void*)LINUX_TO_OSS(uap),
    142       1.38      fvdl 						   retval);
    143       1.32      yamt 		}
    144       1.32      yamt 		else {
    145       1.43  christos 			error = linux_ioctl_termios(l, uap, retval);
    146       1.32      yamt 		}
    147       1.43  christos 		FILE_UNUSE(fp, l);
    148       1.32      yamt #else
    149       1.43  christos 		error = linux_ioctl_termios(l, uap, retval);
    150       1.18  augustss #endif
    151       1.18  augustss 	}
    152       1.39      yamt 		break;
    153       1.40  christos 	case '"':
    154       1.43  christos 		error = linux_ioctl_sg(l, uap, retval);
    155       1.40  christos 		break;
    156       1.13   mycroft 	case 0x89:
    157       1.43  christos 		error = linux_ioctl_socket(l, uap, retval);
    158       1.39      yamt 		break;
    159       1.24      fvdl 	case 0x03:
    160       1.43  christos 		error = linux_ioctl_hdio(l, uap, retval);
    161       1.39      yamt 		break;
    162       1.24      fvdl 	case 0x02:
    163       1.43  christos 		error = linux_ioctl_fdio(l, uap, retval);
    164       1.39      yamt 		break;
    165       1.25      fvdl 	case 0x12:
    166       1.43  christos 		error = linux_ioctl_blkio(l, uap, retval);
    167       1.39      yamt 		break;
    168        1.1      fvdl 	default:
    169       1.43  christos 		error = linux_machdepioctl(l, uap, retval);
    170       1.39      yamt 		break;
    171        1.1      fvdl 	}
    172       1.39      yamt 	if (error == EPASSTHROUGH) {
    173       1.39      yamt 		/*
    174       1.39      yamt 		 * linux returns EINVAL or ENOTTY for not supported ioctls.
    175       1.42     soren 		 */
    176       1.39      yamt 		error = EINVAL;
    177       1.39      yamt 	}
    178       1.39      yamt 
    179       1.39      yamt 	return error;
    180        1.1      fvdl }
    181