fdesc_vnops.c revision 1.20 1 /* $NetBSD: fdesc_vnops.c,v 1.20 1994/11/14 06:05:08 christos Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software donated to Berkeley by
8 * Jan-Simon Pendry.
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 University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * from: Id: fdesc_vnops.c,v 1.12 1993/04/06 16:17:17 jsp Exp
39 * @(#)fdesc_vnops.c 8.9 (Berkeley) 1/21/94
40 */
41
42 /*
43 * /dev/fd Filesystem
44 */
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/types.h>
49 #include <sys/time.h>
50 #include <sys/proc.h>
51 #include <sys/kernel.h> /* boottime */
52 #include <sys/resourcevar.h>
53 #include <sys/filedesc.h>
54 #include <sys/vnode.h>
55 #include <sys/malloc.h>
56 #include <sys/file.h>
57 #include <sys/stat.h>
58 #include <sys/mount.h>
59 #include <sys/namei.h>
60 #include <sys/buf.h>
61 #include <sys/dirent.h>
62 #include <miscfs/fdesc/fdesc.h>
63
64 #define cttyvp(p) ((p)->p_flag & P_CONTROLT ? (p)->p_session->s_ttyvp : NULL)
65
66 #define FDL_WANT 0x01
67 #define FDL_LOCKED 0x02
68 static int fdcache_lock;
69
70 dev_t devctty;
71
72 #if (FD_STDIN != FD_STDOUT-1) || (FD_STDOUT != FD_STDERR-1)
73 FD_STDIN, FD_STDOUT, FD_STDERR must be a sequence n, n+1, n+2
74 #endif
75
76 #define NFDCACHE 4
77
78 #define FD_NHASH(ix) \
79 (&fdhashtbl[(ix) & fdhash])
80 LIST_HEAD(fdhashhead, fdescnode) *fdhashtbl;
81 u_long fdhash;
82
83 /*
84 * Initialise cache headers
85 */
86 fdesc_init()
87 {
88
89 devctty = makedev(nchrdev, 0);
90 fdhashtbl = hashinit(NFDCACHE, M_CACHE, &fdhash);
91 }
92
93 int
94 fdesc_allocvp(ftype, ix, mp, vpp)
95 fdntype ftype;
96 int ix;
97 struct mount *mp;
98 struct vnode **vpp;
99 {
100 struct fdhashhead *fc;
101 struct fdescnode *fd;
102 int error = 0;
103
104 fc = FD_NHASH(ix);
105 loop:
106 for (fd = fc->lh_first; fd != 0; fd = fd->fd_hash.le_next) {
107 if (fd->fd_ix == ix && fd->fd_vnode->v_mount == mp) {
108 if (vget(fd->fd_vnode, 0))
109 goto loop;
110 *vpp = fd->fd_vnode;
111 return (error);
112 }
113 }
114
115 /*
116 * otherwise lock the array while we call getnewvnode
117 * since that can block.
118 */
119 if (fdcache_lock & FDL_LOCKED) {
120 fdcache_lock |= FDL_WANT;
121 sleep((caddr_t) &fdcache_lock, PINOD);
122 goto loop;
123 }
124 fdcache_lock |= FDL_LOCKED;
125
126 error = getnewvnode(VT_FDESC, mp, fdesc_vnodeop_p, vpp);
127 if (error)
128 goto out;
129 MALLOC(fd, void *, sizeof(struct fdescnode), M_TEMP, M_WAITOK);
130 (*vpp)->v_data = fd;
131 fd->fd_vnode = *vpp;
132 fd->fd_type = ftype;
133 fd->fd_fd = -1;
134 fd->fd_link = 0;
135 fd->fd_ix = ix;
136 LIST_INSERT_HEAD(fc, fd, fd_hash);
137
138 out:;
139 fdcache_lock &= ~FDL_LOCKED;
140
141 if (fdcache_lock & FDL_WANT) {
142 fdcache_lock &= ~FDL_WANT;
143 wakeup((caddr_t) &fdcache_lock);
144 }
145
146 return (error);
147 }
148
149 /*
150 * vp is the current namei directory
151 * ndp is the name to locate in that directory...
152 */
153 int
154 fdesc_lookup(ap)
155 struct vop_lookup_args /* {
156 struct vnode * a_dvp;
157 struct vnode ** a_vpp;
158 struct componentname * a_cnp;
159 } */ *ap;
160 {
161 struct vnode **vpp = ap->a_vpp;
162 struct vnode *dvp = ap->a_dvp;
163 char *pname;
164 struct proc *p;
165 int nfiles;
166 unsigned fd;
167 int error;
168 struct vnode *fvp;
169 char *ln;
170
171 pname = ap->a_cnp->cn_nameptr;
172 if (ap->a_cnp->cn_namelen == 1 && *pname == '.') {
173 *vpp = dvp;
174 VREF(dvp);
175 VOP_LOCK(dvp);
176 return (0);
177 }
178
179 p = ap->a_cnp->cn_proc;
180 nfiles = p->p_fd->fd_nfiles;
181
182 switch (VTOFDESC(dvp)->fd_type) {
183 default:
184 case Flink:
185 case Fdesc:
186 case Fctty:
187 error = ENOTDIR;
188 goto bad;
189
190 case Froot:
191 if (ap->a_cnp->cn_namelen == 2 && bcmp(pname, "fd", 2) == 0) {
192 error = fdesc_allocvp(Fdevfd, FD_DEVFD, dvp->v_mount, &fvp);
193 if (error)
194 goto bad;
195 *vpp = fvp;
196 fvp->v_type = VDIR;
197 VOP_LOCK(fvp);
198 return (0);
199 }
200
201 if (ap->a_cnp->cn_namelen == 3 && bcmp(pname, "tty", 3) == 0) {
202 struct vnode *ttyvp = cttyvp(p);
203 if (ttyvp == NULL) {
204 error = ENXIO;
205 goto bad;
206 }
207 error = fdesc_allocvp(Fctty, FD_CTTY, dvp->v_mount, &fvp);
208 if (error)
209 goto bad;
210 *vpp = fvp;
211 fvp->v_type = VFIFO;
212 VOP_LOCK(fvp);
213 return (0);
214 }
215
216 ln = 0;
217 switch (ap->a_cnp->cn_namelen) {
218 case 5:
219 if (bcmp(pname, "stdin", 5) == 0) {
220 ln = "fd/0";
221 fd = FD_STDIN;
222 }
223 break;
224 case 6:
225 if (bcmp(pname, "stdout", 6) == 0) {
226 ln = "fd/1";
227 fd = FD_STDOUT;
228 } else
229 if (bcmp(pname, "stderr", 6) == 0) {
230 ln = "fd/2";
231 fd = FD_STDERR;
232 }
233 break;
234 }
235
236 if (ln) {
237 error = fdesc_allocvp(Flink, fd, dvp->v_mount, &fvp);
238 if (error)
239 goto bad;
240 VTOFDESC(fvp)->fd_link = ln;
241 *vpp = fvp;
242 fvp->v_type = VLNK;
243 VOP_LOCK(fvp);
244 return (0);
245 } else {
246 error = ENOENT;
247 goto bad;
248 }
249
250 /* FALL THROUGH */
251
252 case Fdevfd:
253 if (ap->a_cnp->cn_namelen == 2 && bcmp(pname, "..", 2) == 0) {
254 error = fdesc_root(dvp->v_mount, vpp);
255 return (error);
256 }
257
258 fd = 0;
259 while (*pname >= '0' && *pname <= '9') {
260 fd = 10 * fd + *pname++ - '0';
261 if (fd >= nfiles)
262 break;
263 }
264
265 if (*pname != '\0') {
266 error = ENOENT;
267 goto bad;
268 }
269
270 if (fd >= nfiles || p->p_fd->fd_ofiles[fd] == NULL) {
271 error = EBADF;
272 goto bad;
273 }
274
275 error = fdesc_allocvp(Fdesc, FD_DESC+fd, dvp->v_mount, &fvp);
276 if (error)
277 goto bad;
278 VTOFDESC(fvp)->fd_fd = fd;
279 *vpp = fvp;
280 return (0);
281 }
282
283 bad:;
284 *vpp = NULL;
285 return (error);
286 }
287
288 int
289 fdesc_open(ap)
290 struct vop_open_args /* {
291 struct vnode *a_vp;
292 int a_mode;
293 struct ucred *a_cred;
294 struct proc *a_p;
295 struct file *a_fp;
296 } */ *ap;
297 {
298 struct vnode *vp = ap->a_vp;
299 int error = 0;
300
301 switch (VTOFDESC(vp)->fd_type) {
302 case Fdesc:
303 /*
304 * XXX Kludge: set p->p_dupfd to contain the value of the
305 * the file descriptor being sought for duplication. The error
306 * return ensures that the vnode for this device will be
307 * released by vn_open. Open will detect this special error and
308 * take the actions in dupfdopen. Other callers of vn_open or
309 * VOP_OPEN will simply report the error.
310 */
311 ap->a_p->p_dupfd = VTOFDESC(vp)->fd_fd; /* XXX */
312 error = ENODEV;
313 break;
314
315 case Fctty:
316 error = cttyopen(devctty, ap->a_mode, 0, ap->a_p);
317 break;
318 }
319
320 return (error);
321 }
322
323 static int
324 fdesc_attr(fd, vap, cred, p)
325 int fd;
326 struct vattr *vap;
327 struct ucred *cred;
328 struct proc *p;
329 {
330 struct filedesc *fdp = p->p_fd;
331 struct file *fp;
332 struct stat stb;
333 int error;
334
335 if (fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL)
336 return (EBADF);
337
338 switch (fp->f_type) {
339 case DTYPE_VNODE:
340 error = VOP_GETATTR((struct vnode *) fp->f_data, vap, cred, p);
341 if (error == 0 && vap->va_type == VDIR) {
342 /*
343 * don't allow directories to show up because
344 * that causes loops in the namespace.
345 */
346 vap->va_type = VFIFO;
347 }
348 break;
349
350 case DTYPE_SOCKET:
351 error = soo_stat((struct socket *)fp->f_data, &stb);
352 if (error == 0) {
353 vattr_null(vap);
354 vap->va_type = VSOCK;
355 vap->va_mode = stb.st_mode;
356 vap->va_nlink = stb.st_nlink;
357 vap->va_uid = stb.st_uid;
358 vap->va_gid = stb.st_gid;
359 vap->va_fsid = stb.st_dev;
360 vap->va_fileid = stb.st_ino;
361 vap->va_size = stb.st_size;
362 vap->va_blocksize = stb.st_blksize;
363 vap->va_atime = stb.st_atimespec;
364 vap->va_mtime = stb.st_mtimespec;
365 vap->va_ctime = stb.st_ctimespec;
366 vap->va_gen = stb.st_gen;
367 vap->va_flags = stb.st_flags;
368 vap->va_rdev = stb.st_rdev;
369 vap->va_bytes = stb.st_blocks * stb.st_blksize;
370 }
371 break;
372
373 default:
374 panic("fdesc attr");
375 break;
376 }
377
378 return (error);
379 }
380
381 int
382 fdesc_getattr(ap)
383 struct vop_getattr_args /* {
384 struct vnode *a_vp;
385 struct vattr *a_vap;
386 struct ucred *a_cred;
387 struct proc *a_p;
388 } */ *ap;
389 {
390 struct vnode *vp = ap->a_vp;
391 struct vattr *vap = ap->a_vap;
392 unsigned fd;
393 int error = 0;
394
395 switch (VTOFDESC(vp)->fd_type) {
396 case Froot:
397 case Fdevfd:
398 case Flink:
399 case Fctty:
400 bzero((caddr_t) vap, sizeof(*vap));
401 vattr_null(vap);
402 vap->va_fileid = VTOFDESC(vp)->fd_ix;
403
404 switch (VTOFDESC(vp)->fd_type) {
405 case Flink:
406 vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
407 vap->va_type = VLNK;
408 vap->va_nlink = 1;
409 vap->va_size = strlen(VTOFDESC(vp)->fd_link);
410 break;
411
412 case Fctty:
413 vap->va_mode = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH;
414 vap->va_type = VFIFO;
415 vap->va_nlink = 1;
416 vap->va_size = 0;
417 break;
418
419 default:
420 vap->va_mode = S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH;
421 vap->va_type = VDIR;
422 vap->va_nlink = 2;
423 vap->va_size = DEV_BSIZE;
424 break;
425 }
426 vap->va_uid = 0;
427 vap->va_gid = 0;
428 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
429 vap->va_blocksize = DEV_BSIZE;
430 vap->va_atime.ts_sec = boottime.tv_sec;
431 vap->va_atime.ts_nsec = 0;
432 vap->va_mtime = vap->va_atime;
433 vap->va_ctime = vap->va_mtime;
434 vap->va_gen = 0;
435 vap->va_flags = 0;
436 vap->va_rdev = 0;
437 vap->va_bytes = 0;
438 break;
439
440 case Fdesc:
441 fd = VTOFDESC(vp)->fd_fd;
442 error = fdesc_attr(fd, vap, ap->a_cred, ap->a_p);
443 break;
444
445 default:
446 panic("fdesc_getattr");
447 break;
448 }
449
450 if (error == 0)
451 vp->v_type = vap->va_type;
452
453 return (error);
454 }
455
456 int
457 fdesc_setattr(ap)
458 struct vop_setattr_args /* {
459 struct vnode *a_vp;
460 struct vattr *a_vap;
461 struct ucred *a_cred;
462 struct proc *a_p;
463 } */ *ap;
464 {
465 struct filedesc *fdp = ap->a_p->p_fd;
466 struct file *fp;
467 unsigned fd;
468 int error;
469
470 /*
471 * Can't mess with the root vnode
472 */
473 switch (VTOFDESC(ap->a_vp)->fd_type) {
474 case Fdesc:
475 break;
476
477 case Fctty:
478 return (0);
479
480 default:
481 return (EACCES);
482 }
483
484 fd = VTOFDESC(ap->a_vp)->fd_fd;
485 if (fd >= fdp->fd_nfiles || (fp = fdp->fd_ofiles[fd]) == NULL) {
486 return (EBADF);
487 }
488
489 /*
490 * Can setattr the underlying vnode, but not sockets!
491 */
492 switch (fp->f_type) {
493 case DTYPE_VNODE:
494 error = VOP_SETATTR((struct vnode *) fp->f_data, ap->a_vap, ap->a_cred, ap->a_p);
495 break;
496
497 case DTYPE_SOCKET:
498 error = 0;
499 break;
500
501 default:
502 panic("fdesc setattr");
503 break;
504 }
505
506 return (error);
507 }
508
509 #define UIO_MX 16
510
511 static struct dirtmp {
512 u_long d_fileno;
513 u_short d_reclen;
514 u_short d_namlen;
515 char d_name[8];
516 } rootent[] = {
517 { FD_DEVFD, UIO_MX, 2, "fd" },
518 { FD_STDIN, UIO_MX, 5, "stdin" },
519 { FD_STDOUT, UIO_MX, 6, "stdout" },
520 { FD_STDERR, UIO_MX, 6, "stderr" },
521 { FD_CTTY, UIO_MX, 3, "tty" },
522 { 0 }
523 };
524
525 int
526 fdesc_readdir(ap)
527 struct vop_readdir_args /* {
528 struct vnode *a_vp;
529 struct uio *a_uio;
530 struct ucred *a_cred;
531 } */ *ap;
532 {
533 struct uio *uio = ap->a_uio;
534 struct filedesc *fdp;
535 int i;
536 int error;
537
538 switch (VTOFDESC(ap->a_vp)->fd_type) {
539 case Fctty:
540 return (0);
541
542 case Fdesc:
543 return (ENOTDIR);
544
545 default:
546 break;
547 }
548
549 fdp = uio->uio_procp->p_fd;
550
551 if (VTOFDESC(ap->a_vp)->fd_type == Froot) {
552 struct dirent d;
553 struct dirent *dp = &d;
554 struct dirtmp *dt;
555
556 i = uio->uio_offset / UIO_MX;
557 error = 0;
558
559 while (uio->uio_resid > 0) {
560 dt = &rootent[i];
561 if (dt->d_fileno == 0) {
562 /**eofflagp = 1;*/
563 break;
564 }
565 i++;
566
567 switch (dt->d_fileno) {
568 case FD_CTTY:
569 if (cttyvp(uio->uio_procp) == NULL)
570 continue;
571 break;
572
573 case FD_STDIN:
574 case FD_STDOUT:
575 case FD_STDERR:
576 if ((dt->d_fileno-FD_STDIN) >= fdp->fd_nfiles)
577 continue;
578 if (fdp->fd_ofiles[dt->d_fileno-FD_STDIN] == NULL)
579 continue;
580 break;
581 }
582 bzero((caddr_t) dp, UIO_MX);
583 dp->d_fileno = dt->d_fileno;
584 dp->d_namlen = dt->d_namlen;
585 dp->d_type = DT_UNKNOWN;
586 dp->d_reclen = dt->d_reclen;
587 bcopy(dt->d_name, dp->d_name, dp->d_namlen+1);
588 error = uiomove((caddr_t) dp, UIO_MX, uio);
589 if (error)
590 break;
591 }
592 uio->uio_offset = i * UIO_MX;
593 return (error);
594 }
595
596 i = uio->uio_offset / UIO_MX;
597 error = 0;
598 while (uio->uio_resid > 0) {
599 if (i >= fdp->fd_nfiles)
600 break;
601
602 if (fdp->fd_ofiles[i] != NULL) {
603 struct dirent d;
604 struct dirent *dp = &d;
605
606 bzero((caddr_t) dp, UIO_MX);
607
608 dp->d_namlen = sprintf(dp->d_name, "%d", i);
609 dp->d_reclen = UIO_MX;
610 dp->d_type = DT_UNKNOWN;
611 dp->d_fileno = i + FD_STDIN;
612 /*
613 * And ship to userland
614 */
615 error = uiomove((caddr_t) dp, UIO_MX, uio);
616 if (error)
617 break;
618 }
619 i++;
620 }
621
622 uio->uio_offset = i * UIO_MX;
623 return (error);
624 }
625
626 int
627 fdesc_readlink(ap)
628 struct vop_readlink_args /* {
629 struct vnode *a_vp;
630 struct uio *a_uio;
631 struct ucred *a_cred;
632 } */ *ap;
633 {
634 struct vnode *vp = ap->a_vp;
635 int error;
636
637 if (vp->v_type != VLNK)
638 return (EPERM);
639
640 if (VTOFDESC(vp)->fd_type == Flink) {
641 char *ln = VTOFDESC(vp)->fd_link;
642 error = uiomove(ln, strlen(ln), ap->a_uio);
643 } else {
644 error = EOPNOTSUPP;
645 }
646
647 return (error);
648 }
649
650 int
651 fdesc_read(ap)
652 struct vop_read_args /* {
653 struct vnode *a_vp;
654 struct uio *a_uio;
655 int a_ioflag;
656 struct ucred *a_cred;
657 } */ *ap;
658 {
659 int error = EOPNOTSUPP;
660
661 switch (VTOFDESC(ap->a_vp)->fd_type) {
662 case Fctty:
663 error = cttyread(devctty, ap->a_uio, ap->a_ioflag);
664 break;
665
666 default:
667 error = EOPNOTSUPP;
668 break;
669 }
670
671 return (error);
672 }
673
674 int
675 fdesc_write(ap)
676 struct vop_write_args /* {
677 struct vnode *a_vp;
678 struct uio *a_uio;
679 int a_ioflag;
680 struct ucred *a_cred;
681 } */ *ap;
682 {
683 int error = EOPNOTSUPP;
684
685 switch (VTOFDESC(ap->a_vp)->fd_type) {
686 case Fctty:
687 error = cttywrite(devctty, ap->a_uio, ap->a_ioflag);
688 break;
689
690 default:
691 error = EOPNOTSUPP;
692 break;
693 }
694
695 return (error);
696 }
697
698 int
699 fdesc_ioctl(ap)
700 struct vop_ioctl_args /* {
701 struct vnode *a_vp;
702 u_long a_command;
703 caddr_t a_data;
704 int a_fflag;
705 struct ucred *a_cred;
706 struct proc *a_p;
707 } */ *ap;
708 {
709 int error = EOPNOTSUPP;
710
711 switch (VTOFDESC(ap->a_vp)->fd_type) {
712 case Fctty:
713 error = cttyioctl(devctty, ap->a_command, ap->a_data,
714 ap->a_fflag, ap->a_p);
715 break;
716
717 default:
718 error = EOPNOTSUPP;
719 break;
720 }
721
722 return (error);
723 }
724
725 int
726 fdesc_select(ap)
727 struct vop_select_args /* {
728 struct vnode *a_vp;
729 int a_which;
730 int a_fflags;
731 struct ucred *a_cred;
732 struct proc *a_p;
733 } */ *ap;
734 {
735 int error = EOPNOTSUPP;
736
737 switch (VTOFDESC(ap->a_vp)->fd_type) {
738 case Fctty:
739 error = cttyselect(devctty, ap->a_fflags, ap->a_p);
740 break;
741
742 default:
743 error = EOPNOTSUPP;
744 break;
745 }
746
747 return (error);
748 }
749
750 int
751 fdesc_inactive(ap)
752 struct vop_inactive_args /* {
753 struct vnode *a_vp;
754 } */ *ap;
755 {
756 struct vnode *vp = ap->a_vp;
757
758 /*
759 * Clear out the v_type field to avoid
760 * nasty things happening in vgone().
761 */
762 vp->v_type = VNON;
763 return (0);
764 }
765
766 int
767 fdesc_reclaim(ap)
768 struct vop_reclaim_args /* {
769 struct vnode *a_vp;
770 } */ *ap;
771 {
772 struct vnode *vp = ap->a_vp;
773 struct fdescnode *fd = VTOFDESC(vp);
774
775 LIST_REMOVE(fd, fd_hash);
776 FREE(vp->v_data, M_TEMP);
777 vp->v_data = 0;
778
779 return (0);
780 }
781
782 /*
783 * Return POSIX pathconf information applicable to special devices.
784 */
785 fdesc_pathconf(ap)
786 struct vop_pathconf_args /* {
787 struct vnode *a_vp;
788 int a_name;
789 register_t *a_retval;
790 } */ *ap;
791 {
792
793 switch (ap->a_name) {
794 case _PC_LINK_MAX:
795 *ap->a_retval = LINK_MAX;
796 return (0);
797 case _PC_MAX_CANON:
798 *ap->a_retval = MAX_CANON;
799 return (0);
800 case _PC_MAX_INPUT:
801 *ap->a_retval = MAX_INPUT;
802 return (0);
803 case _PC_PIPE_BUF:
804 *ap->a_retval = PIPE_BUF;
805 return (0);
806 case _PC_CHOWN_RESTRICTED:
807 *ap->a_retval = 1;
808 return (0);
809 case _PC_VDISABLE:
810 *ap->a_retval = _POSIX_VDISABLE;
811 return (0);
812 default:
813 return (EINVAL);
814 }
815 /* NOTREACHED */
816 }
817
818 /*
819 * Print out the contents of a /dev/fd vnode.
820 */
821 /* ARGSUSED */
822 int
823 fdesc_print(ap)
824 struct vop_print_args /* {
825 struct vnode *a_vp;
826 } */ *ap;
827 {
828
829 printf("tag VT_NON, fdesc vnode\n");
830 return (0);
831 }
832
833 /*void*/
834 int
835 fdesc_vfree(ap)
836 struct vop_vfree_args /* {
837 struct vnode *a_pvp;
838 ino_t a_ino;
839 int a_mode;
840 } */ *ap;
841 {
842
843 return (0);
844 }
845
846 /*
847 * /dev/fd vnode unsupported operation
848 */
849 int
850 fdesc_enotsupp()
851 {
852
853 return (EOPNOTSUPP);
854 }
855
856 /*
857 * /dev/fd "should never get here" operation
858 */
859 int
860 fdesc_badop()
861 {
862
863 panic("fdesc: bad op");
864 /* NOTREACHED */
865 }
866
867 /*
868 * /dev/fd vnode null operation
869 */
870 int
871 fdesc_nullop()
872 {
873
874 return (0);
875 }
876
877 #define fdesc_create ((int (*) __P((struct vop_create_args *)))fdesc_enotsupp)
878 #define fdesc_mknod ((int (*) __P((struct vop_mknod_args *)))fdesc_enotsupp)
879 #define fdesc_close ((int (*) __P((struct vop_close_args *)))nullop)
880 #define fdesc_access ((int (*) __P((struct vop_access_args *)))nullop)
881 #define fdesc_mmap ((int (*) __P((struct vop_mmap_args *)))fdesc_enotsupp)
882 #define fdesc_fsync ((int (*) __P((struct vop_fsync_args *)))nullop)
883 #define fdesc_seek ((int (*) __P((struct vop_seek_args *)))nullop)
884 #define fdesc_remove ((int (*) __P((struct vop_remove_args *)))fdesc_enotsupp)
885 #define fdesc_link ((int (*) __P((struct vop_link_args *)))fdesc_enotsupp)
886 #define fdesc_rename ((int (*) __P((struct vop_rename_args *)))fdesc_enotsupp)
887 #define fdesc_mkdir ((int (*) __P((struct vop_mkdir_args *)))fdesc_enotsupp)
888 #define fdesc_rmdir ((int (*) __P((struct vop_rmdir_args *)))fdesc_enotsupp)
889 #define fdesc_symlink ((int (*) __P((struct vop_symlink_args *)))fdesc_enotsupp)
890 #define fdesc_abortop ((int (*) __P((struct vop_abortop_args *)))nullop)
891 #define fdesc_lock ((int (*) __P((struct vop_lock_args *)))nullop)
892 #define fdesc_unlock ((int (*) __P((struct vop_unlock_args *)))nullop)
893 #define fdesc_bmap ((int (*) __P((struct vop_bmap_args *)))fdesc_badop)
894 #define fdesc_strategy ((int (*) __P((struct vop_strategy_args *)))fdesc_badop)
895 #define fdesc_islocked ((int (*) __P((struct vop_islocked_args *)))nullop)
896 #define fdesc_advlock ((int (*) __P((struct vop_advlock_args *)))fdesc_enotsupp)
897 #define fdesc_blkatoff \
898 ((int (*) __P((struct vop_blkatoff_args *)))fdesc_enotsupp)
899 #define fdesc_vget ((int (*) __P((struct vop_vget_args *)))fdesc_enotsupp)
900 #define fdesc_valloc ((int(*) __P(( \
901 struct vnode *pvp, \
902 int mode, \
903 struct ucred *cred, \
904 struct vnode **vpp))) fdesc_enotsupp)
905 #define fdesc_truncate \
906 ((int (*) __P((struct vop_truncate_args *)))fdesc_enotsupp)
907 #define fdesc_update ((int (*) __P((struct vop_update_args *)))fdesc_enotsupp)
908 #define fdesc_bwrite ((int (*) __P((struct vop_bwrite_args *)))fdesc_enotsupp)
909
910 int (**fdesc_vnodeop_p)();
911 struct vnodeopv_entry_desc fdesc_vnodeop_entries[] = {
912 { &vop_default_desc, vn_default_error },
913 { &vop_lookup_desc, fdesc_lookup }, /* lookup */
914 { &vop_create_desc, fdesc_create }, /* create */
915 { &vop_mknod_desc, fdesc_mknod }, /* mknod */
916 { &vop_open_desc, fdesc_open }, /* open */
917 { &vop_close_desc, fdesc_close }, /* close */
918 { &vop_access_desc, fdesc_access }, /* access */
919 { &vop_getattr_desc, fdesc_getattr }, /* getattr */
920 { &vop_setattr_desc, fdesc_setattr }, /* setattr */
921 { &vop_read_desc, fdesc_read }, /* read */
922 { &vop_write_desc, fdesc_write }, /* write */
923 { &vop_ioctl_desc, fdesc_ioctl }, /* ioctl */
924 { &vop_select_desc, fdesc_select }, /* select */
925 { &vop_mmap_desc, fdesc_mmap }, /* mmap */
926 { &vop_fsync_desc, fdesc_fsync }, /* fsync */
927 { &vop_seek_desc, fdesc_seek }, /* seek */
928 { &vop_remove_desc, fdesc_remove }, /* remove */
929 { &vop_link_desc, fdesc_link }, /* link */
930 { &vop_rename_desc, fdesc_rename }, /* rename */
931 { &vop_mkdir_desc, fdesc_mkdir }, /* mkdir */
932 { &vop_rmdir_desc, fdesc_rmdir }, /* rmdir */
933 { &vop_symlink_desc, fdesc_symlink }, /* symlink */
934 { &vop_readdir_desc, fdesc_readdir }, /* readdir */
935 { &vop_readlink_desc, fdesc_readlink }, /* readlink */
936 { &vop_abortop_desc, fdesc_abortop }, /* abortop */
937 { &vop_inactive_desc, fdesc_inactive }, /* inactive */
938 { &vop_reclaim_desc, fdesc_reclaim }, /* reclaim */
939 { &vop_lock_desc, fdesc_lock }, /* lock */
940 { &vop_unlock_desc, fdesc_unlock }, /* unlock */
941 { &vop_bmap_desc, fdesc_bmap }, /* bmap */
942 { &vop_strategy_desc, fdesc_strategy }, /* strategy */
943 { &vop_print_desc, fdesc_print }, /* print */
944 { &vop_islocked_desc, fdesc_islocked }, /* islocked */
945 { &vop_pathconf_desc, fdesc_pathconf }, /* pathconf */
946 { &vop_advlock_desc, fdesc_advlock }, /* advlock */
947 { &vop_blkatoff_desc, fdesc_blkatoff }, /* blkatoff */
948 { &vop_valloc_desc, fdesc_valloc }, /* valloc */
949 { &vop_vfree_desc, fdesc_vfree }, /* vfree */
950 { &vop_truncate_desc, fdesc_truncate }, /* truncate */
951 { &vop_update_desc, fdesc_update }, /* update */
952 { &vop_bwrite_desc, fdesc_bwrite }, /* bwrite */
953 { (struct vnodeop_desc*)NULL, (int(*)())NULL }
954 };
955 struct vnodeopv_desc fdesc_vnodeop_opv_desc =
956 { &fdesc_vnodeop_p, fdesc_vnodeop_entries };
957