Home | History | Annotate | Line # | Download | only in common
linux_file.c revision 1.53
      1  1.53   gehenna /*	$NetBSD: linux_file.c,v 1.53 2002/09/06 13:18:43 gehenna 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.53   gehenna __KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.53 2002/09/06 13:18:43 gehenna 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.13      fvdl #include <sys/vnode.h>
     59  1.13      fvdl #include <sys/tty.h>
     60  1.39      manu #include <sys/socketvar.h>
     61  1.13      fvdl #include <sys/conf.h>
     62  1.41  jdolecek #include <sys/pipe.h>
     63   1.1      fvdl 
     64   1.1      fvdl #include <sys/syscallargs.h>
     65   1.1      fvdl 
     66  1.24  christos #include <compat/linux/common/linux_types.h>
     67  1.24  christos #include <compat/linux/common/linux_signal.h>
     68  1.24  christos #include <compat/linux/common/linux_fcntl.h>
     69  1.24  christos #include <compat/linux/common/linux_util.h>
     70  1.24  christos #include <compat/linux/common/linux_machdep.h>
     71  1.24  christos 
     72   1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     73  1.14  christos 
     74  1.14  christos static int linux_to_bsd_ioflags __P((int));
     75  1.14  christos static int bsd_to_linux_ioflags __P((int));
     76  1.14  christos static void bsd_to_linux_flock __P((struct flock *, struct linux_flock *));
     77  1.14  christos static void linux_to_bsd_flock __P((struct linux_flock *, struct flock *));
     78  1.14  christos static void bsd_to_linux_stat __P((struct stat *, struct linux_stat *));
     79  1.14  christos static int linux_stat1 __P((struct proc *, void *, register_t *, int));
     80  1.14  christos 
     81   1.1      fvdl /*
     82   1.1      fvdl  * Some file-related calls are handled here. The usual flag conversion
     83   1.1      fvdl  * an structure conversion is done, and alternate emul path searching.
     84   1.1      fvdl  */
     85   1.1      fvdl 
     86   1.1      fvdl /*
     87   1.1      fvdl  * The next two functions convert between the Linux and NetBSD values
     88   1.1      fvdl  * of the flags used in open(2) and fcntl(2).
     89   1.1      fvdl  */
     90   1.1      fvdl static int
     91  1.14  christos linux_to_bsd_ioflags(lflags)
     92  1.14  christos 	int lflags;
     93   1.1      fvdl {
     94   1.1      fvdl 	int res = 0;
     95   1.1      fvdl 
     96   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_WRONLY, O_WRONLY);
     97   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDONLY, O_RDONLY);
     98   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDWR, O_RDWR);
     99   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_CREAT, O_CREAT);
    100   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_EXCL, O_EXCL);
    101   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_NOCTTY, O_NOCTTY);
    102   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_TRUNC, O_TRUNC);
    103   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_NDELAY, O_NDELAY);
    104   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_SYNC, O_FSYNC);
    105   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_FASYNC, O_ASYNC);
    106   1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_APPEND, O_APPEND);
    107   1.1      fvdl 
    108   1.1      fvdl 	return res;
    109   1.1      fvdl }
    110   1.1      fvdl 
    111   1.1      fvdl static int
    112  1.14  christos bsd_to_linux_ioflags(bflags)
    113  1.14  christos 	int bflags;
    114   1.1      fvdl {
    115   1.1      fvdl 	int res = 0;
    116   1.1      fvdl 
    117   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_WRONLY, LINUX_O_WRONLY);
    118   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_RDONLY, LINUX_O_RDONLY);
    119   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_RDWR, LINUX_O_RDWR);
    120   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_CREAT, LINUX_O_CREAT);
    121   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_EXCL, LINUX_O_EXCL);
    122   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_NOCTTY, LINUX_O_NOCTTY);
    123   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_TRUNC, LINUX_O_TRUNC);
    124   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_NDELAY, LINUX_O_NDELAY);
    125   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_FSYNC, LINUX_O_SYNC);
    126   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_ASYNC, LINUX_FASYNC);
    127   1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_APPEND, LINUX_O_APPEND);
    128   1.1      fvdl 
    129   1.1      fvdl 	return res;
    130   1.1      fvdl }
    131   1.1      fvdl 
    132   1.1      fvdl /*
    133   1.1      fvdl  * creat(2) is an obsolete function, but it's present as a Linux
    134   1.1      fvdl  * system call, so let's deal with it.
    135   1.1      fvdl  *
    136  1.23       erh  * Note: On the Alpha this doesn't really exist in Linux, but it's defined
    137  1.23       erh  * in syscalls.master anyway so this doesn't have to be special cased.
    138  1.23       erh  *
    139   1.1      fvdl  * Just call open(2) with the TRUNC, CREAT and WRONLY flags.
    140   1.1      fvdl  */
    141   1.1      fvdl int
    142  1.12   mycroft linux_sys_creat(p, v, retval)
    143   1.1      fvdl 	struct proc *p;
    144  1.11   thorpej 	void *v;
    145  1.11   thorpej 	register_t *retval;
    146  1.11   thorpej {
    147  1.12   mycroft 	struct linux_sys_creat_args /* {
    148  1.27  christos 		syscallarg(const char *) path;
    149   1.1      fvdl 		syscallarg(int) mode;
    150  1.11   thorpej 	} */ *uap = v;
    151  1.12   mycroft 	struct sys_open_args oa;
    152   1.1      fvdl 	caddr_t sg;
    153   1.1      fvdl 
    154  1.46  christos 	sg = stackgap_init(p, 0);
    155  1.30  jdolecek 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    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.12   mycroft 	return sys_open(p, &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.12   mycroft linux_sys_open(p, v, retval)
    172   1.1      fvdl 	struct proc *p;
    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.1      fvdl 	int error, fl;
    182  1.12   mycroft 	struct sys_open_args boa;
    183   1.1      fvdl 	caddr_t sg;
    184   1.1      fvdl 
    185  1.46  christos 	sg = stackgap_init(p, 0);
    186   1.1      fvdl 
    187   1.2      fvdl 	fl = linux_to_bsd_ioflags(SCARG(uap, flags));
    188   1.1      fvdl 
    189   1.2      fvdl 	if (fl & O_CREAT)
    190  1.30  jdolecek 		CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    191   1.2      fvdl 	else
    192  1.30  jdolecek 		CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    193   1.1      fvdl 
    194   1.1      fvdl 	SCARG(&boa, path) = SCARG(uap, path);
    195   1.1      fvdl 	SCARG(&boa, flags) = fl;
    196   1.1      fvdl 	SCARG(&boa, mode) = SCARG(uap, mode);
    197   1.2      fvdl 
    198  1.12   mycroft 	if ((error = sys_open(p, &boa, retval)))
    199   1.1      fvdl 		return error;
    200   1.1      fvdl 
    201   1.1      fvdl 	/*
    202   1.1      fvdl 	 * this bit from sunos_misc.c (and svr4_fcntl.c).
    203   1.1      fvdl 	 * If we are a session leader, and we don't have a controlling
    204   1.1      fvdl 	 * terminal yet, and the O_NOCTTY flag is not set, try to make
    205   1.1      fvdl 	 * this the controlling terminal.
    206   1.1      fvdl 	 */
    207   1.1      fvdl         if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
    208   1.1      fvdl                 struct filedesc *fdp = p->p_fd;
    209  1.38   thorpej                 struct file     *fp;
    210  1.38   thorpej 
    211  1.38   thorpej 		fp = fd_getfile(fdp, *retval);
    212   1.1      fvdl 
    213   1.1      fvdl                 /* ignore any error, just give it a try */
    214  1.38   thorpej                 if (fp != NULL && fp->f_type == DTYPE_VNODE)
    215   1.1      fvdl                         (fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, (caddr_t) 0, p);
    216   1.1      fvdl         }
    217   1.1      fvdl 	return 0;
    218   1.1      fvdl }
    219   1.1      fvdl 
    220   1.1      fvdl /*
    221   1.1      fvdl  * The next two functions take care of converting the flock
    222   1.1      fvdl  * structure back and forth between Linux and NetBSD format.
    223   1.1      fvdl  * The only difference in the structures is the order of
    224   1.1      fvdl  * the fields, and the 'whence' value.
    225   1.1      fvdl  */
    226   1.1      fvdl static void
    227   1.1      fvdl bsd_to_linux_flock(bfp, lfp)
    228   1.1      fvdl 	struct flock *bfp;
    229   1.1      fvdl 	struct linux_flock *lfp;
    230   1.1      fvdl {
    231  1.12   mycroft 
    232   1.1      fvdl 	lfp->l_start = bfp->l_start;
    233   1.1      fvdl 	lfp->l_len = bfp->l_len;
    234   1.1      fvdl 	lfp->l_pid = bfp->l_pid;
    235   1.3   mycroft 	lfp->l_whence = bfp->l_whence;
    236   1.3   mycroft 	switch (bfp->l_type) {
    237   1.1      fvdl 	case F_RDLCK:
    238   1.3   mycroft 		lfp->l_type = LINUX_F_RDLCK;
    239   1.1      fvdl 		break;
    240   1.1      fvdl 	case F_UNLCK:
    241   1.3   mycroft 		lfp->l_type = LINUX_F_UNLCK;
    242   1.1      fvdl 		break;
    243   1.1      fvdl 	case F_WRLCK:
    244   1.3   mycroft 		lfp->l_type = LINUX_F_WRLCK;
    245   1.1      fvdl 		break;
    246   1.1      fvdl 	}
    247   1.1      fvdl }
    248   1.1      fvdl 
    249   1.1      fvdl static void
    250   1.1      fvdl linux_to_bsd_flock(lfp, bfp)
    251   1.1      fvdl 	struct linux_flock *lfp;
    252   1.1      fvdl 	struct flock *bfp;
    253   1.1      fvdl {
    254  1.12   mycroft 
    255   1.1      fvdl 	bfp->l_start = lfp->l_start;
    256   1.1      fvdl 	bfp->l_len = lfp->l_len;
    257   1.1      fvdl 	bfp->l_pid = lfp->l_pid;
    258   1.3   mycroft 	bfp->l_whence = lfp->l_whence;
    259   1.3   mycroft 	switch (lfp->l_type) {
    260   1.1      fvdl 	case LINUX_F_RDLCK:
    261   1.3   mycroft 		bfp->l_type = F_RDLCK;
    262   1.1      fvdl 		break;
    263   1.1      fvdl 	case LINUX_F_UNLCK:
    264   1.3   mycroft 		bfp->l_type = F_UNLCK;
    265   1.1      fvdl 		break;
    266   1.1      fvdl 	case LINUX_F_WRLCK:
    267   1.3   mycroft 		bfp->l_type = F_WRLCK;
    268   1.1      fvdl 		break;
    269   1.1      fvdl 	}
    270   1.1      fvdl }
    271   1.1      fvdl 
    272   1.1      fvdl /*
    273   1.1      fvdl  * Most actions in the fcntl() call are straightforward; simply
    274   1.1      fvdl  * pass control to the NetBSD system call. A few commands need
    275   1.1      fvdl  * conversions after the actual system call has done its work,
    276   1.1      fvdl  * because the flag values and lock structure are different.
    277   1.1      fvdl  */
    278   1.1      fvdl int
    279  1.12   mycroft linux_sys_fcntl(p, v, retval)
    280   1.1      fvdl 	struct proc *p;
    281  1.11   thorpej 	void *v;
    282  1.11   thorpej 	register_t *retval;
    283  1.11   thorpej {
    284  1.12   mycroft 	struct linux_sys_fcntl_args /* {
    285   1.1      fvdl 		syscallarg(int) fd;
    286   1.1      fvdl 		syscallarg(int) cmd;
    287   1.1      fvdl 		syscallarg(void *) arg;
    288  1.11   thorpej 	} */ *uap = v;
    289  1.23       erh 	int fd, cmd, error;
    290  1.23       erh 	u_long val;
    291   1.1      fvdl 	caddr_t 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.1      fvdl 	arg = (caddr_t) 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.12   mycroft 		if ((error = sys_fcntl(p, &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.41  jdolecek 		struct file	*fp = NULL;
    328  1.41  jdolecek 
    329  1.23       erh 		val = linux_to_bsd_ioflags((unsigned long)SCARG(uap, arg));
    330  1.41  jdolecek 
    331  1.39      manu 		/*
    332  1.41  jdolecek 		 * Linux seems to have same semantics for sending SIGIO to the
    333  1.41  jdolecek 		 * read side of socket, but slighly different semantics
    334  1.41  jdolecek 		 * for SIGIO to the write side.  Rather than sending the SIGIO
    335  1.41  jdolecek 		 * every time it's possible to write (directly) more data, it
    336  1.41  jdolecek 		 * only sends SIGIO if last write(2) failed due to insufficient
    337  1.41  jdolecek 		 * memory to hold the data. This is compatible enough
    338  1.41  jdolecek 		 * with NetBSD semantics to not do anything about the
    339  1.41  jdolecek 		 * difference.
    340  1.39      manu 		 *
    341  1.41  jdolecek 		 * Linux does NOT send SIGIO for pipes. Deal with socketpair
    342  1.41  jdolecek 		 * ones and DTYPE_PIPE ones. For these, we don't set
    343  1.41  jdolecek 		 * the underlying flags (we don't pass O_ASYNC flag down
    344  1.41  jdolecek 		 * to sys_fcntl()), but set the FASYNC flag for file descriptor,
    345  1.41  jdolecek 		 * so that F_GETFL would report the ASYNC i/o is on.
    346  1.39      manu 		 */
    347  1.41  jdolecek 		if (val & O_ASYNC) {
    348  1.41  jdolecek 			if (((fp = fd_getfile(p->p_fd, fd)) == NULL))
    349  1.39      manu 			    return (EBADF);
    350  1.39      manu 
    351  1.39      manu 			FILE_USE(fp);
    352  1.39      manu 
    353  1.41  jdolecek 			if (((fp->f_type == DTYPE_SOCKET) && fp->f_data
    354  1.41  jdolecek 			      && ((struct socket *)fp->f_data)->so_state & SS_ISAPIPE)
    355  1.41  jdolecek 			    || (fp->f_type == DTYPE_PIPE))
    356  1.41  jdolecek 				val &= ~O_ASYNC;
    357  1.41  jdolecek 			else {
    358  1.41  jdolecek 				/* not a pipe, do not modify anything */
    359  1.41  jdolecek 				FILE_UNUSE(fp, p);
    360  1.41  jdolecek 				fp = NULL;
    361  1.39      manu 			}
    362  1.41  jdolecek 		}
    363  1.41  jdolecek 
    364  1.41  jdolecek 		SCARG(&fca, fd) = fd;
    365  1.41  jdolecek 		SCARG(&fca, cmd) = F_SETFL;
    366  1.41  jdolecek 		SCARG(&fca, arg) = (caddr_t) val;
    367  1.39      manu 
    368  1.41  jdolecek 		error = sys_fcntl(p, &fca, retval);
    369  1.41  jdolecek 
    370  1.41  jdolecek 		/* Now set the FASYNC flag for pipes */
    371  1.41  jdolecek 		if (fp) {
    372  1.41  jdolecek 			if (!error)
    373  1.41  jdolecek 				fp->f_flag |= FASYNC;
    374  1.39      manu 			FILE_UNUSE(fp, p);
    375  1.39      manu 		}
    376  1.41  jdolecek 
    377  1.41  jdolecek 		return (error);
    378  1.41  jdolecek 	    }
    379   1.1      fvdl 	case LINUX_F_GETLK:
    380  1.46  christos 		sg = stackgap_init(p, 0);
    381  1.46  christos 		bfp = (struct flock *) stackgap_alloc(p, &sg, sizeof *bfp);
    382  1.18    kleink 		if ((error = copyin(arg, &lfl, sizeof lfl)))
    383  1.18    kleink 			return error;
    384  1.18    kleink 		linux_to_bsd_flock(&lfl, &bfl);
    385  1.18    kleink 		if ((error = copyout(&bfl, bfp, sizeof bfl)))
    386  1.18    kleink 			return error;
    387   1.1      fvdl 		SCARG(&fca, fd) = fd;
    388   1.1      fvdl 		SCARG(&fca, cmd) = F_GETLK;
    389   1.1      fvdl 		SCARG(&fca, arg) = bfp;
    390  1.12   mycroft 		if ((error = sys_fcntl(p, &fca, retval)))
    391   1.1      fvdl 			return error;
    392   1.1      fvdl 		if ((error = copyin(bfp, &bfl, sizeof bfl)))
    393   1.1      fvdl 			return error;
    394   1.1      fvdl 		bsd_to_linux_flock(&bfl, &lfl);
    395   1.1      fvdl 		return copyout(&lfl, arg, sizeof lfl);
    396  1.47  christos 
    397   1.1      fvdl 	case LINUX_F_SETLK:
    398   1.1      fvdl 	case LINUX_F_SETLKW:
    399   1.1      fvdl 		cmd = (cmd == LINUX_F_SETLK ? F_SETLK : F_SETLKW);
    400   1.1      fvdl 		if ((error = copyin(arg, &lfl, sizeof lfl)))
    401   1.1      fvdl 			return error;
    402   1.1      fvdl 		linux_to_bsd_flock(&lfl, &bfl);
    403  1.46  christos 		sg = stackgap_init(p, 0);
    404  1.46  christos 		bfp = (struct flock *) stackgap_alloc(p, &sg, sizeof *bfp);
    405   1.1      fvdl 		if ((error = copyout(&bfl, bfp, sizeof bfl)))
    406   1.1      fvdl 			return error;
    407  1.51  christos 		arg = (caddr_t)bfp;
    408   1.1      fvdl 		break;
    409  1.47  christos 
    410   1.1      fvdl 	case LINUX_F_SETOWN:
    411  1.13      fvdl 	case LINUX_F_GETOWN:
    412  1.13      fvdl 		/*
    413  1.49  jdolecek 		 * We need to route fcntl() for tty descriptors around normal
    414  1.49  jdolecek 		 * fcntl(), since NetBSD tty TIOC{G,S}PGRP semantics is too
    415  1.49  jdolecek 		 * restrictive for Linux F_{G,S}ETOWN. For non-tty descriptors,
    416  1.49  jdolecek 		 * this is not a problem.
    417  1.13      fvdl 		 */
    418  1.13      fvdl 		fdp = p->p_fd;
    419  1.38   thorpej 		if ((fp = fd_getfile(fdp, fd)) == NULL)
    420  1.13      fvdl 			return EBADF;
    421  1.50  jdolecek 		/* FILE_USE() not needed here */
    422  1.49  jdolecek 		if (fp->f_type != DTYPE_VNODE) {
    423  1.53   gehenna 	    not_tty:
    424  1.49  jdolecek 			/* Not a tty, proceed with common fcntl() */
    425  1.13      fvdl 			cmd = cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
    426  1.49  jdolecek 			break;
    427  1.49  jdolecek 		}
    428  1.47  christos 
    429  1.49  jdolecek 		/* check that the vnode is a tty */
    430  1.49  jdolecek 		vp = (struct vnode *)fp->f_data;
    431  1.49  jdolecek 		if (vp->v_type != VCHR)
    432  1.53   gehenna 			goto not_tty;
    433  1.49  jdolecek 		if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)))
    434  1.49  jdolecek 			return error;
    435  1.53   gehenna 		cdev = cdevsw_lookup(va.va_rdev);
    436  1.53   gehenna 		if (cdev == NULL)
    437  1.53   gehenna 			return (ENXIO);
    438  1.53   gehenna 		d_tty = cdev->d_tty;
    439  1.49  jdolecek 		if (!d_tty || (!(tp = (*d_tty)(va.va_rdev))))
    440  1.53   gehenna 			goto not_tty;
    441  1.49  jdolecek 
    442  1.49  jdolecek 		/* set tty pg_id appropriately */
    443  1.49  jdolecek 		if (cmd == LINUX_F_GETOWN) {
    444  1.49  jdolecek 			retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
    445  1.49  jdolecek 			return 0;
    446  1.49  jdolecek 		}
    447  1.49  jdolecek 		if ((long)arg <= 0) {
    448  1.49  jdolecek 			pgid = -(long)arg;
    449  1.49  jdolecek 		} else {
    450  1.49  jdolecek 			struct proc *p1 = pfind((long)arg);
    451  1.49  jdolecek 			if (p1 == NULL)
    452  1.49  jdolecek 				return (ESRCH);
    453  1.49  jdolecek 			pgid = (long)p1->p_pgrp->pg_id;
    454  1.13      fvdl 		}
    455  1.49  jdolecek 		pgrp = pgfind(pgid);
    456  1.49  jdolecek 		if (pgrp == NULL || pgrp->pg_session != p->p_session)
    457  1.49  jdolecek 			return EPERM;
    458  1.49  jdolecek 		tp->t_pgrp = pgrp;
    459  1.49  jdolecek 		return 0;
    460  1.47  christos 
    461   1.1      fvdl 	default:
    462   1.1      fvdl 		return EOPNOTSUPP;
    463   1.1      fvdl 	}
    464   1.1      fvdl 
    465   1.1      fvdl 	SCARG(&fca, fd) = fd;
    466   1.1      fvdl 	SCARG(&fca, cmd) = cmd;
    467   1.1      fvdl 	SCARG(&fca, arg) = arg;
    468  1.12   mycroft 
    469  1.12   mycroft 	return sys_fcntl(p, &fca, retval);
    470   1.1      fvdl }
    471   1.1      fvdl 
    472   1.1      fvdl /*
    473   1.1      fvdl  * Convert a NetBSD stat structure to a Linux stat structure.
    474   1.1      fvdl  * Only the order of the fields and the padding in the structure
    475   1.9      fvdl  * is different. linux_fakedev is a machine-dependent function
    476   1.9      fvdl  * which optionally converts device driver major/minor numbers
    477   1.9      fvdl  * (XXX horrible, but what can you do against code that compares
    478   1.9      fvdl  * things against constant major device numbers? sigh)
    479   1.1      fvdl  */
    480   1.1      fvdl static void
    481   1.1      fvdl bsd_to_linux_stat(bsp, lsp)
    482   1.1      fvdl 	struct stat *bsp;
    483   1.1      fvdl 	struct linux_stat *lsp;
    484   1.1      fvdl {
    485  1.12   mycroft 
    486  1.45  christos 	lsp->lst_dev     = linux_fakedev(bsp->st_dev, 0);
    487   1.1      fvdl 	lsp->lst_ino     = bsp->st_ino;
    488  1.19  christos 	lsp->lst_mode    = (linux_mode_t)bsp->st_mode;
    489  1.19  christos 	if (bsp->st_nlink >= (1 << 15))
    490  1.19  christos 		lsp->lst_nlink = (1 << 15) - 1;
    491  1.19  christos 	else
    492  1.19  christos 		lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
    493   1.1      fvdl 	lsp->lst_uid     = bsp->st_uid;
    494   1.1      fvdl 	lsp->lst_gid     = bsp->st_gid;
    495  1.45  christos 	lsp->lst_rdev    = linux_fakedev(bsp->st_rdev, 1);
    496   1.1      fvdl 	lsp->lst_size    = bsp->st_size;
    497   1.1      fvdl 	lsp->lst_blksize = bsp->st_blksize;
    498   1.1      fvdl 	lsp->lst_blocks  = bsp->st_blocks;
    499   1.1      fvdl 	lsp->lst_atime   = bsp->st_atime;
    500   1.1      fvdl 	lsp->lst_mtime   = bsp->st_mtime;
    501   1.1      fvdl 	lsp->lst_ctime   = bsp->st_ctime;
    502   1.1      fvdl }
    503   1.1      fvdl 
    504   1.1      fvdl /*
    505   1.1      fvdl  * The stat functions below are plain sailing. stat and lstat are handled
    506   1.1      fvdl  * by one function to avoid code duplication.
    507   1.1      fvdl  */
    508   1.1      fvdl int
    509  1.12   mycroft linux_sys_fstat(p, v, retval)
    510   1.1      fvdl 	struct proc *p;
    511  1.11   thorpej 	void *v;
    512  1.11   thorpej 	register_t *retval;
    513  1.11   thorpej {
    514  1.12   mycroft 	struct linux_sys_fstat_args /* {
    515   1.1      fvdl 		syscallarg(int) fd;
    516   1.1      fvdl 		syscallarg(linux_stat *) sp;
    517  1.11   thorpej 	} */ *uap = v;
    518  1.21   thorpej 	struct sys___fstat13_args fsa;
    519   1.1      fvdl 	struct linux_stat tmplst;
    520   1.1      fvdl 	struct stat *st,tmpst;
    521   1.1      fvdl 	caddr_t sg;
    522   1.1      fvdl 	int error;
    523   1.1      fvdl 
    524  1.46  christos 	sg = stackgap_init(p, 0);
    525   1.1      fvdl 
    526  1.46  christos 	st = stackgap_alloc(p, &sg, sizeof (struct stat));
    527   1.1      fvdl 
    528   1.1      fvdl 	SCARG(&fsa, fd) = SCARG(uap, fd);
    529   1.1      fvdl 	SCARG(&fsa, sb) = st;
    530   1.1      fvdl 
    531  1.21   thorpej 	if ((error = sys___fstat13(p, &fsa, retval)))
    532   1.1      fvdl 		return error;
    533   1.1      fvdl 
    534   1.1      fvdl 	if ((error = copyin(st, &tmpst, sizeof tmpst)))
    535   1.1      fvdl 		return error;
    536   1.1      fvdl 
    537   1.1      fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    538   1.1      fvdl 
    539   1.1      fvdl 	if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
    540   1.1      fvdl 		return error;
    541   1.1      fvdl 
    542   1.1      fvdl 	return 0;
    543   1.1      fvdl }
    544   1.1      fvdl 
    545   1.1      fvdl static int
    546  1.14  christos linux_stat1(p, v, retval, dolstat)
    547   1.1      fvdl 	struct proc *p;
    548  1.14  christos 	void *v;
    549   1.1      fvdl 	register_t *retval;
    550   1.1      fvdl 	int dolstat;
    551   1.1      fvdl {
    552  1.21   thorpej 	struct sys___stat13_args sa;
    553   1.1      fvdl 	struct linux_stat tmplst;
    554   1.1      fvdl 	struct stat *st, tmpst;
    555   1.1      fvdl 	caddr_t sg;
    556   1.1      fvdl 	int error;
    557  1.14  christos 	struct linux_sys_stat_args *uap = v;
    558   1.1      fvdl 
    559  1.46  christos 	sg = stackgap_init(p, 0);
    560  1.46  christos 	st = stackgap_alloc(p, &sg, sizeof (struct stat));
    561  1.37  jdolecek 	if (dolstat)
    562  1.37  jdolecek 		CHECK_ALT_SYMLINK(p, &sg, SCARG(uap, path));
    563  1.37  jdolecek 	else
    564  1.37  jdolecek 		CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    565   1.1      fvdl 
    566   1.1      fvdl 	SCARG(&sa, ub) = st;
    567   1.1      fvdl 	SCARG(&sa, path) = SCARG(uap, path);
    568   1.1      fvdl 
    569  1.21   thorpej 	if ((error = (dolstat ? sys___lstat13(p, &sa, retval) :
    570  1.21   thorpej 				sys___stat13(p, &sa, retval))))
    571   1.1      fvdl 		return error;
    572   1.1      fvdl 
    573   1.1      fvdl 	if ((error = copyin(st, &tmpst, sizeof tmpst)))
    574   1.1      fvdl 		return error;
    575   1.1      fvdl 
    576   1.1      fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    577   1.1      fvdl 
    578   1.1      fvdl 	if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
    579   1.1      fvdl 		return error;
    580   1.1      fvdl 
    581   1.1      fvdl 	return 0;
    582   1.1      fvdl }
    583   1.1      fvdl 
    584   1.1      fvdl int
    585  1.12   mycroft linux_sys_stat(p, v, retval)
    586   1.1      fvdl 	struct proc *p;
    587  1.11   thorpej 	void *v;
    588  1.11   thorpej 	register_t *retval;
    589  1.11   thorpej {
    590  1.12   mycroft 	struct linux_sys_stat_args /* {
    591  1.27  christos 		syscallarg(const char *) path;
    592   1.1      fvdl 		syscallarg(struct linux_stat *) sp;
    593  1.11   thorpej 	} */ *uap = v;
    594  1.11   thorpej 
    595   1.1      fvdl 	return linux_stat1(p, uap, retval, 0);
    596   1.1      fvdl }
    597   1.1      fvdl 
    598  1.23       erh /* Note: this is "newlstat" in the Linux sources */
    599  1.23       erh /*	(we don't bother with the old lstat currently) */
    600   1.1      fvdl int
    601  1.12   mycroft linux_sys_lstat(p, v, retval)
    602   1.1      fvdl 	struct proc *p;
    603  1.11   thorpej 	void *v;
    604  1.11   thorpej 	register_t *retval;
    605  1.11   thorpej {
    606  1.12   mycroft 	struct linux_sys_lstat_args /* {
    607  1.27  christos 		syscallarg(const char *) path;
    608   1.1      fvdl 		syscallarg(struct linux_stat *) sp;
    609  1.11   thorpej 	} */ *uap = v;
    610  1.11   thorpej 
    611   1.1      fvdl 	return linux_stat1(p, uap, retval, 1);
    612   1.1      fvdl }
    613   1.1      fvdl 
    614   1.1      fvdl /*
    615  1.10      fvdl  * The following syscalls are mostly here because of the alternate path check.
    616   1.1      fvdl  */
    617   1.1      fvdl int
    618  1.12   mycroft linux_sys_access(p, v, retval)
    619   1.1      fvdl 	struct proc *p;
    620  1.11   thorpej 	void *v;
    621  1.11   thorpej 	register_t *retval;
    622  1.11   thorpej {
    623  1.12   mycroft 	struct linux_sys_access_args /* {
    624  1.27  christos 		syscallarg(const char *) path;
    625   1.1      fvdl 		syscallarg(int) flags;
    626  1.11   thorpej 	} */ *uap = v;
    627  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    628   1.1      fvdl 
    629  1.30  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    630   1.1      fvdl 
    631  1.12   mycroft 	return sys_access(p, uap, retval);
    632   1.2      fvdl }
    633   1.2      fvdl 
    634   1.2      fvdl int
    635  1.12   mycroft linux_sys_unlink(p, v, retval)
    636   1.2      fvdl 	struct proc *p;
    637  1.11   thorpej 	void *v;
    638   1.2      fvdl 	register_t *retval;
    639   1.2      fvdl 
    640   1.2      fvdl {
    641  1.12   mycroft 	struct linux_sys_unlink_args /* {
    642  1.27  christos 		syscallarg(const char *) path;
    643  1.11   thorpej 	} */ *uap = v;
    644  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    645   1.2      fvdl 
    646  1.30  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    647   1.2      fvdl 
    648  1.12   mycroft 	return sys_unlink(p, uap, retval);
    649   1.2      fvdl }
    650   1.2      fvdl 
    651  1.10      fvdl int
    652  1.12   mycroft linux_sys_chdir(p, v, retval)
    653   1.2      fvdl 	struct proc *p;
    654  1.11   thorpej 	void *v;
    655  1.11   thorpej 	register_t *retval;
    656  1.11   thorpej {
    657  1.12   mycroft 	struct linux_sys_chdir_args /* {
    658  1.27  christos 		syscallarg(const char *) path;
    659  1.11   thorpej 	} */ *uap = v;
    660  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    661   1.2      fvdl 
    662  1.30  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    663   1.2      fvdl 
    664  1.12   mycroft 	return sys_chdir(p, uap, retval);
    665   1.2      fvdl }
    666   1.2      fvdl 
    667   1.2      fvdl int
    668  1.12   mycroft linux_sys_mknod(p, v, retval)
    669   1.2      fvdl 	struct proc *p;
    670  1.11   thorpej 	void *v;
    671  1.11   thorpej 	register_t *retval;
    672  1.11   thorpej {
    673  1.12   mycroft 	struct linux_sys_mknod_args /* {
    674  1.27  christos 		syscallarg(const char *) path;
    675   1.2      fvdl 		syscallarg(int) mode;
    676   1.2      fvdl 		syscallarg(int) dev;
    677  1.11   thorpej 	} */ *uap = v;
    678  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    679  1.21   thorpej 	struct sys_mkfifo_args bma;
    680   1.2      fvdl 
    681  1.30  jdolecek 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    682   1.2      fvdl 
    683  1.10      fvdl 	/*
    684  1.40       wiz 	 * BSD handles FIFOs separately
    685  1.10      fvdl 	 */
    686  1.21   thorpej 	if (SCARG(uap, mode) & S_IFIFO) {
    687  1.21   thorpej 		SCARG(&bma, path) = SCARG(uap, path);
    688  1.21   thorpej 		SCARG(&bma, mode) = SCARG(uap, mode);
    689  1.21   thorpej 		return sys_mkfifo(p, uap, retval);
    690  1.21   thorpej 	} else
    691  1.21   thorpej 		return sys_mknod(p, uap, retval);
    692   1.2      fvdl }
    693   1.2      fvdl 
    694   1.2      fvdl int
    695  1.12   mycroft linux_sys_chmod(p, v, retval)
    696   1.2      fvdl 	struct proc *p;
    697  1.11   thorpej 	void *v;
    698  1.11   thorpej 	register_t *retval;
    699  1.11   thorpej {
    700  1.12   mycroft 	struct linux_sys_chmod_args /* {
    701  1.27  christos 		syscallarg(const char *) path;
    702   1.2      fvdl 		syscallarg(int) mode;
    703  1.11   thorpej 	} */ *uap = v;
    704  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    705   1.2      fvdl 
    706  1.30  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    707   1.2      fvdl 
    708  1.12   mycroft 	return sys_chmod(p, uap, retval);
    709   1.2      fvdl }
    710   1.2      fvdl 
    711  1.44     bjh21 #if defined(__i386__) || defined(__m68k__) || defined(__arm__)
    712   1.2      fvdl int
    713  1.31      fvdl linux_sys_chown16(p, v, retval)
    714   1.2      fvdl 	struct proc *p;
    715  1.11   thorpej 	void *v;
    716  1.11   thorpej 	register_t *retval;
    717  1.11   thorpej {
    718  1.31      fvdl 	struct linux_sys_chown16_args /* {
    719  1.27  christos 		syscallarg(const char *) path;
    720   1.2      fvdl 		syscallarg(int) uid;
    721   1.2      fvdl 		syscallarg(int) gid;
    722  1.11   thorpej 	} */ *uap = v;
    723  1.22    kleink 	struct sys___posix_chown_args bca;
    724  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    725   1.2      fvdl 
    726  1.30  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    727   1.2      fvdl 
    728  1.10      fvdl 	SCARG(&bca, path) = SCARG(uap, path);
    729  1.10      fvdl 	SCARG(&bca, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
    730  1.10      fvdl 		(uid_t)-1 : SCARG(uap, uid);
    731  1.10      fvdl 	SCARG(&bca, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
    732  1.10      fvdl 		(gid_t)-1 : SCARG(uap, gid);
    733  1.10      fvdl 
    734  1.22    kleink 	return sys___posix_chown(p, &bca, retval);
    735  1.10      fvdl }
    736  1.10      fvdl 
    737  1.10      fvdl int
    738  1.31      fvdl linux_sys_fchown16(p, v, retval)
    739  1.10      fvdl 	struct proc *p;
    740  1.11   thorpej 	void *v;
    741  1.11   thorpej 	register_t *retval;
    742  1.11   thorpej {
    743  1.31      fvdl 	struct linux_sys_fchown16_args /* {
    744  1.10      fvdl 		syscallarg(int) fd;
    745  1.10      fvdl 		syscallarg(int) uid;
    746  1.10      fvdl 		syscallarg(int) gid;
    747  1.11   thorpej 	} */ *uap = v;
    748  1.22    kleink 	struct sys___posix_fchown_args bfa;
    749  1.10      fvdl 
    750  1.10      fvdl 	SCARG(&bfa, fd) = SCARG(uap, fd);
    751  1.10      fvdl 	SCARG(&bfa, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
    752  1.10      fvdl 		(uid_t)-1 : SCARG(uap, uid);
    753  1.10      fvdl 	SCARG(&bfa, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
    754  1.10      fvdl 		(gid_t)-1 : SCARG(uap, gid);
    755  1.10      fvdl 
    756  1.22    kleink 	return sys___posix_fchown(p, &bfa, retval);
    757   1.2      fvdl }
    758   1.2      fvdl 
    759   1.2      fvdl int
    760  1.31      fvdl linux_sys_lchown16(p, v, retval)
    761  1.23       erh 	struct proc *p;
    762  1.23       erh 	void *v;
    763  1.23       erh 	register_t *retval;
    764  1.23       erh {
    765  1.31      fvdl 	struct linux_sys_lchown16_args /* {
    766  1.23       erh 		syscallarg(char *) path;
    767  1.23       erh 		syscallarg(int) uid;
    768  1.23       erh 		syscallarg(int) gid;
    769  1.23       erh 	} */ *uap = v;
    770  1.23       erh 	struct sys___posix_lchown_args bla;
    771  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    772  1.33      fvdl 
    773  1.36  jdolecek 	CHECK_ALT_SYMLINK(p, &sg, SCARG(uap, path));
    774  1.23       erh 
    775  1.23       erh 	SCARG(&bla, path) = SCARG(uap, path);
    776  1.23       erh 	SCARG(&bla, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
    777  1.23       erh 		(uid_t)-1 : SCARG(uap, uid);
    778  1.23       erh 	SCARG(&bla, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
    779  1.23       erh 		(gid_t)-1 : SCARG(uap, gid);
    780  1.23       erh 
    781  1.23       erh 	return sys___posix_lchown(p, &bla, retval);
    782  1.33      fvdl }
    783  1.44     bjh21 #endif /* __i386__ || __m68k__ || __arm__ */
    784  1.42      manu #if defined (__i386__) || defined (__m68k__) || \
    785  1.44     bjh21     defined (__powerpc__) || defined (__mips__) || defined(__arm__)
    786  1.33      fvdl int
    787  1.33      fvdl linux_sys_chown(p, v, retval)
    788  1.33      fvdl 	struct proc *p;
    789  1.33      fvdl 	void *v;
    790  1.33      fvdl 	register_t *retval;
    791  1.33      fvdl {
    792  1.33      fvdl 	struct linux_sys_chown_args /* {
    793  1.33      fvdl 		syscallarg(char *) path;
    794  1.33      fvdl 		syscallarg(int) uid;
    795  1.33      fvdl 		syscallarg(int) gid;
    796  1.33      fvdl 	} */ *uap = v;
    797  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    798  1.33      fvdl 
    799  1.33      fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    800  1.33      fvdl 
    801  1.33      fvdl 	return sys___posix_chown(p, uap, retval);
    802  1.33      fvdl }
    803  1.33      fvdl 
    804  1.33      fvdl int
    805  1.33      fvdl linux_sys_lchown(p, v, retval)
    806  1.33      fvdl 	struct proc *p;
    807  1.33      fvdl 	void *v;
    808  1.33      fvdl 	register_t *retval;
    809  1.33      fvdl {
    810  1.33      fvdl 	struct linux_sys_lchown_args /* {
    811  1.33      fvdl 		syscallarg(char *) path;
    812  1.33      fvdl 		syscallarg(int) uid;
    813  1.33      fvdl 		syscallarg(int) gid;
    814  1.33      fvdl 	} */ *uap = v;
    815  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    816  1.33      fvdl 
    817  1.36  jdolecek 	CHECK_ALT_SYMLINK(p, &sg, SCARG(uap, path));
    818  1.33      fvdl 
    819  1.33      fvdl 	return sys___posix_lchown(p, uap, retval);
    820  1.23       erh }
    821  1.44     bjh21 #endif /* __i386__ || __m68k__ || __powerpc__ || __mips__ || __arm__ */
    822  1.32   thorpej 
    823  1.23       erh int
    824  1.12   mycroft linux_sys_rename(p, v, retval)
    825   1.2      fvdl 	struct proc *p;
    826  1.11   thorpej 	void *v;
    827  1.11   thorpej 	register_t *retval;
    828  1.11   thorpej {
    829  1.12   mycroft 	struct linux_sys_rename_args /* {
    830  1.27  christos 		syscallarg(const char *) from;
    831  1.27  christos 		syscallarg(const char *) to;
    832  1.11   thorpej 	} */ *uap = v;
    833  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    834   1.2      fvdl 
    835  1.30  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, from));
    836  1.30  jdolecek 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
    837   1.2      fvdl 
    838  1.22    kleink 	return sys___posix_rename(p, uap, retval);
    839   1.2      fvdl }
    840   1.2      fvdl 
    841   1.2      fvdl int
    842  1.12   mycroft linux_sys_mkdir(p, v, retval)
    843   1.2      fvdl 	struct proc *p;
    844  1.11   thorpej 	void *v;
    845  1.11   thorpej 	register_t *retval;
    846  1.11   thorpej {
    847  1.12   mycroft 	struct linux_sys_mkdir_args /* {
    848  1.27  christos 		syscallarg(const char *) path;
    849   1.7      fvdl 		syscallarg(int) mode;
    850  1.11   thorpej 	} */ *uap = v;
    851  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    852   1.2      fvdl 
    853  1.30  jdolecek 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    854  1.12   mycroft 
    855  1.12   mycroft 	return sys_mkdir(p, uap, retval);
    856   1.2      fvdl }
    857   1.2      fvdl 
    858   1.2      fvdl int
    859  1.12   mycroft linux_sys_rmdir(p, v, retval)
    860   1.2      fvdl 	struct proc *p;
    861  1.11   thorpej 	void *v;
    862  1.11   thorpej 	register_t *retval;
    863  1.11   thorpej {
    864  1.12   mycroft 	struct linux_sys_rmdir_args /* {
    865  1.27  christos 		syscallarg(const char *) path;
    866  1.11   thorpej 	} */ *uap = v;
    867  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    868   1.2      fvdl 
    869  1.30  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    870  1.12   mycroft 
    871  1.12   mycroft 	return sys_rmdir(p, uap, retval);
    872   1.2      fvdl }
    873   1.2      fvdl 
    874   1.2      fvdl int
    875  1.12   mycroft linux_sys_symlink(p, v, retval)
    876   1.2      fvdl 	struct proc *p;
    877  1.11   thorpej 	void *v;
    878  1.11   thorpej 	register_t *retval;
    879  1.11   thorpej {
    880  1.12   mycroft 	struct linux_sys_symlink_args /* {
    881  1.27  christos 		syscallarg(const char *) path;
    882  1.27  christos 		syscallarg(const char *) to;
    883  1.11   thorpej 	} */ *uap = v;
    884  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    885   1.2      fvdl 
    886  1.30  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    887  1.30  jdolecek 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
    888   1.2      fvdl 
    889  1.12   mycroft 	return sys_symlink(p, uap, retval);
    890  1.34      fvdl }
    891  1.34      fvdl 
    892  1.34      fvdl int
    893  1.34      fvdl linux_sys_link(p, v, retval)
    894  1.34      fvdl 	struct proc *p;
    895  1.34      fvdl 	void *v;
    896  1.34      fvdl 	register_t *retval;
    897  1.34      fvdl {
    898  1.34      fvdl 	struct linux_sys_link_args /* {
    899  1.34      fvdl 		syscallarg(const char *) path;
    900  1.34      fvdl 		syscallarg(const char *) link;
    901  1.34      fvdl 	} */ *uap = v;
    902  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    903  1.34      fvdl 
    904  1.34      fvdl 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    905  1.34      fvdl 	CHECK_ALT_CREAT(p, &sg, SCARG(uap, link));
    906  1.34      fvdl 
    907  1.34      fvdl 	return sys_link(p, uap, retval);
    908   1.2      fvdl }
    909   1.2      fvdl 
    910   1.2      fvdl int
    911  1.12   mycroft linux_sys_readlink(p, v, retval)
    912   1.2      fvdl 	struct proc *p;
    913  1.11   thorpej 	void *v;
    914  1.11   thorpej 	register_t *retval;
    915  1.11   thorpej {
    916  1.12   mycroft 	struct linux_sys_readlink_args /* {
    917  1.27  christos 		syscallarg(const char *) name;
    918   1.2      fvdl 		syscallarg(char *) buf;
    919   1.2      fvdl 		syscallarg(int) count;
    920  1.11   thorpej 	} */ *uap = v;
    921  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    922   1.2      fvdl 
    923  1.36  jdolecek 	CHECK_ALT_SYMLINK(p, &sg, SCARG(uap, name));
    924  1.12   mycroft 
    925  1.12   mycroft 	return sys_readlink(p, uap, retval);
    926   1.2      fvdl }
    927   1.2      fvdl 
    928   1.2      fvdl int
    929  1.12   mycroft linux_sys_truncate(p, v, retval)
    930   1.2      fvdl 	struct proc *p;
    931  1.11   thorpej 	void *v;
    932  1.11   thorpej 	register_t *retval;
    933  1.11   thorpej {
    934  1.12   mycroft 	struct linux_sys_truncate_args /* {
    935  1.27  christos 		syscallarg(const char *) path;
    936   1.2      fvdl 		syscallarg(long) length;
    937  1.11   thorpej 	} */ *uap = v;
    938  1.46  christos 	caddr_t sg = stackgap_init(p, 0);
    939   1.2      fvdl 
    940  1.30  jdolecek 	CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    941  1.12   mycroft 
    942  1.12   mycroft 	return compat_43_sys_truncate(p, uap, retval);
    943  1.15      fvdl }
    944  1.15      fvdl 
    945  1.15      fvdl /*
    946  1.15      fvdl  * This is just fsync() for now (just as it is in the Linux kernel)
    947  1.23       erh  * Note: this is not implemented under Linux on Alpha and Arm
    948  1.23       erh  *	but should still be defined in our syscalls.master.
    949  1.23       erh  *	(syscall #148 on the arm)
    950  1.15      fvdl  */
    951  1.15      fvdl int
    952  1.15      fvdl linux_sys_fdatasync(p, v, retval)
    953  1.15      fvdl 	struct proc *p;
    954  1.15      fvdl 	void *v;
    955  1.15      fvdl 	register_t *retval;
    956  1.15      fvdl {
    957  1.16  christos #ifdef notdef
    958  1.15      fvdl 	struct linux_sys_fdatasync_args /* {
    959  1.15      fvdl 		syscallarg(int) fd;
    960  1.15      fvdl 	} */ *uap = v;
    961  1.16  christos #endif
    962  1.15      fvdl 	return sys_fsync(p, v, retval);
    963  1.28      tron }
    964  1.28      tron 
    965  1.28      tron /*
    966  1.28      tron  * pread(2).
    967  1.28      tron  */
    968  1.28      tron int
    969  1.28      tron linux_sys_pread(p, v, retval)
    970  1.28      tron 	struct proc *p;
    971  1.28      tron 	void *v;
    972  1.28      tron 	register_t *retval;
    973  1.28      tron {
    974  1.28      tron 	struct linux_sys_pread_args /* {
    975  1.28      tron 		syscallarg(int) fd;
    976  1.28      tron 		syscallarg(void *) buf;
    977  1.28      tron 		syscallarg(size_t) nbyte;
    978  1.28      tron 		syscallarg(linux_off_t) offset;
    979  1.28      tron 	} */ *uap = v;
    980  1.28      tron 	struct sys_pread_args pra;
    981  1.28      tron 
    982  1.28      tron 	SCARG(&pra, fd) = SCARG(uap, fd);
    983  1.28      tron 	SCARG(&pra, buf) = SCARG(uap, buf);
    984  1.28      tron 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    985  1.28      tron 	SCARG(&pra, offset) = SCARG(uap, offset);
    986  1.28      tron 
    987  1.28      tron 	return sys_read(p, &pra, retval);
    988  1.28      tron }
    989  1.28      tron 
    990  1.28      tron /*
    991  1.28      tron  * pwrite(2).
    992  1.28      tron  */
    993  1.28      tron int
    994  1.28      tron linux_sys_pwrite(p, v, retval)
    995  1.28      tron 	struct proc *p;
    996  1.28      tron 	void *v;
    997  1.28      tron 	register_t *retval;
    998  1.28      tron {
    999  1.28      tron 	struct linux_sys_pwrite_args /* {
   1000  1.28      tron 		syscallarg(int) fd;
   1001  1.28      tron 		syscallarg(void *) buf;
   1002  1.28      tron 		syscallarg(size_t) nbyte;
   1003  1.28      tron 		syscallarg(linux_off_t) offset;
   1004  1.28      tron 	} */ *uap = v;
   1005  1.28      tron 	struct sys_pwrite_args pra;
   1006  1.28      tron 
   1007  1.28      tron 	SCARG(&pra, fd) = SCARG(uap, fd);
   1008  1.28      tron 	SCARG(&pra, buf) = SCARG(uap, buf);
   1009  1.28      tron 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
   1010  1.28      tron 	SCARG(&pra, offset) = SCARG(uap, offset);
   1011  1.28      tron 
   1012  1.28      tron 	return sys_write(p, &pra, retval);
   1013   1.1      fvdl }
   1014