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