Home | History | Annotate | Line # | Download | only in common
linux_file.c revision 1.82
      1  1.82       dsl /*	$NetBSD: linux_file.c,v 1.82 2007/04/22 08:29:57 dsl Exp $	*/
      2  1.23       erh 
      3  1.23       erh /*-
      4  1.25      fvdl  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
      5  1.23       erh  * All rights reserved.
      6  1.23       erh  *
      7  1.23       erh  * This code is derived from software contributed to The NetBSD Foundation
      8  1.25      fvdl  * by Frank van der Linden and Eric Haszlakiewicz.
      9  1.23       erh  *
     10  1.23       erh  * Redistribution and use in source and binary forms, with or without
     11  1.23       erh  * modification, are permitted provided that the following conditions
     12  1.23       erh  * are met:
     13  1.23       erh  * 1. Redistributions of source code must retain the above copyright
     14  1.23       erh  *    notice, this list of conditions and the following disclaimer.
     15  1.23       erh  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.23       erh  *    notice, this list of conditions and the following disclaimer in the
     17  1.23       erh  *    documentation and/or other materials provided with the distribution.
     18  1.23       erh  * 3. All advertising materials mentioning features or use of this software
     19  1.23       erh  *    must display the following acknowledgement:
     20  1.23       erh  *	This product includes software developed by the NetBSD
     21  1.23       erh  *	Foundation, Inc. and its contributors.
     22  1.23       erh  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.23       erh  *    contributors may be used to endorse or promote products derived
     24  1.23       erh  *    from this software without specific prior written permission.
     25  1.23       erh  *
     26  1.23       erh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.23       erh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.23       erh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.23       erh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.23       erh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.23       erh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.23       erh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.23       erh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.23       erh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.23       erh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.23       erh  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1      fvdl  */
     38   1.1      fvdl 
     39  1.23       erh /*
     40  1.23       erh  * Functions in multiarch:
     41  1.23       erh  *	linux_sys_llseek	: linux_llseek.c
     42  1.23       erh  */
     43  1.43     lukem 
     44  1.43     lukem #include <sys/cdefs.h>
     45  1.82       dsl __KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.82 2007/04/22 08:29:57 dsl Exp $");
     46  1.23       erh 
     47   1.1      fvdl #include <sys/param.h>
     48   1.1      fvdl #include <sys/systm.h>
     49   1.1      fvdl #include <sys/namei.h>
     50   1.1      fvdl #include <sys/proc.h>
     51   1.1      fvdl #include <sys/file.h>
     52   1.1      fvdl #include <sys/stat.h>
     53   1.1      fvdl #include <sys/filedesc.h>
     54   1.1      fvdl #include <sys/ioctl.h>
     55   1.1      fvdl #include <sys/kernel.h>
     56   1.1      fvdl #include <sys/mount.h>
     57   1.1      fvdl #include <sys/malloc.h>
     58  1.81       dsl #include <sys/namei.h>
     59  1.13      fvdl #include <sys/vnode.h>
     60  1.13      fvdl #include <sys/tty.h>
     61  1.39      manu #include <sys/socketvar.h>
     62  1.13      fvdl #include <sys/conf.h>
     63  1.41  jdolecek #include <sys/pipe.h>
     64   1.1      fvdl 
     65   1.1      fvdl #include <sys/syscallargs.h>
     66  1.81       dsl #include <sys/vfs_syscalls.h>
     67   1.1      fvdl 
     68  1.24  christos #include <compat/linux/common/linux_types.h>
     69  1.24  christos #include <compat/linux/common/linux_signal.h>
     70  1.24  christos #include <compat/linux/common/linux_fcntl.h>
     71  1.24  christos #include <compat/linux/common/linux_util.h>
     72  1.24  christos #include <compat/linux/common/linux_machdep.h>
     73  1.24  christos 
     74   1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     75  1.14  christos 
     76  1.14  christos static int linux_to_bsd_ioflags __P((int));
     77  1.14  christos static int bsd_to_linux_ioflags __P((int));
     78  1.14  christos static void bsd_to_linux_flock __P((struct flock *, struct linux_flock *));
     79  1.14  christos static void linux_to_bsd_flock __P((struct linux_flock *, struct flock *));
     80  1.67      manu #ifndef __amd64__
     81  1.14  christos static void bsd_to_linux_stat __P((struct stat *, struct linux_stat *));
     82  1.56   thorpej static int linux_stat1 __P((struct lwp *, void *, register_t *, int));
     83  1.67      manu #endif
     84  1.14  christos 
     85   1.1      fvdl /*
     86   1.1      fvdl  * Some file-related calls are handled here. The usual flag conversion
     87   1.1      fvdl  * an structure conversion is done, and alternate emul path searching.
     88   1.1      fvdl  */
     89   1.1      fvdl 
     90   1.1      fvdl /*
     91   1.1      fvdl  * The next two functions convert between the Linux and NetBSD values
     92   1.1      fvdl  * of the flags used in open(2) and fcntl(2).
     93   1.1      fvdl  */
     94   1.1      fvdl static int
     95  1.14  christos linux_to_bsd_ioflags(lflags)
     96  1.14  christos 	int lflags;
     97   1.1      fvdl {
     98   1.1      fvdl 	int res = 0;
     99   1.1      fvdl 
    100   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_WRONLY, O_WRONLY);
    101   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDONLY, O_RDONLY);
    102   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDWR, O_RDWR);
    103   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_CREAT, O_CREAT);
    104   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_EXCL, O_EXCL);
    105   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_NOCTTY, O_NOCTTY);
    106   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_TRUNC, O_TRUNC);
    107   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_NDELAY, O_NDELAY);
    108   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_SYNC, O_FSYNC);
    109   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_FASYNC, O_ASYNC);
    110   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_APPEND, O_APPEND);
    111   1.1      fvdl 
    112   1.1      fvdl 	return res;
    113   1.1      fvdl }
    114   1.1      fvdl 
    115   1.1      fvdl static int
    116  1.14  christos bsd_to_linux_ioflags(bflags)
    117  1.14  christos 	int bflags;
    118   1.1      fvdl {
    119   1.1      fvdl 	int res = 0;
    120   1.1      fvdl 
    121   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_WRONLY, LINUX_O_WRONLY);
    122   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_RDONLY, LINUX_O_RDONLY);
    123   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_RDWR, LINUX_O_RDWR);
    124   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_CREAT, LINUX_O_CREAT);
    125   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_EXCL, LINUX_O_EXCL);
    126   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_NOCTTY, LINUX_O_NOCTTY);
    127   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_TRUNC, LINUX_O_TRUNC);
    128   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_NDELAY, LINUX_O_NDELAY);
    129   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_FSYNC, LINUX_O_SYNC);
    130   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_ASYNC, LINUX_FASYNC);
    131   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_APPEND, LINUX_O_APPEND);
    132   1.1      fvdl 
    133   1.1      fvdl 	return res;
    134   1.1      fvdl }
    135   1.1      fvdl 
    136   1.1      fvdl /*
    137   1.1      fvdl  * creat(2) is an obsolete function, but it's present as a Linux
    138   1.1      fvdl  * system call, so let's deal with it.
    139   1.1      fvdl  *
    140  1.23       erh  * Note: On the Alpha this doesn't really exist in Linux, but it's defined
    141  1.23       erh  * in syscalls.master anyway so this doesn't have to be special cased.
    142  1.23       erh  *
    143   1.1      fvdl  * Just call open(2) with the TRUNC, CREAT and WRONLY flags.
    144   1.1      fvdl  */
    145   1.1      fvdl int
    146  1.56   thorpej linux_sys_creat(l, v, retval)
    147  1.56   thorpej 	struct lwp *l;
    148  1.11   thorpej 	void *v;
    149  1.11   thorpej 	register_t *retval;
    150  1.11   thorpej {
    151  1.12   mycroft 	struct linux_sys_creat_args /* {
    152  1.27  christos 		syscallarg(const char *) path;
    153   1.1      fvdl 		syscallarg(int) mode;
    154  1.11   thorpej 	} */ *uap = v;
    155  1.12   mycroft 	struct sys_open_args oa;
    156   1.1      fvdl 
    157   1.1      fvdl 	SCARG(&oa, path) = SCARG(uap, path);
    158   1.1      fvdl 	SCARG(&oa, flags) = O_CREAT | O_TRUNC | O_WRONLY;
    159   1.1      fvdl 	SCARG(&oa, mode) = SCARG(uap, mode);
    160  1.12   mycroft 
    161  1.56   thorpej 	return sys_open(l, &oa, retval);
    162   1.1      fvdl }
    163   1.1      fvdl 
    164   1.1      fvdl /*
    165   1.1      fvdl  * open(2). Take care of the different flag values, and let the
    166   1.1      fvdl  * NetBSD syscall do the real work. See if this operation
    167   1.1      fvdl  * gives the current process a controlling terminal.
    168   1.1      fvdl  * (XXX is this necessary?)
    169   1.1      fvdl  */
    170   1.1      fvdl int
    171  1.56   thorpej linux_sys_open(l, v, retval)
    172  1.56   thorpej 	struct lwp *l;
    173  1.11   thorpej 	void *v;
    174  1.11   thorpej 	register_t *retval;
    175  1.11   thorpej {
    176  1.12   mycroft 	struct linux_sys_open_args /* {
    177  1.27  christos 		syscallarg(const char *) path;
    178   1.1      fvdl 		syscallarg(int) flags;
    179   1.1      fvdl 		syscallarg(int) mode;
    180  1.11   thorpej 	} */ *uap = v;
    181  1.56   thorpej 	struct proc *p = l->l_proc;
    182   1.1      fvdl 	int error, fl;
    183  1.12   mycroft 	struct sys_open_args boa;
    184   1.1      fvdl 
    185   1.2      fvdl 	fl = linux_to_bsd_ioflags(SCARG(uap, flags));
    186   1.1      fvdl 
    187   1.1      fvdl 	SCARG(&boa, path) = SCARG(uap, path);
    188   1.1      fvdl 	SCARG(&boa, flags) = fl;
    189   1.1      fvdl 	SCARG(&boa, mode) = SCARG(uap, mode);
    190   1.2      fvdl 
    191  1.56   thorpej 	if ((error = sys_open(l, &boa, retval)))
    192   1.1      fvdl 		return error;
    193   1.1      fvdl 
    194   1.1      fvdl 	/*
    195   1.1      fvdl 	 * this bit from sunos_misc.c (and svr4_fcntl.c).
    196   1.1      fvdl 	 * If we are a session leader, and we don't have a controlling
    197   1.1      fvdl 	 * terminal yet, and the O_NOCTTY flag is not set, try to make
    198   1.1      fvdl 	 * this the controlling terminal.
    199  1.65     perry 	 */
    200  1.77        ad         if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_lflag & PL_CONTROLT)) {
    201   1.1      fvdl                 struct filedesc *fdp = p->p_fd;
    202  1.38   thorpej                 struct file     *fp;
    203  1.38   thorpej 
    204  1.38   thorpej 		fp = fd_getfile(fdp, *retval);
    205   1.1      fvdl 
    206   1.1      fvdl                 /* ignore any error, just give it a try */
    207  1.57      yamt                 if (fp != NULL) {
    208  1.57      yamt 			FILE_USE(fp);
    209  1.57      yamt 			if (fp->f_type == DTYPE_VNODE) {
    210  1.57      yamt 				(fp->f_ops->fo_ioctl) (fp, TIOCSCTTY,
    211  1.79  christos 				    (void *) 0, l);
    212  1.57      yamt 			}
    213  1.71  christos 			FILE_UNUSE(fp, l);
    214  1.57      yamt 		}
    215   1.1      fvdl         }
    216   1.1      fvdl 	return 0;
    217   1.1      fvdl }
    218   1.1      fvdl 
    219   1.1      fvdl /*
    220   1.1      fvdl  * The next two functions take care of converting the flock
    221   1.1      fvdl  * structure back and forth between Linux and NetBSD format.
    222   1.1      fvdl  * The only difference in the structures is the order of
    223   1.1      fvdl  * the fields, and the 'whence' value.
    224   1.1      fvdl  */
    225   1.1      fvdl static void
    226   1.1      fvdl bsd_to_linux_flock(bfp, lfp)
    227   1.1      fvdl 	struct flock *bfp;
    228   1.1      fvdl 	struct linux_flock *lfp;
    229   1.1      fvdl {
    230  1.12   mycroft 
    231   1.1      fvdl 	lfp->l_start = bfp->l_start;
    232   1.1      fvdl 	lfp->l_len = bfp->l_len;
    233   1.1      fvdl 	lfp->l_pid = bfp->l_pid;
    234   1.3   mycroft 	lfp->l_whence = bfp->l_whence;
    235   1.3   mycroft 	switch (bfp->l_type) {
    236   1.1      fvdl 	case F_RDLCK:
    237   1.3   mycroft 		lfp->l_type = LINUX_F_RDLCK;
    238   1.1      fvdl 		break;
    239   1.1      fvdl 	case F_UNLCK:
    240   1.3   mycroft 		lfp->l_type = LINUX_F_UNLCK;
    241   1.1      fvdl 		break;
    242   1.1      fvdl 	case F_WRLCK:
    243   1.3   mycroft 		lfp->l_type = LINUX_F_WRLCK;
    244   1.1      fvdl 		break;
    245   1.1      fvdl 	}
    246   1.1      fvdl }
    247   1.1      fvdl 
    248   1.1      fvdl static void
    249   1.1      fvdl linux_to_bsd_flock(lfp, bfp)
    250   1.1      fvdl 	struct linux_flock *lfp;
    251   1.1      fvdl 	struct flock *bfp;
    252   1.1      fvdl {
    253  1.12   mycroft 
    254   1.1      fvdl 	bfp->l_start = lfp->l_start;
    255   1.1      fvdl 	bfp->l_len = lfp->l_len;
    256   1.1      fvdl 	bfp->l_pid = lfp->l_pid;
    257   1.3   mycroft 	bfp->l_whence = lfp->l_whence;
    258   1.3   mycroft 	switch (lfp->l_type) {
    259   1.1      fvdl 	case LINUX_F_RDLCK:
    260   1.3   mycroft 		bfp->l_type = F_RDLCK;
    261   1.1      fvdl 		break;
    262   1.1      fvdl 	case LINUX_F_UNLCK:
    263   1.3   mycroft 		bfp->l_type = F_UNLCK;
    264   1.1      fvdl 		break;
    265   1.1      fvdl 	case LINUX_F_WRLCK:
    266   1.3   mycroft 		bfp->l_type = F_WRLCK;
    267   1.1      fvdl 		break;
    268   1.1      fvdl 	}
    269   1.1      fvdl }
    270   1.1      fvdl 
    271   1.1      fvdl /*
    272   1.1      fvdl  * Most actions in the fcntl() call are straightforward; simply
    273   1.1      fvdl  * pass control to the NetBSD system call. A few commands need
    274   1.1      fvdl  * conversions after the actual system call has done its work,
    275   1.1      fvdl  * because the flag values and lock structure are different.
    276   1.1      fvdl  */
    277   1.1      fvdl int
    278  1.56   thorpej linux_sys_fcntl(l, v, retval)
    279  1.56   thorpej 	struct lwp *l;
    280  1.11   thorpej 	void *v;
    281  1.11   thorpej 	register_t *retval;
    282  1.11   thorpej {
    283  1.12   mycroft 	struct linux_sys_fcntl_args /* {
    284   1.1      fvdl 		syscallarg(int) fd;
    285   1.1      fvdl 		syscallarg(int) cmd;
    286   1.1      fvdl 		syscallarg(void *) arg;
    287  1.11   thorpej 	} */ *uap = v;
    288  1.56   thorpej 	struct proc *p = l->l_proc;
    289  1.23       erh 	int fd, cmd, error;
    290  1.23       erh 	u_long val;
    291  1.79  christos 	void *arg, *sg;
    292   1.1      fvdl 	struct linux_flock lfl;
    293   1.1      fvdl 	struct flock *bfp, bfl;
    294  1.12   mycroft 	struct sys_fcntl_args fca;
    295  1.13      fvdl 	struct filedesc *fdp;
    296  1.13      fvdl 	struct file *fp;
    297  1.13      fvdl 	struct vnode *vp;
    298  1.13      fvdl 	struct vattr va;
    299  1.53   gehenna 	const struct cdevsw *cdev;
    300  1.13      fvdl 	long pgid;
    301  1.13      fvdl 	struct pgrp *pgrp;
    302  1.13      fvdl 	struct tty *tp, *(*d_tty) __P((dev_t));
    303   1.1      fvdl 
    304   1.1      fvdl 	fd = SCARG(uap, fd);
    305   1.1      fvdl 	cmd = SCARG(uap, cmd);
    306  1.79  christos 	arg = (void *) SCARG(uap, arg);
    307   1.1      fvdl 
    308   1.1      fvdl 	switch (cmd) {
    309   1.1      fvdl 	case LINUX_F_DUPFD:
    310   1.1      fvdl 		cmd = F_DUPFD;
    311   1.1      fvdl 		break;
    312   1.1      fvdl 	case LINUX_F_GETFD:
    313   1.1      fvdl 		cmd = F_GETFD;
    314   1.1      fvdl 		break;
    315   1.1      fvdl 	case LINUX_F_SETFD:
    316   1.1      fvdl 		cmd = F_SETFD;
    317   1.1      fvdl 		break;
    318   1.1      fvdl 	case LINUX_F_GETFL:
    319   1.1      fvdl 		SCARG(&fca, fd) = fd;
    320   1.1      fvdl 		SCARG(&fca, cmd) = F_GETFL;
    321   1.1      fvdl 		SCARG(&fca, arg) = arg;
    322  1.56   thorpej 		if ((error = sys_fcntl(l, &fca, retval)))
    323   1.1      fvdl 			return error;
    324   1.1      fvdl 		retval[0] = bsd_to_linux_ioflags(retval[0]);
    325   1.1      fvdl 		return 0;
    326  1.41  jdolecek 	case LINUX_F_SETFL: {
    327  1.69  christos 		struct file	*fp1 = NULL;
    328  1.41  jdolecek 
    329  1.23       erh 		val = linux_to_bsd_ioflags((unsigned long)SCARG(uap, arg));
    330  1.39      manu 		/*
    331  1.41  jdolecek 		 * Linux seems to have same semantics for sending SIGIO to the
    332  1.64       abs 		 * read side of socket, but slightly different semantics
    333  1.41  jdolecek 		 * for SIGIO to the write side.  Rather than sending the SIGIO
    334  1.41  jdolecek 		 * every time it's possible to write (directly) more data, it
    335  1.41  jdolecek 		 * only sends SIGIO if last write(2) failed due to insufficient
    336  1.41  jdolecek 		 * memory to hold the data. This is compatible enough
    337  1.41  jdolecek 		 * with NetBSD semantics to not do anything about the
    338  1.41  jdolecek 		 * difference.
    339  1.65     perry 		 *
    340  1.41  jdolecek 		 * Linux does NOT send SIGIO for pipes. Deal with socketpair
    341  1.41  jdolecek 		 * ones and DTYPE_PIPE ones. For these, we don't set
    342  1.41  jdolecek 		 * the underlying flags (we don't pass O_ASYNC flag down
    343  1.41  jdolecek 		 * to sys_fcntl()), but set the FASYNC flag for file descriptor,
    344  1.41  jdolecek 		 * so that F_GETFL would report the ASYNC i/o is on.
    345  1.39      manu 		 */
    346  1.41  jdolecek 		if (val & O_ASYNC) {
    347  1.69  christos 			if (((fp1 = fd_getfile(p->p_fd, fd)) == NULL))
    348  1.39      manu 			    return (EBADF);
    349  1.39      manu 
    350  1.69  christos 			FILE_USE(fp1);
    351  1.39      manu 
    352  1.69  christos 			if (((fp1->f_type == DTYPE_SOCKET) && fp1->f_data
    353  1.69  christos 			      && ((struct socket *)fp1->f_data)->so_state & SS_ISAPIPE)
    354  1.69  christos 			    || (fp1->f_type == DTYPE_PIPE))
    355  1.41  jdolecek 				val &= ~O_ASYNC;
    356  1.41  jdolecek 			else {
    357  1.41  jdolecek 				/* not a pipe, do not modify anything */
    358  1.71  christos 				FILE_UNUSE(fp1, l);
    359  1.69  christos 				fp1 = NULL;
    360  1.39      manu 			}
    361  1.41  jdolecek 		}
    362  1.41  jdolecek 
    363  1.41  jdolecek 		SCARG(&fca, fd) = fd;
    364  1.41  jdolecek 		SCARG(&fca, cmd) = F_SETFL;
    365  1.79  christos 		SCARG(&fca, arg) = (void *) val;
    366  1.39      manu 
    367  1.56   thorpej 		error = sys_fcntl(l, &fca, retval);
    368  1.41  jdolecek 
    369  1.41  jdolecek 		/* Now set the FASYNC flag for pipes */
    370  1.69  christos 		if (fp1) {
    371  1.41  jdolecek 			if (!error)
    372  1.69  christos 				fp1->f_flag |= FASYNC;
    373  1.71  christos 			FILE_UNUSE(fp1, l);
    374  1.39      manu 		}
    375  1.41  jdolecek 
    376  1.41  jdolecek 		return (error);
    377  1.41  jdolecek 	    }
    378   1.1      fvdl 	case LINUX_F_GETLK:
    379  1.46  christos 		sg = stackgap_init(p, 0);
    380  1.46  christos 		bfp = (struct flock *) stackgap_alloc(p, &sg, sizeof *bfp);
    381  1.18    kleink 		if ((error = copyin(arg, &lfl, sizeof lfl)))
    382  1.18    kleink 			return error;
    383  1.18    kleink 		linux_to_bsd_flock(&lfl, &bfl);
    384  1.18    kleink 		if ((error = copyout(&bfl, bfp, sizeof bfl)))
    385  1.18    kleink 			return error;
    386   1.1      fvdl 		SCARG(&fca, fd) = fd;
    387   1.1      fvdl 		SCARG(&fca, cmd) = F_GETLK;
    388   1.1      fvdl 		SCARG(&fca, arg) = bfp;
    389  1.56   thorpej 		if ((error = sys_fcntl(l, &fca, retval)))
    390   1.1      fvdl 			return error;
    391   1.1      fvdl 		if ((error = copyin(bfp, &bfl, sizeof bfl)))
    392   1.1      fvdl 			return error;
    393   1.1      fvdl 		bsd_to_linux_flock(&bfl, &lfl);
    394   1.1      fvdl 		return copyout(&lfl, arg, sizeof lfl);
    395  1.47  christos 
    396   1.1      fvdl 	case LINUX_F_SETLK:
    397   1.1      fvdl 	case LINUX_F_SETLKW:
    398   1.1      fvdl 		cmd = (cmd == LINUX_F_SETLK ? F_SETLK : F_SETLKW);
    399   1.1      fvdl 		if ((error = copyin(arg, &lfl, sizeof lfl)))
    400   1.1      fvdl 			return error;
    401   1.1      fvdl 		linux_to_bsd_flock(&lfl, &bfl);
    402  1.46  christos 		sg = stackgap_init(p, 0);
    403  1.46  christos 		bfp = (struct flock *) stackgap_alloc(p, &sg, sizeof *bfp);
    404   1.1      fvdl 		if ((error = copyout(&bfl, bfp, sizeof bfl)))
    405   1.1      fvdl 			return error;
    406  1.79  christos 		arg = (void *)bfp;
    407   1.1      fvdl 		break;
    408  1.47  christos 
    409   1.1      fvdl 	case LINUX_F_SETOWN:
    410  1.65     perry 	case LINUX_F_GETOWN:
    411  1.13      fvdl 		/*
    412  1.49  jdolecek 		 * We need to route fcntl() for tty descriptors around normal
    413  1.49  jdolecek 		 * fcntl(), since NetBSD tty TIOC{G,S}PGRP semantics is too
    414  1.49  jdolecek 		 * restrictive for Linux F_{G,S}ETOWN. For non-tty descriptors,
    415  1.49  jdolecek 		 * this is not a problem.
    416  1.13      fvdl 		 */
    417  1.13      fvdl 		fdp = p->p_fd;
    418  1.38   thorpej 		if ((fp = fd_getfile(fdp, fd)) == NULL)
    419  1.13      fvdl 			return EBADF;
    420  1.60  jdolecek 		FILE_USE(fp);
    421  1.60  jdolecek 
    422  1.60  jdolecek 		/* Check it's a character device vnode */
    423  1.60  jdolecek 		if (fp->f_type != DTYPE_VNODE
    424  1.60  jdolecek 		    || (vp = (struct vnode *)fp->f_data) == NULL
    425  1.60  jdolecek 		    || vp->v_type != VCHR) {
    426  1.71  christos 			FILE_UNUSE(fp, l);
    427  1.60  jdolecek 
    428  1.53   gehenna 	    not_tty:
    429  1.49  jdolecek 			/* Not a tty, proceed with common fcntl() */
    430  1.13      fvdl 			cmd = cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
    431  1.49  jdolecek 			break;
    432  1.49  jdolecek 		}
    433  1.47  christos 
    434  1.73        ad 		error = VOP_GETATTR(vp, &va, l->l_cred, l);
    435  1.60  jdolecek 
    436  1.71  christos 		FILE_UNUSE(fp, l);
    437  1.60  jdolecek 
    438  1.60  jdolecek 		if (error)
    439  1.49  jdolecek 			return error;
    440  1.60  jdolecek 
    441  1.53   gehenna 		cdev = cdevsw_lookup(va.va_rdev);
    442  1.53   gehenna 		if (cdev == NULL)
    443  1.53   gehenna 			return (ENXIO);
    444  1.53   gehenna 		d_tty = cdev->d_tty;
    445  1.49  jdolecek 		if (!d_tty || (!(tp = (*d_tty)(va.va_rdev))))
    446  1.53   gehenna 			goto not_tty;
    447  1.49  jdolecek 
    448  1.49  jdolecek 		/* set tty pg_id appropriately */
    449  1.49  jdolecek 		if (cmd == LINUX_F_GETOWN) {
    450  1.58       dsl 			retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
    451  1.49  jdolecek 			return 0;
    452  1.49  jdolecek 		}
    453  1.80        ad 		mutex_enter(&proclist_lock);
    454  1.49  jdolecek 		if ((long)arg <= 0) {
    455  1.49  jdolecek 			pgid = -(long)arg;
    456  1.49  jdolecek 		} else {
    457  1.78       dsl 			struct proc *p1 = p_find((long)arg, PFIND_LOCKED | PFIND_UNLOCK_FAIL);
    458  1.49  jdolecek 			if (p1 == NULL)
    459  1.49  jdolecek 				return (ESRCH);
    460  1.49  jdolecek 			pgid = (long)p1->p_pgrp->pg_id;
    461  1.13      fvdl 		}
    462  1.78       dsl 		pgrp = pg_find(pgid, PFIND_LOCKED);
    463  1.78       dsl 		if (pgrp == NULL || pgrp->pg_session != p->p_session) {
    464  1.80        ad 			mutex_exit(&proclist_lock);
    465  1.49  jdolecek 			return EPERM;
    466  1.78       dsl 		}
    467  1.49  jdolecek 		tp->t_pgrp = pgrp;
    468  1.80        ad 		mutex_exit(&proclist_lock);
    469  1.49  jdolecek 		return 0;
    470  1.47  christos 
    471   1.1      fvdl 	default:
    472   1.1      fvdl 		return EOPNOTSUPP;
    473   1.1      fvdl 	}
    474   1.1      fvdl 
    475   1.1      fvdl 	SCARG(&fca, fd) = fd;
    476   1.1      fvdl 	SCARG(&fca, cmd) = cmd;
    477   1.1      fvdl 	SCARG(&fca, arg) = arg;
    478  1.12   mycroft 
    479  1.56   thorpej 	return sys_fcntl(l, &fca, retval);
    480   1.1      fvdl }
    481   1.1      fvdl 
    482  1.67      manu #if !defined(__amd64__)
    483   1.1      fvdl /*
    484   1.1      fvdl  * Convert a NetBSD stat structure to a Linux stat structure.
    485   1.1      fvdl  * Only the order of the fields and the padding in the structure
    486   1.9      fvdl  * is different. linux_fakedev is a machine-dependent function
    487   1.9      fvdl  * which optionally converts device driver major/minor numbers
    488   1.9      fvdl  * (XXX horrible, but what can you do against code that compares
    489   1.9      fvdl  * things against constant major device numbers? sigh)
    490   1.1      fvdl  */
    491   1.1      fvdl static void
    492   1.1      fvdl bsd_to_linux_stat(bsp, lsp)
    493   1.1      fvdl 	struct stat *bsp;
    494   1.1      fvdl 	struct linux_stat *lsp;
    495   1.1      fvdl {
    496  1.12   mycroft 
    497  1.45  christos 	lsp->lst_dev     = linux_fakedev(bsp->st_dev, 0);
    498   1.1      fvdl 	lsp->lst_ino     = bsp->st_ino;
    499  1.19  christos 	lsp->lst_mode    = (linux_mode_t)bsp->st_mode;
    500  1.19  christos 	if (bsp->st_nlink >= (1 << 15))
    501  1.19  christos 		lsp->lst_nlink = (1 << 15) - 1;
    502  1.19  christos 	else
    503  1.19  christos 		lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
    504   1.1      fvdl 	lsp->lst_uid     = bsp->st_uid;
    505   1.1      fvdl 	lsp->lst_gid     = bsp->st_gid;
    506  1.45  christos 	lsp->lst_rdev    = linux_fakedev(bsp->st_rdev, 1);
    507   1.1      fvdl 	lsp->lst_size    = bsp->st_size;
    508   1.1      fvdl 	lsp->lst_blksize = bsp->st_blksize;
    509   1.1      fvdl 	lsp->lst_blocks  = bsp->st_blocks;
    510   1.1      fvdl 	lsp->lst_atime   = bsp->st_atime;
    511   1.1      fvdl 	lsp->lst_mtime   = bsp->st_mtime;
    512   1.1      fvdl 	lsp->lst_ctime   = bsp->st_ctime;
    513  1.66  christos #ifdef LINUX_STAT_HAS_NSEC
    514  1.66  christos 	lsp->lst_atime_nsec   = bsp->st_atimensec;
    515  1.66  christos 	lsp->lst_mtime_nsec   = bsp->st_mtimensec;
    516  1.66  christos 	lsp->lst_ctime_nsec   = bsp->st_ctimensec;
    517  1.66  christos #endif
    518   1.1      fvdl }
    519   1.1      fvdl 
    520   1.1      fvdl /*
    521   1.1      fvdl  * The stat functions below are plain sailing. stat and lstat are handled
    522   1.1      fvdl  * by one function to avoid code duplication.
    523   1.1      fvdl  */
    524   1.1      fvdl int
    525  1.56   thorpej linux_sys_fstat(l, v, retval)
    526  1.56   thorpej 	struct lwp *l;
    527  1.11   thorpej 	void *v;
    528  1.11   thorpej 	register_t *retval;
    529  1.11   thorpej {
    530  1.12   mycroft 	struct linux_sys_fstat_args /* {
    531   1.1      fvdl 		syscallarg(int) fd;
    532   1.1      fvdl 		syscallarg(linux_stat *) sp;
    533  1.11   thorpej 	} */ *uap = v;
    534   1.1      fvdl 	struct linux_stat tmplst;
    535  1.81       dsl 	struct stat tmpst;
    536   1.1      fvdl 	int error;
    537   1.1      fvdl 
    538  1.81       dsl 	error = do_sys_fstat(l, SCARG(uap, fd), &tmpst);
    539  1.81       dsl 	if (error != 0)
    540   1.1      fvdl 		return error;
    541   1.1      fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    542   1.1      fvdl 
    543  1.81       dsl 	return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
    544   1.1      fvdl }
    545   1.1      fvdl 
    546   1.1      fvdl static int
    547  1.81       dsl linux_stat1(l, v, retval, flags)
    548  1.56   thorpej 	struct lwp *l;
    549  1.14  christos 	void *v;
    550   1.1      fvdl 	register_t *retval;
    551  1.81       dsl 	int flags;
    552   1.1      fvdl {
    553   1.1      fvdl 	struct linux_stat tmplst;
    554  1.81       dsl 	struct stat tmpst;
    555   1.1      fvdl 	int error;
    556  1.14  christos 	struct linux_sys_stat_args *uap = v;
    557   1.1      fvdl 
    558  1.81       dsl 	error = do_sys_stat(l, SCARG(uap, path), flags, &tmpst);
    559  1.81       dsl 	if (error != 0)
    560   1.1      fvdl 		return error;
    561   1.1      fvdl 
    562   1.1      fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    563   1.1      fvdl 
    564  1.81       dsl 	return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
    565   1.1      fvdl }
    566   1.1      fvdl 
    567   1.1      fvdl int
    568  1.56   thorpej linux_sys_stat(l, v, retval)
    569  1.56   thorpej 	struct lwp *l;
    570  1.11   thorpej 	void *v;
    571  1.11   thorpej 	register_t *retval;
    572  1.11   thorpej {
    573  1.12   mycroft 	struct linux_sys_stat_args /* {
    574  1.27  christos 		syscallarg(const char *) path;
    575   1.1      fvdl 		syscallarg(struct linux_stat *) sp;
    576  1.11   thorpej 	} */ *uap = v;
    577  1.11   thorpej 
    578  1.81       dsl 	return linux_stat1(l, uap, retval, FOLLOW);
    579   1.1      fvdl }
    580   1.1      fvdl 
    581  1.23       erh /* Note: this is "newlstat" in the Linux sources */
    582  1.23       erh /*	(we don't bother with the old lstat currently) */
    583   1.1      fvdl int
    584  1.56   thorpej linux_sys_lstat(l, v, retval)
    585  1.56   thorpej 	struct lwp *l;
    586  1.11   thorpej 	void *v;
    587  1.11   thorpej 	register_t *retval;
    588  1.11   thorpej {
    589  1.12   mycroft 	struct linux_sys_lstat_args /* {
    590  1.27  christos 		syscallarg(const char *) path;
    591   1.1      fvdl 		syscallarg(struct linux_stat *) sp;
    592  1.11   thorpej 	} */ *uap = v;
    593  1.11   thorpej 
    594  1.81       dsl 	return linux_stat1(l, uap, retval, NOFOLLOW);
    595   1.1      fvdl }
    596  1.67      manu #endif /* !__amd64__ */
    597   1.1      fvdl 
    598   1.1      fvdl /*
    599  1.10      fvdl  * The following syscalls are mostly here because of the alternate path check.
    600   1.1      fvdl  */
    601   1.1      fvdl int
    602  1.56   thorpej linux_sys_access(l, v, retval)
    603  1.56   thorpej 	struct lwp *l;
    604  1.11   thorpej 	void *v;
    605  1.11   thorpej 	register_t *retval;
    606  1.11   thorpej {
    607  1.12   mycroft 	struct linux_sys_access_args /* {
    608  1.27  christos 		syscallarg(const char *) path;
    609   1.1      fvdl 		syscallarg(int) flags;
    610  1.11   thorpej 	} */ *uap = v;
    611   1.1      fvdl 
    612  1.56   thorpej 	return sys_access(l, uap, retval);
    613   1.2      fvdl }
    614   1.2      fvdl 
    615   1.2      fvdl int
    616  1.56   thorpej linux_sys_unlink(l, v, retval)
    617  1.56   thorpej 	struct lwp *l;
    618  1.11   thorpej 	void *v;
    619   1.2      fvdl 	register_t *retval;
    620   1.2      fvdl 
    621   1.2      fvdl {
    622  1.12   mycroft 	struct linux_sys_unlink_args /* {
    623  1.27  christos 		syscallarg(const char *) path;
    624  1.11   thorpej 	} */ *uap = v;
    625  1.63  jdolecek 	int error;
    626  1.63  jdolecek 	struct nameidata nd;
    627   1.2      fvdl 
    628  1.63  jdolecek 	error = sys_unlink(l, uap, retval);
    629  1.63  jdolecek 	if (error != EPERM)
    630  1.63  jdolecek 		return (error);
    631  1.63  jdolecek 
    632  1.63  jdolecek 	/*
    633  1.63  jdolecek 	 * Linux returns EISDIR if unlink(2) is called on a directory.
    634  1.63  jdolecek 	 * We return EPERM in such cases. To emulate correct behaviour,
    635  1.63  jdolecek 	 * check if the path points to directory and return EISDIR if this
    636  1.63  jdolecek 	 * is the case.
    637  1.63  jdolecek 	 */
    638  1.82       dsl 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, UIO_USERSPACE,
    639  1.71  christos 	    SCARG(uap, path), l);
    640  1.63  jdolecek 	if (namei(&nd) == 0) {
    641  1.63  jdolecek 		struct stat sb;
    642  1.63  jdolecek 
    643  1.71  christos 		if (vn_stat(nd.ni_vp, &sb, l) == 0
    644  1.63  jdolecek 		    && S_ISDIR(sb.st_mode))
    645  1.63  jdolecek 			error = EISDIR;
    646  1.63  jdolecek 
    647  1.63  jdolecek 		vput(nd.ni_vp);
    648  1.63  jdolecek 	}
    649  1.63  jdolecek 
    650  1.63  jdolecek 	return (error);
    651   1.2      fvdl }
    652   1.2      fvdl 
    653  1.10      fvdl int
    654  1.56   thorpej linux_sys_chdir(l, v, retval)
    655  1.56   thorpej 	struct lwp *l;
    656  1.11   thorpej 	void *v;
    657  1.11   thorpej 	register_t *retval;
    658  1.11   thorpej {
    659  1.12   mycroft 	struct linux_sys_chdir_args /* {
    660  1.27  christos 		syscallarg(const char *) path;
    661  1.11   thorpej 	} */ *uap = v;
    662   1.2      fvdl 
    663  1.56   thorpej 	return sys_chdir(l, uap, retval);
    664   1.2      fvdl }
    665   1.2      fvdl 
    666   1.2      fvdl int
    667  1.56   thorpej linux_sys_mknod(l, v, retval)
    668  1.56   thorpej 	struct lwp *l;
    669  1.11   thorpej 	void *v;
    670  1.11   thorpej 	register_t *retval;
    671  1.11   thorpej {
    672  1.12   mycroft 	struct linux_sys_mknod_args /* {
    673  1.27  christos 		syscallarg(const char *) path;
    674   1.2      fvdl 		syscallarg(int) mode;
    675   1.2      fvdl 		syscallarg(int) dev;
    676  1.11   thorpej 	} */ *uap = v;
    677   1.2      fvdl 
    678  1.10      fvdl 	/*
    679  1.40       wiz 	 * BSD handles FIFOs separately
    680  1.10      fvdl 	 */
    681  1.74     pavel 	if (S_ISFIFO(SCARG(uap, mode))) {
    682  1.54  jdolecek 		struct sys_mkfifo_args bma;
    683  1.54  jdolecek 
    684  1.21   thorpej 		SCARG(&bma, path) = SCARG(uap, path);
    685  1.21   thorpej 		SCARG(&bma, mode) = SCARG(uap, mode);
    686  1.56   thorpej 		return sys_mkfifo(l, &bma, retval);
    687  1.54  jdolecek 	} else {
    688  1.54  jdolecek 		struct sys_mknod_args bma;
    689  1.54  jdolecek 
    690  1.54  jdolecek 		SCARG(&bma, path) = SCARG(uap, path);
    691  1.54  jdolecek 		SCARG(&bma, mode) = SCARG(uap, mode);
    692  1.54  jdolecek 		/*
    693  1.54  jdolecek 		 * Linux device numbers uses 8 bits for minor and 8 bits
    694  1.54  jdolecek 		 * for major. Due to how we map our major and minor,
    695  1.82       dsl 		 * this just fits into our dev_t. Just mask off the
    696  1.54  jdolecek 		 * upper 16bit to remove any random junk.
    697  1.54  jdolecek 		 */
    698  1.54  jdolecek 		SCARG(&bma, dev) = SCARG(uap, dev) & 0xffff;
    699  1.56   thorpej 		return sys_mknod(l, &bma, retval);
    700  1.54  jdolecek 	}
    701   1.2      fvdl }
    702   1.2      fvdl 
    703   1.2      fvdl int
    704  1.56   thorpej linux_sys_chmod(l, v, retval)
    705  1.56   thorpej 	struct lwp *l;
    706  1.11   thorpej 	void *v;
    707  1.11   thorpej 	register_t *retval;
    708  1.11   thorpej {
    709  1.12   mycroft 	struct linux_sys_chmod_args /* {
    710  1.27  christos 		syscallarg(const char *) path;
    711   1.2      fvdl 		syscallarg(int) mode;
    712  1.11   thorpej 	} */ *uap = v;
    713   1.2      fvdl 
    714  1.56   thorpej 	return sys_chmod(l, uap, retval);
    715   1.2      fvdl }
    716   1.2      fvdl 
    717  1.67      manu #if defined(__i386__) || defined(__m68k__) || \
    718  1.67      manu     defined(__arm__)
    719   1.2      fvdl int
    720  1.56   thorpej linux_sys_chown16(l, v, retval)
    721  1.56   thorpej 	struct lwp *l;
    722  1.11   thorpej 	void *v;
    723  1.11   thorpej 	register_t *retval;
    724  1.11   thorpej {
    725  1.31      fvdl 	struct linux_sys_chown16_args /* {
    726  1.27  christos 		syscallarg(const char *) path;
    727   1.2      fvdl 		syscallarg(int) uid;
    728   1.2      fvdl 		syscallarg(int) gid;
    729  1.11   thorpej 	} */ *uap = v;
    730  1.22    kleink 	struct sys___posix_chown_args bca;
    731   1.2      fvdl 
    732  1.10      fvdl 	SCARG(&bca, path) = SCARG(uap, path);
    733  1.10      fvdl 	SCARG(&bca, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
    734  1.10      fvdl 		(uid_t)-1 : SCARG(uap, uid);
    735  1.10      fvdl 	SCARG(&bca, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
    736  1.10      fvdl 		(gid_t)-1 : SCARG(uap, gid);
    737  1.65     perry 
    738  1.56   thorpej 	return sys___posix_chown(l, &bca, retval);
    739  1.10      fvdl }
    740  1.10      fvdl 
    741  1.10      fvdl int
    742  1.56   thorpej linux_sys_fchown16(l, v, retval)
    743  1.56   thorpej 	struct lwp *l;
    744  1.11   thorpej 	void *v;
    745  1.11   thorpej 	register_t *retval;
    746  1.11   thorpej {
    747  1.31      fvdl 	struct linux_sys_fchown16_args /* {
    748  1.10      fvdl 		syscallarg(int) fd;
    749  1.10      fvdl 		syscallarg(int) uid;
    750  1.10      fvdl 		syscallarg(int) gid;
    751  1.11   thorpej 	} */ *uap = v;
    752  1.22    kleink 	struct sys___posix_fchown_args bfa;
    753  1.10      fvdl 
    754  1.10      fvdl 	SCARG(&bfa, fd) = SCARG(uap, fd);
    755  1.10      fvdl 	SCARG(&bfa, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
    756  1.10      fvdl 		(uid_t)-1 : SCARG(uap, uid);
    757  1.10      fvdl 	SCARG(&bfa, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
    758  1.10      fvdl 		(gid_t)-1 : SCARG(uap, gid);
    759  1.65     perry 
    760  1.56   thorpej 	return sys___posix_fchown(l, &bfa, retval);
    761   1.2      fvdl }
    762   1.2      fvdl 
    763   1.2      fvdl int
    764  1.56   thorpej linux_sys_lchown16(l, v, retval)
    765  1.56   thorpej 	struct lwp *l;
    766  1.23       erh 	void *v;
    767  1.23       erh 	register_t *retval;
    768  1.23       erh {
    769  1.31      fvdl 	struct linux_sys_lchown16_args /* {
    770  1.23       erh 		syscallarg(char *) path;
    771  1.23       erh 		syscallarg(int) uid;
    772  1.23       erh 		syscallarg(int) gid;
    773  1.23       erh 	} */ *uap = v;
    774  1.23       erh 	struct sys___posix_lchown_args bla;
    775  1.23       erh 
    776  1.23       erh 	SCARG(&bla, path) = SCARG(uap, path);
    777  1.23       erh 	SCARG(&bla, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
    778  1.23       erh 		(uid_t)-1 : SCARG(uap, uid);
    779  1.23       erh 	SCARG(&bla, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
    780  1.23       erh 		(gid_t)-1 : SCARG(uap, gid);
    781  1.23       erh 
    782  1.56   thorpej 	return sys___posix_lchown(l, &bla, retval);
    783  1.33      fvdl }
    784  1.67      manu #endif /* __i386__ || __m68k__ || __arm__ || __amd64__ */
    785  1.67      manu #if defined (__i386__) || defined (__m68k__) || defined(__amd64__) || \
    786  1.67      manu     defined (__powerpc__) || defined (__mips__) || defined (__arm__)
    787  1.33      fvdl int
    788  1.56   thorpej linux_sys_chown(l, v, retval)
    789  1.56   thorpej 	struct lwp *l;
    790  1.33      fvdl 	void *v;
    791  1.33      fvdl 	register_t *retval;
    792  1.33      fvdl {
    793  1.33      fvdl 	struct linux_sys_chown_args /* {
    794  1.33      fvdl 		syscallarg(char *) path;
    795  1.33      fvdl 		syscallarg(int) uid;
    796  1.33      fvdl 		syscallarg(int) gid;
    797  1.33      fvdl 	} */ *uap = v;
    798  1.33      fvdl 
    799  1.56   thorpej 	return sys___posix_chown(l, uap, retval);
    800  1.33      fvdl }
    801  1.33      fvdl 
    802  1.33      fvdl int
    803  1.56   thorpej linux_sys_lchown(l, v, retval)
    804  1.56   thorpej 	struct lwp *l;
    805  1.33      fvdl 	void *v;
    806  1.33      fvdl 	register_t *retval;
    807  1.33      fvdl {
    808  1.33      fvdl 	struct linux_sys_lchown_args /* {
    809  1.33      fvdl 		syscallarg(char *) path;
    810  1.33      fvdl 		syscallarg(int) uid;
    811  1.33      fvdl 		syscallarg(int) gid;
    812  1.33      fvdl 	} */ *uap = v;
    813  1.33      fvdl 
    814  1.56   thorpej 	return sys___posix_lchown(l, uap, retval);
    815  1.23       erh }
    816  1.67      manu #endif /* __i386__||__m68k__||__powerpc__||__mips__||__arm__ ||__amd64__ */
    817  1.32   thorpej 
    818  1.23       erh int
    819  1.56   thorpej linux_sys_rename(l, v, retval)
    820  1.56   thorpej 	struct lwp *l;
    821  1.11   thorpej 	void *v;
    822  1.11   thorpej 	register_t *retval;
    823  1.11   thorpej {
    824  1.12   mycroft 	struct linux_sys_rename_args /* {
    825  1.27  christos 		syscallarg(const char *) from;
    826  1.27  christos 		syscallarg(const char *) to;
    827  1.11   thorpej 	} */ *uap = v;
    828   1.2      fvdl 
    829  1.56   thorpej 	return sys___posix_rename(l, uap, retval);
    830   1.2      fvdl }
    831   1.2      fvdl 
    832   1.2      fvdl int
    833  1.56   thorpej linux_sys_mkdir(l, v, retval)
    834  1.56   thorpej 	struct lwp *l;
    835  1.11   thorpej 	void *v;
    836  1.11   thorpej 	register_t *retval;
    837  1.11   thorpej {
    838  1.12   mycroft 	struct linux_sys_mkdir_args /* {
    839  1.27  christos 		syscallarg(const char *) path;
    840   1.7      fvdl 		syscallarg(int) mode;
    841  1.11   thorpej 	} */ *uap = v;
    842  1.12   mycroft 
    843  1.56   thorpej 	return sys_mkdir(l, uap, retval);
    844   1.2      fvdl }
    845   1.2      fvdl 
    846   1.2      fvdl int
    847  1.56   thorpej linux_sys_rmdir(l, v, retval)
    848  1.56   thorpej 	struct lwp *l;
    849  1.11   thorpej 	void *v;
    850  1.11   thorpej 	register_t *retval;
    851  1.11   thorpej {
    852  1.12   mycroft 	struct linux_sys_rmdir_args /* {
    853  1.27  christos 		syscallarg(const char *) path;
    854  1.11   thorpej 	} */ *uap = v;
    855  1.12   mycroft 
    856  1.56   thorpej 	return sys_rmdir(l, uap, retval);
    857   1.2      fvdl }
    858   1.2      fvdl 
    859   1.2      fvdl int
    860  1.56   thorpej linux_sys_symlink(l, v, retval)
    861  1.56   thorpej 	struct lwp *l;
    862  1.11   thorpej 	void *v;
    863  1.11   thorpej 	register_t *retval;
    864  1.11   thorpej {
    865  1.12   mycroft 	struct linux_sys_symlink_args /* {
    866  1.27  christos 		syscallarg(const char *) path;
    867  1.27  christos 		syscallarg(const char *) to;
    868  1.11   thorpej 	} */ *uap = v;
    869   1.2      fvdl 
    870  1.56   thorpej 	return sys_symlink(l, uap, retval);
    871  1.34      fvdl }
    872  1.34      fvdl 
    873  1.34      fvdl int
    874  1.56   thorpej linux_sys_link(l, v, retval)
    875  1.56   thorpej 	struct lwp *l;
    876  1.34      fvdl 	void *v;
    877  1.34      fvdl 	register_t *retval;
    878  1.34      fvdl {
    879  1.34      fvdl 	struct linux_sys_link_args /* {
    880  1.34      fvdl 		syscallarg(const char *) path;
    881  1.34      fvdl 		syscallarg(const char *) link;
    882  1.34      fvdl 	} */ *uap = v;
    883  1.34      fvdl 
    884  1.56   thorpej 	return sys_link(l, uap, retval);
    885   1.2      fvdl }
    886   1.2      fvdl 
    887   1.2      fvdl int
    888  1.56   thorpej linux_sys_readlink(l, v, retval)
    889  1.56   thorpej 	struct lwp *l;
    890  1.11   thorpej 	void *v;
    891  1.11   thorpej 	register_t *retval;
    892  1.11   thorpej {
    893  1.12   mycroft 	struct linux_sys_readlink_args /* {
    894  1.27  christos 		syscallarg(const char *) name;
    895   1.2      fvdl 		syscallarg(char *) buf;
    896   1.2      fvdl 		syscallarg(int) count;
    897  1.11   thorpej 	} */ *uap = v;
    898  1.12   mycroft 
    899  1.56   thorpej 	return sys_readlink(l, uap, retval);
    900   1.2      fvdl }
    901   1.2      fvdl 
    902  1.67      manu #if !defined(__amd64__)
    903   1.2      fvdl int
    904  1.56   thorpej linux_sys_truncate(l, v, retval)
    905  1.56   thorpej 	struct lwp *l;
    906  1.11   thorpej 	void *v;
    907  1.11   thorpej 	register_t *retval;
    908  1.11   thorpej {
    909  1.12   mycroft 	struct linux_sys_truncate_args /* {
    910  1.27  christos 		syscallarg(const char *) path;
    911   1.2      fvdl 		syscallarg(long) length;
    912  1.11   thorpej 	} */ *uap = v;
    913  1.12   mycroft 
    914  1.56   thorpej 	return compat_43_sys_truncate(l, uap, retval);
    915  1.15      fvdl }
    916  1.67      manu #endif /* !__amd64__ */
    917  1.15      fvdl 
    918  1.15      fvdl /*
    919  1.15      fvdl  * This is just fsync() for now (just as it is in the Linux kernel)
    920  1.23       erh  * Note: this is not implemented under Linux on Alpha and Arm
    921  1.23       erh  *	but should still be defined in our syscalls.master.
    922  1.23       erh  *	(syscall #148 on the arm)
    923  1.15      fvdl  */
    924  1.15      fvdl int
    925  1.56   thorpej linux_sys_fdatasync(l, v, retval)
    926  1.56   thorpej 	struct lwp *l;
    927  1.15      fvdl 	void *v;
    928  1.15      fvdl 	register_t *retval;
    929  1.15      fvdl {
    930  1.16  christos #ifdef notdef
    931  1.15      fvdl 	struct linux_sys_fdatasync_args /* {
    932  1.15      fvdl 		syscallarg(int) fd;
    933  1.15      fvdl 	} */ *uap = v;
    934  1.16  christos #endif
    935  1.56   thorpej 	return sys_fsync(l, v, retval);
    936  1.28      tron }
    937  1.28      tron 
    938  1.28      tron /*
    939  1.28      tron  * pread(2).
    940  1.28      tron  */
    941  1.28      tron int
    942  1.56   thorpej linux_sys_pread(l, v, retval)
    943  1.56   thorpej 	struct lwp *l;
    944  1.28      tron 	void *v;
    945  1.28      tron 	register_t *retval;
    946  1.28      tron {
    947  1.28      tron 	struct linux_sys_pread_args /* {
    948  1.28      tron 		syscallarg(int) fd;
    949  1.28      tron 		syscallarg(void *) buf;
    950  1.28      tron 		syscallarg(size_t) nbyte;
    951  1.28      tron 		syscallarg(linux_off_t) offset;
    952  1.28      tron 	} */ *uap = v;
    953  1.28      tron 	struct sys_pread_args pra;
    954  1.28      tron 
    955  1.28      tron 	SCARG(&pra, fd) = SCARG(uap, fd);
    956  1.28      tron 	SCARG(&pra, buf) = SCARG(uap, buf);
    957  1.28      tron 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    958  1.28      tron 	SCARG(&pra, offset) = SCARG(uap, offset);
    959  1.28      tron 
    960  1.62  jdolecek 	return sys_pread(l, &pra, retval);
    961  1.28      tron }
    962  1.28      tron 
    963  1.28      tron /*
    964  1.28      tron  * pwrite(2).
    965  1.28      tron  */
    966  1.28      tron int
    967  1.56   thorpej linux_sys_pwrite(l, v, retval)
    968  1.56   thorpej 	struct lwp *l;
    969  1.28      tron 	void *v;
    970  1.28      tron 	register_t *retval;
    971  1.28      tron {
    972  1.28      tron 	struct linux_sys_pwrite_args /* {
    973  1.28      tron 		syscallarg(int) fd;
    974  1.28      tron 		syscallarg(void *) buf;
    975  1.28      tron 		syscallarg(size_t) nbyte;
    976  1.28      tron 		syscallarg(linux_off_t) offset;
    977  1.28      tron 	} */ *uap = v;
    978  1.28      tron 	struct sys_pwrite_args pra;
    979  1.28      tron 
    980  1.28      tron 	SCARG(&pra, fd) = SCARG(uap, fd);
    981  1.28      tron 	SCARG(&pra, buf) = SCARG(uap, buf);
    982  1.28      tron 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    983  1.28      tron 	SCARG(&pra, offset) = SCARG(uap, offset);
    984  1.28      tron 
    985  1.62  jdolecek 	return sys_pwrite(l, &pra, retval);
    986   1.1      fvdl }
    987  1.68      fvdl 
    988  1.75  christos #define LINUX_NOT_SUPPORTED(fun) \
    989  1.75  christos int \
    990  1.76  christos fun(struct lwp *l, void *v, register_t *retval) \
    991  1.75  christos { \
    992  1.75  christos 	return EOPNOTSUPP; \
    993  1.75  christos }
    994  1.75  christos 
    995  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_setxattr)
    996  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_lsetxattr)
    997  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_fsetxattr)
    998  1.75  christos 
    999  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_getxattr)
   1000  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_lgetxattr)
   1001  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_fgetxattr)
   1002  1.75  christos 
   1003  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_listxattr)
   1004  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_llistxattr)
   1005  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_flistxattr)
   1006  1.75  christos 
   1007  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_removexattr)
   1008  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_lremovexattr)
   1009  1.75  christos LINUX_NOT_SUPPORTED(linux_sys_fremovexattr)
   1010