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