Home | History | Annotate | Line # | Download | only in ext2fs
ext2fs_vnops.c revision 1.132
      1 /*	$NetBSD: ext2fs_vnops.c,v 1.132 2020/05/16 18:31:53 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1989, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  * (c) UNIX System Laboratories, Inc.
      7  * All or some portions of this file are derived from material licensed
      8  * to the University of California by American Telephone and Telegraph
      9  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     10  * the permission of UNIX System Laboratories, Inc.
     11  *
     12  * Redistribution and use in source and binary forms, with or without
     13  * modification, are permitted provided that the following conditions
     14  * are met:
     15  * 1. Redistributions of source code must retain the above copyright
     16  *    notice, this list of conditions and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. 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  *	@(#)ufs_vnops.c	8.14 (Berkeley) 10/26/94
     37  * Modified for ext2fs by Manuel Bouyer.
     38  */
     39 
     40 /*
     41  * Copyright (c) 1997 Manuel Bouyer.
     42  *
     43  * Redistribution and use in source and binary forms, with or without
     44  * modification, are permitted provided that the following conditions
     45  * are met:
     46  * 1. Redistributions of source code must retain the above copyright
     47  *    notice, this list of conditions and the following disclaimer.
     48  * 2. Redistributions in binary form must reproduce the above copyright
     49  *    notice, this list of conditions and the following disclaimer in the
     50  *    documentation and/or other materials provided with the distribution.
     51  *
     52  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     53  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     54  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     55  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     56  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     57  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     58  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     59  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     60  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     61  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     62  *
     63  *	@(#)ufs_vnops.c	8.14 (Berkeley) 10/26/94
     64  * Modified for ext2fs by Manuel Bouyer.
     65  */
     66 
     67 #include <sys/cdefs.h>
     68 __KERNEL_RCSID(0, "$NetBSD: ext2fs_vnops.c,v 1.132 2020/05/16 18:31:53 christos Exp $");
     69 
     70 #include <sys/param.h>
     71 #include <sys/systm.h>
     72 #include <sys/resourcevar.h>
     73 #include <sys/kernel.h>
     74 #include <sys/file.h>
     75 #include <sys/stat.h>
     76 #include <sys/buf.h>
     77 #include <sys/proc.h>
     78 #include <sys/mount.h>
     79 #include <sys/namei.h>
     80 #include <sys/vnode.h>
     81 #include <sys/lockf.h>
     82 #include <sys/pool.h>
     83 #include <sys/signalvar.h>
     84 #include <sys/kauth.h>
     85 
     86 #include <miscfs/fifofs/fifo.h>
     87 #include <miscfs/genfs/genfs.h>
     88 #include <miscfs/specfs/specdev.h>
     89 
     90 #include <ufs/ufs/inode.h>
     91 #include <ufs/ufs/ufs_extern.h>
     92 #include <ufs/ufs/ufsmount.h>
     93 
     94 #include <ufs/ext2fs/ext2fs.h>
     95 #include <ufs/ext2fs/ext2fs_extern.h>
     96 #include <ufs/ext2fs/ext2fs_dir.h>
     97 #include <ufs/ext2fs/ext2fs_xattr.h>
     98 
     99 extern int prtactive;
    100 
    101 static int ext2fs_chmod(struct vnode *, int, kauth_cred_t, struct lwp *);
    102 static int ext2fs_chown(struct vnode *, uid_t, gid_t, kauth_cred_t,
    103 				struct lwp *);
    104 static int ext2fs_makeinode(struct vattr *, struct vnode *, struct vnode **,
    105 				struct componentname *, int);
    106 
    107 union _qcvt {
    108 	int64_t	qcvt;
    109 	int32_t val[2];
    110 };
    111 
    112 #define SETHIGH(q, h) { \
    113 	union _qcvt tmp; \
    114 	tmp.qcvt = (q); \
    115 	tmp.val[_QUAD_HIGHWORD] = (h); \
    116 	(q) = tmp.qcvt; \
    117 }
    118 #define SETLOW(q, l) { \
    119 	union _qcvt tmp; \
    120 	tmp.qcvt = (q); \
    121 	tmp.val[_QUAD_LOWWORD] = (l); \
    122 	(q) = tmp.qcvt; \
    123 }
    124 
    125 /*
    126  * Create a regular file
    127  */
    128 int
    129 ext2fs_create(void *v)
    130 {
    131 	struct vop_create_v3_args /* {
    132 		struct vnode *a_dvp;
    133 		struct vnode **a_vpp;
    134 		struct componentname *a_cnp;
    135 		struct vattr *a_vap;
    136 	} */ *ap = v;
    137 	int	error;
    138 
    139 	error = ext2fs_makeinode(ap->a_vap, ap->a_dvp, ap->a_vpp, ap->a_cnp, 1);
    140 
    141 	if (error)
    142 		return error;
    143 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
    144 	VOP_UNLOCK(*ap->a_vpp);
    145 	return 0;
    146 }
    147 
    148 /*
    149  * Mknod vnode call
    150  */
    151 /* ARGSUSED */
    152 int
    153 ext2fs_mknod(void *v)
    154 {
    155 	struct vop_mknod_v3_args /* {
    156 		struct vnode *a_dvp;
    157 		struct vnode **a_vpp;
    158 		struct componentname *a_cnp;
    159 		struct vattr *a_vap;
    160 	} */ *ap = v;
    161 	struct vattr *vap = ap->a_vap;
    162 	struct vnode **vpp = ap->a_vpp;
    163 	struct inode *ip;
    164 	int error;
    165 
    166 	if ((error = ext2fs_makeinode(vap, ap->a_dvp, vpp, ap->a_cnp, 1)) != 0)
    167 		return error;
    168 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
    169 	ip = VTOI(*vpp);
    170 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
    171 	VOP_UNLOCK(*vpp);
    172 	return 0;
    173 }
    174 
    175 /*
    176  * Open called.
    177  *
    178  * Just check the APPEND flag.
    179  */
    180 /* ARGSUSED */
    181 int
    182 ext2fs_open(void *v)
    183 {
    184 	struct vop_open_args /* {
    185 		struct vnode *a_vp;
    186 		int  a_mode;
    187 		kauth_cred_t a_cred;
    188 	} */ *ap = v;
    189 
    190 	/*
    191 	 * Files marked append-only must be opened for appending.
    192 	 */
    193 	if ((VTOI(ap->a_vp)->i_e2fs_flags & EXT2_APPEND) &&
    194 		(ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
    195 		return EPERM;
    196 	return 0;
    197 }
    198 
    199 static int
    200 ext2fs_check_possible(struct vnode *vp, struct inode *ip, mode_t mode)
    201 {
    202 
    203 	/*
    204 	 * Disallow write attempts on read-only file systems;
    205 	 * unless the file is a socket, fifo, or a block or
    206 	 * character device resident on the file system.
    207 	 */
    208 	if (mode & VWRITE) {
    209 		switch (vp->v_type) {
    210 		case VDIR:
    211 		case VLNK:
    212 		case VREG:
    213 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
    214 				return EROFS;
    215 			break;
    216 		default:
    217 			break;
    218 		}
    219 	}
    220 
    221 	/* If immutable bit set, nobody gets to write it. */
    222 	if ((mode & VWRITE) && (ip->i_e2fs_flags & EXT2_IMMUTABLE))
    223 		return EPERM;
    224 
    225 	return 0;
    226 }
    227 
    228 static int
    229 ext2fs_check_permitted(struct vnode *vp, struct inode *ip, accmode_t accmode,
    230     kauth_cred_t cred)
    231 {
    232 
    233 	return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(accmode,
    234 	    vp->v_type, ip->i_e2fs_mode & ALLPERMS), vp, NULL,
    235 	    genfs_can_access(vp, cred, ip->i_uid, ip->i_gid,
    236 	    ip->i_e2fs_mode & ALLPERMS, NULL, accmode));
    237 }
    238 
    239 int
    240 ext2fs_access(void *v)
    241 {
    242 	struct vop_access_args /* {
    243 		struct vnode *a_vp;
    244 		accmode_t  a_accmode;
    245 		kauth_cred_t a_cred;
    246 	} */ *ap = v;
    247 	struct vnode *vp = ap->a_vp;
    248 	struct inode *ip = VTOI(vp);
    249 	accmode_t mode = ap->a_accmode;
    250 	int error;
    251 
    252 	error = ext2fs_check_possible(vp, ip, mode);
    253 	if (error)
    254 		return error;
    255 
    256 	error = ext2fs_check_permitted(vp, ip, mode, ap->a_cred);
    257 
    258 	return error;
    259 }
    260 
    261 /* ARGSUSED */
    262 int
    263 ext2fs_getattr(void *v)
    264 {
    265 	struct vop_getattr_args /* {
    266 		struct vnode *a_vp;
    267 		struct vattr *a_vap;
    268 		kauth_cred_t a_cred;
    269 	} */ *ap = v;
    270 	struct vnode *vp = ap->a_vp;
    271 	struct inode *ip = VTOI(vp);
    272 	struct vattr *vap = ap->a_vap;
    273 
    274 	EXT2FS_ITIMES(ip, NULL, NULL, NULL);
    275 	/*
    276 	 * Copy from inode table
    277 	 */
    278 	vap->va_fsid = ip->i_dev;
    279 	vap->va_fileid = ip->i_number;
    280 	vap->va_mode = ip->i_e2fs_mode & ALLPERMS;
    281 	vap->va_nlink = ip->i_e2fs_nlink;
    282 	vap->va_uid = ip->i_uid;
    283 	vap->va_gid = ip->i_gid;
    284 	vap->va_rdev = (dev_t)fs2h32(ip->i_din.e2fs_din->e2di_rdev);
    285 	vap->va_size = vp->v_size;
    286 	EXT2_DINODE_TIME_GET(&vap->va_atime, ip->i_din.e2fs_din, e2di_atime, EXT2_DINODE_SIZE(ip->i_e2fs));
    287 	EXT2_DINODE_TIME_GET(&vap->va_mtime, ip->i_din.e2fs_din, e2di_mtime, EXT2_DINODE_SIZE(ip->i_e2fs));
    288 	EXT2_DINODE_TIME_GET(&vap->va_ctime, ip->i_din.e2fs_din, e2di_ctime, EXT2_DINODE_SIZE(ip->i_e2fs));
    289 	if (EXT2_DINODE_FITS(ip->i_din.e2fs_din, e2di_crtime, EXT2_DINODE_SIZE(ip->i_e2fs))) {
    290 		EXT2_DINODE_TIME_GET(&vap->va_birthtime, ip->i_din.e2fs_din, e2di_crtime, EXT2_DINODE_SIZE(ip->i_e2fs));
    291 	}
    292 
    293 	vap->va_flags = 0;
    294 	vap->va_flags |= (ip->i_e2fs_flags & EXT2_NODUMP) ? UF_NODUMP : 0;
    295 #ifdef EXT2FS_SYSTEM_FLAGS
    296 	vap->va_flags |= (ip->i_e2fs_flags & EXT2_IMMUTABLE) ? SF_IMMUTABLE : 0;
    297 	vap->va_flags |= (ip->i_e2fs_flags & EXT2_APPEND) ? SF_APPEND : 0;
    298 #else
    299 	vap->va_flags |= (ip->i_e2fs_flags & EXT2_IMMUTABLE) ? UF_IMMUTABLE : 0;
    300 	vap->va_flags |= (ip->i_e2fs_flags & EXT2_APPEND) ? UF_APPEND : 0;
    301 #endif
    302 
    303 	vap->va_gen = ip->i_e2fs_gen;
    304 	/* this doesn't belong here */
    305 	if (vp->v_type == VBLK)
    306 		vap->va_blocksize = BLKDEV_IOSIZE;
    307 	else if (vp->v_type == VCHR)
    308 		vap->va_blocksize = MAXBSIZE;
    309 	else
    310 		vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
    311 	vap->va_bytes = dbtob(ext2fs_nblock(ip));
    312 	vap->va_type = vp->v_type;
    313 	vap->va_filerev = ip->i_modrev;
    314 	return 0;
    315 }
    316 
    317 /*
    318  * Set attribute vnode op. called from several syscalls
    319  */
    320 int
    321 ext2fs_setattr(void *v)
    322 {
    323 	struct vop_setattr_args /* {
    324 		struct vnode *a_vp;
    325 		struct vattr *a_vap;
    326 		kauth_cred_t a_cred;
    327 	} */ *ap = v;
    328 	struct vattr *vap = ap->a_vap;
    329 	struct vnode *vp = ap->a_vp;
    330 	struct inode *ip = VTOI(vp);
    331 	kauth_cred_t cred = ap->a_cred;
    332 	struct lwp *l = curlwp;
    333 	int error;
    334 	kauth_action_t action = KAUTH_VNODE_WRITE_FLAGS;
    335 	bool changing_sysflags = false;
    336 
    337 	/*
    338 	 * Check for unsettable attributes.
    339 	 */
    340 	if ((vap->va_type != VNON) || (vap->va_nlink != (nlink_t)VNOVAL) ||
    341 	    (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
    342 	    (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
    343 	    ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
    344 		return EINVAL;
    345 	}
    346 	if (vap->va_flags != VNOVAL) {
    347 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
    348 			return EROFS;
    349 
    350 		/*
    351 		 * Check if we're allowed to change the flags.
    352 		 * If EXT2FS_SYSTEM_FLAGS is set, then the flags are treated
    353 		 * as system flags, otherwise they're considered to be user
    354 		 * flags.
    355 		 */
    356 #ifdef EXT2FS_SYSTEM_FLAGS
    357 		/* Indicate we're changing system flags if we are. */
    358 		if ((vap->va_flags & SF_APPEND) ||
    359 		     (vap->va_flags & SF_IMMUTABLE)) {
    360 			action |= KAUTH_VNODE_WRITE_SYSFLAGS;
    361 			changing_sysflags = true;
    362 		}
    363 
    364 		/* Indicate the node has system flags if it does. */
    365 		if (ip->i_e2fs_flags & (EXT2_APPEND | EXT2_IMMUTABLE)) {
    366 			action |= KAUTH_VNODE_HAS_SYSFLAGS;
    367 		}
    368 #endif /* EXT2FS_SYSTEM_FLAGS */
    369 
    370 		error = kauth_authorize_vnode(cred, action, vp, NULL,
    371 		    genfs_can_chflags(vp, cred, ip->i_uid, changing_sysflags));
    372 		if (error)
    373 			return error;
    374 
    375 		ip->i_e2fs_flags &= ~(EXT2_APPEND | EXT2_IMMUTABLE | EXT2_NODUMP);
    376 #ifdef EXT2FS_SYSTEM_FLAGS
    377 		ip->i_e2fs_flags |=
    378 		    (vap->va_flags & SF_APPEND) ?  EXT2_APPEND : 0 |
    379 		    (vap->va_flags & SF_IMMUTABLE) ? EXT2_IMMUTABLE : 0;
    380 #else
    381 		ip->i_e2fs_flags |=
    382 		    (vap->va_flags & UF_APPEND) ? EXT2_APPEND : 0 |
    383 		    (vap->va_flags & UF_IMMUTABLE) ? EXT2_IMMUTABLE : 0;
    384 #endif
    385 		ip->i_e2fs_flags |=
    386 		    (vap->va_flags & UF_NODUMP) ? EXT2_NODUMP : 0;
    387 		ip->i_flag |= IN_CHANGE;
    388 		if (vap->va_flags & (IMMUTABLE | APPEND))
    389 			return 0;
    390 	}
    391 	if (ip->i_e2fs_flags & (EXT2_APPEND | EXT2_IMMUTABLE))
    392 		return EPERM;
    393 	/*
    394 	 * Go through the fields and update iff not VNOVAL.
    395 	 */
    396 	if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
    397 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
    398 			return EROFS;
    399 		error = ext2fs_chown(vp, vap->va_uid, vap->va_gid, cred, l);
    400 		if (error)
    401 			return error;
    402 	}
    403 	if (vap->va_size != VNOVAL) {
    404 		/*
    405 		 * Disallow write attempts on read-only file systems;
    406 		 * unless the file is a socket, fifo, or a block or
    407 		 * character device resident on the file system.
    408 		 */
    409 		switch (vp->v_type) {
    410 		case VDIR:
    411 			return EISDIR;
    412 		case VLNK:
    413 		case VREG:
    414 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
    415 				return EROFS;
    416 		default:
    417 			break;
    418 		}
    419 		error = ext2fs_truncate(vp, vap->va_size, 0, cred);
    420 		if (error)
    421 			return error;
    422 	}
    423 	ip = VTOI(vp);
    424 	if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL || vap->va_birthtime.tv_sec != VNOVAL) {
    425 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
    426 			return EROFS;
    427 		error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp,
    428 		    NULL, genfs_can_chtimes(vp, cred, ip->i_uid,
    429 		    vap->va_vaflags));
    430 		if (error)
    431 			return error;
    432 		if (vap->va_atime.tv_sec != VNOVAL)
    433 			if (!(vp->v_mount->mnt_flag & MNT_NOATIME))
    434 				ip->i_flag |= IN_ACCESS;
    435 		if (vap->va_mtime.tv_sec != VNOVAL) {
    436 			ip->i_flag |= IN_CHANGE | IN_UPDATE;
    437 			if (vp->v_mount->mnt_flag & MNT_RELATIME)
    438 				ip->i_flag |= IN_ACCESS;
    439 		}
    440 		if (vap->va_birthtime.tv_sec != VNOVAL &&
    441 		    EXT2_DINODE_FITS(ip->i_din.e2fs_din, e2di_crtime, EXT2_DINODE_SIZE(ip->i_e2fs))) {
    442 
    443 			EXT2_DINODE_TIME_SET(&vap->va_birthtime, ip->i_din.e2fs_din, e2di_crtime, EXT2_DINODE_SIZE(ip->i_e2fs));
    444 		}
    445 		error = ext2fs_update(vp, &vap->va_atime, &vap->va_mtime,
    446 			UPDATE_WAIT);
    447 		if (error)
    448 			return error;
    449 	}
    450 	error = 0;
    451 	if (vap->va_mode != (mode_t)VNOVAL) {
    452 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
    453 			return EROFS;
    454 		error = ext2fs_chmod(vp, (int)vap->va_mode, cred, l);
    455 	}
    456 	VN_KNOTE(vp, NOTE_ATTRIB);
    457 	return error;
    458 }
    459 
    460 /*
    461  * Change the mode on a file.
    462  * Inode must be locked before calling.
    463  */
    464 static int
    465 ext2fs_chmod(struct vnode *vp, int mode, kauth_cred_t cred, struct lwp *l)
    466 {
    467 	struct inode *ip = VTOI(vp);
    468 	int error;
    469 
    470 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_SECURITY, vp,
    471 	    NULL, genfs_can_chmod(vp, cred, ip->i_uid, ip->i_gid, mode));
    472 	if (error)
    473 		return error;
    474 
    475 	ip->i_e2fs_mode &= ~ALLPERMS;
    476 	ip->i_e2fs_mode |= (mode & ALLPERMS);
    477 	ip->i_flag |= IN_CHANGE;
    478 	return 0;
    479 }
    480 
    481 /*
    482  * Perform chown operation on inode ip;
    483  * inode must be locked prior to call.
    484  */
    485 static int
    486 ext2fs_chown(struct vnode *vp, uid_t uid, gid_t gid, kauth_cred_t cred,
    487 		struct lwp *l)
    488 {
    489 	struct inode *ip = VTOI(vp);
    490 	uid_t ouid;
    491 	gid_t ogid;
    492 	int error;
    493 
    494 	if (uid == (uid_t)VNOVAL)
    495 		uid = ip->i_uid;
    496 	if (gid == (gid_t)VNOVAL)
    497 		gid = ip->i_gid;
    498 
    499 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_CHANGE_OWNERSHIP, vp,
    500 	    NULL, genfs_can_chown(vp, cred, ip->i_uid, ip->i_gid, uid, gid));
    501 	if (error)
    502 		return error;
    503 
    504 	ogid = ip->i_gid;
    505 	ouid = ip->i_uid;
    506 
    507 	ip->i_e2fs_gid = gid & 0xffff;
    508 	ip->i_e2fs_uid = uid & 0xffff;
    509 	if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0) {
    510 		ip->i_e2fs_gid_high = (gid >> 16) & 0xffff;
    511 		ip->i_e2fs_uid_high = (uid >> 16) & 0xffff;
    512 	} else {
    513 		ip->i_e2fs_gid_high = 0;
    514 		ip->i_e2fs_uid_high = 0;
    515 	}
    516 	if (ouid != uid || ogid != gid) {
    517 		ext2fs_set_inode_guid(ip);
    518 		ip->i_flag |= IN_CHANGE;
    519 	}
    520 	if (ouid != uid && (ip->i_e2fs_mode & ISUID) &&
    521 	    kauth_authorize_vnode(cred, KAUTH_VNODE_RETAIN_SUID,
    522 	    vp, NULL, EPERM) != 0)
    523 		ip->i_e2fs_mode &= ~ISUID;
    524 	if (ogid != gid && (ip->i_e2fs_mode & ISGID) &&
    525 	    kauth_authorize_vnode(cred, KAUTH_VNODE_RETAIN_SGID,
    526 	    vp, NULL, EPERM) != 0)
    527 		ip->i_e2fs_mode &= ~ISGID;
    528 	return 0;
    529 }
    530 
    531 int
    532 ext2fs_remove(void *v)
    533 {
    534 	struct vop_remove_v2_args /* {
    535 		struct vnode *a_dvp;
    536 		struct vnode *a_vp;
    537 		struct componentname *a_cnp;
    538 	} */ *ap = v;
    539 	struct inode *ip;
    540 	struct vnode *vp = ap->a_vp;
    541 	struct vnode *dvp = ap->a_dvp;
    542 	struct ufs_lookup_results *ulr;
    543 	int error;
    544 
    545 	/* XXX should handle this material another way */
    546 	ulr = &VTOI(dvp)->i_crap;
    547 	UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
    548 
    549 	ip = VTOI(vp);
    550 	if (vp->v_type == VDIR ||
    551 		(ip->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND)) ||
    552 		(VTOI(dvp)->i_e2fs_flags & EXT2_APPEND)) {
    553 		error = EPERM;
    554 	} else {
    555 		error = ext2fs_dirremove(dvp, ulr, ap->a_cnp);
    556 		if (error == 0) {
    557 			ip->i_e2fs_nlink--;
    558 			ip->i_flag |= IN_CHANGE;
    559 		}
    560 	}
    561 
    562 	VN_KNOTE(vp, NOTE_DELETE);
    563 	VN_KNOTE(dvp, NOTE_WRITE);
    564 	if (dvp == vp)
    565 		vrele(vp);
    566 	else
    567 		vput(vp);
    568 	return error;
    569 }
    570 
    571 /*
    572  * ext2fs_link: create hard link.
    573  */
    574 int
    575 ext2fs_link(void *v)
    576 {
    577 	struct vop_link_v2_args /* {
    578 		struct vnode *a_dvp;
    579 		struct vnode *a_vp;
    580 		struct componentname *a_cnp;
    581 	} */ *ap = v;
    582 	struct vnode *dvp = ap->a_dvp;
    583 	struct vnode *vp = ap->a_vp;
    584 	struct componentname *cnp = ap->a_cnp;
    585 	struct inode *ip;
    586 	int error;
    587 	struct ufs_lookup_results *ulr;
    588 
    589 	KASSERT(dvp != vp);
    590 	KASSERT(vp->v_type != VDIR);
    591 	KASSERT(dvp->v_mount == vp->v_mount);
    592 
    593 	/* XXX should handle this material another way */
    594 	ulr = &VTOI(dvp)->i_crap;
    595 	UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
    596 
    597 	error = vn_lock(vp, LK_EXCLUSIVE);
    598 	if (error) {
    599 		VOP_ABORTOP(dvp, cnp);
    600 		goto out2;
    601 	}
    602 	ip = VTOI(vp);
    603 	if ((nlink_t)ip->i_e2fs_nlink >= EXT2FS_LINK_MAX) {
    604 		VOP_ABORTOP(dvp, cnp);
    605 		error = EMLINK;
    606 		goto out1;
    607 	}
    608 	if (ip->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND)) {
    609 		VOP_ABORTOP(dvp, cnp);
    610 		error = EPERM;
    611 		goto out1;
    612 	}
    613 	ip->i_e2fs_nlink++;
    614 	ip->i_flag |= IN_CHANGE;
    615 	error = ext2fs_update(vp, NULL, NULL, UPDATE_WAIT);
    616 	if (!error)
    617 		error = ext2fs_direnter(ip, dvp, ulr, cnp);
    618 	if (error) {
    619 		ip->i_e2fs_nlink--;
    620 		ip->i_flag |= IN_CHANGE;
    621 	}
    622 out1:
    623 	VOP_UNLOCK(vp);
    624 out2:
    625 	VN_KNOTE(vp, NOTE_LINK);
    626 	VN_KNOTE(dvp, NOTE_WRITE);
    627 	return error;
    628 }
    629 
    630 /*
    631  * Mkdir system call
    632  */
    633 int
    634 ext2fs_mkdir(void *v)
    635 {
    636 	struct vop_mkdir_v3_args /* {
    637 		struct vnode *a_dvp;
    638 		struct vnode **a_vpp;
    639 		struct componentname *a_cnp;
    640 		struct vattr *a_vap;
    641 	} */ *ap = v;
    642 	struct vnode		*dvp = ap->a_dvp;
    643 	struct componentname	*cnp = ap->a_cnp;
    644 	struct inode		*ip, *dp = VTOI(dvp);
    645 	struct vnode		*tvp;
    646 	struct ext2fs_dirtemplate dirtemplate;
    647 	int			error;
    648 	struct ufs_lookup_results *ulr;
    649 
    650 	/* XXX should handle this material another way */
    651 	ulr = &VTOI(dvp)->i_crap;
    652 	UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
    653 
    654 	KASSERT(ap->a_vap->va_type == VDIR);
    655 
    656 	/*
    657 	 * Acquire the inode, but don't sync/direnter it just yet
    658 	 */
    659 	error = ext2fs_makeinode(ap->a_vap, ap->a_dvp, &tvp, ap->a_cnp, 0);
    660 	if (error)
    661 		goto out;
    662 
    663 	/* the link count is going to be 2 when all is done */
    664 	ip = VTOI(tvp);
    665 	ip->i_e2fs_nlink = 2;
    666 
    667 	/*
    668 	 * Bump link count in parent directory
    669 	 * to reflect work done below.  Should
    670 	 * be done before reference is created
    671 	 * so reparation is possible if we crash.
    672 	 */
    673 	if (dp->i_e2fs_nlink != EXT2FS_LINK_INF)
    674 		dp->i_e2fs_nlink++;
    675 
    676 	/*
    677 	 * If we hit the link limit, for directories just set the nlink
    678 	 * to special value 1, which means the link count is bigger
    679 	 * than EXT2FS_LINK_MAX.
    680 	 */
    681 	if ((nlink_t)dp->i_e2fs_nlink >= EXT2FS_LINK_MAX) {
    682 		dp->i_e2fs_nlink = EXT2FS_LINK_INF;
    683 
    684 		/* set the feature flag DIR_NLINK if not set already */
    685 		if (!EXT2F_HAS_ROCOMPAT_FEATURE(dp->i_e2fs, EXT2F_ROCOMPAT_DIR_NLINK)) {
    686                 	dp->i_e2fs->e2fs.e2fs_features_rocompat |= EXT2F_ROCOMPAT_DIR_NLINK;
    687                 	dp->i_e2fs->e2fs_fmod = 1;
    688 		}
    689 	}
    690 
    691 	dp->i_flag |= IN_CHANGE;
    692 	if ((error = ext2fs_update(dvp, NULL, NULL, UPDATE_DIROP)) != 0)
    693 		goto bad;
    694 
    695 	/* Initialize directory with "." and ".." from static template. */
    696 	memset(&dirtemplate, 0, sizeof(dirtemplate));
    697 	dirtemplate.dot_ino = h2fs32(ip->i_number);
    698 	dirtemplate.dot_reclen = h2fs16(12);
    699 	dirtemplate.dot_namlen = 1;
    700 	if (EXT2F_HAS_INCOMPAT_FEATURE(dp->i_e2fs, EXT2F_INCOMPAT_FTYPE)) {
    701 		dirtemplate.dot_type = EXT2_FT_DIR;
    702 	}
    703 	dirtemplate.dot_name[0] = '.';
    704 	dirtemplate.dotdot_ino = h2fs32(dp->i_number);
    705 	dirtemplate.dotdot_reclen = h2fs16(VTOI(dvp)->i_e2fs->e2fs_bsize - 12);
    706 	dirtemplate.dotdot_namlen = 2;
    707 	if (EXT2F_HAS_INCOMPAT_FEATURE(dp->i_e2fs, EXT2F_INCOMPAT_FTYPE)) {
    708 		dirtemplate.dotdot_type = EXT2_FT_DIR;
    709 	}
    710 	dirtemplate.dotdot_name[0] = dirtemplate.dotdot_name[1] = '.';
    711 	error = ufs_bufio(UIO_WRITE, tvp, (void *)&dirtemplate,
    712 	    sizeof (dirtemplate), (off_t)0, IO_NODELOCKED|IO_SYNC,
    713 	    cnp->cn_cred, (size_t *)0, NULL);
    714 	if (error) {
    715 		if (dp->i_e2fs_nlink != EXT2FS_LINK_INF)
    716 			dp->i_e2fs_nlink--;
    717 		dp->i_flag |= IN_CHANGE;
    718 		goto bad;
    719 	}
    720 	if (VTOI(dvp)->i_e2fs->e2fs_bsize > dvp->v_mount->mnt_stat.f_bsize)
    721 		panic("ext2fs_mkdir: blksize"); /* XXX should grow with balloc() */
    722 	else {
    723 		error = ext2fs_setsize(ip, VTOI(dvp)->i_e2fs->e2fs_bsize);
    724 		if (error) {
    725 			if (dp->i_e2fs_nlink != EXT2FS_LINK_INF)
    726 				dp->i_e2fs_nlink--;
    727 			dp->i_flag |= IN_CHANGE;
    728 			goto bad;
    729 		}
    730 		ip->i_flag |= IN_CHANGE;
    731 		uvm_vnp_setsize(tvp, ext2fs_size(ip));
    732 	}
    733 
    734 	/* Directory set up, now install its entry in the parent directory. */
    735 	error = ext2fs_direnter(ip, dvp, ulr, cnp);
    736 	if (error != 0) {
    737 		if (dp->i_e2fs_nlink != EXT2FS_LINK_INF)
    738 			dp->i_e2fs_nlink--;
    739 		dp->i_flag |= IN_CHANGE;
    740 	}
    741 bad:
    742 	/*
    743 	 * No need to do an explicit ext2fs_truncate here, vrele will do this
    744 	 * for us because we set the link count to 0.
    745 	 */
    746 	if (error) {
    747 		ip->i_e2fs_nlink = 0;
    748 		ip->i_flag |= IN_CHANGE;
    749 		vput(tvp);
    750 	} else {
    751 		VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
    752 		VOP_UNLOCK(tvp);
    753 		*ap->a_vpp = tvp;
    754 	}
    755 out:
    756 	return error;
    757 }
    758 
    759 /*
    760  * Rmdir system call.
    761  */
    762 int
    763 ext2fs_rmdir(void *v)
    764 {
    765 	struct vop_rmdir_v2_args /* {
    766 		struct vnode *a_dvp;
    767 		struct vnode *a_vp;
    768 		struct componentname *a_cnp;
    769 	} */ *ap = v;
    770 	struct vnode *vp = ap->a_vp;
    771 	struct vnode *dvp = ap->a_dvp;
    772 	struct componentname *cnp = ap->a_cnp;
    773 	struct inode *ip, *dp;
    774 	int error;
    775 	struct ufs_lookup_results *ulr;
    776 
    777 	ip = VTOI(vp);
    778 	dp = VTOI(dvp);
    779 
    780 	/* XXX should handle this material another way */
    781 	ulr = &dp->i_crap;
    782 	UFS_CHECK_CRAPCOUNTER(dp);
    783 
    784 	/*
    785 	 * No rmdir "." please.
    786 	 */
    787 	if (dp == ip) {
    788 		vrele(vp);
    789 		return EINVAL;
    790 	}
    791 	/*
    792 	 * Verify the directory is empty (and valid).
    793 	 * (Rmdir ".." won't be valid since
    794 	 *  ".." will contain a reference to
    795 	 *  the current directory and thus be
    796 	 *  non-empty.)
    797 	 */
    798 	error = 0;
    799 	if ((ip->i_e2fs_nlink != 2 && ip->i_e2fs_nlink != EXT2FS_LINK_INF) ||
    800 	    !ext2fs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
    801 		error = ENOTEMPTY;
    802 		goto out;
    803 	}
    804 	if ((dp->i_e2fs_flags & EXT2_APPEND) ||
    805 				 (ip->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND))) {
    806 		error = EPERM;
    807 		goto out;
    808 	}
    809 	/*
    810 	 * Delete reference to directory before purging
    811 	 * inode.  If we crash in between, the directory
    812 	 * will be reattached to lost+found,
    813 	 */
    814 	error = ext2fs_dirremove(dvp, ulr, cnp);
    815 	if (error != 0)
    816 		goto out;
    817 	if (dp->i_e2fs_nlink != EXT2FS_LINK_INF)
    818 		dp->i_e2fs_nlink--;
    819 	dp->i_flag |= IN_CHANGE;
    820 	VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
    821 	cache_purge(dvp);
    822 	/*
    823 	 * Truncate inode.  The only stuff left
    824 	 * in the directory is "." and "..".  The
    825 	 * "." reference is inconsequential since
    826 	 * we're quashing it.  The ".." reference
    827 	 * has already been adjusted above.  We've
    828 	 * removed the "." reference and the reference
    829 	 * in the parent directory, but there may be
    830 	 * other hard links so decrement by 2 and
    831 	 * worry about them later.
    832 	 */
    833 	ip->i_e2fs_nlink -= 2;
    834 	error = ext2fs_truncate(vp, (off_t)0, IO_SYNC, cnp->cn_cred);
    835 	cache_purge(ITOV(ip));
    836 out:
    837 	VN_KNOTE(vp, NOTE_DELETE);
    838 	vput(vp);
    839 	return error;
    840 }
    841 
    842 /*
    843  * symlink -- make a symbolic link
    844  */
    845 int
    846 ext2fs_symlink(void *v)
    847 {
    848 	struct vop_symlink_v3_args /* {
    849 		struct vnode *a_dvp;
    850 		struct vnode **a_vpp;
    851 		struct componentname *a_cnp;
    852 		struct vattr *a_vap;
    853 		char *a_target;
    854 	} */ *ap = v;
    855 	struct vnode	*vp, **vpp;
    856 	struct inode	*ip;
    857 	int		len, error;
    858 
    859 	vpp = ap->a_vpp;
    860 	KASSERT(ap->a_vap->va_type == VLNK);
    861 	error = ext2fs_makeinode(ap->a_vap, ap->a_dvp, vpp, ap->a_cnp, 1);
    862 	if (error)
    863 		return error;
    864 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
    865 	vp = *vpp;
    866 	len = strlen(ap->a_target);
    867 	ip = VTOI(vp);
    868 	if (len < ip->i_ump->um_maxsymlinklen) {
    869 		memcpy(ip->i_din.e2fs_din->e2di_shortlink, ap->a_target, len);
    870 		error = ext2fs_setsize(ip, len);
    871 		if (error)
    872 			goto bad;
    873 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
    874 		if (vp->v_mount->mnt_flag & MNT_RELATIME)
    875 			ip->i_flag |= IN_ACCESS;
    876 		uvm_vnp_setsize(vp, len);
    877 	} else
    878 		error = ufs_bufio(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
    879 		    IO_NODELOCKED, ap->a_cnp->cn_cred, (size_t *)0, NULL);
    880 bad:
    881 	VOP_UNLOCK(vp);
    882 	if (error)
    883 		vrele(vp);
    884 	return error;
    885 }
    886 
    887 /*
    888  * Return target name of a symbolic link
    889  */
    890 int
    891 ext2fs_readlink(void *v)
    892 {
    893 	struct vop_readlink_args /* {
    894 		struct vnode *a_vp;
    895 		struct uio *a_uio;
    896 		kauth_cred_t a_cred;
    897 	} */ *ap = v;
    898 	struct vnode	*vp = ap->a_vp;
    899 	struct inode	*ip = VTOI(vp);
    900 	struct ufsmount	*ump = ip->i_ump;
    901 	int		isize;
    902 
    903 	isize = ext2fs_size(ip);
    904 	if (isize < ump->um_maxsymlinklen ||
    905 	    (ump->um_maxsymlinklen == 0 && ext2fs_nblock(ip) == 0)) {
    906 		uiomove(ip->i_din.e2fs_din->e2di_shortlink, isize, ap->a_uio);
    907 		return 0;
    908 	}
    909 	return UFS_BUFRD(vp, ap->a_uio, 0, ap->a_cred);
    910 }
    911 
    912 /*
    913  * Advisory record locking support
    914  */
    915 int
    916 ext2fs_advlock(void *v)
    917 {
    918 	struct vop_advlock_args /* {
    919 		struct vnode *a_vp;
    920 		void * a_id;
    921 		int  a_op;
    922 		struct flock *a_fl;
    923 		int  a_flags;
    924 	} */ *ap = v;
    925 	struct inode *ip = VTOI(ap->a_vp);
    926 
    927 	return lf_advlock(ap, &ip->i_lockf, ext2fs_size(ip));
    928 }
    929 
    930 int
    931 ext2fs_fsync(void *v)
    932 {
    933 	struct vop_fsync_args /* {
    934 		struct vnode *a_vp;
    935 		kauth_cred_t a_cred;
    936 		int a_flags;
    937 		off_t offlo;
    938 		off_t offhi;
    939 		struct proc *a_p;
    940 	} */ *ap = v;
    941 	struct vnode *vp = ap->a_vp;
    942 	int wait;
    943 	int error;
    944 
    945 	wait = (ap->a_flags & FSYNC_WAIT) != 0;
    946 
    947 	if (vp->v_type == VBLK)
    948 		error = spec_fsync(v);
    949 	else
    950 		error = vflushbuf(vp, ap->a_flags);
    951 	if (error == 0 && (ap->a_flags & FSYNC_DATAONLY) == 0)
    952 		error = ext2fs_update(vp, NULL, NULL, wait ? UPDATE_WAIT : 0);
    953 
    954 	if (error == 0 && ap->a_flags & FSYNC_CACHE) {
    955 		int l = 0;
    956 		error = VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
    957 		    curlwp->l_cred);
    958 	}
    959 
    960 	return error;
    961 }
    962 
    963 /*
    964  * Initialize the vnode associated with a new inode, handle aliased
    965  * vnodes.
    966  */
    967 int
    968 ext2fs_vinit(struct mount *mntp, int (**specops)(void *),
    969 	int (**fifoops)(void *), struct vnode **vpp)
    970 {
    971 	struct timeval tv;
    972 	struct inode *ip;
    973 	struct vnode *vp;
    974 
    975 	vp = *vpp;
    976 	ip = VTOI(vp);
    977 	switch(vp->v_type = IFTOVT(ip->i_e2fs_mode)) {
    978 	case VCHR:
    979 	case VBLK:
    980 		vp->v_op = specops;
    981 		spec_node_init(vp, fs2h32(ip->i_din.e2fs_din->e2di_rdev));
    982 		break;
    983 	case VFIFO:
    984 		vp->v_op = fifoops;
    985 		break;
    986 	case VNON:
    987 	case VBAD:
    988 	case VSOCK:
    989 	case VLNK:
    990 	case VDIR:
    991 	case VREG:
    992 		break;
    993 	}
    994 	if (ip->i_number == UFS_ROOTINO)
    995                 vp->v_vflag |= VV_ROOT;
    996 	/*
    997 	 * Initialize modrev times
    998 	 */
    999 	getmicrouptime(&tv);
   1000 	SETHIGH(ip->i_modrev, tv.tv_sec);
   1001 	SETLOW(ip->i_modrev, tv.tv_usec * 4294U);
   1002 	*vpp = vp;
   1003 	return 0;
   1004 }
   1005 
   1006 /*
   1007  * Allocate a new inode.
   1008  */
   1009 static int
   1010 ext2fs_makeinode(struct vattr *vap, struct vnode *dvp, struct vnode **vpp,
   1011 		struct componentname *cnp, int do_direnter)
   1012 {
   1013 	struct inode *ip, *pdir;
   1014 	struct vnode *tvp;
   1015 	int error;
   1016 	struct ufs_lookup_results *ulr;
   1017 
   1018 	pdir = VTOI(dvp);
   1019 
   1020 	/* XXX should handle this material another way */
   1021 	ulr = &pdir->i_crap;
   1022 	UFS_CHECK_CRAPCOUNTER(pdir);
   1023 
   1024 	*vpp = NULL;
   1025 
   1026 	error = vcache_new(dvp->v_mount, dvp, vap, cnp->cn_cred, NULL, &tvp);
   1027 	if (error)
   1028 		return error;
   1029 	error = vn_lock(tvp, LK_EXCLUSIVE);
   1030 	if (error) {
   1031 		vrele(tvp);
   1032 		return error;
   1033 	}
   1034 	ip = VTOI(tvp);
   1035 	if (do_direnter) {
   1036 		/*
   1037 		 * Make sure inode goes to disk before directory entry.
   1038 		 */
   1039 		if ((error = ext2fs_update(tvp, NULL, NULL, UPDATE_WAIT)) != 0)
   1040 			goto bad;
   1041 		error = ext2fs_direnter(ip, dvp, ulr, cnp);
   1042 		if (error != 0)
   1043 			goto bad;
   1044 	}
   1045 
   1046 	*vpp = tvp;
   1047 	cache_enter(dvp, *vpp, cnp->cn_nameptr, cnp->cn_namelen, cnp->cn_flags);
   1048 	return 0;
   1049 
   1050 bad:
   1051 	/*
   1052 	 * Write error occurred trying to update the inode
   1053 	 * or the directory so must deallocate the inode.
   1054 	 */
   1055 	ip->i_e2fs_nlink = 0;
   1056 	ip->i_flag |= IN_CHANGE;
   1057 	vput(tvp);
   1058 	return error;
   1059 }
   1060 
   1061 /*
   1062  * Reclaim an inode so that it can be used for other purposes.
   1063  */
   1064 int
   1065 ext2fs_reclaim(void *v)
   1066 {
   1067 	struct vop_reclaim_v2_args /* {
   1068 		struct vnode *a_vp;
   1069 	} */ *ap = v;
   1070 	struct vnode *vp = ap->a_vp;
   1071 	struct inode *ip = VTOI(vp);
   1072 	int error;
   1073 
   1074 	VOP_UNLOCK(vp);
   1075 
   1076 	/*
   1077 	 * The inode must be freed and updated before being removed
   1078 	 * from its hash chain.  Other threads trying to gain a hold
   1079 	 * or lock on the inode will be stalled.
   1080 	 */
   1081 	if (ip->i_omode == 1 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0)
   1082 		ext2fs_vfree(vp, ip->i_number, ip->i_e2fs_mode);
   1083 	if ((error = ufs_reclaim(vp)) != 0)
   1084 		return error;
   1085 	if (ip->i_din.e2fs_din != NULL)
   1086 		kmem_free(ip->i_din.e2fs_din, EXT2_DINODE_SIZE(ip->i_e2fs));
   1087 	genfs_node_destroy(vp);
   1088 	pool_put(&ext2fs_inode_pool, vp->v_data);
   1089 	vp->v_data = NULL;
   1090 	return 0;
   1091 }
   1092 
   1093 /* Global vfs data structures for ext2fs. */
   1094 int (**ext2fs_vnodeop_p)(void *);
   1095 const struct vnodeopv_entry_desc ext2fs_vnodeop_entries[] = {
   1096 	{ &vop_default_desc, vn_default_error },
   1097 	{ &vop_lookup_desc, ext2fs_lookup },		/* lookup */
   1098 	{ &vop_create_desc, ext2fs_create },		/* create */
   1099 	{ &vop_mknod_desc, ext2fs_mknod },		/* mknod */
   1100 	{ &vop_open_desc, ext2fs_open },		/* open */
   1101 	{ &vop_close_desc, ufs_close },			/* close */
   1102 	{ &vop_access_desc, ext2fs_access },		/* access */
   1103 	{ &vop_accessx_desc, genfs_accessx },		/* accessx */
   1104 	{ &vop_getattr_desc, ext2fs_getattr },		/* getattr */
   1105 	{ &vop_setattr_desc, ext2fs_setattr },		/* setattr */
   1106 	{ &vop_read_desc, ext2fs_read },		/* read */
   1107 	{ &vop_write_desc, ext2fs_write },		/* write */
   1108 	{ &vop_fallocate_desc, genfs_eopnotsupp },	/* fallocate */
   1109 	{ &vop_fdiscard_desc, genfs_eopnotsupp },	/* fdiscard */
   1110 	{ &vop_ioctl_desc, ufs_ioctl },			/* ioctl */
   1111 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
   1112 	{ &vop_poll_desc, ufs_poll },			/* poll */
   1113 	{ &vop_kqfilter_desc, genfs_kqfilter },		/* kqfilter */
   1114 	{ &vop_revoke_desc, ufs_revoke },		/* revoke */
   1115 	{ &vop_mmap_desc, ufs_mmap },			/* mmap */
   1116 	{ &vop_fsync_desc, ext2fs_fsync },		/* fsync */
   1117 	{ &vop_seek_desc, ufs_seek },			/* seek */
   1118 	{ &vop_remove_desc, ext2fs_remove },		/* remove */
   1119 	{ &vop_link_desc, ext2fs_link },		/* link */
   1120 	{ &vop_rename_desc, ext2fs_rename },		/* rename */
   1121 	{ &vop_mkdir_desc, ext2fs_mkdir },		/* mkdir */
   1122 	{ &vop_rmdir_desc, ext2fs_rmdir },		/* rmdir */
   1123 	{ &vop_symlink_desc, ext2fs_symlink },		/* symlink */
   1124 	{ &vop_readdir_desc, ext2fs_readdir },		/* readdir */
   1125 	{ &vop_readlink_desc, ext2fs_readlink },	/* readlink */
   1126 	{ &vop_abortop_desc, ufs_abortop },		/* abortop */
   1127 	{ &vop_inactive_desc, ext2fs_inactive },	/* inactive */
   1128 	{ &vop_reclaim_desc, ext2fs_reclaim },		/* reclaim */
   1129 	{ &vop_lock_desc, ufs_lock },			/* lock */
   1130 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
   1131 	{ &vop_bmap_desc, ext2fs_bmap },		/* bmap */
   1132 	{ &vop_strategy_desc, ufs_strategy },		/* strategy */
   1133 	{ &vop_print_desc, ufs_print },			/* print */
   1134 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
   1135 	{ &vop_pathconf_desc, ufs_pathconf },		/* pathconf */
   1136 	{ &vop_advlock_desc, ext2fs_advlock },		/* advlock */
   1137 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
   1138 	{ &vop_getpages_desc, genfs_getpages },		/* getpages */
   1139 	{ &vop_putpages_desc, genfs_putpages },		/* putpages */
   1140 	{ &vop_getextattr_desc, ext2fs_getextattr },	/* getextattr */
   1141 	{ &vop_setextattr_desc, ext2fs_setextattr },	/* setextattr */
   1142 	{ &vop_listextattr_desc, ext2fs_listextattr },	/* listextattr */
   1143 	{ &vop_deleteextattr_desc, ext2fs_deleteextattr },/* deleteextattr */
   1144 	{ NULL, NULL }
   1145 };
   1146 const struct vnodeopv_desc ext2fs_vnodeop_opv_desc =
   1147 	{ &ext2fs_vnodeop_p, ext2fs_vnodeop_entries };
   1148 
   1149 int (**ext2fs_specop_p)(void *);
   1150 const struct vnodeopv_entry_desc ext2fs_specop_entries[] = {
   1151 	{ &vop_default_desc, vn_default_error },
   1152 	{ &vop_lookup_desc, spec_lookup },		/* lookup */
   1153 	{ &vop_create_desc, spec_create },		/* create */
   1154 	{ &vop_mknod_desc, spec_mknod },		/* mknod */
   1155 	{ &vop_open_desc, spec_open },			/* open */
   1156 	{ &vop_close_desc, ufsspec_close },		/* close */
   1157 	{ &vop_access_desc, ext2fs_access },		/* access */
   1158 	{ &vop_accessx_desc, genfs_accessx },		/* accessx */
   1159 	{ &vop_getattr_desc, ext2fs_getattr },		/* getattr */
   1160 	{ &vop_setattr_desc, ext2fs_setattr },		/* setattr */
   1161 	{ &vop_read_desc, ufsspec_read },		/* read */
   1162 	{ &vop_write_desc, ufsspec_write },		/* write */
   1163 	{ &vop_fallocate_desc, spec_fallocate },	/* fallocate */
   1164 	{ &vop_fdiscard_desc, spec_fdiscard },		/* fdiscard */
   1165 	{ &vop_ioctl_desc, spec_ioctl },		/* ioctl */
   1166 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
   1167 	{ &vop_poll_desc, spec_poll },			/* poll */
   1168 	{ &vop_kqfilter_desc, spec_kqfilter },		/* kqfilter */
   1169 	{ &vop_revoke_desc, spec_revoke },		/* revoke */
   1170 	{ &vop_mmap_desc, spec_mmap },			/* mmap */
   1171 	{ &vop_fsync_desc, ext2fs_fsync },		/* fsync */
   1172 	{ &vop_seek_desc, spec_seek },			/* seek */
   1173 	{ &vop_remove_desc, spec_remove },		/* remove */
   1174 	{ &vop_link_desc, spec_link },			/* link */
   1175 	{ &vop_rename_desc, spec_rename },		/* rename */
   1176 	{ &vop_mkdir_desc, spec_mkdir },		/* mkdir */
   1177 	{ &vop_rmdir_desc, spec_rmdir },		/* rmdir */
   1178 	{ &vop_symlink_desc, spec_symlink },		/* symlink */
   1179 	{ &vop_readdir_desc, spec_readdir },		/* readdir */
   1180 	{ &vop_readlink_desc, spec_readlink },		/* readlink */
   1181 	{ &vop_abortop_desc, spec_abortop },		/* abortop */
   1182 	{ &vop_inactive_desc, ext2fs_inactive },	/* inactive */
   1183 	{ &vop_reclaim_desc, ext2fs_reclaim },		/* reclaim */
   1184 	{ &vop_lock_desc, ufs_lock },			/* lock */
   1185 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
   1186 	{ &vop_bmap_desc, spec_bmap },			/* bmap */
   1187 	{ &vop_strategy_desc, spec_strategy },		/* strategy */
   1188 	{ &vop_print_desc, ufs_print },			/* print */
   1189 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
   1190 	{ &vop_pathconf_desc, spec_pathconf },		/* pathconf */
   1191 	{ &vop_advlock_desc, spec_advlock },		/* advlock */
   1192 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
   1193 	{ &vop_getpages_desc, spec_getpages },		/* getpages */
   1194 	{ &vop_putpages_desc, spec_putpages },		/* putpages */
   1195 	{ &vop_getextattr_desc, ext2fs_getextattr },	/* getextattr */
   1196 	{ &vop_setextattr_desc, ext2fs_setextattr },	/* setextattr */
   1197 	{ &vop_listextattr_desc, ext2fs_listextattr },	/* listextattr */
   1198 	{ &vop_deleteextattr_desc, ext2fs_deleteextattr },/* deleteextattr */
   1199 	{ NULL, NULL }
   1200 };
   1201 const struct vnodeopv_desc ext2fs_specop_opv_desc =
   1202 	{ &ext2fs_specop_p, ext2fs_specop_entries };
   1203 
   1204 int (**ext2fs_fifoop_p)(void *);
   1205 const struct vnodeopv_entry_desc ext2fs_fifoop_entries[] = {
   1206 	{ &vop_default_desc, vn_default_error },
   1207 	{ &vop_lookup_desc, vn_fifo_bypass },		/* lookup */
   1208 	{ &vop_create_desc, vn_fifo_bypass },		/* create */
   1209 	{ &vop_mknod_desc, vn_fifo_bypass },		/* mknod */
   1210 	{ &vop_open_desc, vn_fifo_bypass },		/* open */
   1211 	{ &vop_close_desc, ufsfifo_close },		/* close */
   1212 	{ &vop_access_desc, ext2fs_access },		/* access */
   1213 	{ &vop_accessx_desc, genfs_accessx },		/* accessx */
   1214 	{ &vop_getattr_desc, ext2fs_getattr },		/* getattr */
   1215 	{ &vop_setattr_desc, ext2fs_setattr },		/* setattr */
   1216 	{ &vop_read_desc, ufsfifo_read },		/* read */
   1217 	{ &vop_write_desc, ufsfifo_write },		/* write */
   1218 	{ &vop_fallocate_desc, vn_fifo_bypass },	/* fallocate */
   1219 	{ &vop_fdiscard_desc, vn_fifo_bypass },		/* fdiscard */
   1220 	{ &vop_ioctl_desc, vn_fifo_bypass },		/* ioctl */
   1221 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
   1222 	{ &vop_poll_desc, vn_fifo_bypass },		/* poll */
   1223 	{ &vop_kqfilter_desc, vn_fifo_bypass },		/* kqfilter */
   1224 	{ &vop_revoke_desc, vn_fifo_bypass },		/* revoke */
   1225 	{ &vop_mmap_desc, vn_fifo_bypass },		/* mmap */
   1226 	{ &vop_fsync_desc, ext2fs_fsync },		/* fsync */
   1227 	{ &vop_seek_desc, vn_fifo_bypass },		/* seek */
   1228 	{ &vop_remove_desc, vn_fifo_bypass },		/* remove */
   1229 	{ &vop_link_desc, vn_fifo_bypass },		/* link */
   1230 	{ &vop_rename_desc, vn_fifo_bypass },		/* rename */
   1231 	{ &vop_mkdir_desc, vn_fifo_bypass },		/* mkdir */
   1232 	{ &vop_rmdir_desc, vn_fifo_bypass },		/* rmdir */
   1233 	{ &vop_symlink_desc, vn_fifo_bypass },		/* symlink */
   1234 	{ &vop_readdir_desc, vn_fifo_bypass },		/* readdir */
   1235 	{ &vop_readlink_desc, vn_fifo_bypass },		/* readlink */
   1236 	{ &vop_abortop_desc, vn_fifo_bypass },		/* abortop */
   1237 	{ &vop_inactive_desc, ext2fs_inactive },	/* inactive */
   1238 	{ &vop_reclaim_desc, ext2fs_reclaim },		/* reclaim */
   1239 	{ &vop_lock_desc, ufs_lock },			/* lock */
   1240 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
   1241 	{ &vop_bmap_desc, vn_fifo_bypass },		/* bmap */
   1242 	{ &vop_strategy_desc, vn_fifo_bypass },		/* strategy */
   1243 	{ &vop_print_desc, ufs_print },			/* print */
   1244 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
   1245 	{ &vop_pathconf_desc, vn_fifo_bypass },		/* pathconf */
   1246 	{ &vop_advlock_desc, vn_fifo_bypass },		/* advlock */
   1247 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
   1248 	{ &vop_putpages_desc, vn_fifo_bypass },		/* putpages */
   1249 	{ &vop_getextattr_desc, ext2fs_getextattr },	/* getextattr */
   1250 	{ &vop_setextattr_desc, ext2fs_setextattr },	/* setextattr */
   1251 	{ &vop_listextattr_desc, ext2fs_listextattr },	/* listextattr */
   1252 	{ &vop_deleteextattr_desc, ext2fs_deleteextattr },/* deleteextattr */
   1253 	{ NULL, NULL }
   1254 };
   1255 const struct vnodeopv_desc ext2fs_fifoop_opv_desc =
   1256 	{ &ext2fs_fifoop_p, ext2fs_fifoop_entries };
   1257