Home | History | Annotate | Line # | Download | only in ext2fs
ext2fs_vnops.c revision 1.64
      1  1.64  christos /*	$NetBSD: ext2fs_vnops.c,v 1.64 2005/12/11 12:25:25 christos 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  * 3. All advertising materials mentioning features or use of this software
     52   1.1    bouyer  *    must display the following acknowledgement:
     53  1.51    bouyer  *	This product includes software developed by Manuel Bouyer.
     54  1.51    bouyer  * 4. The name of the author may not be used to endorse or promote products
     55  1.51    bouyer  *    derived from this software without specific prior written permission.
     56   1.1    bouyer  *
     57  1.52    bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     58  1.52    bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59  1.52    bouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60  1.52    bouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     61  1.52    bouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     62  1.52    bouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     63  1.52    bouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     64  1.52    bouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     65  1.52    bouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     66  1.52    bouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67   1.1    bouyer  *
     68   1.1    bouyer  *	@(#)ufs_vnops.c	8.14 (Berkeley) 10/26/94
     69   1.1    bouyer  * Modified for ext2fs by Manuel Bouyer.
     70   1.1    bouyer  */
     71  1.40     lukem 
     72  1.40     lukem #include <sys/cdefs.h>
     73  1.64  christos __KERNEL_RCSID(0, "$NetBSD: ext2fs_vnops.c,v 1.64 2005/12/11 12:25:25 christos Exp $");
     74   1.7       mrg 
     75   1.1    bouyer #include <sys/param.h>
     76   1.1    bouyer #include <sys/systm.h>
     77   1.1    bouyer #include <sys/resourcevar.h>
     78   1.1    bouyer #include <sys/kernel.h>
     79   1.1    bouyer #include <sys/file.h>
     80   1.1    bouyer #include <sys/stat.h>
     81   1.1    bouyer #include <sys/buf.h>
     82   1.1    bouyer #include <sys/proc.h>
     83   1.1    bouyer #include <sys/mount.h>
     84   1.1    bouyer #include <sys/namei.h>
     85   1.1    bouyer #include <sys/vnode.h>
     86   1.1    bouyer #include <sys/lockf.h>
     87   1.1    bouyer #include <sys/malloc.h>
     88  1.14   thorpej #include <sys/pool.h>
     89   1.1    bouyer #include <sys/signalvar.h>
     90   1.1    bouyer 
     91   1.1    bouyer #include <miscfs/fifofs/fifo.h>
     92   1.1    bouyer #include <miscfs/genfs/genfs.h>
     93   1.1    bouyer #include <miscfs/specfs/specdev.h>
     94   1.1    bouyer 
     95   1.1    bouyer #include <ufs/ufs/inode.h>
     96   1.1    bouyer #include <ufs/ufs/ufs_extern.h>
     97   1.1    bouyer #include <ufs/ufs/ufsmount.h>
     98   1.1    bouyer 
     99   1.1    bouyer #include <ufs/ext2fs/ext2fs.h>
    100   1.1    bouyer #include <ufs/ext2fs/ext2fs_extern.h>
    101   1.1    bouyer #include <ufs/ext2fs/ext2fs_dir.h>
    102   1.1    bouyer 
    103  1.32   tsutsui extern int prtactive;
    104   1.1    bouyer 
    105  1.61   xtraeme static int ext2fs_chmod(struct vnode *, int, struct ucred *, struct proc *);
    106  1.61   xtraeme static int ext2fs_chown(struct vnode *, uid_t, gid_t, struct ucred *,
    107  1.61   xtraeme 				struct proc *);
    108   1.1    bouyer 
    109   1.1    bouyer union _qcvt {
    110   1.1    bouyer 	int64_t	qcvt;
    111   1.1    bouyer 	int32_t val[2];
    112   1.1    bouyer };
    113  1.61   xtraeme 
    114   1.1    bouyer #define SETHIGH(q, h) { \
    115   1.1    bouyer 	union _qcvt tmp; \
    116   1.1    bouyer 	tmp.qcvt = (q); \
    117   1.1    bouyer 	tmp.val[_QUAD_HIGHWORD] = (h); \
    118   1.1    bouyer 	(q) = tmp.qcvt; \
    119   1.1    bouyer }
    120   1.1    bouyer #define SETLOW(q, l) { \
    121   1.1    bouyer 	union _qcvt tmp; \
    122   1.1    bouyer 	tmp.qcvt = (q); \
    123   1.1    bouyer 	tmp.val[_QUAD_LOWWORD] = (l); \
    124   1.1    bouyer 	(q) = tmp.qcvt; \
    125   1.1    bouyer }
    126   1.1    bouyer 
    127   1.1    bouyer /*
    128   1.1    bouyer  * Create a regular file
    129   1.1    bouyer  */
    130   1.1    bouyer int
    131  1.61   xtraeme ext2fs_create(void *v)
    132   1.1    bouyer {
    133   1.1    bouyer 	struct vop_create_args /* {
    134   1.1    bouyer 		struct vnode *a_dvp;
    135   1.1    bouyer 		struct vnode **a_vpp;
    136   1.1    bouyer 		struct componentname *a_cnp;
    137   1.1    bouyer 		struct vattr *a_vap;
    138   1.1    bouyer 	} */ *ap = v;
    139  1.42  jdolecek 	int	error;
    140  1.42  jdolecek 
    141  1.42  jdolecek 	error =
    142  1.42  jdolecek 	    ext2fs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
    143  1.42  jdolecek 			     ap->a_dvp, ap->a_vpp, ap->a_cnp);
    144  1.42  jdolecek 
    145  1.42  jdolecek 	if (error)
    146  1.42  jdolecek 		return (error);
    147  1.42  jdolecek 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
    148  1.42  jdolecek 	return (0);
    149   1.1    bouyer }
    150   1.1    bouyer 
    151   1.1    bouyer /*
    152   1.1    bouyer  * Mknod vnode call
    153   1.1    bouyer  */
    154   1.1    bouyer /* ARGSUSED */
    155   1.1    bouyer int
    156  1.61   xtraeme ext2fs_mknod(void *v)
    157   1.1    bouyer {
    158   1.1    bouyer 	struct vop_mknod_args /* {
    159   1.1    bouyer 		struct vnode *a_dvp;
    160   1.1    bouyer 		struct vnode **a_vpp;
    161   1.1    bouyer 		struct componentname *a_cnp;
    162   1.1    bouyer 		struct vattr *a_vap;
    163   1.1    bouyer 	} */ *ap = v;
    164  1.25  augustss 	struct vattr *vap = ap->a_vap;
    165  1.25  augustss 	struct vnode **vpp = ap->a_vpp;
    166  1.25  augustss 	struct inode *ip;
    167   1.1    bouyer 	int error;
    168  1.59     perry 	struct mount	*mp;
    169  1.34     assar 	ino_t		ino;
    170   1.1    bouyer 
    171   1.8      fvdl 	if ((error = ext2fs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
    172   1.8      fvdl 		    ap->a_dvp, vpp, ap->a_cnp)) != 0)
    173   1.1    bouyer 		return (error);
    174  1.42  jdolecek 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
    175   1.1    bouyer 	ip = VTOI(*vpp);
    176  1.34     assar 	mp  = (*vpp)->v_mount;
    177  1.34     assar 	ino = ip->i_number;
    178   1.1    bouyer 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
    179   1.1    bouyer 	if (vap->va_rdev != VNOVAL) {
    180   1.1    bouyer 		/*
    181   1.1    bouyer 		 * Want to be able to use this to make badblock
    182   1.1    bouyer 		 * inodes, so don't truncate the dev number.
    183   1.1    bouyer 		 */
    184  1.44      fvdl 		ip->i_din.e2fs_din->e2di_rdev = h2fs32(vap->va_rdev);
    185   1.1    bouyer 	}
    186   1.1    bouyer 	/*
    187   1.1    bouyer 	 * Remove inode so that it will be reloaded by VFS_VGET and
    188   1.1    bouyer 	 * checked to see if it is an alias of an existing entry in
    189   1.1    bouyer 	 * the inode cache.
    190   1.1    bouyer 	 */
    191   1.1    bouyer 	vput(*vpp);
    192   1.1    bouyer 	(*vpp)->v_type = VNON;
    193   1.1    bouyer 	vgone(*vpp);
    194  1.47   thorpej 	error = VFS_VGET(mp, ino, vpp);
    195  1.34     assar 	if (error != 0) {
    196  1.34     assar 		*vpp = NULL;
    197  1.34     assar 		return (error);
    198  1.34     assar 	}
    199   1.1    bouyer 	return (0);
    200   1.1    bouyer }
    201   1.1    bouyer 
    202   1.1    bouyer /*
    203   1.1    bouyer  * Open called.
    204   1.1    bouyer  *
    205   1.1    bouyer  * Just check the APPEND flag.
    206   1.1    bouyer  */
    207   1.1    bouyer /* ARGSUSED */
    208   1.1    bouyer int
    209  1.61   xtraeme ext2fs_open(void *v)
    210   1.1    bouyer {
    211   1.1    bouyer 	struct vop_open_args /* {
    212   1.1    bouyer 		struct vnode *a_vp;
    213   1.1    bouyer 		int  a_mode;
    214   1.1    bouyer 		struct ucred *a_cred;
    215  1.64  christos 		struct lwp *a_l;
    216   1.1    bouyer 	} */ *ap = v;
    217   1.1    bouyer 
    218   1.1    bouyer 	/*
    219   1.1    bouyer 	 * Files marked append-only must be opened for appending.
    220   1.1    bouyer 	 */
    221   1.1    bouyer 	if ((VTOI(ap->a_vp)->i_e2fs_flags & EXT2_APPEND) &&
    222   1.1    bouyer 		(ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
    223   1.1    bouyer 		return (EPERM);
    224   1.1    bouyer 	return (0);
    225   1.1    bouyer }
    226   1.1    bouyer 
    227   1.1    bouyer int
    228  1.61   xtraeme ext2fs_access(void *v)
    229   1.1    bouyer {
    230   1.1    bouyer 	struct vop_access_args /* {
    231   1.1    bouyer 		struct vnode *a_vp;
    232   1.1    bouyer 		int  a_mode;
    233   1.1    bouyer 		struct ucred *a_cred;
    234  1.64  christos 		struct lwp *a_l;
    235   1.1    bouyer 	} */ *ap = v;
    236   1.8      fvdl 	struct vnode *vp = ap->a_vp;
    237   1.8      fvdl 	struct inode *ip = VTOI(vp);
    238   1.1    bouyer 	mode_t mode = ap->a_mode;
    239   1.1    bouyer 
    240   1.8      fvdl 	/*
    241   1.8      fvdl 	 * Disallow write attempts on read-only file systems;
    242   1.8      fvdl 	 * unless the file is a socket, fifo, or a block or
    243   1.8      fvdl 	 * character device resident on the file system.
    244   1.8      fvdl 	 */
    245   1.8      fvdl 	if (mode & VWRITE) {
    246   1.8      fvdl 		switch (vp->v_type) {
    247   1.8      fvdl 		case VDIR:
    248   1.8      fvdl 		case VLNK:
    249   1.8      fvdl 		case VREG:
    250   1.8      fvdl 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
    251   1.8      fvdl 				return (EROFS);
    252   1.8      fvdl 			break;
    253   1.8      fvdl 		default:
    254   1.8      fvdl 			break;
    255   1.8      fvdl 		}
    256   1.1    bouyer 	}
    257   1.1    bouyer 
    258   1.1    bouyer 	/* If immutable bit set, nobody gets to write it. */
    259   1.1    bouyer 	if ((mode & VWRITE) && (ip->i_e2fs_flags & EXT2_IMMUTABLE))
    260   1.1    bouyer 		return (EPERM);
    261   1.1    bouyer 
    262   1.1    bouyer 	return (vaccess(vp->v_type, ip->i_e2fs_mode & ALLPERMS,
    263   1.1    bouyer 			ip->i_e2fs_uid, ip->i_e2fs_gid, mode, ap->a_cred));
    264   1.1    bouyer }
    265   1.1    bouyer 
    266   1.1    bouyer /* ARGSUSED */
    267   1.1    bouyer int
    268  1.61   xtraeme ext2fs_getattr(void *v)
    269   1.1    bouyer {
    270   1.1    bouyer 	struct vop_getattr_args /* {
    271   1.1    bouyer 		struct vnode *a_vp;
    272   1.1    bouyer 		struct vattr *a_vap;
    273   1.1    bouyer 		struct ucred *a_cred;
    274  1.64  christos 		struct lwp *a_l;
    275   1.1    bouyer 	} */ *ap = v;
    276  1.25  augustss 	struct vnode *vp = ap->a_vp;
    277  1.25  augustss 	struct inode *ip = VTOI(vp);
    278  1.25  augustss 	struct vattr *vap = ap->a_vap;
    279   1.1    bouyer 
    280  1.62  christos 	EXT2FS_ITIMES(ip, NULL, NULL, NULL);
    281   1.1    bouyer 	/*
    282   1.1    bouyer 	 * Copy from inode table
    283   1.1    bouyer 	 */
    284   1.1    bouyer 	vap->va_fsid = ip->i_dev;
    285   1.1    bouyer 	vap->va_fileid = ip->i_number;
    286   1.1    bouyer 	vap->va_mode = ip->i_e2fs_mode & ALLPERMS;
    287   1.1    bouyer 	vap->va_nlink = ip->i_e2fs_nlink;
    288   1.1    bouyer 	vap->va_uid = ip->i_e2fs_uid;
    289   1.1    bouyer 	vap->va_gid = ip->i_e2fs_gid;
    290  1.44      fvdl 	vap->va_rdev = (dev_t)fs2h32(ip->i_din.e2fs_din->e2di_rdev);
    291  1.37       chs 	vap->va_size = vp->v_size;
    292   1.1    bouyer 	vap->va_atime.tv_sec = ip->i_e2fs_atime;
    293   1.1    bouyer 	vap->va_atime.tv_nsec = 0;
    294   1.1    bouyer 	vap->va_mtime.tv_sec = ip->i_e2fs_mtime;
    295   1.1    bouyer 	vap->va_mtime.tv_nsec = 0;
    296   1.1    bouyer 	vap->va_ctime.tv_sec = ip->i_e2fs_ctime;
    297   1.1    bouyer 	vap->va_ctime.tv_nsec = 0;
    298   1.1    bouyer #ifdef EXT2FS_SYSTEM_FLAGS
    299   1.1    bouyer 	vap->va_flags = (ip->i_e2fs_flags & EXT2_APPEND) ? SF_APPEND : 0;
    300   1.1    bouyer 	vap->va_flags |= (ip->i_e2fs_flags & EXT2_IMMUTABLE) ? SF_IMMUTABLE : 0;
    301   1.1    bouyer #else
    302   1.1    bouyer 	vap->va_flags = (ip->i_e2fs_flags & EXT2_APPEND) ? UF_APPEND : 0;
    303   1.1    bouyer 	vap->va_flags |= (ip->i_e2fs_flags & EXT2_IMMUTABLE) ? UF_IMMUTABLE : 0;
    304   1.1    bouyer #endif
    305   1.1    bouyer 	vap->va_gen = ip->i_e2fs_gen;
    306   1.1    bouyer 	/* this doesn't belong here */
    307   1.1    bouyer 	if (vp->v_type == VBLK)
    308   1.1    bouyer 		vap->va_blocksize = BLKDEV_IOSIZE;
    309   1.1    bouyer 	else if (vp->v_type == VCHR)
    310   1.1    bouyer 		vap->va_blocksize = MAXBSIZE;
    311   1.1    bouyer 	else
    312   1.1    bouyer 		vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
    313   1.8      fvdl 	vap->va_bytes = dbtob((u_quad_t)ip->i_e2fs_nblock);
    314   1.1    bouyer 	vap->va_type = vp->v_type;
    315   1.1    bouyer 	vap->va_filerev = ip->i_modrev;
    316   1.1    bouyer 	return (0);
    317   1.1    bouyer }
    318   1.1    bouyer 
    319   1.1    bouyer /*
    320   1.1    bouyer  * Set attribute vnode op. called from several syscalls
    321   1.1    bouyer  */
    322   1.1    bouyer int
    323  1.61   xtraeme ext2fs_setattr(void *v)
    324   1.1    bouyer {
    325   1.1    bouyer 	struct vop_setattr_args /* {
    326   1.1    bouyer 		struct vnode *a_vp;
    327   1.1    bouyer 		struct vattr *a_vap;
    328   1.1    bouyer 		struct ucred *a_cred;
    329  1.64  christos 		struct lwp *a_l;
    330   1.1    bouyer 	} */ *ap = v;
    331   1.8      fvdl 	struct vattr *vap = ap->a_vap;
    332   1.8      fvdl 	struct vnode *vp = ap->a_vp;
    333   1.8      fvdl 	struct inode *ip = VTOI(vp);
    334   1.8      fvdl 	struct ucred *cred = ap->a_cred;
    335  1.64  christos 	struct lwp *l = ap->a_l;
    336   1.1    bouyer 	int error;
    337   1.1    bouyer 
    338   1.1    bouyer 	/*
    339   1.1    bouyer 	 * Check for unsettable attributes.
    340   1.1    bouyer 	 */
    341   1.5  christos 	if ((vap->va_type != VNON) || (vap->va_nlink != (nlink_t)VNOVAL) ||
    342  1.24   thorpej 	    (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
    343  1.24   thorpej 	    (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
    344  1.24   thorpej 	    ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
    345   1.1    bouyer 		return (EINVAL);
    346   1.1    bouyer 	}
    347   1.1    bouyer 	if (vap->va_flags != VNOVAL) {
    348   1.8      fvdl 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
    349   1.8      fvdl 			return (EROFS);
    350   1.1    bouyer 		if (cred->cr_uid != ip->i_e2fs_uid &&
    351  1.64  christos 			(error = suser(cred, &l->l_proc->p_acflag)))
    352   1.1    bouyer 			return (error);
    353   1.1    bouyer #ifdef EXT2FS_SYSTEM_FLAGS
    354   1.1    bouyer 		if (cred->cr_uid == 0) {
    355  1.24   thorpej 			if ((ip->i_e2fs_flags &
    356  1.24   thorpej 			    (EXT2_APPEND | EXT2_IMMUTABLE)) && securelevel > 0)
    357   1.1    bouyer 				return (EPERM);
    358   1.1    bouyer 			ip->i_e2fs_flags &= ~(EXT2_APPEND | EXT2_IMMUTABLE);
    359  1.24   thorpej 			ip->i_e2fs_flags |=
    360  1.24   thorpej 			    (vap->va_flags & SF_APPEND) ?  EXT2_APPEND : 0 |
    361  1.24   thorpej 			    (vap->va_flags & SF_IMMUTABLE) ? EXT2_IMMUTABLE : 0;
    362  1.24   thorpej 		} else
    363   1.1    bouyer 			return (EPERM);
    364   1.1    bouyer #else
    365   1.1    bouyer 		ip->i_e2fs_flags &= ~(EXT2_APPEND | EXT2_IMMUTABLE);
    366  1.24   thorpej 		ip->i_e2fs_flags |=
    367  1.24   thorpej 		    (vap->va_flags & UF_APPEND) ? EXT2_APPEND : 0 |
    368  1.24   thorpej 		    (vap->va_flags & UF_IMMUTABLE) ? EXT2_IMMUTABLE : 0;
    369   1.1    bouyer #endif
    370   1.1    bouyer 		ip->i_flag |= IN_CHANGE;
    371   1.1    bouyer 		if (vap->va_flags & (IMMUTABLE | APPEND))
    372   1.1    bouyer 			return (0);
    373   1.1    bouyer 	}
    374   1.1    bouyer 	if (ip->i_e2fs_flags & (EXT2_APPEND | EXT2_IMMUTABLE))
    375   1.1    bouyer 		return (EPERM);
    376   1.1    bouyer 	/*
    377   1.1    bouyer 	 * Go through the fields and update iff not VNOVAL.
    378   1.1    bouyer 	 */
    379   1.1    bouyer 	if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
    380   1.8      fvdl 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
    381   1.8      fvdl 			return (EROFS);
    382  1.64  christos 		error = ext2fs_chown(vp, vap->va_uid, vap->va_gid, cred, l->l_proc);
    383   1.1    bouyer 		if (error)
    384   1.1    bouyer 			return (error);
    385   1.1    bouyer 	}
    386   1.1    bouyer 	if (vap->va_size != VNOVAL) {
    387   1.8      fvdl 		/*
    388   1.8      fvdl 		 * Disallow write attempts on read-only file systems;
    389   1.8      fvdl 		 * unless the file is a socket, fifo, or a block or
    390   1.8      fvdl 		 * character device resident on the file system.
    391   1.8      fvdl 		 */
    392   1.8      fvdl 		switch (vp->v_type) {
    393   1.8      fvdl 		case VDIR:
    394   1.1    bouyer 			return (EISDIR);
    395   1.8      fvdl 		case VLNK:
    396   1.8      fvdl 		case VREG:
    397   1.8      fvdl 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
    398   1.8      fvdl 				return (EROFS);
    399   1.8      fvdl 		default:
    400   1.8      fvdl 			break;
    401   1.8      fvdl 		}
    402  1.64  christos 		error = ext2fs_truncate(vp, vap->va_size, 0, cred, l->l_proc);
    403   1.1    bouyer 		if (error)
    404   1.1    bouyer 			return (error);
    405   1.1    bouyer 	}
    406   1.1    bouyer 	ip = VTOI(vp);
    407   1.1    bouyer 	if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
    408   1.8      fvdl 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
    409   1.8      fvdl 			return (EROFS);
    410   1.1    bouyer 		if (cred->cr_uid != ip->i_e2fs_uid &&
    411  1.64  christos 			(error = suser(cred, &l->l_proc->p_acflag)) &&
    412  1.59     perry 			((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
    413  1.64  christos 			(error = VOP_ACCESS(vp, VWRITE, cred, l))))
    414   1.1    bouyer 			return (error);
    415   1.1    bouyer 		if (vap->va_atime.tv_sec != VNOVAL)
    416   1.1    bouyer 			if (!(vp->v_mount->mnt_flag & MNT_NOATIME))
    417   1.1    bouyer 				ip->i_flag |= IN_ACCESS;
    418   1.1    bouyer 		if (vap->va_mtime.tv_sec != VNOVAL)
    419   1.1    bouyer 			ip->i_flag |= IN_CHANGE | IN_UPDATE;
    420  1.63      yamt 		error = ext2fs_update(vp, &vap->va_atime, &vap->va_mtime,
    421  1.26  perseant 			UPDATE_WAIT);
    422   1.1    bouyer 		if (error)
    423   1.1    bouyer 			return (error);
    424   1.1    bouyer 	}
    425   1.1    bouyer 	error = 0;
    426   1.8      fvdl 	if (vap->va_mode != (mode_t)VNOVAL) {
    427   1.8      fvdl 		if (vp->v_mount->mnt_flag & MNT_RDONLY)
    428   1.8      fvdl 			return (EROFS);
    429  1.64  christos 		error = ext2fs_chmod(vp, (int)vap->va_mode, cred, l->l_proc);
    430   1.8      fvdl 	}
    431  1.42  jdolecek 	VN_KNOTE(vp, NOTE_ATTRIB);
    432   1.1    bouyer 	return (error);
    433   1.1    bouyer }
    434   1.1    bouyer 
    435   1.1    bouyer /*
    436   1.1    bouyer  * Change the mode on a file.
    437   1.1    bouyer  * Inode must be locked before calling.
    438   1.1    bouyer  */
    439   1.1    bouyer static int
    440  1.61   xtraeme ext2fs_chmod(struct vnode *vp, int mode, struct ucred *cred, struct proc *p)
    441   1.1    bouyer {
    442  1.25  augustss 	struct inode *ip = VTOI(vp);
    443   1.1    bouyer 	int error;
    444   1.1    bouyer 
    445   1.1    bouyer 	if (cred->cr_uid != ip->i_e2fs_uid &&
    446   1.1    bouyer 		(error = suser(cred, &p->p_acflag)))
    447   1.1    bouyer 		return (error);
    448   1.1    bouyer 	if (cred->cr_uid) {
    449   1.1    bouyer 		if (vp->v_type != VDIR && (mode & S_ISTXT))
    450   1.1    bouyer 			return (EFTYPE);
    451   1.1    bouyer 		if (!groupmember(ip->i_e2fs_gid, cred) && (mode & ISGID))
    452   1.1    bouyer 			return (EPERM);
    453   1.1    bouyer 	}
    454   1.1    bouyer 	ip->i_e2fs_mode &= ~ALLPERMS;
    455   1.1    bouyer 	ip->i_e2fs_mode |= (mode & ALLPERMS);
    456   1.1    bouyer 	ip->i_flag |= IN_CHANGE;
    457   1.1    bouyer 	return (0);
    458   1.1    bouyer }
    459   1.1    bouyer 
    460   1.1    bouyer /*
    461   1.1    bouyer  * Perform chown operation on inode ip;
    462   1.1    bouyer  * inode must be locked prior to call.
    463   1.1    bouyer  */
    464   1.1    bouyer static int
    465  1.61   xtraeme ext2fs_chown(struct vnode *vp, uid_t uid, gid_t gid, struct ucred *cred,
    466  1.61   xtraeme 		struct proc *p)
    467   1.1    bouyer {
    468  1.25  augustss 	struct inode *ip = VTOI(vp);
    469   1.1    bouyer 	uid_t ouid;
    470   1.1    bouyer 	gid_t ogid;
    471   1.1    bouyer 	int error = 0;
    472   1.1    bouyer 
    473   1.1    bouyer 	if (uid == (uid_t)VNOVAL)
    474   1.1    bouyer 		uid = ip->i_e2fs_uid;
    475   1.1    bouyer 	if (gid == (gid_t)VNOVAL)
    476   1.1    bouyer 		gid = ip->i_e2fs_gid;
    477   1.1    bouyer 	/*
    478   1.1    bouyer 	 * If we don't own the file, are trying to change the owner
    479   1.1    bouyer 	 * of the file, or are not a member of the target group,
    480   1.1    bouyer 	 * the caller must be superuser or the call fails.
    481   1.1    bouyer 	 */
    482   1.1    bouyer 	if ((cred->cr_uid != ip->i_e2fs_uid || uid != ip->i_e2fs_uid ||
    483  1.53    kleink 		(gid != ip->i_e2fs_gid &&
    484  1.53    kleink 		 !(cred->cr_gid == gid || groupmember((gid_t)gid, cred)))) &&
    485   1.1    bouyer 		(error = suser(cred, &p->p_acflag)))
    486   1.1    bouyer 		return (error);
    487   1.1    bouyer 	ogid = ip->i_e2fs_gid;
    488   1.1    bouyer 	ouid = ip->i_e2fs_uid;
    489   1.1    bouyer 
    490   1.1    bouyer 	ip->i_e2fs_gid = gid;
    491   1.1    bouyer 	ip->i_e2fs_uid = uid;
    492   1.1    bouyer 	if (ouid != uid || ogid != gid)
    493   1.1    bouyer 		ip->i_flag |= IN_CHANGE;
    494   1.1    bouyer 	if (ouid != uid && cred->cr_uid != 0)
    495   1.1    bouyer 		ip->i_e2fs_mode &= ~ISUID;
    496   1.1    bouyer 	if (ogid != gid && cred->cr_uid != 0)
    497   1.1    bouyer 		ip->i_e2fs_mode &= ~ISGID;
    498   1.1    bouyer 	return (0);
    499   1.1    bouyer }
    500   1.1    bouyer 
    501   1.1    bouyer int
    502  1.61   xtraeme ext2fs_remove(void *v)
    503   1.1    bouyer {
    504   1.1    bouyer 	struct vop_remove_args /* {
    505   1.1    bouyer 		struct vnode *a_dvp;
    506   1.1    bouyer 		struct vnode *a_vp;
    507   1.1    bouyer 		struct componentname *a_cnp;
    508   1.1    bouyer 	} */ *ap = v;
    509   1.8      fvdl 	struct inode *ip;
    510   1.8      fvdl 	struct vnode *vp = ap->a_vp;
    511   1.8      fvdl 	struct vnode *dvp = ap->a_dvp;
    512   1.1    bouyer 	int error;
    513   1.1    bouyer 
    514   1.1    bouyer 	ip = VTOI(vp);
    515   1.2      fvdl 	if (vp->v_type == VDIR ||
    516   1.2      fvdl 		(ip->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND)) ||
    517   1.1    bouyer 		(VTOI(dvp)->i_e2fs_flags & EXT2_APPEND)) {
    518   1.1    bouyer 		error = EPERM;
    519  1.43  jdolecek 	} else {
    520  1.43  jdolecek 		error = ext2fs_dirremove(dvp, ap->a_cnp);
    521  1.43  jdolecek 		if (error == 0) {
    522  1.43  jdolecek 			ip->i_e2fs_nlink--;
    523  1.43  jdolecek 			ip->i_flag |= IN_CHANGE;
    524  1.43  jdolecek 		}
    525   1.1    bouyer 	}
    526  1.43  jdolecek 
    527  1.42  jdolecek 	VN_KNOTE(vp, NOTE_DELETE);
    528  1.42  jdolecek 	VN_KNOTE(dvp, NOTE_WRITE);
    529   1.1    bouyer 	if (dvp == vp)
    530   1.1    bouyer 		vrele(vp);
    531   1.1    bouyer 	else
    532   1.1    bouyer 		vput(vp);
    533   1.1    bouyer 	vput(dvp);
    534   1.1    bouyer 	return (error);
    535   1.1    bouyer }
    536   1.1    bouyer 
    537   1.1    bouyer /*
    538   1.1    bouyer  * link vnode call
    539   1.1    bouyer  */
    540   1.1    bouyer int
    541  1.61   xtraeme ext2fs_link(void *v)
    542   1.1    bouyer {
    543   1.1    bouyer 	struct vop_link_args /* {
    544   1.1    bouyer 		struct vnode *a_dvp;
    545   1.1    bouyer 		struct vnode *a_vp;
    546   1.1    bouyer 		struct componentname *a_cnp;
    547   1.1    bouyer 	} */ *ap = v;
    548   1.8      fvdl 	struct vnode *dvp = ap->a_dvp;
    549   1.8      fvdl 	struct vnode *vp = ap->a_vp;
    550   1.8      fvdl 	struct componentname *cnp = ap->a_cnp;
    551   1.8      fvdl 	struct inode *ip;
    552   1.1    bouyer 	int error;
    553   1.1    bouyer 
    554   1.1    bouyer #ifdef DIAGNOSTIC
    555   1.1    bouyer 	if ((cnp->cn_flags & HASBUF) == 0)
    556   1.1    bouyer 		panic("ext2fs_link: no name");
    557   1.1    bouyer #endif
    558   1.1    bouyer 	if (vp->v_type == VDIR) {
    559   1.1    bouyer 		VOP_ABORTOP(dvp, cnp);
    560   1.1    bouyer 		error = EISDIR;
    561   1.1    bouyer 		goto out2;
    562   1.1    bouyer 	}
    563   1.1    bouyer 	if (dvp->v_mount != vp->v_mount) {
    564   1.1    bouyer 		VOP_ABORTOP(dvp, cnp);
    565   1.1    bouyer 		error = EXDEV;
    566   1.1    bouyer 		goto out2;
    567   1.1    bouyer 	}
    568   1.8      fvdl 	if (dvp != vp && (error = vn_lock(vp, LK_EXCLUSIVE))) {
    569   1.1    bouyer 		VOP_ABORTOP(dvp, cnp);
    570   1.1    bouyer 		goto out2;
    571   1.1    bouyer 	}
    572   1.1    bouyer 	ip = VTOI(vp);
    573   1.1    bouyer 	if ((nlink_t)ip->i_e2fs_nlink >= LINK_MAX) {
    574   1.1    bouyer 		VOP_ABORTOP(dvp, cnp);
    575   1.1    bouyer 		error = EMLINK;
    576   1.1    bouyer 		goto out1;
    577   1.1    bouyer 	}
    578   1.1    bouyer 	if (ip->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND)) {
    579   1.1    bouyer 		VOP_ABORTOP(dvp, cnp);
    580   1.1    bouyer 		error = EPERM;
    581   1.1    bouyer 		goto out1;
    582   1.1    bouyer 	}
    583   1.1    bouyer 	ip->i_e2fs_nlink++;
    584   1.1    bouyer 	ip->i_flag |= IN_CHANGE;
    585  1.63      yamt 	error = ext2fs_update(vp, NULL, NULL, UPDATE_WAIT);
    586   1.1    bouyer 	if (!error)
    587   1.1    bouyer 		error = ext2fs_direnter(ip, dvp, cnp);
    588   1.1    bouyer 	if (error) {
    589   1.1    bouyer 		ip->i_e2fs_nlink--;
    590   1.1    bouyer 		ip->i_flag |= IN_CHANGE;
    591   1.1    bouyer 	}
    592  1.29   thorpej 	PNBUF_PUT(cnp->cn_pnbuf);
    593   1.1    bouyer out1:
    594   1.1    bouyer 	if (dvp != vp)
    595   1.8      fvdl 		VOP_UNLOCK(vp, 0);
    596   1.1    bouyer out2:
    597  1.42  jdolecek 	VN_KNOTE(vp, NOTE_LINK);
    598  1.42  jdolecek 	VN_KNOTE(dvp, NOTE_WRITE);
    599   1.1    bouyer 	vput(dvp);
    600   1.1    bouyer 	return (error);
    601   1.1    bouyer }
    602   1.1    bouyer 
    603   1.1    bouyer /*
    604   1.1    bouyer  * Rename system call.
    605   1.1    bouyer  * 	rename("foo", "bar");
    606   1.1    bouyer  * is essentially
    607   1.1    bouyer  *	unlink("bar");
    608   1.1    bouyer  *	link("foo", "bar");
    609   1.1    bouyer  *	unlink("foo");
    610   1.1    bouyer  * but ``atomically''.  Can't do full commit without saving state in the
    611   1.1    bouyer  * inode on disk which isn't feasible at this time.  Best we can do is
    612   1.1    bouyer  * always guarantee the target exists.
    613   1.1    bouyer  *
    614   1.1    bouyer  * Basic algorithm is:
    615   1.1    bouyer  *
    616   1.1    bouyer  * 1) Bump link count on source while we're linking it to the
    617   1.1    bouyer  *    target.  This also ensure the inode won't be deleted out
    618   1.1    bouyer  *    from underneath us while we work (it may be truncated by
    619   1.1    bouyer  *    a concurrent `trunc' or `open' for creation).
    620   1.1    bouyer  * 2) Link source to destination.  If destination already exists,
    621   1.1    bouyer  *    delete it first.
    622   1.1    bouyer  * 3) Unlink source reference to inode if still around. If a
    623   1.1    bouyer  *    directory was moved and the parent of the destination
    624   1.1    bouyer  *    is different from the source, patch the ".." entry in the
    625   1.1    bouyer  *    directory.
    626   1.1    bouyer  */
    627   1.1    bouyer int
    628  1.61   xtraeme ext2fs_rename(void *v)
    629   1.1    bouyer {
    630   1.1    bouyer 	struct vop_rename_args  /* {
    631   1.1    bouyer 		struct vnode *a_fdvp;
    632   1.1    bouyer 		struct vnode *a_fvp;
    633   1.1    bouyer 		struct componentname *a_fcnp;
    634   1.1    bouyer 		struct vnode *a_tdvp;
    635   1.1    bouyer 		struct vnode *a_tvp;
    636   1.1    bouyer 		struct componentname *a_tcnp;
    637   1.1    bouyer 	} */ *ap = v;
    638   1.1    bouyer 	struct vnode *tvp = ap->a_tvp;
    639  1.25  augustss 	struct vnode *tdvp = ap->a_tdvp;
    640   1.1    bouyer 	struct vnode *fvp = ap->a_fvp;
    641   1.8      fvdl 	struct vnode *fdvp = ap->a_fdvp;
    642   1.8      fvdl 	struct componentname *tcnp = ap->a_tcnp;
    643   1.8      fvdl 	struct componentname *fcnp = ap->a_fcnp;
    644   1.8      fvdl 	struct inode *ip, *xp, *dp;
    645   1.1    bouyer 	struct ext2fs_dirtemplate dirbuf;
    646   1.1    bouyer 	int doingdirectory = 0, oldparent = 0, newparent = 0;
    647   1.1    bouyer 	int error = 0;
    648   1.1    bouyer 	u_char namlen;
    649   1.1    bouyer 
    650   1.1    bouyer #ifdef DIAGNOSTIC
    651   1.1    bouyer 	if ((tcnp->cn_flags & HASBUF) == 0 ||
    652   1.1    bouyer 	    (fcnp->cn_flags & HASBUF) == 0)
    653   1.1    bouyer 		panic("ext2fs_rename: no name");
    654   1.1    bouyer #endif
    655   1.1    bouyer 	/*
    656   1.1    bouyer 	 * Check for cross-device rename.
    657   1.1    bouyer 	 */
    658   1.1    bouyer 	if ((fvp->v_mount != tdvp->v_mount) ||
    659   1.1    bouyer 	    (tvp && (fvp->v_mount != tvp->v_mount))) {
    660   1.1    bouyer 		error = EXDEV;
    661   1.1    bouyer abortit:
    662   1.1    bouyer 		VOP_ABORTOP(tdvp, tcnp); /* XXX, why not in NFS? */
    663   1.1    bouyer 		if (tdvp == tvp)
    664   1.1    bouyer 			vrele(tdvp);
    665   1.1    bouyer 		else
    666   1.1    bouyer 			vput(tdvp);
    667   1.1    bouyer 		if (tvp)
    668   1.1    bouyer 			vput(tvp);
    669   1.1    bouyer 		VOP_ABORTOP(fdvp, fcnp); /* XXX, why not in NFS? */
    670   1.1    bouyer 		vrele(fdvp);
    671   1.1    bouyer 		vrele(fvp);
    672   1.1    bouyer 		return (error);
    673   1.1    bouyer 	}
    674   1.1    bouyer 
    675   1.1    bouyer 	/*
    676   1.1    bouyer 	 * Check if just deleting a link name.
    677   1.1    bouyer 	 */
    678   1.1    bouyer 	if (tvp && ((VTOI(tvp)->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND)) ||
    679   1.1    bouyer 	    (VTOI(tdvp)->i_e2fs_flags & EXT2_APPEND))) {
    680   1.1    bouyer 		error = EPERM;
    681   1.1    bouyer 		goto abortit;
    682   1.1    bouyer 	}
    683   1.1    bouyer 	if (fvp == tvp) {
    684   1.1    bouyer 		if (fvp->v_type == VDIR) {
    685   1.1    bouyer 			error = EINVAL;
    686   1.1    bouyer 			goto abortit;
    687   1.1    bouyer 		}
    688   1.1    bouyer 
    689   1.1    bouyer 		/* Release destination completely. */
    690   1.1    bouyer 		VOP_ABORTOP(tdvp, tcnp);
    691   1.1    bouyer 		vput(tdvp);
    692   1.1    bouyer 		vput(tvp);
    693   1.1    bouyer 
    694   1.1    bouyer 		/* Delete source. */
    695   1.1    bouyer 		vrele(fdvp);
    696   1.1    bouyer 		vrele(fvp);
    697   1.1    bouyer 		fcnp->cn_flags &= ~MODMASK;
    698   1.1    bouyer 		fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
    699   1.1    bouyer 		if ((fcnp->cn_flags & SAVESTART) == 0)
    700   1.1    bouyer 			panic("ext2fs_rename: lost from startdir");
    701   1.1    bouyer 		fcnp->cn_nameiop = DELETE;
    702   1.1    bouyer 		(void) relookup(fdvp, &fvp, fcnp);
    703   1.1    bouyer 		return (VOP_REMOVE(fdvp, fvp, fcnp));
    704   1.1    bouyer 	}
    705   1.8      fvdl 	if ((error = vn_lock(fvp, LK_EXCLUSIVE)) != 0)
    706   1.1    bouyer 		goto abortit;
    707   1.1    bouyer 	dp = VTOI(fdvp);
    708   1.1    bouyer 	ip = VTOI(fvp);
    709  1.17       mrg 	if ((nlink_t) ip->i_e2fs_nlink >= LINK_MAX) {
    710  1.17       mrg 		VOP_UNLOCK(fvp, 0);
    711  1.17       mrg 		error = EMLINK;
    712  1.17       mrg 		goto abortit;
    713  1.17       mrg 	}
    714   1.1    bouyer 	if ((ip->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND)) ||
    715   1.1    bouyer 		(dp->i_e2fs_flags & EXT2_APPEND)) {
    716   1.8      fvdl 		VOP_UNLOCK(fvp, 0);
    717   1.1    bouyer 		error = EPERM;
    718   1.1    bouyer 		goto abortit;
    719   1.1    bouyer 	}
    720   1.1    bouyer 	if ((ip->i_e2fs_mode & IFMT) == IFDIR) {
    721  1.64  christos         	error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_lwp);
    722  1.16    bouyer         	if (!error && tvp)
    723  1.16    bouyer                 	error = VOP_ACCESS(tvp, VWRITE, tcnp->cn_cred,
    724  1.64  christos 			    tcnp->cn_lwp);
    725  1.16    bouyer         	if (error) {
    726  1.16    bouyer                 	VOP_UNLOCK(fvp, 0);
    727  1.16    bouyer                 	error = EACCES;
    728  1.16    bouyer                 	goto abortit;
    729  1.16    bouyer         	}
    730   1.1    bouyer 		/*
    731   1.1    bouyer 		 * Avoid ".", "..", and aliases of "." for obvious reasons.
    732   1.1    bouyer 		 */
    733   1.1    bouyer 		if ((fcnp->cn_namelen == 1 && fcnp->cn_nameptr[0] == '.') ||
    734   1.3    bouyer 		    dp == ip ||
    735  1.16    bouyer 		    (fcnp->cn_flags&ISDOTDOT) ||
    736  1.16    bouyer 		    (tcnp->cn_flags & ISDOTDOT) ||
    737   1.1    bouyer 		    (ip->i_flag & IN_RENAME)) {
    738   1.8      fvdl 			VOP_UNLOCK(fvp, 0);
    739   1.1    bouyer 			error = EINVAL;
    740   1.1    bouyer 			goto abortit;
    741   1.1    bouyer 		}
    742   1.1    bouyer 		ip->i_flag |= IN_RENAME;
    743   1.1    bouyer 		oldparent = dp->i_number;
    744   1.1    bouyer 		doingdirectory++;
    745   1.1    bouyer 	}
    746  1.42  jdolecek 	VN_KNOTE(fdvp, NOTE_WRITE);		/* XXXLUKEM/XXX: right place? */
    747   1.1    bouyer 	vrele(fdvp);
    748   1.1    bouyer 
    749   1.1    bouyer 	/*
    750   1.1    bouyer 	 * When the target exists, both the directory
    751   1.1    bouyer 	 * and target vnodes are returned locked.
    752   1.1    bouyer 	 */
    753   1.1    bouyer 	dp = VTOI(tdvp);
    754   1.1    bouyer 	xp = NULL;
    755   1.1    bouyer 	if (tvp)
    756   1.1    bouyer 		xp = VTOI(tvp);
    757   1.1    bouyer 
    758   1.1    bouyer 	/*
    759   1.1    bouyer 	 * 1) Bump link count while we're moving stuff
    760   1.1    bouyer 	 *    around.  If we crash somewhere before
    761   1.1    bouyer 	 *    completing our work, the link count
    762   1.1    bouyer 	 *    may be wrong, but correctable.
    763   1.1    bouyer 	 */
    764   1.1    bouyer 	ip->i_e2fs_nlink++;
    765   1.1    bouyer 	ip->i_flag |= IN_CHANGE;
    766  1.63      yamt 	if ((error = ext2fs_update(fvp, NULL, NULL, UPDATE_WAIT)) != 0) {
    767   1.8      fvdl 		VOP_UNLOCK(fvp, 0);
    768   1.1    bouyer 		goto bad;
    769   1.1    bouyer 	}
    770   1.1    bouyer 
    771   1.1    bouyer 	/*
    772   1.1    bouyer 	 * If ".." must be changed (ie the directory gets a new
    773   1.1    bouyer 	 * parent) then the source directory must not be in the
    774  1.36       wiz 	 * directory hierarchy above the target, as this would
    775   1.1    bouyer 	 * orphan everything below the source directory. Also
    776   1.1    bouyer 	 * the user must have write permission in the source so
    777  1.59     perry 	 * as to be able to change "..". We must repeat the call
    778   1.1    bouyer 	 * to namei, as the parent directory is unlocked by the
    779   1.1    bouyer 	 * call to checkpath().
    780   1.1    bouyer 	 */
    781  1.64  christos 	error = VOP_ACCESS(fvp, VWRITE, tcnp->cn_cred, tcnp->cn_lwp);
    782   1.8      fvdl 	VOP_UNLOCK(fvp, 0);
    783   1.1    bouyer 	if (oldparent != dp->i_number)
    784   1.1    bouyer 		newparent = dp->i_number;
    785   1.1    bouyer 	if (doingdirectory && newparent) {
    786   1.1    bouyer 		if (error)	/* write access check above */
    787   1.1    bouyer 			goto bad;
    788   1.1    bouyer 		if (xp != NULL)
    789   1.1    bouyer 			vput(tvp);
    790  1.47   thorpej 		error = ext2fs_checkpath(ip, dp, tcnp->cn_cred);
    791   1.1    bouyer 		if (error != 0)
    792   1.1    bouyer 			goto out;
    793   1.1    bouyer 		if ((tcnp->cn_flags & SAVESTART) == 0)
    794   1.1    bouyer 			panic("ext2fs_rename: lost to startdir");
    795   1.1    bouyer 		if ((error = relookup(tdvp, &tvp, tcnp)) != 0)
    796   1.1    bouyer 			goto out;
    797   1.1    bouyer 		dp = VTOI(tdvp);
    798   1.1    bouyer 		xp = NULL;
    799   1.1    bouyer 		if (tvp)
    800   1.1    bouyer 			xp = VTOI(tvp);
    801   1.1    bouyer 	}
    802   1.1    bouyer 	/*
    803   1.1    bouyer 	 * 2) If target doesn't exist, link the target
    804  1.59     perry 	 *    to the source and unlink the source.
    805   1.1    bouyer 	 *    Otherwise, rewrite the target directory
    806   1.1    bouyer 	 *    entry to reference the source inode and
    807   1.1    bouyer 	 *    expunge the original entry's existence.
    808   1.1    bouyer 	 */
    809   1.1    bouyer 	if (xp == NULL) {
    810   1.1    bouyer 		if (dp->i_dev != ip->i_dev)
    811   1.1    bouyer 			panic("rename: EXDEV");
    812   1.1    bouyer 		/*
    813   1.1    bouyer 		 * Account for ".." in new directory.
    814   1.1    bouyer 		 * When source and destination have the same
    815   1.1    bouyer 		 * parent we don't fool with the link count.
    816   1.1    bouyer 		 */
    817   1.1    bouyer 		if (doingdirectory && newparent) {
    818   1.1    bouyer 			if ((nlink_t)dp->i_e2fs_nlink >= LINK_MAX) {
    819   1.1    bouyer 				error = EMLINK;
    820   1.1    bouyer 				goto bad;
    821   1.1    bouyer 			}
    822   1.1    bouyer 			dp->i_e2fs_nlink++;
    823   1.1    bouyer 			dp->i_flag |= IN_CHANGE;
    824  1.63      yamt 			if ((error = ext2fs_update(tdvp, NULL, NULL,
    825  1.63      yamt 			    UPDATE_WAIT)) != 0)
    826   1.1    bouyer 				goto bad;
    827   1.1    bouyer 		}
    828   1.1    bouyer 		error = ext2fs_direnter(ip, tdvp, tcnp);
    829   1.1    bouyer 		if (error != 0) {
    830   1.1    bouyer 			if (doingdirectory && newparent) {
    831   1.1    bouyer 				dp->i_e2fs_nlink--;
    832   1.1    bouyer 				dp->i_flag |= IN_CHANGE;
    833  1.63      yamt 				(void)ext2fs_update(tdvp, NULL, NULL,
    834  1.63      yamt 				    UPDATE_WAIT);
    835   1.1    bouyer 			}
    836   1.1    bouyer 			goto bad;
    837   1.1    bouyer 		}
    838  1.42  jdolecek 		VN_KNOTE(tdvp, NOTE_WRITE);
    839   1.1    bouyer 		vput(tdvp);
    840   1.1    bouyer 	} else {
    841   1.1    bouyer 		if (xp->i_dev != dp->i_dev || xp->i_dev != ip->i_dev)
    842   1.1    bouyer 			panic("rename: EXDEV");
    843   1.1    bouyer 		/*
    844   1.1    bouyer 		 * Short circuit rename(foo, foo).
    845   1.1    bouyer 		 */
    846   1.1    bouyer 		if (xp->i_number == ip->i_number)
    847   1.1    bouyer 			panic("rename: same file");
    848   1.1    bouyer 		/*
    849   1.1    bouyer 		 * If the parent directory is "sticky", then the user must
    850   1.1    bouyer 		 * own the parent directory, or the destination of the rename,
    851   1.1    bouyer 		 * otherwise the destination may not be changed (except by
    852   1.1    bouyer 		 * root). This implements append-only directories.
    853   1.1    bouyer 		 */
    854   1.1    bouyer 		if ((dp->i_e2fs_mode & S_ISTXT) && tcnp->cn_cred->cr_uid != 0 &&
    855   1.1    bouyer 		    tcnp->cn_cred->cr_uid != dp->i_e2fs_uid &&
    856   1.1    bouyer 		    xp->i_e2fs_uid != tcnp->cn_cred->cr_uid) {
    857   1.1    bouyer 			error = EPERM;
    858   1.1    bouyer 			goto bad;
    859   1.1    bouyer 		}
    860   1.1    bouyer 		/*
    861   1.1    bouyer 		 * Target must be empty if a directory and have no links
    862   1.1    bouyer 		 * to it. Also, ensure source and target are compatible
    863   1.1    bouyer 		 * (both directories, or both not directories).
    864   1.1    bouyer 		 */
    865   1.1    bouyer 		if ((xp->i_e2fs_mode & IFMT) == IFDIR) {
    866   1.1    bouyer 			if (!ext2fs_dirempty(xp, dp->i_number, tcnp->cn_cred) ||
    867   1.1    bouyer 				xp->i_e2fs_nlink > 2) {
    868   1.1    bouyer 				error = ENOTEMPTY;
    869   1.1    bouyer 				goto bad;
    870   1.1    bouyer 			}
    871   1.1    bouyer 			if (!doingdirectory) {
    872   1.1    bouyer 				error = ENOTDIR;
    873   1.1    bouyer 				goto bad;
    874   1.1    bouyer 			}
    875   1.1    bouyer 			cache_purge(tdvp);
    876   1.1    bouyer 		} else if (doingdirectory) {
    877   1.1    bouyer 			error = EISDIR;
    878   1.1    bouyer 			goto bad;
    879   1.1    bouyer 		}
    880   1.1    bouyer 		error = ext2fs_dirrewrite(dp, ip, tcnp);
    881   1.1    bouyer 		if (error != 0)
    882   1.1    bouyer 			goto bad;
    883   1.1    bouyer 		/*
    884   1.1    bouyer 		 * If the target directory is in the same
    885   1.1    bouyer 		 * directory as the source directory,
    886   1.1    bouyer 		 * decrement the link count on the parent
    887   1.1    bouyer 		 * of the target directory.
    888   1.1    bouyer 		 */
    889   1.1    bouyer 		 if (doingdirectory && !newparent) {
    890   1.1    bouyer 			dp->i_e2fs_nlink--;
    891   1.1    bouyer 			dp->i_flag |= IN_CHANGE;
    892   1.1    bouyer 		}
    893  1.42  jdolecek 		VN_KNOTE(tdvp, NOTE_WRITE);
    894   1.1    bouyer 		vput(tdvp);
    895   1.1    bouyer 		/*
    896   1.1    bouyer 		 * Adjust the link count of the target to
    897   1.1    bouyer 		 * reflect the dirrewrite above.  If this is
    898   1.1    bouyer 		 * a directory it is empty and there are
    899   1.1    bouyer 		 * no links to it, so we can squash the inode and
    900   1.1    bouyer 		 * any space associated with it.  We disallowed
    901   1.1    bouyer 		 * renaming over top of a directory with links to
    902   1.1    bouyer 		 * it above, as the remaining link would point to
    903   1.1    bouyer 		 * a directory without "." or ".." entries.
    904   1.1    bouyer 		 */
    905   1.1    bouyer 		xp->i_e2fs_nlink--;
    906   1.1    bouyer 		if (doingdirectory) {
    907   1.1    bouyer 			if (--xp->i_e2fs_nlink != 0)
    908   1.1    bouyer 				panic("rename: linked directory");
    909  1.63      yamt 			error = ext2fs_truncate(tvp, (off_t)0, IO_SYNC,
    910  1.64  christos 			    tcnp->cn_cred, tcnp->cn_lwp->l_proc);
    911   1.1    bouyer 		}
    912   1.1    bouyer 		xp->i_flag |= IN_CHANGE;
    913  1.42  jdolecek 		VN_KNOTE(tvp, NOTE_DELETE);
    914   1.1    bouyer 		vput(tvp);
    915   1.1    bouyer 		xp = NULL;
    916   1.1    bouyer 	}
    917   1.1    bouyer 
    918   1.1    bouyer 	/*
    919   1.1    bouyer 	 * 3) Unlink the source.
    920   1.1    bouyer 	 */
    921   1.1    bouyer 	fcnp->cn_flags &= ~MODMASK;
    922   1.1    bouyer 	fcnp->cn_flags |= LOCKPARENT | LOCKLEAF;
    923   1.1    bouyer 	if ((fcnp->cn_flags & SAVESTART) == 0)
    924   1.1    bouyer 		panic("ext2fs_rename: lost from startdir");
    925   1.1    bouyer 	(void) relookup(fdvp, &fvp, fcnp);
    926   1.1    bouyer 	if (fvp != NULL) {
    927   1.1    bouyer 		xp = VTOI(fvp);
    928   1.1    bouyer 		dp = VTOI(fdvp);
    929   1.1    bouyer 	} else {
    930   1.1    bouyer 		/*
    931   1.1    bouyer 		 * From name has disappeared.
    932   1.1    bouyer 		 */
    933   1.1    bouyer 		if (doingdirectory)
    934   1.1    bouyer 			panic("ext2fs_rename: lost dir entry");
    935   1.1    bouyer 		vrele(ap->a_fvp);
    936   1.1    bouyer 		return (0);
    937   1.1    bouyer 	}
    938   1.1    bouyer 	/*
    939   1.1    bouyer 	 * Ensure that the directory entry still exists and has not
    940   1.1    bouyer 	 * changed while the new name has been entered. If the source is
    941   1.1    bouyer 	 * a file then the entry may have been unlinked or renamed. In
    942   1.1    bouyer 	 * either case there is no further work to be done. If the source
    943   1.1    bouyer 	 * is a directory then it cannot have been rmdir'ed; its link
    944   1.1    bouyer 	 * count of three would cause a rmdir to fail with ENOTEMPTY.
    945   1.1    bouyer 	 * The IRENAME flag ensures that it cannot be moved by another
    946   1.1    bouyer 	 * rename.
    947   1.1    bouyer 	 */
    948   1.1    bouyer 	if (xp != ip) {
    949   1.1    bouyer 		if (doingdirectory)
    950   1.1    bouyer 			panic("ext2fs_rename: lost dir entry");
    951   1.1    bouyer 	} else {
    952   1.1    bouyer 		/*
    953   1.1    bouyer 		 * If the source is a directory with a
    954   1.1    bouyer 		 * new parent, the link count of the old
    955   1.1    bouyer 		 * parent directory must be decremented
    956   1.1    bouyer 		 * and ".." set to point to the new parent.
    957   1.1    bouyer 		 */
    958   1.1    bouyer 		if (doingdirectory && newparent) {
    959   1.1    bouyer 			dp->i_e2fs_nlink--;
    960   1.1    bouyer 			dp->i_flag |= IN_CHANGE;
    961   1.1    bouyer 			error = vn_rdwr(UIO_READ, fvp, (caddr_t)&dirbuf,
    962   1.1    bouyer 				sizeof (struct ext2fs_dirtemplate), (off_t)0,
    963  1.59     perry 				UIO_SYSSPACE, IO_NODELOCKED,
    964  1.56     skrll 				tcnp->cn_cred, (size_t *)0, NULL);
    965   1.1    bouyer 			if (error == 0) {
    966  1.22    bouyer 					namlen = dirbuf.dotdot_namlen;
    967   1.1    bouyer 				if (namlen != 2 ||
    968   1.1    bouyer 				    dirbuf.dotdot_name[0] != '.' ||
    969   1.1    bouyer 				    dirbuf.dotdot_name[1] != '.') {
    970   1.1    bouyer 					ufs_dirbad(xp, (doff_t)12,
    971   1.1    bouyer 					    "ext2fs_rename: mangled dir");
    972   1.1    bouyer 				} else {
    973   1.4    bouyer 					dirbuf.dotdot_ino = h2fs32(newparent);
    974   1.1    bouyer 					(void) vn_rdwr(UIO_WRITE, fvp,
    975   1.1    bouyer 					    (caddr_t)&dirbuf,
    976   1.1    bouyer 					    sizeof (struct dirtemplate),
    977   1.1    bouyer 					    (off_t)0, UIO_SYSSPACE,
    978   1.1    bouyer 					    IO_NODELOCKED|IO_SYNC,
    979  1.12    mjacob 					    tcnp->cn_cred, (size_t *)0,
    980  1.56     skrll 					    NULL);
    981   1.1    bouyer 					cache_purge(fdvp);
    982   1.1    bouyer 				}
    983   1.1    bouyer 			}
    984   1.1    bouyer 		}
    985   1.1    bouyer 		error = ext2fs_dirremove(fdvp, fcnp);
    986   1.1    bouyer 		if (!error) {
    987   1.1    bouyer 			xp->i_e2fs_nlink--;
    988   1.1    bouyer 			xp->i_flag |= IN_CHANGE;
    989   1.1    bouyer 		}
    990   1.1    bouyer 		xp->i_flag &= ~IN_RENAME;
    991   1.1    bouyer 	}
    992  1.42  jdolecek 	VN_KNOTE(fvp, NOTE_RENAME);
    993   1.1    bouyer 	if (dp)
    994   1.1    bouyer 		vput(fdvp);
    995   1.1    bouyer 	if (xp)
    996   1.1    bouyer 		vput(fvp);
    997   1.1    bouyer 	vrele(ap->a_fvp);
    998   1.1    bouyer 	return (error);
    999   1.1    bouyer 
   1000   1.1    bouyer bad:
   1001   1.1    bouyer 	if (xp)
   1002   1.1    bouyer 		vput(ITOV(xp));
   1003   1.1    bouyer 	vput(ITOV(dp));
   1004   1.1    bouyer out:
   1005   1.1    bouyer 	if (doingdirectory)
   1006   1.1    bouyer 		ip->i_flag &= ~IN_RENAME;
   1007   1.8      fvdl 	if (vn_lock(fvp, LK_EXCLUSIVE) == 0) {
   1008   1.1    bouyer 		ip->i_e2fs_nlink--;
   1009   1.1    bouyer 		ip->i_flag |= IN_CHANGE;
   1010   1.1    bouyer 		vput(fvp);
   1011   1.1    bouyer 	} else
   1012   1.1    bouyer 		vrele(fvp);
   1013   1.1    bouyer 	return (error);
   1014   1.1    bouyer }
   1015   1.1    bouyer 
   1016   1.1    bouyer /*
   1017   1.1    bouyer  * Mkdir system call
   1018   1.1    bouyer  */
   1019   1.1    bouyer int
   1020  1.61   xtraeme ext2fs_mkdir(void *v)
   1021   1.1    bouyer {
   1022   1.1    bouyer 	struct vop_mkdir_args /* {
   1023   1.1    bouyer 		struct vnode *a_dvp;
   1024   1.1    bouyer 		struct vnode **a_vpp;
   1025   1.1    bouyer 		struct componentname *a_cnp;
   1026   1.1    bouyer 		struct vattr *a_vap;
   1027   1.1    bouyer 	} */ *ap = v;
   1028  1.55   mycroft 	struct vnode		*dvp = ap->a_dvp;
   1029  1.55   mycroft 	struct vattr		*vap = ap->a_vap;
   1030  1.55   mycroft 	struct componentname	*cnp = ap->a_cnp;
   1031  1.55   mycroft 	struct inode		*ip, *dp = VTOI(dvp);
   1032  1.55   mycroft 	struct vnode		*tvp;
   1033   1.4    bouyer 	struct ext2fs_dirtemplate dirtemplate;
   1034  1.55   mycroft 	int			error, dmode;
   1035   1.1    bouyer 
   1036   1.1    bouyer #ifdef DIAGNOSTIC
   1037   1.1    bouyer 	if ((cnp->cn_flags & HASBUF) == 0)
   1038   1.1    bouyer 		panic("ext2fs_mkdir: no name");
   1039   1.1    bouyer #endif
   1040   1.1    bouyer 	if ((nlink_t)dp->i_e2fs_nlink >= LINK_MAX) {
   1041   1.1    bouyer 		error = EMLINK;
   1042   1.1    bouyer 		goto out;
   1043   1.1    bouyer 	}
   1044   1.1    bouyer 	dmode = vap->va_mode & ACCESSPERMS;
   1045   1.1    bouyer 	dmode |= IFDIR;
   1046   1.1    bouyer 	/*
   1047   1.1    bouyer 	 * Must simulate part of ext2fs_makeinode here to acquire the inode,
   1048   1.1    bouyer 	 * but not have it entered in the parent directory. The entry is
   1049   1.1    bouyer 	 * made later after writing "." and ".." entries.
   1050   1.1    bouyer 	 */
   1051  1.63      yamt 	if ((error = ext2fs_valloc(dvp, dmode, cnp->cn_cred, &tvp)) != 0)
   1052   1.1    bouyer 		goto out;
   1053   1.1    bouyer 	ip = VTOI(tvp);
   1054   1.1    bouyer 	ip->i_e2fs_uid = cnp->cn_cred->cr_uid;
   1055   1.1    bouyer 	ip->i_e2fs_gid = dp->i_e2fs_gid;
   1056   1.1    bouyer 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
   1057   1.1    bouyer 	ip->i_e2fs_mode = dmode;
   1058   1.1    bouyer 	tvp->v_type = VDIR;	/* Rest init'd in getnewvnode(). */
   1059   1.1    bouyer 	ip->i_e2fs_nlink = 2;
   1060   1.1    bouyer 
   1061   1.1    bouyer 	/*
   1062   1.1    bouyer 	 * Bump link count in parent directory
   1063   1.1    bouyer 	 * to reflect work done below.  Should
   1064   1.1    bouyer 	 * be done before reference is created
   1065   1.1    bouyer 	 * so reparation is possible if we crash.
   1066   1.1    bouyer 	 */
   1067   1.1    bouyer 	dp->i_e2fs_nlink++;
   1068   1.1    bouyer 	dp->i_flag |= IN_CHANGE;
   1069  1.63      yamt 	if ((error = ext2fs_update(dvp, NULL, NULL, UPDATE_DIROP)) != 0)
   1070   1.1    bouyer 		goto bad;
   1071   1.1    bouyer 
   1072   1.1    bouyer 	/* Initialize directory with "." and ".." from static template. */
   1073  1.13     perry 	memset(&dirtemplate, 0, sizeof(dirtemplate));
   1074   1.4    bouyer 	dirtemplate.dot_ino = h2fs32(ip->i_number);
   1075   1.4    bouyer 	dirtemplate.dot_reclen = h2fs16(12);
   1076  1.22    bouyer 	dirtemplate.dot_namlen = 1;
   1077  1.22    bouyer 	if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 &&
   1078  1.22    bouyer 	    (ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) {
   1079  1.23    bouyer 		dirtemplate.dot_type = EXT2_FT_DIR;
   1080  1.22    bouyer 	}
   1081   1.4    bouyer 	dirtemplate.dot_name[0] = '.';
   1082   1.4    bouyer 	dirtemplate.dotdot_ino = h2fs32(dp->i_number);
   1083   1.4    bouyer     dirtemplate.dotdot_reclen = h2fs16(VTOI(dvp)->i_e2fs->e2fs_bsize - 12);
   1084  1.22    bouyer 	dirtemplate.dotdot_namlen = 2;
   1085  1.22    bouyer 	if (ip->i_e2fs->e2fs.e2fs_rev > E2FS_REV0 &&
   1086  1.22    bouyer 	    (ip->i_e2fs->e2fs.e2fs_features_incompat & EXT2F_INCOMPAT_FTYPE)) {
   1087  1.23    bouyer 		dirtemplate.dotdot_type = EXT2_FT_DIR;
   1088  1.22    bouyer 	}
   1089   1.4    bouyer 	dirtemplate.dotdot_name[0] = dirtemplate.dotdot_name[1] = '.';
   1090   1.1    bouyer 	error = vn_rdwr(UIO_WRITE, tvp, (caddr_t)&dirtemplate,
   1091   1.1    bouyer 	    sizeof (dirtemplate), (off_t)0, UIO_SYSSPACE,
   1092  1.56     skrll 	    IO_NODELOCKED|IO_SYNC, cnp->cn_cred, (size_t *)0, NULL);
   1093   1.1    bouyer 	if (error) {
   1094   1.1    bouyer 		dp->i_e2fs_nlink--;
   1095   1.1    bouyer 		dp->i_flag |= IN_CHANGE;
   1096   1.1    bouyer 		goto bad;
   1097   1.1    bouyer 	}
   1098  1.55   mycroft 	if (VTOI(dvp)->i_e2fs->e2fs_bsize > dvp->v_mount->mnt_stat.f_bsize)
   1099   1.1    bouyer 		panic("ext2fs_mkdir: blksize"); /* XXX should grow with balloc() */
   1100   1.1    bouyer 	else {
   1101  1.58        ws 		error = ext2fs_setsize(ip, VTOI(dvp)->i_e2fs->e2fs_bsize);
   1102  1.58        ws 		if (error) {
   1103  1.58        ws 			dp->i_e2fs_nlink--;
   1104  1.58        ws 			dp->i_flag |= IN_CHANGE;
   1105  1.58        ws 			goto bad;
   1106  1.58        ws 		}
   1107   1.1    bouyer 		ip->i_flag |= IN_CHANGE;
   1108  1.60       kml 		uvm_vnp_setsize(tvp, ext2fs_size(ip));
   1109   1.1    bouyer 	}
   1110   1.1    bouyer 
   1111   1.1    bouyer 	/* Directory set up, now install it's entry in the parent directory. */
   1112   1.1    bouyer 	error = ext2fs_direnter(ip, dvp, cnp);
   1113   1.1    bouyer 	if (error != 0) {
   1114   1.1    bouyer 		dp->i_e2fs_nlink--;
   1115   1.1    bouyer 		dp->i_flag |= IN_CHANGE;
   1116   1.1    bouyer 	}
   1117   1.1    bouyer bad:
   1118   1.1    bouyer 	/*
   1119  1.63      yamt 	 * No need to do an explicit ext2fs_truncate here, vrele will do this
   1120   1.1    bouyer 	 * for us because we set the link count to 0.
   1121   1.1    bouyer 	 */
   1122   1.1    bouyer 	if (error) {
   1123   1.1    bouyer 		ip->i_e2fs_nlink = 0;
   1124   1.1    bouyer 		ip->i_flag |= IN_CHANGE;
   1125   1.1    bouyer 		vput(tvp);
   1126  1.42  jdolecek 	} else {
   1127  1.42  jdolecek 		VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
   1128   1.1    bouyer 		*ap->a_vpp = tvp;
   1129  1.42  jdolecek 	}
   1130   1.1    bouyer out:
   1131  1.29   thorpej 	PNBUF_PUT(cnp->cn_pnbuf);
   1132   1.1    bouyer 	vput(dvp);
   1133   1.1    bouyer 	return (error);
   1134   1.1    bouyer }
   1135   1.1    bouyer 
   1136   1.1    bouyer /*
   1137   1.1    bouyer  * Rmdir system call.
   1138   1.1    bouyer  */
   1139   1.1    bouyer int
   1140  1.61   xtraeme ext2fs_rmdir(void *v)
   1141   1.1    bouyer {
   1142   1.1    bouyer 	struct vop_rmdir_args /* {
   1143   1.1    bouyer 		struct vnode *a_dvp;
   1144   1.1    bouyer 		struct vnode *a_vp;
   1145   1.1    bouyer 		struct componentname *a_cnp;
   1146   1.1    bouyer 	} */ *ap = v;
   1147  1.25  augustss 	struct vnode *vp = ap->a_vp;
   1148  1.25  augustss 	struct vnode *dvp = ap->a_dvp;
   1149  1.25  augustss 	struct componentname *cnp = ap->a_cnp;
   1150  1.25  augustss 	struct inode *ip, *dp;
   1151   1.1    bouyer 	int error;
   1152   1.1    bouyer 
   1153   1.1    bouyer 	ip = VTOI(vp);
   1154   1.1    bouyer 	dp = VTOI(dvp);
   1155   1.1    bouyer 	/*
   1156   1.1    bouyer 	 * No rmdir "." please.
   1157   1.1    bouyer 	 */
   1158   1.1    bouyer 	if (dp == ip) {
   1159   1.1    bouyer 		vrele(dvp);
   1160   1.1    bouyer 		vput(vp);
   1161   1.1    bouyer 		return (EINVAL);
   1162   1.1    bouyer 	}
   1163   1.1    bouyer 	/*
   1164   1.1    bouyer 	 * Verify the directory is empty (and valid).
   1165   1.1    bouyer 	 * (Rmdir ".." won't be valid since
   1166   1.1    bouyer 	 *  ".." will contain a reference to
   1167   1.1    bouyer 	 *  the current directory and thus be
   1168   1.1    bouyer 	 *  non-empty.)
   1169   1.1    bouyer 	 */
   1170   1.1    bouyer 	error = 0;
   1171   1.1    bouyer 	if (ip->i_e2fs_nlink != 2 ||
   1172   1.1    bouyer 	    !ext2fs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
   1173   1.1    bouyer 		error = ENOTEMPTY;
   1174   1.1    bouyer 		goto out;
   1175   1.1    bouyer 	}
   1176   1.1    bouyer 	if ((dp->i_e2fs_flags & EXT2_APPEND) ||
   1177   1.1    bouyer 				 (ip->i_e2fs_flags & (EXT2_IMMUTABLE | EXT2_APPEND))) {
   1178   1.1    bouyer 		error = EPERM;
   1179   1.1    bouyer 		goto out;
   1180   1.1    bouyer 	}
   1181   1.1    bouyer 	/*
   1182   1.1    bouyer 	 * Delete reference to directory before purging
   1183   1.1    bouyer 	 * inode.  If we crash in between, the directory
   1184   1.1    bouyer 	 * will be reattached to lost+found,
   1185   1.1    bouyer 	 */
   1186   1.1    bouyer 	error = ext2fs_dirremove(dvp, cnp);
   1187   1.1    bouyer 	if (error != 0)
   1188   1.1    bouyer 		goto out;
   1189   1.1    bouyer 	dp->i_e2fs_nlink--;
   1190   1.1    bouyer 	dp->i_flag |= IN_CHANGE;
   1191  1.42  jdolecek 	VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
   1192   1.1    bouyer 	cache_purge(dvp);
   1193   1.1    bouyer 	vput(dvp);
   1194   1.1    bouyer 	dvp = NULL;
   1195   1.1    bouyer 	/*
   1196   1.1    bouyer 	 * Truncate inode.  The only stuff left
   1197   1.1    bouyer 	 * in the directory is "." and "..".  The
   1198   1.1    bouyer 	 * "." reference is inconsequential since
   1199   1.1    bouyer 	 * we're quashing it.  The ".." reference
   1200   1.1    bouyer 	 * has already been adjusted above.  We've
   1201   1.1    bouyer 	 * removed the "." reference and the reference
   1202   1.1    bouyer 	 * in the parent directory, but there may be
   1203   1.1    bouyer 	 * other hard links so decrement by 2 and
   1204   1.1    bouyer 	 * worry about them later.
   1205   1.1    bouyer 	 */
   1206   1.1    bouyer 	ip->i_e2fs_nlink -= 2;
   1207  1.63      yamt 	error = ext2fs_truncate(vp, (off_t)0, IO_SYNC, cnp->cn_cred,
   1208  1.64  christos 	    cnp->cn_lwp->l_proc);
   1209   1.1    bouyer 	cache_purge(ITOV(ip));
   1210   1.1    bouyer out:
   1211  1.42  jdolecek 	VN_KNOTE(vp, NOTE_DELETE);
   1212   1.1    bouyer 	if (dvp)
   1213   1.1    bouyer 		vput(dvp);
   1214   1.1    bouyer 	vput(vp);
   1215   1.1    bouyer 	return (error);
   1216   1.1    bouyer }
   1217   1.1    bouyer 
   1218   1.1    bouyer /*
   1219   1.1    bouyer  * symlink -- make a symbolic link
   1220   1.1    bouyer  */
   1221   1.1    bouyer int
   1222  1.61   xtraeme ext2fs_symlink(void *v)
   1223   1.1    bouyer {
   1224   1.1    bouyer 	struct vop_symlink_args /* {
   1225   1.1    bouyer 		struct vnode *a_dvp;
   1226   1.1    bouyer 		struct vnode **a_vpp;
   1227   1.1    bouyer 		struct componentname *a_cnp;
   1228   1.1    bouyer 		struct vattr *a_vap;
   1229   1.1    bouyer 		char *a_target;
   1230   1.1    bouyer 	} */ *ap = v;
   1231  1.55   mycroft 	struct vnode	*vp, **vpp;
   1232  1.55   mycroft 	struct inode	*ip;
   1233  1.55   mycroft 	int		len, error;
   1234   1.1    bouyer 
   1235  1.55   mycroft 	vpp = ap->a_vpp;
   1236   1.1    bouyer 	error = ext2fs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp,
   1237   1.1    bouyer 			      vpp, ap->a_cnp);
   1238   1.1    bouyer 	if (error)
   1239   1.1    bouyer 		return (error);
   1240  1.42  jdolecek 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
   1241   1.1    bouyer 	vp = *vpp;
   1242   1.1    bouyer 	len = strlen(ap->a_target);
   1243  1.55   mycroft 	ip = VTOI(vp);
   1244  1.55   mycroft 	if (len < ip->i_ump->um_maxsymlinklen) {
   1245  1.44      fvdl 		memcpy((char *)ip->i_din.e2fs_din->e2di_shortlink, ap->a_target, len);
   1246  1.58        ws 		error = ext2fs_setsize(ip, len);
   1247  1.58        ws 		if (error)
   1248  1.58        ws 			goto bad;
   1249   1.1    bouyer 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
   1250  1.60       kml 		uvm_vnp_setsize(vp, len);
   1251   1.1    bouyer 	} else
   1252   1.1    bouyer 		error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
   1253  1.12    mjacob 		    UIO_SYSSPACE, IO_NODELOCKED, ap->a_cnp->cn_cred,
   1254  1.56     skrll 		    (size_t *)0, NULL);
   1255  1.58        ws bad:
   1256  1.34     assar 	if (error)
   1257  1.34     assar 		vput(vp);
   1258   1.1    bouyer 	return (error);
   1259   1.1    bouyer }
   1260   1.1    bouyer 
   1261   1.1    bouyer /*
   1262   1.1    bouyer  * Return target name of a symbolic link
   1263   1.1    bouyer  */
   1264   1.1    bouyer int
   1265  1.61   xtraeme ext2fs_readlink(void *v)
   1266   1.1    bouyer {
   1267   1.1    bouyer 	struct vop_readlink_args /* {
   1268   1.1    bouyer 		struct vnode *a_vp;
   1269   1.1    bouyer 		struct uio *a_uio;
   1270   1.1    bouyer 		struct ucred *a_cred;
   1271   1.1    bouyer 	} */ *ap = v;
   1272  1.55   mycroft 	struct vnode	*vp = ap->a_vp;
   1273  1.55   mycroft 	struct inode	*ip = VTOI(vp);
   1274  1.55   mycroft 	struct ufsmount	*ump = ip->i_ump;
   1275  1.55   mycroft 	int		isize;
   1276   1.1    bouyer 
   1277  1.58        ws 	isize = ext2fs_size(ip);
   1278  1.55   mycroft 	if (isize < ump->um_maxsymlinklen ||
   1279  1.55   mycroft 	    (ump->um_maxsymlinklen == 0 && ip->i_e2fs_nblock == 0)) {
   1280  1.44      fvdl 		uiomove((char *)ip->i_din.e2fs_din->e2di_shortlink, isize, ap->a_uio);
   1281   1.1    bouyer 		return (0);
   1282   1.1    bouyer 	}
   1283   1.1    bouyer 	return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
   1284   1.1    bouyer }
   1285   1.1    bouyer 
   1286   1.1    bouyer /*
   1287   1.1    bouyer  * Advisory record locking support
   1288   1.1    bouyer  */
   1289   1.1    bouyer int
   1290  1.61   xtraeme ext2fs_advlock(void *v)
   1291   1.1    bouyer {
   1292   1.1    bouyer 	struct vop_advlock_args /* {
   1293   1.1    bouyer 		struct vnode *a_vp;
   1294   1.1    bouyer 		caddr_t  a_id;
   1295   1.1    bouyer 		int  a_op;
   1296   1.1    bouyer 		struct flock *a_fl;
   1297   1.1    bouyer 		int  a_flags;
   1298   1.1    bouyer 	} */ *ap = v;
   1299  1.25  augustss 	struct inode *ip = VTOI(ap->a_vp);
   1300   1.1    bouyer 
   1301  1.58        ws 	return lf_advlock(ap, &ip->i_lockf, ext2fs_size(ip));
   1302   1.1    bouyer }
   1303   1.1    bouyer 
   1304  1.63      yamt int
   1305  1.63      yamt ext2fs_fsync(void *v)
   1306  1.63      yamt {
   1307  1.63      yamt 	struct vop_fsync_args /* {
   1308  1.63      yamt 		struct vnode *a_vp;
   1309  1.63      yamt 		struct ucred *a_cred;
   1310  1.63      yamt 		int a_flags;
   1311  1.63      yamt 		off_t offlo;
   1312  1.63      yamt 		off_t offhi;
   1313  1.63      yamt 		struct proc *a_p;
   1314  1.63      yamt 	} */ *ap = v;
   1315  1.63      yamt 	struct vnode *vp = ap->a_vp;
   1316  1.63      yamt 	int wait;
   1317  1.63      yamt 	int error;
   1318  1.63      yamt 
   1319  1.63      yamt 	wait = (ap->a_flags & FSYNC_WAIT) != 0;
   1320  1.63      yamt 	vflushbuf(vp, wait);
   1321  1.63      yamt 	if ((ap->a_flags & FSYNC_DATAONLY) != 0)
   1322  1.63      yamt 		error = 0;
   1323  1.63      yamt 	else
   1324  1.63      yamt 		error = ext2fs_update(vp, NULL, NULL, wait ? UPDATE_WAIT : 0);
   1325  1.63      yamt 
   1326  1.63      yamt 	if (error == 0 && ap->a_flags & FSYNC_CACHE) {
   1327  1.63      yamt 		int l = 0;
   1328  1.63      yamt 		error = VOP_IOCTL(VTOI(vp)->i_devvp, DIOCCACHESYNC, &l, FWRITE,
   1329  1.64  christos 		    ap->a_l->l_proc->p_ucred, ap->a_l);
   1330  1.63      yamt 	}
   1331  1.63      yamt 
   1332  1.63      yamt 	return error;
   1333  1.63      yamt }
   1334  1.63      yamt 
   1335   1.1    bouyer /*
   1336   1.1    bouyer  * Initialize the vnode associated with a new inode, handle aliased
   1337   1.1    bouyer  * vnodes.
   1338   1.1    bouyer  */
   1339   1.1    bouyer int
   1340  1.61   xtraeme ext2fs_vinit(struct mount *mntp, int (**specops)(void *),
   1341  1.61   xtraeme 	int (**fifoops)(void *), struct vnode **vpp)
   1342   1.1    bouyer {
   1343   1.1    bouyer 	struct inode *ip;
   1344   1.1    bouyer 	struct vnode *vp, *nvp;
   1345   1.1    bouyer 
   1346   1.1    bouyer 	vp = *vpp;
   1347   1.1    bouyer 	ip = VTOI(vp);
   1348   1.1    bouyer 	switch(vp->v_type = IFTOVT(ip->i_e2fs_mode)) {
   1349   1.1    bouyer 	case VCHR:
   1350   1.1    bouyer 	case VBLK:
   1351   1.1    bouyer 		vp->v_op = specops;
   1352  1.16    bouyer 		if ((nvp = checkalias(vp,
   1353  1.44      fvdl 		    fs2h32(ip->i_din.e2fs_din->e2di_rdev), mntp)) != NULL) {
   1354   1.1    bouyer 			/*
   1355   1.1    bouyer 			 * Discard unneeded vnode, but save its inode.
   1356   1.1    bouyer 			 */
   1357   1.1    bouyer 			nvp->v_data = vp->v_data;
   1358   1.1    bouyer 			vp->v_data = NULL;
   1359  1.33      fvdl 			VOP_UNLOCK(vp, 0);
   1360   1.1    bouyer 			vp->v_op = spec_vnodeop_p;
   1361  1.57   thorpej 			vp->v_flag &= ~VLOCKSWORK;
   1362  1.33      fvdl 			vrele(vp);
   1363   1.1    bouyer 			vgone(vp);
   1364  1.20  wrstuden 			lockmgr(&nvp->v_lock, LK_EXCLUSIVE, &nvp->v_interlock);
   1365   1.1    bouyer 			/*
   1366   1.1    bouyer 			 * Reinitialize aliased inode.
   1367   1.1    bouyer 			 */
   1368   1.1    bouyer 			vp = nvp;
   1369   1.1    bouyer 			ip->i_vnode = vp;
   1370   1.1    bouyer 		}
   1371   1.1    bouyer 		break;
   1372   1.1    bouyer 	case VFIFO:
   1373   1.1    bouyer 		vp->v_op = fifoops;
   1374   1.1    bouyer 		break;
   1375   1.1    bouyer 	case VNON:
   1376   1.1    bouyer 	case VBAD:
   1377   1.1    bouyer 	case VSOCK:
   1378   1.1    bouyer 	case VLNK:
   1379   1.1    bouyer 	case VDIR:
   1380   1.1    bouyer 	case VREG:
   1381   1.1    bouyer 		break;
   1382   1.1    bouyer 	}
   1383   1.1    bouyer 	if (ip->i_number == ROOTINO)
   1384   1.1    bouyer                 vp->v_flag |= VROOT;
   1385   1.1    bouyer 	/*
   1386   1.1    bouyer 	 * Initialize modrev times
   1387   1.1    bouyer 	 */
   1388   1.1    bouyer 	SETHIGH(ip->i_modrev, mono_time.tv_sec);
   1389   1.1    bouyer 	SETLOW(ip->i_modrev, mono_time.tv_usec * 4294);
   1390   1.1    bouyer 	*vpp = vp;
   1391   1.1    bouyer 	return (0);
   1392   1.1    bouyer }
   1393   1.1    bouyer 
   1394   1.1    bouyer /*
   1395   1.1    bouyer  * Allocate a new inode.
   1396   1.1    bouyer  */
   1397   1.1    bouyer int
   1398  1.61   xtraeme ext2fs_makeinode(int mode, struct vnode *dvp, struct vnode **vpp,
   1399  1.61   xtraeme 		struct componentname *cnp)
   1400   1.1    bouyer {
   1401  1.25  augustss 	struct inode *ip, *pdir;
   1402   1.1    bouyer 	struct vnode *tvp;
   1403   1.1    bouyer 	int error;
   1404   1.1    bouyer 
   1405   1.1    bouyer 	pdir = VTOI(dvp);
   1406   1.1    bouyer #ifdef DIAGNOSTIC
   1407   1.1    bouyer 	if ((cnp->cn_flags & HASBUF) == 0)
   1408   1.1    bouyer 		panic("ext2fs_makeinode: no name");
   1409   1.1    bouyer #endif
   1410   1.1    bouyer 	*vpp = NULL;
   1411   1.1    bouyer 	if ((mode & IFMT) == 0)
   1412   1.1    bouyer 		mode |= IFREG;
   1413   1.1    bouyer 
   1414  1.63      yamt 	if ((error = ext2fs_valloc(dvp, mode, cnp->cn_cred, &tvp)) != 0) {
   1415  1.29   thorpej 		PNBUF_PUT(cnp->cn_pnbuf);
   1416   1.1    bouyer 		vput(dvp);
   1417   1.1    bouyer 		return (error);
   1418   1.1    bouyer 	}
   1419   1.1    bouyer 	ip = VTOI(tvp);
   1420   1.1    bouyer 	ip->i_e2fs_gid = pdir->i_e2fs_gid;
   1421   1.1    bouyer 	ip->i_e2fs_uid = cnp->cn_cred->cr_uid;
   1422   1.1    bouyer 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
   1423   1.1    bouyer 	ip->i_e2fs_mode = mode;
   1424   1.1    bouyer 	tvp->v_type = IFTOVT(mode);	/* Rest init'd in getnewvnode(). */
   1425   1.1    bouyer 	ip->i_e2fs_nlink = 1;
   1426   1.1    bouyer 	if ((ip->i_e2fs_mode & ISGID) &&
   1427   1.1    bouyer 		!groupmember(ip->i_e2fs_gid, cnp->cn_cred) &&
   1428   1.1    bouyer 	    suser(cnp->cn_cred, NULL))
   1429   1.1    bouyer 		ip->i_e2fs_mode &= ~ISGID;
   1430   1.1    bouyer 
   1431   1.1    bouyer 	/*
   1432   1.1    bouyer 	 * Make sure inode goes to disk before directory entry.
   1433   1.1    bouyer 	 */
   1434  1.63      yamt 	if ((error = ext2fs_update(tvp, NULL, NULL, UPDATE_WAIT)) != 0)
   1435   1.1    bouyer 		goto bad;
   1436   1.1    bouyer 	error = ext2fs_direnter(ip, dvp, cnp);
   1437   1.1    bouyer 	if (error != 0)
   1438   1.1    bouyer 		goto bad;
   1439   1.1    bouyer 	if ((cnp->cn_flags & SAVESTART) == 0)
   1440  1.29   thorpej 		PNBUF_PUT(cnp->cn_pnbuf);
   1441   1.1    bouyer 	vput(dvp);
   1442   1.1    bouyer 	*vpp = tvp;
   1443   1.1    bouyer 	return (0);
   1444   1.1    bouyer 
   1445   1.1    bouyer bad:
   1446   1.1    bouyer 	/*
   1447   1.1    bouyer 	 * Write error occurred trying to update the inode
   1448   1.1    bouyer 	 * or the directory so must deallocate the inode.
   1449   1.1    bouyer 	 */
   1450  1.50       dsl 	tvp->v_type = VNON;	/* Stop explosion if VBLK */
   1451   1.1    bouyer 	ip->i_e2fs_nlink = 0;
   1452   1.1    bouyer 	ip->i_flag |= IN_CHANGE;
   1453   1.1    bouyer 	vput(tvp);
   1454  1.50       dsl 	PNBUF_PUT(cnp->cn_pnbuf);
   1455  1.50       dsl 	vput(dvp);
   1456   1.1    bouyer 	return (error);
   1457   1.1    bouyer }
   1458   1.1    bouyer 
   1459   1.1    bouyer /*
   1460   1.1    bouyer  * Reclaim an inode so that it can be used for other purposes.
   1461   1.1    bouyer  */
   1462   1.1    bouyer int
   1463  1.61   xtraeme ext2fs_reclaim(void *v)
   1464   1.1    bouyer {
   1465   1.1    bouyer 	struct vop_reclaim_args /* {
   1466   1.1    bouyer 		struct vnode *a_vp;
   1467   1.1    bouyer 	} */ *ap = v;
   1468  1.25  augustss 	struct vnode *vp = ap->a_vp;
   1469  1.54   mycroft 	struct inode *ip = VTOI(vp);
   1470  1.54   mycroft 	int error;
   1471  1.45      fvdl 
   1472  1.64  christos 	if ((error = ufs_reclaim(vp, ap->a_l)) != 0)
   1473  1.54   mycroft 		return (error);
   1474  1.45      fvdl 	if (ip->i_din.e2fs_din != NULL)
   1475  1.45      fvdl 		pool_put(&ext2fs_dinode_pool, ip->i_din.e2fs_din);
   1476  1.14   thorpej 	pool_put(&ext2fs_inode_pool, vp->v_data);
   1477   1.1    bouyer 	vp->v_data = NULL;
   1478   1.1    bouyer 	return (0);
   1479   1.1    bouyer }
   1480   1.1    bouyer 
   1481   1.1    bouyer /* Global vfs data structures for ext2fs. */
   1482  1.61   xtraeme int (**ext2fs_vnodeop_p)(void *);
   1483  1.31  jdolecek const struct vnodeopv_entry_desc ext2fs_vnodeop_entries[] = {
   1484   1.1    bouyer 	{ &vop_default_desc, vn_default_error },
   1485   1.8      fvdl 	{ &vop_lookup_desc, ext2fs_lookup },		/* lookup */
   1486   1.8      fvdl 	{ &vop_create_desc, ext2fs_create },		/* create */
   1487   1.1    bouyer 	{ &vop_mknod_desc, ext2fs_mknod },		/* mknod */
   1488   1.1    bouyer 	{ &vop_open_desc, ext2fs_open },		/* open */
   1489   1.1    bouyer 	{ &vop_close_desc, ufs_close },			/* close */
   1490   1.8      fvdl 	{ &vop_access_desc, ext2fs_access },		/* access */
   1491   1.8      fvdl 	{ &vop_getattr_desc, ext2fs_getattr },		/* getattr */
   1492   1.8      fvdl 	{ &vop_setattr_desc, ext2fs_setattr },		/* setattr */
   1493   1.1    bouyer 	{ &vop_read_desc, ext2fs_read },		/* read */
   1494   1.1    bouyer 	{ &vop_write_desc, ext2fs_write },		/* write */
   1495   1.8      fvdl 	{ &vop_lease_desc, ufs_lease_check },		/* lease */
   1496   1.1    bouyer 	{ &vop_ioctl_desc, ufs_ioctl },			/* ioctl */
   1497  1.21  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
   1498   1.1    bouyer 	{ &vop_poll_desc, ufs_poll },			/* poll */
   1499  1.42  jdolecek 	{ &vop_kqfilter_desc, genfs_kqfilter },		/* kqfilter */
   1500   1.8      fvdl 	{ &vop_revoke_desc, ufs_revoke },		/* revoke */
   1501   1.1    bouyer 	{ &vop_mmap_desc, ufs_mmap },			/* mmap */
   1502   1.1    bouyer 	{ &vop_fsync_desc, ext2fs_fsync },		/* fsync */
   1503   1.1    bouyer 	{ &vop_seek_desc, ufs_seek },			/* seek */
   1504   1.8      fvdl 	{ &vop_remove_desc, ext2fs_remove },		/* remove */
   1505   1.1    bouyer 	{ &vop_link_desc, ext2fs_link },		/* link */
   1506   1.8      fvdl 	{ &vop_rename_desc, ext2fs_rename },		/* rename */
   1507   1.1    bouyer 	{ &vop_mkdir_desc, ext2fs_mkdir },		/* mkdir */
   1508   1.1    bouyer 	{ &vop_rmdir_desc, ext2fs_rmdir },		/* rmdir */
   1509   1.8      fvdl 	{ &vop_symlink_desc, ext2fs_symlink },		/* symlink */
   1510   1.8      fvdl 	{ &vop_readdir_desc, ext2fs_readdir },		/* readdir */
   1511   1.8      fvdl 	{ &vop_readlink_desc, ext2fs_readlink },	/* readlink */
   1512   1.1    bouyer 	{ &vop_abortop_desc, ufs_abortop },		/* abortop */
   1513   1.8      fvdl 	{ &vop_inactive_desc, ext2fs_inactive },	/* inactive */
   1514   1.8      fvdl 	{ &vop_reclaim_desc, ext2fs_reclaim },		/* reclaim */
   1515   1.1    bouyer 	{ &vop_lock_desc, ufs_lock },			/* lock */
   1516   1.1    bouyer 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
   1517   1.1    bouyer 	{ &vop_bmap_desc, ext2fs_bmap },		/* bmap */
   1518   1.8      fvdl 	{ &vop_strategy_desc, ufs_strategy },		/* strategy */
   1519   1.1    bouyer 	{ &vop_print_desc, ufs_print },			/* print */
   1520   1.8      fvdl 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
   1521   1.8      fvdl 	{ &vop_pathconf_desc, ufs_pathconf },		/* pathconf */
   1522   1.8      fvdl 	{ &vop_advlock_desc, ext2fs_advlock },		/* advlock */
   1523   1.1    bouyer 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
   1524  1.30       chs 	{ &vop_getpages_desc, genfs_getpages },		/* getpages */
   1525  1.30       chs 	{ &vop_putpages_desc, genfs_putpages },		/* putpages */
   1526  1.30       chs 	{ NULL, NULL }
   1527   1.1    bouyer };
   1528  1.31  jdolecek const struct vnodeopv_desc ext2fs_vnodeop_opv_desc =
   1529   1.1    bouyer 	{ &ext2fs_vnodeop_p, ext2fs_vnodeop_entries };
   1530   1.1    bouyer 
   1531  1.61   xtraeme int (**ext2fs_specop_p)(void *);
   1532  1.31  jdolecek const struct vnodeopv_entry_desc ext2fs_specop_entries[] = {
   1533   1.1    bouyer 	{ &vop_default_desc, vn_default_error },
   1534   1.1    bouyer 	{ &vop_lookup_desc, spec_lookup },		/* lookup */
   1535   1.1    bouyer 	{ &vop_create_desc, spec_create },		/* create */
   1536   1.1    bouyer 	{ &vop_mknod_desc, spec_mknod },		/* mknod */
   1537   1.1    bouyer 	{ &vop_open_desc, spec_open },			/* open */
   1538   1.1    bouyer 	{ &vop_close_desc, ufsspec_close },		/* close */
   1539   1.8      fvdl 	{ &vop_access_desc, ext2fs_access },		/* access */
   1540   1.8      fvdl 	{ &vop_getattr_desc, ext2fs_getattr },		/* getattr */
   1541   1.8      fvdl 	{ &vop_setattr_desc, ext2fs_setattr },		/* setattr */
   1542   1.1    bouyer 	{ &vop_read_desc, ufsspec_read },		/* read */
   1543   1.1    bouyer 	{ &vop_write_desc, ufsspec_write },		/* write */
   1544   1.8      fvdl 	{ &vop_lease_desc, spec_lease_check },		/* lease */
   1545   1.1    bouyer 	{ &vop_ioctl_desc, spec_ioctl },		/* ioctl */
   1546  1.21  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
   1547   1.1    bouyer 	{ &vop_poll_desc, spec_poll },			/* poll */
   1548  1.42  jdolecek 	{ &vop_kqfilter_desc, spec_kqfilter },		/* kqfilter */
   1549   1.8      fvdl 	{ &vop_revoke_desc, spec_revoke },		/* revoke */
   1550   1.1    bouyer 	{ &vop_mmap_desc, spec_mmap },			/* mmap */
   1551   1.1    bouyer 	{ &vop_fsync_desc, ext2fs_fsync },		/* fsync */
   1552   1.1    bouyer 	{ &vop_seek_desc, spec_seek },			/* seek */
   1553   1.1    bouyer 	{ &vop_remove_desc, spec_remove },		/* remove */
   1554   1.1    bouyer 	{ &vop_link_desc, spec_link },			/* link */
   1555   1.1    bouyer 	{ &vop_rename_desc, spec_rename },		/* rename */
   1556   1.1    bouyer 	{ &vop_mkdir_desc, spec_mkdir },		/* mkdir */
   1557   1.1    bouyer 	{ &vop_rmdir_desc, spec_rmdir },		/* rmdir */
   1558   1.8      fvdl 	{ &vop_symlink_desc, spec_symlink },		/* symlink */
   1559   1.8      fvdl 	{ &vop_readdir_desc, spec_readdir },		/* readdir */
   1560   1.8      fvdl 	{ &vop_readlink_desc, spec_readlink },		/* readlink */
   1561   1.8      fvdl 	{ &vop_abortop_desc, spec_abortop },		/* abortop */
   1562   1.8      fvdl 	{ &vop_inactive_desc, ext2fs_inactive },	/* inactive */
   1563   1.8      fvdl 	{ &vop_reclaim_desc, ext2fs_reclaim },		/* reclaim */
   1564   1.1    bouyer 	{ &vop_lock_desc, ufs_lock },			/* lock */
   1565   1.1    bouyer 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
   1566   1.1    bouyer 	{ &vop_bmap_desc, spec_bmap },			/* bmap */
   1567   1.8      fvdl 	{ &vop_strategy_desc, spec_strategy },		/* strategy */
   1568   1.1    bouyer 	{ &vop_print_desc, ufs_print },			/* print */
   1569   1.8      fvdl 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
   1570   1.8      fvdl 	{ &vop_pathconf_desc, spec_pathconf },		/* pathconf */
   1571   1.8      fvdl 	{ &vop_advlock_desc, spec_advlock },		/* advlock */
   1572   1.1    bouyer 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
   1573  1.35       chs 	{ &vop_getpages_desc, spec_getpages },		/* getpages */
   1574  1.35       chs 	{ &vop_putpages_desc, spec_putpages },		/* putpages */
   1575  1.30       chs 	{ NULL, NULL }
   1576   1.1    bouyer };
   1577  1.31  jdolecek const struct vnodeopv_desc ext2fs_specop_opv_desc =
   1578   1.1    bouyer 	{ &ext2fs_specop_p, ext2fs_specop_entries };
   1579   1.1    bouyer 
   1580  1.61   xtraeme int (**ext2fs_fifoop_p)(void *);
   1581  1.31  jdolecek const struct vnodeopv_entry_desc ext2fs_fifoop_entries[] = {
   1582   1.1    bouyer 	{ &vop_default_desc, vn_default_error },
   1583   1.1    bouyer 	{ &vop_lookup_desc, fifo_lookup },		/* lookup */
   1584   1.1    bouyer 	{ &vop_create_desc, fifo_create },		/* create */
   1585   1.1    bouyer 	{ &vop_mknod_desc, fifo_mknod },		/* mknod */
   1586   1.1    bouyer 	{ &vop_open_desc, fifo_open },			/* open */
   1587   1.1    bouyer 	{ &vop_close_desc, ufsfifo_close },		/* close */
   1588   1.8      fvdl 	{ &vop_access_desc, ext2fs_access },		/* access */
   1589   1.8      fvdl 	{ &vop_getattr_desc, ext2fs_getattr },		/* getattr */
   1590   1.8      fvdl 	{ &vop_setattr_desc, ext2fs_setattr },		/* setattr */
   1591   1.1    bouyer 	{ &vop_read_desc, ufsfifo_read },		/* read */
   1592   1.1    bouyer 	{ &vop_write_desc, ufsfifo_write },		/* write */
   1593   1.8      fvdl 	{ &vop_lease_desc, fifo_lease_check },		/* lease */
   1594   1.1    bouyer 	{ &vop_ioctl_desc, fifo_ioctl },		/* ioctl */
   1595  1.21  wrstuden 	{ &vop_fcntl_desc, ufs_fcntl },			/* fcntl */
   1596   1.1    bouyer 	{ &vop_poll_desc, fifo_poll },			/* poll */
   1597  1.42  jdolecek 	{ &vop_kqfilter_desc, fifo_kqfilter },		/* kqfilter */
   1598   1.8      fvdl 	{ &vop_revoke_desc, fifo_revoke },		/* revoke */
   1599   1.1    bouyer 	{ &vop_mmap_desc, fifo_mmap },			/* mmap */
   1600   1.1    bouyer 	{ &vop_fsync_desc, ext2fs_fsync },		/* fsync */
   1601   1.1    bouyer 	{ &vop_seek_desc, fifo_seek },			/* seek */
   1602   1.1    bouyer 	{ &vop_remove_desc, fifo_remove },		/* remove */
   1603   1.1    bouyer 	{ &vop_link_desc, fifo_link },			/* link */
   1604   1.1    bouyer 	{ &vop_rename_desc, fifo_rename },		/* rename */
   1605   1.1    bouyer 	{ &vop_mkdir_desc, fifo_mkdir },		/* mkdir */
   1606   1.1    bouyer 	{ &vop_rmdir_desc, fifo_rmdir },		/* rmdir */
   1607   1.8      fvdl 	{ &vop_symlink_desc, fifo_symlink },		/* symlink */
   1608   1.8      fvdl 	{ &vop_readdir_desc, fifo_readdir },		/* readdir */
   1609   1.8      fvdl 	{ &vop_readlink_desc, fifo_readlink },		/* readlink */
   1610   1.8      fvdl 	{ &vop_abortop_desc, fifo_abortop },		/* abortop */
   1611   1.8      fvdl 	{ &vop_inactive_desc, ext2fs_inactive },	/* inactive */
   1612   1.8      fvdl 	{ &vop_reclaim_desc, ext2fs_reclaim },		/* reclaim */
   1613   1.1    bouyer 	{ &vop_lock_desc, ufs_lock },			/* lock */
   1614   1.1    bouyer 	{ &vop_unlock_desc, ufs_unlock },		/* unlock */
   1615   1.1    bouyer 	{ &vop_bmap_desc, fifo_bmap },			/* bmap */
   1616   1.8      fvdl 	{ &vop_strategy_desc, fifo_strategy },		/* strategy */
   1617   1.1    bouyer 	{ &vop_print_desc, ufs_print },			/* print */
   1618   1.8      fvdl 	{ &vop_islocked_desc, ufs_islocked },		/* islocked */
   1619   1.8      fvdl 	{ &vop_pathconf_desc, fifo_pathconf },		/* pathconf */
   1620   1.8      fvdl 	{ &vop_advlock_desc, fifo_advlock },		/* advlock */
   1621   1.1    bouyer 	{ &vop_bwrite_desc, vn_bwrite },		/* bwrite */
   1622  1.38  sommerfe 	{ &vop_putpages_desc, fifo_putpages }, 		/* putpages */
   1623  1.30       chs 	{ NULL, NULL }
   1624   1.1    bouyer };
   1625  1.31  jdolecek const struct vnodeopv_desc ext2fs_fifoop_opv_desc =
   1626   1.1    bouyer 	{ &ext2fs_fifoop_p, ext2fs_fifoop_entries };
   1627