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