sys_descrip.c revision 1.31.4.2 1 /* $NetBSD: sys_descrip.c,v 1.31.4.2 2020/04/08 14:08:52 martin Exp $ */
2
3 /*-
4 * Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 /*
30 * Copyright (c) 1982, 1986, 1989, 1991, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)kern_descrip.c 8.8 (Berkeley) 2/14/95
63 */
64
65 /*
66 * System calls on descriptors.
67 */
68
69 #include <sys/cdefs.h>
70 __KERNEL_RCSID(0, "$NetBSD: sys_descrip.c,v 1.31.4.2 2020/04/08 14:08:52 martin Exp $");
71
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/filedesc.h>
75 #include <sys/kernel.h>
76 #include <sys/vnode.h>
77 #include <sys/proc.h>
78 #include <sys/file.h>
79 #include <sys/namei.h>
80 #include <sys/socket.h>
81 #include <sys/socketvar.h>
82 #include <sys/stat.h>
83 #include <sys/ioctl.h>
84 #include <sys/fcntl.h>
85 #include <sys/kmem.h>
86 #include <sys/pool.h>
87 #include <sys/syslog.h>
88 #include <sys/unistd.h>
89 #include <sys/resourcevar.h>
90 #include <sys/conf.h>
91 #include <sys/event.h>
92 #include <sys/kauth.h>
93 #include <sys/atomic.h>
94 #include <sys/mount.h>
95 #include <sys/syscallargs.h>
96
97 #include <uvm/uvm_readahead.h>
98
99 /*
100 * Duplicate a file descriptor.
101 */
102 int
103 sys_dup(struct lwp *l, const struct sys_dup_args *uap, register_t *retval)
104 {
105 /* {
106 syscallarg(int) fd;
107 } */
108 int error, newfd, oldfd;
109 file_t *fp;
110
111 oldfd = SCARG(uap, fd);
112
113 if ((fp = fd_getfile(oldfd)) == NULL) {
114 return EBADF;
115 }
116 error = fd_dup(fp, 0, &newfd, false);
117 fd_putfile(oldfd);
118 *retval = newfd;
119 return error;
120 }
121
122 /*
123 * Duplicate a file descriptor to a particular value.
124 */
125 int
126 dodup(struct lwp *l, int from, int to, int flags, register_t *retval)
127 {
128 int error;
129 file_t *fp;
130
131 if ((fp = fd_getfile(from)) == NULL)
132 return EBADF;
133 mutex_enter(&fp->f_lock);
134 fp->f_count++;
135 mutex_exit(&fp->f_lock);
136 fd_putfile(from);
137
138 if ((u_int)to >= curproc->p_rlimit[RLIMIT_NOFILE].rlim_cur ||
139 (u_int)to >= maxfiles)
140 error = EBADF;
141 else if (from == to)
142 error = 0;
143 else
144 error = fd_dup2(fp, to, flags);
145 closef(fp);
146 *retval = to;
147
148 return error;
149 }
150
151 int
152 sys_dup3(struct lwp *l, const struct sys_dup3_args *uap, register_t *retval)
153 {
154 /* {
155 syscallarg(int) from;
156 syscallarg(int) to;
157 syscallarg(int) flags;
158 } */
159 return dodup(l, SCARG(uap, from), SCARG(uap, to), SCARG(uap, flags),
160 retval);
161 }
162
163 int
164 sys_dup2(struct lwp *l, const struct sys_dup2_args *uap, register_t *retval)
165 {
166 /* {
167 syscallarg(int) from;
168 syscallarg(int) to;
169 } */
170 return dodup(l, SCARG(uap, from), SCARG(uap, to), 0, retval);
171 }
172
173 /*
174 * fcntl call which is being passed to the file's fs.
175 */
176 static int
177 fcntl_forfs(int fd, file_t *fp, int cmd, void *arg)
178 {
179 int error;
180 u_int size;
181 void *data, *memp;
182 #define STK_PARAMS 128
183 char stkbuf[STK_PARAMS];
184
185 if ((fp->f_flag & (FREAD | FWRITE)) == 0)
186 return (EBADF);
187
188 /*
189 * Interpret high order word to find amount of data to be
190 * copied to/from the user's address space.
191 */
192 size = (size_t)F_PARAM_LEN(cmd);
193 if (size > F_PARAM_MAX)
194 return (EINVAL);
195 memp = NULL;
196 if (size > sizeof(stkbuf)) {
197 memp = kmem_alloc(size, KM_SLEEP);
198 data = memp;
199 } else
200 data = stkbuf;
201 if (cmd & F_FSIN) {
202 if (size) {
203 error = copyin(arg, data, size);
204 if (error) {
205 if (memp)
206 kmem_free(memp, size);
207 return (error);
208 }
209 } else
210 *(void **)data = arg;
211 } else if ((cmd & F_FSOUT) != 0 && size != 0) {
212 /*
213 * Zero the buffer so the user always
214 * gets back something deterministic.
215 */
216 memset(data, 0, size);
217 } else if (cmd & F_FSVOID)
218 *(void **)data = arg;
219
220
221 error = (*fp->f_ops->fo_fcntl)(fp, cmd, data);
222
223 /*
224 * Copy any data to user, size was
225 * already set and checked above.
226 */
227 if (error == 0 && (cmd & F_FSOUT) && size)
228 error = copyout(data, arg, size);
229 if (memp)
230 kmem_free(memp, size);
231 return (error);
232 }
233
234 int
235 do_fcntl_lock(int fd, int cmd, struct flock *fl)
236 {
237 file_t *fp;
238 vnode_t *vp;
239 proc_t *p;
240 int error, flg;
241
242 if ((fp = fd_getfile(fd)) == NULL)
243 return EBADF;
244 if (fp->f_type != DTYPE_VNODE) {
245 fd_putfile(fd);
246 return EINVAL;
247 }
248 vp = fp->f_vnode;
249 if (fl->l_whence == SEEK_CUR)
250 fl->l_start += fp->f_offset;
251
252 flg = F_POSIX;
253 p = curproc;
254
255 switch (cmd) {
256 case F_SETLKW:
257 flg |= F_WAIT;
258 /* Fall into F_SETLK */
259
260 /* FALLTHROUGH */
261 case F_SETLK:
262 switch (fl->l_type) {
263 case F_RDLCK:
264 if ((fp->f_flag & FREAD) == 0) {
265 error = EBADF;
266 break;
267 }
268 if ((p->p_flag & PK_ADVLOCK) == 0) {
269 mutex_enter(p->p_lock);
270 p->p_flag |= PK_ADVLOCK;
271 mutex_exit(p->p_lock);
272 }
273 error = VOP_ADVLOCK(vp, p, F_SETLK, fl, flg);
274 break;
275
276 case F_WRLCK:
277 if ((fp->f_flag & FWRITE) == 0) {
278 error = EBADF;
279 break;
280 }
281 if ((p->p_flag & PK_ADVLOCK) == 0) {
282 mutex_enter(p->p_lock);
283 p->p_flag |= PK_ADVLOCK;
284 mutex_exit(p->p_lock);
285 }
286 error = VOP_ADVLOCK(vp, p, F_SETLK, fl, flg);
287 break;
288
289 case F_UNLCK:
290 error = VOP_ADVLOCK(vp, p, F_UNLCK, fl, F_POSIX);
291 break;
292
293 default:
294 error = EINVAL;
295 break;
296 }
297 break;
298
299 case F_GETLK:
300 if (fl->l_type != F_RDLCK &&
301 fl->l_type != F_WRLCK &&
302 fl->l_type != F_UNLCK) {
303 error = EINVAL;
304 break;
305 }
306 error = VOP_ADVLOCK(vp, p, F_GETLK, fl, F_POSIX);
307 break;
308
309 default:
310 error = EINVAL;
311 break;
312 }
313
314 fd_putfile(fd);
315 return error;
316 }
317
318 /*
319 * The file control system call.
320 */
321 int
322 sys_fcntl(struct lwp *l, const struct sys_fcntl_args *uap, register_t *retval)
323 {
324 /* {
325 syscallarg(int) fd;
326 syscallarg(int) cmd;
327 syscallarg(void *) arg;
328 } */
329 int fd, i, tmp, error, cmd, newmin;
330 filedesc_t *fdp;
331 fdtab_t *dt;
332 file_t *fp;
333 struct flock fl;
334 bool cloexec = false;
335
336 fd = SCARG(uap, fd);
337 cmd = SCARG(uap, cmd);
338 fdp = l->l_fd;
339 error = 0;
340
341 switch (cmd) {
342 case F_CLOSEM:
343 if (fd < 0)
344 return EBADF;
345 while ((i = fdp->fd_lastfile) >= fd) {
346 if (fd_getfile(i) == NULL) {
347 /* Another thread has updated. */
348 continue;
349 }
350 fd_close(i);
351 }
352 return 0;
353
354 case F_MAXFD:
355 *retval = fdp->fd_lastfile;
356 return 0;
357
358 case F_SETLKW:
359 case F_SETLK:
360 case F_GETLK:
361 error = copyin(SCARG(uap, arg), &fl, sizeof(fl));
362 if (error)
363 return error;
364 error = do_fcntl_lock(fd, cmd, &fl);
365 if (cmd == F_GETLK && error == 0)
366 error = copyout(&fl, SCARG(uap, arg), sizeof(fl));
367 return error;
368
369 default:
370 /* Handled below */
371 break;
372 }
373
374 if ((fp = fd_getfile(fd)) == NULL)
375 return (EBADF);
376
377 if ((cmd & F_FSCTL)) {
378 error = fcntl_forfs(fd, fp, cmd, SCARG(uap, arg));
379 fd_putfile(fd);
380 return error;
381 }
382
383 switch (cmd) {
384 case F_DUPFD_CLOEXEC:
385 cloexec = true;
386 /*FALLTHROUGH*/
387 case F_DUPFD:
388 newmin = (long)SCARG(uap, arg);
389 if ((u_int)newmin >=
390 l->l_proc->p_rlimit[RLIMIT_NOFILE].rlim_cur ||
391 (u_int)newmin >= maxfiles) {
392 fd_putfile(fd);
393 return EINVAL;
394 }
395 error = fd_dup(fp, newmin, &i, cloexec);
396 *retval = i;
397 break;
398
399 case F_GETFD:
400 dt = atomic_load_consume(&fdp->fd_dt);
401 *retval = dt->dt_ff[fd]->ff_exclose;
402 break;
403
404 case F_SETFD:
405 fd_set_exclose(l, fd,
406 ((long)SCARG(uap, arg) & FD_CLOEXEC) != 0);
407 break;
408
409 case F_GETNOSIGPIPE:
410 *retval = (fp->f_flag & FNOSIGPIPE) != 0;
411 break;
412
413 case F_SETNOSIGPIPE:
414 if (SCARG(uap, arg))
415 atomic_or_uint(&fp->f_flag, FNOSIGPIPE);
416 else
417 atomic_and_uint(&fp->f_flag, ~FNOSIGPIPE);
418 *retval = 0;
419 break;
420
421 case F_GETFL:
422 *retval = OFLAGS(fp->f_flag);
423 break;
424
425 case F_SETFL:
426 /* XXX not guaranteed to be atomic. */
427 tmp = FFLAGS((long)SCARG(uap, arg)) & FCNTLFLAGS;
428 error = (*fp->f_ops->fo_fcntl)(fp, F_SETFL, &tmp);
429 if (error)
430 break;
431 i = tmp ^ fp->f_flag;
432 if (i & FNONBLOCK) {
433 int flgs = tmp & FNONBLOCK;
434 error = (*fp->f_ops->fo_ioctl)(fp, FIONBIO, &flgs);
435 if (error) {
436 (*fp->f_ops->fo_fcntl)(fp, F_SETFL,
437 &fp->f_flag);
438 break;
439 }
440 }
441 if (i & FASYNC) {
442 int flgs = tmp & FASYNC;
443 error = (*fp->f_ops->fo_ioctl)(fp, FIOASYNC, &flgs);
444 if (error) {
445 if (i & FNONBLOCK) {
446 tmp = fp->f_flag & FNONBLOCK;
447 (void)(*fp->f_ops->fo_ioctl)(fp,
448 FIONBIO, &tmp);
449 }
450 (*fp->f_ops->fo_fcntl)(fp, F_SETFL,
451 &fp->f_flag);
452 break;
453 }
454 }
455 fp->f_flag = (fp->f_flag & ~FCNTLFLAGS) | tmp;
456 break;
457
458 case F_GETOWN:
459 error = (*fp->f_ops->fo_ioctl)(fp, FIOGETOWN, &tmp);
460 *retval = tmp;
461 break;
462
463 case F_SETOWN:
464 tmp = (int)(uintptr_t) SCARG(uap, arg);
465 error = (*fp->f_ops->fo_ioctl)(fp, FIOSETOWN, &tmp);
466 break;
467
468 default:
469 error = EINVAL;
470 }
471
472 fd_putfile(fd);
473 return (error);
474 }
475
476 /*
477 * Close a file descriptor.
478 */
479 int
480 sys_close(struct lwp *l, const struct sys_close_args *uap, register_t *retval)
481 {
482 /* {
483 syscallarg(int) fd;
484 } */
485 int error;
486 int fd = SCARG(uap, fd);
487
488 if (fd_getfile(fd) == NULL) {
489 return EBADF;
490 }
491
492 error = fd_close(fd);
493 if (error == ERESTART) {
494 #ifdef DIAGNOSTIC
495 printf("%s[%d]: close(%d) returned ERESTART\n",
496 l->l_proc->p_comm, (int)l->l_proc->p_pid, fd);
497 #endif
498 error = EINTR;
499 }
500
501 return error;
502 }
503
504 /*
505 * Return status information about a file descriptor.
506 * Common function for compat code.
507 */
508 int
509 do_sys_fstat(int fd, struct stat *sb)
510 {
511 file_t *fp;
512 int error;
513
514 if ((fp = fd_getfile(fd)) == NULL) {
515 return EBADF;
516 }
517 error = (*fp->f_ops->fo_stat)(fp, sb);
518 fd_putfile(fd);
519
520 return error;
521 }
522
523 /*
524 * Return status information about a file descriptor.
525 */
526 int
527 sys___fstat50(struct lwp *l, const struct sys___fstat50_args *uap,
528 register_t *retval)
529 {
530 /* {
531 syscallarg(int) fd;
532 syscallarg(struct stat *) sb;
533 } */
534 struct stat sb;
535 int error;
536
537 error = do_sys_fstat(SCARG(uap, fd), &sb);
538 if (error == 0) {
539 error = copyout(&sb, SCARG(uap, sb), sizeof(sb));
540 }
541 return error;
542 }
543
544 /*
545 * Return pathconf information about a file descriptor.
546 */
547 int
548 sys_fpathconf(struct lwp *l, const struct sys_fpathconf_args *uap,
549 register_t *retval)
550 {
551 /* {
552 syscallarg(int) fd;
553 syscallarg(int) name;
554 } */
555 int fd, error;
556 file_t *fp;
557
558 fd = SCARG(uap, fd);
559 error = 0;
560
561 if ((fp = fd_getfile(fd)) == NULL) {
562 return (EBADF);
563 }
564 switch (fp->f_type) {
565 case DTYPE_SOCKET:
566 case DTYPE_PIPE:
567 if (SCARG(uap, name) != _PC_PIPE_BUF)
568 error = EINVAL;
569 else
570 *retval = PIPE_BUF;
571 break;
572
573 case DTYPE_VNODE:
574 error = VOP_PATHCONF(fp->f_vnode, SCARG(uap, name), retval);
575 break;
576
577 case DTYPE_KQUEUE:
578 error = EINVAL;
579 break;
580
581 default:
582 error = EOPNOTSUPP;
583 break;
584 }
585
586 fd_putfile(fd);
587 return (error);
588 }
589
590 /*
591 * Apply an advisory lock on a file descriptor.
592 *
593 * Just attempt to get a record lock of the requested type on
594 * the entire file (l_whence = SEEK_SET, l_start = 0, l_len = 0).
595 */
596 /* ARGSUSED */
597 int
598 sys_flock(struct lwp *l, const struct sys_flock_args *uap, register_t *retval)
599 {
600 /* {
601 syscallarg(int) fd;
602 syscallarg(int) how;
603 } */
604 int fd, how, error;
605 file_t *fp;
606 vnode_t *vp;
607 struct flock lf;
608
609 fd = SCARG(uap, fd);
610 how = SCARG(uap, how);
611 error = 0;
612
613 if ((fp = fd_getfile(fd)) == NULL) {
614 return EBADF;
615 }
616 if (fp->f_type != DTYPE_VNODE) {
617 fd_putfile(fd);
618 return EOPNOTSUPP;
619 }
620
621 vp = fp->f_vnode;
622 lf.l_whence = SEEK_SET;
623 lf.l_start = 0;
624 lf.l_len = 0;
625
626 switch (how & ~LOCK_NB) {
627 case LOCK_UN:
628 lf.l_type = F_UNLCK;
629 atomic_and_uint(&fp->f_flag, ~FHASLOCK);
630 error = VOP_ADVLOCK(vp, fp, F_UNLCK, &lf, F_FLOCK);
631 fd_putfile(fd);
632 return error;
633 case LOCK_EX:
634 lf.l_type = F_WRLCK;
635 break;
636 case LOCK_SH:
637 lf.l_type = F_RDLCK;
638 break;
639 default:
640 fd_putfile(fd);
641 return EINVAL;
642 }
643
644 atomic_or_uint(&fp->f_flag, FHASLOCK);
645 if (how & LOCK_NB) {
646 error = VOP_ADVLOCK(vp, fp, F_SETLK, &lf, F_FLOCK);
647 } else {
648 error = VOP_ADVLOCK(vp, fp, F_SETLK, &lf, F_FLOCK|F_WAIT);
649 }
650 fd_putfile(fd);
651 return error;
652 }
653
654 int
655 do_posix_fadvise(int fd, off_t offset, off_t len, int advice)
656 {
657 file_t *fp;
658 vnode_t *vp;
659 off_t endoffset;
660 int error;
661
662 CTASSERT(POSIX_FADV_NORMAL == UVM_ADV_NORMAL);
663 CTASSERT(POSIX_FADV_RANDOM == UVM_ADV_RANDOM);
664 CTASSERT(POSIX_FADV_SEQUENTIAL == UVM_ADV_SEQUENTIAL);
665
666 if (len == 0) {
667 endoffset = INT64_MAX;
668 } else if (len > 0 && (INT64_MAX - offset) >= len) {
669 endoffset = offset + len;
670 } else {
671 return EINVAL;
672 }
673 if ((fp = fd_getfile(fd)) == NULL) {
674 return EBADF;
675 }
676 if (fp->f_type != DTYPE_VNODE) {
677 if (fp->f_type == DTYPE_PIPE || fp->f_type == DTYPE_SOCKET) {
678 error = ESPIPE;
679 } else {
680 error = EOPNOTSUPP;
681 }
682 fd_putfile(fd);
683 return error;
684 }
685
686 switch (advice) {
687 case POSIX_FADV_WILLNEED:
688 case POSIX_FADV_DONTNEED:
689 vp = fp->f_vnode;
690 if (vp->v_type != VREG && vp->v_type != VBLK) {
691 fd_putfile(fd);
692 return 0;
693 }
694 break;
695 }
696
697 switch (advice) {
698 case POSIX_FADV_NORMAL:
699 case POSIX_FADV_RANDOM:
700 case POSIX_FADV_SEQUENTIAL:
701 /*
702 * We ignore offset and size. Must lock the file to
703 * do this, as f_advice is sub-word sized.
704 */
705 mutex_enter(&fp->f_lock);
706 fp->f_advice = (u_char)advice;
707 mutex_exit(&fp->f_lock);
708 error = 0;
709 break;
710
711 case POSIX_FADV_WILLNEED:
712 vp = fp->f_vnode;
713 error = uvm_readahead(&vp->v_uobj, offset, endoffset - offset);
714 break;
715
716 case POSIX_FADV_DONTNEED:
717 vp = fp->f_vnode;
718 /*
719 * Align the region to page boundaries as VOP_PUTPAGES expects
720 * by shrinking it. We shrink instead of expand because we
721 * do not want to deactivate cache outside of the requested
722 * region. It means that if the specified region is smaller
723 * than PAGE_SIZE, we do nothing.
724 */
725 if (round_page(offset) < trunc_page(endoffset) &&
726 offset <= round_page(offset)) {
727 rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
728 error = VOP_PUTPAGES(vp,
729 round_page(offset), trunc_page(endoffset),
730 PGO_DEACTIVATE | PGO_CLEANIT);
731 } else {
732 error = 0;
733 }
734 break;
735
736 case POSIX_FADV_NOREUSE:
737 /* Not implemented yet. */
738 error = 0;
739 break;
740 default:
741 error = EINVAL;
742 break;
743 }
744
745 fd_putfile(fd);
746 return error;
747 }
748
749 int
750 sys___posix_fadvise50(struct lwp *l,
751 const struct sys___posix_fadvise50_args *uap,
752 register_t *retval)
753 {
754 /* {
755 syscallarg(int) fd;
756 syscallarg(int) pad;
757 syscallarg(off_t) offset;
758 syscallarg(off_t) len;
759 syscallarg(int) advice;
760 } */
761
762 *retval = do_posix_fadvise(SCARG(uap, fd), SCARG(uap, offset),
763 SCARG(uap, len), SCARG(uap, advice));
764
765 return 0;
766 }
767
768 int
769 sys_pipe(struct lwp *l, const void *v, register_t *retval)
770 {
771 int fd[2], error;
772
773 if ((error = pipe1(l, fd, 0)) != 0)
774 return error;
775
776 retval[0] = fd[0];
777 retval[1] = fd[1];
778
779 return 0;
780 }
781
782 int
783 sys_pipe2(struct lwp *l, const struct sys_pipe2_args *uap, register_t *retval)
784 {
785 /* {
786 syscallarg(int[2]) fildes;
787 syscallarg(int) flags;
788 } */
789 int fd[2], error;
790
791 if ((error = pipe1(l, fd, SCARG(uap, flags))) != 0)
792 return error;
793
794 if ((error = copyout(fd, SCARG(uap, fildes), sizeof(fd))) != 0)
795 return error;
796 retval[0] = 0;
797 return 0;
798 }
799