linux_file.c revision 1.23 1 /* $NetBSD: linux_file.c,v 1.23 1998/10/01 03:22:11 erh Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by 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 * Copyright (c) 1995 Frank van der Linden
41 * All rights reserved.
42 *
43 * Redistribution and use in source and binary forms, with or without
44 * modification, are permitted provided that the following conditions
45 * are met:
46 * 1. Redistributions of source code must retain the above copyright
47 * notice, this list of conditions and the following disclaimer.
48 * 2. Redistributions in binary form must reproduce the above copyright
49 * notice, this list of conditions and the following disclaimer in the
50 * documentation and/or other materials provided with the distribution.
51 * 3. All advertising materials mentioning features or use of this software
52 * must display the following acknowledgement:
53 * This product includes software developed for the NetBSD Project
54 * by Frank van der Linden
55 * 4. The name of the author may not be used to endorse or promote products
56 * derived from this software without specific prior written permission
57 *
58 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
59 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
60 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
61 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
62 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
64 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
65 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
66 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
67 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
68 */
69
70 /*
71 * Functions in multiarch:
72 * linux_sys_llseek : linux_llseek.c
73 */
74
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/namei.h>
78 #include <sys/proc.h>
79 #include <sys/file.h>
80 #include <sys/stat.h>
81 #include <sys/filedesc.h>
82 #include <sys/ioctl.h>
83 #include <sys/kernel.h>
84 #include <sys/mount.h>
85 #include <sys/malloc.h>
86 #include <sys/vnode.h>
87 #include <sys/tty.h>
88 #include <sys/conf.h>
89
90 #include <sys/syscallargs.h>
91
92 #include <compat/linux/linux_types.h>
93 #include <compat/linux/linux_signal.h>
94 #include <compat/linux/linux_siginfo.h>
95 #include <compat/linux/linux_syscallargs.h>
96 #include <compat/linux/linux_fcntl.h>
97 #include <compat/linux/linux_util.h>
98
99 #include <compat/linux/linux_machdep.h>
100
101 static int linux_to_bsd_ioflags __P((int));
102 static int bsd_to_linux_ioflags __P((int));
103 static void bsd_to_linux_flock __P((struct flock *, struct linux_flock *));
104 static void linux_to_bsd_flock __P((struct linux_flock *, struct flock *));
105 static void bsd_to_linux_stat __P((struct stat *, struct linux_stat *));
106 static int linux_stat1 __P((struct proc *, void *, register_t *, int));
107
108 /*
109 * Some file-related calls are handled here. The usual flag conversion
110 * an structure conversion is done, and alternate emul path searching.
111 */
112
113 /*
114 * The next two functions convert between the Linux and NetBSD values
115 * of the flags used in open(2) and fcntl(2).
116 */
117 static int
118 linux_to_bsd_ioflags(lflags)
119 int lflags;
120 {
121 int res = 0;
122
123 res |= cvtto_bsd_mask(lflags, LINUX_O_WRONLY, O_WRONLY);
124 res |= cvtto_bsd_mask(lflags, LINUX_O_RDONLY, O_RDONLY);
125 res |= cvtto_bsd_mask(lflags, LINUX_O_RDWR, O_RDWR);
126 res |= cvtto_bsd_mask(lflags, LINUX_O_CREAT, O_CREAT);
127 res |= cvtto_bsd_mask(lflags, LINUX_O_EXCL, O_EXCL);
128 res |= cvtto_bsd_mask(lflags, LINUX_O_NOCTTY, O_NOCTTY);
129 res |= cvtto_bsd_mask(lflags, LINUX_O_TRUNC, O_TRUNC);
130 res |= cvtto_bsd_mask(lflags, LINUX_O_NDELAY, O_NDELAY);
131 res |= cvtto_bsd_mask(lflags, LINUX_O_SYNC, O_FSYNC);
132 res |= cvtto_bsd_mask(lflags, LINUX_FASYNC, O_ASYNC);
133 res |= cvtto_bsd_mask(lflags, LINUX_O_APPEND, O_APPEND);
134
135 return res;
136 }
137
138 static int
139 bsd_to_linux_ioflags(bflags)
140 int bflags;
141 {
142 int res = 0;
143
144 res |= cvtto_linux_mask(bflags, O_WRONLY, LINUX_O_WRONLY);
145 res |= cvtto_linux_mask(bflags, O_RDONLY, LINUX_O_RDONLY);
146 res |= cvtto_linux_mask(bflags, O_RDWR, LINUX_O_RDWR);
147 res |= cvtto_linux_mask(bflags, O_CREAT, LINUX_O_CREAT);
148 res |= cvtto_linux_mask(bflags, O_EXCL, LINUX_O_EXCL);
149 res |= cvtto_linux_mask(bflags, O_NOCTTY, LINUX_O_NOCTTY);
150 res |= cvtto_linux_mask(bflags, O_TRUNC, LINUX_O_TRUNC);
151 res |= cvtto_linux_mask(bflags, O_NDELAY, LINUX_O_NDELAY);
152 res |= cvtto_linux_mask(bflags, O_FSYNC, LINUX_O_SYNC);
153 res |= cvtto_linux_mask(bflags, O_ASYNC, LINUX_FASYNC);
154 res |= cvtto_linux_mask(bflags, O_APPEND, LINUX_O_APPEND);
155
156 return res;
157 }
158
159 /*
160 * creat(2) is an obsolete function, but it's present as a Linux
161 * system call, so let's deal with it.
162 *
163 * Note: On the Alpha this doesn't really exist in Linux, but it's defined
164 * in syscalls.master anyway so this doesn't have to be special cased.
165 *
166 * Just call open(2) with the TRUNC, CREAT and WRONLY flags.
167 */
168 int
169 linux_sys_creat(p, v, retval)
170 struct proc *p;
171 void *v;
172 register_t *retval;
173 {
174 struct linux_sys_creat_args /* {
175 syscallarg(char *) path;
176 syscallarg(int) mode;
177 } */ *uap = v;
178 struct sys_open_args oa;
179 caddr_t sg;
180
181 sg = stackgap_init(p->p_emul);
182 LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
183
184 SCARG(&oa, path) = SCARG(uap, path);
185 SCARG(&oa, flags) = O_CREAT | O_TRUNC | O_WRONLY;
186 SCARG(&oa, mode) = SCARG(uap, mode);
187
188 return sys_open(p, &oa, retval);
189 }
190
191 /*
192 * open(2). Take care of the different flag values, and let the
193 * NetBSD syscall do the real work. See if this operation
194 * gives the current process a controlling terminal.
195 * (XXX is this necessary?)
196 */
197 int
198 linux_sys_open(p, v, retval)
199 struct proc *p;
200 void *v;
201 register_t *retval;
202 {
203 struct linux_sys_open_args /* {
204 syscallarg(char *) path;
205 syscallarg(int) flags;
206 syscallarg(int) mode;
207 } */ *uap = v;
208 int error, fl;
209 struct sys_open_args boa;
210 caddr_t sg;
211
212 sg = stackgap_init(p->p_emul);
213
214 fl = linux_to_bsd_ioflags(SCARG(uap, flags));
215
216 if (fl & O_CREAT)
217 LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
218 else
219 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
220
221 SCARG(&boa, path) = SCARG(uap, path);
222 SCARG(&boa, flags) = fl;
223 SCARG(&boa, mode) = SCARG(uap, mode);
224
225 if ((error = sys_open(p, &boa, retval)))
226 return error;
227
228 /*
229 * this bit from sunos_misc.c (and svr4_fcntl.c).
230 * If we are a session leader, and we don't have a controlling
231 * terminal yet, and the O_NOCTTY flag is not set, try to make
232 * this the controlling terminal.
233 */
234 if (!(fl & O_NOCTTY) && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
235 struct filedesc *fdp = p->p_fd;
236 struct file *fp = fdp->fd_ofiles[*retval];
237
238 /* ignore any error, just give it a try */
239 if (fp->f_type == DTYPE_VNODE)
240 (fp->f_ops->fo_ioctl) (fp, TIOCSCTTY, (caddr_t) 0, p);
241 }
242 return 0;
243 }
244
245 /*
246 * The next two functions take care of converting the flock
247 * structure back and forth between Linux and NetBSD format.
248 * The only difference in the structures is the order of
249 * the fields, and the 'whence' value.
250 */
251 static void
252 bsd_to_linux_flock(bfp, lfp)
253 struct flock *bfp;
254 struct linux_flock *lfp;
255 {
256
257 lfp->l_start = bfp->l_start;
258 lfp->l_len = bfp->l_len;
259 lfp->l_pid = bfp->l_pid;
260 lfp->l_whence = bfp->l_whence;
261 switch (bfp->l_type) {
262 case F_RDLCK:
263 lfp->l_type = LINUX_F_RDLCK;
264 break;
265 case F_UNLCK:
266 lfp->l_type = LINUX_F_UNLCK;
267 break;
268 case F_WRLCK:
269 lfp->l_type = LINUX_F_WRLCK;
270 break;
271 }
272 }
273
274 static void
275 linux_to_bsd_flock(lfp, bfp)
276 struct linux_flock *lfp;
277 struct flock *bfp;
278 {
279
280 bfp->l_start = lfp->l_start;
281 bfp->l_len = lfp->l_len;
282 bfp->l_pid = lfp->l_pid;
283 bfp->l_whence = lfp->l_whence;
284 switch (lfp->l_type) {
285 case LINUX_F_RDLCK:
286 bfp->l_type = F_RDLCK;
287 break;
288 case LINUX_F_UNLCK:
289 bfp->l_type = F_UNLCK;
290 break;
291 case LINUX_F_WRLCK:
292 bfp->l_type = F_WRLCK;
293 break;
294 }
295 }
296
297 /*
298 * Most actions in the fcntl() call are straightforward; simply
299 * pass control to the NetBSD system call. A few commands need
300 * conversions after the actual system call has done its work,
301 * because the flag values and lock structure are different.
302 */
303 int
304 linux_sys_fcntl(p, v, retval)
305 struct proc *p;
306 void *v;
307 register_t *retval;
308 {
309 struct linux_sys_fcntl_args /* {
310 syscallarg(int) fd;
311 syscallarg(int) cmd;
312 syscallarg(void *) arg;
313 } */ *uap = v;
314 int fd, cmd, error;
315 u_long val;
316 caddr_t arg, sg;
317 struct linux_flock lfl;
318 struct flock *bfp, bfl;
319 struct sys_fcntl_args fca;
320 struct filedesc *fdp;
321 struct file *fp;
322 struct vnode *vp;
323 struct vattr va;
324 long pgid;
325 struct pgrp *pgrp;
326 struct tty *tp, *(*d_tty) __P((dev_t));
327
328 fd = SCARG(uap, fd);
329 cmd = SCARG(uap, cmd);
330 arg = (caddr_t) SCARG(uap, arg);
331
332 switch (cmd) {
333 case LINUX_F_DUPFD:
334 cmd = F_DUPFD;
335 break;
336 case LINUX_F_GETFD:
337 cmd = F_GETFD;
338 break;
339 case LINUX_F_SETFD:
340 cmd = F_SETFD;
341 break;
342 case LINUX_F_GETFL:
343 SCARG(&fca, fd) = fd;
344 SCARG(&fca, cmd) = F_GETFL;
345 SCARG(&fca, arg) = arg;
346 if ((error = sys_fcntl(p, &fca, retval)))
347 return error;
348 retval[0] = bsd_to_linux_ioflags(retval[0]);
349 return 0;
350 case LINUX_F_SETFL:
351 val = linux_to_bsd_ioflags((unsigned long)SCARG(uap, arg));
352 SCARG(&fca, fd) = fd;
353 SCARG(&fca, cmd) = F_SETFL;
354 SCARG(&fca, arg) = (caddr_t) val;
355 return sys_fcntl(p, &fca, retval);
356 case LINUX_F_GETLK:
357 sg = stackgap_init(p->p_emul);
358 bfp = (struct flock *) stackgap_alloc(&sg, sizeof *bfp);
359 if ((error = copyin(arg, &lfl, sizeof lfl)))
360 return error;
361 linux_to_bsd_flock(&lfl, &bfl);
362 if ((error = copyout(&bfl, bfp, sizeof bfl)))
363 return error;
364 SCARG(&fca, fd) = fd;
365 SCARG(&fca, cmd) = F_GETLK;
366 SCARG(&fca, arg) = bfp;
367 if ((error = sys_fcntl(p, &fca, retval)))
368 return error;
369 if ((error = copyin(bfp, &bfl, sizeof bfl)))
370 return error;
371 bsd_to_linux_flock(&bfl, &lfl);
372 return copyout(&lfl, arg, sizeof lfl);
373 break;
374 case LINUX_F_SETLK:
375 case LINUX_F_SETLKW:
376 cmd = (cmd == LINUX_F_SETLK ? F_SETLK : F_SETLKW);
377 if ((error = copyin(arg, &lfl, sizeof lfl)))
378 return error;
379 linux_to_bsd_flock(&lfl, &bfl);
380 sg = stackgap_init(p->p_emul);
381 bfp = (struct flock *) stackgap_alloc(&sg, sizeof *bfp);
382 if ((error = copyout(&bfl, bfp, sizeof bfl)))
383 return error;
384 SCARG(&fca, fd) = fd;
385 SCARG(&fca, cmd) = cmd;
386 SCARG(&fca, arg) = bfp;
387 return sys_fcntl(p, &fca, retval);
388 break;
389 case LINUX_F_SETOWN:
390 case LINUX_F_GETOWN:
391 /*
392 * We need to route around the normal fcntl() for these calls,
393 * since it uses TIOC{G,S}PGRP, which is too restrictive for
394 * Linux F_{G,S}ETOWN semantics. For sockets, this problem
395 * does not exist.
396 */
397 fdp = p->p_fd;
398 if ((u_int)fd >= fdp->fd_nfiles ||
399 (fp = fdp->fd_ofiles[fd]) == NULL)
400 return EBADF;
401 if (fp->f_type == DTYPE_SOCKET) {
402 cmd = cmd == LINUX_F_SETOWN ? F_SETOWN : F_GETOWN;
403 break;
404 }
405 vp = (struct vnode *)fp->f_data;
406 if (vp->v_type != VCHR)
407 return EINVAL;
408 if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)))
409 return error;
410 d_tty = cdevsw[major(va.va_rdev)].d_tty;
411 if (!d_tty || (!(tp = (*d_tty)(va.va_rdev))))
412 return EINVAL;
413 if (cmd == LINUX_F_GETOWN) {
414 retval[0] = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
415 return 0;
416 }
417 if ((long)arg <= 0) {
418 pgid = -(long)arg;
419 } else {
420 struct proc *p1 = pfind((long)arg);
421 if (p1 == 0)
422 return (ESRCH);
423 pgid = (long)p1->p_pgrp->pg_id;
424 }
425 pgrp = pgfind(pgid);
426 if (pgrp == NULL || pgrp->pg_session != p->p_session)
427 return EPERM;
428 tp->t_pgrp = pgrp;
429 return 0;
430 default:
431 return EOPNOTSUPP;
432 }
433
434 SCARG(&fca, fd) = fd;
435 SCARG(&fca, cmd) = cmd;
436 SCARG(&fca, arg) = arg;
437
438 return sys_fcntl(p, &fca, retval);
439 }
440
441 /*
442 * Convert a NetBSD stat structure to a Linux stat structure.
443 * Only the order of the fields and the padding in the structure
444 * is different. linux_fakedev is a machine-dependent function
445 * which optionally converts device driver major/minor numbers
446 * (XXX horrible, but what can you do against code that compares
447 * things against constant major device numbers? sigh)
448 */
449 static void
450 bsd_to_linux_stat(bsp, lsp)
451 struct stat *bsp;
452 struct linux_stat *lsp;
453 {
454
455 lsp->lst_dev = bsp->st_dev;
456 lsp->lst_ino = bsp->st_ino;
457 lsp->lst_mode = (linux_mode_t)bsp->st_mode;
458 if (bsp->st_nlink >= (1 << 15))
459 lsp->lst_nlink = (1 << 15) - 1;
460 else
461 lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
462 lsp->lst_uid = bsp->st_uid;
463 lsp->lst_gid = bsp->st_gid;
464 lsp->lst_rdev = linux_fakedev(bsp->st_rdev);
465 lsp->lst_size = bsp->st_size;
466 lsp->lst_blksize = bsp->st_blksize;
467 lsp->lst_blocks = bsp->st_blocks;
468 lsp->lst_atime = bsp->st_atime;
469 lsp->lst_mtime = bsp->st_mtime;
470 lsp->lst_ctime = bsp->st_ctime;
471 }
472
473 /*
474 * The stat functions below are plain sailing. stat and lstat are handled
475 * by one function to avoid code duplication.
476 */
477 int
478 linux_sys_fstat(p, v, retval)
479 struct proc *p;
480 void *v;
481 register_t *retval;
482 {
483 struct linux_sys_fstat_args /* {
484 syscallarg(int) fd;
485 syscallarg(linux_stat *) sp;
486 } */ *uap = v;
487 struct sys___fstat13_args fsa;
488 struct linux_stat tmplst;
489 struct stat *st,tmpst;
490 caddr_t sg;
491 int error;
492
493 sg = stackgap_init(p->p_emul);
494
495 st = stackgap_alloc(&sg, sizeof (struct stat));
496
497 SCARG(&fsa, fd) = SCARG(uap, fd);
498 SCARG(&fsa, sb) = st;
499
500 if ((error = sys___fstat13(p, &fsa, retval)))
501 return error;
502
503 if ((error = copyin(st, &tmpst, sizeof tmpst)))
504 return error;
505
506 bsd_to_linux_stat(&tmpst, &tmplst);
507
508 if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
509 return error;
510
511 return 0;
512 }
513
514 static int
515 linux_stat1(p, v, retval, dolstat)
516 struct proc *p;
517 void *v;
518 register_t *retval;
519 int dolstat;
520 {
521 struct sys___stat13_args sa;
522 struct linux_stat tmplst;
523 struct stat *st, tmpst;
524 caddr_t sg;
525 int error;
526 struct linux_sys_stat_args *uap = v;
527
528 sg = stackgap_init(p->p_emul);
529
530 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
531
532 st = stackgap_alloc(&sg, sizeof (struct stat));
533 SCARG(&sa, ub) = st;
534 SCARG(&sa, path) = SCARG(uap, path);
535
536 if ((error = (dolstat ? sys___lstat13(p, &sa, retval) :
537 sys___stat13(p, &sa, retval))))
538 return error;
539
540 if ((error = copyin(st, &tmpst, sizeof tmpst)))
541 return error;
542
543 bsd_to_linux_stat(&tmpst, &tmplst);
544
545 if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
546 return error;
547
548 return 0;
549 }
550
551 int
552 linux_sys_stat(p, v, retval)
553 struct proc *p;
554 void *v;
555 register_t *retval;
556 {
557 struct linux_sys_stat_args /* {
558 syscallarg(char *) path;
559 syscallarg(struct linux_stat *) sp;
560 } */ *uap = v;
561
562 return linux_stat1(p, uap, retval, 0);
563 }
564
565 /* Note: this is "newlstat" in the Linux sources */
566 /* (we don't bother with the old lstat currently) */
567 int
568 linux_sys_lstat(p, v, retval)
569 struct proc *p;
570 void *v;
571 register_t *retval;
572 {
573 struct linux_sys_lstat_args /* {
574 syscallarg(char *) path;
575 syscallarg(struct linux_stat *) sp;
576 } */ *uap = v;
577
578 return linux_stat1(p, uap, retval, 1);
579 }
580
581 /*
582 * The following syscalls are mostly here because of the alternate path check.
583 */
584 int
585 linux_sys_access(p, v, retval)
586 struct proc *p;
587 void *v;
588 register_t *retval;
589 {
590 struct linux_sys_access_args /* {
591 syscallarg(char *) path;
592 syscallarg(int) flags;
593 } */ *uap = v;
594 caddr_t sg = stackgap_init(p->p_emul);
595
596 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
597
598 return sys_access(p, uap, retval);
599 }
600
601 int
602 linux_sys_unlink(p, v, retval)
603 struct proc *p;
604 void *v;
605 register_t *retval;
606
607 {
608 struct linux_sys_unlink_args /* {
609 syscallarg(char *) path;
610 } */ *uap = v;
611 caddr_t sg = stackgap_init(p->p_emul);
612
613 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
614
615 return sys_unlink(p, uap, retval);
616 }
617
618 int
619 linux_sys_chdir(p, v, retval)
620 struct proc *p;
621 void *v;
622 register_t *retval;
623 {
624 struct linux_sys_chdir_args /* {
625 syscallarg(char *) path;
626 } */ *uap = v;
627 caddr_t sg = stackgap_init(p->p_emul);
628
629 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
630
631 return sys_chdir(p, uap, retval);
632 }
633
634 int
635 linux_sys_mknod(p, v, retval)
636 struct proc *p;
637 void *v;
638 register_t *retval;
639 {
640 struct linux_sys_mknod_args /* {
641 syscallarg(char *) path;
642 syscallarg(int) mode;
643 syscallarg(int) dev;
644 } */ *uap = v;
645 caddr_t sg = stackgap_init(p->p_emul);
646 struct sys_mkfifo_args bma;
647
648 LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
649
650 /*
651 * BSD handles FIFOs seperately
652 */
653 if (SCARG(uap, mode) & S_IFIFO) {
654 SCARG(&bma, path) = SCARG(uap, path);
655 SCARG(&bma, mode) = SCARG(uap, mode);
656 return sys_mkfifo(p, uap, retval);
657 } else
658 return sys_mknod(p, uap, retval);
659 }
660
661 int
662 linux_sys_chmod(p, v, retval)
663 struct proc *p;
664 void *v;
665 register_t *retval;
666 {
667 struct linux_sys_chmod_args /* {
668 syscallarg(char *) path;
669 syscallarg(int) mode;
670 } */ *uap = v;
671 caddr_t sg = stackgap_init(p->p_emul);
672
673 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
674
675 return sys_chmod(p, uap, retval);
676 }
677
678 int
679 linux_sys_chown(p, v, retval)
680 struct proc *p;
681 void *v;
682 register_t *retval;
683 {
684 struct linux_sys_chown_args /* {
685 syscallarg(char *) path;
686 syscallarg(int) uid;
687 syscallarg(int) gid;
688 } */ *uap = v;
689 struct sys___posix_chown_args bca;
690 caddr_t sg = stackgap_init(p->p_emul);
691
692 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
693
694 SCARG(&bca, path) = SCARG(uap, path);
695 SCARG(&bca, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
696 (uid_t)-1 : SCARG(uap, uid);
697 SCARG(&bca, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
698 (gid_t)-1 : SCARG(uap, gid);
699
700 return sys___posix_chown(p, &bca, retval);
701 }
702
703 int
704 linux_sys_fchown(p, v, retval)
705 struct proc *p;
706 void *v;
707 register_t *retval;
708 {
709 struct linux_sys_fchown_args /* {
710 syscallarg(int) fd;
711 syscallarg(int) uid;
712 syscallarg(int) gid;
713 } */ *uap = v;
714 struct sys___posix_fchown_args bfa;
715
716 SCARG(&bfa, fd) = SCARG(uap, fd);
717 SCARG(&bfa, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
718 (uid_t)-1 : SCARG(uap, uid);
719 SCARG(&bfa, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
720 (gid_t)-1 : SCARG(uap, gid);
721
722 return sys___posix_fchown(p, &bfa, retval);
723 }
724
725 int
726 linux_sys_lchown(p, v, retval)
727 struct proc *p;
728 void *v;
729 register_t *retval;
730 {
731 struct linux_sys_lchown_args /* {
732 syscallarg(char *) path;
733 syscallarg(int) uid;
734 syscallarg(int) gid;
735 } */ *uap = v;
736 struct sys___posix_lchown_args bla;
737
738 SCARG(&bla, path) = SCARG(uap, path);
739 SCARG(&bla, uid) = ((linux_uid_t)SCARG(uap, uid) == (linux_uid_t)-1) ?
740 (uid_t)-1 : SCARG(uap, uid);
741 SCARG(&bla, gid) = ((linux_gid_t)SCARG(uap, gid) == (linux_gid_t)-1) ?
742 (gid_t)-1 : SCARG(uap, gid);
743
744 return sys___posix_lchown(p, &bla, retval);
745 }
746
747 int
748 linux_sys_rename(p, v, retval)
749 struct proc *p;
750 void *v;
751 register_t *retval;
752 {
753 struct linux_sys_rename_args /* {
754 syscallarg(char *) from;
755 syscallarg(char *) to;
756 } */ *uap = v;
757 caddr_t sg = stackgap_init(p->p_emul);
758
759 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, from));
760 LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
761
762 return sys___posix_rename(p, uap, retval);
763 }
764
765 int
766 linux_sys_mkdir(p, v, retval)
767 struct proc *p;
768 void *v;
769 register_t *retval;
770 {
771 struct linux_sys_mkdir_args /* {
772 syscallarg(char *) path;
773 syscallarg(int) mode;
774 } */ *uap = v;
775 caddr_t sg = stackgap_init(p->p_emul);
776
777 LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, path));
778
779 return sys_mkdir(p, uap, retval);
780 }
781
782 int
783 linux_sys_rmdir(p, v, retval)
784 struct proc *p;
785 void *v;
786 register_t *retval;
787 {
788 struct linux_sys_rmdir_args /* {
789 syscallarg(char *) path;
790 } */ *uap = v;
791 caddr_t sg = stackgap_init(p->p_emul);
792
793 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
794
795 return sys_rmdir(p, uap, retval);
796 }
797
798 int
799 linux_sys_symlink(p, v, retval)
800 struct proc *p;
801 void *v;
802 register_t *retval;
803 {
804 struct linux_sys_symlink_args /* {
805 syscallarg(char *) path;
806 syscallarg(char *) to;
807 } */ *uap = v;
808 caddr_t sg = stackgap_init(p->p_emul);
809
810 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
811 LINUX_CHECK_ALT_CREAT(p, &sg, SCARG(uap, to));
812
813 return sys_symlink(p, uap, retval);
814 }
815
816 int
817 linux_sys_readlink(p, v, retval)
818 struct proc *p;
819 void *v;
820 register_t *retval;
821 {
822 struct linux_sys_readlink_args /* {
823 syscallarg(char *) name;
824 syscallarg(char *) buf;
825 syscallarg(int) count;
826 } */ *uap = v;
827 caddr_t sg = stackgap_init(p->p_emul);
828
829 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, name));
830
831 return sys_readlink(p, uap, retval);
832 }
833
834 int
835 linux_sys_truncate(p, v, retval)
836 struct proc *p;
837 void *v;
838 register_t *retval;
839 {
840 struct linux_sys_truncate_args /* {
841 syscallarg(char *) path;
842 syscallarg(long) length;
843 } */ *uap = v;
844 caddr_t sg = stackgap_init(p->p_emul);
845
846 LINUX_CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
847
848 return compat_43_sys_truncate(p, uap, retval);
849 }
850
851 /*
852 * This is just fsync() for now (just as it is in the Linux kernel)
853 * Note: this is not implemented under Linux on Alpha and Arm
854 * but should still be defined in our syscalls.master.
855 * (syscall #148 on the arm)
856 */
857 int
858 linux_sys_fdatasync(p, v, retval)
859 struct proc *p;
860 void *v;
861 register_t *retval;
862 {
863 #ifdef notdef
864 struct linux_sys_fdatasync_args /* {
865 syscallarg(int) fd;
866 } */ *uap = v;
867 #endif
868 return sys_fsync(p, v, retval);
869 }
870