linux_file.c revision 1.69.2.5 1 /* $NetBSD: linux_file.c,v 1.69.2.5 2007/10/27 11:29:36 yamt 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.69.2.5 2007/10/27 11:29:36 yamt 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 __P((int));
79 static int bsd_to_linux_ioflags __P((int));
80 static void bsd_to_linux_flock __P((struct flock *, struct linux_flock *));
81 static void linux_to_bsd_flock __P((struct linux_flock *, struct flock *));
82 #ifndef __amd64__
83 static void bsd_to_linux_stat __P((struct stat *, struct linux_stat *));
84 static int linux_stat1 __P((struct lwp *, void *, register_t *, int));
85 #endif
86
87 /*
88 * Some file-related calls are handled here. The usual flag conversion
89 * an structure conversion is done, and alternate emul path searching.
90 */
91
92 /*
93 * The next two functions convert between the Linux and NetBSD values
94 * of the flags used in open(2) and fcntl(2).
95 */
96 static int
97 linux_to_bsd_ioflags(lflags)
98 int lflags;
99 {
100 int res = 0;
101
102 res |= cvtto_bsd_mask(lflags, LINUX_O_WRONLY, O_WRONLY);
103 res |= cvtto_bsd_mask(lflags, LINUX_O_RDONLY, O_RDONLY);
104 res |= cvtto_bsd_mask(lflags, LINUX_O_RDWR, O_RDWR);
105 res |= cvtto_bsd_mask(lflags, LINUX_O_CREAT, O_CREAT);
106 res |= cvtto_bsd_mask(lflags, LINUX_O_EXCL, O_EXCL);
107 res |= cvtto_bsd_mask(lflags, LINUX_O_NOCTTY, O_NOCTTY);
108 res |= cvtto_bsd_mask(lflags, LINUX_O_TRUNC, O_TRUNC);
109 res |= cvtto_bsd_mask(lflags, LINUX_O_NDELAY, O_NDELAY);
110 res |= cvtto_bsd_mask(lflags, LINUX_O_SYNC, O_FSYNC);
111 res |= cvtto_bsd_mask(lflags, LINUX_FASYNC, O_ASYNC);
112 res |= cvtto_bsd_mask(lflags, LINUX_O_APPEND, O_APPEND);
113
114 return res;
115 }
116
117 static int
118 bsd_to_linux_ioflags(bflags)
119 int bflags;
120 {
121 int res = 0;
122
123 res |= cvtto_linux_mask(bflags, O_WRONLY, LINUX_O_WRONLY);
124 res |= cvtto_linux_mask(bflags, O_RDONLY, LINUX_O_RDONLY);
125 res |= cvtto_linux_mask(bflags, O_RDWR, LINUX_O_RDWR);
126 res |= cvtto_linux_mask(bflags, O_CREAT, LINUX_O_CREAT);
127 res |= cvtto_linux_mask(bflags, O_EXCL, LINUX_O_EXCL);
128 res |= cvtto_linux_mask(bflags, O_NOCTTY, LINUX_O_NOCTTY);
129 res |= cvtto_linux_mask(bflags, O_TRUNC, LINUX_O_TRUNC);
130 res |= cvtto_linux_mask(bflags, O_NDELAY, LINUX_O_NDELAY);
131 res |= cvtto_linux_mask(bflags, O_FSYNC, LINUX_O_SYNC);
132 res |= cvtto_linux_mask(bflags, O_ASYNC, LINUX_FASYNC);
133 res |= cvtto_linux_mask(bflags, O_APPEND, LINUX_O_APPEND);
134
135 return res;
136 }
137
138 /*
139 * creat(2) is an obsolete function, but it's present as a Linux
140 * system call, so let's deal with it.
141 *
142 * Note: On the Alpha this doesn't really exist in Linux, but it's defined
143 * in syscalls.master anyway so this doesn't have to be special cased.
144 *
145 * Just call open(2) with the TRUNC, CREAT and WRONLY flags.
146 */
147 int
148 linux_sys_creat(l, v, retval)
149 struct lwp *l;
150 void *v;
151 register_t *retval;
152 {
153 struct linux_sys_creat_args /* {
154 syscallarg(const char *) path;
155 syscallarg(int) mode;
156 } */ *uap = v;
157 struct sys_open_args oa;
158
159 SCARG(&oa, path) = SCARG(uap, path);
160 SCARG(&oa, flags) = O_CREAT | O_TRUNC | O_WRONLY;
161 SCARG(&oa, mode) = SCARG(uap, mode);
162
163 return sys_open(l, &oa, retval);
164 }
165
166 /*
167 * open(2). Take care of the different flag values, and let the
168 * NetBSD syscall do the real work. See if this operation
169 * gives the current process a controlling terminal.
170 * (XXX is this necessary?)
171 */
172 int
173 linux_sys_open(l, v, retval)
174 struct lwp *l;
175 void *v;
176 register_t *retval;
177 {
178 struct linux_sys_open_args /* {
179 syscallarg(const char *) path;
180 syscallarg(int) flags;
181 syscallarg(int) mode;
182 } */ *uap = v;
183 struct proc *p = l->l_proc;
184 int error, fl;
185 struct sys_open_args boa;
186
187 fl = linux_to_bsd_ioflags(SCARG(uap, flags));
188
189 SCARG(&boa, path) = SCARG(uap, path);
190 SCARG(&boa, flags) = fl;
191 SCARG(&boa, mode) = SCARG(uap, mode);
192
193 if ((error = sys_open(l, &boa, retval)))
194 return error;
195
196 /*
197 * this bit from sunos_misc.c (and svr4_fcntl.c).
198 * If we are a session leader, and we don't have a controlling
199 * terminal yet, and the O_NOCTTY flag is not set, try to make
200 * this the controlling terminal.
201 */
202 if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_lflag & PL_CONTROLT)) {
203 struct filedesc *fdp = p->p_fd;
204 struct file *fp;
205
206 fp = fd_getfile(fdp, *retval);
207
208 /* ignore any error, just give it a try */
209 if (fp != NULL) {
210 FILE_USE(fp);
211 if (fp->f_type == DTYPE_VNODE) {
212 (fp->f_ops->fo_ioctl) (fp, TIOCSCTTY,
213 (void *) 0, l);
214 }
215 FILE_UNUSE(fp, l);
216 }
217 }
218 return 0;
219 }
220
221 /*
222 * The next two functions take care of converting the flock
223 * structure back and forth between Linux and NetBSD format.
224 * The only difference in the structures is the order of
225 * the fields, and the 'whence' value.
226 */
227 static void
228 bsd_to_linux_flock(bfp, lfp)
229 struct flock *bfp;
230 struct linux_flock *lfp;
231 {
232
233 lfp->l_start = bfp->l_start;
234 lfp->l_len = bfp->l_len;
235 lfp->l_pid = bfp->l_pid;
236 lfp->l_whence = bfp->l_whence;
237 switch (bfp->l_type) {
238 case F_RDLCK:
239 lfp->l_type = LINUX_F_RDLCK;
240 break;
241 case F_UNLCK:
242 lfp->l_type = LINUX_F_UNLCK;
243 break;
244 case F_WRLCK:
245 lfp->l_type = LINUX_F_WRLCK;
246 break;
247 }
248 }
249
250 static void
251 linux_to_bsd_flock(lfp, bfp)
252 struct linux_flock *lfp;
253 struct flock *bfp;
254 {
255
256 bfp->l_start = lfp->l_start;
257 bfp->l_len = lfp->l_len;
258 bfp->l_pid = lfp->l_pid;
259 bfp->l_whence = lfp->l_whence;
260 switch (lfp->l_type) {
261 case LINUX_F_RDLCK:
262 bfp->l_type = F_RDLCK;
263 break;
264 case LINUX_F_UNLCK:
265 bfp->l_type = F_UNLCK;
266 break;
267 case LINUX_F_WRLCK:
268 bfp->l_type = F_WRLCK;
269 break;
270 }
271 }
272
273 /*
274 * Most actions in the fcntl() call are straightforward; simply
275 * pass control to the NetBSD system call. A few commands need
276 * conversions after the actual system call has done its work,
277 * because the flag values and lock structure are different.
278 */
279 int
280 linux_sys_fcntl(l, v, retval)
281 struct lwp *l;
282 void *v;
283 register_t *retval;
284 {
285 struct linux_sys_fcntl_args /* {
286 syscallarg(int) fd;
287 syscallarg(int) cmd;
288 syscallarg(void *) arg;
289 } */ *uap = v;
290 struct proc *p = l->l_proc;
291 int fd, cmd, error;
292 u_long val;
293 void *arg;
294 struct linux_flock lfl;
295 struct flock bfl;
296 struct sys_fcntl_args fca;
297 struct filedesc *fdp;
298 struct file *fp;
299 struct vnode *vp;
300 struct vattr va;
301 const struct cdevsw *cdev;
302 long pgid;
303 struct pgrp *pgrp;
304 struct tty *tp, *(*d_tty) __P((dev_t));
305
306 fd = SCARG(uap, fd);
307 cmd = SCARG(uap, cmd);
308 arg = (void *) SCARG(uap, arg);
309
310 switch (cmd) {
311 case LINUX_F_DUPFD:
312 cmd = F_DUPFD;
313 break;
314 case LINUX_F_GETFD:
315 cmd = F_GETFD;
316 break;
317 case LINUX_F_SETFD:
318 cmd = F_SETFD;
319 break;
320 case LINUX_F_GETFL:
321 SCARG(&fca, fd) = fd;
322 SCARG(&fca, cmd) = F_GETFL;
323 SCARG(&fca, arg) = arg;
324 if ((error = sys_fcntl(l, &fca, retval)))
325 return error;
326 retval[0] = bsd_to_linux_ioflags(retval[0]);
327 return 0;
328 case LINUX_F_SETFL: {
329 struct file *fp1 = NULL;
330
331 val = linux_to_bsd_ioflags((unsigned long)SCARG(uap, arg));
332 /*
333 * Linux seems to have same semantics for sending SIGIO to the
334 * read side of socket, but slightly different semantics
335 * for SIGIO to the write side. Rather than sending the SIGIO
336 * every time it's possible to write (directly) more data, it
337 * only sends SIGIO if last write(2) failed due to insufficient
338 * memory to hold the data. This is compatible enough
339 * with NetBSD semantics to not do anything about the
340 * difference.
341 *
342 * Linux does NOT send SIGIO for pipes. Deal with socketpair
343 * ones and DTYPE_PIPE ones. For these, we don't set
344 * the underlying flags (we don't pass O_ASYNC flag down
345 * to sys_fcntl()), but set the FASYNC flag for file descriptor,
346 * so that F_GETFL would report the ASYNC i/o is on.
347 */
348 if (val & O_ASYNC) {
349 if (((fp1 = fd_getfile(p->p_fd, fd)) == NULL))
350 return (EBADF);
351
352 FILE_USE(fp1);
353
354 if (((fp1->f_type == DTYPE_SOCKET) && fp1->f_data
355 && ((struct socket *)fp1->f_data)->so_state & SS_ISAPIPE)
356 || (fp1->f_type == DTYPE_PIPE))
357 val &= ~O_ASYNC;
358 else {
359 /* not a pipe, do not modify anything */
360 FILE_UNUSE(fp1, l);
361 fp1 = NULL;
362 }
363 }
364
365 SCARG(&fca, fd) = fd;
366 SCARG(&fca, cmd) = F_SETFL;
367 SCARG(&fca, arg) = (void *) val;
368
369 error = sys_fcntl(l, &fca, retval);
370
371 /* Now set the FASYNC flag for pipes */
372 if (fp1) {
373 if (!error)
374 fp1->f_flag |= FASYNC;
375 FILE_UNUSE(fp1, l);
376 }
377
378 return (error);
379 }
380 case LINUX_F_GETLK:
381 if ((error = copyin(arg, &lfl, sizeof lfl)))
382 return error;
383 linux_to_bsd_flock(&lfl, &bfl);
384 error = do_fcntl_lock(l, fd, F_GETLK, &bfl);
385 if (error)
386 return error;
387 bsd_to_linux_flock(&bfl, &lfl);
388 return copyout(&lfl, arg, sizeof lfl);
389
390 case LINUX_F_SETLK:
391 case LINUX_F_SETLKW:
392 cmd = (cmd == LINUX_F_SETLK ? F_SETLK : F_SETLKW);
393 if ((error = copyin(arg, &lfl, sizeof lfl)))
394 return error;
395 linux_to_bsd_flock(&lfl, &bfl);
396 return do_fcntl_lock(l, fd, cmd, &bfl);
397
398 case LINUX_F_SETOWN:
399 case LINUX_F_GETOWN:
400 /*
401 * We need to route fcntl() for tty descriptors around normal
402 * fcntl(), since NetBSD tty TIOC{G,S}PGRP semantics is too
403 * restrictive for Linux F_{G,S}ETOWN. For non-tty descriptors,
404 * this is not a problem.
405 */
406 fdp = p->p_fd;
407 if ((fp = fd_getfile(fdp, fd)) == NULL)
408 return EBADF;
409 FILE_USE(fp);
410
411 /* Check it's a character device vnode */
412 if (fp->f_type != DTYPE_VNODE
413 || (vp = (struct vnode *)fp->f_data) == NULL
414 || vp->v_type != VCHR) {
415 FILE_UNUSE(fp, l);
416
417 not_tty:
418 /* Not a tty, proceed with common fcntl() */
419 cmd = cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
420 break;
421 }
422
423 error = VOP_GETATTR(vp, &va, l->l_cred, l);
424
425 FILE_UNUSE(fp, l);
426
427 if (error)
428 return error;
429
430 cdev = cdevsw_lookup(va.va_rdev);
431 if (cdev == NULL)
432 return (ENXIO);
433 d_tty = cdev->d_tty;
434 if (!d_tty || (!(tp = (*d_tty)(va.va_rdev))))
435 goto not_tty;
436
437 /* set tty pg_id appropriately */
438 if (cmd == LINUX_F_GETOWN) {
439 retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PGID;
440 return 0;
441 }
442 mutex_enter(&proclist_lock);
443 if ((long)arg <= 0) {
444 pgid = -(long)arg;
445 } else {
446 struct proc *p1 = p_find((long)arg, PFIND_LOCKED | PFIND_UNLOCK_FAIL);
447 if (p1 == NULL)
448 return (ESRCH);
449 pgid = (long)p1->p_pgrp->pg_id;
450 }
451 pgrp = pg_find(pgid, PFIND_LOCKED);
452 if (pgrp == NULL || pgrp->pg_session != p->p_session) {
453 mutex_exit(&proclist_lock);
454 return EPERM;
455 }
456 tp->t_pgrp = pgrp;
457 mutex_exit(&proclist_lock);
458 return 0;
459
460 default:
461 return EOPNOTSUPP;
462 }
463
464 SCARG(&fca, fd) = fd;
465 SCARG(&fca, cmd) = cmd;
466 SCARG(&fca, arg) = arg;
467
468 return sys_fcntl(l, &fca, retval);
469 }
470
471 #if !defined(__amd64__)
472 /*
473 * Convert a NetBSD stat structure to a Linux stat structure.
474 * Only the order of the fields and the padding in the structure
475 * is different. linux_fakedev is a machine-dependent function
476 * which optionally converts device driver major/minor numbers
477 * (XXX horrible, but what can you do against code that compares
478 * things against constant major device numbers? sigh)
479 */
480 static void
481 bsd_to_linux_stat(bsp, lsp)
482 struct stat *bsp;
483 struct linux_stat *lsp;
484 {
485
486 lsp->lst_dev = linux_fakedev(bsp->st_dev, 0);
487 lsp->lst_ino = bsp->st_ino;
488 lsp->lst_mode = (linux_mode_t)bsp->st_mode;
489 if (bsp->st_nlink >= (1 << 15))
490 lsp->lst_nlink = (1 << 15) - 1;
491 else
492 lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
493 lsp->lst_uid = bsp->st_uid;
494 lsp->lst_gid = bsp->st_gid;
495 lsp->lst_rdev = linux_fakedev(bsp->st_rdev, 1);
496 lsp->lst_size = bsp->st_size;
497 lsp->lst_blksize = bsp->st_blksize;
498 lsp->lst_blocks = bsp->st_blocks;
499 lsp->lst_atime = bsp->st_atime;
500 lsp->lst_mtime = bsp->st_mtime;
501 lsp->lst_ctime = bsp->st_ctime;
502 #ifdef LINUX_STAT_HAS_NSEC
503 lsp->lst_atime_nsec = bsp->st_atimensec;
504 lsp->lst_mtime_nsec = bsp->st_mtimensec;
505 lsp->lst_ctime_nsec = bsp->st_ctimensec;
506 #endif
507 }
508
509 /*
510 * The stat functions below are plain sailing. stat and lstat are handled
511 * by one function to avoid code duplication.
512 */
513 int
514 linux_sys_fstat(l, v, retval)
515 struct lwp *l;
516 void *v;
517 register_t *retval;
518 {
519 struct linux_sys_fstat_args /* {
520 syscallarg(int) fd;
521 syscallarg(linux_stat *) sp;
522 } */ *uap = v;
523 struct linux_stat tmplst;
524 struct stat tmpst;
525 int error;
526
527 error = do_sys_fstat(l, SCARG(uap, fd), &tmpst);
528 if (error != 0)
529 return error;
530 bsd_to_linux_stat(&tmpst, &tmplst);
531
532 return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
533 }
534
535 static int
536 linux_stat1(l, v, retval, flags)
537 struct lwp *l;
538 void *v;
539 register_t *retval;
540 int flags;
541 {
542 struct linux_stat tmplst;
543 struct stat tmpst;
544 int error;
545 struct linux_sys_stat_args *uap = v;
546
547 error = do_sys_stat(l, SCARG(uap, path), flags, &tmpst);
548 if (error != 0)
549 return error;
550
551 bsd_to_linux_stat(&tmpst, &tmplst);
552
553 return copyout(&tmplst, SCARG(uap, sp), sizeof tmplst);
554 }
555
556 int
557 linux_sys_stat(l, v, retval)
558 struct lwp *l;
559 void *v;
560 register_t *retval;
561 {
562 struct linux_sys_stat_args /* {
563 syscallarg(const char *) path;
564 syscallarg(struct linux_stat *) sp;
565 } */ *uap = v;
566
567 return linux_stat1(l, uap, retval, FOLLOW);
568 }
569
570 /* Note: this is "newlstat" in the Linux sources */
571 /* (we don't bother with the old lstat currently) */
572 int
573 linux_sys_lstat(l, v, retval)
574 struct lwp *l;
575 void *v;
576 register_t *retval;
577 {
578 struct linux_sys_lstat_args /* {
579 syscallarg(const char *) path;
580 syscallarg(struct linux_stat *) sp;
581 } */ *uap = v;
582
583 return linux_stat1(l, uap, retval, NOFOLLOW);
584 }
585 #endif /* !__amd64__ */
586
587 /*
588 * The following syscalls are mostly here because of the alternate path check.
589 */
590 int
591 linux_sys_access(l, v, retval)
592 struct lwp *l;
593 void *v;
594 register_t *retval;
595 {
596 struct linux_sys_access_args /* {
597 syscallarg(const char *) path;
598 syscallarg(int) flags;
599 } */ *uap = v;
600
601 return sys_access(l, uap, retval);
602 }
603
604 int
605 linux_sys_unlink(l, v, retval)
606 struct lwp *l;
607 void *v;
608 register_t *retval;
609
610 {
611 struct linux_sys_unlink_args /* {
612 syscallarg(const char *) path;
613 } */ *uap = v;
614 int error;
615 struct nameidata nd;
616
617 error = sys_unlink(l, uap, retval);
618 if (error != EPERM)
619 return (error);
620
621 /*
622 * Linux returns EISDIR if unlink(2) is called on a directory.
623 * We return EPERM in such cases. To emulate correct behaviour,
624 * check if the path points to directory and return EISDIR if this
625 * is the case.
626 */
627 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | TRYEMULROOT, UIO_USERSPACE,
628 SCARG(uap, path), l);
629 if (namei(&nd) == 0) {
630 struct stat sb;
631
632 if (vn_stat(nd.ni_vp, &sb, l) == 0
633 && S_ISDIR(sb.st_mode))
634 error = EISDIR;
635
636 vput(nd.ni_vp);
637 }
638
639 return (error);
640 }
641
642 int
643 linux_sys_chdir(l, v, retval)
644 struct lwp *l;
645 void *v;
646 register_t *retval;
647 {
648 struct linux_sys_chdir_args /* {
649 syscallarg(const char *) path;
650 } */ *uap = v;
651
652 return sys_chdir(l, uap, retval);
653 }
654
655 int
656 linux_sys_mknod(l, v, retval)
657 struct lwp *l;
658 void *v;
659 register_t *retval;
660 {
661 struct linux_sys_mknod_args /* {
662 syscallarg(const char *) path;
663 syscallarg(int) mode;
664 syscallarg(int) dev;
665 } */ *uap = v;
666
667 /*
668 * BSD handles FIFOs separately
669 */
670 if (S_ISFIFO(SCARG(uap, mode))) {
671 struct sys_mkfifo_args bma;
672
673 SCARG(&bma, path) = SCARG(uap, path);
674 SCARG(&bma, mode) = SCARG(uap, mode);
675 return sys_mkfifo(l, &bma, retval);
676 } else {
677 struct sys_mknod_args bma;
678
679 SCARG(&bma, path) = SCARG(uap, path);
680 SCARG(&bma, mode) = SCARG(uap, mode);
681 /*
682 * Linux device numbers uses 8 bits for minor and 8 bits
683 * for major. Due to how we map our major and minor,
684 * this just fits into our dev_t. Just mask off the
685 * upper 16bit to remove any random junk.
686 */
687 SCARG(&bma, dev) = SCARG(uap, dev) & 0xffff;
688 return sys_mknod(l, &bma, retval);
689 }
690 }
691
692 int
693 linux_sys_chmod(l, v, retval)
694 struct lwp *l;
695 void *v;
696 register_t *retval;
697 {
698 struct linux_sys_chmod_args /* {
699 syscallarg(const char *) path;
700 syscallarg(int) mode;
701 } */ *uap = v;
702
703 return sys_chmod(l, uap, retval);
704 }
705
706 #if defined(__i386__) || defined(__m68k__) || \
707 defined(__arm__)
708 int
709 linux_sys_chown16(l, v, retval)
710 struct lwp *l;
711 void *v;
712 register_t *retval;
713 {
714 struct linux_sys_chown16_args /* {
715 syscallarg(const char *) path;
716 syscallarg(int) uid;
717 syscallarg(int) gid;
718 } */ *uap = v;
719 struct sys___posix_chown_args bca;
720
721 SCARG(&bca, path) = SCARG(uap, path);
722 SCARG(&bca, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
723 (uid_t)-1 : SCARG(uap, uid);
724 SCARG(&bca, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
725 (gid_t)-1 : SCARG(uap, gid);
726
727 return sys___posix_chown(l, &bca, retval);
728 }
729
730 int
731 linux_sys_fchown16(l, v, retval)
732 struct lwp *l;
733 void *v;
734 register_t *retval;
735 {
736 struct linux_sys_fchown16_args /* {
737 syscallarg(int) fd;
738 syscallarg(int) uid;
739 syscallarg(int) gid;
740 } */ *uap = v;
741 struct sys___posix_fchown_args bfa;
742
743 SCARG(&bfa, fd) = SCARG(uap, fd);
744 SCARG(&bfa, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
745 (uid_t)-1 : SCARG(uap, uid);
746 SCARG(&bfa, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
747 (gid_t)-1 : SCARG(uap, gid);
748
749 return sys___posix_fchown(l, &bfa, retval);
750 }
751
752 int
753 linux_sys_lchown16(l, v, retval)
754 struct lwp *l;
755 void *v;
756 register_t *retval;
757 {
758 struct linux_sys_lchown16_args /* {
759 syscallarg(char *) path;
760 syscallarg(int) uid;
761 syscallarg(int) gid;
762 } */ *uap = v;
763 struct sys___posix_lchown_args bla;
764
765 SCARG(&bla, path) = SCARG(uap, path);
766 SCARG(&bla, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
767 (uid_t)-1 : SCARG(uap, uid);
768 SCARG(&bla, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
769 (gid_t)-1 : SCARG(uap, gid);
770
771 return sys___posix_lchown(l, &bla, retval);
772 }
773 #endif /* __i386__ || __m68k__ || __arm__ || __amd64__ */
774 #if defined (__i386__) || defined (__m68k__) || defined(__amd64__) || \
775 defined (__powerpc__) || defined (__mips__) || defined (__arm__)
776 int
777 linux_sys_chown(l, v, retval)
778 struct lwp *l;
779 void *v;
780 register_t *retval;
781 {
782 struct linux_sys_chown_args /* {
783 syscallarg(char *) path;
784 syscallarg(int) uid;
785 syscallarg(int) gid;
786 } */ *uap = v;
787
788 return sys___posix_chown(l, uap, retval);
789 }
790
791 int
792 linux_sys_lchown(l, v, retval)
793 struct lwp *l;
794 void *v;
795 register_t *retval;
796 {
797 struct linux_sys_lchown_args /* {
798 syscallarg(char *) path;
799 syscallarg(int) uid;
800 syscallarg(int) gid;
801 } */ *uap = v;
802
803 return sys___posix_lchown(l, uap, retval);
804 }
805 #endif /* __i386__||__m68k__||__powerpc__||__mips__||__arm__ ||__amd64__ */
806
807 int
808 linux_sys_rename(l, v, retval)
809 struct lwp *l;
810 void *v;
811 register_t *retval;
812 {
813 struct linux_sys_rename_args /* {
814 syscallarg(const char *) from;
815 syscallarg(const char *) to;
816 } */ *uap = v;
817
818 return sys___posix_rename(l, uap, retval);
819 }
820
821 int
822 linux_sys_mkdir(l, v, retval)
823 struct lwp *l;
824 void *v;
825 register_t *retval;
826 {
827 struct linux_sys_mkdir_args /* {
828 syscallarg(const char *) path;
829 syscallarg(int) mode;
830 } */ *uap = v;
831
832 return sys_mkdir(l, uap, retval);
833 }
834
835 int
836 linux_sys_rmdir(l, v, retval)
837 struct lwp *l;
838 void *v;
839 register_t *retval;
840 {
841 struct linux_sys_rmdir_args /* {
842 syscallarg(const char *) path;
843 } */ *uap = v;
844
845 return sys_rmdir(l, uap, retval);
846 }
847
848 int
849 linux_sys_symlink(l, v, retval)
850 struct lwp *l;
851 void *v;
852 register_t *retval;
853 {
854 struct linux_sys_symlink_args /* {
855 syscallarg(const char *) path;
856 syscallarg(const char *) to;
857 } */ *uap = v;
858
859 return sys_symlink(l, uap, retval);
860 }
861
862 int
863 linux_sys_link(l, v, retval)
864 struct lwp *l;
865 void *v;
866 register_t *retval;
867 {
868 struct linux_sys_link_args /* {
869 syscallarg(const char *) path;
870 syscallarg(const char *) link;
871 } */ *uap = v;
872
873 return sys_link(l, uap, retval);
874 }
875
876 int
877 linux_sys_readlink(l, v, retval)
878 struct lwp *l;
879 void *v;
880 register_t *retval;
881 {
882 struct linux_sys_readlink_args /* {
883 syscallarg(const char *) name;
884 syscallarg(char *) buf;
885 syscallarg(int) count;
886 } */ *uap = v;
887
888 return sys_readlink(l, uap, retval);
889 }
890
891 #if !defined(__amd64__)
892 int
893 linux_sys_truncate(l, v, retval)
894 struct lwp *l;
895 void *v;
896 register_t *retval;
897 {
898 struct linux_sys_truncate_args /* {
899 syscallarg(const char *) path;
900 syscallarg(long) length;
901 } */ *uap = v;
902
903 return compat_43_sys_truncate(l, uap, retval);
904 }
905 #endif /* !__amd64__ */
906
907 /*
908 * This is just fsync() for now (just as it is in the Linux kernel)
909 * Note: this is not implemented under Linux on Alpha and Arm
910 * but should still be defined in our syscalls.master.
911 * (syscall #148 on the arm)
912 */
913 int
914 linux_sys_fdatasync(l, v, retval)
915 struct lwp *l;
916 void *v;
917 register_t *retval;
918 {
919 #ifdef notdef
920 struct linux_sys_fdatasync_args /* {
921 syscallarg(int) fd;
922 } */ *uap = v;
923 #endif
924 return sys_fsync(l, v, retval);
925 }
926
927 /*
928 * pread(2).
929 */
930 int
931 linux_sys_pread(l, v, retval)
932 struct lwp *l;
933 void *v;
934 register_t *retval;
935 {
936 struct linux_sys_pread_args /* {
937 syscallarg(int) fd;
938 syscallarg(void *) buf;
939 syscallarg(size_t) nbyte;
940 syscallarg(linux_off_t) offset;
941 } */ *uap = v;
942 struct sys_pread_args pra;
943
944 SCARG(&pra, fd) = SCARG(uap, fd);
945 SCARG(&pra, buf) = SCARG(uap, buf);
946 SCARG(&pra, nbyte) = SCARG(uap, nbyte);
947 SCARG(&pra, offset) = SCARG(uap, offset);
948
949 return sys_pread(l, &pra, retval);
950 }
951
952 /*
953 * pwrite(2).
954 */
955 int
956 linux_sys_pwrite(l, v, retval)
957 struct lwp *l;
958 void *v;
959 register_t *retval;
960 {
961 struct linux_sys_pwrite_args /* {
962 syscallarg(int) fd;
963 syscallarg(void *) buf;
964 syscallarg(size_t) nbyte;
965 syscallarg(linux_off_t) offset;
966 } */ *uap = v;
967 struct sys_pwrite_args pra;
968
969 SCARG(&pra, fd) = SCARG(uap, fd);
970 SCARG(&pra, buf) = SCARG(uap, buf);
971 SCARG(&pra, nbyte) = SCARG(uap, nbyte);
972 SCARG(&pra, offset) = SCARG(uap, offset);
973
974 return sys_pwrite(l, &pra, retval);
975 }
976
977 #define LINUX_NOT_SUPPORTED(fun) \
978 int \
979 fun(struct lwp *l, void *v, register_t *retval) \
980 { \
981 return EOPNOTSUPP; \
982 }
983
984 LINUX_NOT_SUPPORTED(linux_sys_setxattr)
985 LINUX_NOT_SUPPORTED(linux_sys_lsetxattr)
986 LINUX_NOT_SUPPORTED(linux_sys_fsetxattr)
987
988 LINUX_NOT_SUPPORTED(linux_sys_getxattr)
989 LINUX_NOT_SUPPORTED(linux_sys_lgetxattr)
990 LINUX_NOT_SUPPORTED(linux_sys_fgetxattr)
991
992 LINUX_NOT_SUPPORTED(linux_sys_listxattr)
993 LINUX_NOT_SUPPORTED(linux_sys_llistxattr)
994 LINUX_NOT_SUPPORTED(linux_sys_flistxattr)
995
996 LINUX_NOT_SUPPORTED(linux_sys_removexattr)
997 LINUX_NOT_SUPPORTED(linux_sys_lremovexattr)
998 LINUX_NOT_SUPPORTED(linux_sys_fremovexattr)
999