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