2008-03-22 00:54:58 +03:00
|
|
|
/* $NetBSD: darwin_ioctl.c,v 1.9 2008/03/21 21:54:58 ad Exp $ */
|
2003-09-03 11:28:38 +04:00
|
|
|
|
|
|
|
/*-
|
2008-03-22 00:54:58 +03:00
|
|
|
* Copyright (c) 2003, 2008 The NetBSD Foundation, Inc.
|
2003-09-03 11:28:38 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Emmanuel Dreyfus.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2008-03-22 00:54:58 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: darwin_ioctl.c,v 1.9 2008/03/21 21:54:58 ad Exp $");
|
2003-09-03 11:28:38 +04:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/filedesc.h>
|
|
|
|
#include <sys/dirent.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
|
2005-09-13 05:42:32 +04:00
|
|
|
#include <compat/sys/signal.h>
|
|
|
|
|
2003-09-03 11:28:38 +04:00
|
|
|
#include <compat/mach/mach_types.h>
|
|
|
|
#include <compat/mach/mach_vm.h>
|
|
|
|
|
2004-07-29 02:24:06 +04:00
|
|
|
#include <compat/darwin/darwin_audit.h>
|
2003-09-03 11:28:38 +04:00
|
|
|
#include <compat/darwin/darwin_ioctl.h>
|
|
|
|
#include <compat/darwin/darwin_syscallargs.h>
|
|
|
|
|
|
|
|
static int vtype_to_dtype(int);
|
|
|
|
|
|
|
|
int
|
2007-12-21 02:02:38 +03:00
|
|
|
darwin_sys_ioctl(struct lwp *l, const struct darwin_sys_ioctl_args *uap, register_t *retval)
|
2003-09-03 11:28:38 +04:00
|
|
|
{
|
2007-12-21 02:02:38 +03:00
|
|
|
/* {
|
2003-09-03 11:28:38 +04:00
|
|
|
syscallarg(int) fd;
|
|
|
|
syscallarg(u_long) com;
|
|
|
|
syscallarg(void *) data;
|
2007-12-21 02:02:38 +03:00
|
|
|
} */
|
2003-09-03 11:28:38 +04:00
|
|
|
struct sys_ioctl_args cup;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
switch (SCARG(uap, com)) {
|
|
|
|
case DARWIN_FIODTYPE: { /* Get file d_type */
|
2008-03-22 00:54:58 +03:00
|
|
|
file_t *fp;
|
2003-09-03 11:28:38 +04:00
|
|
|
struct vnode *vp;
|
|
|
|
int *data = SCARG(uap, data);
|
|
|
|
int type;
|
|
|
|
|
|
|
|
/* getvnode() will use the descriptor for us */
|
2008-03-22 00:54:58 +03:00
|
|
|
if ((error = fd_getvnode(SCARG(uap, fd), &fp)))
|
2003-09-03 11:28:38 +04:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
vp = fp->f_data;
|
|
|
|
type = vtype_to_dtype(vp->v_type);
|
2008-03-22 00:54:58 +03:00
|
|
|
fd_putfile(SCARG(uap, fd));
|
2003-09-03 11:28:38 +04:00
|
|
|
|
|
|
|
error = copyout(&type, data, sizeof(*data));
|
|
|
|
|
|
|
|
return error;
|
|
|
|
break;
|
|
|
|
}
|
2005-02-27 01:58:54 +03:00
|
|
|
|
2003-09-03 11:28:38 +04:00
|
|
|
default:
|
|
|
|
/* Try native ioctl */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SCARG(&cup, fd) = SCARG(uap, fd);
|
|
|
|
SCARG(&cup, com) = SCARG(uap, com);
|
|
|
|
SCARG(&cup, data) = SCARG(uap, data);
|
|
|
|
|
|
|
|
error = sys_ioctl(l, &cup, retval);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2007-12-08 21:35:53 +03:00
|
|
|
vtype_to_dtype(int dtype)
|
2003-09-03 11:28:38 +04:00
|
|
|
{
|
|
|
|
switch (dtype) {
|
2005-02-27 01:58:54 +03:00
|
|
|
case VNON:
|
2003-09-03 11:28:38 +04:00
|
|
|
return DT_UNKNOWN;
|
|
|
|
break;
|
2005-02-27 01:58:54 +03:00
|
|
|
case VREG:
|
2003-09-03 11:28:38 +04:00
|
|
|
return DT_REG;
|
|
|
|
break;
|
2005-02-27 01:58:54 +03:00
|
|
|
case VDIR:
|
2003-09-03 11:28:38 +04:00
|
|
|
return DT_DIR;
|
|
|
|
break;
|
2005-02-27 01:58:54 +03:00
|
|
|
case VBLK:
|
2003-09-03 11:28:38 +04:00
|
|
|
return DT_BLK;
|
|
|
|
break;
|
2005-02-27 01:58:54 +03:00
|
|
|
case VCHR:
|
2003-09-03 11:28:38 +04:00
|
|
|
return DT_CHR;
|
|
|
|
break;
|
2005-02-27 01:58:54 +03:00
|
|
|
case VLNK:
|
2003-09-03 11:28:38 +04:00
|
|
|
return DT_LNK;
|
|
|
|
break;
|
2005-02-27 01:58:54 +03:00
|
|
|
case VSOCK:
|
2003-09-03 11:28:38 +04:00
|
|
|
return DT_SOCK;
|
|
|
|
break;
|
2005-02-27 01:58:54 +03:00
|
|
|
case VFIFO:
|
2003-09-03 11:28:38 +04:00
|
|
|
return DT_FIFO;
|
|
|
|
break;
|
2005-02-27 01:58:54 +03:00
|
|
|
case VBAD:
|
2003-09-03 11:28:38 +04:00
|
|
|
return DT_WHT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return DT_UNKNOWN;
|
|
|
|
}
|