Home | History | Annotate | Line # | Download | only in common
linux_file.c revision 1.101.2.1
      1 /*	$NetBSD: linux_file.c,v 1.101.2.1 2011/06/06 09:07:27 jruoho Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1995, 1998, 2008 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*
     33  * Functions in multiarch:
     34  *	linux_sys_llseek	: linux_llseek.c
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 __KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.101.2.1 2011/06/06 09:07:27 jruoho Exp $");
     39 
     40 #include <sys/param.h>
     41 #include <sys/systm.h>
     42 #include <sys/namei.h>
     43 #include <sys/proc.h>
     44 #include <sys/file.h>
     45 #include <sys/fcntl.h>
     46 #include <sys/stat.h>
     47 #include <sys/filedesc.h>
     48 #include <sys/ioctl.h>
     49 #include <sys/kernel.h>
     50 #include <sys/mount.h>
     51 #include <sys/malloc.h>
     52 #include <sys/namei.h>
     53 #include <sys/vnode.h>
     54 #include <sys/tty.h>
     55 #include <sys/socketvar.h>
     56 #include <sys/conf.h>
     57 #include <sys/pipe.h>
     58 
     59 #include <sys/syscallargs.h>
     60 #include <sys/vfs_syscalls.h>
     61 
     62 #include <compat/linux/common/linux_types.h>
     63 #include <compat/linux/common/linux_signal.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 #include <compat/linux/common/linux_ipc.h>
     68 #include <compat/linux/common/linux_sem.h>
     69 
     70 #include <compat/linux/linux_syscallargs.h>
     71 
     72 static int linux_to_bsd_ioflags(int);
     73 static int bsd_to_linux_ioflags(int);
     74 #ifndef __amd64__
     75 static void bsd_to_linux_stat(struct stat *, struct linux_stat *);
     76 #endif
     77 
     78 conv_linux_flock(linux, flock)
     79 
     80 /*
     81  * Some file-related calls are handled here. The usual flag conversion
     82  * an structure conversion is done, and alternate emul path searching.
     83  */
     84 
     85 /*
     86  * The next two functions convert between the Linux and NetBSD values
     87  * of the flags used in open(2) and fcntl(2).
     88  */
     89 static int
     90 linux_to_bsd_ioflags(int lflags)
     91 {
     92 	int res = 0;
     93 
     94 	res |= cvtto_bsd_mask(lflags, LINUX_O_WRONLY, O_WRONLY);
     95 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDONLY, O_RDONLY);
     96 	res |= cvtto_bsd_mask(lflags, LINUX_O_RDWR, O_RDWR);
     97 	res |= cvtto_bsd_mask(lflags, LINUX_O_CREAT, O_CREAT);
     98 	res |= cvtto_bsd_mask(lflags, LINUX_O_EXCL, O_EXCL);
     99 	res |= cvtto_bsd_mask(lflags, LINUX_O_NOCTTY, O_NOCTTY);
    100 	res |= cvtto_bsd_mask(lflags, LINUX_O_TRUNC, O_TRUNC);
    101 	res |= cvtto_bsd_mask(lflags, LINUX_O_NDELAY, O_NDELAY);
    102 	res |= cvtto_bsd_mask(lflags, LINUX_O_SYNC, O_FSYNC);
    103 	res |= cvtto_bsd_mask(lflags, LINUX_FASYNC, O_ASYNC);
    104 	res |= cvtto_bsd_mask(lflags, LINUX_O_APPEND, O_APPEND);
    105 	res |= cvtto_bsd_mask(lflags, LINUX_O_DIRECTORY, O_DIRECTORY);
    106 	res |= cvtto_bsd_mask(lflags, LINUX_O_CLOEXEC, O_CLOEXEC);
    107 
    108 	return res;
    109 }
    110 
    111 static int
    112 bsd_to_linux_ioflags(int bflags)
    113 {
    114 	int res = 0;
    115 
    116 	res |= cvtto_linux_mask(bflags, O_WRONLY, LINUX_O_WRONLY);
    117 	res |= cvtto_linux_mask(bflags, O_RDONLY, LINUX_O_RDONLY);
    118 	res |= cvtto_linux_mask(bflags, O_RDWR, LINUX_O_RDWR);
    119 	res |= cvtto_linux_mask(bflags, O_CREAT, LINUX_O_CREAT);
    120 	res |= cvtto_linux_mask(bflags, O_EXCL, LINUX_O_EXCL);
    121 	res |= cvtto_linux_mask(bflags, O_NOCTTY, LINUX_O_NOCTTY);
    122 	res |= cvtto_linux_mask(bflags, O_TRUNC, LINUX_O_TRUNC);
    123 	res |= cvtto_linux_mask(bflags, O_NDELAY, LINUX_O_NDELAY);
    124 	res |= cvtto_linux_mask(bflags, O_FSYNC, LINUX_O_SYNC);
    125 	res |= cvtto_linux_mask(bflags, O_ASYNC, LINUX_FASYNC);
    126 	res |= cvtto_linux_mask(bflags, O_APPEND, LINUX_O_APPEND);
    127 	res |= cvtto_linux_mask(bflags, O_DIRECTORY, LINUX_O_DIRECTORY);
    128 	res |= cvtto_linux_mask(bflags, O_CLOEXEC, LINUX_O_CLOEXEC);
    129 
    130 	return res;
    131 }
    132 
    133 /*
    134  * creat(2) is an obsolete function, but it's present as a Linux
    135  * system call, so let's deal with it.
    136  *
    137  * Note: On the Alpha this doesn't really exist in Linux, but it's defined
    138  * in syscalls.master anyway so this doesn't have to be special cased.
    139  *
    140  * Just call open(2) with the TRUNC, CREAT and WRONLY flags.
    141  */
    142 int
    143 linux_sys_creat(struct lwp *l, const struct linux_sys_creat_args *uap, register_t *retval)
    144 {
    145 	/* {
    146 		syscallarg(const char *) path;
    147 		syscallarg(int) mode;
    148 	} */
    149 	struct sys_open_args oa;
    150 
    151 	SCARG(&oa, path) = SCARG(uap, path);
    152 	SCARG(&oa, flags) = O_CREAT | O_TRUNC | O_WRONLY;
    153 	SCARG(&oa, mode) = SCARG(uap, mode);
    154 
    155 	return sys_open(l, &oa, retval);
    156 }
    157 
    158 /*
    159  * open(2). Take care of the different flag values, and let the
    160  * NetBSD syscall do the real work. See if this operation
    161  * gives the current process a controlling terminal.
    162  * (XXX is this necessary?)
    163  */
    164 int
    165 linux_sys_open(struct lwp *l, const struct linux_sys_open_args *uap, register_t *retval)
    166 {
    167 	/* {
    168 		syscallarg(const char *) path;
    169 		syscallarg(int) flags;
    170 		syscallarg(int) mode;
    171 	} */
    172 	struct proc *p = l->l_proc;
    173 	int error, fl;
    174 	struct sys_open_args boa;
    175 
    176 	fl = linux_to_bsd_ioflags(SCARG(uap, flags));
    177 
    178 	SCARG(&boa, path) = SCARG(uap, path);
    179 	SCARG(&boa, flags) = fl;
    180 	SCARG(&boa, mode) = SCARG(uap, mode);
    181 
    182 	if ((error = sys_open(l, &boa, retval)))
    183 		return error;
    184 
    185 	/*
    186 	 * this bit from sunos_misc.c (and svr4_fcntl.c).
    187 	 * If we are a session leader, and we don't have a controlling
    188 	 * terminal yet, and the O_NOCTTY flag is not set, try to make
    189 	 * this the controlling terminal.
    190 	 */
    191         if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_lflag & PL_CONTROLT)) {
    192                 file_t *fp;
    193 
    194 		fp = fd_getfile(*retval);
    195 
    196                 /* ignore any error, just give it a try */
    197                 if (fp != NULL) {
    198 			if (fp->f_type == DTYPE_VNODE) {
    199 				(fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, NULL);
    200 			}
    201 			fd_putfile(*retval);
    202 		}
    203         }
    204 	return 0;
    205 }
    206 
    207 /*
    208  * Most actions in the fcntl() call are straightforward; simply
    209  * pass control to the NetBSD system call. A few commands need
    210  * conversions after the actual system call has done its work,
    211  * because the flag values and lock structure are different.
    212  */
    213 int
    214 linux_sys_fcntl(struct lwp *l, const struct linux_sys_fcntl_args *uap, register_t *retval)
    215 {
    216 	/* {
    217 		syscallarg(int) fd;
    218 		syscallarg(int) cmd;
    219 		syscallarg(void *) arg;
    220 	} */
    221 	struct proc *p = l->l_proc;
    222 	int fd, cmd, error;
    223 	u_long val;
    224 	void *arg;
    225 	struct sys_fcntl_args fca;
    226 	file_t *fp;
    227 	struct vnode *vp;
    228 	struct vattr va;
    229 	long pgid;
    230 	struct pgrp *pgrp;
    231 	struct tty *tp;
    232 
    233 	fd = SCARG(uap, fd);
    234 	cmd = SCARG(uap, cmd);
    235 	arg = SCARG(uap, arg);
    236 
    237 	switch (cmd) {
    238 
    239 	case LINUX_F_DUPFD:
    240 		cmd = F_DUPFD;
    241 		break;
    242 
    243 	case LINUX_F_GETFD:
    244 		cmd = F_GETFD;
    245 		break;
    246 
    247 	case LINUX_F_SETFD:
    248 		cmd = F_SETFD;
    249 		break;
    250 
    251 	case LINUX_F_GETFL:
    252 		SCARG(&fca, fd) = fd;
    253 		SCARG(&fca, cmd) = F_GETFL;
    254 		SCARG(&fca, arg) = arg;
    255 		if ((error = sys_fcntl(l, &fca, retval)))
    256 			return error;
    257 		retval[0] = bsd_to_linux_ioflags(retval[0]);
    258 		return 0;
    259 
    260 	case LINUX_F_SETFL: {
    261 		file_t	*fp1 = NULL;
    262 
    263 		val = linux_to_bsd_ioflags((unsigned long)SCARG(uap, arg));
    264 		/*
    265 		 * Linux seems to have same semantics for sending SIGIO to the
    266 		 * read side of socket, but slightly different semantics
    267 		 * for SIGIO to the write side.  Rather than sending the SIGIO
    268 		 * every time it's possible to write (directly) more data, it
    269 		 * only sends SIGIO if last write(2) failed due to insufficient
    270 		 * memory to hold the data. This is compatible enough
    271 		 * with NetBSD semantics to not do anything about the
    272 		 * difference.
    273 		 *
    274 		 * Linux does NOT send SIGIO for pipes. Deal with socketpair
    275 		 * ones and DTYPE_PIPE ones. For these, we don't set
    276 		 * the underlying flags (we don't pass O_ASYNC flag down
    277 		 * to sys_fcntl()), but set the FASYNC flag for file descriptor,
    278 		 * so that F_GETFL would report the ASYNC i/o is on.
    279 		 */
    280 		if (val & O_ASYNC) {
    281 			if (((fp1 = fd_getfile(fd)) == NULL))
    282 			    return (EBADF);
    283 			if (((fp1->f_type == DTYPE_SOCKET) && fp1->f_data
    284 			      && ((struct socket *)fp1->f_data)->so_state & SS_ISAPIPE)
    285 			    || (fp1->f_type == DTYPE_PIPE))
    286 				val &= ~O_ASYNC;
    287 			else {
    288 				/* not a pipe, do not modify anything */
    289 				fd_putfile(fd);
    290 				fp1 = NULL;
    291 			}
    292 		}
    293 
    294 		SCARG(&fca, fd) = fd;
    295 		SCARG(&fca, cmd) = F_SETFL;
    296 		SCARG(&fca, arg) = (void *) val;
    297 
    298 		error = sys_fcntl(l, &fca, retval);
    299 
    300 		/* Now set the FASYNC flag for pipes */
    301 		if (fp1) {
    302 			if (!error) {
    303 				mutex_enter(&fp1->f_lock);
    304 				fp1->f_flag |= FASYNC;
    305 				mutex_exit(&fp1->f_lock);
    306 			}
    307 			fd_putfile(fd);
    308 		}
    309 
    310 		return (error);
    311 	    }
    312 
    313 	case LINUX_F_GETLK:
    314 		do_linux_getlk(fd, cmd, arg, linux, flock);
    315 
    316 	case LINUX_F_SETLK:
    317 	case LINUX_F_SETLKW:
    318 		do_linux_setlk(fd, cmd, arg, linux, flock, LINUX_F_SETLK);
    319 
    320 	case LINUX_F_SETOWN:
    321 	case LINUX_F_GETOWN:
    322 		/*
    323 		 * We need to route fcntl() for tty descriptors around normal
    324 		 * fcntl(), since NetBSD tty TIOC{G,S}PGRP semantics is too
    325 		 * restrictive for Linux F_{G,S}ETOWN. For non-tty descriptors,
    326 		 * this is not a problem.
    327 		 */
    328 		if ((fp = fd_getfile(fd)) == NULL)
    329 			return EBADF;
    330 
    331 		/* Check it's a character device vnode */
    332 		if (fp->f_type != DTYPE_VNODE
    333 		    || (vp = (struct vnode *)fp->f_data) == NULL
    334 		    || vp->v_type != VCHR) {
    335 			fd_putfile(fd);
    336 
    337 	    not_tty:
    338 			/* Not a tty, proceed with common fcntl() */
    339 			cmd = cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
    340 			break;
    341 		}
    342 
    343 		error = VOP_GETATTR(vp, &va, l->l_cred);
    344 
    345 		fd_putfile(fd);
    346 
    347 		if (error)
    348 			return error;
    349 
    350 		if ((tp = cdev_tty(va.va_rdev)) == NULL)
    351 			goto not_tty;
    352 
    353 		/* set tty pg_id appropriately */
    354 		mutex_enter(proc_lock);
    355 		if (cmd == LINUX_F_GETOWN) {
    356 			retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
    357 			mutex_exit(proc_lock);
    358 			return 0;
    359 		}
    360 		if ((long)arg <= 0) {
    361 			pgid = -(long)arg;
    362 		} else {
    363 			struct proc *p1 = proc_find((long)arg);
    364 			if (p1 == NULL) {
    365 				mutex_exit(proc_lock);
    366 				return (ESRCH);
    367 			}
    368 			pgid = (long)p1->p_pgrp->pg_id;
    369 		}
    370 		pgrp = pgrp_find(pgid);
    371 		if (pgrp == NULL || pgrp->pg_session != p->p_session) {
    372 			mutex_exit(proc_lock);
    373 			return EPERM;
    374 		}
    375 		tp->t_pgrp = pgrp;
    376 		mutex_exit(proc_lock);
    377 		return 0;
    378 
    379 	default:
    380 		return EOPNOTSUPP;
    381 	}
    382 
    383 	SCARG(&fca, fd) = fd;
    384 	SCARG(&fca, cmd) = cmd;
    385 	SCARG(&fca, arg) = arg;
    386 
    387 	return sys_fcntl(l, &fca, retval);
    388 }
    389 
    390 #if !defined(__amd64__)
    391 /*
    392  * Convert a NetBSD stat structure to a Linux stat structure.
    393  * Only the order of the fields and the padding in the structure
    394  * is different. linux_fakedev is a machine-dependent function
    395  * which optionally converts device driver major/minor numbers
    396  * (XXX horrible, but what can you do against code that compares
    397  * things against constant major device numbers? sigh)
    398  */
    399 static void
    400 bsd_to_linux_stat(struct stat *bsp, struct linux_stat *lsp)
    401 {
    402 
    403 	lsp->lst_dev     = linux_fakedev(bsp->st_dev, 0);
    404 	lsp->lst_ino     = bsp->st_ino;
    405 	lsp->lst_mode    = (linux_mode_t)bsp->st_mode;
    406 	if (bsp->st_nlink >= (1 << 15))
    407 		lsp->lst_nlink = (1 << 15) - 1;
    408 	else
    409 		lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
    410 	lsp->lst_uid     = bsp->st_uid;
    411 	lsp->lst_gid     = bsp->st_gid;
    412 	lsp->lst_rdev    = linux_fakedev(bsp->st_rdev, 1);
    413 	lsp->lst_size    = bsp->st_size;
    414 	lsp->lst_blksize = bsp->st_blksize;
    415 	lsp->lst_blocks  = bsp->st_blocks;
    416 	lsp->lst_atime   = bsp->st_atime;
    417 	lsp->lst_mtime   = bsp->st_mtime;
    418 	lsp->lst_ctime   = bsp->st_ctime;
    419 #ifdef LINUX_STAT_HAS_NSEC
    420 	lsp->lst_atime_nsec   = bsp->st_atimensec;
    421 	lsp->lst_mtime_nsec   = bsp->st_mtimensec;
    422 	lsp->lst_ctime_nsec   = bsp->st_ctimensec;
    423 #endif
    424 }
    425 
    426 /*
    427  * The stat functions below are plain sailing. stat and lstat are handled
    428  * by one function to avoid code duplication.
    429  */
    430 int
    431 linux_sys_fstat(struct lwp *l, const struct linux_sys_fstat_args *uap, register_t *retval)
    432 {
    433 	/* {
    434 		syscallarg(int) fd;
    435 		syscallarg(linux_stat *) sp;
    436 	} */
    437 	struct linux_stat tmplst;
    438 	struct stat tmpst;
    439 	int error;
    440 
    441 	error = do_sys_fstat(SCARG(uap, fd), &tmpst);
    442 	if (error != 0)
    443 		return error;
    444 	bsd_to_linux_stat(&tmpst, &tmplst);
    445 
    446 	return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
    447 }
    448 
    449 static int
    450 linux_stat1(const struct linux_sys_stat_args *uap, register_t *retval, int flags)
    451 {
    452 	struct linux_stat tmplst;
    453 	struct stat tmpst;
    454 	int error;
    455 
    456 	error = do_sys_stat(SCARG(uap, path), flags, &tmpst);
    457 	if (error != 0)
    458 		return error;
    459 
    460 	bsd_to_linux_stat(&tmpst, &tmplst);
    461 
    462 	return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
    463 }
    464 
    465 int
    466 linux_sys_stat(struct lwp *l, const struct linux_sys_stat_args *uap, register_t *retval)
    467 {
    468 	/* {
    469 		syscallarg(const char *) path;
    470 		syscallarg(struct linux_stat *) sp;
    471 	} */
    472 
    473 	return linux_stat1(uap, retval, FOLLOW);
    474 }
    475 
    476 /* Note: this is "newlstat" in the Linux sources */
    477 /*	(we don't bother with the old lstat currently) */
    478 int
    479 linux_sys_lstat(struct lwp *l, const struct linux_sys_lstat_args *uap, register_t *retval)
    480 {
    481 	/* {
    482 		syscallarg(const char *) path;
    483 		syscallarg(struct linux_stat *) sp;
    484 	} */
    485 
    486 	return linux_stat1((const void *)uap, retval, NOFOLLOW);
    487 }
    488 #endif /* !__amd64__ */
    489 
    490 /*
    491  * The following syscalls are mostly here because of the alternate path check.
    492  */
    493 int
    494 linux_sys_unlink(struct lwp *l, const struct linux_sys_unlink_args *uap, register_t *retval)
    495 {
    496 	/* {
    497 		syscallarg(const char *) path;
    498 	} */
    499 	int error, error2;
    500 	struct pathbuf *pb;
    501 	struct nameidata nd;
    502 
    503 	error = sys_unlink(l, (const void *)uap, retval);
    504 	if (error != EPERM)
    505 		return (error);
    506 
    507 	/*
    508 	 * Linux returns EISDIR if unlink(2) is called on a directory.
    509 	 * We return EPERM in such cases. To emulate correct behaviour,
    510 	 * check if the path points to directory and return EISDIR if this
    511 	 * is the case.
    512 	 *
    513 	 * XXX this should really not copy in the path buffer twice...
    514 	 */
    515 	error2 = pathbuf_copyin(SCARG(uap, path), &pb);
    516 	if (error2) {
    517 		return error2;
    518 	}
    519 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, pb);
    520 	if (namei(&nd) == 0) {
    521 		struct stat sb;
    522 
    523 		if (vn_stat(nd.ni_vp, &sb) == 0
    524 		    && S_ISDIR(sb.st_mode))
    525 			error = EISDIR;
    526 
    527 		vput(nd.ni_vp);
    528 	}
    529 	pathbuf_destroy(pb);
    530 
    531 	return (error);
    532 }
    533 
    534 int
    535 linux_sys_mknod(struct lwp *l, const struct linux_sys_mknod_args *uap, register_t *retval)
    536 {
    537 	/* {
    538 		syscallarg(const char *) path;
    539 		syscallarg(int) mode;
    540 		syscallarg(int) dev;
    541 	} */
    542 
    543 	/*
    544 	 * BSD handles FIFOs separately
    545 	 */
    546 	if (S_ISFIFO(SCARG(uap, mode))) {
    547 		struct sys_mkfifo_args bma;
    548 
    549 		SCARG(&bma, path) = SCARG(uap, path);
    550 		SCARG(&bma, mode) = SCARG(uap, mode);
    551 		return sys_mkfifo(l, &bma, retval);
    552 	} else {
    553 
    554 		/*
    555 		 * Linux device numbers uses 8 bits for minor and 8 bits
    556 		 * for major. Due to how we map our major and minor,
    557 		 * this just fits into our dev_t. Just mask off the
    558 		 * upper 16bit to remove any random junk.
    559 		 */
    560 		return do_sys_mknod(l, SCARG(uap, path), SCARG(uap, mode),
    561 		    SCARG(uap, dev) & 0xffff, retval, UIO_USERSPACE);
    562 	}
    563 }
    564 
    565 /*
    566  * This is just fsync() for now (just as it is in the Linux kernel)
    567  * Note: this is not implemented under Linux on Alpha and Arm
    568  *	but should still be defined in our syscalls.master.
    569  *	(syscall #148 on the arm)
    570  */
    571 int
    572 linux_sys_fdatasync(struct lwp *l, const struct linux_sys_fdatasync_args *uap, register_t *retval)
    573 {
    574 	/* {
    575 		syscallarg(int) fd;
    576 	} */
    577 
    578 	return sys_fsync(l, (const void *)uap, retval);
    579 }
    580 
    581 /*
    582  * pread(2).
    583  */
    584 int
    585 linux_sys_pread(struct lwp *l, const struct linux_sys_pread_args *uap, register_t *retval)
    586 {
    587 	/* {
    588 		syscallarg(int) fd;
    589 		syscallarg(void *) buf;
    590 		syscallarg(size_t) nbyte;
    591 		syscallarg(linux_off_t) offset;
    592 	} */
    593 	struct sys_pread_args pra;
    594 
    595 	SCARG(&pra, fd) = SCARG(uap, fd);
    596 	SCARG(&pra, buf) = SCARG(uap, buf);
    597 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    598 	SCARG(&pra, offset) = SCARG(uap, offset);
    599 
    600 	return sys_pread(l, &pra, retval);
    601 }
    602 
    603 /*
    604  * pwrite(2).
    605  */
    606 int
    607 linux_sys_pwrite(struct lwp *l, const struct linux_sys_pwrite_args *uap, register_t *retval)
    608 {
    609 	/* {
    610 		syscallarg(int) fd;
    611 		syscallarg(void *) buf;
    612 		syscallarg(size_t) nbyte;
    613 		syscallarg(linux_off_t) offset;
    614 	} */
    615 	struct sys_pwrite_args pra;
    616 
    617 	SCARG(&pra, fd) = SCARG(uap, fd);
    618 	SCARG(&pra, buf) = SCARG(uap, buf);
    619 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
    620 	SCARG(&pra, offset) = SCARG(uap, offset);
    621 
    622 	return sys_pwrite(l, &pra, retval);
    623 }
    624 
    625 int
    626 linux_sys_dup3(struct lwp *l, const struct linux_sys_dup3_args *uap,
    627     register_t *retval)
    628 {
    629 	/* {
    630 		syscallarg(int) from;
    631 		syscallarg(int) to;
    632 		syscallarg(int) flags;
    633 	} */
    634 	int error;
    635 	if ((error = sys_dup2(l, (const struct sys_dup2_args *)uap, retval)))
    636 		return error;
    637 
    638 	if (SCARG(uap, flags) & LINUX_O_CLOEXEC)
    639 		fd_set_exclose(l, SCARG(uap, to), true);
    640 
    641 	return 0;
    642 }
    643 
    644 #define LINUX_NOT_SUPPORTED(fun) \
    645 int \
    646 fun(struct lwp *l, const struct fun##_args *uap, register_t *retval) \
    647 { \
    648 	return EOPNOTSUPP; \
    649 }
    650 
    651 LINUX_NOT_SUPPORTED(linux_sys_setxattr)
    652 LINUX_NOT_SUPPORTED(linux_sys_lsetxattr)
    653 LINUX_NOT_SUPPORTED(linux_sys_fsetxattr)
    654 
    655 LINUX_NOT_SUPPORTED(linux_sys_getxattr)
    656 LINUX_NOT_SUPPORTED(linux_sys_lgetxattr)
    657 LINUX_NOT_SUPPORTED(linux_sys_fgetxattr)
    658 
    659 LINUX_NOT_SUPPORTED(linux_sys_listxattr)
    660 LINUX_NOT_SUPPORTED(linux_sys_llistxattr)
    661 LINUX_NOT_SUPPORTED(linux_sys_flistxattr)
    662 
    663 LINUX_NOT_SUPPORTED(linux_sys_removexattr)
    664 LINUX_NOT_SUPPORTED(linux_sys_lremovexattr)
    665 LINUX_NOT_SUPPORTED(linux_sys_fremovexattr)
    666