Implement Darwin's FIODTYPE ioctl (get a file d_type)
This commit is contained in:
parent
d4ea794325
commit
fcd3e861d0
150
sys/compat/darwin/darwin_ioctl.c
Normal file
150
sys/compat/darwin/darwin_ioctl.c
Normal file
@ -0,0 +1,150 @@
|
||||
/* $NetBSD: darwin_ioctl.c,v 1.1 2003/09/03 07:28:38 manu Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* 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>
|
||||
__KERNEL_RCSID(0, "$NetBSD: darwin_ioctl.c,v 1.1 2003/09/03 07:28:38 manu Exp $");
|
||||
|
||||
#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/sa.h>
|
||||
|
||||
#include <sys/syscallargs.h>
|
||||
|
||||
#include <compat/mach/mach_types.h>
|
||||
#include <compat/mach/mach_vm.h>
|
||||
|
||||
#include <compat/darwin/darwin_ioctl.h>
|
||||
#include <compat/darwin/darwin_syscallargs.h>
|
||||
|
||||
static int vtype_to_dtype(int);
|
||||
|
||||
int
|
||||
darwin_sys_ioctl(l, v, retval)
|
||||
struct lwp *l;
|
||||
void *v;
|
||||
register_t *retval;
|
||||
{
|
||||
struct darwin_sys_ioctl_args /* {
|
||||
syscallarg(int) fd;
|
||||
syscallarg(u_long) com;
|
||||
syscallarg(void *) data;
|
||||
} */ *uap = v;
|
||||
struct sys_ioctl_args cup;
|
||||
int error;
|
||||
|
||||
switch (SCARG(uap, com)) {
|
||||
case DARWIN_FIODTYPE: { /* Get file d_type */
|
||||
struct proc *p = l->l_proc;
|
||||
struct file *fp;
|
||||
struct vnode *vp;
|
||||
int *data = SCARG(uap, data);
|
||||
int type;
|
||||
|
||||
/* getvnode() will use the descriptor for us */
|
||||
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)))
|
||||
return (error);
|
||||
|
||||
vp = fp->f_data;
|
||||
type = vtype_to_dtype(vp->v_type);
|
||||
FILE_UNUSE(fp, p);
|
||||
|
||||
error = copyout(&type, data, sizeof(*data));
|
||||
|
||||
return error;
|
||||
break;
|
||||
}
|
||||
|
||||
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
|
||||
vtype_to_dtype(dtype)
|
||||
int dtype;
|
||||
{
|
||||
switch (dtype) {
|
||||
case VNON:
|
||||
return DT_UNKNOWN;
|
||||
break;
|
||||
case VREG:
|
||||
return DT_REG;
|
||||
break;
|
||||
case VDIR:
|
||||
return DT_DIR;
|
||||
break;
|
||||
case VBLK:
|
||||
return DT_BLK;
|
||||
break;
|
||||
case VCHR:
|
||||
return DT_CHR;
|
||||
break;
|
||||
case VLNK:
|
||||
return DT_LNK;
|
||||
break;
|
||||
case VSOCK:
|
||||
return DT_SOCK;
|
||||
break;
|
||||
case VFIFO:
|
||||
return DT_FIFO;
|
||||
break;
|
||||
case VBAD:
|
||||
return DT_WHT;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DT_UNKNOWN;
|
||||
}
|
44
sys/compat/darwin/darwin_ioctl.h
Normal file
44
sys/compat/darwin/darwin_ioctl.h
Normal file
@ -0,0 +1,44 @@
|
||||
/* $NetBSD: darwin_ioctl.h,v 1.1 2003/09/03 07:28:39 manu Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _DARWIN_IOCTL_H_
|
||||
#define _DARWIN_IOCTL_H_
|
||||
|
||||
#define DARWIN_FIODTYPE _IOR('f', 122, int)
|
||||
|
||||
#endif /* _DARWIN_IOCTL_H_ */
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: darwin_syscall.h,v 1.27 2003/09/02 21:48:49 manu Exp $ */
|
||||
/* $NetBSD: darwin_syscall.h,v 1.28 2003/09/03 07:28:39 manu Exp $ */
|
||||
|
||||
/*
|
||||
* System call numbers.
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: darwin_syscallargs.h,v 1.27 2003/09/02 21:48:50 manu Exp $ */
|
||||
/* $NetBSD: darwin_syscallargs.h,v 1.28 2003/09/03 07:28:39 manu Exp $ */
|
||||
|
||||
/*
|
||||
* System call argument lists.
|
||||
@ -116,6 +116,12 @@ struct bsd_sys_acct_args {
|
||||
syscallarg(const char *) path;
|
||||
};
|
||||
|
||||
struct darwin_sys_ioctl_args {
|
||||
syscallarg(int) fd;
|
||||
syscallarg(u_long) com;
|
||||
syscallarg(void *) data;
|
||||
};
|
||||
|
||||
struct bsd_sys_revoke_args {
|
||||
syscallarg(const char *) path;
|
||||
};
|
||||
@ -321,7 +327,7 @@ int sys___setlogin(struct lwp *, void *, register_t *);
|
||||
int bsd_sys_acct(struct lwp *, void *, register_t *);
|
||||
int compat_13_sys_sigpending(struct lwp *, void *, register_t *);
|
||||
int compat_13_sys_sigaltstack(struct lwp *, void *, register_t *);
|
||||
int sys_ioctl(struct lwp *, void *, register_t *);
|
||||
int darwin_sys_ioctl(struct lwp *, void *, register_t *);
|
||||
int sys_reboot(struct lwp *, void *, register_t *);
|
||||
int bsd_sys_revoke(struct lwp *, void *, register_t *);
|
||||
int bsd_sys_symlink(struct lwp *, void *, register_t *);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: darwin_syscalls.c,v 1.27 2003/09/02 21:48:50 manu Exp $ */
|
||||
/* $NetBSD: darwin_syscalls.c,v 1.28 2003/09/03 07:28:39 manu Exp $ */
|
||||
|
||||
/*
|
||||
* System call names.
|
||||
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: darwin_syscalls.c,v 1.27 2003/09/02 21:48:50 manu Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: darwin_syscalls.c,v 1.28 2003/09/03 07:28:39 manu Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_ktrace.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: darwin_sysent.c,v 1.28 2003/09/02 21:48:50 manu Exp $ */
|
||||
/* $NetBSD: darwin_sysent.c,v 1.29 2003/09/03 07:28:39 manu Exp $ */
|
||||
|
||||
/*
|
||||
* System call switch table.
|
||||
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: darwin_sysent.c,v 1.28 2003/09/02 21:48:50 manu Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: darwin_sysent.c,v 1.29 2003/09/03 07:28:39 manu Exp $");
|
||||
|
||||
#include "opt_ktrace.h"
|
||||
#include "opt_nfsserver.h"
|
||||
@ -156,8 +156,8 @@ struct sysent darwin_sysent[] = {
|
||||
compat_13_sys_sigpending }, /* 52 = sigpending13 */
|
||||
{ 2, s(struct compat_13_sys_sigaltstack_args), 0,
|
||||
compat_13_sys_sigaltstack }, /* 53 = sigaltstack13 */
|
||||
{ 3, s(struct sys_ioctl_args), 0,
|
||||
sys_ioctl }, /* 54 = ioctl */
|
||||
{ 3, s(struct darwin_sys_ioctl_args), 0,
|
||||
darwin_sys_ioctl }, /* 54 = ioctl */
|
||||
{ 1, s(struct sys_reboot_args), 0,
|
||||
sys_reboot }, /* 55 = oreboot */
|
||||
{ 1, s(struct bsd_sys_revoke_args), 0,
|
||||
|
@ -1,4 +1,4 @@
|
||||
# $NetBSD: files.darwin,v 1.11 2003/09/02 21:31:04 manu Exp $
|
||||
# $NetBSD: files.darwin,v 1.12 2003/09/03 07:28:40 manu Exp $
|
||||
#
|
||||
# Config file description for machine-independent Darwin compat code.
|
||||
# Included by ports that need it.
|
||||
@ -7,6 +7,7 @@
|
||||
# own file lists.
|
||||
|
||||
file compat/darwin/darwin_exec.c compat_darwin
|
||||
file compat/darwin/darwin_ioctl.c compat_darwin
|
||||
file compat/darwin/darwin_iokit.c compat_darwin
|
||||
file compat/darwin/darwin_iohidsystem.c compat_darwin
|
||||
file compat/darwin/darwin_ioframebuffer.c compat_darwin
|
||||
|
@ -1,4 +1,4 @@
|
||||
$NetBSD: syscalls.master,v 1.14 2003/09/02 21:31:04 manu Exp $
|
||||
$NetBSD: syscalls.master,v 1.15 2003/09/03 07:28:40 manu Exp $
|
||||
|
||||
; @(#)syscalls.master 8.2 (Berkeley) 1/13/94
|
||||
|
||||
@ -159,7 +159,7 @@
|
||||
53 NOARGS { int compat_13_sys_sigaltstack( \
|
||||
const struct sigaltstack13 *nss, \
|
||||
struct sigaltstack13 *oss); } sigaltstack13
|
||||
54 NOARGS { int sys_ioctl(int fd, \
|
||||
54 STD { int darwin_sys_ioctl(int fd, \
|
||||
u_long com, ... void *data); }
|
||||
55 NOARGS { int sys_reboot(int opt); } oreboot
|
||||
56 NODEF { int bsd_sys_revoke(const char *path); }
|
||||
|
Loading…
Reference in New Issue
Block a user