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