Home | History | Annotate | Line # | Download | only in kernfs
kernfs_vnops.c revision 1.1.1.2
      1 /*
      2  * Copyright (c) 1992, 1993
      3  *	The Regents of the University of California.  All rights reserved.
      4  *
      5  * This code is derived from software donated to Berkeley by
      6  * Jan-Simon Pendry.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by the University of
     19  *	California, Berkeley and its contributors.
     20  * 4. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  *	@(#)kernfs_vnops.c	8.15 (Berkeley) 5/21/95
     37  */
     38 
     39 /*
     40  * Kernel parameter filesystem (/kern)
     41  */
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/kernel.h>
     46 #include <sys/vmmeter.h>
     47 #include <sys/types.h>
     48 #include <sys/time.h>
     49 #include <sys/proc.h>
     50 #include <sys/vnode.h>
     51 #include <sys/malloc.h>
     52 #include <sys/file.h>
     53 #include <sys/stat.h>
     54 #include <sys/mount.h>
     55 #include <sys/namei.h>
     56 #include <sys/buf.h>
     57 #include <sys/dirent.h>
     58 #include <miscfs/kernfs/kernfs.h>
     59 
     60 #define KSTRING	256		/* Largest I/O available via this filesystem */
     61 #define	UIO_MX 32
     62 
     63 #define	READ_MODE	(S_IRUSR|S_IRGRP|S_IROTH)
     64 #define	WRITE_MODE	(S_IWUSR|S_IRUSR|S_IRGRP|S_IROTH)
     65 #define DIR_MODE	(S_IRUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
     66 
     67 struct kern_target {
     68 	u_char kt_type;
     69 	u_char kt_namlen;
     70 	char *kt_name;
     71 	void *kt_data;
     72 #define	KTT_NULL	 1
     73 #define	KTT_TIME	 5
     74 #define KTT_INT		17
     75 #define	KTT_STRING	31
     76 #define KTT_HOSTNAME	47
     77 #define KTT_AVENRUN	53
     78 #define KTT_DEVICE	71
     79 	u_char kt_tag;
     80 	u_char kt_vtype;
     81 	mode_t kt_mode;
     82 } kern_targets[] = {
     83 /* NOTE: The name must be less than UIO_MX-16 chars in length */
     84 #define N(s) sizeof(s)-1, s
     85      /*        name            data          tag           type  ro/rw */
     86      { DT_DIR, N("."),         0,            KTT_NULL,     VDIR, DIR_MODE   },
     87      { DT_DIR, N(".."),        0,            KTT_NULL,     VDIR, DIR_MODE   },
     88      { DT_REG, N("boottime"),  &boottime.tv_sec, KTT_INT,  VREG, READ_MODE  },
     89      { DT_REG, N("copyright"), copyright,    KTT_STRING,   VREG, READ_MODE  },
     90      { DT_REG, N("hostname"),  0,            KTT_HOSTNAME, VREG, WRITE_MODE },
     91      { DT_REG, N("hz"),        &hz,          KTT_INT,      VREG, READ_MODE  },
     92      { DT_REG, N("loadavg"),   0,            KTT_AVENRUN,  VREG, READ_MODE  },
     93      { DT_REG, N("pagesize"),  &cnt.v_page_size, KTT_INT,  VREG, READ_MODE  },
     94      { DT_REG, N("physmem"),   &physmem,     KTT_INT,      VREG, READ_MODE  },
     95 #if 0
     96      { DT_DIR, N("root"),      0,            KTT_NULL,     VDIR, DIR_MODE   },
     97 #endif
     98      { DT_BLK, N("rootdev"),   &rootdev,     KTT_DEVICE,   VBLK, READ_MODE  },
     99      { DT_CHR, N("rrootdev"),  &rrootdev,    KTT_DEVICE,   VCHR, READ_MODE  },
    100      { DT_REG, N("time"),      0,            KTT_TIME,     VREG, READ_MODE  },
    101      { DT_REG, N("version"),   version,      KTT_STRING,   VREG, READ_MODE  },
    102 #undef N
    103 };
    104 static int nkern_targets = sizeof(kern_targets) / sizeof(kern_targets[0]);
    105 
    106 static int
    107 kernfs_xread(kt, buf, len, lenp)
    108 	struct kern_target *kt;
    109 	char *buf;
    110 	int len;
    111 	int *lenp;
    112 {
    113 
    114 	switch (kt->kt_tag) {
    115 	case KTT_TIME: {
    116 		struct timeval tv;
    117 		microtime(&tv);
    118 		sprintf(buf, "%d %d\n", tv.tv_sec, tv.tv_usec);
    119 		break;
    120 	}
    121 
    122 	case KTT_INT: {
    123 		int *ip = kt->kt_data;
    124 		sprintf(buf, "%d\n", *ip);
    125 		break;
    126 	}
    127 
    128 	case KTT_STRING: {
    129 		char *cp = kt->kt_data;
    130 		int xlen = strlen(cp) + 1;
    131 
    132 		if (xlen >= len)
    133 			return (EINVAL);
    134 
    135 		bcopy(cp, buf, xlen);
    136 		break;
    137 	}
    138 
    139 	case KTT_HOSTNAME: {
    140 		char *cp = hostname;
    141 		int xlen = hostnamelen;
    142 
    143 		if (xlen >= (len-2))
    144 			return (EINVAL);
    145 
    146 		bcopy(cp, buf, xlen);
    147 		buf[xlen] = '\n';
    148 		buf[xlen+1] = '\0';
    149 		break;
    150 	}
    151 
    152 	case KTT_AVENRUN:
    153 		sprintf(buf, "%ld %ld %ld %ld\n",
    154 		    averunnable.ldavg[0], averunnable.ldavg[1],
    155 		    averunnable.ldavg[2], averunnable.fscale);
    156 		break;
    157 
    158 	default:
    159 		return (EIO);
    160 	}
    161 
    162 	*lenp = strlen(buf);
    163 	return (0);
    164 }
    165 
    166 static int
    167 kernfs_xwrite(kt, buf, len)
    168 	struct kern_target *kt;
    169 	char *buf;
    170 	int len;
    171 {
    172 
    173 	switch (kt->kt_tag) {
    174 	case KTT_HOSTNAME:
    175 		if (buf[len-1] == '\n')
    176 			--len;
    177 		bcopy(buf, hostname, len);
    178 		hostname[len] = '\0';
    179 		hostnamelen = len;
    180 		return (0);
    181 
    182 	default:
    183 		return (EIO);
    184 	}
    185 }
    186 
    187 
    188 /*
    189  * vp is the current namei directory
    190  * ndp is the name to locate in that directory...
    191  */
    192 kernfs_lookup(ap)
    193 	struct vop_lookup_args /* {
    194 		struct vnode * a_dvp;
    195 		struct vnode ** a_vpp;
    196 		struct componentname * a_cnp;
    197 	} */ *ap;
    198 {
    199 	struct componentname *cnp = ap->a_cnp;
    200 	struct vnode **vpp = ap->a_vpp;
    201 	struct vnode *dvp = ap->a_dvp;
    202 	char *pname = cnp->cn_nameptr;
    203 	struct proc *p = cnp->cn_proc;
    204 	struct kern_target *kt;
    205 	struct vnode *fvp;
    206 	int error, i;
    207 
    208 #ifdef KERNFS_DIAGNOSTIC
    209 	printf("kernfs_lookup(%x)\n", ap);
    210 	printf("kernfs_lookup(dp = %x, vpp = %x, cnp = %x)\n", dvp, vpp, ap->a_cnp);
    211 	printf("kernfs_lookup(%s)\n", pname);
    212 #endif
    213 
    214 	*vpp = NULLVP;
    215 
    216 	if (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)
    217 		return (EROFS);
    218 
    219 	VOP_UNLOCK(dvp, 0, p);
    220 	if (cnp->cn_namelen == 1 && *pname == '.') {
    221 		*vpp = dvp;
    222 		VREF(dvp);
    223 		vn_lock(dvp, LK_SHARED | LK_RETRY, p);
    224 		return (0);
    225 	}
    226 
    227 #if 0
    228 	if (cnp->cn_namelen == 4 && bcmp(pname, "root", 4) == 0) {
    229 		*vpp = rootdir;
    230 		VREF(rootdir);
    231 		vn_lock(rootdir, LK_SHARED | LK_RETRY, p)
    232 		return (0);
    233 	}
    234 #endif
    235 
    236 	for (kt = kern_targets, i = 0; i < nkern_targets; kt++, i++) {
    237 		if (cnp->cn_namelen == kt->kt_namlen &&
    238 		    bcmp(kt->kt_name, pname, cnp->cn_namelen) == 0)
    239 			goto found;
    240 	}
    241 
    242 #ifdef KERNFS_DIAGNOSTIC
    243 	printf("kernfs_lookup: i = %d, failed", i);
    244 #endif
    245 
    246 	vn_lock(dvp, LK_SHARED | LK_RETRY, p);
    247 	return (cnp->cn_nameiop == LOOKUP ? ENOENT : EROFS);
    248 
    249 found:
    250 	if (kt->kt_tag == KTT_DEVICE) {
    251 		dev_t *dp = kt->kt_data;
    252 	loop:
    253 		if (*dp == NODEV || !vfinddev(*dp, kt->kt_vtype, &fvp)) {
    254 			vn_lock(dvp, LK_SHARED | LK_RETRY, p);
    255 			return (ENOENT);
    256 		}
    257 		*vpp = fvp;
    258 		if (vget(fvp, LK_EXCLUSIVE, p))
    259 			goto loop;
    260 		return (0);
    261 	}
    262 
    263 #ifdef KERNFS_DIAGNOSTIC
    264 	printf("kernfs_lookup: allocate new vnode\n");
    265 #endif
    266 	if (error = getnewvnode(VT_KERNFS, dvp->v_mount, kernfs_vnodeop_p,
    267 	    &fvp)) {
    268 		vn_lock(dvp, LK_SHARED | LK_RETRY, p);
    269 		return (error);
    270 	}
    271 
    272 	MALLOC(fvp->v_data, void *, sizeof(struct kernfs_node), M_TEMP,
    273 	    M_WAITOK);
    274 	VTOKERN(fvp)->kf_kt = kt;
    275 	fvp->v_type = kt->kt_vtype;
    276 	vn_lock(fvp, LK_SHARED | LK_RETRY, p);
    277 	*vpp = fvp;
    278 
    279 #ifdef KERNFS_DIAGNOSTIC
    280 	printf("kernfs_lookup: newvp = %x\n", fvp);
    281 #endif
    282 	return (0);
    283 }
    284 
    285 kernfs_open(ap)
    286 	struct vop_open_args /* {
    287 		struct vnode *a_vp;
    288 		int  a_mode;
    289 		struct ucred *a_cred;
    290 		struct proc *a_p;
    291 	} */ *ap;
    292 {
    293 
    294 	/* Only need to check access permissions. */
    295 	return (0);
    296 }
    297 
    298 static int
    299 kernfs_access(ap)
    300 	struct vop_access_args /* {
    301 		struct vnode *a_vp;
    302 		int  a_mode;
    303 		struct ucred *a_cred;
    304 		struct proc *a_p;
    305 	} */ *ap;
    306 {
    307 	register struct vnode *vp = ap->a_vp;
    308 	register struct ucred *cred = ap->a_cred;
    309 	mode_t amode = ap->a_mode;
    310 	mode_t fmode =
    311 	    (vp->v_flag & VROOT) ? DIR_MODE : VTOKERN(vp)->kf_kt->kt_mode;
    312 	mode_t mask = 0;
    313 	register gid_t *gp;
    314 	int i;
    315 
    316 	/* Some files are simply not modifiable. */
    317 	if ((amode & VWRITE) && (fmode & (S_IWUSR|S_IWGRP|S_IWOTH)) == 0)
    318 		return (EPERM);
    319 
    320 	/* Root can do anything else. */
    321 	if (cred->cr_uid == 0)
    322 		return (0);
    323 
    324 	/* Check for group 0 (wheel) permissions. */
    325 	for (i = 0, gp = cred->cr_groups; i < cred->cr_ngroups; i++, gp++)
    326 		if (*gp == 0) {
    327 			if (amode & VEXEC)
    328 				mask |= S_IXGRP;
    329 			if (amode & VREAD)
    330 				mask |= S_IRGRP;
    331 			if (amode & VWRITE)
    332 				mask |= S_IWGRP;
    333 			return ((fmode & mask) == mask ?  0 : EACCES);
    334 		}
    335 
    336         /* Otherwise, check everyone else. */
    337 	if (amode & VEXEC)
    338 		mask |= S_IXOTH;
    339 	if (amode & VREAD)
    340 		mask |= S_IROTH;
    341 	if (amode & VWRITE)
    342 		mask |= S_IWOTH;
    343 	return ((fmode & mask) == mask ? 0 : EACCES);
    344 }
    345 
    346 kernfs_getattr(ap)
    347 	struct vop_getattr_args /* {
    348 		struct vnode *a_vp;
    349 		struct vattr *a_vap;
    350 		struct ucred *a_cred;
    351 		struct proc *a_p;
    352 	} */ *ap;
    353 {
    354 	struct vnode *vp = ap->a_vp;
    355 	struct vattr *vap = ap->a_vap;
    356 	struct timeval tv;
    357 	int error = 0;
    358 	char strbuf[KSTRING];
    359 
    360 	bzero((caddr_t) vap, sizeof(*vap));
    361 	vattr_null(vap);
    362 	vap->va_uid = 0;
    363 	vap->va_gid = 0;
    364 	vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
    365 	vap->va_size = 0;
    366 	vap->va_blocksize = DEV_BSIZE;
    367 	microtime(&tv);
    368 	TIMEVAL_TO_TIMESPEC(&tv, &vap->va_atime);
    369 	vap->va_mtime = vap->va_atime;
    370 	vap->va_ctime = vap->va_ctime;
    371 	vap->va_gen = 0;
    372 	vap->va_flags = 0;
    373 	vap->va_rdev = 0;
    374 	vap->va_bytes = 0;
    375 
    376 	if (vp->v_flag & VROOT) {
    377 #ifdef KERNFS_DIAGNOSTIC
    378 		printf("kernfs_getattr: stat rootdir\n");
    379 #endif
    380 		vap->va_type = VDIR;
    381 		vap->va_mode = DIR_MODE;
    382 		vap->va_nlink = 2;
    383 		vap->va_fileid = 2;
    384 		vap->va_size = DEV_BSIZE;
    385 	} else {
    386 		struct kern_target *kt = VTOKERN(vp)->kf_kt;
    387 		int nbytes;
    388 #ifdef KERNFS_DIAGNOSTIC
    389 		printf("kernfs_getattr: stat target %s\n", kt->kt_name);
    390 #endif
    391 		vap->va_type = kt->kt_vtype;
    392 		vap->va_mode = kt->kt_mode;
    393 		vap->va_nlink = 1;
    394 		vap->va_fileid = 1 + (kt - kern_targets) / sizeof(*kt);
    395 		error = kernfs_xread(kt, strbuf, sizeof(strbuf), &nbytes);
    396 		vap->va_size = nbytes;
    397 	}
    398 
    399 #ifdef KERNFS_DIAGNOSTIC
    400 	printf("kernfs_getattr: return error %d\n", error);
    401 #endif
    402 	return (error);
    403 }
    404 
    405 kernfs_setattr(ap)
    406 	struct vop_setattr_args /* {
    407 		struct vnode *a_vp;
    408 		struct vattr *a_vap;
    409 		struct ucred *a_cred;
    410 		struct proc *a_p;
    411 	} */ *ap;
    412 {
    413 
    414 	/*
    415 	 * Silently ignore attribute changes.
    416 	 * This allows for open with truncate to have no
    417 	 * effect until some data is written.  I want to
    418 	 * do it this way because all writes are atomic.
    419 	 */
    420 	return (0);
    421 }
    422 
    423 static int
    424 kernfs_read(ap)
    425 	struct vop_read_args /* {
    426 		struct vnode *a_vp;
    427 		struct uio *a_uio;
    428 		int  a_ioflag;
    429 		struct ucred *a_cred;
    430 	} */ *ap;
    431 {
    432 	struct vnode *vp = ap->a_vp;
    433 	struct uio *uio = ap->a_uio;
    434 	struct kern_target *kt;
    435 	char strbuf[KSTRING];
    436 	int off = uio->uio_offset;
    437 	int error, len;
    438 	char *cp;
    439 
    440 	if (vp->v_type == VDIR)
    441 		return (EOPNOTSUPP);
    442 
    443 	kt = VTOKERN(vp)->kf_kt;
    444 
    445 #ifdef KERNFS_DIAGNOSTIC
    446 	printf("kern_read %s\n", kt->kt_name);
    447 #endif
    448 
    449 	len = 0;
    450 	if (error = kernfs_xread(kt, strbuf, sizeof(strbuf), &len))
    451 		return (error);
    452 	if (len <= off)
    453 		return (0);
    454 	return (uiomove(&strbuf[off], len - off, uio));
    455 }
    456 
    457 static int
    458 kernfs_write(ap)
    459 	struct vop_write_args /* {
    460 		struct vnode *a_vp;
    461 		struct uio *a_uio;
    462 		int  a_ioflag;
    463 		struct ucred *a_cred;
    464 	} */ *ap;
    465 {
    466 	struct vnode *vp = ap->a_vp;
    467 	struct uio *uio = ap->a_uio;
    468 	struct kern_target *kt;
    469 	int error, xlen;
    470 	char strbuf[KSTRING];
    471 
    472 	if (vp->v_type == VDIR)
    473 		return (EOPNOTSUPP);
    474 
    475 	kt = VTOKERN(vp)->kf_kt;
    476 
    477 	if (uio->uio_offset != 0)
    478 		return (EINVAL);
    479 
    480 	xlen = min(uio->uio_resid, KSTRING-1);
    481 	if (error = uiomove(strbuf, xlen, uio))
    482 		return (error);
    483 
    484 	if (uio->uio_resid != 0)
    485 		return (EIO);
    486 
    487 	strbuf[xlen] = '\0';
    488 	xlen = strlen(strbuf);
    489 	return (kernfs_xwrite(kt, strbuf, xlen));
    490 }
    491 
    492 kernfs_readdir(ap)
    493 	struct vop_readdir_args /* {
    494 		struct vnode *a_vp;
    495 		struct uio *a_uio;
    496 		struct ucred *a_cred;
    497 		int *a_eofflag;
    498 		u_long *a_cookies;
    499 		int a_ncookies;
    500 	} */ *ap;
    501 {
    502 	int error, i;
    503 	struct uio *uio = ap->a_uio;
    504 	struct kern_target *kt;
    505 	struct dirent d;
    506 
    507 	if (ap->a_vp->v_type != VDIR)
    508 		return (ENOTDIR);
    509 
    510 	/*
    511 	 * We don't allow exporting kernfs mounts, and currently local
    512 	 * requests do not need cookies.
    513 	 */
    514 	if (ap->a_ncookies != NULL)
    515 		panic("kernfs_readdir: not hungry");
    516 
    517 	i = uio->uio_offset / UIO_MX;
    518 	error = 0;
    519 	for (kt = &kern_targets[i];
    520 		uio->uio_resid >= UIO_MX && i < nkern_targets; kt++, i++) {
    521 		struct dirent *dp = &d;
    522 #ifdef KERNFS_DIAGNOSTIC
    523 		printf("kernfs_readdir: i = %d\n", i);
    524 #endif
    525 
    526 		if (kt->kt_tag == KTT_DEVICE) {
    527 			dev_t *dp = kt->kt_data;
    528 			struct vnode *fvp;
    529 
    530 			if (*dp == NODEV || !vfinddev(*dp, kt->kt_vtype, &fvp))
    531 				continue;
    532 		}
    533 
    534 		bzero((caddr_t)dp, UIO_MX);
    535 		dp->d_namlen = kt->kt_namlen;
    536 		bcopy(kt->kt_name, dp->d_name, kt->kt_namlen+1);
    537 
    538 #ifdef KERNFS_DIAGNOSTIC
    539 		printf("kernfs_readdir: name = %s, len = %d\n",
    540 				dp->d_name, dp->d_namlen);
    541 #endif
    542 		/*
    543 		 * Fill in the remaining fields
    544 		 */
    545 		dp->d_reclen = UIO_MX;
    546 		dp->d_fileno = i + 3;
    547 		dp->d_type = kt->kt_type;
    548 		/*
    549 		 * And ship to userland
    550 		 */
    551 		if (error = uiomove((caddr_t)dp, UIO_MX, uio))
    552 			break;
    553 	}
    554 
    555 	uio->uio_offset = i * UIO_MX;
    556 
    557 	return (error);
    558 }
    559 
    560 kernfs_inactive(ap)
    561 	struct vop_inactive_args /* {
    562 		struct vnode *a_vp;
    563 		struct proc *a_p;
    564 	} */ *ap;
    565 {
    566 	struct vnode *vp = ap->a_vp;
    567 
    568 #ifdef KERNFS_DIAGNOSTIC
    569 	printf("kernfs_inactive(%x)\n", vp);
    570 #endif
    571 	/*
    572 	 * Clear out the v_type field to avoid
    573 	 * nasty things happening in vgone().
    574 	 */
    575 	VOP_UNLOCK(vp, 0, ap->a_p);
    576 	vp->v_type = VNON;
    577 	return (0);
    578 }
    579 
    580 kernfs_reclaim(ap)
    581 	struct vop_reclaim_args /* {
    582 		struct vnode *a_vp;
    583 	} */ *ap;
    584 {
    585 	struct vnode *vp = ap->a_vp;
    586 
    587 #ifdef KERNFS_DIAGNOSTIC
    588 	printf("kernfs_reclaim(%x)\n", vp);
    589 #endif
    590 	if (vp->v_data) {
    591 		FREE(vp->v_data, M_TEMP);
    592 		vp->v_data = 0;
    593 	}
    594 	return (0);
    595 }
    596 
    597 /*
    598  * Return POSIX pathconf information applicable to special devices.
    599  */
    600 kernfs_pathconf(ap)
    601 	struct vop_pathconf_args /* {
    602 		struct vnode *a_vp;
    603 		int a_name;
    604 		int *a_retval;
    605 	} */ *ap;
    606 {
    607 
    608 	switch (ap->a_name) {
    609 	case _PC_LINK_MAX:
    610 		*ap->a_retval = LINK_MAX;
    611 		return (0);
    612 	case _PC_MAX_CANON:
    613 		*ap->a_retval = MAX_CANON;
    614 		return (0);
    615 	case _PC_MAX_INPUT:
    616 		*ap->a_retval = MAX_INPUT;
    617 		return (0);
    618 	case _PC_PIPE_BUF:
    619 		*ap->a_retval = PIPE_BUF;
    620 		return (0);
    621 	case _PC_CHOWN_RESTRICTED:
    622 		*ap->a_retval = 1;
    623 		return (0);
    624 	case _PC_VDISABLE:
    625 		*ap->a_retval = _POSIX_VDISABLE;
    626 		return (0);
    627 	default:
    628 		return (EINVAL);
    629 	}
    630 	/* NOTREACHED */
    631 }
    632 
    633 /*
    634  * Print out the contents of a /dev/fd vnode.
    635  */
    636 /* ARGSUSED */
    637 kernfs_print(ap)
    638 	struct vop_print_args /* {
    639 		struct vnode *a_vp;
    640 	} */ *ap;
    641 {
    642 
    643 	printf("tag VT_KERNFS, kernfs vnode\n");
    644 	return (0);
    645 }
    646 
    647 /*void*/
    648 kernfs_vfree(ap)
    649 	struct vop_vfree_args /* {
    650 		struct vnode *a_pvp;
    651 		ino_t a_ino;
    652 		int a_mode;
    653 	} */ *ap;
    654 {
    655 
    656 	return (0);
    657 }
    658 
    659 /*
    660  * /dev/fd "should never get here" operation
    661  */
    662 kernfs_badop()
    663 {
    664 
    665 	panic("kernfs: bad op");
    666 	/* NOTREACHED */
    667 }
    668 
    669 /*
    670  * kernfs vnode null operation
    671  */
    672 kernfs_nullop()
    673 {
    674 
    675 	return (0);
    676 }
    677 
    678 #define kernfs_create ((int (*) __P((struct  vop_create_args *)))eopnotsupp)
    679 #define kernfs_mknod ((int (*) __P((struct  vop_mknod_args *)))eopnotsupp)
    680 #define kernfs_close ((int (*) __P((struct  vop_close_args *)))nullop)
    681 #define kernfs_ioctl ((int (*) __P((struct  vop_ioctl_args *)))eopnotsupp)
    682 #define kernfs_select ((int (*) __P((struct  vop_select_args *)))eopnotsupp)
    683 #define kernfs_revoke vop_revoke
    684 #define kernfs_mmap ((int (*) __P((struct  vop_mmap_args *)))eopnotsupp)
    685 #define kernfs_fsync ((int (*) __P((struct  vop_fsync_args *)))nullop)
    686 #define kernfs_seek ((int (*) __P((struct  vop_seek_args *)))nullop)
    687 #define kernfs_remove ((int (*) __P((struct  vop_remove_args *)))eopnotsupp)
    688 #define kernfs_link ((int (*) __P((struct  vop_link_args *)))eopnotsupp)
    689 #define kernfs_rename ((int (*) __P((struct  vop_rename_args *)))eopnotsupp)
    690 #define kernfs_mkdir ((int (*) __P((struct  vop_mkdir_args *)))eopnotsupp)
    691 #define kernfs_rmdir ((int (*) __P((struct  vop_rmdir_args *)))eopnotsupp)
    692 #define kernfs_symlink ((int (*) __P((struct vop_symlink_args *)))eopnotsupp)
    693 #define kernfs_readlink ((int (*) __P((struct  vop_readlink_args *)))eopnotsupp)
    694 #define kernfs_abortop ((int (*) __P((struct  vop_abortop_args *)))nullop)
    695 #define kernfs_lock ((int (*) __P((struct  vop_lock_args *)))vop_nolock)
    696 #define kernfs_unlock ((int (*) __P((struct  vop_unlock_args *)))vop_nounlock)
    697 #define kernfs_bmap ((int (*) __P((struct  vop_bmap_args *)))kernfs_badop)
    698 #define kernfs_strategy \
    699 	((int (*) __P((struct  vop_strategy_args *)))kernfs_badop)
    700 #define kernfs_islocked \
    701 	((int (*) __P((struct vop_islocked_args *)))vop_noislocked)
    702 #define kernfs_advlock ((int (*) __P((struct vop_advlock_args *)))eopnotsupp)
    703 #define kernfs_blkatoff ((int (*) __P((struct  vop_blkatoff_args *)))eopnotsupp)
    704 #define kernfs_valloc ((int(*) __P(( \
    705 		struct vnode *pvp, \
    706 		int mode, \
    707 		struct ucred *cred, \
    708 		struct vnode **vpp))) eopnotsupp)
    709 #define kernfs_truncate ((int (*) __P((struct  vop_truncate_args *)))eopnotsupp)
    710 #define kernfs_update ((int (*) __P((struct  vop_update_args *)))eopnotsupp)
    711 #define kernfs_bwrite ((int (*) __P((struct  vop_bwrite_args *)))eopnotsupp)
    712 
    713 int (**kernfs_vnodeop_p)();
    714 struct vnodeopv_entry_desc kernfs_vnodeop_entries[] = {
    715 	{ &vop_default_desc, vn_default_error },
    716 	{ &vop_lookup_desc, kernfs_lookup },	/* lookup */
    717 	{ &vop_create_desc, kernfs_create },	/* create */
    718 	{ &vop_mknod_desc, kernfs_mknod },	/* mknod */
    719 	{ &vop_open_desc, kernfs_open },	/* open */
    720 	{ &vop_close_desc, kernfs_close },	/* close */
    721 	{ &vop_access_desc, kernfs_access },	/* access */
    722 	{ &vop_getattr_desc, kernfs_getattr },	/* getattr */
    723 	{ &vop_setattr_desc, kernfs_setattr },	/* setattr */
    724 	{ &vop_read_desc, kernfs_read },	/* read */
    725 	{ &vop_write_desc, kernfs_write },	/* write */
    726 	{ &vop_ioctl_desc, kernfs_ioctl },	/* ioctl */
    727 	{ &vop_select_desc, kernfs_select },	/* select */
    728 	{ &vop_revoke_desc, kernfs_revoke },	/* revoke */
    729 	{ &vop_mmap_desc, kernfs_mmap },	/* mmap */
    730 	{ &vop_fsync_desc, kernfs_fsync },	/* fsync */
    731 	{ &vop_seek_desc, kernfs_seek },	/* seek */
    732 	{ &vop_remove_desc, kernfs_remove },	/* remove */
    733 	{ &vop_link_desc, kernfs_link },	/* link */
    734 	{ &vop_rename_desc, kernfs_rename },	/* rename */
    735 	{ &vop_mkdir_desc, kernfs_mkdir },	/* mkdir */
    736 	{ &vop_rmdir_desc, kernfs_rmdir },	/* rmdir */
    737 	{ &vop_symlink_desc, kernfs_symlink },	/* symlink */
    738 	{ &vop_readdir_desc, kernfs_readdir },	/* readdir */
    739 	{ &vop_readlink_desc, kernfs_readlink },/* readlink */
    740 	{ &vop_abortop_desc, kernfs_abortop },	/* abortop */
    741 	{ &vop_inactive_desc, kernfs_inactive },/* inactive */
    742 	{ &vop_reclaim_desc, kernfs_reclaim },	/* reclaim */
    743 	{ &vop_lock_desc, kernfs_lock },	/* lock */
    744 	{ &vop_unlock_desc, kernfs_unlock },	/* unlock */
    745 	{ &vop_bmap_desc, kernfs_bmap },	/* bmap */
    746 	{ &vop_strategy_desc, kernfs_strategy },/* strategy */
    747 	{ &vop_print_desc, kernfs_print },	/* print */
    748 	{ &vop_islocked_desc, kernfs_islocked },/* islocked */
    749 	{ &vop_pathconf_desc, kernfs_pathconf },/* pathconf */
    750 	{ &vop_advlock_desc, kernfs_advlock },	/* advlock */
    751 	{ &vop_blkatoff_desc, kernfs_blkatoff },/* blkatoff */
    752 	{ &vop_valloc_desc, kernfs_valloc },	/* valloc */
    753 	{ &vop_vfree_desc, kernfs_vfree },	/* vfree */
    754 	{ &vop_truncate_desc, kernfs_truncate },/* truncate */
    755 	{ &vop_update_desc, kernfs_update },	/* update */
    756 	{ &vop_bwrite_desc, kernfs_bwrite },	/* bwrite */
    757 	{ (struct vnodeop_desc*)NULL, (int(*)())NULL }
    758 };
    759 struct vnodeopv_desc kernfs_vnodeop_opv_desc =
    760 	{ &kernfs_vnodeop_p, kernfs_vnodeop_entries };
    761