xref: /netbsd-src/sys/compat/linux/common/linux_file.c (revision 6a9b3088d8d2341ca1454531d365c15fe9c1c589)
1 /*	$NetBSD: linux_file.c,v 1.101 2010/11/19 06:44:37 dholland 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 2010/11/19 06:44:37 dholland 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 
106 	return res;
107 }
108 
109 static int
110 bsd_to_linux_ioflags(int bflags)
111 {
112 	int res = 0;
113 
114 	res |= cvtto_linux_mask(bflags, O_WRONLY, LINUX_O_WRONLY);
115 	res |= cvtto_linux_mask(bflags, O_RDONLY, LINUX_O_RDONLY);
116 	res |= cvtto_linux_mask(bflags, O_RDWR, LINUX_O_RDWR);
117 	res |= cvtto_linux_mask(bflags, O_CREAT, LINUX_O_CREAT);
118 	res |= cvtto_linux_mask(bflags, O_EXCL, LINUX_O_EXCL);
119 	res |= cvtto_linux_mask(bflags, O_NOCTTY, LINUX_O_NOCTTY);
120 	res |= cvtto_linux_mask(bflags, O_TRUNC, LINUX_O_TRUNC);
121 	res |= cvtto_linux_mask(bflags, O_NDELAY, LINUX_O_NDELAY);
122 	res |= cvtto_linux_mask(bflags, O_FSYNC, LINUX_O_SYNC);
123 	res |= cvtto_linux_mask(bflags, O_ASYNC, LINUX_FASYNC);
124 	res |= cvtto_linux_mask(bflags, O_APPEND, LINUX_O_APPEND);
125 	res |= cvtto_linux_mask(bflags, O_DIRECTORY, LINUX_O_DIRECTORY);
126 
127 	return res;
128 }
129 
130 /*
131  * creat(2) is an obsolete function, but it's present as a Linux
132  * system call, so let's deal with it.
133  *
134  * Note: On the Alpha this doesn't really exist in Linux, but it's defined
135  * in syscalls.master anyway so this doesn't have to be special cased.
136  *
137  * Just call open(2) with the TRUNC, CREAT and WRONLY flags.
138  */
139 int
140 linux_sys_creat(struct lwp *l, const struct linux_sys_creat_args *uap, register_t *retval)
141 {
142 	/* {
143 		syscallarg(const char *) path;
144 		syscallarg(int) mode;
145 	} */
146 	struct sys_open_args oa;
147 
148 	SCARG(&oa, path) = SCARG(uap, path);
149 	SCARG(&oa, flags) = O_CREAT | O_TRUNC | O_WRONLY;
150 	SCARG(&oa, mode) = SCARG(uap, mode);
151 
152 	return sys_open(l, &oa, retval);
153 }
154 
155 /*
156  * open(2). Take care of the different flag values, and let the
157  * NetBSD syscall do the real work. See if this operation
158  * gives the current process a controlling terminal.
159  * (XXX is this necessary?)
160  */
161 int
162 linux_sys_open(struct lwp *l, const struct linux_sys_open_args *uap, register_t *retval)
163 {
164 	/* {
165 		syscallarg(const char *) path;
166 		syscallarg(int) flags;
167 		syscallarg(int) mode;
168 	} */
169 	struct proc *p = l->l_proc;
170 	int error, fl;
171 	struct sys_open_args boa;
172 
173 	fl = linux_to_bsd_ioflags(SCARG(uap, flags));
174 
175 	SCARG(&boa, path) = SCARG(uap, path);
176 	SCARG(&boa, flags) = fl;
177 	SCARG(&boa, mode) = SCARG(uap, mode);
178 
179 	if ((error = sys_open(l, &boa, retval)))
180 		return error;
181 
182 	/*
183 	 * this bit from sunos_misc.c (and svr4_fcntl.c).
184 	 * If we are a session leader, and we don't have a controlling
185 	 * terminal yet, and the O_NOCTTY flag is not set, try to make
186 	 * this the controlling terminal.
187 	 */
188         if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_lflag & PL_CONTROLT)) {
189                 file_t *fp;
190 
191 		fp = fd_getfile(*retval);
192 
193                 /* ignore any error, just give it a try */
194                 if (fp != NULL) {
195 			if (fp->f_type == DTYPE_VNODE) {
196 				(fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, NULL);
197 			}
198 			fd_putfile(*retval);
199 		}
200         }
201 	return 0;
202 }
203 
204 /*
205  * Most actions in the fcntl() call are straightforward; simply
206  * pass control to the NetBSD system call. A few commands need
207  * conversions after the actual system call has done its work,
208  * because the flag values and lock structure are different.
209  */
210 int
211 linux_sys_fcntl(struct lwp *l, const struct linux_sys_fcntl_args *uap, register_t *retval)
212 {
213 	/* {
214 		syscallarg(int) fd;
215 		syscallarg(int) cmd;
216 		syscallarg(void *) arg;
217 	} */
218 	struct proc *p = l->l_proc;
219 	int fd, cmd, error;
220 	u_long val;
221 	void *arg;
222 	struct sys_fcntl_args fca;
223 	file_t *fp;
224 	struct vnode *vp;
225 	struct vattr va;
226 	long pgid;
227 	struct pgrp *pgrp;
228 	struct tty *tp;
229 
230 	fd = SCARG(uap, fd);
231 	cmd = SCARG(uap, cmd);
232 	arg = SCARG(uap, arg);
233 
234 	switch (cmd) {
235 
236 	case LINUX_F_DUPFD:
237 		cmd = F_DUPFD;
238 		break;
239 
240 	case LINUX_F_GETFD:
241 		cmd = F_GETFD;
242 		break;
243 
244 	case LINUX_F_SETFD:
245 		cmd = F_SETFD;
246 		break;
247 
248 	case LINUX_F_GETFL:
249 		SCARG(&fca, fd) = fd;
250 		SCARG(&fca, cmd) = F_GETFL;
251 		SCARG(&fca, arg) = arg;
252 		if ((error = sys_fcntl(l, &fca, retval)))
253 			return error;
254 		retval[0] = bsd_to_linux_ioflags(retval[0]);
255 		return 0;
256 
257 	case LINUX_F_SETFL: {
258 		file_t	*fp1 = NULL;
259 
260 		val = linux_to_bsd_ioflags((unsigned long)SCARG(uap, arg));
261 		/*
262 		 * Linux seems to have same semantics for sending SIGIO to the
263 		 * read side of socket, but slightly different semantics
264 		 * for SIGIO to the write side.  Rather than sending the SIGIO
265 		 * every time it's possible to write (directly) more data, it
266 		 * only sends SIGIO if last write(2) failed due to insufficient
267 		 * memory to hold the data. This is compatible enough
268 		 * with NetBSD semantics to not do anything about the
269 		 * difference.
270 		 *
271 		 * Linux does NOT send SIGIO for pipes. Deal with socketpair
272 		 * ones and DTYPE_PIPE ones. For these, we don't set
273 		 * the underlying flags (we don't pass O_ASYNC flag down
274 		 * to sys_fcntl()), but set the FASYNC flag for file descriptor,
275 		 * so that F_GETFL would report the ASYNC i/o is on.
276 		 */
277 		if (val & O_ASYNC) {
278 			if (((fp1 = fd_getfile(fd)) == NULL))
279 			    return (EBADF);
280 			if (((fp1->f_type == DTYPE_SOCKET) && fp1->f_data
281 			      && ((struct socket *)fp1->f_data)->so_state & SS_ISAPIPE)
282 			    || (fp1->f_type == DTYPE_PIPE))
283 				val &= ~O_ASYNC;
284 			else {
285 				/* not a pipe, do not modify anything */
286 				fd_putfile(fd);
287 				fp1 = NULL;
288 			}
289 		}
290 
291 		SCARG(&fca, fd) = fd;
292 		SCARG(&fca, cmd) = F_SETFL;
293 		SCARG(&fca, arg) = (void *) val;
294 
295 		error = sys_fcntl(l, &fca, retval);
296 
297 		/* Now set the FASYNC flag for pipes */
298 		if (fp1) {
299 			if (!error) {
300 				mutex_enter(&fp1->f_lock);
301 				fp1->f_flag |= FASYNC;
302 				mutex_exit(&fp1->f_lock);
303 			}
304 			fd_putfile(fd);
305 		}
306 
307 		return (error);
308 	    }
309 
310 	case LINUX_F_GETLK:
311 		do_linux_getlk(fd, cmd, arg, linux, flock);
312 
313 	case LINUX_F_SETLK:
314 	case LINUX_F_SETLKW:
315 		do_linux_setlk(fd, cmd, arg, linux, flock, LINUX_F_SETLK);
316 
317 	case LINUX_F_SETOWN:
318 	case LINUX_F_GETOWN:
319 		/*
320 		 * We need to route fcntl() for tty descriptors around normal
321 		 * fcntl(), since NetBSD tty TIOC{G,S}PGRP semantics is too
322 		 * restrictive for Linux F_{G,S}ETOWN. For non-tty descriptors,
323 		 * this is not a problem.
324 		 */
325 		if ((fp = fd_getfile(fd)) == NULL)
326 			return EBADF;
327 
328 		/* Check it's a character device vnode */
329 		if (fp->f_type != DTYPE_VNODE
330 		    || (vp = (struct vnode *)fp->f_data) == NULL
331 		    || vp->v_type != VCHR) {
332 			fd_putfile(fd);
333 
334 	    not_tty:
335 			/* Not a tty, proceed with common fcntl() */
336 			cmd = cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
337 			break;
338 		}
339 
340 		error = VOP_GETATTR(vp, &va, l->l_cred);
341 
342 		fd_putfile(fd);
343 
344 		if (error)
345 			return error;
346 
347 		if ((tp = cdev_tty(va.va_rdev)) == NULL)
348 			goto not_tty;
349 
350 		/* set tty pg_id appropriately */
351 		mutex_enter(proc_lock);
352 		if (cmd == LINUX_F_GETOWN) {
353 			retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
354 			mutex_exit(proc_lock);
355 			return 0;
356 		}
357 		if ((long)arg <= 0) {
358 			pgid = -(long)arg;
359 		} else {
360 			struct proc *p1 = proc_find((long)arg);
361 			if (p1 == NULL) {
362 				mutex_exit(proc_lock);
363 				return (ESRCH);
364 			}
365 			pgid = (long)p1->p_pgrp->pg_id;
366 		}
367 		pgrp = pgrp_find(pgid);
368 		if (pgrp == NULL || pgrp->pg_session != p->p_session) {
369 			mutex_exit(proc_lock);
370 			return EPERM;
371 		}
372 		tp->t_pgrp = pgrp;
373 		mutex_exit(proc_lock);
374 		return 0;
375 
376 	default:
377 		return EOPNOTSUPP;
378 	}
379 
380 	SCARG(&fca, fd) = fd;
381 	SCARG(&fca, cmd) = cmd;
382 	SCARG(&fca, arg) = arg;
383 
384 	return sys_fcntl(l, &fca, retval);
385 }
386 
387 #if !defined(__amd64__)
388 /*
389  * Convert a NetBSD stat structure to a Linux stat structure.
390  * Only the order of the fields and the padding in the structure
391  * is different. linux_fakedev is a machine-dependent function
392  * which optionally converts device driver major/minor numbers
393  * (XXX horrible, but what can you do against code that compares
394  * things against constant major device numbers? sigh)
395  */
396 static void
397 bsd_to_linux_stat(struct stat *bsp, struct linux_stat *lsp)
398 {
399 
400 	lsp->lst_dev     = linux_fakedev(bsp->st_dev, 0);
401 	lsp->lst_ino     = bsp->st_ino;
402 	lsp->lst_mode    = (linux_mode_t)bsp->st_mode;
403 	if (bsp->st_nlink >= (1 << 15))
404 		lsp->lst_nlink = (1 << 15) - 1;
405 	else
406 		lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
407 	lsp->lst_uid     = bsp->st_uid;
408 	lsp->lst_gid     = bsp->st_gid;
409 	lsp->lst_rdev    = linux_fakedev(bsp->st_rdev, 1);
410 	lsp->lst_size    = bsp->st_size;
411 	lsp->lst_blksize = bsp->st_blksize;
412 	lsp->lst_blocks  = bsp->st_blocks;
413 	lsp->lst_atime   = bsp->st_atime;
414 	lsp->lst_mtime   = bsp->st_mtime;
415 	lsp->lst_ctime   = bsp->st_ctime;
416 #ifdef LINUX_STAT_HAS_NSEC
417 	lsp->lst_atime_nsec   = bsp->st_atimensec;
418 	lsp->lst_mtime_nsec   = bsp->st_mtimensec;
419 	lsp->lst_ctime_nsec   = bsp->st_ctimensec;
420 #endif
421 }
422 
423 /*
424  * The stat functions below are plain sailing. stat and lstat are handled
425  * by one function to avoid code duplication.
426  */
427 int
428 linux_sys_fstat(struct lwp *l, const struct linux_sys_fstat_args *uap, register_t *retval)
429 {
430 	/* {
431 		syscallarg(int) fd;
432 		syscallarg(linux_stat *) sp;
433 	} */
434 	struct linux_stat tmplst;
435 	struct stat tmpst;
436 	int error;
437 
438 	error = do_sys_fstat(SCARG(uap, fd), &tmpst);
439 	if (error != 0)
440 		return error;
441 	bsd_to_linux_stat(&tmpst, &tmplst);
442 
443 	return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
444 }
445 
446 static int
447 linux_stat1(const struct linux_sys_stat_args *uap, register_t *retval, int flags)
448 {
449 	struct linux_stat tmplst;
450 	struct stat tmpst;
451 	int error;
452 
453 	error = do_sys_stat(SCARG(uap, path), flags, &tmpst);
454 	if (error != 0)
455 		return error;
456 
457 	bsd_to_linux_stat(&tmpst, &tmplst);
458 
459 	return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
460 }
461 
462 int
463 linux_sys_stat(struct lwp *l, const struct linux_sys_stat_args *uap, register_t *retval)
464 {
465 	/* {
466 		syscallarg(const char *) path;
467 		syscallarg(struct linux_stat *) sp;
468 	} */
469 
470 	return linux_stat1(uap, retval, FOLLOW);
471 }
472 
473 /* Note: this is "newlstat" in the Linux sources */
474 /*	(we don't bother with the old lstat currently) */
475 int
476 linux_sys_lstat(struct lwp *l, const struct linux_sys_lstat_args *uap, register_t *retval)
477 {
478 	/* {
479 		syscallarg(const char *) path;
480 		syscallarg(struct linux_stat *) sp;
481 	} */
482 
483 	return linux_stat1((const void *)uap, retval, NOFOLLOW);
484 }
485 #endif /* !__amd64__ */
486 
487 /*
488  * The following syscalls are mostly here because of the alternate path check.
489  */
490 int
491 linux_sys_unlink(struct lwp *l, const struct linux_sys_unlink_args *uap, register_t *retval)
492 {
493 	/* {
494 		syscallarg(const char *) path;
495 	} */
496 	int error, error2;
497 	struct pathbuf *pb;
498 	struct nameidata nd;
499 
500 	error = sys_unlink(l, (const void *)uap, retval);
501 	if (error != EPERM)
502 		return (error);
503 
504 	/*
505 	 * Linux returns EISDIR if unlink(2) is called on a directory.
506 	 * We return EPERM in such cases. To emulate correct behaviour,
507 	 * check if the path points to directory and return EISDIR if this
508 	 * is the case.
509 	 *
510 	 * XXX this should really not copy in the path buffer twice...
511 	 */
512 	error2 = pathbuf_copyin(SCARG(uap, path), &pb);
513 	if (error2) {
514 		return error2;
515 	}
516 	NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, pb);
517 	if (namei(&nd) == 0) {
518 		struct stat sb;
519 
520 		if (vn_stat(nd.ni_vp, &sb) == 0
521 		    && S_ISDIR(sb.st_mode))
522 			error = EISDIR;
523 
524 		vput(nd.ni_vp);
525 	}
526 	pathbuf_destroy(pb);
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, UIO_USERSPACE);
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