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