linux_file.c revision 1.105 1 /* $NetBSD: linux_file.c,v 1.105 2013/09/24 13:27:50 njoly 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.105 2013/09/24 13:27:50 njoly 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 vn_lock(vp, LK_SHARED | LK_RETRY);
344 error = VOP_GETATTR(vp, &va, l->l_cred);
345 VOP_UNLOCK(vp);
346
347 fd_putfile(fd);
348
349 if (error)
350 return error;
351
352 if ((tp = cdev_tty(va.va_rdev)) == NULL)
353 goto not_tty;
354
355 /* set tty pg_id appropriately */
356 mutex_enter(proc_lock);
357 if (cmd == LINUX_F_GETOWN) {
358 retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
359 mutex_exit(proc_lock);
360 return 0;
361 }
362 if ((long)arg <= 0) {
363 pgid = -(long)arg;
364 } else {
365 struct proc *p1 = proc_find((long)arg);
366 if (p1 == NULL) {
367 mutex_exit(proc_lock);
368 return (ESRCH);
369 }
370 pgid = (long)p1->p_pgrp->pg_id;
371 }
372 pgrp = pgrp_find(pgid);
373 if (pgrp == NULL || pgrp->pg_session != p->p_session) {
374 mutex_exit(proc_lock);
375 return EPERM;
376 }
377 tp->t_pgrp = pgrp;
378 mutex_exit(proc_lock);
379 return 0;
380
381 default:
382 return EOPNOTSUPP;
383 }
384
385 SCARG(&fca, fd) = fd;
386 SCARG(&fca, cmd) = cmd;
387 SCARG(&fca, arg) = arg;
388
389 return sys_fcntl(l, &fca, retval);
390 }
391
392 #if !defined(__amd64__)
393 /*
394 * Convert a NetBSD stat structure to a Linux stat structure.
395 * Only the order of the fields and the padding in the structure
396 * is different. linux_fakedev is a machine-dependent function
397 * which optionally converts device driver major/minor numbers
398 * (XXX horrible, but what can you do against code that compares
399 * things against constant major device numbers? sigh)
400 */
401 static void
402 bsd_to_linux_stat(struct stat *bsp, struct linux_stat *lsp)
403 {
404
405 lsp->lst_dev = linux_fakedev(bsp->st_dev, 0);
406 lsp->lst_ino = bsp->st_ino;
407 lsp->lst_mode = (linux_mode_t)bsp->st_mode;
408 if (bsp->st_nlink >= (1 << 15))
409 lsp->lst_nlink = (1 << 15) - 1;
410 else
411 lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
412 lsp->lst_uid = bsp->st_uid;
413 lsp->lst_gid = bsp->st_gid;
414 lsp->lst_rdev = linux_fakedev(bsp->st_rdev, 1);
415 lsp->lst_size = bsp->st_size;
416 lsp->lst_blksize = bsp->st_blksize;
417 lsp->lst_blocks = bsp->st_blocks;
418 lsp->lst_atime = bsp->st_atime;
419 lsp->lst_mtime = bsp->st_mtime;
420 lsp->lst_ctime = bsp->st_ctime;
421 #ifdef LINUX_STAT_HAS_NSEC
422 lsp->lst_atime_nsec = bsp->st_atimensec;
423 lsp->lst_mtime_nsec = bsp->st_mtimensec;
424 lsp->lst_ctime_nsec = bsp->st_ctimensec;
425 #endif
426 }
427
428 /*
429 * The stat functions below are plain sailing. stat and lstat are handled
430 * by one function to avoid code duplication.
431 */
432 int
433 linux_sys_fstat(struct lwp *l, const struct linux_sys_fstat_args *uap, register_t *retval)
434 {
435 /* {
436 syscallarg(int) fd;
437 syscallarg(linux_stat *) sp;
438 } */
439 struct linux_stat tmplst;
440 struct stat tmpst;
441 int error;
442
443 error = do_sys_fstat(SCARG(uap, fd), &tmpst);
444 if (error != 0)
445 return error;
446 bsd_to_linux_stat(&tmpst, &tmplst);
447
448 return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
449 }
450
451 static int
452 linux_stat1(const struct linux_sys_stat_args *uap, register_t *retval, int flags)
453 {
454 struct linux_stat tmplst;
455 struct stat tmpst;
456 int error;
457
458 error = do_sys_stat(SCARG(uap, path), flags, &tmpst);
459 if (error != 0)
460 return error;
461
462 bsd_to_linux_stat(&tmpst, &tmplst);
463
464 return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
465 }
466
467 int
468 linux_sys_stat(struct lwp *l, const struct linux_sys_stat_args *uap, register_t *retval)
469 {
470 /* {
471 syscallarg(const char *) path;
472 syscallarg(struct linux_stat *) sp;
473 } */
474
475 return linux_stat1(uap, retval, FOLLOW);
476 }
477
478 /* Note: this is "newlstat" in the Linux sources */
479 /* (we don't bother with the old lstat currently) */
480 int
481 linux_sys_lstat(struct lwp *l, const struct linux_sys_lstat_args *uap, register_t *retval)
482 {
483 /* {
484 syscallarg(const char *) path;
485 syscallarg(struct linux_stat *) sp;
486 } */
487
488 return linux_stat1((const void *)uap, retval, NOFOLLOW);
489 }
490 #endif /* !__amd64__ */
491
492 /*
493 * The following syscalls are mostly here because of the alternate path check.
494 */
495 int
496 linux_sys_unlink(struct lwp *l, const struct linux_sys_unlink_args *uap, register_t *retval)
497 {
498 /* {
499 syscallarg(const char *) path;
500 } */
501 int error, error2;
502 struct pathbuf *pb;
503 struct nameidata nd;
504
505 error = sys_unlink(l, (const void *)uap, retval);
506 if (error != EPERM)
507 return (error);
508
509 /*
510 * Linux returns EISDIR if unlink(2) is called on a directory.
511 * We return EPERM in such cases. To emulate correct behaviour,
512 * check if the path points to directory and return EISDIR if this
513 * is the case.
514 *
515 * XXX this should really not copy in the path buffer twice...
516 */
517 error2 = pathbuf_copyin(SCARG(uap, path), &pb);
518 if (error2) {
519 return error2;
520 }
521 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, pb);
522 if (namei(&nd) == 0) {
523 struct stat sb;
524
525 if (vn_stat(nd.ni_vp, &sb) == 0
526 && S_ISDIR(sb.st_mode))
527 error = EISDIR;
528
529 vput(nd.ni_vp);
530 }
531 pathbuf_destroy(pb);
532
533 return (error);
534 }
535
536 int
537 linux_sys_mknod(struct lwp *l, const struct linux_sys_mknod_args *uap, register_t *retval)
538 {
539 /* {
540 syscallarg(const char *) path;
541 syscallarg(int) mode;
542 syscallarg(int) dev;
543 } */
544
545 /*
546 * BSD handles FIFOs separately
547 */
548 if (S_ISFIFO(SCARG(uap, mode))) {
549 struct sys_mkfifo_args bma;
550
551 SCARG(&bma, path) = SCARG(uap, path);
552 SCARG(&bma, mode) = SCARG(uap, mode);
553 return sys_mkfifo(l, &bma, retval);
554 } else {
555
556 /*
557 * Linux device numbers uses 8 bits for minor and 8 bits
558 * for major. Due to how we map our major and minor,
559 * this just fits into our dev_t. Just mask off the
560 * upper 16bit to remove any random junk.
561 */
562 return do_sys_mknod(l, SCARG(uap, path), SCARG(uap, mode),
563 SCARG(uap, dev) & 0xffff, retval, UIO_USERSPACE);
564 }
565 }
566
567 /*
568 * This is just fsync() for now (just as it is in the Linux kernel)
569 * Note: this is not implemented under Linux on Alpha and Arm
570 * but should still be defined in our syscalls.master.
571 * (syscall #148 on the arm)
572 */
573 int
574 linux_sys_fdatasync(struct lwp *l, const struct linux_sys_fdatasync_args *uap, register_t *retval)
575 {
576 /* {
577 syscallarg(int) fd;
578 } */
579
580 return sys_fsync(l, (const void *)uap, retval);
581 }
582
583 /*
584 * pread(2).
585 */
586 int
587 linux_sys_pread(struct lwp *l, const struct linux_sys_pread_args *uap, register_t *retval)
588 {
589 /* {
590 syscallarg(int) fd;
591 syscallarg(void *) buf;
592 syscallarg(size_t) nbyte;
593 syscallarg(linux_off_t) offset;
594 } */
595 struct sys_pread_args pra;
596
597 SCARG(&pra, fd) = SCARG(uap, fd);
598 SCARG(&pra, buf) = SCARG(uap, buf);
599 SCARG(&pra, nbyte) = SCARG(uap, nbyte);
600 SCARG(&pra, offset) = SCARG(uap, offset);
601
602 return sys_pread(l, &pra, retval);
603 }
604
605 /*
606 * pwrite(2).
607 */
608 int
609 linux_sys_pwrite(struct lwp *l, const struct linux_sys_pwrite_args *uap, register_t *retval)
610 {
611 /* {
612 syscallarg(int) fd;
613 syscallarg(void *) buf;
614 syscallarg(size_t) nbyte;
615 syscallarg(linux_off_t) offset;
616 } */
617 struct sys_pwrite_args pra;
618
619 SCARG(&pra, fd) = SCARG(uap, fd);
620 SCARG(&pra, buf) = SCARG(uap, buf);
621 SCARG(&pra, nbyte) = SCARG(uap, nbyte);
622 SCARG(&pra, offset) = SCARG(uap, offset);
623
624 return sys_pwrite(l, &pra, retval);
625 }
626
627 int
628 linux_sys_dup3(struct lwp *l, const struct linux_sys_dup3_args *uap,
629 register_t *retval)
630 {
631 /* {
632 syscallarg(int) from;
633 syscallarg(int) to;
634 syscallarg(int) flags;
635 } */
636 int error;
637 if ((error = sys_dup2(l, (const struct sys_dup2_args *)uap, retval)))
638 return error;
639
640 if (SCARG(uap, flags) & LINUX_O_CLOEXEC)
641 fd_set_exclose(l, SCARG(uap, to), true);
642
643 return 0;
644 }
645
646
647 int
648 linux_to_bsd_atflags(int lflags)
649 {
650 int bflags = 0;
651
652 if (lflags & LINUX_AT_SYMLINK_NOFOLLOW)
653 bflags |= AT_SYMLINK_NOFOLLOW;
654 if (lflags & LINUX_AT_REMOVEDIR)
655 bflags |= AT_REMOVEDIR;
656 if (lflags & LINUX_AT_SYMLINK_FOLLOW)
657 bflags |= AT_SYMLINK_FOLLOW;
658
659 return bflags;
660 }
661
662
663 #define LINUX_NOT_SUPPORTED(fun) \
664 int \
665 fun(struct lwp *l, const struct fun##_args *uap, register_t *retval) \
666 { \
667 return EOPNOTSUPP; \
668 }
669
670 LINUX_NOT_SUPPORTED(linux_sys_setxattr)
671 LINUX_NOT_SUPPORTED(linux_sys_lsetxattr)
672 LINUX_NOT_SUPPORTED(linux_sys_fsetxattr)
673
674 LINUX_NOT_SUPPORTED(linux_sys_getxattr)
675 LINUX_NOT_SUPPORTED(linux_sys_lgetxattr)
676 LINUX_NOT_SUPPORTED(linux_sys_fgetxattr)
677
678 LINUX_NOT_SUPPORTED(linux_sys_listxattr)
679 LINUX_NOT_SUPPORTED(linux_sys_llistxattr)
680 LINUX_NOT_SUPPORTED(linux_sys_flistxattr)
681
682 LINUX_NOT_SUPPORTED(linux_sys_removexattr)
683 LINUX_NOT_SUPPORTED(linux_sys_lremovexattr)
684 LINUX_NOT_SUPPORTED(linux_sys_fremovexattr)
685