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