Home | History | Annotate | Line # | Download | only in common
linux_file.c revision 1.121
      1  1.121       ryo /*	$NetBSD: linux_file.c,v 1.121 2021/09/23 06:56:27 ryo Exp $	*/
      2   1.23       erh 
      3   1.23       erh /*-
      4   1.93        ad  * Copyright (c) 1995, 1998, 2008 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  *
     19   1.23       erh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.23       erh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.23       erh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.23       erh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.23       erh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.23       erh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.23       erh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.23       erh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.23       erh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.23       erh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.23       erh  * POSSIBILITY OF SUCH DAMAGE.
     30    1.1      fvdl  */
     31    1.1      fvdl 
     32   1.23       erh /*
     33   1.23       erh  * Functions in multiarch:
     34   1.23       erh  *	linux_sys_llseek	: linux_llseek.c
     35   1.23       erh  */
     36   1.43     lukem 
     37   1.43     lukem #include <sys/cdefs.h>
     38  1.121       ryo __KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.121 2021/09/23 06:56:27 ryo Exp $");
     39   1.23       erh 
     40    1.1      fvdl #include <sys/param.h>
     41    1.1      fvdl #include <sys/systm.h>
     42    1.1      fvdl #include <sys/namei.h>
     43    1.1      fvdl #include <sys/proc.h>
     44    1.1      fvdl #include <sys/file.h>
     45  1.103  christos #include <sys/fcntl.h>
     46    1.1      fvdl #include <sys/stat.h>
     47    1.1      fvdl #include <sys/filedesc.h>
     48    1.1      fvdl #include <sys/ioctl.h>
     49    1.1      fvdl #include <sys/kernel.h>
     50    1.1      fvdl #include <sys/mount.h>
     51   1.81       dsl #include <sys/namei.h>
     52   1.13      fvdl #include <sys/vnode.h>
     53   1.13      fvdl #include <sys/tty.h>
     54   1.39      manu #include <sys/socketvar.h>
     55   1.13      fvdl #include <sys/conf.h>
     56   1.41  jdolecek #include <sys/pipe.h>
     57    1.1      fvdl 
     58    1.1      fvdl #include <sys/syscallargs.h>
     59   1.81       dsl #include <sys/vfs_syscalls.h>
     60    1.1      fvdl 
     61   1.24  christos #include <compat/linux/common/linux_types.h>
     62   1.24  christos #include <compat/linux/common/linux_signal.h>
     63   1.24  christos #include <compat/linux/common/linux_fcntl.h>
     64   1.24  christos #include <compat/linux/common/linux_util.h>
     65   1.24  christos #include <compat/linux/common/linux_machdep.h>
     66   1.84     njoly #include <compat/linux/common/linux_ipc.h>
     67   1.84     njoly #include <compat/linux/common/linux_sem.h>
     68   1.24  christos 
     69    1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     70   1.14  christos 
     71   1.87       dsl static int bsd_to_linux_ioflags(int);
     72  1.121       ryo #if !defined(__aarch64__) && !defined(__amd64__)
     73   1.87       dsl static void bsd_to_linux_stat(struct stat *, struct linux_stat *);
     74   1.67      manu #endif
     75   1.14  christos 
     76   1.92       dsl conv_linux_flock(linux, flock)
     77   1.92       dsl 
     78    1.1      fvdl /*
     79    1.1      fvdl  * Some file-related calls are handled here. The usual flag conversion
     80    1.1      fvdl  * an structure conversion is done, and alternate emul path searching.
     81    1.1      fvdl  */
     82    1.1      fvdl 
     83    1.1      fvdl /*
     84    1.1      fvdl  * The next two functions convert between the Linux and NetBSD values
     85    1.1      fvdl  * of the flags used in open(2) and fcntl(2).
     86    1.1      fvdl  */
     87  1.112     njoly int
     88   1.88       dsl linux_to_bsd_ioflags(int lflags)
     89    1.1      fvdl {
     90    1.1      fvdl 	int res = 0;
     91    1.1      fvdl 
     92    1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_WRONLY, O_WRONLY);
     93    1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDONLY, O_RDONLY);
     94    1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDWR, O_RDWR);
     95  1.113     njoly 
     96    1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_CREAT, O_CREAT);
     97    1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_EXCL, O_EXCL);
     98    1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_NOCTTY, O_NOCTTY);
     99    1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_TRUNC, O_TRUNC);
    100  1.113     njoly 	res |= cvtto_bsd_mask(lflags, LINUX_O_APPEND, O_APPEND);
    101  1.113     njoly 	res |= cvtto_bsd_mask(lflags, LINUX_O_NONBLOCK, O_NONBLOCK);
    102    1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_NDELAY, O_NDELAY);
    103    1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_SYNC, O_FSYNC);
    104    1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_FASYNC, O_ASYNC);
    105  1.113     njoly 	res |= cvtto_bsd_mask(lflags, LINUX_O_DIRECT, O_DIRECT);
    106  1.100       chs 	res |= cvtto_bsd_mask(lflags, LINUX_O_DIRECTORY, O_DIRECTORY);
    107  1.113     njoly 	res |= cvtto_bsd_mask(lflags, LINUX_O_NOFOLLOW, O_NOFOLLOW);
    108  1.102  christos 	res |= cvtto_bsd_mask(lflags, LINUX_O_CLOEXEC, O_CLOEXEC);
    109    1.1      fvdl 
    110    1.1      fvdl 	return res;
    111    1.1      fvdl }
    112    1.1      fvdl 
    113    1.1      fvdl static int
    114   1.88       dsl bsd_to_linux_ioflags(int bflags)
    115    1.1      fvdl {
    116    1.1      fvdl 	int res = 0;
    117    1.1      fvdl 
    118    1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_WRONLY, LINUX_O_WRONLY);
    119    1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_RDONLY, LINUX_O_RDONLY);
    120    1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_RDWR, LINUX_O_RDWR);
    121  1.113     njoly 
    122    1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_CREAT, LINUX_O_CREAT);
    123    1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_EXCL, LINUX_O_EXCL);
    124    1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_NOCTTY, LINUX_O_NOCTTY);
    125    1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_TRUNC, LINUX_O_TRUNC);
    126  1.113     njoly 	res |= cvtto_linux_mask(bflags, O_APPEND, LINUX_O_APPEND);
    127  1.113     njoly 	res |= cvtto_linux_mask(bflags, O_NONBLOCK, LINUX_O_NONBLOCK);
    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.113     njoly 	res |= cvtto_linux_mask(bflags, O_DIRECT, LINUX_O_DIRECT);
    132  1.100       chs 	res |= cvtto_linux_mask(bflags, O_DIRECTORY, LINUX_O_DIRECTORY);
    133  1.113     njoly 	res |= cvtto_linux_mask(bflags, O_NOFOLLOW, LINUX_O_NOFOLLOW);
    134  1.102  christos 	res |= cvtto_linux_mask(bflags, O_CLOEXEC, LINUX_O_CLOEXEC);
    135    1.1      fvdl 
    136    1.1      fvdl 	return res;
    137    1.1      fvdl }
    138    1.1      fvdl 
    139  1.120   thorpej static inline off_t
    140  1.120   thorpej linux_hilo_to_off_t(unsigned long hi, unsigned long lo)
    141  1.120   thorpej {
    142  1.120   thorpej #ifdef _LP64
    143  1.120   thorpej 	/*
    144  1.120   thorpej 	 * Linux discards the "hi" portion on LP64 platforms; even though
    145  1.120   thorpej 	 * glibc puts of the upper 32-bits of the offset into the "hi"
    146  1.120   thorpej 	 * argument regardless, the "lo" argument has all the bits in
    147  1.120   thorpej 	 * this case.
    148  1.120   thorpej 	 */
    149  1.120   thorpej 	(void) hi;
    150  1.120   thorpej 	return (off_t)lo;
    151  1.120   thorpej #else
    152  1.120   thorpej 	return (((off_t)hi) << 32) | lo;
    153  1.120   thorpej #endif /* _LP64 */
    154  1.120   thorpej }
    155  1.120   thorpej 
    156  1.121       ryo #if !defined(__aarch64__)
    157    1.1      fvdl /*
    158    1.1      fvdl  * creat(2) is an obsolete function, but it's present as a Linux
    159    1.1      fvdl  * system call, so let's deal with it.
    160    1.1      fvdl  *
    161   1.23       erh  * Note: On the Alpha this doesn't really exist in Linux, but it's defined
    162   1.23       erh  * in syscalls.master anyway so this doesn't have to be special cased.
    163   1.23       erh  *
    164    1.1      fvdl  * Just call open(2) with the TRUNC, CREAT and WRONLY flags.
    165    1.1      fvdl  */
    166    1.1      fvdl int
    167   1.90       dsl linux_sys_creat(struct lwp *l, const struct linux_sys_creat_args *uap, register_t *retval)
    168   1.11   thorpej {
    169   1.90       dsl 	/* {
    170   1.27  christos 		syscallarg(const char *) path;
    171  1.108     njoly 		syscallarg(linux_umode_t) mode;
    172   1.90       dsl 	} */
    173   1.12   mycroft 	struct sys_open_args oa;
    174    1.1      fvdl 
    175    1.1      fvdl 	SCARG(&oa, path) = SCARG(uap, path);
    176    1.1      fvdl 	SCARG(&oa, flags) = O_CREAT | O_TRUNC | O_WRONLY;
    177    1.1      fvdl 	SCARG(&oa, mode) = SCARG(uap, mode);
    178   1.12   mycroft 
    179   1.56   thorpej 	return sys_open(l, &oa, retval);
    180    1.1      fvdl }
    181  1.121       ryo #endif
    182    1.1      fvdl 
    183  1.106       chs static void
    184  1.106       chs linux_open_ctty(struct lwp *l, int flags, int fd)
    185  1.106       chs {
    186  1.106       chs 	struct proc *p = l->l_proc;
    187  1.106       chs 
    188  1.106       chs 	/*
    189  1.106       chs 	 * this bit from sunos_misc.c (and svr4_fcntl.c).
    190  1.106       chs 	 * If we are a session leader, and we don't have a controlling
    191  1.106       chs 	 * terminal yet, and the O_NOCTTY flag is not set, try to make
    192  1.106       chs 	 * this the controlling terminal.
    193  1.106       chs 	 */
    194  1.106       chs         if (!(flags & O_NOCTTY) && SESS_LEADER(p) && !(p->p_lflag & PL_CONTROLT)) {
    195  1.106       chs                 file_t *fp;
    196  1.106       chs 
    197  1.106       chs 		fp = fd_getfile(fd);
    198  1.106       chs 
    199  1.106       chs                 /* ignore any error, just give it a try */
    200  1.106       chs                 if (fp != NULL) {
    201  1.106       chs 			if (fp->f_type == DTYPE_VNODE) {
    202  1.106       chs 				(fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, NULL);
    203  1.106       chs 			}
    204  1.106       chs 			fd_putfile(fd);
    205  1.106       chs 		}
    206  1.106       chs         }
    207  1.106       chs }
    208  1.106       chs 
    209  1.121       ryo #if !defined(__aarch64__)
    210    1.1      fvdl /*
    211    1.1      fvdl  * open(2). Take care of the different flag values, and let the
    212    1.1      fvdl  * NetBSD syscall do the real work. See if this operation
    213    1.1      fvdl  * gives the current process a controlling terminal.
    214    1.1      fvdl  * (XXX is this necessary?)
    215    1.1      fvdl  */
    216    1.1      fvdl int
    217   1.90       dsl linux_sys_open(struct lwp *l, const struct linux_sys_open_args *uap, register_t *retval)
    218   1.11   thorpej {
    219   1.90       dsl 	/* {
    220   1.27  christos 		syscallarg(const char *) path;
    221    1.1      fvdl 		syscallarg(int) flags;
    222  1.108     njoly 		syscallarg(linux_umode_t) mode;
    223   1.90       dsl 	} */
    224    1.1      fvdl 	int error, fl;
    225   1.12   mycroft 	struct sys_open_args boa;
    226    1.1      fvdl 
    227    1.2      fvdl 	fl = linux_to_bsd_ioflags(SCARG(uap, flags));
    228    1.1      fvdl 
    229    1.1      fvdl 	SCARG(&boa, path) = SCARG(uap, path);
    230    1.1      fvdl 	SCARG(&boa, flags) = fl;
    231    1.1      fvdl 	SCARG(&boa, mode) = SCARG(uap, mode);
    232    1.2      fvdl 
    233   1.56   thorpej 	if ((error = sys_open(l, &boa, retval)))
    234  1.113     njoly 		return (error == EFTYPE) ? ELOOP : error;
    235    1.1      fvdl 
    236  1.106       chs 	linux_open_ctty(l, fl, *retval);
    237  1.106       chs 	return 0;
    238  1.106       chs }
    239  1.121       ryo #endif
    240  1.106       chs 
    241  1.106       chs int
    242  1.106       chs linux_sys_openat(struct lwp *l, const struct linux_sys_openat_args *uap, register_t *retval)
    243  1.106       chs {
    244  1.106       chs 	/* {
    245  1.107     njoly 		syscallarg(int) fd;
    246  1.106       chs 		syscallarg(const char *) path;
    247  1.106       chs 		syscallarg(int) flags;
    248  1.108     njoly 		syscallarg(linux_umode_t) mode;
    249  1.106       chs 	} */
    250  1.106       chs 	int error, fl;
    251  1.106       chs 	struct sys_openat_args boa;
    252  1.106       chs 
    253  1.106       chs 	fl = linux_to_bsd_ioflags(SCARG(uap, flags));
    254  1.106       chs 
    255  1.106       chs 	SCARG(&boa, fd) = SCARG(uap, fd);
    256  1.106       chs 	SCARG(&boa, path) = SCARG(uap, path);
    257  1.106       chs 	SCARG(&boa, oflags) = fl;
    258  1.106       chs 	SCARG(&boa, mode) = SCARG(uap, mode);
    259   1.38   thorpej 
    260  1.106       chs 	if ((error = sys_openat(l, &boa, retval)))
    261  1.113     njoly 		return (error == EFTYPE) ? ELOOP : error;
    262    1.1      fvdl 
    263  1.106       chs 	linux_open_ctty(l, fl, *retval);
    264    1.1      fvdl 	return 0;
    265    1.1      fvdl }
    266    1.1      fvdl 
    267    1.1      fvdl /*
    268    1.1      fvdl  * Most actions in the fcntl() call are straightforward; simply
    269    1.1      fvdl  * pass control to the NetBSD system call. A few commands need
    270    1.1      fvdl  * conversions after the actual system call has done its work,
    271    1.1      fvdl  * because the flag values and lock structure are different.
    272    1.1      fvdl  */
    273    1.1      fvdl int
    274   1.90       dsl linux_sys_fcntl(struct lwp *l, const struct linux_sys_fcntl_args *uap, register_t *retval)
    275   1.11   thorpej {
    276   1.90       dsl 	/* {
    277    1.1      fvdl 		syscallarg(int) fd;
    278    1.1      fvdl 		syscallarg(int) cmd;
    279    1.1      fvdl 		syscallarg(void *) arg;
    280   1.90       dsl 	} */
    281   1.56   thorpej 	struct proc *p = l->l_proc;
    282   1.23       erh 	int fd, cmd, error;
    283   1.23       erh 	u_long val;
    284   1.83       dsl 	void *arg;
    285   1.12   mycroft 	struct sys_fcntl_args fca;
    286   1.93        ad 	file_t *fp;
    287   1.13      fvdl 	struct vnode *vp;
    288   1.13      fvdl 	struct vattr va;
    289   1.13      fvdl 	long pgid;
    290   1.13      fvdl 	struct pgrp *pgrp;
    291   1.94        ad 	struct tty *tp;
    292    1.1      fvdl 
    293    1.1      fvdl 	fd = SCARG(uap, fd);
    294    1.1      fvdl 	cmd = SCARG(uap, cmd);
    295   1.92       dsl 	arg = SCARG(uap, arg);
    296    1.1      fvdl 
    297    1.1      fvdl 	switch (cmd) {
    298   1.92       dsl 
    299    1.1      fvdl 	case LINUX_F_DUPFD:
    300    1.1      fvdl 		cmd = F_DUPFD;
    301    1.1      fvdl 		break;
    302   1.92       dsl 
    303    1.1      fvdl 	case LINUX_F_GETFD:
    304    1.1      fvdl 		cmd = F_GETFD;
    305    1.1      fvdl 		break;
    306   1.92       dsl 
    307    1.1      fvdl 	case LINUX_F_SETFD:
    308    1.1      fvdl 		cmd = F_SETFD;
    309    1.1      fvdl 		break;
    310   1.92       dsl 
    311    1.1      fvdl 	case LINUX_F_GETFL:
    312    1.1      fvdl 		SCARG(&fca, fd) = fd;
    313    1.1      fvdl 		SCARG(&fca, cmd) = F_GETFL;
    314    1.1      fvdl 		SCARG(&fca, arg) = arg;
    315   1.56   thorpej 		if ((error = sys_fcntl(l, &fca, retval)))
    316    1.1      fvdl 			return error;
    317    1.1      fvdl 		retval[0] = bsd_to_linux_ioflags(retval[0]);
    318    1.1      fvdl 		return 0;
    319   1.92       dsl 
    320   1.41  jdolecek 	case LINUX_F_SETFL: {
    321   1.93        ad 		file_t	*fp1 = NULL;
    322   1.41  jdolecek 
    323   1.23       erh 		val = linux_to_bsd_ioflags((unsigned long)SCARG(uap, arg));
    324   1.39      manu 		/*
    325   1.41  jdolecek 		 * Linux seems to have same semantics for sending SIGIO to the
    326   1.64       abs 		 * read side of socket, but slightly different semantics
    327   1.41  jdolecek 		 * for SIGIO to the write side.  Rather than sending the SIGIO
    328   1.41  jdolecek 		 * every time it's possible to write (directly) more data, it
    329   1.41  jdolecek 		 * only sends SIGIO if last write(2) failed due to insufficient
    330   1.41  jdolecek 		 * memory to hold the data. This is compatible enough
    331   1.41  jdolecek 		 * with NetBSD semantics to not do anything about the
    332   1.41  jdolecek 		 * difference.
    333   1.65     perry 		 *
    334   1.41  jdolecek 		 * Linux does NOT send SIGIO for pipes. Deal with socketpair
    335   1.41  jdolecek 		 * ones and DTYPE_PIPE ones. For these, we don't set
    336   1.41  jdolecek 		 * the underlying flags (we don't pass O_ASYNC flag down
    337   1.41  jdolecek 		 * to sys_fcntl()), but set the FASYNC flag for file descriptor,
    338   1.41  jdolecek 		 * so that F_GETFL would report the ASYNC i/o is on.
    339   1.39      manu 		 */
    340   1.41  jdolecek 		if (val & O_ASYNC) {
    341   1.93        ad 			if (((fp1 = fd_getfile(fd)) == NULL))
    342   1.39      manu 			    return (EBADF);
    343   1.69  christos 			if (((fp1->f_type == DTYPE_SOCKET) && fp1->f_data
    344   1.69  christos 			      && ((struct socket *)fp1->f_data)->so_state & SS_ISAPIPE)
    345   1.69  christos 			    || (fp1->f_type == DTYPE_PIPE))
    346   1.41  jdolecek 				val &= ~O_ASYNC;
    347   1.41  jdolecek 			else {
    348   1.41  jdolecek 				/* not a pipe, do not modify anything */
    349   1.93        ad 				fd_putfile(fd);
    350   1.69  christos 				fp1 = NULL;
    351   1.39      manu 			}
    352   1.41  jdolecek 		}
    353   1.41  jdolecek 
    354   1.41  jdolecek 		SCARG(&fca, fd) = fd;
    355   1.41  jdolecek 		SCARG(&fca, cmd) = F_SETFL;
    356   1.79  christos 		SCARG(&fca, arg) = (void *) val;
    357   1.39      manu 
    358   1.56   thorpej 		error = sys_fcntl(l, &fca, retval);
    359   1.41  jdolecek 
    360   1.41  jdolecek 		/* Now set the FASYNC flag for pipes */
    361   1.69  christos 		if (fp1) {
    362   1.93        ad 			if (!error) {
    363   1.93        ad 				mutex_enter(&fp1->f_lock);
    364   1.69  christos 				fp1->f_flag |= FASYNC;
    365   1.93        ad 				mutex_exit(&fp1->f_lock);
    366   1.93        ad 			}
    367   1.93        ad 			fd_putfile(fd);
    368   1.39      manu 		}
    369   1.41  jdolecek 
    370   1.41  jdolecek 		return (error);
    371   1.41  jdolecek 	    }
    372   1.92       dsl 
    373    1.1      fvdl 	case LINUX_F_GETLK:
    374   1.92       dsl 		do_linux_getlk(fd, cmd, arg, linux, flock);
    375   1.47  christos 
    376    1.1      fvdl 	case LINUX_F_SETLK:
    377    1.1      fvdl 	case LINUX_F_SETLKW:
    378   1.92       dsl 		do_linux_setlk(fd, cmd, arg, linux, flock, LINUX_F_SETLK);
    379   1.47  christos 
    380    1.1      fvdl 	case LINUX_F_SETOWN:
    381   1.65     perry 	case LINUX_F_GETOWN:
    382   1.13      fvdl 		/*
    383   1.49  jdolecek 		 * We need to route fcntl() for tty descriptors around normal
    384   1.49  jdolecek 		 * fcntl(), since NetBSD tty TIOC{G,S}PGRP semantics is too
    385   1.49  jdolecek 		 * restrictive for Linux F_{G,S}ETOWN. For non-tty descriptors,
    386   1.49  jdolecek 		 * this is not a problem.
    387   1.13      fvdl 		 */
    388   1.93        ad 		if ((fp = fd_getfile(fd)) == NULL)
    389   1.13      fvdl 			return EBADF;
    390   1.60  jdolecek 
    391   1.60  jdolecek 		/* Check it's a character device vnode */
    392   1.60  jdolecek 		if (fp->f_type != DTYPE_VNODE
    393   1.60  jdolecek 		    || (vp = (struct vnode *)fp->f_data) == NULL
    394   1.60  jdolecek 		    || vp->v_type != VCHR) {
    395   1.93        ad 			fd_putfile(fd);
    396   1.60  jdolecek 
    397   1.53   gehenna 	    not_tty:
    398   1.49  jdolecek 			/* Not a tty, proceed with common fcntl() */
    399   1.13      fvdl 			cmd = cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
    400   1.49  jdolecek 			break;
    401   1.49  jdolecek 		}
    402   1.47  christos 
    403  1.104   hannken 		vn_lock(vp, LK_SHARED | LK_RETRY);
    404   1.86     pooka 		error = VOP_GETATTR(vp, &va, l->l_cred);
    405  1.104   hannken 		VOP_UNLOCK(vp);
    406   1.60  jdolecek 
    407   1.93        ad 		fd_putfile(fd);
    408   1.60  jdolecek 
    409   1.60  jdolecek 		if (error)
    410   1.49  jdolecek 			return error;
    411   1.60  jdolecek 
    412   1.94        ad 		if ((tp = cdev_tty(va.va_rdev)) == NULL)
    413   1.53   gehenna 			goto not_tty;
    414   1.49  jdolecek 
    415   1.49  jdolecek 		/* set tty pg_id appropriately */
    416  1.118        ad 		mutex_enter(&proc_lock);
    417   1.49  jdolecek 		if (cmd == LINUX_F_GETOWN) {
    418   1.58       dsl 			retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
    419  1.118        ad 			mutex_exit(&proc_lock);
    420   1.49  jdolecek 			return 0;
    421   1.49  jdolecek 		}
    422   1.49  jdolecek 		if ((long)arg <= 0) {
    423   1.49  jdolecek 			pgid = -(long)arg;
    424   1.49  jdolecek 		} else {
    425   1.99     rmind 			struct proc *p1 = proc_find((long)arg);
    426   1.99     rmind 			if (p1 == NULL) {
    427  1.118        ad 				mutex_exit(&proc_lock);
    428   1.49  jdolecek 				return (ESRCH);
    429   1.99     rmind 			}
    430   1.49  jdolecek 			pgid = (long)p1->p_pgrp->pg_id;
    431   1.13      fvdl 		}
    432   1.99     rmind 		pgrp = pgrp_find(pgid);
    433   1.78       dsl 		if (pgrp == NULL || pgrp->pg_session != p->p_session) {
    434  1.118        ad 			mutex_exit(&proc_lock);
    435   1.49  jdolecek 			return EPERM;
    436   1.78       dsl 		}
    437   1.49  jdolecek 		tp->t_pgrp = pgrp;
    438  1.118        ad 		mutex_exit(&proc_lock);
    439   1.49  jdolecek 		return 0;
    440   1.47  christos 
    441  1.115     njoly 	case LINUX_F_DUPFD_CLOEXEC:
    442  1.115     njoly 		cmd = F_DUPFD_CLOEXEC;
    443  1.115     njoly 		break;
    444  1.115     njoly 
    445    1.1      fvdl 	default:
    446    1.1      fvdl 		return EOPNOTSUPP;
    447    1.1      fvdl 	}
    448    1.1      fvdl 
    449    1.1      fvdl 	SCARG(&fca, fd) = fd;
    450    1.1      fvdl 	SCARG(&fca, cmd) = cmd;
    451    1.1      fvdl 	SCARG(&fca, arg) = arg;
    452   1.12   mycroft 
    453   1.56   thorpej 	return sys_fcntl(l, &fca, retval);
    454    1.1      fvdl }
    455    1.1      fvdl 
    456  1.121       ryo #if !defined(__aarch64__) && !defined(__amd64__)
    457    1.1      fvdl /*
    458    1.1      fvdl  * Convert a NetBSD stat structure to a Linux stat structure.
    459    1.1      fvdl  * Only the order of the fields and the padding in the structure
    460    1.9      fvdl  * is different. linux_fakedev is a machine-dependent function
    461    1.9      fvdl  * which optionally converts device driver major/minor numbers
    462    1.9      fvdl  * (XXX horrible, but what can you do against code that compares
    463    1.9      fvdl  * things against constant major device numbers? sigh)
    464    1.1      fvdl  */
    465    1.1      fvdl static void
    466   1.88       dsl bsd_to_linux_stat(struct stat *bsp, struct linux_stat *lsp)
    467    1.1      fvdl {
    468   1.12   mycroft 
    469  1.119  riastrad 	memset(lsp, 0, sizeof(*lsp));
    470   1.45  christos 	lsp->lst_dev     = linux_fakedev(bsp->st_dev, 0);
    471    1.1      fvdl 	lsp->lst_ino     = bsp->st_ino;
    472   1.19  christos 	lsp->lst_mode    = (linux_mode_t)bsp->st_mode;
    473   1.19  christos 	if (bsp->st_nlink >= (1 << 15))
    474   1.19  christos 		lsp->lst_nlink = (1 << 15) - 1;
    475   1.19  christos 	else
    476   1.19  christos 		lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
    477    1.1      fvdl 	lsp->lst_uid     = bsp->st_uid;
    478    1.1      fvdl 	lsp->lst_gid     = bsp->st_gid;
    479   1.45  christos 	lsp->lst_rdev    = linux_fakedev(bsp->st_rdev, 1);
    480    1.1      fvdl 	lsp->lst_size    = bsp->st_size;
    481    1.1      fvdl 	lsp->lst_blksize = bsp->st_blksize;
    482    1.1      fvdl 	lsp->lst_blocks  = bsp->st_blocks;
    483    1.1      fvdl 	lsp->lst_atime   = bsp->st_atime;
    484    1.1      fvdl 	lsp->lst_mtime   = bsp->st_mtime;
    485    1.1      fvdl 	lsp->lst_ctime   = bsp->st_ctime;
    486   1.66  christos #ifdef LINUX_STAT_HAS_NSEC
    487   1.66  christos 	lsp->lst_atime_nsec   = bsp->st_atimensec;
    488   1.66  christos 	lsp->lst_mtime_nsec   = bsp->st_mtimensec;
    489   1.66  christos 	lsp->lst_ctime_nsec   = bsp->st_ctimensec;
    490   1.66  christos #endif
    491    1.1      fvdl }
    492    1.1      fvdl 
    493    1.1      fvdl /*
    494    1.1      fvdl  * The stat functions below are plain sailing. stat and lstat are handled
    495    1.1      fvdl  * by one function to avoid code duplication.
    496    1.1      fvdl  */
    497    1.1      fvdl int
    498   1.90       dsl linux_sys_fstat(struct lwp *l, const struct linux_sys_fstat_args *uap, register_t *retval)
    499   1.11   thorpej {
    500   1.90       dsl 	/* {
    501    1.1      fvdl 		syscallarg(int) fd;
    502    1.1      fvdl 		syscallarg(linux_stat *) sp;
    503   1.90       dsl 	} */
    504    1.1      fvdl 	struct linux_stat tmplst;
    505   1.81       dsl 	struct stat tmpst;
    506    1.1      fvdl 	int error;
    507    1.1      fvdl 
    508   1.93        ad 	error = do_sys_fstat(SCARG(uap, fd), &tmpst);
    509   1.81       dsl 	if (error != 0)
    510    1.1      fvdl 		return error;
    511    1.1      fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    512    1.1      fvdl 
    513   1.81       dsl 	return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
    514    1.1      fvdl }
    515    1.1      fvdl 
    516    1.1      fvdl static int
    517   1.93        ad linux_stat1(const struct linux_sys_stat_args *uap, register_t *retval, int flags)
    518    1.1      fvdl {
    519    1.1      fvdl 	struct linux_stat tmplst;
    520   1.81       dsl 	struct stat tmpst;
    521    1.1      fvdl 	int error;
    522    1.1      fvdl 
    523   1.93        ad 	error = do_sys_stat(SCARG(uap, path), flags, &tmpst);
    524   1.81       dsl 	if (error != 0)
    525    1.1      fvdl 		return error;
    526    1.1      fvdl 
    527    1.1      fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    528    1.1      fvdl 
    529   1.81       dsl 	return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
    530    1.1      fvdl }
    531    1.1      fvdl 
    532    1.1      fvdl int
    533   1.90       dsl linux_sys_stat(struct lwp *l, const struct linux_sys_stat_args *uap, register_t *retval)
    534   1.11   thorpej {
    535   1.90       dsl 	/* {
    536   1.27  christos 		syscallarg(const char *) path;
    537    1.1      fvdl 		syscallarg(struct linux_stat *) sp;
    538   1.90       dsl 	} */
    539   1.11   thorpej 
    540   1.93        ad 	return linux_stat1(uap, retval, FOLLOW);
    541    1.1      fvdl }
    542    1.1      fvdl 
    543   1.23       erh /* Note: this is "newlstat" in the Linux sources */
    544   1.23       erh /*	(we don't bother with the old lstat currently) */
    545    1.1      fvdl int
    546   1.90       dsl linux_sys_lstat(struct lwp *l, const struct linux_sys_lstat_args *uap, register_t *retval)
    547   1.11   thorpej {
    548   1.90       dsl 	/* {
    549   1.27  christos 		syscallarg(const char *) path;
    550    1.1      fvdl 		syscallarg(struct linux_stat *) sp;
    551   1.90       dsl 	} */
    552   1.11   thorpej 
    553   1.93        ad 	return linux_stat1((const void *)uap, retval, NOFOLLOW);
    554    1.1      fvdl }
    555  1.121       ryo #endif /* !__aarch64__ && !__amd64__ */
    556    1.1      fvdl 
    557    1.1      fvdl /*
    558   1.10      fvdl  * The following syscalls are mostly here because of the alternate path check.
    559    1.1      fvdl  */
    560  1.106       chs 
    561    1.1      fvdl int
    562  1.106       chs linux_sys_linkat(struct lwp *l, const struct linux_sys_linkat_args *uap, register_t *retval)
    563    1.2      fvdl {
    564   1.90       dsl 	/* {
    565  1.106       chs 		syscallarg(int) fd1;
    566  1.106       chs 		syscallarg(const char *) name1;
    567  1.106       chs 		syscallarg(int) fd2;
    568  1.106       chs 		syscallarg(const char *) name2;
    569  1.106       chs 		syscallarg(int) flags;
    570   1.90       dsl 	} */
    571  1.106       chs 	int fd1 = SCARG(uap, fd1);
    572  1.106       chs 	const char *name1 = SCARG(uap, name1);
    573  1.106       chs 	int fd2 = SCARG(uap, fd2);
    574  1.106       chs 	const char *name2 = SCARG(uap, name2);
    575  1.106       chs 	int follow;
    576  1.106       chs 
    577  1.106       chs 	follow = SCARG(uap, flags) & LINUX_AT_SYMLINK_FOLLOW;
    578  1.106       chs 
    579  1.106       chs 	return do_sys_linkat(l, fd1, name1, fd2, name2, follow, retval);
    580  1.106       chs }
    581  1.106       chs 
    582  1.106       chs static int
    583  1.106       chs linux_unlink_dircheck(const char *path)
    584  1.106       chs {
    585  1.106       chs 	struct nameidata nd;
    586  1.101  dholland 	struct pathbuf *pb;
    587  1.106       chs 	int error;
    588   1.63  jdolecek 
    589   1.63  jdolecek 	/*
    590   1.63  jdolecek 	 * Linux returns EISDIR if unlink(2) is called on a directory.
    591   1.63  jdolecek 	 * We return EPERM in such cases. To emulate correct behaviour,
    592   1.63  jdolecek 	 * check if the path points to directory and return EISDIR if this
    593   1.63  jdolecek 	 * is the case.
    594  1.101  dholland 	 *
    595  1.101  dholland 	 * XXX this should really not copy in the path buffer twice...
    596   1.63  jdolecek 	 */
    597  1.106       chs 	error = pathbuf_copyin(path, &pb);
    598  1.106       chs 	if (error) {
    599  1.106       chs 		return error;
    600  1.101  dholland 	}
    601  1.101  dholland 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, pb);
    602   1.63  jdolecek 	if (namei(&nd) == 0) {
    603   1.63  jdolecek 		struct stat sb;
    604   1.63  jdolecek 
    605   1.93        ad 		if (vn_stat(nd.ni_vp, &sb) == 0
    606   1.63  jdolecek 		    && S_ISDIR(sb.st_mode))
    607   1.63  jdolecek 			error = EISDIR;
    608   1.63  jdolecek 
    609   1.63  jdolecek 		vput(nd.ni_vp);
    610   1.63  jdolecek 	}
    611  1.101  dholland 	pathbuf_destroy(pb);
    612  1.106       chs 	return error ? error : EPERM;
    613  1.106       chs }
    614   1.63  jdolecek 
    615  1.121       ryo #if !defined(__aarch64__)
    616  1.106       chs int
    617  1.106       chs linux_sys_unlink(struct lwp *l, const struct linux_sys_unlink_args *uap, register_t *retval)
    618  1.106       chs {
    619  1.106       chs 	/* {
    620  1.106       chs 		syscallarg(const char *) path;
    621  1.106       chs 	} */
    622  1.106       chs 	int error;
    623  1.106       chs 
    624  1.106       chs 	error = sys_unlink(l, (const void *)uap, retval);
    625  1.106       chs 	if (error == EPERM)
    626  1.106       chs 		error = linux_unlink_dircheck(SCARG(uap, path));
    627  1.106       chs 
    628  1.106       chs 	return error;
    629  1.106       chs }
    630  1.121       ryo #endif
    631  1.106       chs 
    632  1.106       chs int
    633  1.106       chs linux_sys_unlinkat(struct lwp *l, const struct linux_sys_unlinkat_args *uap, register_t *retval)
    634  1.106       chs {
    635  1.106       chs 	/* {
    636  1.106       chs 		syscallarg(int) fd;
    637  1.106       chs 		syscallarg(const char *) path;
    638  1.106       chs 		syscallarg(int) flag;
    639  1.106       chs 	} */
    640  1.106       chs 	struct sys_unlinkat_args ua;
    641  1.106       chs 	int error;
    642  1.106       chs 
    643  1.106       chs 	SCARG(&ua, fd) = SCARG(uap, fd);
    644  1.106       chs 	SCARG(&ua, path) = SCARG(uap, path);
    645  1.106       chs 	SCARG(&ua, flag) = linux_to_bsd_atflags(SCARG(uap, flag));
    646  1.106       chs 
    647  1.106       chs 	error = sys_unlinkat(l, &ua, retval);
    648  1.106       chs 	if (error == EPERM)
    649  1.106       chs 		error = linux_unlink_dircheck(SCARG(uap, path));
    650  1.106       chs 
    651  1.106       chs 	return error;
    652    1.2      fvdl }
    653    1.2      fvdl 
    654  1.121       ryo #if !defined(__aarch64__)
    655   1.10      fvdl int
    656   1.90       dsl linux_sys_mknod(struct lwp *l, const struct linux_sys_mknod_args *uap, register_t *retval)
    657   1.11   thorpej {
    658   1.90       dsl 	/* {
    659   1.27  christos 		syscallarg(const char *) path;
    660  1.106       chs 		syscallarg(linux_umode_t) mode;
    661  1.106       chs 		syscallarg(unsigned) dev;
    662  1.106       chs 	} */
    663  1.106       chs 	struct linux_sys_mknodat_args ua;
    664  1.106       chs 
    665  1.106       chs 	SCARG(&ua, fd) = LINUX_AT_FDCWD;
    666  1.106       chs 	SCARG(&ua, path) = SCARG(uap, path);
    667  1.106       chs 	SCARG(&ua, mode) = SCARG(uap, mode);
    668  1.106       chs 	SCARG(&ua, dev) = SCARG(uap, dev);
    669  1.106       chs 
    670  1.106       chs 	return linux_sys_mknodat(l, &ua, retval);
    671  1.106       chs }
    672  1.121       ryo #endif
    673  1.106       chs 
    674  1.106       chs int
    675  1.106       chs linux_sys_mknodat(struct lwp *l, const struct linux_sys_mknodat_args *uap, register_t *retval)
    676  1.106       chs {
    677  1.106       chs 	/* {
    678  1.106       chs 		syscallarg(int) fd;
    679  1.106       chs 		syscallarg(const char *) path;
    680  1.106       chs 		syscallarg(linux_umode_t) mode;
    681  1.106       chs 		syscallarg(unsigned) dev;
    682   1.90       dsl 	} */
    683    1.2      fvdl 
    684   1.10      fvdl 	/*
    685   1.40       wiz 	 * BSD handles FIFOs separately
    686   1.10      fvdl 	 */
    687   1.74     pavel 	if (S_ISFIFO(SCARG(uap, mode))) {
    688  1.106       chs 		struct sys_mkfifoat_args bma;
    689   1.54  jdolecek 
    690  1.106       chs 		SCARG(&bma, fd) = SCARG(uap, fd);
    691   1.21   thorpej 		SCARG(&bma, path) = SCARG(uap, path);
    692   1.21   thorpej 		SCARG(&bma, mode) = SCARG(uap, mode);
    693  1.106       chs 		return sys_mkfifoat(l, &bma, retval);
    694   1.54  jdolecek 	} else {
    695   1.54  jdolecek 
    696   1.54  jdolecek 		/*
    697   1.54  jdolecek 		 * Linux device numbers uses 8 bits for minor and 8 bits
    698   1.54  jdolecek 		 * for major. Due to how we map our major and minor,
    699   1.82       dsl 		 * this just fits into our dev_t. Just mask off the
    700   1.54  jdolecek 		 * upper 16bit to remove any random junk.
    701   1.54  jdolecek 		 */
    702  1.106       chs 
    703  1.106       chs 		return do_sys_mknodat(l, SCARG(uap, fd), SCARG(uap, path),
    704  1.116     kamil 		    SCARG(uap, mode), SCARG(uap, dev) & 0xffff, UIO_USERSPACE);
    705   1.54  jdolecek 	}
    706    1.2      fvdl }
    707    1.2      fvdl 
    708  1.106       chs int
    709  1.106       chs linux_sys_fchmodat(struct lwp *l, const struct linux_sys_fchmodat_args *uap, register_t *retval)
    710  1.106       chs {
    711  1.106       chs 	/* {
    712  1.106       chs 		syscallarg(int) fd;
    713  1.106       chs 		syscallarg(const char *) path;
    714  1.106       chs 		syscallarg(linux_umode_t) mode;
    715  1.106       chs 	} */
    716  1.106       chs 
    717  1.106       chs 	return do_sys_chmodat(l, SCARG(uap, fd), SCARG(uap, path),
    718  1.106       chs 			      SCARG(uap, mode), AT_SYMLINK_FOLLOW);
    719  1.106       chs }
    720  1.106       chs 
    721  1.106       chs int
    722  1.106       chs linux_sys_fchownat(struct lwp *l, const struct linux_sys_fchownat_args *uap, register_t *retval)
    723  1.106       chs {
    724  1.106       chs 	/* {
    725  1.106       chs 		syscallarg(int) fd;
    726  1.106       chs 		syscallarg(const char *) path;
    727  1.106       chs 		syscallarg(uid_t) owner;
    728  1.106       chs 		syscallarg(gid_t) group;
    729  1.106       chs 		syscallarg(int) flag;
    730  1.106       chs 	} */
    731  1.106       chs 	int flag;
    732  1.106       chs 
    733  1.106       chs 	flag = linux_to_bsd_atflags(SCARG(uap, flag));
    734  1.106       chs 	return do_sys_chownat(l, SCARG(uap, fd), SCARG(uap, path),
    735  1.106       chs 			      SCARG(uap, owner), SCARG(uap, group), flag);
    736  1.106       chs }
    737  1.106       chs 
    738  1.106       chs int
    739  1.106       chs linux_sys_faccessat(struct lwp *l, const struct linux_sys_faccessat_args *uap, register_t *retval)
    740  1.106       chs {
    741  1.106       chs 	/* {
    742  1.106       chs 		syscallarg(int) fd;
    743  1.106       chs 		syscallarg(const char *) path;
    744  1.106       chs 		syscallarg(int) amode;
    745  1.106       chs 	} */
    746  1.106       chs 
    747  1.106       chs 	return do_sys_accessat(l, SCARG(uap, fd), SCARG(uap, path),
    748  1.106       chs 	     SCARG(uap, amode), AT_SYMLINK_FOLLOW);
    749  1.106       chs }
    750  1.106       chs 
    751   1.15      fvdl /*
    752   1.15      fvdl  * This is just fsync() for now (just as it is in the Linux kernel)
    753   1.23       erh  * Note: this is not implemented under Linux on Alpha and Arm
    754   1.23       erh  *	but should still be defined in our syscalls.master.
    755   1.23       erh  *	(syscall #148 on the arm)
    756   1.15      fvdl  */
    757   1.15      fvdl int
    758   1.90       dsl linux_sys_fdatasync(struct lwp *l, const struct linux_sys_fdatasync_args *uap, register_t *retval)
    759   1.15      fvdl {
    760   1.90       dsl 	/* {
    761   1.15      fvdl 		syscallarg(int) fd;
    762   1.90       dsl 	} */
    763   1.90       dsl 
    764   1.90       dsl 	return sys_fsync(l, (const void *)uap, retval);
    765   1.28      tron }
    766   1.28      tron 
    767   1.28      tron /*
    768   1.28      tron  * pread(2).
    769   1.28      tron  */
    770   1.28      tron int
    771   1.90       dsl linux_sys_pread(struct lwp *l, const struct linux_sys_pread_args *uap, register_t *retval)
    772   1.28      tron {
    773   1.90       dsl 	/* {
    774   1.28      tron 		syscallarg(int) fd;
    775   1.28      tron 		syscallarg(void *) buf;
    776   1.28      tron 		syscallarg(size_t) nbyte;
    777  1.109     njoly 		syscallarg(off_t) offset;
    778   1.90       dsl 	} */
    779   1.28      tron 	struct sys_pread_args pra;
    780   1.28      tron 
    781   1.28      tron 	SCARG(&pra, fd) = SCARG(uap, fd);
    782   1.28      tron 	SCARG(&pra, buf) = SCARG(uap, buf);
    783   1.28      tron 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    784  1.109     njoly 	SCARG(&pra, PAD) = 0;
    785   1.28      tron 	SCARG(&pra, offset) = SCARG(uap, offset);
    786   1.28      tron 
    787   1.62  jdolecek 	return sys_pread(l, &pra, retval);
    788   1.28      tron }
    789   1.28      tron 
    790   1.28      tron /*
    791   1.28      tron  * pwrite(2).
    792   1.28      tron  */
    793   1.28      tron int
    794   1.90       dsl linux_sys_pwrite(struct lwp *l, const struct linux_sys_pwrite_args *uap, register_t *retval)
    795   1.28      tron {
    796   1.90       dsl 	/* {
    797   1.28      tron 		syscallarg(int) fd;
    798   1.28      tron 		syscallarg(void *) buf;
    799   1.28      tron 		syscallarg(size_t) nbyte;
    800  1.110     njoly 		syscallarg(off_t) offset;
    801   1.90       dsl 	} */
    802   1.28      tron 	struct sys_pwrite_args pra;
    803   1.28      tron 
    804   1.28      tron 	SCARG(&pra, fd) = SCARG(uap, fd);
    805   1.28      tron 	SCARG(&pra, buf) = SCARG(uap, buf);
    806   1.28      tron 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    807  1.109     njoly 	SCARG(&pra, PAD) = 0;
    808   1.28      tron 	SCARG(&pra, offset) = SCARG(uap, offset);
    809   1.28      tron 
    810   1.62  jdolecek 	return sys_pwrite(l, &pra, retval);
    811    1.1      fvdl }
    812   1.68      fvdl 
    813  1.120   thorpej /*
    814  1.120   thorpej  * preadv(2)
    815  1.120   thorpej  */
    816  1.120   thorpej int
    817  1.120   thorpej linux_sys_preadv(struct lwp *l, const struct linux_sys_preadv_args *uap,
    818  1.120   thorpej     register_t *retval)
    819  1.120   thorpej {
    820  1.120   thorpej 	/* {
    821  1.120   thorpej 		syscallarg(int) fd;
    822  1.120   thorpej 		syscallarg(const struct iovec *) iovp;
    823  1.120   thorpej 		syscallarg(int) iovcnt;
    824  1.120   thorpej 		syscallarg(unsigned long) off_lo;
    825  1.120   thorpej 		syscallarg(unsigned long) off_hi;
    826  1.120   thorpej 	} */
    827  1.120   thorpej 	struct sys_preadv_args ua;
    828  1.120   thorpej 
    829  1.120   thorpej 	SCARG(&ua, fd) = SCARG(uap, fd);
    830  1.120   thorpej 	SCARG(&ua, iovp) = SCARG(uap, iovp);
    831  1.120   thorpej 	SCARG(&ua, iovcnt) = SCARG(uap, iovcnt);
    832  1.120   thorpej 	SCARG(&ua, PAD) = 0;
    833  1.120   thorpej 	SCARG(&ua, offset) = linux_hilo_to_off_t(SCARG(uap, off_hi),
    834  1.120   thorpej 						 SCARG(uap, off_lo));
    835  1.120   thorpej 	return sys_preadv(l, &ua, retval);
    836  1.120   thorpej }
    837  1.120   thorpej 
    838  1.120   thorpej /*
    839  1.120   thorpej  * pwritev(2)
    840  1.120   thorpej  */
    841  1.120   thorpej int
    842  1.120   thorpej linux_sys_pwritev(struct lwp *l, const struct linux_sys_pwritev_args *uap,
    843  1.120   thorpej     register_t *retval)
    844  1.120   thorpej {
    845  1.120   thorpej 	/* {
    846  1.120   thorpej 		syscallarg(int) fd;
    847  1.120   thorpej 		syscallarg(const struct iovec *) iovp;
    848  1.120   thorpej 		syscallarg(int) iovcnt;
    849  1.120   thorpej 		syscallarg(unsigned long) off_lo;
    850  1.120   thorpej 		syscallarg(unsigned long) off_hi;
    851  1.120   thorpej 	} */
    852  1.120   thorpej 	struct sys_pwritev_args ua;
    853  1.120   thorpej 
    854  1.120   thorpej 	SCARG(&ua, fd) = SCARG(uap, fd);
    855  1.120   thorpej 	SCARG(&ua, iovp) = (const void *)SCARG(uap, iovp);
    856  1.120   thorpej 	SCARG(&ua, iovcnt) = SCARG(uap, iovcnt);
    857  1.120   thorpej 	SCARG(&ua, PAD) = 0;
    858  1.120   thorpej 	SCARG(&ua, offset) = linux_hilo_to_off_t(SCARG(uap, off_hi),
    859  1.120   thorpej 						 SCARG(uap, off_lo));
    860  1.120   thorpej 	return sys_pwritev(l, &ua, retval);
    861  1.120   thorpej }
    862  1.120   thorpej 
    863  1.103  christos int
    864  1.103  christos linux_sys_dup3(struct lwp *l, const struct linux_sys_dup3_args *uap,
    865  1.103  christos     register_t *retval)
    866  1.103  christos {
    867  1.103  christos 	/* {
    868  1.103  christos 		syscallarg(int) from;
    869  1.103  christos 		syscallarg(int) to;
    870  1.103  christos 		syscallarg(int) flags;
    871  1.103  christos 	} */
    872  1.111     njoly 	int flags;
    873  1.111     njoly 
    874  1.111     njoly 	flags = linux_to_bsd_ioflags(SCARG(uap, flags));
    875  1.111     njoly 	if ((flags & ~O_CLOEXEC) != 0)
    876  1.111     njoly 		return EINVAL;
    877  1.103  christos 
    878  1.111     njoly 	if (SCARG(uap, from) == SCARG(uap, to))
    879  1.111     njoly 		return EINVAL;
    880  1.103  christos 
    881  1.111     njoly 	return dodup(l, SCARG(uap, from), SCARG(uap, to), flags, retval);
    882  1.103  christos }
    883  1.103  christos 
    884  1.105     njoly 
    885  1.105     njoly int
    886  1.105     njoly linux_to_bsd_atflags(int lflags)
    887  1.105     njoly {
    888  1.105     njoly 	int bflags = 0;
    889  1.105     njoly 
    890  1.105     njoly 	if (lflags & LINUX_AT_SYMLINK_NOFOLLOW)
    891  1.105     njoly 		bflags |= AT_SYMLINK_NOFOLLOW;
    892  1.105     njoly 	if (lflags & LINUX_AT_REMOVEDIR)
    893  1.105     njoly 		bflags |= AT_REMOVEDIR;
    894  1.105     njoly 	if (lflags & LINUX_AT_SYMLINK_FOLLOW)
    895  1.105     njoly 		bflags |= AT_SYMLINK_FOLLOW;
    896  1.105     njoly 
    897  1.105     njoly 	return bflags;
    898  1.105     njoly }
    899  1.105     njoly 
    900  1.105     njoly 
    901   1.75  christos #define LINUX_NOT_SUPPORTED(fun) \
    902   1.75  christos int \
    903   1.90       dsl fun(struct lwp *l, const struct fun##_args *uap, register_t *retval) \
    904   1.75  christos { \
    905   1.75  christos 	return EOPNOTSUPP; \
    906   1.75  christos }
    907   1.75  christos 
    908   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_setxattr)
    909   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_lsetxattr)
    910   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_fsetxattr)
    911   1.75  christos 
    912   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_getxattr)
    913   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_lgetxattr)
    914   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_fgetxattr)
    915   1.75  christos 
    916   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_listxattr)
    917   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_llistxattr)
    918   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_flistxattr)
    919   1.75  christos 
    920   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_removexattr)
    921   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_lremovexattr)
    922   1.75  christos LINUX_NOT_SUPPORTED(linux_sys_fremovexattr)
    923  1.117  jdolecek 
    924  1.117  jdolecek /*
    925  1.117  jdolecek  * For now just return EOPNOTSUPP, this makes glibc posix_fallocate()
    926  1.117  jdolecek  * to fallback to emulation.
    927  1.117  jdolecek  * XXX Right now no filesystem actually implements fallocate support,
    928  1.117  jdolecek  * so no need for mapping.
    929  1.117  jdolecek  */
    930  1.117  jdolecek LINUX_NOT_SUPPORTED(linux_sys_fallocate)
    931