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