xref: /netbsd-src/sys/compat/linux/common/linux_file.c (revision 267197ec1eebfcb9810ea27a89625b6ddf68e3e7)
1 /*	$NetBSD: linux_file.c,v 1.92 2008/02/02 21:54:01 dsl 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/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD: linux_file.c,v 1.92 2008/02/02 21:54:01 dsl 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                 struct filedesc *fdp = p->p_fd;
195                 struct file     *fp;
196 
197 		fp = fd_getfile(fdp, *retval);
198 
199                 /* ignore any error, just give it a try */
200                 if (fp != NULL) {
201 			FILE_USE(fp);
202 			if (fp->f_type == DTYPE_VNODE) {
203 				(fp->f_ops->fo_ioctl) (fp, TIOCSCTTY,
204 				    (void *) 0, l);
205 			}
206 			FILE_UNUSE(fp, l);
207 		}
208         }
209 	return 0;
210 }
211 
212 /*
213  * Most actions in the fcntl() call are straightforward; simply
214  * pass control to the NetBSD system call. A few commands need
215  * conversions after the actual system call has done its work,
216  * because the flag values and lock structure are different.
217  */
218 int
219 linux_sys_fcntl(struct lwp *l, const struct linux_sys_fcntl_args *uap, register_t *retval)
220 {
221 	/* {
222 		syscallarg(int) fd;
223 		syscallarg(int) cmd;
224 		syscallarg(void *) arg;
225 	} */
226 	struct proc *p = l->l_proc;
227 	int fd, cmd, error;
228 	u_long val;
229 	void *arg;
230 	struct sys_fcntl_args fca;
231 	struct filedesc *fdp;
232 	struct file *fp;
233 	struct vnode *vp;
234 	struct vattr va;
235 	const struct cdevsw *cdev;
236 	long pgid;
237 	struct pgrp *pgrp;
238 	struct tty *tp, *(*d_tty)(dev_t);
239 
240 	fd = SCARG(uap, fd);
241 	cmd = SCARG(uap, cmd);
242 	arg = SCARG(uap, arg);
243 
244 	switch (cmd) {
245 
246 	case LINUX_F_DUPFD:
247 		cmd = F_DUPFD;
248 		break;
249 
250 	case LINUX_F_GETFD:
251 		cmd = F_GETFD;
252 		break;
253 
254 	case LINUX_F_SETFD:
255 		cmd = F_SETFD;
256 		break;
257 
258 	case LINUX_F_GETFL:
259 		SCARG(&fca, fd) = fd;
260 		SCARG(&fca, cmd) = F_GETFL;
261 		SCARG(&fca, arg) = arg;
262 		if ((error = sys_fcntl(l, &fca, retval)))
263 			return error;
264 		retval[0] = bsd_to_linux_ioflags(retval[0]);
265 		return 0;
266 
267 	case LINUX_F_SETFL: {
268 		struct file	*fp1 = NULL;
269 
270 		val = linux_to_bsd_ioflags((unsigned long)SCARG(uap, arg));
271 		/*
272 		 * Linux seems to have same semantics for sending SIGIO to the
273 		 * read side of socket, but slightly different semantics
274 		 * for SIGIO to the write side.  Rather than sending the SIGIO
275 		 * every time it's possible to write (directly) more data, it
276 		 * only sends SIGIO if last write(2) failed due to insufficient
277 		 * memory to hold the data. This is compatible enough
278 		 * with NetBSD semantics to not do anything about the
279 		 * difference.
280 		 *
281 		 * Linux does NOT send SIGIO for pipes. Deal with socketpair
282 		 * ones and DTYPE_PIPE ones. For these, we don't set
283 		 * the underlying flags (we don't pass O_ASYNC flag down
284 		 * to sys_fcntl()), but set the FASYNC flag for file descriptor,
285 		 * so that F_GETFL would report the ASYNC i/o is on.
286 		 */
287 		if (val & O_ASYNC) {
288 			if (((fp1 = fd_getfile(p->p_fd, fd)) == NULL))
289 			    return (EBADF);
290 
291 			FILE_USE(fp1);
292 
293 			if (((fp1->f_type == DTYPE_SOCKET) && fp1->f_data
294 			      && ((struct socket *)fp1->f_data)->so_state & SS_ISAPIPE)
295 			    || (fp1->f_type == DTYPE_PIPE))
296 				val &= ~O_ASYNC;
297 			else {
298 				/* not a pipe, do not modify anything */
299 				FILE_UNUSE(fp1, l);
300 				fp1 = NULL;
301 			}
302 		}
303 
304 		SCARG(&fca, fd) = fd;
305 		SCARG(&fca, cmd) = F_SETFL;
306 		SCARG(&fca, arg) = (void *) val;
307 
308 		error = sys_fcntl(l, &fca, retval);
309 
310 		/* Now set the FASYNC flag for pipes */
311 		if (fp1) {
312 			if (!error)
313 				fp1->f_flag |= FASYNC;
314 			FILE_UNUSE(fp1, l);
315 		}
316 
317 		return (error);
318 	    }
319 
320 	case LINUX_F_GETLK:
321 		do_linux_getlk(fd, cmd, arg, linux, flock);
322 
323 	case LINUX_F_SETLK:
324 	case LINUX_F_SETLKW:
325 		do_linux_setlk(fd, cmd, arg, linux, flock, LINUX_F_SETLK);
326 
327 	case LINUX_F_SETOWN:
328 	case LINUX_F_GETOWN:
329 		/*
330 		 * We need to route fcntl() for tty descriptors around normal
331 		 * fcntl(), since NetBSD tty TIOC{G,S}PGRP semantics is too
332 		 * restrictive for Linux F_{G,S}ETOWN. For non-tty descriptors,
333 		 * this is not a problem.
334 		 */
335 		fdp = p->p_fd;
336 		if ((fp = fd_getfile(fdp, fd)) == NULL)
337 			return EBADF;
338 		FILE_USE(fp);
339 
340 		/* Check it's a character device vnode */
341 		if (fp->f_type != DTYPE_VNODE
342 		    || (vp = (struct vnode *)fp->f_data) == NULL
343 		    || vp->v_type != VCHR) {
344 			FILE_UNUSE(fp, l);
345 
346 	    not_tty:
347 			/* Not a tty, proceed with common fcntl() */
348 			cmd = cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
349 			break;
350 		}
351 
352 		error = VOP_GETATTR(vp, &va, l->l_cred);
353 
354 		FILE_UNUSE(fp, l);
355 
356 		if (error)
357 			return error;
358 
359 		cdev = cdevsw_lookup(va.va_rdev);
360 		if (cdev == NULL)
361 			return (ENXIO);
362 		d_tty = cdev->d_tty;
363 		if (!d_tty || (!(tp = (*d_tty)(va.va_rdev))))
364 			goto not_tty;
365 
366 		/* set tty pg_id appropriately */
367 		if (cmd == LINUX_F_GETOWN) {
368 			retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
369 			return 0;
370 		}
371 		mutex_enter(&proclist_lock);
372 		if ((long)arg <= 0) {
373 			pgid = -(long)arg;
374 		} else {
375 			struct proc *p1 = p_find((long)arg, PFIND_LOCKED | PFIND_UNLOCK_FAIL);
376 			if (p1 == NULL)
377 				return (ESRCH);
378 			pgid = (long)p1->p_pgrp->pg_id;
379 		}
380 		pgrp = pg_find(pgid, PFIND_LOCKED);
381 		if (pgrp == NULL || pgrp->pg_session != p->p_session) {
382 			mutex_exit(&proclist_lock);
383 			return EPERM;
384 		}
385 		tp->t_pgrp = pgrp;
386 		mutex_exit(&proclist_lock);
387 		return 0;
388 
389 	default:
390 		return EOPNOTSUPP;
391 	}
392 
393 	SCARG(&fca, fd) = fd;
394 	SCARG(&fca, cmd) = cmd;
395 	SCARG(&fca, arg) = arg;
396 
397 	return sys_fcntl(l, &fca, retval);
398 }
399 
400 #if !defined(__amd64__)
401 /*
402  * Convert a NetBSD stat structure to a Linux stat structure.
403  * Only the order of the fields and the padding in the structure
404  * is different. linux_fakedev is a machine-dependent function
405  * which optionally converts device driver major/minor numbers
406  * (XXX horrible, but what can you do against code that compares
407  * things against constant major device numbers? sigh)
408  */
409 static void
410 bsd_to_linux_stat(struct stat *bsp, struct linux_stat *lsp)
411 {
412 
413 	lsp->lst_dev     = linux_fakedev(bsp->st_dev, 0);
414 	lsp->lst_ino     = bsp->st_ino;
415 	lsp->lst_mode    = (linux_mode_t)bsp->st_mode;
416 	if (bsp->st_nlink >= (1 << 15))
417 		lsp->lst_nlink = (1 << 15) - 1;
418 	else
419 		lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
420 	lsp->lst_uid     = bsp->st_uid;
421 	lsp->lst_gid     = bsp->st_gid;
422 	lsp->lst_rdev    = linux_fakedev(bsp->st_rdev, 1);
423 	lsp->lst_size    = bsp->st_size;
424 	lsp->lst_blksize = bsp->st_blksize;
425 	lsp->lst_blocks  = bsp->st_blocks;
426 	lsp->lst_atime   = bsp->st_atime;
427 	lsp->lst_mtime   = bsp->st_mtime;
428 	lsp->lst_ctime   = bsp->st_ctime;
429 #ifdef LINUX_STAT_HAS_NSEC
430 	lsp->lst_atime_nsec   = bsp->st_atimensec;
431 	lsp->lst_mtime_nsec   = bsp->st_mtimensec;
432 	lsp->lst_ctime_nsec   = bsp->st_ctimensec;
433 #endif
434 }
435 
436 /*
437  * The stat functions below are plain sailing. stat and lstat are handled
438  * by one function to avoid code duplication.
439  */
440 int
441 linux_sys_fstat(struct lwp *l, const struct linux_sys_fstat_args *uap, register_t *retval)
442 {
443 	/* {
444 		syscallarg(int) fd;
445 		syscallarg(linux_stat *) sp;
446 	} */
447 	struct linux_stat tmplst;
448 	struct stat tmpst;
449 	int error;
450 
451 	error = do_sys_fstat(l, SCARG(uap, fd), &tmpst);
452 	if (error != 0)
453 		return error;
454 	bsd_to_linux_stat(&tmpst, &tmplst);
455 
456 	return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
457 }
458 
459 static int
460 linux_stat1(struct lwp *l, const struct linux_sys_stat_args *uap, register_t *retval, int flags)
461 {
462 	struct linux_stat tmplst;
463 	struct stat tmpst;
464 	int error;
465 
466 	error = do_sys_stat(l, SCARG(uap, path), flags, &tmpst);
467 	if (error != 0)
468 		return error;
469 
470 	bsd_to_linux_stat(&tmpst, &tmplst);
471 
472 	return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
473 }
474 
475 int
476 linux_sys_stat(struct lwp *l, const struct linux_sys_stat_args *uap, register_t *retval)
477 {
478 	/* {
479 		syscallarg(const char *) path;
480 		syscallarg(struct linux_stat *) sp;
481 	} */
482 
483 	return linux_stat1(l, uap, retval, FOLLOW);
484 }
485 
486 /* Note: this is "newlstat" in the Linux sources */
487 /*	(we don't bother with the old lstat currently) */
488 int
489 linux_sys_lstat(struct lwp *l, const struct linux_sys_lstat_args *uap, register_t *retval)
490 {
491 	/* {
492 		syscallarg(const char *) path;
493 		syscallarg(struct linux_stat *) sp;
494 	} */
495 
496 	return linux_stat1(l, (const void *)uap, retval, NOFOLLOW);
497 }
498 #endif /* !__amd64__ */
499 
500 /*
501  * The following syscalls are mostly here because of the alternate path check.
502  */
503 int
504 linux_sys_unlink(struct lwp *l, const struct linux_sys_unlink_args *uap, register_t *retval)
505 {
506 	/* {
507 		syscallarg(const char *) path;
508 	} */
509 	int error;
510 	struct nameidata nd;
511 
512 	error = sys_unlink(l, (const void *)uap, retval);
513 	if (error != EPERM)
514 		return (error);
515 
516 	/*
517 	 * Linux returns EISDIR if unlink(2) is called on a directory.
518 	 * We return EPERM in such cases. To emulate correct behaviour,
519 	 * check if the path points to directory and return EISDIR if this
520 	 * is the case.
521 	 */
522 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, UIO_USERSPACE,
523 	    SCARG(uap, path));
524 	if (namei(&nd) == 0) {
525 		struct stat sb;
526 
527 		if (vn_stat(nd.ni_vp, &sb, l) == 0
528 		    && S_ISDIR(sb.st_mode))
529 			error = EISDIR;
530 
531 		vput(nd.ni_vp);
532 	}
533 
534 	return (error);
535 }
536 
537 int
538 linux_sys_mknod(struct lwp *l, const struct linux_sys_mknod_args *uap, register_t *retval)
539 {
540 	/* {
541 		syscallarg(const char *) path;
542 		syscallarg(int) mode;
543 		syscallarg(int) dev;
544 	} */
545 
546 	/*
547 	 * BSD handles FIFOs separately
548 	 */
549 	if (S_ISFIFO(SCARG(uap, mode))) {
550 		struct sys_mkfifo_args bma;
551 
552 		SCARG(&bma, path) = SCARG(uap, path);
553 		SCARG(&bma, mode) = SCARG(uap, mode);
554 		return sys_mkfifo(l, &bma, retval);
555 	} else {
556 		struct sys_mknod_args bma;
557 
558 		SCARG(&bma, path) = SCARG(uap, path);
559 		SCARG(&bma, mode) = SCARG(uap, mode);
560 		/*
561 		 * Linux device numbers uses 8 bits for minor and 8 bits
562 		 * for major. Due to how we map our major and minor,
563 		 * this just fits into our dev_t. Just mask off the
564 		 * upper 16bit to remove any random junk.
565 		 */
566 		SCARG(&bma, dev) = SCARG(uap, dev) & 0xffff;
567 		return sys_mknod(l, &bma, retval);
568 	}
569 }
570 
571 /*
572  * This is just fsync() for now (just as it is in the Linux kernel)
573  * Note: this is not implemented under Linux on Alpha and Arm
574  *	but should still be defined in our syscalls.master.
575  *	(syscall #148 on the arm)
576  */
577 int
578 linux_sys_fdatasync(struct lwp *l, const struct linux_sys_fdatasync_args *uap, register_t *retval)
579 {
580 	/* {
581 		syscallarg(int) fd;
582 	} */
583 
584 	return sys_fsync(l, (const void *)uap, retval);
585 }
586 
587 /*
588  * pread(2).
589  */
590 int
591 linux_sys_pread(struct lwp *l, const struct linux_sys_pread_args *uap, register_t *retval)
592 {
593 	/* {
594 		syscallarg(int) fd;
595 		syscallarg(void *) buf;
596 		syscallarg(size_t) nbyte;
597 		syscallarg(linux_off_t) offset;
598 	} */
599 	struct sys_pread_args pra;
600 
601 	SCARG(&pra, fd) = SCARG(uap, fd);
602 	SCARG(&pra, buf) = SCARG(uap, buf);
603 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
604 	SCARG(&pra, offset) = SCARG(uap, offset);
605 
606 	return sys_pread(l, &pra, retval);
607 }
608 
609 /*
610  * pwrite(2).
611  */
612 int
613 linux_sys_pwrite(struct lwp *l, const struct linux_sys_pwrite_args *uap, register_t *retval)
614 {
615 	/* {
616 		syscallarg(int) fd;
617 		syscallarg(void *) buf;
618 		syscallarg(size_t) nbyte;
619 		syscallarg(linux_off_t) offset;
620 	} */
621 	struct sys_pwrite_args pra;
622 
623 	SCARG(&pra, fd) = SCARG(uap, fd);
624 	SCARG(&pra, buf) = SCARG(uap, buf);
625 	SCARG(&pra, nbyte) = SCARG(uap, nbyte);
626 	SCARG(&pra, offset) = SCARG(uap, offset);
627 
628 	return sys_pwrite(l, &pra, retval);
629 }
630 
631 #define LINUX_NOT_SUPPORTED(fun) \
632 int \
633 fun(struct lwp *l, const struct fun##_args *uap, register_t *retval) \
634 { \
635 	return EOPNOTSUPP; \
636 }
637 
638 LINUX_NOT_SUPPORTED(linux_sys_setxattr)
639 LINUX_NOT_SUPPORTED(linux_sys_lsetxattr)
640 LINUX_NOT_SUPPORTED(linux_sys_fsetxattr)
641 
642 LINUX_NOT_SUPPORTED(linux_sys_getxattr)
643 LINUX_NOT_SUPPORTED(linux_sys_lgetxattr)
644 LINUX_NOT_SUPPORTED(linux_sys_fgetxattr)
645 
646 LINUX_NOT_SUPPORTED(linux_sys_listxattr)
647 LINUX_NOT_SUPPORTED(linux_sys_llistxattr)
648 LINUX_NOT_SUPPORTED(linux_sys_flistxattr)
649 
650 LINUX_NOT_SUPPORTED(linux_sys_removexattr)
651 LINUX_NOT_SUPPORTED(linux_sys_lremovexattr)
652 LINUX_NOT_SUPPORTED(linux_sys_fremovexattr)
653 
654