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