Home | History | Annotate | Line # | Download | only in common
linux_file.c revision 1.17.4.1
      1  1.17.4.1   thorpej /*	$NetBSD: linux_file.c,v 1.17.4.1 1997/09/06 18:45:33 thorpej Exp $	*/
      2       1.1      fvdl 
      3       1.1      fvdl /*
      4       1.1      fvdl  * Copyright (c) 1995 Frank van der Linden
      5       1.1      fvdl  * All rights reserved.
      6       1.1      fvdl  *
      7       1.1      fvdl  * Redistribution and use in source and binary forms, with or without
      8       1.1      fvdl  * modification, are permitted provided that the following conditions
      9       1.1      fvdl  * are met:
     10       1.1      fvdl  * 1. Redistributions of source code must retain the above copyright
     11       1.1      fvdl  *    notice, this list of conditions and the following disclaimer.
     12       1.1      fvdl  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1      fvdl  *    notice, this list of conditions and the following disclaimer in the
     14       1.1      fvdl  *    documentation and/or other materials provided with the distribution.
     15       1.1      fvdl  * 3. All advertising materials mentioning features or use of this software
     16       1.1      fvdl  *    must display the following acknowledgement:
     17       1.1      fvdl  *      This product includes software developed for the NetBSD Project
     18       1.1      fvdl  *      by Frank van der Linden
     19       1.1      fvdl  * 4. The name of the author may not be used to endorse or promote products
     20       1.1      fvdl  *    derived from this software without specific prior written permission
     21       1.1      fvdl  *
     22       1.1      fvdl  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23       1.1      fvdl  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24       1.1      fvdl  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25       1.1      fvdl  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26       1.1      fvdl  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27       1.1      fvdl  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28       1.1      fvdl  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29       1.1      fvdl  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30       1.1      fvdl  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31       1.1      fvdl  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32       1.1      fvdl  */
     33       1.1      fvdl 
     34       1.1      fvdl #include <sys/param.h>
     35       1.1      fvdl #include <sys/systm.h>
     36       1.1      fvdl #include <sys/namei.h>
     37       1.1      fvdl #include <sys/proc.h>
     38       1.1      fvdl #include <sys/file.h>
     39       1.1      fvdl #include <sys/stat.h>
     40       1.1      fvdl #include <sys/filedesc.h>
     41       1.1      fvdl #include <sys/ioctl.h>
     42       1.1      fvdl #include <sys/kernel.h>
     43       1.1      fvdl #include <sys/mount.h>
     44       1.1      fvdl #include <sys/malloc.h>
     45      1.13      fvdl #include <sys/vnode.h>
     46      1.13      fvdl #include <sys/tty.h>
     47      1.13      fvdl #include <sys/conf.h>
     48       1.1      fvdl 
     49       1.1      fvdl #include <sys/syscallargs.h>
     50       1.1      fvdl 
     51       1.1      fvdl #include <compat/linux/linux_types.h>
     52       1.8   mycroft #include <compat/linux/linux_signal.h>
     53       1.1      fvdl #include <compat/linux/linux_syscallargs.h>
     54       1.1      fvdl #include <compat/linux/linux_fcntl.h>
     55       1.1      fvdl #include <compat/linux/linux_util.h>
     56       1.1      fvdl 
     57      1.14  christos #include <machine/linux_machdep.h>
     58      1.14  christos 
     59      1.14  christos static int linux_to_bsd_ioflags __P((int));
     60      1.14  christos static int bsd_to_linux_ioflags __P((int));
     61      1.14  christos static void bsd_to_linux_flock __P((struct flock *, struct linux_flock *));
     62      1.14  christos static void linux_to_bsd_flock __P((struct linux_flock *, struct flock *));
     63      1.14  christos static void bsd_to_linux_stat __P((struct stat *, struct linux_stat *));
     64      1.14  christos static int linux_stat1 __P((struct proc *, void *, register_t *, int));
     65      1.14  christos 
     66       1.1      fvdl /*
     67       1.1      fvdl  * Some file-related calls are handled here. The usual flag conversion
     68       1.1      fvdl  * an structure conversion is done, and alternate emul path searching.
     69       1.1      fvdl  */
     70       1.1      fvdl 
     71       1.1      fvdl /*
     72       1.1      fvdl  * The next two functions convert between the Linux and NetBSD values
     73       1.1      fvdl  * of the flags used in open(2) and fcntl(2).
     74       1.1      fvdl  */
     75       1.1      fvdl static int
     76      1.14  christos linux_to_bsd_ioflags(lflags)
     77      1.14  christos 	int lflags;
     78       1.1      fvdl {
     79       1.1      fvdl 	int res = 0;
     80       1.1      fvdl 
     81       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_WRONLY, O_WRONLY);
     82       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDONLY, O_RDONLY);
     83       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDWR, O_RDWR);
     84       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_CREAT, O_CREAT);
     85       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_EXCL, O_EXCL);
     86       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_NOCTTY, O_NOCTTY);
     87       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_TRUNC, O_TRUNC);
     88       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_NDELAY, O_NDELAY);
     89       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_SYNC, O_FSYNC);
     90       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_FASYNC, O_ASYNC);
     91       1.1      fvdl 	res |= cvtto_bsd_mask(lflags, LINUX_O_APPEND, O_APPEND);
     92       1.1      fvdl 
     93       1.1      fvdl 	return res;
     94       1.1      fvdl }
     95       1.1      fvdl 
     96       1.1      fvdl static int
     97      1.14  christos bsd_to_linux_ioflags(bflags)
     98      1.14  christos 	int bflags;
     99       1.1      fvdl {
    100       1.1      fvdl 	int res = 0;
    101       1.1      fvdl 
    102       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_WRONLY, LINUX_O_WRONLY);
    103       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_RDONLY, LINUX_O_RDONLY);
    104       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_RDWR, LINUX_O_RDWR);
    105       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_CREAT, LINUX_O_CREAT);
    106       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_EXCL, LINUX_O_EXCL);
    107       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_NOCTTY, LINUX_O_NOCTTY);
    108       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_TRUNC, LINUX_O_TRUNC);
    109       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_NDELAY, LINUX_O_NDELAY);
    110       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_FSYNC, LINUX_O_SYNC);
    111       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_ASYNC, LINUX_FASYNC);
    112       1.1      fvdl 	res |= cvtto_linux_mask(bflags, O_APPEND, LINUX_O_APPEND);
    113       1.1      fvdl 
    114       1.1      fvdl 	return res;
    115       1.1      fvdl }
    116       1.1      fvdl 
    117       1.1      fvdl /*
    118       1.1      fvdl  * creat(2) is an obsolete function, but it's present as a Linux
    119       1.1      fvdl  * system call, so let's deal with it.
    120       1.1      fvdl  *
    121       1.1      fvdl  * Just call open(2) with the TRUNC, CREAT and WRONLY flags.
    122       1.1      fvdl  */
    123       1.1      fvdl int
    124      1.12   mycroft linux_sys_creat(p, v, retval)
    125       1.1      fvdl 	struct proc *p;
    126      1.11   thorpej 	void *v;
    127      1.11   thorpej 	register_t *retval;
    128      1.11   thorpej {
    129      1.12   mycroft 	struct linux_sys_creat_args /* {
    130       1.1      fvdl 		syscallarg(char *) path;
    131       1.1      fvdl 		syscallarg(int) mode;
    132      1.11   thorpej 	} */ *uap = v;
    133      1.12   mycroft 	struct sys_open_args oa;
    134       1.1      fvdl 	caddr_t sg;
    135       1.1      fvdl 
    136       1.5  christos 	sg = stackgap_init(p->p_emul);
    137       1.5  christos 	LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    138       1.1      fvdl 
    139       1.1      fvdl 	SCARG(&oa, path) = SCARG(uap, path);
    140       1.1      fvdl 	SCARG(&oa, flags) = O_CREAT | O_TRUNC | O_WRONLY;
    141       1.1      fvdl 	SCARG(&oa, mode) = SCARG(uap, mode);
    142      1.12   mycroft 
    143      1.12   mycroft 	return sys_open(p, &oa, retval);
    144       1.1      fvdl }
    145       1.1      fvdl 
    146       1.1      fvdl /*
    147       1.1      fvdl  * open(2). Take care of the different flag values, and let the
    148       1.1      fvdl  * NetBSD syscall do the real work. See if this operation
    149       1.1      fvdl  * gives the current process a controlling terminal.
    150       1.1      fvdl  * (XXX is this necessary?)
    151       1.1      fvdl  */
    152       1.1      fvdl int
    153      1.12   mycroft linux_sys_open(p, v, retval)
    154       1.1      fvdl 	struct proc *p;
    155      1.11   thorpej 	void *v;
    156      1.11   thorpej 	register_t *retval;
    157      1.11   thorpej {
    158      1.12   mycroft 	struct linux_sys_open_args /* {
    159       1.1      fvdl 		syscallarg(char *) path;
    160       1.1      fvdl 		syscallarg(int) flags;
    161       1.1      fvdl 		syscallarg(int) mode;
    162      1.11   thorpej 	} */ *uap = v;
    163       1.1      fvdl 	int error, fl;
    164      1.12   mycroft 	struct sys_open_args boa;
    165       1.1      fvdl 	caddr_t sg;
    166       1.1      fvdl 
    167       1.5  christos 	sg = stackgap_init(p->p_emul);
    168       1.1      fvdl 
    169       1.2      fvdl 	fl = linux_to_bsd_ioflags(SCARG(uap, flags));
    170       1.1      fvdl 
    171       1.2      fvdl 	if (fl & O_CREAT)
    172       1.5  christos 		LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    173       1.2      fvdl 	else
    174       1.5  christos 		LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    175       1.1      fvdl 
    176       1.1      fvdl 	SCARG(&boa, path) = SCARG(uap, path);
    177       1.1      fvdl 	SCARG(&boa, flags) = fl;
    178       1.1      fvdl 	SCARG(&boa, mode) = SCARG(uap, mode);
    179       1.2      fvdl 
    180      1.12   mycroft 	if ((error = sys_open(p, &boa, retval)))
    181       1.1      fvdl 		return error;
    182       1.1      fvdl 
    183       1.1      fvdl 	/*
    184       1.1      fvdl 	 * this bit from sunos_misc.c (and svr4_fcntl.c).
    185       1.1      fvdl 	 * If we are a session leader, and we don't have a controlling
    186       1.1      fvdl 	 * terminal yet, and the O_NOCTTY flag is not set, try to make
    187       1.1      fvdl 	 * this the controlling terminal.
    188       1.1      fvdl 	 */
    189       1.1      fvdl         if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
    190       1.1      fvdl                 struct filedesc *fdp = p->p_fd;
    191       1.1      fvdl                 struct file     *fp = fdp->fd_ofiles[*retval];
    192       1.1      fvdl 
    193       1.1      fvdl                 /* ignore any error, just give it a try */
    194       1.1      fvdl                 if (fp->f_type == DTYPE_VNODE)
    195       1.1      fvdl                         (fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, (caddr_t) 0, p);
    196       1.1      fvdl         }
    197       1.1      fvdl 	return 0;
    198       1.1      fvdl }
    199       1.1      fvdl 
    200       1.1      fvdl /*
    201       1.2      fvdl  * This appears to be part of a Linux attempt to switch to 64 bits file sizes.
    202       1.2      fvdl  */
    203       1.2      fvdl int
    204      1.12   mycroft linux_sys_llseek(p, v, retval)
    205       1.2      fvdl 	struct proc *p;
    206      1.11   thorpej 	void *v;
    207      1.11   thorpej 	register_t *retval;
    208      1.11   thorpej {
    209      1.12   mycroft 	struct linux_sys_llseek_args /* {
    210       1.2      fvdl 		syscallarg(int) fd;
    211       1.2      fvdl 		syscallarg(uint32_t) ohigh;
    212       1.2      fvdl 		syscallarg(uint32_t) olow;
    213       1.2      fvdl 		syscallarg(caddr_t) res;
    214       1.2      fvdl 		syscallarg(int) whence;
    215      1.11   thorpej 	} */ *uap = v;
    216      1.12   mycroft 	struct sys_lseek_args bla;
    217       1.2      fvdl 	int error;
    218       1.2      fvdl 	off_t off;
    219       1.2      fvdl 
    220       1.2      fvdl 	off = SCARG(uap, olow) | (((off_t) SCARG(uap, ohigh)) << 32);
    221       1.2      fvdl 
    222       1.2      fvdl 	SCARG(&bla, fd) = SCARG(uap, fd);
    223       1.2      fvdl 	SCARG(&bla, offset) = off;
    224       1.2      fvdl 	SCARG(&bla, whence) = SCARG(uap, whence);
    225       1.2      fvdl 
    226      1.12   mycroft 	if ((error = sys_lseek(p, &bla, retval)))
    227       1.2      fvdl 		return error;
    228       1.2      fvdl 
    229       1.2      fvdl 	if ((error = copyout(retval, SCARG(uap, res), sizeof (off_t))))
    230       1.2      fvdl 		return error;
    231       1.2      fvdl 
    232       1.2      fvdl 	retval[0] = 0;
    233       1.2      fvdl 	return 0;
    234       1.2      fvdl }
    235       1.2      fvdl 
    236       1.2      fvdl /*
    237       1.1      fvdl  * The next two functions take care of converting the flock
    238       1.1      fvdl  * structure back and forth between Linux and NetBSD format.
    239       1.1      fvdl  * The only difference in the structures is the order of
    240       1.1      fvdl  * the fields, and the 'whence' value.
    241       1.1      fvdl  */
    242       1.1      fvdl static void
    243       1.1      fvdl bsd_to_linux_flock(bfp, lfp)
    244       1.1      fvdl 	struct flock *bfp;
    245       1.1      fvdl 	struct linux_flock *lfp;
    246       1.1      fvdl {
    247      1.12   mycroft 
    248       1.1      fvdl 	lfp->l_start = bfp->l_start;
    249       1.1      fvdl 	lfp->l_len = bfp->l_len;
    250       1.1      fvdl 	lfp->l_pid = bfp->l_pid;
    251       1.3   mycroft 	lfp->l_whence = bfp->l_whence;
    252       1.3   mycroft 	switch (bfp->l_type) {
    253       1.1      fvdl 	case F_RDLCK:
    254       1.3   mycroft 		lfp->l_type = LINUX_F_RDLCK;
    255       1.1      fvdl 		break;
    256       1.1      fvdl 	case F_UNLCK:
    257       1.3   mycroft 		lfp->l_type = LINUX_F_UNLCK;
    258       1.1      fvdl 		break;
    259       1.1      fvdl 	case F_WRLCK:
    260       1.3   mycroft 		lfp->l_type = LINUX_F_WRLCK;
    261       1.1      fvdl 		break;
    262       1.1      fvdl 	}
    263       1.1      fvdl }
    264       1.1      fvdl 
    265       1.1      fvdl static void
    266       1.1      fvdl linux_to_bsd_flock(lfp, bfp)
    267       1.1      fvdl 	struct linux_flock *lfp;
    268       1.1      fvdl 	struct flock *bfp;
    269       1.1      fvdl {
    270      1.12   mycroft 
    271       1.1      fvdl 	bfp->l_start = lfp->l_start;
    272       1.1      fvdl 	bfp->l_len = lfp->l_len;
    273       1.1      fvdl 	bfp->l_pid = lfp->l_pid;
    274       1.3   mycroft 	bfp->l_whence = lfp->l_whence;
    275       1.3   mycroft 	switch (lfp->l_type) {
    276       1.1      fvdl 	case LINUX_F_RDLCK:
    277       1.3   mycroft 		bfp->l_type = F_RDLCK;
    278       1.1      fvdl 		break;
    279       1.1      fvdl 	case LINUX_F_UNLCK:
    280       1.3   mycroft 		bfp->l_type = F_UNLCK;
    281       1.1      fvdl 		break;
    282       1.1      fvdl 	case LINUX_F_WRLCK:
    283       1.3   mycroft 		bfp->l_type = F_WRLCK;
    284       1.1      fvdl 		break;
    285       1.1      fvdl 	}
    286       1.1      fvdl }
    287       1.1      fvdl 
    288       1.1      fvdl /*
    289       1.1      fvdl  * Most actions in the fcntl() call are straightforward; simply
    290       1.1      fvdl  * pass control to the NetBSD system call. A few commands need
    291       1.1      fvdl  * conversions after the actual system call has done its work,
    292       1.1      fvdl  * because the flag values and lock structure are different.
    293       1.1      fvdl  */
    294       1.1      fvdl int
    295      1.12   mycroft linux_sys_fcntl(p, v, retval)
    296       1.1      fvdl 	struct proc *p;
    297      1.11   thorpej 	void *v;
    298      1.11   thorpej 	register_t *retval;
    299      1.11   thorpej {
    300      1.12   mycroft 	struct linux_sys_fcntl_args /* {
    301       1.1      fvdl 		syscallarg(int) fd;
    302       1.1      fvdl 		syscallarg(int) cmd;
    303       1.1      fvdl 		syscallarg(void *) arg;
    304      1.11   thorpej 	} */ *uap = v;
    305       1.6      fvdl 	int fd, cmd, error, val;
    306       1.1      fvdl 	caddr_t arg, sg;
    307       1.1      fvdl 	struct linux_flock lfl;
    308       1.1      fvdl 	struct flock *bfp, bfl;
    309      1.12   mycroft 	struct sys_fcntl_args fca;
    310      1.13      fvdl 	struct filedesc *fdp;
    311      1.13      fvdl 	struct file *fp;
    312      1.13      fvdl 	struct vnode *vp;
    313      1.13      fvdl 	struct vattr va;
    314      1.13      fvdl 	long pgid;
    315      1.13      fvdl 	struct pgrp *pgrp;
    316      1.13      fvdl 	struct tty *tp, *(*d_tty) __P((dev_t));
    317       1.1      fvdl 
    318       1.1      fvdl 	fd = SCARG(uap, fd);
    319       1.1      fvdl 	cmd = SCARG(uap, cmd);
    320       1.1      fvdl 	arg = (caddr_t) SCARG(uap, arg);
    321       1.1      fvdl 
    322       1.1      fvdl 	switch (cmd) {
    323       1.1      fvdl 	case LINUX_F_DUPFD:
    324       1.1      fvdl 		cmd = F_DUPFD;
    325       1.1      fvdl 		break;
    326       1.1      fvdl 	case LINUX_F_GETFD:
    327       1.1      fvdl 		cmd = F_GETFD;
    328       1.1      fvdl 		break;
    329       1.1      fvdl 	case LINUX_F_SETFD:
    330       1.1      fvdl 		cmd = F_SETFD;
    331       1.1      fvdl 		break;
    332       1.1      fvdl 	case LINUX_F_GETFL:
    333       1.1      fvdl 		SCARG(&fca, fd) = fd;
    334       1.1      fvdl 		SCARG(&fca, cmd) = F_GETFL;
    335       1.1      fvdl 		SCARG(&fca, arg) = arg;
    336      1.12   mycroft 		if ((error = sys_fcntl(p, &fca, retval)))
    337       1.1      fvdl 			return error;
    338       1.1      fvdl 		retval[0] = bsd_to_linux_ioflags(retval[0]);
    339       1.1      fvdl 		return 0;
    340       1.1      fvdl 	case LINUX_F_SETFL:
    341       1.6      fvdl 		val = linux_to_bsd_ioflags((int)SCARG(uap, arg));
    342       1.1      fvdl 		SCARG(&fca, fd) = fd;
    343       1.1      fvdl 		SCARG(&fca, cmd) = F_SETFL;
    344       1.6      fvdl 		SCARG(&fca, arg) = (caddr_t) val;
    345      1.12   mycroft 		return sys_fcntl(p, &fca, retval);
    346       1.1      fvdl 	case LINUX_F_GETLK:
    347       1.5  christos 		sg = stackgap_init(p->p_emul);
    348       1.1      fvdl 		bfp = (struct flock *) stackgap_alloc(&sg, sizeof *bfp);
    349  1.17.4.1   thorpej 		if ((error = copyin(arg, &lfl, sizeof lfl)))
    350  1.17.4.1   thorpej 			return error;
    351  1.17.4.1   thorpej 		linux_to_bsd_flock(&lfl, &bfl);
    352  1.17.4.1   thorpej 		if ((error = copyout(&bfl, bfp, sizeof bfl)))
    353  1.17.4.1   thorpej 			return error;
    354       1.1      fvdl 		SCARG(&fca, fd) = fd;
    355       1.1      fvdl 		SCARG(&fca, cmd) = F_GETLK;
    356       1.1      fvdl 		SCARG(&fca, arg) = bfp;
    357      1.12   mycroft 		if ((error = sys_fcntl(p, &fca, retval)))
    358       1.1      fvdl 			return error;
    359       1.1      fvdl 		if ((error = copyin(bfp, &bfl, sizeof bfl)))
    360       1.1      fvdl 			return error;
    361       1.1      fvdl 		bsd_to_linux_flock(&bfl, &lfl);
    362       1.1      fvdl 		return copyout(&lfl, arg, sizeof lfl);
    363       1.1      fvdl 		break;
    364       1.1      fvdl 	case LINUX_F_SETLK:
    365       1.1      fvdl 	case LINUX_F_SETLKW:
    366       1.1      fvdl 		cmd = (cmd == LINUX_F_SETLK ? F_SETLK : F_SETLKW);
    367       1.1      fvdl 		if ((error = copyin(arg, &lfl, sizeof lfl)))
    368       1.1      fvdl 			return error;
    369       1.1      fvdl 		linux_to_bsd_flock(&lfl, &bfl);
    370       1.5  christos 		sg = stackgap_init(p->p_emul);
    371       1.1      fvdl 		bfp = (struct flock *) stackgap_alloc(&sg, sizeof *bfp);
    372       1.1      fvdl 		if ((error = copyout(&bfl, bfp, sizeof bfl)))
    373       1.1      fvdl 			return error;
    374       1.1      fvdl 		SCARG(&fca, fd) = fd;
    375       1.1      fvdl 		SCARG(&fca, cmd) = cmd;
    376       1.1      fvdl 		SCARG(&fca, arg) = bfp;
    377      1.12   mycroft 		return sys_fcntl(p, &fca, retval);
    378       1.1      fvdl 		break;
    379       1.1      fvdl 	case LINUX_F_SETOWN:
    380      1.13      fvdl 	case LINUX_F_GETOWN:
    381      1.13      fvdl 		/*
    382      1.13      fvdl 		 * We need to route around the normal fcntl() for these calls,
    383      1.13      fvdl 		 * since it uses TIOC{G,S}PGRP, which is too restrictive for
    384      1.13      fvdl 		 * Linux F_{G,S}ETOWN semantics. For sockets, this problem
    385      1.13      fvdl 		 * does not exist.
    386      1.13      fvdl 		 */
    387      1.13      fvdl 		fdp = p->p_fd;
    388      1.13      fvdl 		if ((u_int)fd >= fdp->fd_nfiles ||
    389      1.13      fvdl 		    (fp = fdp->fd_ofiles[fd]) == NULL)
    390      1.13      fvdl 			return EBADF;
    391      1.13      fvdl 		if (fp->f_type == DTYPE_SOCKET) {
    392      1.13      fvdl 			cmd = cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
    393      1.13      fvdl 			break;
    394      1.13      fvdl 		}
    395      1.13      fvdl 		vp = (struct vnode *)fp->f_data;
    396      1.13      fvdl 		if (vp->v_type != VCHR)
    397      1.13      fvdl 			return EINVAL;
    398      1.13      fvdl 		if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)))
    399      1.13      fvdl 			return error;
    400      1.13      fvdl 		d_tty = cdevsw[major(va.va_rdev)].d_tty;
    401      1.13      fvdl 		if (!d_tty || (!(tp = (*d_tty)(va.va_rdev))))
    402      1.13      fvdl 			return EINVAL;
    403      1.13      fvdl 		if (cmd == LINUX_F_GETOWN) {
    404      1.13      fvdl 			retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
    405      1.13      fvdl 			return 0;
    406      1.13      fvdl 		}
    407      1.13      fvdl 		if ((long)arg <= 0) {
    408      1.13      fvdl 			pgid = -(long)arg;
    409      1.13      fvdl 		} else {
    410      1.13      fvdl 			struct proc *p1 = pfind((long)arg);
    411      1.13      fvdl 			if (p1 == 0)
    412      1.13      fvdl 				return (ESRCH);
    413      1.13      fvdl 			pgid = (long)p1->p_pgrp->pg_id;
    414      1.13      fvdl 		}
    415      1.13      fvdl 		pgrp = pgfind(pgid);
    416      1.13      fvdl 		if (pgrp == NULL || pgrp->pg_session != p->p_session)
    417      1.13      fvdl 			return EPERM;
    418      1.13      fvdl 		tp->t_pgrp = pgrp;
    419      1.13      fvdl 		return 0;
    420       1.1      fvdl 	default:
    421       1.1      fvdl 		return EOPNOTSUPP;
    422       1.1      fvdl 	}
    423       1.1      fvdl 
    424       1.1      fvdl 	SCARG(&fca, fd) = fd;
    425       1.1      fvdl 	SCARG(&fca, cmd) = cmd;
    426       1.1      fvdl 	SCARG(&fca, arg) = arg;
    427      1.12   mycroft 
    428      1.12   mycroft 	return sys_fcntl(p, &fca, retval);
    429       1.1      fvdl }
    430       1.1      fvdl 
    431       1.1      fvdl /*
    432       1.1      fvdl  * Convert a NetBSD stat structure to a Linux stat structure.
    433       1.1      fvdl  * Only the order of the fields and the padding in the structure
    434       1.9      fvdl  * is different. linux_fakedev is a machine-dependent function
    435       1.9      fvdl  * which optionally converts device driver major/minor numbers
    436       1.9      fvdl  * (XXX horrible, but what can you do against code that compares
    437       1.9      fvdl  * things against constant major device numbers? sigh)
    438       1.1      fvdl  */
    439       1.1      fvdl static void
    440       1.1      fvdl bsd_to_linux_stat(bsp, lsp)
    441       1.1      fvdl 	struct stat *bsp;
    442       1.1      fvdl 	struct linux_stat *lsp;
    443       1.1      fvdl {
    444      1.12   mycroft 
    445       1.1      fvdl 	lsp->lst_dev     = bsp->st_dev;
    446       1.1      fvdl 	lsp->lst_ino     = bsp->st_ino;
    447       1.1      fvdl 	lsp->lst_mode    = bsp->st_mode;
    448       1.1      fvdl 	lsp->lst_nlink   = bsp->st_nlink;
    449       1.1      fvdl 	lsp->lst_uid     = bsp->st_uid;
    450       1.1      fvdl 	lsp->lst_gid     = bsp->st_gid;
    451       1.9      fvdl 	lsp->lst_rdev    = linux_fakedev(bsp->st_rdev);
    452       1.1      fvdl 	lsp->lst_size    = bsp->st_size;
    453       1.1      fvdl 	lsp->lst_blksize = bsp->st_blksize;
    454       1.1      fvdl 	lsp->lst_blocks  = bsp->st_blocks;
    455       1.1      fvdl 	lsp->lst_atime   = bsp->st_atime;
    456       1.1      fvdl 	lsp->lst_mtime   = bsp->st_mtime;
    457       1.1      fvdl 	lsp->lst_ctime   = bsp->st_ctime;
    458       1.1      fvdl }
    459       1.1      fvdl 
    460       1.1      fvdl /*
    461       1.1      fvdl  * The stat functions below are plain sailing. stat and lstat are handled
    462       1.1      fvdl  * by one function to avoid code duplication.
    463       1.1      fvdl  */
    464       1.1      fvdl int
    465      1.12   mycroft linux_sys_fstat(p, v, retval)
    466       1.1      fvdl 	struct proc *p;
    467      1.11   thorpej 	void *v;
    468      1.11   thorpej 	register_t *retval;
    469      1.11   thorpej {
    470      1.12   mycroft 	struct linux_sys_fstat_args /* {
    471       1.1      fvdl 		syscallarg(int) fd;
    472       1.1      fvdl 		syscallarg(linux_stat *) sp;
    473      1.11   thorpej 	} */ *uap = v;
    474      1.12   mycroft 	struct sys_fstat_args fsa;
    475       1.1      fvdl 	struct linux_stat tmplst;
    476       1.1      fvdl 	struct stat *st,tmpst;
    477       1.1      fvdl 	caddr_t sg;
    478       1.1      fvdl 	int error;
    479       1.1      fvdl 
    480       1.5  christos 	sg = stackgap_init(p->p_emul);
    481       1.1      fvdl 
    482       1.1      fvdl 	st = stackgap_alloc(&sg, sizeof (struct stat));
    483       1.1      fvdl 
    484       1.1      fvdl 	SCARG(&fsa, fd) = SCARG(uap, fd);
    485       1.1      fvdl 	SCARG(&fsa, sb) = st;
    486       1.1      fvdl 
    487      1.12   mycroft 	if ((error = sys_fstat(p, &fsa, retval)))
    488       1.1      fvdl 		return error;
    489       1.1      fvdl 
    490       1.1      fvdl 	if ((error = copyin(st, &tmpst, sizeof tmpst)))
    491       1.1      fvdl 		return error;
    492       1.1      fvdl 
    493       1.1      fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    494       1.1      fvdl 
    495       1.1      fvdl 	if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
    496       1.1      fvdl 		return error;
    497       1.1      fvdl 
    498       1.1      fvdl 	return 0;
    499       1.1      fvdl }
    500       1.1      fvdl 
    501       1.1      fvdl static int
    502      1.14  christos linux_stat1(p, v, retval, dolstat)
    503       1.1      fvdl 	struct proc *p;
    504      1.14  christos 	void *v;
    505       1.1      fvdl 	register_t *retval;
    506       1.1      fvdl 	int dolstat;
    507       1.1      fvdl {
    508      1.12   mycroft 	struct sys_stat_args sa;
    509       1.1      fvdl 	struct linux_stat tmplst;
    510       1.1      fvdl 	struct stat *st, tmpst;
    511       1.1      fvdl 	caddr_t sg;
    512       1.1      fvdl 	int error;
    513      1.14  christos 	struct linux_sys_stat_args *uap = v;
    514       1.1      fvdl 
    515       1.5  christos 	sg = stackgap_init(p->p_emul);
    516       1.1      fvdl 
    517       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    518       1.1      fvdl 
    519       1.1      fvdl 	st = stackgap_alloc(&sg, sizeof (struct stat));
    520       1.1      fvdl 	SCARG(&sa, ub) = st;
    521       1.1      fvdl 	SCARG(&sa, path) = SCARG(uap, path);
    522       1.1      fvdl 
    523      1.12   mycroft 	if ((error = (dolstat ? sys_lstat(p, &sa, retval) :
    524      1.12   mycroft 				sys_stat(p, &sa, retval))))
    525       1.1      fvdl 		return error;
    526       1.1      fvdl 
    527       1.1      fvdl 	if ((error = copyin(st, &tmpst, sizeof tmpst)))
    528       1.1      fvdl 		return error;
    529       1.1      fvdl 
    530       1.1      fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    531       1.1      fvdl 
    532       1.1      fvdl 	if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
    533       1.1      fvdl 		return error;
    534       1.1      fvdl 
    535       1.1      fvdl 	return 0;
    536       1.1      fvdl }
    537       1.1      fvdl 
    538       1.1      fvdl int
    539      1.12   mycroft linux_sys_stat(p, v, retval)
    540       1.1      fvdl 	struct proc *p;
    541      1.11   thorpej 	void *v;
    542      1.11   thorpej 	register_t *retval;
    543      1.11   thorpej {
    544      1.12   mycroft 	struct linux_sys_stat_args /* {
    545       1.1      fvdl 		syscallarg(char *) path;
    546       1.1      fvdl 		syscallarg(struct linux_stat *) sp;
    547      1.11   thorpej 	} */ *uap = v;
    548      1.11   thorpej 
    549       1.1      fvdl 	return linux_stat1(p, uap, retval, 0);
    550       1.1      fvdl }
    551       1.1      fvdl 
    552       1.1      fvdl int
    553      1.12   mycroft linux_sys_lstat(p, v, retval)
    554       1.1      fvdl 	struct proc *p;
    555      1.11   thorpej 	void *v;
    556      1.11   thorpej 	register_t *retval;
    557      1.11   thorpej {
    558      1.12   mycroft 	struct linux_sys_lstat_args /* {
    559       1.1      fvdl 		syscallarg(char *) path;
    560       1.1      fvdl 		syscallarg(struct linux_stat *) sp;
    561      1.11   thorpej 	} */ *uap = v;
    562      1.11   thorpej 
    563       1.1      fvdl 	return linux_stat1(p, uap, retval, 1);
    564       1.1      fvdl }
    565       1.1      fvdl 
    566       1.1      fvdl /*
    567      1.10      fvdl  * The following syscalls are mostly here because of the alternate path check.
    568       1.1      fvdl  */
    569       1.1      fvdl int
    570      1.12   mycroft linux_sys_access(p, v, retval)
    571       1.1      fvdl 	struct proc *p;
    572      1.11   thorpej 	void *v;
    573      1.11   thorpej 	register_t *retval;
    574      1.11   thorpej {
    575      1.12   mycroft 	struct linux_sys_access_args /* {
    576       1.1      fvdl 		syscallarg(char *) path;
    577       1.1      fvdl 		syscallarg(int) flags;
    578      1.11   thorpej 	} */ *uap = v;
    579       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    580       1.1      fvdl 
    581       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    582       1.1      fvdl 
    583      1.12   mycroft 	return sys_access(p, uap, retval);
    584       1.2      fvdl }
    585       1.2      fvdl 
    586       1.2      fvdl int
    587      1.12   mycroft linux_sys_unlink(p, v, retval)
    588       1.2      fvdl 	struct proc *p;
    589      1.11   thorpej 	void *v;
    590       1.2      fvdl 	register_t *retval;
    591       1.2      fvdl 
    592       1.2      fvdl {
    593      1.12   mycroft 	struct linux_sys_unlink_args /* {
    594      1.11   thorpej 		syscallarg(char *) path;
    595      1.11   thorpej 	} */ *uap = v;
    596       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    597       1.2      fvdl 
    598       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    599       1.2      fvdl 
    600      1.12   mycroft 	return sys_unlink(p, uap, retval);
    601       1.2      fvdl }
    602       1.2      fvdl 
    603      1.10      fvdl int
    604      1.12   mycroft linux_sys_chdir(p, v, retval)
    605       1.2      fvdl 	struct proc *p;
    606      1.11   thorpej 	void *v;
    607      1.11   thorpej 	register_t *retval;
    608      1.11   thorpej {
    609      1.12   mycroft 	struct linux_sys_chdir_args /* {
    610       1.2      fvdl 		syscallarg(char *) path;
    611      1.11   thorpej 	} */ *uap = v;
    612       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    613       1.2      fvdl 
    614       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    615       1.2      fvdl 
    616      1.12   mycroft 	return sys_chdir(p, uap, retval);
    617       1.2      fvdl }
    618       1.2      fvdl 
    619       1.2      fvdl int
    620      1.12   mycroft linux_sys_mknod(p, v, retval)
    621       1.2      fvdl 	struct proc *p;
    622      1.11   thorpej 	void *v;
    623      1.11   thorpej 	register_t *retval;
    624      1.11   thorpej {
    625      1.12   mycroft 	struct linux_sys_mknod_args /* {
    626       1.2      fvdl 		syscallarg(char *) path;
    627       1.2      fvdl 		syscallarg(int) mode;
    628       1.2      fvdl 		syscallarg(int) dev;
    629      1.11   thorpej 	} */ *uap = v;
    630       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    631      1.12   mycroft 	struct sys_mkfifo_args bma;
    632       1.2      fvdl 
    633       1.5  christos 	LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    634       1.2      fvdl 
    635      1.10      fvdl 	/*
    636      1.10      fvdl 	 * BSD handles FIFOs seperately
    637      1.10      fvdl 	 */
    638      1.10      fvdl 	if (SCARG(uap, mode) & S_IFIFO) {
    639      1.10      fvdl 		SCARG(&bma, path) = SCARG(uap, path);
    640      1.10      fvdl 		SCARG(&bma, mode) = SCARG(uap, mode);
    641      1.12   mycroft 		return sys_mkfifo(p, uap, retval);
    642      1.10      fvdl 	} else
    643      1.12   mycroft 		return sys_mknod(p, uap, retval);
    644       1.2      fvdl }
    645       1.2      fvdl 
    646       1.2      fvdl int
    647      1.12   mycroft linux_sys_chmod(p, v, retval)
    648       1.2      fvdl 	struct proc *p;
    649      1.11   thorpej 	void *v;
    650      1.11   thorpej 	register_t *retval;
    651      1.11   thorpej {
    652      1.12   mycroft 	struct linux_sys_chmod_args /* {
    653       1.2      fvdl 		syscallarg(char *) path;
    654       1.2      fvdl 		syscallarg(int) mode;
    655      1.11   thorpej 	} */ *uap = v;
    656       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    657       1.2      fvdl 
    658       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    659       1.2      fvdl 
    660      1.12   mycroft 	return sys_chmod(p, uap, retval);
    661       1.2      fvdl }
    662       1.2      fvdl 
    663       1.2      fvdl int
    664      1.12   mycroft linux_sys_chown(p, v, retval)
    665       1.2      fvdl 	struct proc *p;
    666      1.11   thorpej 	void *v;
    667      1.11   thorpej 	register_t *retval;
    668      1.11   thorpej {
    669      1.12   mycroft 	struct linux_sys_chown_args /* {
    670       1.2      fvdl 		syscallarg(char *) path;
    671       1.2      fvdl 		syscallarg(int) uid;
    672       1.2      fvdl 		syscallarg(int) gid;
    673      1.11   thorpej 	} */ *uap = v;
    674      1.12   mycroft 	struct sys_chown_args bca;
    675       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    676       1.2      fvdl 
    677       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    678       1.2      fvdl 
    679      1.10      fvdl 	SCARG(&bca, path) = SCARG(uap, path);
    680      1.10      fvdl 	SCARG(&bca, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
    681      1.10      fvdl 		(uid_t)-1 : SCARG(uap, uid);
    682      1.10      fvdl 	SCARG(&bca, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
    683      1.10      fvdl 		(gid_t)-1 : SCARG(uap, gid);
    684      1.10      fvdl 
    685      1.12   mycroft 	return sys_chown(p, &bca, retval);
    686      1.10      fvdl }
    687      1.10      fvdl 
    688      1.10      fvdl int
    689      1.12   mycroft linux_sys_fchown(p, v, retval)
    690      1.10      fvdl 	struct proc *p;
    691      1.11   thorpej 	void *v;
    692      1.11   thorpej 	register_t *retval;
    693      1.11   thorpej {
    694      1.12   mycroft 	struct linux_sys_fchown_args /* {
    695      1.10      fvdl 		syscallarg(int) fd;
    696      1.10      fvdl 		syscallarg(int) uid;
    697      1.10      fvdl 		syscallarg(int) gid;
    698      1.11   thorpej 	} */ *uap = v;
    699      1.12   mycroft 	struct sys_fchown_args bfa;
    700      1.10      fvdl 
    701      1.10      fvdl 	SCARG(&bfa, fd) = SCARG(uap, fd);
    702      1.10      fvdl 	SCARG(&bfa, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
    703      1.10      fvdl 		(uid_t)-1 : SCARG(uap, uid);
    704      1.10      fvdl 	SCARG(&bfa, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
    705      1.10      fvdl 		(gid_t)-1 : SCARG(uap, gid);
    706      1.10      fvdl 
    707      1.12   mycroft 	return sys_fchown(p, &bfa, retval);
    708       1.2      fvdl }
    709       1.2      fvdl 
    710       1.2      fvdl int
    711      1.12   mycroft linux_sys_rename(p, v, retval)
    712       1.2      fvdl 	struct proc *p;
    713      1.11   thorpej 	void *v;
    714      1.11   thorpej 	register_t *retval;
    715      1.11   thorpej {
    716      1.12   mycroft 	struct linux_sys_rename_args /* {
    717       1.2      fvdl 		syscallarg(char *) from;
    718       1.2      fvdl 		syscallarg(char *) to;
    719      1.11   thorpej 	} */ *uap = v;
    720       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    721       1.2      fvdl 
    722       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, from));
    723       1.5  christos 	LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
    724       1.2      fvdl 
    725      1.17    kleink 	return sys_posix_rename(p, uap, retval);
    726       1.2      fvdl }
    727       1.2      fvdl 
    728       1.2      fvdl int
    729      1.12   mycroft linux_sys_mkdir(p, v, retval)
    730       1.2      fvdl 	struct proc *p;
    731      1.11   thorpej 	void *v;
    732      1.11   thorpej 	register_t *retval;
    733      1.11   thorpej {
    734      1.12   mycroft 	struct linux_sys_mkdir_args /* {
    735       1.2      fvdl 		syscallarg(char *) path;
    736       1.7      fvdl 		syscallarg(int) mode;
    737      1.11   thorpej 	} */ *uap = v;
    738       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    739       1.2      fvdl 
    740       1.5  christos 	LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    741      1.12   mycroft 
    742      1.12   mycroft 	return sys_mkdir(p, uap, retval);
    743       1.2      fvdl }
    744       1.2      fvdl 
    745       1.2      fvdl int
    746      1.12   mycroft linux_sys_rmdir(p, v, retval)
    747       1.2      fvdl 	struct proc *p;
    748      1.11   thorpej 	void *v;
    749      1.11   thorpej 	register_t *retval;
    750      1.11   thorpej {
    751      1.12   mycroft 	struct linux_sys_rmdir_args /* {
    752       1.2      fvdl 		syscallarg(char *) path;
    753      1.11   thorpej 	} */ *uap = v;
    754       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    755       1.2      fvdl 
    756       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    757      1.12   mycroft 
    758      1.12   mycroft 	return sys_rmdir(p, uap, retval);
    759       1.2      fvdl }
    760       1.2      fvdl 
    761       1.2      fvdl int
    762      1.12   mycroft linux_sys_symlink(p, v, retval)
    763       1.2      fvdl 	struct proc *p;
    764      1.11   thorpej 	void *v;
    765      1.11   thorpej 	register_t *retval;
    766      1.11   thorpej {
    767      1.12   mycroft 	struct linux_sys_symlink_args /* {
    768       1.2      fvdl 		syscallarg(char *) path;
    769       1.2      fvdl 		syscallarg(char *) to;
    770      1.11   thorpej 	} */ *uap = v;
    771       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    772       1.2      fvdl 
    773       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    774       1.5  christos 	LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
    775       1.2      fvdl 
    776      1.12   mycroft 	return sys_symlink(p, uap, retval);
    777       1.2      fvdl }
    778       1.2      fvdl 
    779       1.2      fvdl int
    780      1.12   mycroft linux_sys_readlink(p, v, retval)
    781       1.2      fvdl 	struct proc *p;
    782      1.11   thorpej 	void *v;
    783      1.11   thorpej 	register_t *retval;
    784      1.11   thorpej {
    785      1.12   mycroft 	struct linux_sys_readlink_args /* {
    786       1.2      fvdl 		syscallarg(char *) name;
    787       1.2      fvdl 		syscallarg(char *) buf;
    788       1.2      fvdl 		syscallarg(int) count;
    789      1.11   thorpej 	} */ *uap = v;
    790       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    791       1.2      fvdl 
    792       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, name));
    793      1.12   mycroft 
    794      1.12   mycroft 	return sys_readlink(p, uap, retval);
    795       1.2      fvdl }
    796       1.2      fvdl 
    797       1.2      fvdl int
    798      1.12   mycroft linux_sys_truncate(p, v, retval)
    799       1.2      fvdl 	struct proc *p;
    800      1.11   thorpej 	void *v;
    801      1.11   thorpej 	register_t *retval;
    802      1.11   thorpej {
    803      1.12   mycroft 	struct linux_sys_truncate_args /* {
    804       1.2      fvdl 		syscallarg(char *) path;
    805       1.2      fvdl 		syscallarg(long) length;
    806      1.11   thorpej 	} */ *uap = v;
    807       1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    808       1.2      fvdl 
    809       1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    810      1.12   mycroft 
    811      1.12   mycroft 	return compat_43_sys_truncate(p, uap, retval);
    812      1.15      fvdl }
    813      1.15      fvdl 
    814      1.15      fvdl /*
    815      1.15      fvdl  * This is just fsync() for now (just as it is in the Linux kernel)
    816      1.15      fvdl  */
    817      1.15      fvdl int
    818      1.15      fvdl linux_sys_fdatasync(p, v, retval)
    819      1.15      fvdl 	struct proc *p;
    820      1.15      fvdl 	void *v;
    821      1.15      fvdl 	register_t *retval;
    822      1.15      fvdl {
    823      1.16  christos #ifdef notdef
    824      1.15      fvdl 	struct linux_sys_fdatasync_args /* {
    825      1.15      fvdl 		syscallarg(int) fd;
    826      1.15      fvdl 	} */ *uap = v;
    827      1.16  christos #endif
    828      1.15      fvdl 	return sys_fsync(p, v, retval);
    829       1.1      fvdl }
    830