Home | History | Annotate | Line # | Download | only in common
linux_file.c revision 1.21
      1  1.20   mycroft /*	$NetBSD: linux_file.c,v 1.21 1997/10/20 22:05:16 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.18    kleink 		if ((error = copyin(arg, &lfl, sizeof lfl)))
    350  1.18    kleink 			return error;
    351  1.18    kleink 		linux_to_bsd_flock(&lfl, &bfl);
    352  1.18    kleink 		if ((error = copyout(&bfl, bfp, sizeof bfl)))
    353  1.18    kleink 			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.19  christos 	lsp->lst_mode    = (linux_mode_t)bsp->st_mode;
    448  1.19  christos 	if (bsp->st_nlink >= (1 << 15))
    449  1.19  christos 		lsp->lst_nlink = (1 << 15) - 1;
    450  1.19  christos 	else
    451  1.19  christos 		lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
    452   1.1      fvdl 	lsp->lst_uid     = bsp->st_uid;
    453   1.1      fvdl 	lsp->lst_gid     = bsp->st_gid;
    454   1.9      fvdl 	lsp->lst_rdev    = linux_fakedev(bsp->st_rdev);
    455   1.1      fvdl 	lsp->lst_size    = bsp->st_size;
    456   1.1      fvdl 	lsp->lst_blksize = bsp->st_blksize;
    457   1.1      fvdl 	lsp->lst_blocks  = bsp->st_blocks;
    458   1.1      fvdl 	lsp->lst_atime   = bsp->st_atime;
    459   1.1      fvdl 	lsp->lst_mtime   = bsp->st_mtime;
    460   1.1      fvdl 	lsp->lst_ctime   = bsp->st_ctime;
    461   1.1      fvdl }
    462   1.1      fvdl 
    463   1.1      fvdl /*
    464   1.1      fvdl  * The stat functions below are plain sailing. stat and lstat are handled
    465   1.1      fvdl  * by one function to avoid code duplication.
    466   1.1      fvdl  */
    467   1.1      fvdl int
    468  1.12   mycroft linux_sys_fstat(p, v, retval)
    469   1.1      fvdl 	struct proc *p;
    470  1.11   thorpej 	void *v;
    471  1.11   thorpej 	register_t *retval;
    472  1.11   thorpej {
    473  1.12   mycroft 	struct linux_sys_fstat_args /* {
    474   1.1      fvdl 		syscallarg(int) fd;
    475   1.1      fvdl 		syscallarg(linux_stat *) sp;
    476  1.11   thorpej 	} */ *uap = v;
    477  1.21   thorpej 	struct sys___fstat13_args fsa;
    478   1.1      fvdl 	struct linux_stat tmplst;
    479   1.1      fvdl 	struct stat *st,tmpst;
    480   1.1      fvdl 	caddr_t sg;
    481   1.1      fvdl 	int error;
    482   1.1      fvdl 
    483   1.5  christos 	sg = stackgap_init(p->p_emul);
    484   1.1      fvdl 
    485   1.1      fvdl 	st = stackgap_alloc(&sg, sizeof (struct stat));
    486   1.1      fvdl 
    487   1.1      fvdl 	SCARG(&fsa, fd) = SCARG(uap, fd);
    488   1.1      fvdl 	SCARG(&fsa, sb) = st;
    489   1.1      fvdl 
    490  1.21   thorpej 	if ((error = sys___fstat13(p, &fsa, retval)))
    491   1.1      fvdl 		return error;
    492   1.1      fvdl 
    493   1.1      fvdl 	if ((error = copyin(st, &tmpst, sizeof tmpst)))
    494   1.1      fvdl 		return error;
    495   1.1      fvdl 
    496   1.1      fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    497   1.1      fvdl 
    498   1.1      fvdl 	if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
    499   1.1      fvdl 		return error;
    500   1.1      fvdl 
    501   1.1      fvdl 	return 0;
    502   1.1      fvdl }
    503   1.1      fvdl 
    504   1.1      fvdl static int
    505  1.14  christos linux_stat1(p, v, retval, dolstat)
    506   1.1      fvdl 	struct proc *p;
    507  1.14  christos 	void *v;
    508   1.1      fvdl 	register_t *retval;
    509   1.1      fvdl 	int dolstat;
    510   1.1      fvdl {
    511  1.21   thorpej 	struct sys___stat13_args sa;
    512   1.1      fvdl 	struct linux_stat tmplst;
    513   1.1      fvdl 	struct stat *st, tmpst;
    514   1.1      fvdl 	caddr_t sg;
    515   1.1      fvdl 	int error;
    516  1.14  christos 	struct linux_sys_stat_args *uap = v;
    517   1.1      fvdl 
    518   1.5  christos 	sg = stackgap_init(p->p_emul);
    519   1.1      fvdl 
    520   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    521   1.1      fvdl 
    522   1.1      fvdl 	st = stackgap_alloc(&sg, sizeof (struct stat));
    523   1.1      fvdl 	SCARG(&sa, ub) = st;
    524   1.1      fvdl 	SCARG(&sa, path) = SCARG(uap, path);
    525   1.1      fvdl 
    526  1.21   thorpej 	if ((error = (dolstat ? sys___lstat13(p, &sa, retval) :
    527  1.21   thorpej 				sys___stat13(p, &sa, retval))))
    528   1.1      fvdl 		return error;
    529   1.1      fvdl 
    530   1.1      fvdl 	if ((error = copyin(st, &tmpst, sizeof tmpst)))
    531   1.1      fvdl 		return error;
    532   1.1      fvdl 
    533   1.1      fvdl 	bsd_to_linux_stat(&tmpst, &tmplst);
    534   1.1      fvdl 
    535   1.1      fvdl 	if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
    536   1.1      fvdl 		return error;
    537   1.1      fvdl 
    538   1.1      fvdl 	return 0;
    539   1.1      fvdl }
    540   1.1      fvdl 
    541   1.1      fvdl int
    542  1.12   mycroft linux_sys_stat(p, v, retval)
    543   1.1      fvdl 	struct proc *p;
    544  1.11   thorpej 	void *v;
    545  1.11   thorpej 	register_t *retval;
    546  1.11   thorpej {
    547  1.12   mycroft 	struct linux_sys_stat_args /* {
    548   1.1      fvdl 		syscallarg(char *) path;
    549   1.1      fvdl 		syscallarg(struct linux_stat *) sp;
    550  1.11   thorpej 	} */ *uap = v;
    551  1.11   thorpej 
    552   1.1      fvdl 	return linux_stat1(p, uap, retval, 0);
    553   1.1      fvdl }
    554   1.1      fvdl 
    555   1.1      fvdl int
    556  1.12   mycroft linux_sys_lstat(p, v, retval)
    557   1.1      fvdl 	struct proc *p;
    558  1.11   thorpej 	void *v;
    559  1.11   thorpej 	register_t *retval;
    560  1.11   thorpej {
    561  1.12   mycroft 	struct linux_sys_lstat_args /* {
    562   1.1      fvdl 		syscallarg(char *) path;
    563   1.1      fvdl 		syscallarg(struct linux_stat *) sp;
    564  1.11   thorpej 	} */ *uap = v;
    565  1.11   thorpej 
    566   1.1      fvdl 	return linux_stat1(p, uap, retval, 1);
    567   1.1      fvdl }
    568   1.1      fvdl 
    569   1.1      fvdl /*
    570  1.10      fvdl  * The following syscalls are mostly here because of the alternate path check.
    571   1.1      fvdl  */
    572   1.1      fvdl int
    573  1.12   mycroft linux_sys_access(p, v, retval)
    574   1.1      fvdl 	struct proc *p;
    575  1.11   thorpej 	void *v;
    576  1.11   thorpej 	register_t *retval;
    577  1.11   thorpej {
    578  1.12   mycroft 	struct linux_sys_access_args /* {
    579   1.1      fvdl 		syscallarg(char *) path;
    580   1.1      fvdl 		syscallarg(int) flags;
    581  1.11   thorpej 	} */ *uap = v;
    582   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    583   1.1      fvdl 
    584   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    585   1.1      fvdl 
    586  1.12   mycroft 	return sys_access(p, uap, retval);
    587   1.2      fvdl }
    588   1.2      fvdl 
    589   1.2      fvdl int
    590  1.12   mycroft linux_sys_unlink(p, v, retval)
    591   1.2      fvdl 	struct proc *p;
    592  1.11   thorpej 	void *v;
    593   1.2      fvdl 	register_t *retval;
    594   1.2      fvdl 
    595   1.2      fvdl {
    596  1.12   mycroft 	struct linux_sys_unlink_args /* {
    597  1.11   thorpej 		syscallarg(char *) path;
    598  1.11   thorpej 	} */ *uap = v;
    599   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    600   1.2      fvdl 
    601   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    602   1.2      fvdl 
    603  1.12   mycroft 	return sys_unlink(p, uap, retval);
    604   1.2      fvdl }
    605   1.2      fvdl 
    606  1.10      fvdl int
    607  1.12   mycroft linux_sys_chdir(p, v, retval)
    608   1.2      fvdl 	struct proc *p;
    609  1.11   thorpej 	void *v;
    610  1.11   thorpej 	register_t *retval;
    611  1.11   thorpej {
    612  1.12   mycroft 	struct linux_sys_chdir_args /* {
    613   1.2      fvdl 		syscallarg(char *) path;
    614  1.11   thorpej 	} */ *uap = v;
    615   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    616   1.2      fvdl 
    617   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    618   1.2      fvdl 
    619  1.12   mycroft 	return sys_chdir(p, uap, retval);
    620   1.2      fvdl }
    621   1.2      fvdl 
    622   1.2      fvdl int
    623  1.12   mycroft linux_sys_mknod(p, v, retval)
    624   1.2      fvdl 	struct proc *p;
    625  1.11   thorpej 	void *v;
    626  1.11   thorpej 	register_t *retval;
    627  1.11   thorpej {
    628  1.12   mycroft 	struct linux_sys_mknod_args /* {
    629   1.2      fvdl 		syscallarg(char *) path;
    630   1.2      fvdl 		syscallarg(int) mode;
    631   1.2      fvdl 		syscallarg(int) dev;
    632  1.11   thorpej 	} */ *uap = v;
    633   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    634  1.21   thorpej 	struct sys_mkfifo_args bma;
    635   1.2      fvdl 
    636   1.5  christos 	LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    637   1.2      fvdl 
    638  1.10      fvdl 	/*
    639  1.10      fvdl 	 * BSD handles FIFOs seperately
    640  1.10      fvdl 	 */
    641  1.21   thorpej 	if (SCARG(uap, mode) & S_IFIFO) {
    642  1.21   thorpej 		SCARG(&bma, path) = SCARG(uap, path);
    643  1.21   thorpej 		SCARG(&bma, mode) = SCARG(uap, mode);
    644  1.21   thorpej 		return sys_mkfifo(p, uap, retval);
    645  1.21   thorpej 	} else
    646  1.21   thorpej 		return sys_mknod(p, uap, retval);
    647   1.2      fvdl }
    648   1.2      fvdl 
    649   1.2      fvdl int
    650  1.12   mycroft linux_sys_chmod(p, v, retval)
    651   1.2      fvdl 	struct proc *p;
    652  1.11   thorpej 	void *v;
    653  1.11   thorpej 	register_t *retval;
    654  1.11   thorpej {
    655  1.12   mycroft 	struct linux_sys_chmod_args /* {
    656   1.2      fvdl 		syscallarg(char *) path;
    657   1.2      fvdl 		syscallarg(int) mode;
    658  1.11   thorpej 	} */ *uap = v;
    659   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    660   1.2      fvdl 
    661   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    662   1.2      fvdl 
    663  1.12   mycroft 	return sys_chmod(p, uap, retval);
    664   1.2      fvdl }
    665   1.2      fvdl 
    666   1.2      fvdl int
    667  1.12   mycroft linux_sys_chown(p, v, retval)
    668   1.2      fvdl 	struct proc *p;
    669  1.11   thorpej 	void *v;
    670  1.11   thorpej 	register_t *retval;
    671  1.11   thorpej {
    672  1.12   mycroft 	struct linux_sys_chown_args /* {
    673   1.2      fvdl 		syscallarg(char *) path;
    674   1.2      fvdl 		syscallarg(int) uid;
    675   1.2      fvdl 		syscallarg(int) gid;
    676  1.11   thorpej 	} */ *uap = v;
    677  1.12   mycroft 	struct sys_chown_args bca;
    678   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    679   1.2      fvdl 
    680   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    681   1.2      fvdl 
    682  1.10      fvdl 	SCARG(&bca, path) = SCARG(uap, path);
    683  1.10      fvdl 	SCARG(&bca, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
    684  1.10      fvdl 		(uid_t)-1 : SCARG(uap, uid);
    685  1.10      fvdl 	SCARG(&bca, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
    686  1.10      fvdl 		(gid_t)-1 : SCARG(uap, gid);
    687  1.10      fvdl 
    688  1.12   mycroft 	return sys_chown(p, &bca, retval);
    689  1.10      fvdl }
    690  1.10      fvdl 
    691  1.10      fvdl int
    692  1.12   mycroft linux_sys_fchown(p, v, retval)
    693  1.10      fvdl 	struct proc *p;
    694  1.11   thorpej 	void *v;
    695  1.11   thorpej 	register_t *retval;
    696  1.11   thorpej {
    697  1.12   mycroft 	struct linux_sys_fchown_args /* {
    698  1.10      fvdl 		syscallarg(int) fd;
    699  1.10      fvdl 		syscallarg(int) uid;
    700  1.10      fvdl 		syscallarg(int) gid;
    701  1.11   thorpej 	} */ *uap = v;
    702  1.12   mycroft 	struct sys_fchown_args bfa;
    703  1.10      fvdl 
    704  1.10      fvdl 	SCARG(&bfa, fd) = SCARG(uap, fd);
    705  1.10      fvdl 	SCARG(&bfa, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
    706  1.10      fvdl 		(uid_t)-1 : SCARG(uap, uid);
    707  1.10      fvdl 	SCARG(&bfa, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
    708  1.10      fvdl 		(gid_t)-1 : SCARG(uap, gid);
    709  1.10      fvdl 
    710  1.12   mycroft 	return sys_fchown(p, &bfa, retval);
    711   1.2      fvdl }
    712   1.2      fvdl 
    713   1.2      fvdl int
    714  1.12   mycroft linux_sys_rename(p, v, retval)
    715   1.2      fvdl 	struct proc *p;
    716  1.11   thorpej 	void *v;
    717  1.11   thorpej 	register_t *retval;
    718  1.11   thorpej {
    719  1.12   mycroft 	struct linux_sys_rename_args /* {
    720   1.2      fvdl 		syscallarg(char *) from;
    721   1.2      fvdl 		syscallarg(char *) to;
    722  1.11   thorpej 	} */ *uap = v;
    723   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    724   1.2      fvdl 
    725   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, from));
    726   1.5  christos 	LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
    727   1.2      fvdl 
    728  1.17    kleink 	return sys_posix_rename(p, uap, retval);
    729   1.2      fvdl }
    730   1.2      fvdl 
    731   1.2      fvdl int
    732  1.12   mycroft linux_sys_mkdir(p, v, retval)
    733   1.2      fvdl 	struct proc *p;
    734  1.11   thorpej 	void *v;
    735  1.11   thorpej 	register_t *retval;
    736  1.11   thorpej {
    737  1.12   mycroft 	struct linux_sys_mkdir_args /* {
    738   1.2      fvdl 		syscallarg(char *) path;
    739   1.7      fvdl 		syscallarg(int) mode;
    740  1.11   thorpej 	} */ *uap = v;
    741   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    742   1.2      fvdl 
    743   1.5  christos 	LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
    744  1.12   mycroft 
    745  1.12   mycroft 	return sys_mkdir(p, uap, retval);
    746   1.2      fvdl }
    747   1.2      fvdl 
    748   1.2      fvdl int
    749  1.12   mycroft linux_sys_rmdir(p, v, retval)
    750   1.2      fvdl 	struct proc *p;
    751  1.11   thorpej 	void *v;
    752  1.11   thorpej 	register_t *retval;
    753  1.11   thorpej {
    754  1.12   mycroft 	struct linux_sys_rmdir_args /* {
    755   1.2      fvdl 		syscallarg(char *) path;
    756  1.11   thorpej 	} */ *uap = v;
    757   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    758   1.2      fvdl 
    759   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    760  1.12   mycroft 
    761  1.12   mycroft 	return sys_rmdir(p, uap, retval);
    762   1.2      fvdl }
    763   1.2      fvdl 
    764   1.2      fvdl int
    765  1.12   mycroft linux_sys_symlink(p, v, retval)
    766   1.2      fvdl 	struct proc *p;
    767  1.11   thorpej 	void *v;
    768  1.11   thorpej 	register_t *retval;
    769  1.11   thorpej {
    770  1.12   mycroft 	struct linux_sys_symlink_args /* {
    771   1.2      fvdl 		syscallarg(char *) path;
    772   1.2      fvdl 		syscallarg(char *) to;
    773  1.11   thorpej 	} */ *uap = v;
    774   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    775   1.2      fvdl 
    776   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    777   1.5  christos 	LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
    778   1.2      fvdl 
    779  1.12   mycroft 	return sys_symlink(p, uap, retval);
    780   1.2      fvdl }
    781   1.2      fvdl 
    782   1.2      fvdl int
    783  1.12   mycroft linux_sys_readlink(p, v, retval)
    784   1.2      fvdl 	struct proc *p;
    785  1.11   thorpej 	void *v;
    786  1.11   thorpej 	register_t *retval;
    787  1.11   thorpej {
    788  1.12   mycroft 	struct linux_sys_readlink_args /* {
    789   1.2      fvdl 		syscallarg(char *) name;
    790   1.2      fvdl 		syscallarg(char *) buf;
    791   1.2      fvdl 		syscallarg(int) count;
    792  1.11   thorpej 	} */ *uap = v;
    793   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    794   1.2      fvdl 
    795   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, name));
    796  1.12   mycroft 
    797  1.12   mycroft 	return sys_readlink(p, uap, retval);
    798   1.2      fvdl }
    799   1.2      fvdl 
    800   1.2      fvdl int
    801  1.12   mycroft linux_sys_truncate(p, v, retval)
    802   1.2      fvdl 	struct proc *p;
    803  1.11   thorpej 	void *v;
    804  1.11   thorpej 	register_t *retval;
    805  1.11   thorpej {
    806  1.12   mycroft 	struct linux_sys_truncate_args /* {
    807   1.2      fvdl 		syscallarg(char *) path;
    808   1.2      fvdl 		syscallarg(long) length;
    809  1.11   thorpej 	} */ *uap = v;
    810   1.5  christos 	caddr_t sg = stackgap_init(p->p_emul);
    811   1.2      fvdl 
    812   1.5  christos 	LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
    813  1.12   mycroft 
    814  1.12   mycroft 	return compat_43_sys_truncate(p, uap, retval);
    815  1.15      fvdl }
    816  1.15      fvdl 
    817  1.15      fvdl /*
    818  1.15      fvdl  * This is just fsync() for now (just as it is in the Linux kernel)
    819  1.15      fvdl  */
    820  1.15      fvdl int
    821  1.15      fvdl linux_sys_fdatasync(p, v, retval)
    822  1.15      fvdl 	struct proc *p;
    823  1.15      fvdl 	void *v;
    824  1.15      fvdl 	register_t *retval;
    825  1.15      fvdl {
    826  1.16  christos #ifdef notdef
    827  1.15      fvdl 	struct linux_sys_fdatasync_args /* {
    828  1.15      fvdl 		syscallarg(int) fd;
    829  1.15      fvdl 	} */ *uap = v;
    830  1.16  christos #endif
    831  1.15      fvdl 	return sys_fsync(p, v, retval);
    832   1.1      fvdl }
    833