Home | History | Annotate | Line # | Download | only in chfs
chfs_vnops.c revision 1.38
      1 /*	$NetBSD: chfs_vnops.c,v 1.38 2020/04/23 21:47:08 ad Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2010 Department of Software Engineering,
      5  *		      University of Szeged, Hungary
      6  * Copyright (C) 2010 Tamas Toth <ttoth (at) inf.u-szeged.hu>
      7  * Copyright (C) 2010 Adam Hoka <ahoka (at) NetBSD.org>
      8  * All rights reserved.
      9  *
     10  * This code is derived from software contributed to The NetBSD Foundation
     11  * by the Department of Software Engineering, University of Szeged, Hungary
     12  *
     13  * Redistribution and use in source and binary forms, with or without
     14  * modification, are permitted provided that the following conditions
     15  * are met:
     16  * 1. Redistributions of source code must retain the above copyright
     17  *    notice, this list of conditions and the following disclaimer.
     18  * 2. Redistributions in binary form must reproduce the above copyright
     19  *    notice, this list of conditions and the following disclaimer in the
     20  *    documentation and/or other materials provided with the distribution.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 #include <sys/param.h>
     36 #include <miscfs/specfs/specdev.h>
     37 #include <miscfs/fifofs/fifo.h>
     38 #include <miscfs/genfs/genfs.h>
     39 #include <ufs/ufs/dir.h>
     40 #include <ufs/ufs/ufs_extern.h>
     41 #include <uvm/uvm.h>
     42 #include <sys/namei.h>
     43 #include <sys/stat.h>
     44 #include <sys/fcntl.h>
     45 #include <sys/buf.h>
     46 #include <sys/vnode.h>
     47 
     48 #include "chfs.h"
     49 
     50 #define READ_S  "chfs_read"
     51 
     52 int
     53 chfs_lookup(void *v)
     54 {
     55 	struct vnode *dvp = ((struct vop_lookup_v2_args *) v)->a_dvp;
     56 	struct vnode **vpp = ((struct vop_lookup_v2_args *) v)->a_vpp;
     57 	struct componentname *cnp = ((struct vop_lookup_v2_args *) v)->a_cnp;
     58 
     59 	int error;
     60 	struct chfs_inode* ip;
     61 	struct ufsmount* ump;
     62 	struct chfs_mount* chmp;
     63 	struct chfs_vnode_cache* chvc __diagused;
     64 	struct chfs_dirent* fd;
     65 
     66 	dbg("lookup(): %s\n", cnp->cn_nameptr);
     67 
     68 	KASSERT(VOP_ISLOCKED(dvp));
     69 
     70 	*vpp = NULL;
     71 
     72 	/* Check accessibility of requested node as a first step. */
     73 	error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred);
     74 	if (error != 0) {
     75 		goto out;
     76 	}
     77 
     78 	/* If requesting the last path component on a read-only file system
     79 	 * with a write operation, deny it. */
     80 	if ((cnp->cn_flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY)
     81 	    && (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME)) {
     82 		error = EROFS;
     83 		goto out;
     84 	}
     85 
     86 	/* Avoid doing a linear scan of the directory if the requested
     87 	 * directory/name couple is already in the cache. */
     88 	if (cache_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen,
     89 			 cnp->cn_nameiop, cnp->cn_flags, NULL, vpp)) {
     90 		return (*vpp == NULLVP ? ENOENT : 0);
     91 	}
     92 
     93 	/* May need to restart the lookup with an exclusive lock. */
     94 	if (VOP_ISLOCKED(dvp) != LK_EXCLUSIVE)
     95 		return ENOLCK;
     96 
     97 	ip = VTOI(dvp);
     98 	ump = VFSTOUFS(dvp->v_mount);
     99 	chmp = ump->um_chfs;
    100 	if (ip->ino == 0) {
    101 		ip->ino = ++chmp->chm_max_vno;
    102 	}
    103 	mutex_enter(&chmp->chm_lock_vnocache);
    104 	chvc = chfs_vnode_cache_get(chmp, ip->ino);
    105 	mutex_exit(&chmp->chm_lock_vnocache);
    106 
    107 	/* We cannot be requesting the parent directory of the root node. */
    108 	KASSERT(IMPLIES(ip->ch_type == CHT_DIR && chvc->pvno == chvc->vno,
    109 		!(cnp->cn_flags & ISDOTDOT)));
    110 
    111 	if (cnp->cn_flags & ISDOTDOT) {
    112 		VOP_UNLOCK(dvp);
    113 		error = VFS_VGET(dvp->v_mount, ip->chvc->pvno, LK_EXCLUSIVE,
    114 		    vpp);
    115 		vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
    116 	} else if (cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.') {
    117 		vref(dvp);
    118 		*vpp = dvp;
    119 		error = 0;
    120 	} else {
    121 		fd = chfs_dir_lookup(ip, cnp);
    122 
    123 		if (fd == NULL) {
    124 			dbg("fd null\n");
    125 			/* The entry was not found in the directory.
    126 			 * This is OK if we are creating or renaming an
    127 			 * entry and are working on the last component of
    128 			 * the path name. */
    129 			if ((cnp->cn_flags & ISLASTCN) && (cnp->cn_nameiop == CREATE
    130 				|| cnp->cn_nameiop == RENAME)) {
    131 				error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred);
    132 				if (error) {
    133 					dbg("after the entry was not found in dir\n");
    134 					goto out;
    135 				}
    136 
    137 				dbg("return EJUSTRETURN\n");
    138 				error = EJUSTRETURN;
    139 			} else {
    140 				error = ENOENT;
    141 			}
    142 		} else {
    143 			/* If we are not at the last path component and
    144 			 * found a non-directory or non-link entry (which
    145 			 * may itself be pointing to a directory), raise
    146 			 * an error. */
    147 			if ((fd->type != CHT_DIR && fd->type != CHT_LNK) && !(cnp->cn_flags
    148 				& ISLASTCN)) {
    149 				error = ENOTDIR;
    150 				goto out;
    151 			}
    152 
    153 			dbg("vno@allocating new vnode: %llu\n",
    154 				(unsigned long long)fd->vno);
    155 			error = VFS_VGET(dvp->v_mount, fd->vno, LK_EXCLUSIVE,
    156 			    vpp);
    157 		}
    158 	}
    159 	/* Store the result of this lookup in the cache.  Avoid this if the
    160 	 * request was for creation, as it does not improve timings on
    161 	 * emprical tests. */
    162 	if (cnp->cn_nameiop != CREATE && (cnp->cn_flags & ISDOTDOT) == 0) {
    163 		cache_enter(dvp, *vpp, cnp->cn_nameptr, cnp->cn_namelen,
    164 			    cnp->cn_flags);
    165 	}
    166 
    167 out:
    168 	/* If there were no errors, *vpp cannot be NULL. */
    169 	KASSERT(IFF(error == 0, *vpp != NULL));
    170 	KASSERT(VOP_ISLOCKED(dvp));
    171 
    172 	if (error)
    173 		return error;
    174 	if (*vpp != dvp)
    175 		VOP_UNLOCK(*vpp);
    176 	return 0;
    177 }
    178 
    179 /* --------------------------------------------------------------------- */
    180 
    181 int
    182 chfs_create(void *v)
    183 {
    184 	struct vop_create_v3_args /* {
    185 				  struct vnode *a_dvp;
    186 				  struct vnode **a_vpp;
    187 				  struct componentname *a_cnp;
    188 				  struct vattr *a_vap;
    189 				  } */*ap = v;
    190 	int error, mode;
    191 	dbg("create()\n");
    192 
    193 	mode = MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode);
    194 
    195 	if ((mode & IFMT) == 0) {
    196 		if (ap->a_vap->va_type == VREG)
    197 			mode |= IFREG;
    198 		if (ap->a_vap->va_type == VSOCK)
    199 			mode |= IFSOCK;
    200 	}
    201 
    202 	error = chfs_makeinode(mode, ap->a_dvp,	ap->a_vpp, ap->a_cnp, ap->a_vap->va_type);
    203 
    204 	if (error) {
    205 		dbg("error: %d\n", error);
    206 		return error;
    207 	}
    208 
    209 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
    210 	return 0;
    211 }
    212 /* --------------------------------------------------------------------- */
    213 
    214 int
    215 chfs_mknod(void *v)
    216 {
    217 	struct vnode *dvp = ((struct vop_mknod_v3_args *) v)->a_dvp;
    218 	struct vnode **vpp = ((struct vop_mknod_v3_args *) v)->a_vpp;
    219 	struct componentname *cnp = ((struct vop_mknod_v3_args *) v)->a_cnp;
    220 	struct vattr *vap = ((struct vop_mknod_v3_args *) v)->a_vap;
    221 	int mode, err = 0;
    222 	struct chfs_inode *ip;
    223 	struct vnode *vp;
    224 
    225 	struct ufsmount *ump;
    226 	struct chfs_mount *chmp;
    227 
    228 	struct chfs_full_dnode *fd;
    229 	struct buf *bp;
    230 	int len;
    231 	dbg("mknod()\n");
    232 
    233 	ump = VFSTOUFS(dvp->v_mount);
    234 	chmp = ump->um_chfs;
    235 
    236 	/* Check type of node. */
    237 	if (vap->va_type != VBLK && vap->va_type != VCHR && vap->va_type != VFIFO)
    238 		return EINVAL;
    239 
    240 	vp = *vpp;
    241 
    242 	mode = MAKEIMODE(vap->va_type, vap->va_mode);
    243 
    244 	if ((mode & IFMT) == 0) {
    245 		switch (vap->va_type) {
    246 		case VBLK:
    247 			mode |= IFBLK;
    248 			break;
    249 		case VCHR:
    250 			mode |= IFCHR;
    251 			break;
    252 		case VFIFO:
    253 			mode |= IFIFO;
    254 			break;
    255 		default:
    256 			break;
    257 		}
    258 	}
    259 
    260 	/* Create a new node. */
    261 	err = chfs_makeinode(mode, dvp, &vp, cnp, vap->va_type);
    262 
    263 	ip = VTOI(vp);
    264 	if (vap->va_rdev != VNOVAL)
    265 		ip->rdev = vap->va_rdev;
    266 
    267 	if (vap->va_type == VFIFO)
    268 		vp->v_op = chfs_fifoop_p;
    269 	else {
    270 		vp->v_op = chfs_specop_p;
    271 		spec_node_init(vp, ip->rdev);
    272 	}
    273 
    274 	if (err)
    275 		return err;
    276 
    277 	/* Device is written out as a data node. */
    278 	len = sizeof(dev_t);
    279 	chfs_set_vnode_size(vp, len);
    280 	bp = getiobuf(vp, true);
    281 	bp->b_bufsize = bp->b_resid = len;
    282 	bp->b_data = kmem_alloc(len, KM_SLEEP);
    283 	memcpy(bp->b_data, &ip->rdev, len);
    284 	bp->b_blkno = 0;
    285 
    286 	fd = chfs_alloc_full_dnode();
    287 
    288 	mutex_enter(&chmp->chm_lock_mountfields);
    289 
    290 	err = chfs_write_flash_dnode(chmp, vp, bp, fd);
    291 	if (err) {
    292 		mutex_exit(&chmp->chm_lock_mountfields);
    293 		kmem_free(bp->b_data, len);
    294 		return err;
    295 	}
    296 
    297 	/* Add data node to the inode. */
    298 	err = chfs_add_full_dnode_to_inode(chmp, ip, fd);
    299 	if (err) {
    300 		mutex_exit(&chmp->chm_lock_mountfields);
    301 		kmem_free(bp->b_data, len);
    302 		return err;
    303 	}
    304 
    305 	mutex_exit(&chmp->chm_lock_mountfields);
    306 
    307 	*vpp = vp;
    308 	kmem_free(bp->b_data, len);
    309 	putiobuf(bp);
    310 
    311 	return 0;
    312 }
    313 
    314 /* --------------------------------------------------------------------- */
    315 
    316 int
    317 chfs_open(void *v)
    318 {
    319 	struct vnode *vp = ((struct vop_open_args *) v)->a_vp;
    320 	int mode = ((struct vop_open_args *) v)->a_mode;
    321 	dbg("open()\n");
    322 
    323 	int error;
    324 	struct chfs_inode *ip;
    325 
    326 	KASSERT(VOP_ISLOCKED(vp));
    327 
    328 	ip = VTOI(vp);
    329 
    330 	KASSERT(vp->v_size == ip->size);
    331 	if (ip->chvc->nlink < 1) {
    332 		error = ENOENT;
    333 		goto out;
    334 	}
    335 
    336 	/* If the file is marked append-only, deny write requests. */
    337 	if (ip->flags & APPEND && (mode & (FWRITE | O_APPEND)) == FWRITE)
    338 		error = EPERM;
    339 	else
    340 		error = 0;
    341 
    342 out:
    343 	KASSERT(VOP_ISLOCKED(vp));
    344 	return error;
    345 }
    346 
    347 /* --------------------------------------------------------------------- */
    348 
    349 int
    350 chfs_close(void *v)
    351 {
    352 	struct vnode *vp = ((struct vop_close_args *) v)->a_vp;
    353 	dbg("close()\n");
    354 
    355 	struct chfs_inode *ip;
    356 
    357 	KASSERT(VOP_ISLOCKED(vp));
    358 
    359 	ip = VTOI(vp);
    360 
    361 	if (ip->chvc->nlink > 0) {
    362 		chfs_update(vp, NULL, NULL, UPDATE_CLOSE);
    363 	}
    364 
    365 	return 0;
    366 }
    367 
    368 /* --------------------------------------------------------------------- */
    369 
    370 int
    371 chfs_access(void *v)
    372 {
    373 	struct vnode *vp = ((struct vop_access_args *) v)->a_vp;
    374 	int mode = ((struct vop_access_args *) v)->a_mode;
    375 	kauth_cred_t cred = ((struct vop_access_args *) v)->a_cred;
    376 
    377 	dbg("access()\n");
    378 	struct chfs_inode *ip = VTOI(vp);
    379 
    380 	if (mode & VWRITE) {
    381 		switch (vp->v_type) {
    382 		case VLNK:
    383 		case VDIR:
    384 		case VREG:
    385 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
    386 				return (EROFS);
    387 			break;
    388 		case VBLK:
    389 		case VCHR:
    390 		case VSOCK:
    391 		case VFIFO:
    392 			break;
    393 		default:
    394 			break;
    395 		}
    396 	}
    397 
    398 	if (mode & VWRITE && ip->flags & IMMUTABLE)
    399 		return (EPERM);
    400 
    401 	return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(mode, vp->v_type,
    402 	    ip->mode & ALLPERMS), vp, NULL, genfs_can_access(vp->v_type,
    403 	    ip->mode & ALLPERMS, ip->uid, ip->gid, mode, cred));
    404 }
    405 
    406 /* --------------------------------------------------------------------- */
    407 
    408 int
    409 chfs_getattr(void *v)
    410 {
    411 	struct vnode *vp = ((struct vop_getattr_args *) v)->a_vp;
    412 	struct vattr *vap = ((struct vop_getattr_args *) v)->a_vap;
    413 
    414 	struct chfs_inode *ip = VTOI(vp);
    415 	dbg("getattr()\n");
    416 
    417 	KASSERT(vp->v_size == ip->size);
    418 
    419 	vattr_null(vap);
    420 	CHFS_ITIMES(ip, NULL, NULL, NULL);
    421 
    422 	vap->va_type = CHTTOVT(ip->ch_type);
    423 	vap->va_mode = ip->mode & ALLPERMS;
    424 	vap->va_nlink = ip->chvc->nlink;
    425 	vap->va_uid = ip->uid;
    426 	vap->va_gid = ip->gid;
    427 	vap->va_fsid = ip->dev;
    428 	vap->va_fileid = ip->ino;
    429 	vap->va_size = ip->size;
    430 	vap->va_blocksize = PAGE_SIZE;
    431 	vap->va_atime.tv_sec = ip->atime;
    432 	vap->va_atime.tv_nsec = 0;
    433 	vap->va_mtime.tv_sec = ip->mtime;
    434 	vap->va_mtime.tv_nsec = 0;
    435 	vap->va_ctime.tv_sec = ip->ctime;
    436 	vap->va_ctime.tv_nsec = 0;
    437 	vap->va_gen = ip->version;
    438 	vap->va_flags = ip->flags;
    439 	vap->va_rdev = ip->rdev;
    440 	vap->va_bytes = round_page(ip->size);
    441 	vap->va_filerev = VNOVAL;
    442 	vap->va_vaflags = 0;
    443 	vap->va_spare = VNOVAL;
    444 
    445 	return 0;
    446 }
    447 
    448 /* --------------------------------------------------------------------- */
    449 
    450 /* Note: modelled after tmpfs's same function */
    451 
    452 int
    453 chfs_setattr(void *v)
    454 {
    455 	struct vnode *vp = ((struct vop_setattr_args *) v)->a_vp;
    456 	struct vattr *vap = ((struct vop_setattr_args *) v)->a_vap;
    457 	kauth_cred_t cred = ((struct vop_setattr_args *) v)->a_cred;
    458 
    459 	struct chfs_inode *ip;
    460 	struct ufsmount *ump = VFSTOUFS(vp->v_mount);
    461 	struct chfs_mount *chmp = ump->um_chfs;
    462 	int error = 0;
    463 
    464 	dbg("setattr()\n");
    465 
    466 	KASSERT(VOP_ISLOCKED(vp));
    467 	ip = VTOI(vp);
    468 
    469 	/* Abort if any unsettable attribute is given. */
    470 	if (vap->va_type != VNON || vap->va_nlink != VNOVAL ||
    471 	    vap->va_fsid != VNOVAL || vap->va_fileid != VNOVAL ||
    472 	    vap->va_blocksize != VNOVAL /*|| GOODTIME(&vap->va_ctime)*/ ||
    473 	    vap->va_gen != VNOVAL || vap->va_rdev != VNOVAL ||
    474 	    vap->va_bytes != VNOVAL) {
    475 		return EINVAL;
    476 	}
    477 
    478 	/* set flags */
    479 	if (error == 0 && (vap->va_flags != VNOVAL)) {
    480 		error = chfs_chflags(vp, vap->va_flags, cred);
    481 		return error;
    482 	}
    483 
    484 	if (ip->flags & (IMMUTABLE | APPEND)) {
    485 		error = EPERM;
    486 		return error;
    487 	}
    488 
    489 	/* set size */
    490 	if (error == 0 && (vap->va_size != VNOVAL)) {
    491 		error = chfs_chsize(vp, vap->va_size, cred);
    492 		if (error)
    493 			return error;
    494 	}
    495 
    496 	/* set owner */
    497 	if (error == 0 && (vap->va_uid != VNOVAL || vap->va_gid != VNOVAL)) {
    498 		error = chfs_chown(vp, vap->va_uid, vap->va_gid, cred);
    499 		if (error)
    500 			return error;
    501 	}
    502 
    503 	/* set mode */
    504 	if (error == 0 && (vap->va_mode != VNOVAL)) {
    505 		error = chfs_chmod(vp, vap->va_mode, cred);
    506 		if (error)
    507 			return error;
    508 	}
    509 
    510 	/* set time */
    511 	if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
    512 		error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp,
    513 		    NULL, genfs_can_chtimes(vp, vap->va_vaflags, ip->uid, cred));
    514 		if (error)
    515 			return error;
    516 		if (vap->va_atime.tv_sec != VNOVAL)
    517 			ip->iflag |= IN_ACCESS;
    518 		if (vap->va_mtime.tv_sec != VNOVAL)
    519 			ip->iflag |= IN_CHANGE | IN_UPDATE;
    520 		error = chfs_update(vp,
    521 		    &vap->va_atime, &vap->va_mtime, UPDATE_WAIT);
    522 		if (error)
    523 			return error;
    524 	}
    525 
    526 	/* Write it out. */
    527 	mutex_enter(&chmp->chm_lock_mountfields);
    528 	error = chfs_write_flash_vnode(chmp, ip, ALLOC_NORMAL);
    529 	mutex_exit(&chmp->chm_lock_mountfields);
    530 
    531 	return error;
    532 }
    533 
    534 int
    535 chfs_chmod(struct vnode *vp, int mode, kauth_cred_t cred)
    536 {
    537 	struct chfs_inode *ip = VTOI(vp);
    538 	int error;
    539 	dbg("chmod\n");
    540 
    541 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_SECURITY, vp,
    542 	    NULL, genfs_can_chmod(vp->v_type, cred, ip->uid, ip->gid, mode));
    543 	if (error)
    544 		return error;
    545 	ip->mode &= ~ALLPERMS;
    546 	ip->mode |= (mode & ALLPERMS);
    547 	ip->iflag |= IN_CHANGE;
    548 
    549 	error = chfs_update(vp, NULL, NULL, UPDATE_WAIT);
    550 	if (error)
    551 		return error;
    552 
    553 	return 0;
    554 }
    555 
    556 int
    557 chfs_chown(struct vnode *vp, uid_t uid, gid_t gid, kauth_cred_t cred)
    558 {
    559 	struct chfs_inode *ip = VTOI(vp);
    560 	int error;
    561 	dbg("chown\n");
    562 
    563 	if (uid == (uid_t)VNOVAL)
    564 		uid = ip->uid;
    565 	if (gid == (gid_t)VNOVAL)
    566 		gid = ip->gid;
    567 
    568 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_CHANGE_OWNERSHIP, vp,
    569 	    NULL, genfs_can_chown(cred, ip->uid, ip->gid, uid, gid));
    570 	if (error)
    571 		return error;
    572 
    573 	ip->gid = gid;
    574 	ip->uid = uid;
    575 	ip->iflag |= IN_CHANGE;
    576 
    577 	error = chfs_update(vp, NULL, NULL, UPDATE_WAIT);
    578 	if (error)
    579 		return error;
    580 
    581 	return 0;
    582 }
    583 
    584 
    585 /* --------------------------------------------------------------------- */
    586 /* calculates ((off_t)blk * chmp->chm_chm_fs_bsize) */
    587 #define	chfs_lblktosize(chmp, blk)					      \
    588 	(((off_t)(blk)) << (chmp)->chm_fs_bshift)
    589 
    590 /* calculates (loc % chmp->chm_chm_fs_bsize) */
    591 #define	chfs_blkoff(chmp, loc)							      \
    592 	((loc) & (chmp)->chm_fs_qbmask)
    593 
    594 /* calculates (loc / chmp->chm_chm_fs_bsize) */
    595 #define	chfs_lblkno(chmp, loc)							      \
    596 	((loc) >> (chmp)->chm_fs_bshift)
    597 
    598 /* calculates roundup(size, chmp->chm_chm_fs_fsize) */
    599 #define	chfs_fragroundup(chmp, size)					      \
    600 	(((size) + (chmp)->chm_fs_qfmask) & (chmp)->chm_fs_fmask)
    601 
    602 #define	chfs_blksize(chmp, ip, lbn)					      \
    603 	(((lbn) >= UFS_NDADDR || (ip)->size >= chfs_lblktosize(chmp, (lbn) + 1))	      \
    604 	    ? (chmp)->chm_fs_bsize					      \
    605 	    : (chfs_fragroundup(chmp, chfs_blkoff(chmp, (ip)->size))))
    606 
    607 /* calculates roundup(size, chmp->chm_chm_fs_bsize) */
    608 #define	chfs_blkroundup(chmp, size)					      \
    609  	(((size) + (chmp)->chm_fs_qbmask) & (chmp)->chm_fs_bmask)
    610 
    611 /* from ffs read */
    612 int
    613 chfs_read(void *v)
    614 {
    615 	struct vop_read_args /* {
    616 				struct vnode *a_vp;
    617 				struct uio *a_uio;
    618 				int a_ioflag;
    619 				kauth_cred_t a_cred;
    620 				} */ *ap = v;
    621 	struct vnode *vp;
    622 	struct chfs_inode *ip;
    623 	struct uio *uio;
    624 	struct ufsmount *ump;
    625 	struct buf *bp;
    626 	struct chfs_mount *chmp;
    627 	daddr_t lbn, nextlbn;
    628 	off_t bytesinfile;
    629 	long size, xfersize, blkoffset;
    630 	int error, ioflag;
    631 	vsize_t bytelen;
    632 	bool usepc = false;
    633 
    634 	dbg("chfs_read\n");
    635 
    636 	vp = ap->a_vp;
    637 	ip = VTOI(vp);
    638 	ump = ip->ump;
    639 	uio = ap->a_uio;
    640 	ioflag = ap->a_ioflag;
    641 	error = 0;
    642 
    643 	dbg("ip->size:%llu\n", (unsigned long long)ip->size);
    644 
    645 #ifdef DIAGNOSTIC
    646 	if (uio->uio_rw != UIO_READ)
    647 		panic("%s: mode", READ_S);
    648 
    649 	if (vp->v_type == VLNK) {
    650 		if (ip->size < ump->um_maxsymlinklen)
    651 			panic("%s: short symlink", READ_S);
    652 	} else if (vp->v_type != VREG && vp->v_type != VDIR)
    653 		panic("%s: type %d", READ_S, vp->v_type);
    654 #endif
    655 	chmp = ip->chmp;
    656 	if ((u_int64_t)uio->uio_offset > ump->um_maxfilesize)
    657 		return (EFBIG);
    658 	if (uio->uio_resid == 0)
    659 		return (0);
    660 
    661 	if (uio->uio_offset >= ip->size)
    662 		goto out;
    663 
    664 	usepc = vp->v_type == VREG;
    665 	bytelen = 0;
    666 	if (usepc) {
    667 		const int advice = IO_ADV_DECODE(ap->a_ioflag);
    668 
    669 		while (uio->uio_resid > 0) {
    670 			if (ioflag & IO_DIRECT) {
    671 				genfs_directio(vp, uio, ioflag);
    672 			}
    673 			bytelen = MIN(ip->size - uio->uio_offset,
    674 			    uio->uio_resid);
    675 			if (bytelen == 0)
    676 				break;
    677 			error = ubc_uiomove(&vp->v_uobj, uio, bytelen, advice,
    678 			    UBC_READ | UBC_PARTIALOK | UBC_VNODE_FLAGS(vp));
    679 			if (error)
    680 				break;
    681 
    682 		}
    683 		goto out;
    684 	}
    685 
    686 	dbg("start reading\n");
    687 	for (error = 0, bp = NULL; uio->uio_resid > 0; bp = NULL) {
    688 		bytesinfile = ip->size - uio->uio_offset;
    689 		if (bytesinfile <= 0)
    690 			break;
    691 		lbn = chfs_lblkno(chmp, uio->uio_offset);
    692 		nextlbn = lbn + 1;
    693 		size = chfs_blksize(chmp, ip, lbn);
    694 		blkoffset = chfs_blkoff(chmp, uio->uio_offset);
    695 		xfersize = MIN(MIN(chmp->chm_fs_bsize - blkoffset, uio->uio_resid),
    696 		    bytesinfile);
    697 
    698 		if (chfs_lblktosize(chmp, nextlbn) >= ip->size) {
    699 			error = bread(vp, lbn, size, 0, &bp);
    700 			dbg("after bread\n");
    701 		} else {
    702 			int nextsize = chfs_blksize(chmp, ip, nextlbn);
    703 			dbg("size: %ld\n", size);
    704 			error = breadn(vp, lbn,
    705 			    size, &nextlbn, &nextsize, 1, 0, &bp);
    706 			dbg("after breadN\n");
    707 		}
    708 		if (error)
    709 			break;
    710 
    711 		/*
    712 		 * We should only get non-zero b_resid when an I/O error
    713 		 * has occurred, which should cause us to break above.
    714 		 * However, if the short read did not cause an error,
    715 		 * then we want to ensure that we do not uiomove bad
    716 		 * or uninitialized data.
    717 		 */
    718 		size -= bp->b_resid;
    719 		if (size < xfersize) {
    720 			if (size == 0)
    721 				break;
    722 			xfersize = size;
    723 		}
    724 		dbg("uiomove\n");
    725 		error = uiomove((char *)bp->b_data + blkoffset, xfersize, uio);
    726 		if (error)
    727 			break;
    728 		brelse(bp, 0);
    729 	}
    730 
    731 	if (bp != NULL)
    732 		brelse(bp, 0);
    733 
    734 out:
    735 	// FIXME HACK
    736 	ip->ino = ip->chvc->vno;
    737 
    738 	if (!(vp->v_mount->mnt_flag & MNT_NOATIME)) {
    739 		ip->iflag |= IN_ACCESS;
    740 		if ((ap->a_ioflag & IO_SYNC) == IO_SYNC) {
    741 			if (error) {
    742 				return error;
    743 			}
    744 			error = chfs_update(vp, NULL, NULL, UPDATE_WAIT);
    745 		}
    746 	}
    747 
    748 	dbg("[END]\n");
    749 
    750 	return (error);
    751 }
    752 
    753 
    754 /* --------------------------------------------------------------------- */
    755 
    756 /* from ffs write */
    757 int
    758 chfs_write(void *v)
    759 {
    760 	struct vop_write_args /* {
    761 				 struct vnode *a_vp;
    762 				 struct uio *a_uio;
    763 				 int a_ioflag;
    764 				 kauth_cred_t a_cred;
    765 				 } */ *ap = v;
    766 	struct vnode *vp ;
    767 	struct uio *uio;
    768 	struct chfs_inode *ip;
    769 	struct chfs_mount *chmp;
    770 	struct lwp *l;
    771 	kauth_cred_t cred;
    772 	off_t osize, origoff, oldoff, preallocoff, endallocoff, nsize;
    773 	int blkoffset, error, flags, ioflag, resid;
    774 	int aflag;
    775 	int extended=0;
    776 	vsize_t bytelen;
    777 	bool async;
    778 	struct ufsmount *ump;
    779 
    780 
    781 	cred = ap->a_cred;
    782 	ioflag = ap->a_ioflag;
    783 	uio = ap->a_uio;
    784 	vp = ap->a_vp;
    785 	ip = VTOI(vp);
    786 	ump = ip->ump;
    787 
    788 	dbg("write\n");
    789 
    790 	KASSERT(vp->v_size == ip->size);
    791 
    792 	switch (vp->v_type) {
    793 	case VREG:
    794 		if (ioflag & IO_APPEND)
    795 			uio->uio_offset = ip->size;
    796 		if ((ip->flags & APPEND) && uio->uio_offset != ip->size)
    797 			return (EPERM);
    798 		/* FALLTHROUGH */
    799 	case VLNK:
    800 		break;
    801 	case VDIR:
    802 		if ((ioflag & IO_SYNC) == 0)
    803 			panic("chfs_write: nonsync dir write");
    804 		break;
    805 	default:
    806 		panic("chfs_write: type");
    807 	}
    808 
    809 	chmp = ip->chmp;
    810 	if (uio->uio_offset < 0 ||
    811 	    (u_int64_t)uio->uio_offset +
    812 	    uio->uio_resid > ump->um_maxfilesize) {
    813 		dbg("uio->uio_offset = %lld | uio->uio_offset + "
    814 		    "uio->uio_resid (%llu) > ump->um_maxfilesize (%lld)\n",
    815 		    (long long)uio->uio_offset,
    816 		    (uint64_t)uio->uio_offset + uio->uio_resid,
    817 		    (long long)ump->um_maxfilesize);
    818 		return (EFBIG);
    819 	}
    820 	/*
    821 	 * Maybe this should be above the vnode op call, but so long as
    822 	 * file servers have no limits, I don't think it matters.
    823 	 */
    824 	l = curlwp;
    825 	if (vp->v_type == VREG && l &&
    826 	    uio->uio_offset + uio->uio_resid >
    827 	    l->l_proc->p_rlimit[RLIMIT_FSIZE].rlim_cur) {
    828 		mutex_enter(proc_lock);
    829 		psignal(l->l_proc, SIGXFSZ);
    830 		mutex_exit(proc_lock);
    831 		return (EFBIG);
    832 	}
    833 	if (uio->uio_resid == 0)
    834 		return (0);
    835 
    836 	flags = ioflag & IO_SYNC ? B_SYNC : 0;
    837 	async = vp->v_mount->mnt_flag & MNT_ASYNC;
    838 	origoff = uio->uio_offset;
    839 	resid = uio->uio_resid;
    840 	osize = ip->size;
    841 	error = 0;
    842 
    843 	preallocoff = round_page(chfs_blkroundup(chmp,
    844 		MAX(osize, uio->uio_offset)));
    845 	aflag = ioflag & IO_SYNC ? B_SYNC : 0;
    846 	nsize = MAX(osize, uio->uio_offset + uio->uio_resid);
    847 	endallocoff = nsize - chfs_blkoff(chmp, nsize);
    848 
    849 	/*
    850 	 * if we're increasing the file size, deal with expanding
    851 	 * the fragment if there is one.
    852 	 */
    853 
    854 	if (nsize > osize && chfs_lblkno(chmp, osize) < UFS_NDADDR &&
    855 	    chfs_lblkno(chmp, osize) != chfs_lblkno(chmp, nsize) &&
    856 	    chfs_blkroundup(chmp, osize) != osize) {
    857 		off_t eob;
    858 
    859 		eob = chfs_blkroundup(chmp, osize);
    860 		uvm_vnp_setwritesize(vp, eob);
    861 		error = ufs_balloc_range(vp, osize, eob - osize, cred, aflag);
    862 		if (error)
    863 			goto out;
    864 		if (flags & B_SYNC) {
    865 			rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
    866 			VOP_PUTPAGES(vp,
    867 			    trunc_page(osize & chmp->chm_fs_bmask),
    868 			    round_page(eob),
    869 			    PGO_CLEANIT | PGO_SYNCIO | PGO_JOURNALLOCKED);
    870 		}
    871 	}
    872 
    873 	while (uio->uio_resid > 0) {
    874 		int ubc_flags = UBC_WRITE;
    875 		bool overwrite; /* if we're overwrite a whole block */
    876 		off_t newoff;
    877 
    878 		if (ioflag & IO_DIRECT) {
    879 			genfs_directio(vp, uio, ioflag | IO_JOURNALLOCKED);
    880 		}
    881 
    882 		oldoff = uio->uio_offset;
    883 		blkoffset = chfs_blkoff(chmp, uio->uio_offset);
    884 		bytelen = MIN(chmp->chm_fs_bsize - blkoffset, uio->uio_resid);
    885 		if (bytelen == 0) {
    886 			break;
    887 		}
    888 
    889 		/*
    890 		 * if we're filling in a hole, allocate the blocks now and
    891 		 * initialize the pages first.  if we're extending the file,
    892 		 * we can safely allocate blocks without initializing pages
    893 		 * since the new blocks will be inaccessible until the write
    894 		 * is complete.
    895 		 */
    896 		overwrite = uio->uio_offset >= preallocoff &&
    897 		    uio->uio_offset < endallocoff;
    898 		if (!overwrite && (vp->v_vflag & VV_MAPPED) == 0 &&
    899 		    chfs_blkoff(chmp, uio->uio_offset) == 0 &&
    900 		    (uio->uio_offset & PAGE_MASK) == 0) {
    901 			vsize_t len;
    902 
    903 			len = trunc_page(bytelen);
    904 			len -= chfs_blkoff(chmp, len);
    905 			if (len > 0) {
    906 				overwrite = true;
    907 				bytelen = len;
    908 			}
    909 		}
    910 
    911 		newoff = oldoff + bytelen;
    912 		if (vp->v_size < newoff) {
    913 			uvm_vnp_setwritesize(vp, newoff);
    914 		}
    915 
    916 		if (!overwrite) {
    917 			error = ufs_balloc_range(vp, uio->uio_offset, bytelen,
    918 			    cred, aflag);
    919 			if (error)
    920 				break;
    921 		} else {
    922 			genfs_node_wrlock(vp);
    923 			error = GOP_ALLOC(vp, uio->uio_offset, bytelen,
    924 			    aflag, cred);
    925 			genfs_node_unlock(vp);
    926 			if (error)
    927 				break;
    928 			ubc_flags |= UBC_FAULTBUSY;
    929 		}
    930 
    931 		/*
    932 		 * copy the data.
    933 		 */
    934 
    935 		ubc_flags |= UBC_VNODE_FLAGS(vp);
    936 		error = ubc_uiomove(&vp->v_uobj, uio, bytelen,
    937 		    IO_ADV_DECODE(ioflag), ubc_flags);
    938 
    939 		/*
    940 		 * update UVM's notion of the size now that we've
    941 		 * copied the data into the vnode's pages.
    942 		 *
    943 		 * we should update the size even when uiomove failed.
    944 		 */
    945 
    946 		if (vp->v_size < newoff) {
    947 			uvm_vnp_setsize(vp, newoff);
    948 			extended = 1;
    949 		}
    950 
    951 		if (error)
    952 			break;
    953 
    954 		/*
    955 		 * flush what we just wrote if necessary.
    956 		 * XXXUBC simplistic async flushing.
    957 		 */
    958 
    959 		if (!async && oldoff >> 16 != uio->uio_offset >> 16) {
    960 			rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
    961 			error = VOP_PUTPAGES(vp, (oldoff >> 16) << 16,
    962 			    (uio->uio_offset >> 16) << 16,
    963 			    PGO_CLEANIT | PGO_JOURNALLOCKED);
    964 			if (error)
    965 				break;
    966 		}
    967 	}
    968 out:
    969 	if (error == 0 && ioflag & IO_SYNC) {
    970 		rw_enter(vp->v_uobj.vmobjlock, RW_WRITER);
    971 		error = VOP_PUTPAGES(vp,
    972 		    trunc_page(origoff & chmp->chm_fs_bmask),
    973 		    round_page(chfs_blkroundup(chmp, uio->uio_offset)),
    974 		    PGO_CLEANIT | PGO_SYNCIO | PGO_JOURNALLOCKED);
    975 	}
    976 	ip->iflag |= IN_CHANGE | IN_UPDATE;
    977 	if (resid > uio->uio_resid && ap->a_cred) {
    978 		if (ip->mode & ISUID) {
    979 			if (kauth_authorize_vnode(ap->a_cred,
    980 			    KAUTH_VNODE_RETAIN_SUID, vp, NULL, EPERM) != 0)
    981 				ip->mode &= ~ISUID;
    982 		}
    983 
    984 		if (ip->mode & ISGID) {
    985 			if (kauth_authorize_vnode(ap->a_cred,
    986 			    KAUTH_VNODE_RETAIN_SGID, vp, NULL, EPERM) != 0)
    987 				ip->mode &= ~ISGID;
    988 		}
    989 	}
    990 	if (resid > uio->uio_resid)
    991 		VN_KNOTE(vp, NOTE_WRITE | (extended ? NOTE_EXTEND : 0));
    992 	if (error) {
    993 		(void) UFS_TRUNCATE(vp, osize, ioflag & IO_SYNC, ap->a_cred);
    994 		uio->uio_offset -= resid - uio->uio_resid;
    995 		uio->uio_resid = resid;
    996 	} else if (resid > uio->uio_resid && (ioflag & IO_SYNC) == IO_SYNC)
    997 		error = UFS_UPDATE(vp, NULL, NULL, UPDATE_WAIT);
    998 
    999 	//FIXME HACK
   1000 	chfs_set_vnode_size(vp, vp->v_size);
   1001 
   1002 
   1003 	KASSERT(vp->v_size == ip->size);
   1004 
   1005 	mutex_enter(&chmp->chm_lock_mountfields);
   1006 	error = chfs_write_flash_vnode(chmp, ip, ALLOC_NORMAL);
   1007 	mutex_exit(&chmp->chm_lock_mountfields);
   1008 
   1009 	return (error);
   1010 }
   1011 
   1012 
   1013 /* --------------------------------------------------------------------- */
   1014 
   1015 int
   1016 chfs_fsync(void *v)
   1017 {
   1018 	struct vop_fsync_args /* {
   1019 				 struct vnode *a_vp;
   1020 				 kauth_cred_t a_cred;
   1021 				 int a_flags;
   1022 				 off_t offlo;
   1023 				 off_t offhi;
   1024 				 } */ *ap = v;
   1025 	struct vnode *vp = ap->a_vp;
   1026 
   1027 	if (ap->a_flags & FSYNC_CACHE) {
   1028 		return ENODEV;
   1029 	}
   1030  	vflushbuf(vp, ap->a_flags);
   1031 
   1032 	return 0;
   1033 }
   1034 
   1035 /* --------------------------------------------------------------------- */
   1036 
   1037 int
   1038 chfs_remove(void *v)
   1039 {
   1040 	struct vnode *dvp = ((struct vop_remove_v2_args *) v)->a_dvp;
   1041 	struct vnode *vp = ((struct vop_remove_v2_args *) v)->a_vp;
   1042 	struct componentname *cnp = (((struct vop_remove_v2_args *) v)->a_cnp);
   1043 	dbg("remove\n");
   1044 
   1045 	KASSERT(VOP_ISLOCKED(dvp));
   1046 	KASSERT(VOP_ISLOCKED(vp));
   1047 
   1048 	struct chfs_inode *ip = VTOI(vp);
   1049 	struct chfs_inode *parent = VTOI(dvp);
   1050 	int error = 0;
   1051 
   1052 	if (vp->v_type == VDIR || (ip->flags & (IMMUTABLE | APPEND)) ||
   1053 		(parent->flags & APPEND)) {
   1054 		error = EPERM;
   1055 		goto out;
   1056 	}
   1057 
   1058 	KASSERT(ip->chvc->vno != ip->chvc->pvno);
   1059 
   1060 	error = chfs_do_unlink(ip,
   1061 	    parent, cnp->cn_nameptr, cnp->cn_namelen);
   1062 
   1063 out:
   1064 	vput(vp);
   1065 
   1066 	return error;
   1067 }
   1068 
   1069 /* --------------------------------------------------------------------- */
   1070 
   1071 int
   1072 chfs_link(void *v)
   1073 {
   1074 	struct vnode *dvp = ((struct vop_link_v2_args *) v)->a_dvp;
   1075 	struct vnode *vp = ((struct vop_link_v2_args *) v)->a_vp;
   1076 	struct componentname *cnp = ((struct vop_link_v2_args *) v)->a_cnp;
   1077 
   1078 	struct chfs_inode *ip, *parent;
   1079 	int error = 0;
   1080 
   1081 	if (vp->v_type == VDIR) {
   1082 		VOP_ABORTOP(dvp, cnp);
   1083 		error = EISDIR;
   1084 		goto out;
   1085 	}
   1086 	if (dvp->v_mount != vp->v_mount) {
   1087 		VOP_ABORTOP(dvp, cnp);
   1088 		error = EXDEV;
   1089 		goto out;
   1090 	}
   1091 	if (dvp != vp && (error = vn_lock(vp, LK_EXCLUSIVE))) {
   1092 		VOP_ABORTOP(dvp, cnp);
   1093 		goto out;
   1094 	}
   1095 
   1096 	parent = VTOI(dvp);
   1097 	ip = VTOI(vp);
   1098 
   1099 	error = chfs_do_link(ip,
   1100 	    parent, cnp->cn_nameptr, cnp->cn_namelen, ip->ch_type);
   1101 
   1102 	if (dvp != vp)
   1103 		VOP_UNLOCK(vp);
   1104 out:
   1105 	return error;
   1106 }
   1107 
   1108 /* --------------------------------------------------------------------- */
   1109 
   1110 int
   1111 chfs_rename(void *v)
   1112 {
   1113 	struct vnode *fdvp = ((struct vop_rename_args *) v)->a_fdvp;
   1114 	struct vnode *fvp = ((struct vop_rename_args *) v)->a_fvp;
   1115 	struct componentname *fcnp = ((struct vop_rename_args *) v)->a_fcnp;
   1116 	struct vnode *tdvp = ((struct vop_rename_args *) v)->a_tdvp;
   1117 	struct vnode *tvp = ((struct vop_rename_args *) v)->a_tvp;
   1118 	struct componentname *tcnp = ((struct vop_rename_args *) v)->a_tcnp;
   1119 
   1120 	struct chfs_inode *oldparent, *old;
   1121 	struct chfs_inode *newparent;
   1122 	struct chfs_dirent *fd;
   1123 	struct chfs_inode *ip;
   1124 	int error = 0;
   1125 	dbg("rename\n");
   1126 
   1127 	KASSERT(VOP_ISLOCKED(tdvp));
   1128 	KASSERT(IMPLIES(tvp != NULL, VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
   1129 
   1130 	oldparent = VTOI(fdvp);
   1131 	old = VTOI(fvp);
   1132 	newparent = VTOI(tdvp);
   1133 	if (tvp) {
   1134 		dbg("tvp not null\n");
   1135 		ip = VTOI(tvp);
   1136 		if (tvp->v_type == VDIR) {
   1137 			TAILQ_FOREACH(fd, &ip->dents, fds) {
   1138 				if (fd->vno) {
   1139 					error = ENOTEMPTY;
   1140 					goto out_unlocked;
   1141 				}
   1142 			}
   1143 		}
   1144 		error = chfs_do_unlink(ip,
   1145 		    newparent, tcnp->cn_nameptr, tcnp->cn_namelen);
   1146 		vput(tvp);
   1147 	}
   1148 	VFS_VGET(tdvp->v_mount, old->ino, LK_EXCLUSIVE, &tvp);
   1149 	ip = VTOI(tvp);
   1150 
   1151 	/* link new */
   1152 	error = chfs_do_link(ip,
   1153 	    newparent, tcnp->cn_nameptr, tcnp->cn_namelen, ip->ch_type);
   1154 	/* remove old */
   1155 	error = chfs_do_unlink(old,
   1156 	    oldparent, fcnp->cn_nameptr, fcnp->cn_namelen);
   1157 
   1158 out_unlocked:
   1159 	/* Release target nodes. */
   1160 	if (tdvp == tvp)
   1161 		vrele(tdvp);
   1162 	else
   1163 		vput(tdvp);
   1164 	if (tvp != NULL)
   1165 		vput(tvp);
   1166 
   1167 	/* Release source nodes. */
   1168 	vrele(fdvp);
   1169 	vrele(fvp);
   1170 
   1171 	return error;
   1172 }
   1173 
   1174 /* --------------------------------------------------------------------- */
   1175 
   1176 int
   1177 chfs_mkdir(void *v)
   1178 {
   1179 	struct vnode *dvp = ((struct vop_mkdir_v3_args *) v)->a_dvp;
   1180 	struct vnode **vpp = ((struct vop_mkdir_v3_args *)v)->a_vpp;
   1181 	struct componentname *cnp = ((struct vop_mkdir_v3_args *) v)->a_cnp;
   1182 	struct vattr *vap = ((struct vop_mkdir_v3_args *) v)->a_vap;
   1183 	dbg("mkdir()\n");
   1184 
   1185 	int mode;
   1186 
   1187 	mode = vap->va_mode & ACCESSPERMS;
   1188 	if ((mode & IFMT) == 0) {
   1189 		mode |= IFDIR;
   1190 	}
   1191 
   1192 	KASSERT(vap->va_type == VDIR);
   1193 
   1194 	return chfs_makeinode(mode, dvp, vpp, cnp, VDIR);
   1195 }
   1196 
   1197 /* --------------------------------------------------------------------- */
   1198 
   1199 int
   1200 chfs_rmdir(void *v)
   1201 {
   1202 	struct vnode *dvp = ((struct vop_rmdir_v2_args *) v)->a_dvp;
   1203 	struct vnode *vp = ((struct vop_rmdir_v2_args *) v)->a_vp;
   1204 	struct componentname *cnp = ((struct vop_rmdir_v2_args *) v)->a_cnp;
   1205 	dbg("rmdir()\n");
   1206 
   1207 	KASSERT(VOP_ISLOCKED(dvp));
   1208 	KASSERT(VOP_ISLOCKED(vp));
   1209 
   1210 	struct chfs_inode *ip = VTOI(vp);
   1211 	struct chfs_inode *parent = VTOI(dvp);
   1212 	struct chfs_dirent *fd;
   1213 	int error = 0;
   1214 
   1215 	if (vp->v_type != VDIR) {
   1216 		error = ENOTDIR;
   1217 		goto out;
   1218 	}
   1219 
   1220 	KASSERT(ip->chvc->vno != ip->chvc->pvno);
   1221 
   1222 	TAILQ_FOREACH(fd, &ip->dents, fds) {
   1223 		if (fd->vno) {
   1224 			error = ENOTEMPTY;
   1225 			goto out;
   1226 		}
   1227 	}
   1228 
   1229 	error = chfs_do_unlink(ip,
   1230 	    parent, cnp->cn_nameptr, cnp->cn_namelen);
   1231 
   1232 out:
   1233 	vput(vp);
   1234 
   1235 	return error;
   1236 }
   1237 
   1238 /* --------------------------------------------------------------------- */
   1239 
   1240 int
   1241 chfs_symlink(void *v)
   1242 {
   1243 	struct vnode *dvp = ((struct vop_symlink_v3_args *) v)->a_dvp;
   1244 	struct vnode **vpp = ((struct vop_symlink_v3_args *) v)->a_vpp;
   1245 	struct componentname *cnp = ((struct vop_symlink_v3_args *) v)->a_cnp;
   1246 	struct vattr *vap = ((struct vop_symlink_v3_args *) v)->a_vap;
   1247 	char *target = ((struct vop_symlink_v3_args *) v)->a_target;
   1248 
   1249 	struct ufsmount *ump;
   1250 	struct chfs_mount *chmp;
   1251 	struct vnode *vp;
   1252 	struct chfs_inode *ip;
   1253 	int len, err;
   1254 	struct chfs_full_dnode *fd;
   1255 	struct buf *bp;
   1256 	dbg("symlink()\n");
   1257 
   1258 	ump = VFSTOUFS(dvp->v_mount);
   1259 	chmp = ump->um_chfs;
   1260 
   1261 	err = chfs_makeinode(IFLNK | vap->va_mode, dvp, vpp, cnp, VLNK);
   1262 	if (err)
   1263 		return (err);
   1264 	VN_KNOTE(dvp, NOTE_WRITE);
   1265 	vp = *vpp;
   1266 	len = strlen(target);
   1267 	ip = VTOI(vp);
   1268 	/* TODO max symlink len instead of "100" */
   1269 	if (len < 100) {
   1270 		/* symlink path stored as a data node */
   1271 		ip->target = kmem_alloc(len, KM_SLEEP);
   1272 		memcpy(ip->target, target, len);
   1273 		chfs_set_vnode_size(vp, len);
   1274 		ip->iflag |= IN_CHANGE | IN_UPDATE;
   1275 
   1276 		bp = getiobuf(vp, true);
   1277 		bp->b_bufsize = bp->b_resid = len;
   1278 		bp->b_data = kmem_alloc(len, KM_SLEEP);
   1279 		memcpy(bp->b_data, target, len);
   1280 		bp->b_blkno = 0;
   1281 
   1282 		fd = chfs_alloc_full_dnode();
   1283 
   1284 		mutex_enter(&chmp->chm_lock_mountfields);
   1285 
   1286 		/* write out the data node */
   1287 		err = chfs_write_flash_dnode(chmp, vp, bp, fd);
   1288 		if (err) {
   1289 			mutex_exit(&chmp->chm_lock_mountfields);
   1290 			goto out;
   1291 		}
   1292 
   1293 		/* add it to the inode */
   1294 		err = chfs_add_full_dnode_to_inode(chmp, ip, fd);
   1295 		if (err) {
   1296 			mutex_exit(&chmp->chm_lock_mountfields);
   1297 			goto out;
   1298 		}
   1299 
   1300 		mutex_exit(&chmp->chm_lock_mountfields);
   1301 
   1302 		kmem_free(bp->b_data, len);
   1303 		putiobuf(bp);
   1304 
   1305 		uvm_vnp_setsize(vp, len);
   1306 	} else {
   1307 		err = ufs_bufio(UIO_WRITE, vp, target, len, (off_t)0,
   1308 		    IO_NODELOCKED, cnp->cn_cred, (size_t *)0, NULL);
   1309 	}
   1310 
   1311 out:
   1312 	if (err)
   1313 		vrele(vp);
   1314 
   1315 	return (err);
   1316 }
   1317 
   1318 /* --------------------------------------------------------------------- */
   1319 
   1320 int
   1321 chfs_readdir(void *v)
   1322 {
   1323 	struct vnode *vp = ((struct vop_readdir_args *) v)->a_vp;
   1324 	struct uio *uio = ((struct vop_readdir_args *) v)->a_uio;
   1325 	int *eofflag = ((struct vop_readdir_args *) v)->a_eofflag;
   1326 
   1327 	int error = 0;
   1328 	off_t skip, offset;
   1329 	struct chfs_inode *ip;
   1330 	struct chfs_dirent *fd;
   1331 
   1332 	struct ufsmount *ump;
   1333 	struct chfs_mount *chmp;
   1334 	struct chfs_vnode_cache *chvc;
   1335 
   1336 	KASSERT(VOP_ISLOCKED(vp));
   1337 
   1338 	/* This operation only makes sense on directory nodes. */
   1339 	if (vp->v_type != VDIR) {
   1340 		error = ENOTDIR;
   1341 		goto out;
   1342 	}
   1343 
   1344 	ip = VTOI(vp);
   1345 
   1346 	/* uiomove in chfs_filldir automatically increments the
   1347 	 * uio_offset by an arbitrary size, so we discard any change
   1348 	 * to uio_offset and set it to our own value on return
   1349 	 */
   1350 	offset = uio->uio_offset;
   1351 
   1352 	/* Add this entry. */
   1353 	if (offset == CHFS_OFFSET_DOT) {
   1354 		error = chfs_filldir(uio, ip->ino, ".", 1, CHT_DIR);
   1355 		if (error == -1) {
   1356 			error = 0;
   1357 			goto outok;
   1358 		} else if (error != 0)
   1359 			goto outok;
   1360 
   1361 		offset = CHFS_OFFSET_DOTDOT;
   1362 	}
   1363 
   1364 	/* Add parent entry. */
   1365 	if (offset == CHFS_OFFSET_DOTDOT) {
   1366 		ump = VFSTOUFS(vp->v_mount);
   1367 		chmp = ump->um_chfs;
   1368 		mutex_enter(&chmp->chm_lock_vnocache);
   1369 		chvc = chfs_vnode_cache_get(chmp, ip->ino);
   1370 		mutex_exit(&chmp->chm_lock_vnocache);
   1371 
   1372 		error = chfs_filldir(uio, chvc->pvno, "..", 2, CHT_DIR);
   1373 		if (error == -1) {
   1374 			error = 0;
   1375 			goto outok;
   1376 		} else if (error != 0) {
   1377 			goto outok;
   1378 		}
   1379 
   1380 		/* Has child or not? */
   1381 		if (TAILQ_EMPTY(&ip->dents)) {
   1382 			offset = CHFS_OFFSET_EOF;
   1383 		} else {
   1384 			offset = CHFS_OFFSET_FIRST;
   1385 		}
   1386 	}
   1387 
   1388 	if (offset != CHFS_OFFSET_EOF) {
   1389 		/* Child entries. */
   1390 		skip = offset - CHFS_OFFSET_FIRST;
   1391 
   1392 		TAILQ_FOREACH(fd, &ip->dents, fds) {
   1393 			/* seek to offset by skipping items */
   1394 			/* XXX race conditions by changed dirent? */
   1395 			if (skip > 0) {
   1396 				skip--;
   1397 				continue;
   1398 			}
   1399 
   1400 			if (fd->vno != 0) {
   1401 				error = chfs_filldir(uio, fd->vno,
   1402 				    fd->name, fd->nsize, fd->type);
   1403 				if (error == -1) {
   1404 					error = 0;
   1405 					goto outok;
   1406 				} else if (error != 0) {
   1407 					dbg("err %d\n", error);
   1408 					goto outok;
   1409 				}
   1410 			}
   1411 			offset++;
   1412 		}
   1413 	}
   1414 	offset = CHFS_OFFSET_EOF;
   1415 
   1416 outok:
   1417 	uio->uio_offset = offset;
   1418 
   1419 	if (eofflag != NULL) {
   1420 		*eofflag = (error == 0 &&
   1421 		    uio->uio_offset == CHFS_OFFSET_EOF);
   1422 	}
   1423 
   1424 out:
   1425 	KASSERT(VOP_ISLOCKED(vp));
   1426 
   1427 	return error;
   1428 }
   1429 
   1430 /* --------------------------------------------------------------------- */
   1431 
   1432 int
   1433 chfs_readlink(void *v)
   1434 {
   1435 
   1436 	struct vnode *vp = ((struct vop_readlink_args *) v)->a_vp;
   1437 	struct uio *uio = ((struct vop_readlink_args *) v)->a_uio;
   1438 	kauth_cred_t cred = ((struct vop_readlink_args *) v)->a_cred;
   1439 
   1440 	struct chfs_inode *ip = VTOI(vp);
   1441 
   1442 	dbg("readlink()\n");
   1443 
   1444 	/* TODO max symlink len instead of "100" */
   1445 	if (ip->size < 100) {
   1446 		uiomove(ip->target, ip->size, uio);
   1447 		return (0);
   1448 	}
   1449 
   1450 	return (UFS_BUFRD(vp, uio, 0, cred));
   1451 }
   1452 
   1453 /* --------------------------------------------------------------------- */
   1454 
   1455 int
   1456 chfs_inactive(void *v)
   1457 {
   1458 	struct vnode *vp = ((struct vop_inactive_v2_args *) v)->a_vp;
   1459 	struct chfs_inode *ip = VTOI(vp);
   1460 	struct chfs_vnode_cache *chvc;
   1461 	dbg("inactive | vno: %llu\n", (unsigned long long)ip->ino);
   1462 
   1463 	KASSERT(VOP_ISLOCKED(vp));
   1464 
   1465 	/* Reclaim only if there is no link to the node. */
   1466 	if (ip->ino) {
   1467 		chvc = ip->chvc;
   1468 		if (chvc->nlink)
   1469 			*((struct vop_inactive_v2_args *) v)->a_recycle = 0;
   1470 	} else {
   1471 		*((struct vop_inactive_v2_args *) v)->a_recycle = 1;
   1472 	}
   1473 
   1474 	return 0;
   1475 }
   1476 
   1477 /* --------------------------------------------------------------------- */
   1478 
   1479 int
   1480 chfs_reclaim(void *v)
   1481 {
   1482 	struct vop_reclaim_v2_args *ap = v;
   1483 	struct vnode *vp = ap->a_vp;
   1484 	struct chfs_inode *ip = VTOI(vp);
   1485 	struct chfs_mount *chmp = ip->chmp;
   1486 	struct chfs_dirent *fd;
   1487 
   1488 	VOP_UNLOCK(vp);
   1489 
   1490 	mutex_enter(&chmp->chm_lock_mountfields);
   1491 
   1492 	mutex_enter(&chmp->chm_lock_vnocache);
   1493 	ip->chvc->state = VNO_STATE_CHECKEDABSENT;
   1494 	mutex_exit(&chmp->chm_lock_vnocache);
   1495 
   1496 	chfs_update(vp, NULL, NULL, UPDATE_CLOSE);
   1497 
   1498 	/* Clean fragments. */
   1499 	chfs_kill_fragtree(chmp, &ip->fragtree);
   1500 
   1501 	/* Clean dirents. */
   1502 	fd = TAILQ_FIRST(&ip->dents);
   1503 	while (fd) {
   1504 		TAILQ_REMOVE(&ip->dents, fd, fds);
   1505 		chfs_free_dirent(fd);
   1506 		fd = TAILQ_FIRST(&ip->dents);
   1507 	}
   1508 
   1509 	cache_purge(vp);
   1510 	if (ip->devvp) {
   1511 		vrele(ip->devvp);
   1512 		ip->devvp = 0;
   1513 	}
   1514 
   1515 	genfs_node_destroy(vp);
   1516 	pool_put(&chfs_inode_pool, vp->v_data);
   1517 	vp->v_data = NULL;
   1518 
   1519 	mutex_exit(&chmp->chm_lock_mountfields);
   1520 
   1521 	return (0);
   1522 }
   1523 
   1524 /* --------------------------------------------------------------------- */
   1525 
   1526 int
   1527 chfs_advlock(void *v)
   1528 {
   1529 	return 0;
   1530 }
   1531 
   1532 /* --------------------------------------------------------------------- */
   1533 int
   1534 chfs_strategy(void *v)
   1535 {
   1536 	struct vop_strategy_args /* {
   1537 				    const struct vnodeop_desc *a_desc;
   1538 				    struct vnode *a_vp;
   1539 				    struct buf *a_bp;
   1540 				    } */ *ap = v;
   1541 	struct chfs_full_dnode *fd;
   1542 	struct buf *bp = ap->a_bp;
   1543 	struct vnode *vp = ap->a_vp;
   1544 	struct chfs_inode *ip = VTOI(vp);
   1545 	struct chfs_mount *chmp = ip->chmp;
   1546 	int read = (bp->b_flags & B_READ) ? 1 : 0;
   1547 	int err = 0;
   1548 
   1549 	if (read) {
   1550 		err = chfs_read_data(chmp, vp, bp);
   1551 	} else {
   1552 		mutex_enter(&chmp->chm_lock_mountfields);
   1553 
   1554 		fd = chfs_alloc_full_dnode();
   1555 
   1556 		err = chfs_write_flash_dnode(chmp, vp, bp, fd);
   1557 		if (err) {
   1558 			mutex_exit(&chmp->chm_lock_mountfields);
   1559 			goto out;
   1560 		}
   1561 
   1562 		ip = VTOI(vp);
   1563 		err = chfs_add_full_dnode_to_inode(chmp, ip, fd);
   1564 
   1565 		mutex_exit(&chmp->chm_lock_mountfields);
   1566 	}
   1567 out:
   1568 	biodone(bp);
   1569 	return err;
   1570 }
   1571 
   1572 int
   1573 chfs_bmap(void *v)
   1574 {
   1575 	struct vop_bmap_args /* {
   1576 				struct vnode *a_vp;
   1577 				daddr_t  a_bn;
   1578 				struct vnode **a_vpp;
   1579 				daddr_t *a_bnp;
   1580 				int *a_runp;
   1581 				int *a_runb;
   1582 				} */ *ap = v;
   1583 	if (ap->a_vpp != NULL)
   1584 		*ap->a_vpp = ap->a_vp;
   1585 	if (ap->a_bnp != NULL)
   1586 		*ap->a_bnp = ap->a_bn;
   1587 	if (ap->a_runp != NULL)
   1588 		*ap->a_runp = 0;
   1589 	return (0);
   1590 }
   1591 
   1592 /*
   1593  * vnode operations vector used for files stored in a chfs file system.
   1594  */
   1595 int
   1596 (**chfs_vnodeop_p)(void *);
   1597 const struct vnodeopv_entry_desc chfs_vnodeop_entries[] =
   1598 	{
   1599 		{ &vop_default_desc, vn_default_error },
   1600 		{ &vop_lookup_desc, chfs_lookup },
   1601 		{ &vop_create_desc, chfs_create },
   1602 		{ &vop_mknod_desc, chfs_mknod },
   1603 		{ &vop_open_desc, chfs_open },
   1604 		{ &vop_close_desc, chfs_close },
   1605 		{ &vop_access_desc, chfs_access },
   1606 		{ &vop_getattr_desc, chfs_getattr },
   1607 		{ &vop_setattr_desc, chfs_setattr },
   1608 		{ &vop_read_desc, chfs_read },
   1609 		{ &vop_write_desc, chfs_write },
   1610 		{ &vop_fallocate_desc, genfs_eopnotsupp },
   1611 		{ &vop_fdiscard_desc, genfs_eopnotsupp },
   1612 		{ &vop_ioctl_desc, genfs_enoioctl },
   1613 		{ &vop_fcntl_desc, genfs_fcntl },
   1614 		{ &vop_poll_desc, genfs_poll },
   1615 		{ &vop_kqfilter_desc, genfs_kqfilter },
   1616 		{ &vop_revoke_desc, genfs_revoke },
   1617 		{ &vop_mmap_desc, genfs_mmap },
   1618 		{ &vop_fsync_desc, chfs_fsync },
   1619 		{ &vop_seek_desc, genfs_seek },
   1620 		{ &vop_remove_desc, chfs_remove },
   1621 		{ &vop_link_desc, chfs_link },
   1622 		{ &vop_rename_desc, chfs_rename },
   1623 		{ &vop_mkdir_desc, chfs_mkdir },
   1624 		{ &vop_rmdir_desc, chfs_rmdir },
   1625 		{ &vop_symlink_desc, chfs_symlink },
   1626 		{ &vop_readdir_desc, chfs_readdir },
   1627 		{ &vop_readlink_desc, chfs_readlink },
   1628 		{ &vop_abortop_desc, genfs_abortop },
   1629 		{ &vop_inactive_desc, chfs_inactive },
   1630 		{ &vop_reclaim_desc, chfs_reclaim },
   1631 		{ &vop_lock_desc, genfs_lock },
   1632 		{ &vop_unlock_desc, genfs_unlock },
   1633 		{ &vop_bmap_desc, chfs_bmap },
   1634 		{ &vop_strategy_desc, chfs_strategy },
   1635 		{ &vop_print_desc, ufs_print },
   1636 		{ &vop_pathconf_desc, ufs_pathconf },
   1637 		{ &vop_islocked_desc, genfs_islocked },
   1638 		{ &vop_advlock_desc, chfs_advlock },
   1639 		{ &vop_bwrite_desc, vn_bwrite },
   1640 		{ &vop_getpages_desc, genfs_getpages },
   1641 		{ &vop_putpages_desc, genfs_putpages },
   1642 		{ NULL, NULL } };
   1643 
   1644 const struct vnodeopv_desc chfs_vnodeop_opv_desc =
   1645 	{ &chfs_vnodeop_p, chfs_vnodeop_entries };
   1646 
   1647 /* --------------------------------------------------------------------- */
   1648 
   1649 /*
   1650  * vnode operations vector used for special devices stored in a chfs
   1651  * file system.
   1652  */
   1653 int
   1654 (**chfs_specop_p)(void *);
   1655 const struct vnodeopv_entry_desc chfs_specop_entries[] =
   1656 	{
   1657 		{ &vop_default_desc, vn_default_error },
   1658 		{ &vop_lookup_desc, spec_lookup },
   1659 		{ &vop_create_desc, spec_create },
   1660 		{ &vop_mknod_desc, spec_mknod },
   1661 		{ &vop_open_desc, spec_open },
   1662 		{ &vop_close_desc, ufsspec_close },
   1663 		{ &vop_access_desc, chfs_access },
   1664 		{ &vop_getattr_desc, chfs_getattr },
   1665 		{ &vop_setattr_desc, chfs_setattr },
   1666 		{ &vop_read_desc, chfs_read },
   1667 		{ &vop_write_desc, chfs_write },
   1668 		{ &vop_fallocate_desc, spec_fallocate },
   1669 		{ &vop_fdiscard_desc, spec_fdiscard },
   1670 		{ &vop_ioctl_desc, spec_ioctl },
   1671 		{ &vop_fcntl_desc, genfs_fcntl },
   1672 		{ &vop_poll_desc, spec_poll },
   1673 		{ &vop_kqfilter_desc, spec_kqfilter },
   1674 		{ &vop_revoke_desc, spec_revoke },
   1675 		{ &vop_mmap_desc, spec_mmap },
   1676 		{ &vop_fsync_desc, spec_fsync },
   1677 		{ &vop_seek_desc, spec_seek },
   1678 		{ &vop_remove_desc, spec_remove },
   1679 		{ &vop_link_desc, spec_link },
   1680 		{ &vop_rename_desc, spec_rename },
   1681 		{ &vop_mkdir_desc, spec_mkdir },
   1682 		{ &vop_rmdir_desc, spec_rmdir },
   1683 		{ &vop_symlink_desc, spec_symlink },
   1684 		{ &vop_readdir_desc, spec_readdir },
   1685 		{ &vop_readlink_desc, spec_readlink },
   1686 		{ &vop_abortop_desc, spec_abortop },
   1687 		{ &vop_inactive_desc, chfs_inactive },
   1688 		{ &vop_reclaim_desc, chfs_reclaim },
   1689 		{ &vop_lock_desc, genfs_lock },
   1690 		{ &vop_unlock_desc, genfs_unlock },
   1691 		{ &vop_bmap_desc, spec_bmap },
   1692 		{ &vop_strategy_desc, spec_strategy },
   1693 		{ &vop_print_desc, ufs_print },
   1694 		{ &vop_pathconf_desc, spec_pathconf },
   1695 		{ &vop_islocked_desc, genfs_islocked },
   1696 		{ &vop_advlock_desc, spec_advlock },
   1697 		{ &vop_bwrite_desc, vn_bwrite },
   1698 		{ &vop_getpages_desc, spec_getpages },
   1699 		{ &vop_putpages_desc, spec_putpages },
   1700 		{ NULL, NULL } };
   1701 
   1702 const struct vnodeopv_desc chfs_specop_opv_desc =
   1703 	{ &chfs_specop_p, chfs_specop_entries };
   1704 
   1705 /* --------------------------------------------------------------------- */
   1706 /*
   1707  * vnode operations vector used for fifos stored in a chfs file system.
   1708  */
   1709 int
   1710 (**chfs_fifoop_p)(void *);
   1711 const struct vnodeopv_entry_desc chfs_fifoop_entries[] =
   1712 	{
   1713 		{ &vop_default_desc, vn_default_error },
   1714 		{ &vop_lookup_desc, vn_fifo_bypass },
   1715 		{ &vop_create_desc, vn_fifo_bypass },
   1716 		{ &vop_mknod_desc, vn_fifo_bypass },
   1717 		{ &vop_open_desc, vn_fifo_bypass },
   1718 		{ &vop_close_desc, ufsfifo_close },
   1719 		{ &vop_access_desc, chfs_access },
   1720 		{ &vop_getattr_desc, chfs_getattr },
   1721 		{ &vop_setattr_desc, chfs_setattr },
   1722 		{ &vop_read_desc, ufsfifo_read },
   1723 		{ &vop_write_desc, ufsfifo_write },
   1724 		{ &vop_fallocate_desc, vn_fifo_bypass },
   1725 		{ &vop_fdiscard_desc, vn_fifo_bypass },
   1726 		{ &vop_ioctl_desc, vn_fifo_bypass },
   1727 		{ &vop_fcntl_desc, genfs_fcntl },
   1728 		{ &vop_poll_desc, vn_fifo_bypass },
   1729 		{ &vop_kqfilter_desc, vn_fifo_bypass },
   1730 		{ &vop_revoke_desc, vn_fifo_bypass },
   1731 		{ &vop_mmap_desc, vn_fifo_bypass },
   1732 		{ &vop_fsync_desc, vn_fifo_bypass },
   1733 		{ &vop_seek_desc, vn_fifo_bypass },
   1734 		{ &vop_remove_desc, vn_fifo_bypass },
   1735 		{ &vop_link_desc, vn_fifo_bypass },
   1736 		{ &vop_rename_desc, vn_fifo_bypass },
   1737 		{ &vop_mkdir_desc, vn_fifo_bypass },
   1738 		{ &vop_rmdir_desc, vn_fifo_bypass },
   1739 		{ &vop_symlink_desc, vn_fifo_bypass },
   1740 		{ &vop_readdir_desc, vn_fifo_bypass },
   1741 		{ &vop_readlink_desc, vn_fifo_bypass },
   1742 		{ &vop_abortop_desc, vn_fifo_bypass },
   1743 		{ &vop_inactive_desc, chfs_inactive },
   1744 		{ &vop_reclaim_desc, chfs_reclaim },
   1745 		{ &vop_lock_desc, genfs_lock },
   1746 		{ &vop_unlock_desc, genfs_unlock },
   1747 		{ &vop_bmap_desc, vn_fifo_bypass },
   1748 		{ &vop_strategy_desc, vn_fifo_bypass },
   1749 		{ &vop_print_desc, ufs_print },
   1750 		{ &vop_pathconf_desc, vn_fifo_bypass },
   1751 		{ &vop_islocked_desc, genfs_islocked },
   1752 		{ &vop_advlock_desc, vn_fifo_bypass },
   1753 		{ &vop_bwrite_desc, genfs_nullop },
   1754 		{ &vop_getpages_desc, genfs_badop },
   1755 		{ &vop_putpages_desc, vn_fifo_bypass },
   1756 		{ NULL, NULL } };
   1757 
   1758 const struct vnodeopv_desc chfs_fifoop_opv_desc =
   1759 	{ &chfs_fifoop_p, chfs_fifoop_entries };
   1760