Home | History | Annotate | Line # | Download | only in lfs
ulfs_vnops.c revision 1.1
      1  1.1  dholland /*	$NetBSD: ulfs_vnops.c,v 1.1 2013/06/06 00:40:55 dholland Exp $	*/
      2  1.1  dholland /*  from NetBSD: ufs_vnops.c,v 1.212 2013/03/18 19:35:48 plunky Exp  */
      3  1.1  dholland 
      4  1.1  dholland /*-
      5  1.1  dholland  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      6  1.1  dholland  * All rights reserved.
      7  1.1  dholland  *
      8  1.1  dholland  * This code is derived from software contributed to The NetBSD Foundation
      9  1.1  dholland  * by Wasabi Systems, Inc.
     10  1.1  dholland  *
     11  1.1  dholland  * Redistribution and use in source and binary forms, with or without
     12  1.1  dholland  * modification, are permitted provided that the following conditions
     13  1.1  dholland  * are met:
     14  1.1  dholland  * 1. Redistributions of source code must retain the above copyright
     15  1.1  dholland  *    notice, this list of conditions and the following disclaimer.
     16  1.1  dholland  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  dholland  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  dholland  *    documentation and/or other materials provided with the distribution.
     19  1.1  dholland  *
     20  1.1  dholland  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     21  1.1  dholland  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     22  1.1  dholland  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     23  1.1  dholland  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     24  1.1  dholland  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  1.1  dholland  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     26  1.1  dholland  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     27  1.1  dholland  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     28  1.1  dholland  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     29  1.1  dholland  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     30  1.1  dholland  * POSSIBILITY OF SUCH DAMAGE.
     31  1.1  dholland  */
     32  1.1  dholland 
     33  1.1  dholland /*
     34  1.1  dholland  * Copyright (c) 1982, 1986, 1989, 1993, 1995
     35  1.1  dholland  *	The Regents of the University of California.  All rights reserved.
     36  1.1  dholland  * (c) UNIX System Laboratories, Inc.
     37  1.1  dholland  * All or some portions of this file are derived from material licensed
     38  1.1  dholland  * to the University of California by American Telephone and Telegraph
     39  1.1  dholland  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     40  1.1  dholland  * the permission of UNIX System Laboratories, Inc.
     41  1.1  dholland  *
     42  1.1  dholland  * Redistribution and use in source and binary forms, with or without
     43  1.1  dholland  * modification, are permitted provided that the following conditions
     44  1.1  dholland  * are met:
     45  1.1  dholland  * 1. Redistributions of source code must retain the above copyright
     46  1.1  dholland  *    notice, this list of conditions and the following disclaimer.
     47  1.1  dholland  * 2. Redistributions in binary form must reproduce the above copyright
     48  1.1  dholland  *    notice, this list of conditions and the following disclaimer in the
     49  1.1  dholland  *    documentation and/or other materials provided with the distribution.
     50  1.1  dholland  * 3. Neither the name of the University nor the names of its contributors
     51  1.1  dholland  *    may be used to endorse or promote products derived from this software
     52  1.1  dholland  *    without specific prior written permission.
     53  1.1  dholland  *
     54  1.1  dholland  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     55  1.1  dholland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     56  1.1  dholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     57  1.1  dholland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     58  1.1  dholland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     59  1.1  dholland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     60  1.1  dholland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     61  1.1  dholland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     62  1.1  dholland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     63  1.1  dholland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     64  1.1  dholland  * SUCH DAMAGE.
     65  1.1  dholland  *
     66  1.1  dholland  *	@(#)ufs_vnops.c	8.28 (Berkeley) 7/31/95
     67  1.1  dholland  */
     68  1.1  dholland 
     69  1.1  dholland #include <sys/cdefs.h>
     70  1.1  dholland __KERNEL_RCSID(0, "$NetBSD: ulfs_vnops.c,v 1.1 2013/06/06 00:40:55 dholland Exp $");
     71  1.1  dholland 
     72  1.1  dholland #if defined(_KERNEL_OPT)
     73  1.1  dholland #include "opt_ffs.h"
     74  1.1  dholland #include "opt_quota.h"
     75  1.1  dholland #endif
     76  1.1  dholland 
     77  1.1  dholland #include <sys/param.h>
     78  1.1  dholland #include <sys/systm.h>
     79  1.1  dholland #include <sys/namei.h>
     80  1.1  dholland #include <sys/resourcevar.h>
     81  1.1  dholland #include <sys/kernel.h>
     82  1.1  dholland #include <sys/file.h>
     83  1.1  dholland #include <sys/stat.h>
     84  1.1  dholland #include <sys/buf.h>
     85  1.1  dholland #include <sys/proc.h>
     86  1.1  dholland #include <sys/mount.h>
     87  1.1  dholland #include <sys/vnode.h>
     88  1.1  dholland #include <sys/kmem.h>
     89  1.1  dholland #include <sys/malloc.h>
     90  1.1  dholland #include <sys/dirent.h>
     91  1.1  dholland #include <sys/lockf.h>
     92  1.1  dholland #include <sys/kauth.h>
     93  1.1  dholland #include <sys/wapbl.h>
     94  1.1  dholland #include <sys/fstrans.h>
     95  1.1  dholland 
     96  1.1  dholland #include <miscfs/specfs/specdev.h>
     97  1.1  dholland #include <miscfs/fifofs/fifo.h>
     98  1.1  dholland #include <miscfs/genfs/genfs.h>
     99  1.1  dholland 
    100  1.1  dholland #include <ufs/ufs/inode.h>
    101  1.1  dholland #include <ufs/ufs/dir.h>
    102  1.1  dholland #include <ufs/ufs/ufsmount.h>
    103  1.1  dholland #include <ufs/ufs/ufs_bswap.h>
    104  1.1  dholland #include <ufs/ufs/ufs_extern.h>
    105  1.1  dholland #include <ufs/ufs/ufs_wapbl.h>
    106  1.1  dholland #ifdef UFS_DIRHASH
    107  1.1  dholland #include <ufs/ufs/dirhash.h>
    108  1.1  dholland #endif
    109  1.1  dholland #include <ufs/ext2fs/ext2fs_extern.h>
    110  1.1  dholland #include <ufs/ext2fs/ext2fs_dir.h>
    111  1.1  dholland #include <ufs/ffs/ffs_extern.h>
    112  1.1  dholland #include <ufs/lfs/lfs_extern.h>
    113  1.1  dholland #include <ufs/lfs/lfs.h>
    114  1.1  dholland 
    115  1.1  dholland #include <uvm/uvm.h>
    116  1.1  dholland 
    117  1.1  dholland __CTASSERT(EXT2FS_MAXNAMLEN == FFS_MAXNAMLEN);
    118  1.1  dholland __CTASSERT(LFS_MAXNAMLEN == FFS_MAXNAMLEN);
    119  1.1  dholland 
    120  1.1  dholland static int ufs_chmod(struct vnode *, int, kauth_cred_t, struct lwp *);
    121  1.1  dholland static int ufs_chown(struct vnode *, uid_t, gid_t, kauth_cred_t,
    122  1.1  dholland     struct lwp *);
    123  1.1  dholland 
    124  1.1  dholland /*
    125  1.1  dholland  * A virgin directory (no blushing please).
    126  1.1  dholland  */
    127  1.1  dholland static const struct dirtemplate mastertemplate = {
    128  1.1  dholland 	0,	12,		DT_DIR,	1,	".",
    129  1.1  dholland 	0,	DIRBLKSIZ - 12,	DT_DIR,	2,	".."
    130  1.1  dholland };
    131  1.1  dholland 
    132  1.1  dholland /*
    133  1.1  dholland  * Create a regular file
    134  1.1  dholland  */
    135  1.1  dholland int
    136  1.1  dholland ufs_create(void *v)
    137  1.1  dholland {
    138  1.1  dholland 	struct vop_create_args /* {
    139  1.1  dholland 		struct vnode		*a_dvp;
    140  1.1  dholland 		struct vnode		**a_vpp;
    141  1.1  dholland 		struct componentname	*a_cnp;
    142  1.1  dholland 		struct vattr		*a_vap;
    143  1.1  dholland 	} */ *ap = v;
    144  1.1  dholland 	int	error;
    145  1.1  dholland 	struct vnode *dvp = ap->a_dvp;
    146  1.1  dholland 	struct ufs_lookup_results *ulr;
    147  1.1  dholland 
    148  1.1  dholland 	/* XXX should handle this material another way */
    149  1.1  dholland 	ulr = &VTOI(dvp)->i_crap;
    150  1.1  dholland 	UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
    151  1.1  dholland 
    152  1.1  dholland 	/*
    153  1.1  dholland 	 * UFS_WAPBL_BEGIN1(dvp->v_mount, dvp) performed by successful
    154  1.1  dholland 	 * ufs_makeinode
    155  1.1  dholland 	 */
    156  1.1  dholland 	fstrans_start(dvp->v_mount, FSTRANS_SHARED);
    157  1.1  dholland 	error =
    158  1.1  dholland 	    ufs_makeinode(MAKEIMODE(ap->a_vap->va_type, ap->a_vap->va_mode),
    159  1.1  dholland 			  dvp, ulr, ap->a_vpp, ap->a_cnp);
    160  1.1  dholland 	if (error) {
    161  1.1  dholland 		fstrans_done(dvp->v_mount);
    162  1.1  dholland 		return (error);
    163  1.1  dholland 	}
    164  1.1  dholland 	UFS_WAPBL_END1(dvp->v_mount, dvp);
    165  1.1  dholland 	fstrans_done(dvp->v_mount);
    166  1.1  dholland 	VN_KNOTE(dvp, NOTE_WRITE);
    167  1.1  dholland 	return (0);
    168  1.1  dholland }
    169  1.1  dholland 
    170  1.1  dholland /*
    171  1.1  dholland  * Mknod vnode call
    172  1.1  dholland  */
    173  1.1  dholland /* ARGSUSED */
    174  1.1  dholland int
    175  1.1  dholland ufs_mknod(void *v)
    176  1.1  dholland {
    177  1.1  dholland 	struct vop_mknod_args /* {
    178  1.1  dholland 		struct vnode		*a_dvp;
    179  1.1  dholland 		struct vnode		**a_vpp;
    180  1.1  dholland 		struct componentname	*a_cnp;
    181  1.1  dholland 		struct vattr		*a_vap;
    182  1.1  dholland 	} */ *ap = v;
    183  1.1  dholland 	struct vattr	*vap;
    184  1.1  dholland 	struct vnode	**vpp;
    185  1.1  dholland 	struct inode	*ip;
    186  1.1  dholland 	int		error;
    187  1.1  dholland 	struct mount	*mp;
    188  1.1  dholland 	ino_t		ino;
    189  1.1  dholland 	struct ufs_lookup_results *ulr;
    190  1.1  dholland 
    191  1.1  dholland 	vap = ap->a_vap;
    192  1.1  dholland 	vpp = ap->a_vpp;
    193  1.1  dholland 
    194  1.1  dholland 	/* XXX should handle this material another way */
    195  1.1  dholland 	ulr = &VTOI(ap->a_dvp)->i_crap;
    196  1.1  dholland 	UFS_CHECK_CRAPCOUNTER(VTOI(ap->a_dvp));
    197  1.1  dholland 
    198  1.1  dholland 	/*
    199  1.1  dholland 	 * UFS_WAPBL_BEGIN1(dvp->v_mount, dvp) performed by successful
    200  1.1  dholland 	 * ufs_makeinode
    201  1.1  dholland 	 */
    202  1.1  dholland 	fstrans_start(ap->a_dvp->v_mount, FSTRANS_SHARED);
    203  1.1  dholland 	if ((error =
    204  1.1  dholland 	    ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode),
    205  1.1  dholland 	    ap->a_dvp, ulr, vpp, ap->a_cnp)) != 0)
    206  1.1  dholland 		goto out;
    207  1.1  dholland 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
    208  1.1  dholland 	ip = VTOI(*vpp);
    209  1.1  dholland 	mp  = (*vpp)->v_mount;
    210  1.1  dholland 	ino = ip->i_number;
    211  1.1  dholland 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
    212  1.1  dholland 	if (vap->va_rdev != VNOVAL) {
    213  1.1  dholland 		struct ufsmount *ump = ip->i_ump;
    214  1.1  dholland 		/*
    215  1.1  dholland 		 * Want to be able to use this to make badblock
    216  1.1  dholland 		 * inodes, so don't truncate the dev number.
    217  1.1  dholland 		 */
    218  1.1  dholland 		if (ump->um_fstype == UFS1)
    219  1.1  dholland 			ip->i_ffs1_rdev = ufs_rw32(vap->va_rdev,
    220  1.1  dholland 			    UFS_MPNEEDSWAP(ump));
    221  1.1  dholland 		else
    222  1.1  dholland 			ip->i_ffs2_rdev = ufs_rw64(vap->va_rdev,
    223  1.1  dholland 			    UFS_MPNEEDSWAP(ump));
    224  1.1  dholland 	}
    225  1.1  dholland 	UFS_WAPBL_UPDATE(*vpp, NULL, NULL, 0);
    226  1.1  dholland 	UFS_WAPBL_END1(ap->a_dvp->v_mount, ap->a_dvp);
    227  1.1  dholland 	/*
    228  1.1  dholland 	 * Remove inode so that it will be reloaded by VFS_VGET and
    229  1.1  dholland 	 * checked to see if it is an alias of an existing entry in
    230  1.1  dholland 	 * the inode cache.
    231  1.1  dholland 	 */
    232  1.1  dholland 	(*vpp)->v_type = VNON;
    233  1.1  dholland 	VOP_UNLOCK(*vpp);
    234  1.1  dholland 	vgone(*vpp);
    235  1.1  dholland 	error = VFS_VGET(mp, ino, vpp);
    236  1.1  dholland out:
    237  1.1  dholland 	fstrans_done(ap->a_dvp->v_mount);
    238  1.1  dholland 	if (error != 0) {
    239  1.1  dholland 		*vpp = NULL;
    240  1.1  dholland 		return (error);
    241  1.1  dholland 	}
    242  1.1  dholland 	return (0);
    243  1.1  dholland }
    244  1.1  dholland 
    245  1.1  dholland /*
    246  1.1  dholland  * Open called.
    247  1.1  dholland  *
    248  1.1  dholland  * Nothing to do.
    249  1.1  dholland  */
    250  1.1  dholland /* ARGSUSED */
    251  1.1  dholland int
    252  1.1  dholland ufs_open(void *v)
    253  1.1  dholland {
    254  1.1  dholland 	struct vop_open_args /* {
    255  1.1  dholland 		struct vnode	*a_vp;
    256  1.1  dholland 		int		a_mode;
    257  1.1  dholland 		kauth_cred_t	a_cred;
    258  1.1  dholland 	} */ *ap = v;
    259  1.1  dholland 
    260  1.1  dholland 	/*
    261  1.1  dholland 	 * Files marked append-only must be opened for appending.
    262  1.1  dholland 	 */
    263  1.1  dholland 	if ((VTOI(ap->a_vp)->i_flags & APPEND) &&
    264  1.1  dholland 	    (ap->a_mode & (FWRITE | O_APPEND)) == FWRITE)
    265  1.1  dholland 		return (EPERM);
    266  1.1  dholland 	return (0);
    267  1.1  dholland }
    268  1.1  dholland 
    269  1.1  dholland /*
    270  1.1  dholland  * Close called.
    271  1.1  dholland  *
    272  1.1  dholland  * Update the times on the inode.
    273  1.1  dholland  */
    274  1.1  dholland /* ARGSUSED */
    275  1.1  dholland int
    276  1.1  dholland ufs_close(void *v)
    277  1.1  dholland {
    278  1.1  dholland 	struct vop_close_args /* {
    279  1.1  dholland 		struct vnode	*a_vp;
    280  1.1  dholland 		int		a_fflag;
    281  1.1  dholland 		kauth_cred_t	a_cred;
    282  1.1  dholland 	} */ *ap = v;
    283  1.1  dholland 	struct vnode	*vp;
    284  1.1  dholland 	struct inode	*ip;
    285  1.1  dholland 
    286  1.1  dholland 	vp = ap->a_vp;
    287  1.1  dholland 	ip = VTOI(vp);
    288  1.1  dholland 	fstrans_start(vp->v_mount, FSTRANS_SHARED);
    289  1.1  dholland 	if (vp->v_usecount > 1)
    290  1.1  dholland 		UFS_ITIMES(vp, NULL, NULL, NULL);
    291  1.1  dholland 	fstrans_done(vp->v_mount);
    292  1.1  dholland 	return (0);
    293  1.1  dholland }
    294  1.1  dholland 
    295  1.1  dholland static int
    296  1.1  dholland ufs_check_possible(struct vnode *vp, struct inode *ip, mode_t mode,
    297  1.1  dholland     kauth_cred_t cred)
    298  1.1  dholland {
    299  1.1  dholland #if defined(QUOTA) || defined(QUOTA2)
    300  1.1  dholland 	int error;
    301  1.1  dholland #endif
    302  1.1  dholland 
    303  1.1  dholland 	/*
    304  1.1  dholland 	 * Disallow write attempts on read-only file systems;
    305  1.1  dholland 	 * unless the file is a socket, fifo, or a block or
    306  1.1  dholland 	 * character device resident on the file system.
    307  1.1  dholland 	 */
    308  1.1  dholland 	if (mode & VWRITE) {
    309  1.1  dholland 		switch (vp->v_type) {
    310  1.1  dholland 		case VDIR:
    311  1.1  dholland 		case VLNK:
    312  1.1  dholland 		case VREG:
    313  1.1  dholland 			if (vp->v_mount->mnt_flag & MNT_RDONLY)
    314  1.1  dholland 				return (EROFS);
    315  1.1  dholland #if defined(QUOTA) || defined(QUOTA2)
    316  1.1  dholland 			fstrans_start(vp->v_mount, FSTRANS_SHARED);
    317  1.1  dholland 			error = chkdq(ip, 0, cred, 0);
    318  1.1  dholland 			fstrans_done(vp->v_mount);
    319  1.1  dholland 			if (error != 0)
    320  1.1  dholland 				return error;
    321  1.1  dholland #endif
    322  1.1  dholland 			break;
    323  1.1  dholland 		case VBAD:
    324  1.1  dholland 		case VBLK:
    325  1.1  dholland 		case VCHR:
    326  1.1  dholland 		case VSOCK:
    327  1.1  dholland 		case VFIFO:
    328  1.1  dholland 		case VNON:
    329  1.1  dholland 		default:
    330  1.1  dholland 			break;
    331  1.1  dholland 		}
    332  1.1  dholland 	}
    333  1.1  dholland 
    334  1.1  dholland 	/* If it is a snapshot, nobody gets access to it. */
    335  1.1  dholland 	if ((ip->i_flags & SF_SNAPSHOT))
    336  1.1  dholland 		return (EPERM);
    337  1.1  dholland 	/* If immutable bit set, nobody gets to write it. */
    338  1.1  dholland 	if ((mode & VWRITE) && (ip->i_flags & IMMUTABLE))
    339  1.1  dholland 		return (EPERM);
    340  1.1  dholland 
    341  1.1  dholland 	return 0;
    342  1.1  dholland }
    343  1.1  dholland 
    344  1.1  dholland static int
    345  1.1  dholland ufs_check_permitted(struct vnode *vp, struct inode *ip, mode_t mode,
    346  1.1  dholland     kauth_cred_t cred)
    347  1.1  dholland {
    348  1.1  dholland 
    349  1.1  dholland 	return kauth_authorize_vnode(cred, KAUTH_ACCESS_ACTION(mode, vp->v_type,
    350  1.1  dholland 	    ip->i_mode & ALLPERMS), vp, NULL, genfs_can_access(vp->v_type,
    351  1.1  dholland 	    ip->i_mode & ALLPERMS, ip->i_uid, ip->i_gid, mode, cred));
    352  1.1  dholland }
    353  1.1  dholland 
    354  1.1  dholland int
    355  1.1  dholland ufs_access(void *v)
    356  1.1  dholland {
    357  1.1  dholland 	struct vop_access_args /* {
    358  1.1  dholland 		struct vnode	*a_vp;
    359  1.1  dholland 		int		a_mode;
    360  1.1  dholland 		kauth_cred_t	a_cred;
    361  1.1  dholland 	} */ *ap = v;
    362  1.1  dholland 	struct vnode	*vp;
    363  1.1  dholland 	struct inode	*ip;
    364  1.1  dholland 	mode_t		mode;
    365  1.1  dholland 	int		error;
    366  1.1  dholland 
    367  1.1  dholland 	vp = ap->a_vp;
    368  1.1  dholland 	ip = VTOI(vp);
    369  1.1  dholland 	mode = ap->a_mode;
    370  1.1  dholland 
    371  1.1  dholland 	error = ufs_check_possible(vp, ip, mode, ap->a_cred);
    372  1.1  dholland 	if (error)
    373  1.1  dholland 		return error;
    374  1.1  dholland 
    375  1.1  dholland 	error = ufs_check_permitted(vp, ip, mode, ap->a_cred);
    376  1.1  dholland 
    377  1.1  dholland 	return error;
    378  1.1  dholland }
    379  1.1  dholland 
    380  1.1  dholland /* ARGSUSED */
    381  1.1  dholland int
    382  1.1  dholland ufs_getattr(void *v)
    383  1.1  dholland {
    384  1.1  dholland 	struct vop_getattr_args /* {
    385  1.1  dholland 		struct vnode	*a_vp;
    386  1.1  dholland 		struct vattr	*a_vap;
    387  1.1  dholland 		kauth_cred_t	a_cred;
    388  1.1  dholland 	} */ *ap = v;
    389  1.1  dholland 	struct vnode	*vp;
    390  1.1  dholland 	struct inode	*ip;
    391  1.1  dholland 	struct vattr	*vap;
    392  1.1  dholland 
    393  1.1  dholland 	vp = ap->a_vp;
    394  1.1  dholland 	ip = VTOI(vp);
    395  1.1  dholland 	vap = ap->a_vap;
    396  1.1  dholland 	fstrans_start(vp->v_mount, FSTRANS_SHARED);
    397  1.1  dholland 	UFS_ITIMES(vp, NULL, NULL, NULL);
    398  1.1  dholland 
    399  1.1  dholland 	/*
    400  1.1  dholland 	 * Copy from inode table
    401  1.1  dholland 	 */
    402  1.1  dholland 	vap->va_fsid = ip->i_dev;
    403  1.1  dholland 	vap->va_fileid = ip->i_number;
    404  1.1  dholland 	vap->va_mode = ip->i_mode & ALLPERMS;
    405  1.1  dholland 	vap->va_nlink = ip->i_nlink;
    406  1.1  dholland 	vap->va_uid = ip->i_uid;
    407  1.1  dholland 	vap->va_gid = ip->i_gid;
    408  1.1  dholland 	vap->va_size = vp->v_size;
    409  1.1  dholland 	if (ip->i_ump->um_fstype == UFS1) {
    410  1.1  dholland 		vap->va_rdev = (dev_t)ufs_rw32(ip->i_ffs1_rdev,
    411  1.1  dholland 		    UFS_MPNEEDSWAP(ip->i_ump));
    412  1.1  dholland 		vap->va_atime.tv_sec = ip->i_ffs1_atime;
    413  1.1  dholland 		vap->va_atime.tv_nsec = ip->i_ffs1_atimensec;
    414  1.1  dholland 		vap->va_mtime.tv_sec = ip->i_ffs1_mtime;
    415  1.1  dholland 		vap->va_mtime.tv_nsec = ip->i_ffs1_mtimensec;
    416  1.1  dholland 		vap->va_ctime.tv_sec = ip->i_ffs1_ctime;
    417  1.1  dholland 		vap->va_ctime.tv_nsec = ip->i_ffs1_ctimensec;
    418  1.1  dholland 		vap->va_birthtime.tv_sec = 0;
    419  1.1  dholland 		vap->va_birthtime.tv_nsec = 0;
    420  1.1  dholland 		vap->va_bytes = dbtob((u_quad_t)ip->i_ffs1_blocks);
    421  1.1  dholland 	} else {
    422  1.1  dholland 		vap->va_rdev = (dev_t)ufs_rw64(ip->i_ffs2_rdev,
    423  1.1  dholland 		    UFS_MPNEEDSWAP(ip->i_ump));
    424  1.1  dholland 		vap->va_atime.tv_sec = ip->i_ffs2_atime;
    425  1.1  dholland 		vap->va_atime.tv_nsec = ip->i_ffs2_atimensec;
    426  1.1  dholland 		vap->va_mtime.tv_sec = ip->i_ffs2_mtime;
    427  1.1  dholland 		vap->va_mtime.tv_nsec = ip->i_ffs2_mtimensec;
    428  1.1  dholland 		vap->va_ctime.tv_sec = ip->i_ffs2_ctime;
    429  1.1  dholland 		vap->va_ctime.tv_nsec = ip->i_ffs2_ctimensec;
    430  1.1  dholland 		vap->va_birthtime.tv_sec = ip->i_ffs2_birthtime;
    431  1.1  dholland 		vap->va_birthtime.tv_nsec = ip->i_ffs2_birthnsec;
    432  1.1  dholland 		vap->va_bytes = dbtob(ip->i_ffs2_blocks);
    433  1.1  dholland 	}
    434  1.1  dholland 	vap->va_gen = ip->i_gen;
    435  1.1  dholland 	vap->va_flags = ip->i_flags;
    436  1.1  dholland 
    437  1.1  dholland 	/* this doesn't belong here */
    438  1.1  dholland 	if (vp->v_type == VBLK)
    439  1.1  dholland 		vap->va_blocksize = BLKDEV_IOSIZE;
    440  1.1  dholland 	else if (vp->v_type == VCHR)
    441  1.1  dholland 		vap->va_blocksize = MAXBSIZE;
    442  1.1  dholland 	else
    443  1.1  dholland 		vap->va_blocksize = vp->v_mount->mnt_stat.f_iosize;
    444  1.1  dholland 	vap->va_type = vp->v_type;
    445  1.1  dholland 	vap->va_filerev = ip->i_modrev;
    446  1.1  dholland 	fstrans_done(vp->v_mount);
    447  1.1  dholland 	return (0);
    448  1.1  dholland }
    449  1.1  dholland 
    450  1.1  dholland /*
    451  1.1  dholland  * Set attribute vnode op. called from several syscalls
    452  1.1  dholland  */
    453  1.1  dholland int
    454  1.1  dholland ufs_setattr(void *v)
    455  1.1  dholland {
    456  1.1  dholland 	struct vop_setattr_args /* {
    457  1.1  dholland 		struct vnode	*a_vp;
    458  1.1  dholland 		struct vattr	*a_vap;
    459  1.1  dholland 		kauth_cred_t	a_cred;
    460  1.1  dholland 	} */ *ap = v;
    461  1.1  dholland 	struct vattr	*vap;
    462  1.1  dholland 	struct vnode	*vp;
    463  1.1  dholland 	struct inode	*ip;
    464  1.1  dholland 	kauth_cred_t	cred;
    465  1.1  dholland 	struct lwp	*l;
    466  1.1  dholland 	int		error;
    467  1.1  dholland 	kauth_action_t	action;
    468  1.1  dholland 	bool		changing_sysflags;
    469  1.1  dholland 
    470  1.1  dholland 	vap = ap->a_vap;
    471  1.1  dholland 	vp = ap->a_vp;
    472  1.1  dholland 	ip = VTOI(vp);
    473  1.1  dholland 	cred = ap->a_cred;
    474  1.1  dholland 	l = curlwp;
    475  1.1  dholland 	action = KAUTH_VNODE_WRITE_FLAGS;
    476  1.1  dholland 	changing_sysflags = false;
    477  1.1  dholland 
    478  1.1  dholland 	/*
    479  1.1  dholland 	 * Check for unsettable attributes.
    480  1.1  dholland 	 */
    481  1.1  dholland 	if ((vap->va_type != VNON) || (vap->va_nlink != VNOVAL) ||
    482  1.1  dholland 	    (vap->va_fsid != VNOVAL) || (vap->va_fileid != VNOVAL) ||
    483  1.1  dholland 	    (vap->va_blocksize != VNOVAL) || (vap->va_rdev != VNOVAL) ||
    484  1.1  dholland 	    ((int)vap->va_bytes != VNOVAL) || (vap->va_gen != VNOVAL)) {
    485  1.1  dholland 		return (EINVAL);
    486  1.1  dholland 	}
    487  1.1  dholland 
    488  1.1  dholland 	fstrans_start(vp->v_mount, FSTRANS_SHARED);
    489  1.1  dholland 
    490  1.1  dholland 	if (vap->va_flags != VNOVAL) {
    491  1.1  dholland 		if (vp->v_mount->mnt_flag & MNT_RDONLY) {
    492  1.1  dholland 			error = EROFS;
    493  1.1  dholland 			goto out;
    494  1.1  dholland 		}
    495  1.1  dholland 
    496  1.1  dholland 		/* Snapshot flag cannot be set or cleared */
    497  1.1  dholland 		if ((vap->va_flags & (SF_SNAPSHOT | SF_SNAPINVAL)) !=
    498  1.1  dholland 		    (ip->i_flags & (SF_SNAPSHOT | SF_SNAPINVAL))) {
    499  1.1  dholland 			error = EPERM;
    500  1.1  dholland 			goto out;
    501  1.1  dholland 		}
    502  1.1  dholland 
    503  1.1  dholland 		if (ip->i_flags & (SF_IMMUTABLE | SF_APPEND)) {
    504  1.1  dholland 			action |= KAUTH_VNODE_HAS_SYSFLAGS;
    505  1.1  dholland 		}
    506  1.1  dholland 
    507  1.1  dholland 		if ((vap->va_flags & UF_SETTABLE) != vap->va_flags) {
    508  1.1  dholland 			action |= KAUTH_VNODE_WRITE_SYSFLAGS;
    509  1.1  dholland 			changing_sysflags = true;
    510  1.1  dholland 		}
    511  1.1  dholland 
    512  1.1  dholland 		error = kauth_authorize_vnode(cred, action, vp, NULL,
    513  1.1  dholland 		    genfs_can_chflags(cred, vp->v_type, ip->i_uid,
    514  1.1  dholland 		    changing_sysflags));
    515  1.1  dholland 		if (error)
    516  1.1  dholland 			goto out;
    517  1.1  dholland 
    518  1.1  dholland 		if (changing_sysflags) {
    519  1.1  dholland 			error = UFS_WAPBL_BEGIN(vp->v_mount);
    520  1.1  dholland 			if (error)
    521  1.1  dholland 				goto out;
    522  1.1  dholland 			ip->i_flags = vap->va_flags;
    523  1.1  dholland 			DIP_ASSIGN(ip, flags, ip->i_flags);
    524  1.1  dholland 		} else {
    525  1.1  dholland 			error = UFS_WAPBL_BEGIN(vp->v_mount);
    526  1.1  dholland 			if (error)
    527  1.1  dholland 				goto out;
    528  1.1  dholland 			ip->i_flags &= SF_SETTABLE;
    529  1.1  dholland 			ip->i_flags |= (vap->va_flags & UF_SETTABLE);
    530  1.1  dholland 			DIP_ASSIGN(ip, flags, ip->i_flags);
    531  1.1  dholland 		}
    532  1.1  dholland 		ip->i_flag |= IN_CHANGE;
    533  1.1  dholland 		UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
    534  1.1  dholland 		UFS_WAPBL_END(vp->v_mount);
    535  1.1  dholland 		if (vap->va_flags & (IMMUTABLE | APPEND)) {
    536  1.1  dholland 			error = 0;
    537  1.1  dholland 			goto out;
    538  1.1  dholland 		}
    539  1.1  dholland 	}
    540  1.1  dholland 	if (ip->i_flags & (IMMUTABLE | APPEND)) {
    541  1.1  dholland 		error = EPERM;
    542  1.1  dholland 		goto out;
    543  1.1  dholland 	}
    544  1.1  dholland 	/*
    545  1.1  dholland 	 * Go through the fields and update iff not VNOVAL.
    546  1.1  dholland 	 */
    547  1.1  dholland 	if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL) {
    548  1.1  dholland 		if (vp->v_mount->mnt_flag & MNT_RDONLY) {
    549  1.1  dholland 			error = EROFS;
    550  1.1  dholland 			goto out;
    551  1.1  dholland 		}
    552  1.1  dholland 		error = UFS_WAPBL_BEGIN(vp->v_mount);
    553  1.1  dholland 		if (error)
    554  1.1  dholland 			goto out;
    555  1.1  dholland 		error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred, l);
    556  1.1  dholland 		UFS_WAPBL_END(vp->v_mount);
    557  1.1  dholland 		if (error)
    558  1.1  dholland 			goto out;
    559  1.1  dholland 	}
    560  1.1  dholland 	if (vap->va_size != VNOVAL) {
    561  1.1  dholland 		/*
    562  1.1  dholland 		 * Disallow write attempts on read-only file systems;
    563  1.1  dholland 		 * unless the file is a socket, fifo, or a block or
    564  1.1  dholland 		 * character device resident on the file system.
    565  1.1  dholland 		 */
    566  1.1  dholland 		switch (vp->v_type) {
    567  1.1  dholland 		case VDIR:
    568  1.1  dholland 			error = EISDIR;
    569  1.1  dholland 			goto out;
    570  1.1  dholland 		case VCHR:
    571  1.1  dholland 		case VBLK:
    572  1.1  dholland 		case VFIFO:
    573  1.1  dholland 			break;
    574  1.1  dholland 		case VREG:
    575  1.1  dholland 			if (vp->v_mount->mnt_flag & MNT_RDONLY) {
    576  1.1  dholland 				error = EROFS;
    577  1.1  dholland 				goto out;
    578  1.1  dholland 			}
    579  1.1  dholland 			if ((ip->i_flags & SF_SNAPSHOT) != 0) {
    580  1.1  dholland 				error = EPERM;
    581  1.1  dholland 				goto out;
    582  1.1  dholland 			}
    583  1.1  dholland 			error = UFS_WAPBL_BEGIN(vp->v_mount);
    584  1.1  dholland 			if (error)
    585  1.1  dholland 				goto out;
    586  1.1  dholland 			/*
    587  1.1  dholland 			 * When journaling, only truncate one indirect block
    588  1.1  dholland 			 * at a time.
    589  1.1  dholland 			 */
    590  1.1  dholland 			if (vp->v_mount->mnt_wapbl) {
    591  1.1  dholland 				uint64_t incr = MNINDIR(ip->i_ump) <<
    592  1.1  dholland 				    vp->v_mount->mnt_fs_bshift; /* Power of 2 */
    593  1.1  dholland 				uint64_t base = UFS_NDADDR <<
    594  1.1  dholland 				    vp->v_mount->mnt_fs_bshift;
    595  1.1  dholland 				while (!error && ip->i_size > base + incr &&
    596  1.1  dholland 				    ip->i_size > vap->va_size + incr) {
    597  1.1  dholland 					/*
    598  1.1  dholland 					 * round down to next full indirect
    599  1.1  dholland 					 * block boundary.
    600  1.1  dholland 					 */
    601  1.1  dholland 					uint64_t nsize = base +
    602  1.1  dholland 					    ((ip->i_size - base - 1) &
    603  1.1  dholland 					    ~(incr - 1));
    604  1.1  dholland 					error = UFS_TRUNCATE(vp, nsize, 0,
    605  1.1  dholland 					    cred);
    606  1.1  dholland 					if (error == 0) {
    607  1.1  dholland 						UFS_WAPBL_END(vp->v_mount);
    608  1.1  dholland 						error =
    609  1.1  dholland 						   UFS_WAPBL_BEGIN(vp->v_mount);
    610  1.1  dholland 					}
    611  1.1  dholland 				}
    612  1.1  dholland 			}
    613  1.1  dholland 			if (!error)
    614  1.1  dholland 				error = UFS_TRUNCATE(vp, vap->va_size, 0, cred);
    615  1.1  dholland 			UFS_WAPBL_END(vp->v_mount);
    616  1.1  dholland 			if (error)
    617  1.1  dholland 				goto out;
    618  1.1  dholland 			break;
    619  1.1  dholland 		default:
    620  1.1  dholland 			error = EOPNOTSUPP;
    621  1.1  dholland 			goto out;
    622  1.1  dholland 		}
    623  1.1  dholland 	}
    624  1.1  dholland 	ip = VTOI(vp);
    625  1.1  dholland 	if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL ||
    626  1.1  dholland 	    vap->va_birthtime.tv_sec != VNOVAL) {
    627  1.1  dholland 		if (vp->v_mount->mnt_flag & MNT_RDONLY) {
    628  1.1  dholland 			error = EROFS;
    629  1.1  dholland 			goto out;
    630  1.1  dholland 		}
    631  1.1  dholland 		if ((ip->i_flags & SF_SNAPSHOT) != 0) {
    632  1.1  dholland 			error = EPERM;
    633  1.1  dholland 			goto out;
    634  1.1  dholland 		}
    635  1.1  dholland 		error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp,
    636  1.1  dholland 		    NULL, genfs_can_chtimes(vp, vap->va_vaflags, ip->i_uid, cred));
    637  1.1  dholland 		if (error)
    638  1.1  dholland 			goto out;
    639  1.1  dholland 		error = UFS_WAPBL_BEGIN(vp->v_mount);
    640  1.1  dholland 		if (error)
    641  1.1  dholland 			goto out;
    642  1.1  dholland 		if (vap->va_atime.tv_sec != VNOVAL)
    643  1.1  dholland 			if (!(vp->v_mount->mnt_flag & MNT_NOATIME))
    644  1.1  dholland 				ip->i_flag |= IN_ACCESS;
    645  1.1  dholland 		if (vap->va_mtime.tv_sec != VNOVAL) {
    646  1.1  dholland 			ip->i_flag |= IN_CHANGE | IN_UPDATE;
    647  1.1  dholland 			if (vp->v_mount->mnt_flag & MNT_RELATIME)
    648  1.1  dholland 				ip->i_flag |= IN_ACCESS;
    649  1.1  dholland 		}
    650  1.1  dholland 		if (vap->va_birthtime.tv_sec != VNOVAL &&
    651  1.1  dholland 		    ip->i_ump->um_fstype == UFS2) {
    652  1.1  dholland 			ip->i_ffs2_birthtime = vap->va_birthtime.tv_sec;
    653  1.1  dholland 			ip->i_ffs2_birthnsec = vap->va_birthtime.tv_nsec;
    654  1.1  dholland 		}
    655  1.1  dholland 		error = UFS_UPDATE(vp, &vap->va_atime, &vap->va_mtime, 0);
    656  1.1  dholland 		UFS_WAPBL_END(vp->v_mount);
    657  1.1  dholland 		if (error)
    658  1.1  dholland 			goto out;
    659  1.1  dholland 	}
    660  1.1  dholland 	error = 0;
    661  1.1  dholland 	if (vap->va_mode != (mode_t)VNOVAL) {
    662  1.1  dholland 		if (vp->v_mount->mnt_flag & MNT_RDONLY) {
    663  1.1  dholland 			error = EROFS;
    664  1.1  dholland 			goto out;
    665  1.1  dholland 		}
    666  1.1  dholland 		if ((ip->i_flags & SF_SNAPSHOT) != 0 &&
    667  1.1  dholland 		    (vap->va_mode & (S_IXUSR | S_IWUSR | S_IXGRP | S_IWGRP |
    668  1.1  dholland 		     S_IXOTH | S_IWOTH))) {
    669  1.1  dholland 			error = EPERM;
    670  1.1  dholland 			goto out;
    671  1.1  dholland 		}
    672  1.1  dholland 		error = UFS_WAPBL_BEGIN(vp->v_mount);
    673  1.1  dholland 		if (error)
    674  1.1  dholland 			goto out;
    675  1.1  dholland 		error = ufs_chmod(vp, (int)vap->va_mode, cred, l);
    676  1.1  dholland 		UFS_WAPBL_END(vp->v_mount);
    677  1.1  dholland 	}
    678  1.1  dholland 	VN_KNOTE(vp, NOTE_ATTRIB);
    679  1.1  dholland out:
    680  1.1  dholland 	fstrans_done(vp->v_mount);
    681  1.1  dholland 	return (error);
    682  1.1  dholland }
    683  1.1  dholland 
    684  1.1  dholland /*
    685  1.1  dholland  * Change the mode on a file.
    686  1.1  dholland  * Inode must be locked before calling.
    687  1.1  dholland  */
    688  1.1  dholland static int
    689  1.1  dholland ufs_chmod(struct vnode *vp, int mode, kauth_cred_t cred, struct lwp *l)
    690  1.1  dholland {
    691  1.1  dholland 	struct inode	*ip;
    692  1.1  dholland 	int		error;
    693  1.1  dholland 
    694  1.1  dholland 	UFS_WAPBL_JLOCK_ASSERT(vp->v_mount);
    695  1.1  dholland 
    696  1.1  dholland 	ip = VTOI(vp);
    697  1.1  dholland 
    698  1.1  dholland 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_SECURITY, vp,
    699  1.1  dholland 	    NULL, genfs_can_chmod(vp->v_type, cred, ip->i_uid, ip->i_gid, mode));
    700  1.1  dholland 	if (error)
    701  1.1  dholland 		return (error);
    702  1.1  dholland 
    703  1.1  dholland 	fstrans_start(vp->v_mount, FSTRANS_SHARED);
    704  1.1  dholland 	ip->i_mode &= ~ALLPERMS;
    705  1.1  dholland 	ip->i_mode |= (mode & ALLPERMS);
    706  1.1  dholland 	ip->i_flag |= IN_CHANGE;
    707  1.1  dholland 	DIP_ASSIGN(ip, mode, ip->i_mode);
    708  1.1  dholland 	UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
    709  1.1  dholland 	fstrans_done(vp->v_mount);
    710  1.1  dholland 	return (0);
    711  1.1  dholland }
    712  1.1  dholland 
    713  1.1  dholland /*
    714  1.1  dholland  * Perform chown operation on inode ip;
    715  1.1  dholland  * inode must be locked prior to call.
    716  1.1  dholland  */
    717  1.1  dholland static int
    718  1.1  dholland ufs_chown(struct vnode *vp, uid_t uid, gid_t gid, kauth_cred_t cred,
    719  1.1  dholland     	struct lwp *l)
    720  1.1  dholland {
    721  1.1  dholland 	struct inode	*ip;
    722  1.1  dholland 	int		error = 0;
    723  1.1  dholland #if defined(QUOTA) || defined(QUOTA2)
    724  1.1  dholland 	uid_t		ouid;
    725  1.1  dholland 	gid_t		ogid;
    726  1.1  dholland 	int64_t		change;
    727  1.1  dholland #endif
    728  1.1  dholland 	ip = VTOI(vp);
    729  1.1  dholland 	error = 0;
    730  1.1  dholland 
    731  1.1  dholland 	if (uid == (uid_t)VNOVAL)
    732  1.1  dholland 		uid = ip->i_uid;
    733  1.1  dholland 	if (gid == (gid_t)VNOVAL)
    734  1.1  dholland 		gid = ip->i_gid;
    735  1.1  dholland 
    736  1.1  dholland 	error = kauth_authorize_vnode(cred, KAUTH_VNODE_CHANGE_OWNERSHIP, vp,
    737  1.1  dholland 	    NULL, genfs_can_chown(cred, ip->i_uid, ip->i_gid, uid, gid));
    738  1.1  dholland 	if (error)
    739  1.1  dholland 		return (error);
    740  1.1  dholland 
    741  1.1  dholland 	fstrans_start(vp->v_mount, FSTRANS_SHARED);
    742  1.1  dholland #if defined(QUOTA) || defined(QUOTA2)
    743  1.1  dholland 	ogid = ip->i_gid;
    744  1.1  dholland 	ouid = ip->i_uid;
    745  1.1  dholland 	change = DIP(ip, blocks);
    746  1.1  dholland 	(void) chkdq(ip, -change, cred, 0);
    747  1.1  dholland 	(void) chkiq(ip, -1, cred, 0);
    748  1.1  dholland #endif
    749  1.1  dholland 	ip->i_gid = gid;
    750  1.1  dholland 	DIP_ASSIGN(ip, gid, gid);
    751  1.1  dholland 	ip->i_uid = uid;
    752  1.1  dholland 	DIP_ASSIGN(ip, uid, uid);
    753  1.1  dholland #if defined(QUOTA) || defined(QUOTA2)
    754  1.1  dholland 	if ((error = chkdq(ip, change, cred, 0)) == 0) {
    755  1.1  dholland 		if ((error = chkiq(ip, 1, cred, 0)) == 0)
    756  1.1  dholland 			goto good;
    757  1.1  dholland 		else
    758  1.1  dholland 			(void) chkdq(ip, -change, cred, FORCE);
    759  1.1  dholland 	}
    760  1.1  dholland 	ip->i_gid = ogid;
    761  1.1  dholland 	DIP_ASSIGN(ip, gid, ogid);
    762  1.1  dholland 	ip->i_uid = ouid;
    763  1.1  dholland 	DIP_ASSIGN(ip, uid, ouid);
    764  1.1  dholland 	(void) chkdq(ip, change, cred, FORCE);
    765  1.1  dholland 	(void) chkiq(ip, 1, cred, FORCE);
    766  1.1  dholland 	fstrans_done(vp->v_mount);
    767  1.1  dholland 	return (error);
    768  1.1  dholland  good:
    769  1.1  dholland #endif /* QUOTA || QUOTA2 */
    770  1.1  dholland 	ip->i_flag |= IN_CHANGE;
    771  1.1  dholland 	UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
    772  1.1  dholland 	fstrans_done(vp->v_mount);
    773  1.1  dholland 	return (0);
    774  1.1  dholland }
    775  1.1  dholland 
    776  1.1  dholland int
    777  1.1  dholland ufs_remove(void *v)
    778  1.1  dholland {
    779  1.1  dholland 	struct vop_remove_args /* {
    780  1.1  dholland 		struct vnode		*a_dvp;
    781  1.1  dholland 		struct vnode		*a_vp;
    782  1.1  dholland 		struct componentname	*a_cnp;
    783  1.1  dholland 	} */ *ap = v;
    784  1.1  dholland 	struct vnode	*vp, *dvp;
    785  1.1  dholland 	struct inode	*ip;
    786  1.1  dholland 	int		error;
    787  1.1  dholland 	struct ufs_lookup_results *ulr;
    788  1.1  dholland 
    789  1.1  dholland 	vp = ap->a_vp;
    790  1.1  dholland 	dvp = ap->a_dvp;
    791  1.1  dholland 	ip = VTOI(vp);
    792  1.1  dholland 
    793  1.1  dholland 	/* XXX should handle this material another way */
    794  1.1  dholland 	ulr = &VTOI(dvp)->i_crap;
    795  1.1  dholland 	UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
    796  1.1  dholland 
    797  1.1  dholland 	fstrans_start(dvp->v_mount, FSTRANS_SHARED);
    798  1.1  dholland 	if (vp->v_type == VDIR || (ip->i_flags & (IMMUTABLE | APPEND)) ||
    799  1.1  dholland 	    (VTOI(dvp)->i_flags & APPEND))
    800  1.1  dholland 		error = EPERM;
    801  1.1  dholland 	else {
    802  1.1  dholland 		error = UFS_WAPBL_BEGIN(dvp->v_mount);
    803  1.1  dholland 		if (error == 0) {
    804  1.1  dholland 			error = ufs_dirremove(dvp, ulr,
    805  1.1  dholland 					      ip, ap->a_cnp->cn_flags, 0);
    806  1.1  dholland 			UFS_WAPBL_END(dvp->v_mount);
    807  1.1  dholland 		}
    808  1.1  dholland 	}
    809  1.1  dholland 	VN_KNOTE(vp, NOTE_DELETE);
    810  1.1  dholland 	VN_KNOTE(dvp, NOTE_WRITE);
    811  1.1  dholland 	if (dvp == vp)
    812  1.1  dholland 		vrele(vp);
    813  1.1  dholland 	else
    814  1.1  dholland 		vput(vp);
    815  1.1  dholland 	vput(dvp);
    816  1.1  dholland 	fstrans_done(dvp->v_mount);
    817  1.1  dholland 	return (error);
    818  1.1  dholland }
    819  1.1  dholland 
    820  1.1  dholland /*
    821  1.1  dholland  * ufs_link: create hard link.
    822  1.1  dholland  */
    823  1.1  dholland int
    824  1.1  dholland ufs_link(void *v)
    825  1.1  dholland {
    826  1.1  dholland 	struct vop_link_args /* {
    827  1.1  dholland 		struct vnode *a_dvp;
    828  1.1  dholland 		struct vnode *a_vp;
    829  1.1  dholland 		struct componentname *a_cnp;
    830  1.1  dholland 	} */ *ap = v;
    831  1.1  dholland 	struct vnode *dvp = ap->a_dvp;
    832  1.1  dholland 	struct vnode *vp = ap->a_vp;
    833  1.1  dholland 	struct componentname *cnp = ap->a_cnp;
    834  1.1  dholland 	struct inode *ip;
    835  1.1  dholland 	struct direct *newdir;
    836  1.1  dholland 	int error;
    837  1.1  dholland 	struct ufs_lookup_results *ulr;
    838  1.1  dholland 
    839  1.1  dholland 	KASSERT(dvp != vp);
    840  1.1  dholland 	KASSERT(vp->v_type != VDIR);
    841  1.1  dholland 	KASSERT(dvp->v_mount == vp->v_mount);
    842  1.1  dholland 
    843  1.1  dholland 	/* XXX should handle this material another way */
    844  1.1  dholland 	ulr = &VTOI(dvp)->i_crap;
    845  1.1  dholland 	UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
    846  1.1  dholland 
    847  1.1  dholland 	fstrans_start(dvp->v_mount, FSTRANS_SHARED);
    848  1.1  dholland 	error = vn_lock(vp, LK_EXCLUSIVE);
    849  1.1  dholland 	if (error) {
    850  1.1  dholland 		VOP_ABORTOP(dvp, cnp);
    851  1.1  dholland 		goto out2;
    852  1.1  dholland 	}
    853  1.1  dholland 	ip = VTOI(vp);
    854  1.1  dholland 	if ((nlink_t)ip->i_nlink >= LINK_MAX) {
    855  1.1  dholland 		VOP_ABORTOP(dvp, cnp);
    856  1.1  dholland 		error = EMLINK;
    857  1.1  dholland 		goto out1;
    858  1.1  dholland 	}
    859  1.1  dholland 	if (ip->i_flags & (IMMUTABLE | APPEND)) {
    860  1.1  dholland 		VOP_ABORTOP(dvp, cnp);
    861  1.1  dholland 		error = EPERM;
    862  1.1  dholland 		goto out1;
    863  1.1  dholland 	}
    864  1.1  dholland 	error = UFS_WAPBL_BEGIN(vp->v_mount);
    865  1.1  dholland 	if (error) {
    866  1.1  dholland 		VOP_ABORTOP(dvp, cnp);
    867  1.1  dholland 		goto out1;
    868  1.1  dholland 	}
    869  1.1  dholland 	ip->i_nlink++;
    870  1.1  dholland 	DIP_ASSIGN(ip, nlink, ip->i_nlink);
    871  1.1  dholland 	ip->i_flag |= IN_CHANGE;
    872  1.1  dholland 	error = UFS_UPDATE(vp, NULL, NULL, UPDATE_DIROP);
    873  1.1  dholland 	if (!error) {
    874  1.1  dholland 		newdir = pool_cache_get(ufs_direct_cache, PR_WAITOK);
    875  1.1  dholland 		ufs_makedirentry(ip, cnp, newdir);
    876  1.1  dholland 		error = ufs_direnter(dvp, ulr, vp, newdir, cnp, NULL);
    877  1.1  dholland 		pool_cache_put(ufs_direct_cache, newdir);
    878  1.1  dholland 	}
    879  1.1  dholland 	if (error) {
    880  1.1  dholland 		ip->i_nlink--;
    881  1.1  dholland 		DIP_ASSIGN(ip, nlink, ip->i_nlink);
    882  1.1  dholland 		ip->i_flag |= IN_CHANGE;
    883  1.1  dholland 		UFS_WAPBL_UPDATE(vp, NULL, NULL, UPDATE_DIROP);
    884  1.1  dholland 	}
    885  1.1  dholland 	UFS_WAPBL_END(vp->v_mount);
    886  1.1  dholland  out1:
    887  1.1  dholland 	VOP_UNLOCK(vp);
    888  1.1  dholland  out2:
    889  1.1  dholland 	VN_KNOTE(vp, NOTE_LINK);
    890  1.1  dholland 	VN_KNOTE(dvp, NOTE_WRITE);
    891  1.1  dholland 	vput(dvp);
    892  1.1  dholland 	fstrans_done(dvp->v_mount);
    893  1.1  dholland 	return (error);
    894  1.1  dholland }
    895  1.1  dholland 
    896  1.1  dholland /*
    897  1.1  dholland  * whiteout vnode call
    898  1.1  dholland  */
    899  1.1  dholland int
    900  1.1  dholland ufs_whiteout(void *v)
    901  1.1  dholland {
    902  1.1  dholland 	struct vop_whiteout_args /* {
    903  1.1  dholland 		struct vnode		*a_dvp;
    904  1.1  dholland 		struct componentname	*a_cnp;
    905  1.1  dholland 		int			a_flags;
    906  1.1  dholland 	} */ *ap = v;
    907  1.1  dholland 	struct vnode		*dvp = ap->a_dvp;
    908  1.1  dholland 	struct componentname	*cnp = ap->a_cnp;
    909  1.1  dholland 	struct direct		*newdir;
    910  1.1  dholland 	int			error;
    911  1.1  dholland 	struct ufsmount		*ump = VFSTOUFS(dvp->v_mount);
    912  1.1  dholland 	struct ufs_lookup_results *ulr;
    913  1.1  dholland 
    914  1.1  dholland 	/* XXX should handle this material another way */
    915  1.1  dholland 	ulr = &VTOI(dvp)->i_crap;
    916  1.1  dholland 	UFS_CHECK_CRAPCOUNTER(VTOI(dvp));
    917  1.1  dholland 
    918  1.1  dholland 	error = 0;
    919  1.1  dholland 	switch (ap->a_flags) {
    920  1.1  dholland 	case LOOKUP:
    921  1.1  dholland 		/* 4.4 format directories support whiteout operations */
    922  1.1  dholland 		if (ump->um_maxsymlinklen > 0)
    923  1.1  dholland 			return (0);
    924  1.1  dholland 		return (EOPNOTSUPP);
    925  1.1  dholland 
    926  1.1  dholland 	case CREATE:
    927  1.1  dholland 		/* create a new directory whiteout */
    928  1.1  dholland 		fstrans_start(dvp->v_mount, FSTRANS_SHARED);
    929  1.1  dholland 		error = UFS_WAPBL_BEGIN(dvp->v_mount);
    930  1.1  dholland 		if (error)
    931  1.1  dholland 			break;
    932  1.1  dholland #ifdef DIAGNOSTIC
    933  1.1  dholland 		if (ump->um_maxsymlinklen <= 0)
    934  1.1  dholland 			panic("ufs_whiteout: old format filesystem");
    935  1.1  dholland #endif
    936  1.1  dholland 
    937  1.1  dholland 		newdir = pool_cache_get(ufs_direct_cache, PR_WAITOK);
    938  1.1  dholland 		newdir->d_ino = UFS_WINO;
    939  1.1  dholland 		newdir->d_namlen = cnp->cn_namelen;
    940  1.1  dholland 		memcpy(newdir->d_name, cnp->cn_nameptr,
    941  1.1  dholland 		    (size_t)cnp->cn_namelen);
    942  1.1  dholland 		newdir->d_name[cnp->cn_namelen] = '\0';
    943  1.1  dholland 		newdir->d_type = DT_WHT;
    944  1.1  dholland 		error = ufs_direnter(dvp, ulr, NULL, newdir, cnp, NULL);
    945  1.1  dholland 		pool_cache_put(ufs_direct_cache, newdir);
    946  1.1  dholland 		break;
    947  1.1  dholland 
    948  1.1  dholland 	case DELETE:
    949  1.1  dholland 		/* remove an existing directory whiteout */
    950  1.1  dholland 		fstrans_start(dvp->v_mount, FSTRANS_SHARED);
    951  1.1  dholland 		error = UFS_WAPBL_BEGIN(dvp->v_mount);
    952  1.1  dholland 		if (error)
    953  1.1  dholland 			break;
    954  1.1  dholland #ifdef DIAGNOSTIC
    955  1.1  dholland 		if (ump->um_maxsymlinklen <= 0)
    956  1.1  dholland 			panic("ufs_whiteout: old format filesystem");
    957  1.1  dholland #endif
    958  1.1  dholland 
    959  1.1  dholland 		cnp->cn_flags &= ~DOWHITEOUT;
    960  1.1  dholland 		error = ufs_dirremove(dvp, ulr, NULL, cnp->cn_flags, 0);
    961  1.1  dholland 		break;
    962  1.1  dholland 	default:
    963  1.1  dholland 		panic("ufs_whiteout: unknown op");
    964  1.1  dholland 		/* NOTREACHED */
    965  1.1  dholland 	}
    966  1.1  dholland 	UFS_WAPBL_END(dvp->v_mount);
    967  1.1  dholland 	fstrans_done(dvp->v_mount);
    968  1.1  dholland 	return (error);
    969  1.1  dholland }
    970  1.1  dholland 
    971  1.1  dholland int
    972  1.1  dholland ufs_mkdir(void *v)
    973  1.1  dholland {
    974  1.1  dholland 	struct vop_mkdir_args /* {
    975  1.1  dholland 		struct vnode		*a_dvp;
    976  1.1  dholland 		struct vnode		**a_vpp;
    977  1.1  dholland 		struct componentname	*a_cnp;
    978  1.1  dholland 		struct vattr		*a_vap;
    979  1.1  dholland 	} */ *ap = v;
    980  1.1  dholland 	struct vnode		*dvp = ap->a_dvp, *tvp;
    981  1.1  dholland 	struct vattr		*vap = ap->a_vap;
    982  1.1  dholland 	struct componentname	*cnp = ap->a_cnp;
    983  1.1  dholland 	struct inode		*ip, *dp = VTOI(dvp);
    984  1.1  dholland 	struct buf		*bp;
    985  1.1  dholland 	struct dirtemplate	dirtemplate;
    986  1.1  dholland 	struct direct		*newdir;
    987  1.1  dholland 	int			error, dmode;
    988  1.1  dholland 	struct ufsmount		*ump = dp->i_ump;
    989  1.1  dholland 	int			dirblksiz = ump->um_dirblksiz;
    990  1.1  dholland 	struct ufs_lookup_results *ulr;
    991  1.1  dholland 
    992  1.1  dholland 	fstrans_start(dvp->v_mount, FSTRANS_SHARED);
    993  1.1  dholland 
    994  1.1  dholland 	/* XXX should handle this material another way */
    995  1.1  dholland 	ulr = &dp->i_crap;
    996  1.1  dholland 	UFS_CHECK_CRAPCOUNTER(dp);
    997  1.1  dholland 
    998  1.1  dholland 	if ((nlink_t)dp->i_nlink >= LINK_MAX) {
    999  1.1  dholland 		error = EMLINK;
   1000  1.1  dholland 		goto out;
   1001  1.1  dholland 	}
   1002  1.1  dholland 	dmode = vap->va_mode & ACCESSPERMS;
   1003  1.1  dholland 	dmode |= IFDIR;
   1004  1.1  dholland 	/*
   1005  1.1  dholland 	 * Must simulate part of ufs_makeinode here to acquire the inode,
   1006  1.1  dholland 	 * but not have it entered in the parent directory. The entry is
   1007  1.1  dholland 	 * made later after writing "." and ".." entries.
   1008  1.1  dholland 	 */
   1009  1.1  dholland 	if ((error = UFS_VALLOC(dvp, dmode, cnp->cn_cred, ap->a_vpp)) != 0)
   1010  1.1  dholland 		goto out;
   1011  1.1  dholland 
   1012  1.1  dholland 	tvp = *ap->a_vpp;
   1013  1.1  dholland 	ip = VTOI(tvp);
   1014  1.1  dholland 
   1015  1.1  dholland 	error = UFS_WAPBL_BEGIN(ap->a_dvp->v_mount);
   1016  1.1  dholland 	if (error) {
   1017  1.1  dholland 		UFS_VFREE(tvp, ip->i_number, dmode);
   1018  1.1  dholland 		vput(tvp);
   1019  1.1  dholland 		goto out;
   1020  1.1  dholland 	}
   1021  1.1  dholland 	ip->i_uid = kauth_cred_geteuid(cnp->cn_cred);
   1022  1.1  dholland 	DIP_ASSIGN(ip, uid, ip->i_uid);
   1023  1.1  dholland 	ip->i_gid = dp->i_gid;
   1024  1.1  dholland 	DIP_ASSIGN(ip, gid, ip->i_gid);
   1025  1.1  dholland #if defined(QUOTA) || defined(QUOTA2)
   1026  1.1  dholland 	if ((error = chkiq(ip, 1, cnp->cn_cred, 0))) {
   1027  1.1  dholland 		UFS_VFREE(tvp, ip->i_number, dmode);
   1028  1.1  dholland 		UFS_WAPBL_END(dvp->v_mount);
   1029  1.1  dholland 		fstrans_done(dvp->v_mount);
   1030  1.1  dholland 		vput(tvp);
   1031  1.1  dholland 		vput(dvp);
   1032  1.1  dholland 		return (error);
   1033  1.1  dholland 	}
   1034  1.1  dholland #endif
   1035  1.1  dholland 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
   1036  1.1  dholland 	ip->i_mode = dmode;
   1037  1.1  dholland 	DIP_ASSIGN(ip, mode, dmode);
   1038  1.1  dholland 	tvp->v_type = VDIR;	/* Rest init'd in getnewvnode(). */
   1039  1.1  dholland 	ip->i_nlink = 2;
   1040  1.1  dholland 	DIP_ASSIGN(ip, nlink, 2);
   1041  1.1  dholland 	if (cnp->cn_flags & ISWHITEOUT) {
   1042  1.1  dholland 		ip->i_flags |= UF_OPAQUE;
   1043  1.1  dholland 		DIP_ASSIGN(ip, flags, ip->i_flags);
   1044  1.1  dholland 	}
   1045  1.1  dholland 
   1046  1.1  dholland 	/*
   1047  1.1  dholland 	 * Bump link count in parent directory to reflect work done below.
   1048  1.1  dholland 	 * Should be done before reference is created so cleanup is
   1049  1.1  dholland 	 * possible if we crash.
   1050  1.1  dholland 	 */
   1051  1.1  dholland 	dp->i_nlink++;
   1052  1.1  dholland 	DIP_ASSIGN(dp, nlink, dp->i_nlink);
   1053  1.1  dholland 	dp->i_flag |= IN_CHANGE;
   1054  1.1  dholland 	if ((error = UFS_UPDATE(dvp, NULL, NULL, UPDATE_DIROP)) != 0)
   1055  1.1  dholland 		goto bad;
   1056  1.1  dholland 
   1057  1.1  dholland 	/*
   1058  1.1  dholland 	 * Initialize directory with "." and ".." from static template.
   1059  1.1  dholland 	 */
   1060  1.1  dholland 	dirtemplate = mastertemplate;
   1061  1.1  dholland 	dirtemplate.dotdot_reclen = dirblksiz - dirtemplate.dot_reclen;
   1062  1.1  dholland 	dirtemplate.dot_ino = ufs_rw32(ip->i_number, UFS_MPNEEDSWAP(ump));
   1063  1.1  dholland 	dirtemplate.dotdot_ino = ufs_rw32(dp->i_number, UFS_MPNEEDSWAP(ump));
   1064  1.1  dholland 	dirtemplate.dot_reclen = ufs_rw16(dirtemplate.dot_reclen,
   1065  1.1  dholland 	    UFS_MPNEEDSWAP(ump));
   1066  1.1  dholland 	dirtemplate.dotdot_reclen = ufs_rw16(dirtemplate.dotdot_reclen,
   1067  1.1  dholland 	    UFS_MPNEEDSWAP(ump));
   1068  1.1  dholland 	if (ump->um_maxsymlinklen <= 0) {
   1069  1.1  dholland #if BYTE_ORDER == LITTLE_ENDIAN
   1070  1.1  dholland 		if (UFS_MPNEEDSWAP(ump) == 0)
   1071  1.1  dholland #else
   1072  1.1  dholland 		if (UFS_MPNEEDSWAP(ump) != 0)
   1073  1.1  dholland #endif
   1074  1.1  dholland 		{
   1075  1.1  dholland 			dirtemplate.dot_type = dirtemplate.dot_namlen;
   1076  1.1  dholland 			dirtemplate.dotdot_type = dirtemplate.dotdot_namlen;
   1077  1.1  dholland 			dirtemplate.dot_namlen = dirtemplate.dotdot_namlen = 0;
   1078  1.1  dholland 		} else
   1079  1.1  dholland 			dirtemplate.dot_type = dirtemplate.dotdot_type = 0;
   1080  1.1  dholland 	}
   1081  1.1  dholland 	if ((error = UFS_BALLOC(tvp, (off_t)0, dirblksiz, cnp->cn_cred,
   1082  1.1  dholland 	    B_CLRBUF, &bp)) != 0)
   1083  1.1  dholland 		goto bad;
   1084  1.1  dholland 	ip->i_size = dirblksiz;
   1085  1.1  dholland 	DIP_ASSIGN(ip, size, dirblksiz);
   1086  1.1  dholland 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
   1087  1.1  dholland 	uvm_vnp_setsize(tvp, ip->i_size);
   1088  1.1  dholland 	memcpy((void *)bp->b_data, (void *)&dirtemplate, sizeof dirtemplate);
   1089  1.1  dholland 
   1090  1.1  dholland 	/*
   1091  1.1  dholland 	 * Directory set up, now install it's entry in the parent directory.
   1092  1.1  dholland 	 * We must write out the buffer containing the new directory body
   1093  1.1  dholland 	 * before entering the new name in the parent.
   1094  1.1  dholland 	 */
   1095  1.1  dholland 	if ((error = VOP_BWRITE(bp->b_vp, bp)) != 0)
   1096  1.1  dholland 		goto bad;
   1097  1.1  dholland 	if ((error = UFS_UPDATE(tvp, NULL, NULL, UPDATE_DIROP)) != 0) {
   1098  1.1  dholland 		goto bad;
   1099  1.1  dholland 	}
   1100  1.1  dholland 	newdir = pool_cache_get(ufs_direct_cache, PR_WAITOK);
   1101  1.1  dholland 	ufs_makedirentry(ip, cnp, newdir);
   1102  1.1  dholland 	error = ufs_direnter(dvp, ulr, tvp, newdir, cnp, bp);
   1103  1.1  dholland 	pool_cache_put(ufs_direct_cache, newdir);
   1104  1.1  dholland  bad:
   1105  1.1  dholland 	if (error == 0) {
   1106  1.1  dholland 		VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
   1107  1.1  dholland 		UFS_WAPBL_END(dvp->v_mount);
   1108  1.1  dholland 	} else {
   1109  1.1  dholland 		dp->i_nlink--;
   1110  1.1  dholland 		DIP_ASSIGN(dp, nlink, dp->i_nlink);
   1111  1.1  dholland 		dp->i_flag |= IN_CHANGE;
   1112  1.1  dholland 		UFS_WAPBL_UPDATE(dvp, NULL, NULL, UPDATE_DIROP);
   1113  1.1  dholland 		/*
   1114  1.1  dholland 		 * No need to do an explicit UFS_TRUNCATE here, vrele will
   1115  1.1  dholland 		 * do this for us because we set the link count to 0.
   1116  1.1  dholland 		 */
   1117  1.1  dholland 		ip->i_nlink = 0;
   1118  1.1  dholland 		DIP_ASSIGN(ip, nlink, 0);
   1119  1.1  dholland 		ip->i_flag |= IN_CHANGE;
   1120  1.1  dholland 		/* If IN_ADIROP, account for it */
   1121  1.1  dholland 		UFS_UNMARK_VNODE(tvp);
   1122  1.1  dholland 		UFS_WAPBL_UPDATE(tvp, NULL, NULL, UPDATE_DIROP);
   1123  1.1  dholland 		UFS_WAPBL_END(dvp->v_mount);
   1124  1.1  dholland 		vput(tvp);
   1125  1.1  dholland 	}
   1126  1.1  dholland  out:
   1127  1.1  dholland 	fstrans_done(dvp->v_mount);
   1128  1.1  dholland 	vput(dvp);
   1129  1.1  dholland 	return (error);
   1130  1.1  dholland }
   1131  1.1  dholland 
   1132  1.1  dholland int
   1133  1.1  dholland ufs_rmdir(void *v)
   1134  1.1  dholland {
   1135  1.1  dholland 	struct vop_rmdir_args /* {
   1136  1.1  dholland 		struct vnode		*a_dvp;
   1137  1.1  dholland 		struct vnode		*a_vp;
   1138  1.1  dholland 		struct componentname	*a_cnp;
   1139  1.1  dholland 	} */ *ap = v;
   1140  1.1  dholland 	struct vnode		*vp, *dvp;
   1141  1.1  dholland 	struct componentname	*cnp;
   1142  1.1  dholland 	struct inode		*ip, *dp;
   1143  1.1  dholland 	int			error;
   1144  1.1  dholland 	struct ufs_lookup_results *ulr;
   1145  1.1  dholland 
   1146  1.1  dholland 	vp = ap->a_vp;
   1147  1.1  dholland 	dvp = ap->a_dvp;
   1148  1.1  dholland 	cnp = ap->a_cnp;
   1149  1.1  dholland 	ip = VTOI(vp);
   1150  1.1  dholland 	dp = VTOI(dvp);
   1151  1.1  dholland 
   1152  1.1  dholland 	/* XXX should handle this material another way */
   1153  1.1  dholland 	ulr = &dp->i_crap;
   1154  1.1  dholland 	UFS_CHECK_CRAPCOUNTER(dp);
   1155  1.1  dholland 
   1156  1.1  dholland 	/*
   1157  1.1  dholland 	 * No rmdir "." or of mounted directories please.
   1158  1.1  dholland 	 */
   1159  1.1  dholland 	if (dp == ip || vp->v_mountedhere != NULL) {
   1160  1.1  dholland 		if (dp == ip)
   1161  1.1  dholland 			vrele(dvp);
   1162  1.1  dholland 		else
   1163  1.1  dholland 			vput(dvp);
   1164  1.1  dholland 		vput(vp);
   1165  1.1  dholland 		return (EINVAL);
   1166  1.1  dholland 	}
   1167  1.1  dholland 
   1168  1.1  dholland 	fstrans_start(dvp->v_mount, FSTRANS_SHARED);
   1169  1.1  dholland 
   1170  1.1  dholland 	/*
   1171  1.1  dholland 	 * Do not remove a directory that is in the process of being renamed.
   1172  1.1  dholland 	 * Verify that the directory is empty (and valid). (Rmdir ".." won't
   1173  1.1  dholland 	 * be valid since ".." will contain a reference to the current
   1174  1.1  dholland 	 * directory and thus be non-empty.)
   1175  1.1  dholland 	 */
   1176  1.1  dholland 	error = 0;
   1177  1.1  dholland 	if (ip->i_nlink != 2 ||
   1178  1.1  dholland 	    !ufs_dirempty(ip, dp->i_number, cnp->cn_cred)) {
   1179  1.1  dholland 		error = ENOTEMPTY;
   1180  1.1  dholland 		goto out;
   1181  1.1  dholland 	}
   1182  1.1  dholland 	if ((dp->i_flags & APPEND) ||
   1183  1.1  dholland 		(ip->i_flags & (IMMUTABLE | APPEND))) {
   1184  1.1  dholland 		error = EPERM;
   1185  1.1  dholland 		goto out;
   1186  1.1  dholland 	}
   1187  1.1  dholland 	error = UFS_WAPBL_BEGIN(dvp->v_mount);
   1188  1.1  dholland 	if (error)
   1189  1.1  dholland 		goto out;
   1190  1.1  dholland 	/*
   1191  1.1  dholland 	 * Delete reference to directory before purging
   1192  1.1  dholland 	 * inode.  If we crash in between, the directory
   1193  1.1  dholland 	 * will be reattached to lost+found,
   1194  1.1  dholland 	 */
   1195  1.1  dholland 	error = ufs_dirremove(dvp, ulr, ip, cnp->cn_flags, 1);
   1196  1.1  dholland 	if (error) {
   1197  1.1  dholland 		UFS_WAPBL_END(dvp->v_mount);
   1198  1.1  dholland 		goto out;
   1199  1.1  dholland 	}
   1200  1.1  dholland 	VN_KNOTE(dvp, NOTE_WRITE | NOTE_LINK);
   1201  1.1  dholland 	cache_purge(dvp);
   1202  1.1  dholland 	/*
   1203  1.1  dholland 	 * Truncate inode.  The only stuff left in the directory is "." and
   1204  1.1  dholland 	 * "..".  The "." reference is inconsequential since we're quashing
   1205  1.1  dholland 	 * it.
   1206  1.1  dholland 	 */
   1207  1.1  dholland 	dp->i_nlink--;
   1208  1.1  dholland 	DIP_ASSIGN(dp, nlink, dp->i_nlink);
   1209  1.1  dholland 	dp->i_flag |= IN_CHANGE;
   1210  1.1  dholland 	UFS_WAPBL_UPDATE(dvp, NULL, NULL, UPDATE_DIROP);
   1211  1.1  dholland 	ip->i_nlink--;
   1212  1.1  dholland 	DIP_ASSIGN(ip, nlink, ip->i_nlink);
   1213  1.1  dholland 	ip->i_flag |= IN_CHANGE;
   1214  1.1  dholland 	error = UFS_TRUNCATE(vp, (off_t)0, IO_SYNC, cnp->cn_cred);
   1215  1.1  dholland 	cache_purge(vp);
   1216  1.1  dholland 	/*
   1217  1.1  dholland 	 * Unlock the log while we still have reference to unlinked
   1218  1.1  dholland 	 * directory vp so that it will not get locked for recycling
   1219  1.1  dholland 	 */
   1220  1.1  dholland 	UFS_WAPBL_END(dvp->v_mount);
   1221  1.1  dholland #ifdef UFS_DIRHASH
   1222  1.1  dholland 	if (ip->i_dirhash != NULL)
   1223  1.1  dholland 		ufsdirhash_free(ip);
   1224  1.1  dholland #endif
   1225  1.1  dholland  out:
   1226  1.1  dholland 	VN_KNOTE(vp, NOTE_DELETE);
   1227  1.1  dholland 	vput(vp);
   1228  1.1  dholland 	fstrans_done(dvp->v_mount);
   1229  1.1  dholland 	vput(dvp);
   1230  1.1  dholland 	return (error);
   1231  1.1  dholland }
   1232  1.1  dholland 
   1233  1.1  dholland /*
   1234  1.1  dholland  * symlink -- make a symbolic link
   1235  1.1  dholland  */
   1236  1.1  dholland int
   1237  1.1  dholland ufs_symlink(void *v)
   1238  1.1  dholland {
   1239  1.1  dholland 	struct vop_symlink_args /* {
   1240  1.1  dholland 		struct vnode		*a_dvp;
   1241  1.1  dholland 		struct vnode		**a_vpp;
   1242  1.1  dholland 		struct componentname	*a_cnp;
   1243  1.1  dholland 		struct vattr		*a_vap;
   1244  1.1  dholland 		char			*a_target;
   1245  1.1  dholland 	} */ *ap = v;
   1246  1.1  dholland 	struct vnode	*vp, **vpp;
   1247  1.1  dholland 	struct inode	*ip;
   1248  1.1  dholland 	int		len, error;
   1249  1.1  dholland 	struct ufs_lookup_results *ulr;
   1250  1.1  dholland 
   1251  1.1  dholland 	vpp = ap->a_vpp;
   1252  1.1  dholland 
   1253  1.1  dholland 	/* XXX should handle this material another way */
   1254  1.1  dholland 	ulr = &VTOI(ap->a_dvp)->i_crap;
   1255  1.1  dholland 	UFS_CHECK_CRAPCOUNTER(VTOI(ap->a_dvp));
   1256  1.1  dholland 
   1257  1.1  dholland 	/*
   1258  1.1  dholland 	 * UFS_WAPBL_BEGIN1(dvp->v_mount, dvp) performed by successful
   1259  1.1  dholland 	 * ufs_makeinode
   1260  1.1  dholland 	 */
   1261  1.1  dholland 	fstrans_start(ap->a_dvp->v_mount, FSTRANS_SHARED);
   1262  1.1  dholland 	error = ufs_makeinode(IFLNK | ap->a_vap->va_mode, ap->a_dvp, ulr,
   1263  1.1  dholland 			      vpp, ap->a_cnp);
   1264  1.1  dholland 	if (error)
   1265  1.1  dholland 		goto out;
   1266  1.1  dholland 	VN_KNOTE(ap->a_dvp, NOTE_WRITE);
   1267  1.1  dholland 	vp = *vpp;
   1268  1.1  dholland 	len = strlen(ap->a_target);
   1269  1.1  dholland 	ip = VTOI(vp);
   1270  1.1  dholland 	if (len < ip->i_ump->um_maxsymlinklen) {
   1271  1.1  dholland 		memcpy((char *)SHORTLINK(ip), ap->a_target, len);
   1272  1.1  dholland 		ip->i_size = len;
   1273  1.1  dholland 		DIP_ASSIGN(ip, size, len);
   1274  1.1  dholland 		uvm_vnp_setsize(vp, ip->i_size);
   1275  1.1  dholland 		ip->i_flag |= IN_CHANGE | IN_UPDATE;
   1276  1.1  dholland 		if (vp->v_mount->mnt_flag & MNT_RELATIME)
   1277  1.1  dholland 			ip->i_flag |= IN_ACCESS;
   1278  1.1  dholland 		UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
   1279  1.1  dholland 	} else
   1280  1.1  dholland 		error = vn_rdwr(UIO_WRITE, vp, ap->a_target, len, (off_t)0,
   1281  1.1  dholland 		    UIO_SYSSPACE, IO_NODELOCKED | IO_JOURNALLOCKED,
   1282  1.1  dholland 		    ap->a_cnp->cn_cred, NULL, NULL);
   1283  1.1  dholland 	UFS_WAPBL_END1(ap->a_dvp->v_mount, ap->a_dvp);
   1284  1.1  dholland 	if (error)
   1285  1.1  dholland 		vput(vp);
   1286  1.1  dholland out:
   1287  1.1  dholland 	fstrans_done(ap->a_dvp->v_mount);
   1288  1.1  dholland 	return (error);
   1289  1.1  dholland }
   1290  1.1  dholland 
   1291  1.1  dholland /*
   1292  1.1  dholland  * Vnode op for reading directories.
   1293  1.1  dholland  *
   1294  1.1  dholland  * This routine handles converting from the on-disk directory format
   1295  1.1  dholland  * "struct direct" to the in-memory format "struct dirent" as well as
   1296  1.1  dholland  * byte swapping the entries if necessary.
   1297  1.1  dholland  */
   1298  1.1  dholland int
   1299  1.1  dholland ufs_readdir(void *v)
   1300  1.1  dholland {
   1301  1.1  dholland 	struct vop_readdir_args /* {
   1302  1.1  dholland 		struct vnode	*a_vp;
   1303  1.1  dholland 		struct uio	*a_uio;
   1304  1.1  dholland 		kauth_cred_t	a_cred;
   1305  1.1  dholland 		int		*a_eofflag;
   1306  1.1  dholland 		off_t		**a_cookies;
   1307  1.1  dholland 		int		*ncookies;
   1308  1.1  dholland 	} */ *ap = v;
   1309  1.1  dholland 	struct vnode	*vp = ap->a_vp;
   1310  1.1  dholland 	struct direct	*cdp, *ecdp;
   1311  1.1  dholland 	struct dirent	*ndp;
   1312  1.1  dholland 	char		*cdbuf, *ndbuf, *endp;
   1313  1.1  dholland 	struct uio	auio, *uio;
   1314  1.1  dholland 	struct iovec	aiov;
   1315  1.1  dholland 	int		error;
   1316  1.1  dholland 	size_t		count, ccount, rcount, cdbufsz, ndbufsz;
   1317  1.1  dholland 	off_t		off, *ccp;
   1318  1.1  dholland 	off_t		startoff;
   1319  1.1  dholland 	size_t		skipbytes;
   1320  1.1  dholland 	struct ufsmount	*ump = VFSTOUFS(vp->v_mount);
   1321  1.1  dholland 	int nswap = UFS_MPNEEDSWAP(ump);
   1322  1.1  dholland #if BYTE_ORDER == LITTLE_ENDIAN
   1323  1.1  dholland 	int needswap = ump->um_maxsymlinklen <= 0 && nswap == 0;
   1324  1.1  dholland #else
   1325  1.1  dholland 	int needswap = ump->um_maxsymlinklen <= 0 && nswap != 0;
   1326  1.1  dholland #endif
   1327  1.1  dholland 	uio = ap->a_uio;
   1328  1.1  dholland 	count = uio->uio_resid;
   1329  1.1  dholland 	rcount = count - ((uio->uio_offset + count) & (ump->um_dirblksiz - 1));
   1330  1.1  dholland 
   1331  1.1  dholland 	if (rcount < _DIRENT_MINSIZE(cdp) || count < _DIRENT_MINSIZE(ndp))
   1332  1.1  dholland 		return EINVAL;
   1333  1.1  dholland 
   1334  1.1  dholland 	startoff = uio->uio_offset & ~(ump->um_dirblksiz - 1);
   1335  1.1  dholland 	skipbytes = uio->uio_offset - startoff;
   1336  1.1  dholland 	rcount += skipbytes;
   1337  1.1  dholland 
   1338  1.1  dholland 	auio.uio_iov = &aiov;
   1339  1.1  dholland 	auio.uio_iovcnt = 1;
   1340  1.1  dholland 	auio.uio_offset = startoff;
   1341  1.1  dholland 	auio.uio_resid = rcount;
   1342  1.1  dholland 	UIO_SETUP_SYSSPACE(&auio);
   1343  1.1  dholland 	auio.uio_rw = UIO_READ;
   1344  1.1  dholland 	cdbufsz = rcount;
   1345  1.1  dholland 	cdbuf = kmem_alloc(cdbufsz, KM_SLEEP);
   1346  1.1  dholland 	aiov.iov_base = cdbuf;
   1347  1.1  dholland 	aiov.iov_len = rcount;
   1348  1.1  dholland 	error = VOP_READ(vp, &auio, 0, ap->a_cred);
   1349  1.1  dholland 	if (error != 0) {
   1350  1.1  dholland 		kmem_free(cdbuf, cdbufsz);
   1351  1.1  dholland 		return error;
   1352  1.1  dholland 	}
   1353  1.1  dholland 
   1354  1.1  dholland 	rcount -= auio.uio_resid;
   1355  1.1  dholland 
   1356  1.1  dholland 	cdp = (struct direct *)(void *)cdbuf;
   1357  1.1  dholland 	ecdp = (struct direct *)(void *)&cdbuf[rcount];
   1358  1.1  dholland 
   1359  1.1  dholland 	ndbufsz = count;
   1360  1.1  dholland 	ndbuf = kmem_alloc(ndbufsz, KM_SLEEP);
   1361  1.1  dholland 	ndp = (struct dirent *)(void *)ndbuf;
   1362  1.1  dholland 	endp = &ndbuf[count];
   1363  1.1  dholland 
   1364  1.1  dholland 	off = uio->uio_offset;
   1365  1.1  dholland 	if (ap->a_cookies) {
   1366  1.1  dholland 		ccount = rcount / _DIRENT_RECLEN(cdp, 1);
   1367  1.1  dholland 		ccp = *(ap->a_cookies) = malloc(ccount * sizeof(*ccp),
   1368  1.1  dholland 		    M_TEMP, M_WAITOK);
   1369  1.1  dholland 	} else {
   1370  1.1  dholland 		/* XXX: GCC */
   1371  1.1  dholland 		ccount = 0;
   1372  1.1  dholland 		ccp = NULL;
   1373  1.1  dholland 	}
   1374  1.1  dholland 
   1375  1.1  dholland 	while (cdp < ecdp) {
   1376  1.1  dholland 		cdp->d_reclen = ufs_rw16(cdp->d_reclen, nswap);
   1377  1.1  dholland 		if (skipbytes > 0) {
   1378  1.1  dholland 			if (cdp->d_reclen <= skipbytes) {
   1379  1.1  dholland 				skipbytes -= cdp->d_reclen;
   1380  1.1  dholland 				cdp = _DIRENT_NEXT(cdp);
   1381  1.1  dholland 				continue;
   1382  1.1  dholland 			}
   1383  1.1  dholland 			/*
   1384  1.1  dholland 			 * invalid cookie.
   1385  1.1  dholland 			 */
   1386  1.1  dholland 			error = EINVAL;
   1387  1.1  dholland 			goto out;
   1388  1.1  dholland 		}
   1389  1.1  dholland 		if (cdp->d_reclen == 0) {
   1390  1.1  dholland 			struct dirent *ondp = ndp;
   1391  1.1  dholland 			ndp->d_reclen = _DIRENT_MINSIZE(ndp);
   1392  1.1  dholland 			ndp = _DIRENT_NEXT(ndp);
   1393  1.1  dholland 			ondp->d_reclen = 0;
   1394  1.1  dholland 			cdp = ecdp;
   1395  1.1  dholland 			break;
   1396  1.1  dholland 		}
   1397  1.1  dholland 		if (needswap) {
   1398  1.1  dholland 			ndp->d_type = cdp->d_namlen;
   1399  1.1  dholland 			ndp->d_namlen = cdp->d_type;
   1400  1.1  dholland 		} else {
   1401  1.1  dholland 			ndp->d_type = cdp->d_type;
   1402  1.1  dholland 			ndp->d_namlen = cdp->d_namlen;
   1403  1.1  dholland 		}
   1404  1.1  dholland 		ndp->d_reclen = _DIRENT_RECLEN(ndp, ndp->d_namlen);
   1405  1.1  dholland 		if ((char *)(void *)ndp + ndp->d_reclen +
   1406  1.1  dholland 		    _DIRENT_MINSIZE(ndp) > endp)
   1407  1.1  dholland 			break;
   1408  1.1  dholland 		ndp->d_fileno = ufs_rw32(cdp->d_ino, nswap);
   1409  1.1  dholland 		(void)memcpy(ndp->d_name, cdp->d_name, ndp->d_namlen);
   1410  1.1  dholland 		memset(&ndp->d_name[ndp->d_namlen], 0,
   1411  1.1  dholland 		    ndp->d_reclen - _DIRENT_NAMEOFF(ndp) - ndp->d_namlen);
   1412  1.1  dholland 		off += cdp->d_reclen;
   1413  1.1  dholland 		if (ap->a_cookies) {
   1414  1.1  dholland 			KASSERT(ccp - *(ap->a_cookies) < ccount);
   1415  1.1  dholland 			*(ccp++) = off;
   1416  1.1  dholland 		}
   1417  1.1  dholland 		ndp = _DIRENT_NEXT(ndp);
   1418  1.1  dholland 		cdp = _DIRENT_NEXT(cdp);
   1419  1.1  dholland 	}
   1420  1.1  dholland 
   1421  1.1  dholland 	count = ((char *)(void *)ndp - ndbuf);
   1422  1.1  dholland 	error = uiomove(ndbuf, count, uio);
   1423  1.1  dholland out:
   1424  1.1  dholland 	if (ap->a_cookies) {
   1425  1.1  dholland 		if (error) {
   1426  1.1  dholland 			free(*(ap->a_cookies), M_TEMP);
   1427  1.1  dholland 			*(ap->a_cookies) = NULL;
   1428  1.1  dholland 			*(ap->a_ncookies) = 0;
   1429  1.1  dholland 		} else {
   1430  1.1  dholland 			*ap->a_ncookies = ccp - *(ap->a_cookies);
   1431  1.1  dholland 		}
   1432  1.1  dholland 	}
   1433  1.1  dholland 	uio->uio_offset = off;
   1434  1.1  dholland 	kmem_free(ndbuf, ndbufsz);
   1435  1.1  dholland 	kmem_free(cdbuf, cdbufsz);
   1436  1.1  dholland 	*ap->a_eofflag = VTOI(vp)->i_size <= uio->uio_offset;
   1437  1.1  dholland 	return error;
   1438  1.1  dholland }
   1439  1.1  dholland 
   1440  1.1  dholland /*
   1441  1.1  dholland  * Return target name of a symbolic link
   1442  1.1  dholland  */
   1443  1.1  dholland int
   1444  1.1  dholland ufs_readlink(void *v)
   1445  1.1  dholland {
   1446  1.1  dholland 	struct vop_readlink_args /* {
   1447  1.1  dholland 		struct vnode	*a_vp;
   1448  1.1  dholland 		struct uio	*a_uio;
   1449  1.1  dholland 		kauth_cred_t	a_cred;
   1450  1.1  dholland 	} */ *ap = v;
   1451  1.1  dholland 	struct vnode	*vp = ap->a_vp;
   1452  1.1  dholland 	struct inode	*ip = VTOI(vp);
   1453  1.1  dholland 	struct ufsmount	*ump = VFSTOUFS(vp->v_mount);
   1454  1.1  dholland 	int		isize;
   1455  1.1  dholland 
   1456  1.1  dholland 	isize = ip->i_size;
   1457  1.1  dholland 	if (isize < ump->um_maxsymlinklen ||
   1458  1.1  dholland 	    (ump->um_maxsymlinklen == 0 && DIP(ip, blocks) == 0)) {
   1459  1.1  dholland 		uiomove((char *)SHORTLINK(ip), isize, ap->a_uio);
   1460  1.1  dholland 		return (0);
   1461  1.1  dholland 	}
   1462  1.1  dholland 	return (VOP_READ(vp, ap->a_uio, 0, ap->a_cred));
   1463  1.1  dholland }
   1464  1.1  dholland 
   1465  1.1  dholland /*
   1466  1.1  dholland  * Calculate the logical to physical mapping if not done already,
   1467  1.1  dholland  * then call the device strategy routine.
   1468  1.1  dholland  */
   1469  1.1  dholland int
   1470  1.1  dholland ufs_strategy(void *v)
   1471  1.1  dholland {
   1472  1.1  dholland 	struct vop_strategy_args /* {
   1473  1.1  dholland 		struct vnode *a_vp;
   1474  1.1  dholland 		struct buf *a_bp;
   1475  1.1  dholland 	} */ *ap = v;
   1476  1.1  dholland 	struct buf	*bp;
   1477  1.1  dholland 	struct vnode	*vp;
   1478  1.1  dholland 	struct inode	*ip;
   1479  1.1  dholland 	struct mount	*mp;
   1480  1.1  dholland 	int		error;
   1481  1.1  dholland 
   1482  1.1  dholland 	bp = ap->a_bp;
   1483  1.1  dholland 	vp = ap->a_vp;
   1484  1.1  dholland 	ip = VTOI(vp);
   1485  1.1  dholland 	if (vp->v_type == VBLK || vp->v_type == VCHR)
   1486  1.1  dholland 		panic("ufs_strategy: spec");
   1487  1.1  dholland 	KASSERT(bp->b_bcount != 0);
   1488  1.1  dholland 	if (bp->b_blkno == bp->b_lblkno) {
   1489  1.1  dholland 		error = VOP_BMAP(vp, bp->b_lblkno, NULL, &bp->b_blkno,
   1490  1.1  dholland 				 NULL);
   1491  1.1  dholland 		if (error) {
   1492  1.1  dholland 			bp->b_error = error;
   1493  1.1  dholland 			biodone(bp);
   1494  1.1  dholland 			return (error);
   1495  1.1  dholland 		}
   1496  1.1  dholland 		if (bp->b_blkno == -1) /* no valid data */
   1497  1.1  dholland 			clrbuf(bp);
   1498  1.1  dholland 	}
   1499  1.1  dholland 	if (bp->b_blkno < 0) { /* block is not on disk */
   1500  1.1  dholland 		biodone(bp);
   1501  1.1  dholland 		return (0);
   1502  1.1  dholland 	}
   1503  1.1  dholland 	vp = ip->i_devvp;
   1504  1.1  dholland 
   1505  1.1  dholland 	error = VOP_STRATEGY(vp, bp);
   1506  1.1  dholland 	if (error)
   1507  1.1  dholland 		return error;
   1508  1.1  dholland 
   1509  1.1  dholland 	if (!BUF_ISREAD(bp))
   1510  1.1  dholland 		return 0;
   1511  1.1  dholland 
   1512  1.1  dholland 	mp = wapbl_vptomp(vp);
   1513  1.1  dholland 	if (mp == NULL || mp->mnt_wapbl_replay == NULL ||
   1514  1.1  dholland 	    !WAPBL_REPLAY_ISOPEN(mp) ||
   1515  1.1  dholland 	    !WAPBL_REPLAY_CAN_READ(mp, bp->b_blkno, bp->b_bcount))
   1516  1.1  dholland 		return 0;
   1517  1.1  dholland 
   1518  1.1  dholland 	error = biowait(bp);
   1519  1.1  dholland 	if (error)
   1520  1.1  dholland 		return error;
   1521  1.1  dholland 
   1522  1.1  dholland 	error = WAPBL_REPLAY_READ(mp, bp->b_data, bp->b_blkno, bp->b_bcount);
   1523  1.1  dholland 	if (error) {
   1524  1.1  dholland 		mutex_enter(&bufcache_lock);
   1525  1.1  dholland 		SET(bp->b_cflags, BC_INVAL);
   1526  1.1  dholland 		mutex_exit(&bufcache_lock);
   1527  1.1  dholland 	}
   1528  1.1  dholland 	return error;
   1529  1.1  dholland }
   1530  1.1  dholland 
   1531  1.1  dholland /*
   1532  1.1  dholland  * Print out the contents of an inode.
   1533  1.1  dholland  */
   1534  1.1  dholland int
   1535  1.1  dholland ufs_print(void *v)
   1536  1.1  dholland {
   1537  1.1  dholland 	struct vop_print_args /* {
   1538  1.1  dholland 		struct vnode	*a_vp;
   1539  1.1  dholland 	} */ *ap = v;
   1540  1.1  dholland 	struct vnode	*vp;
   1541  1.1  dholland 	struct inode	*ip;
   1542  1.1  dholland 
   1543  1.1  dholland 	vp = ap->a_vp;
   1544  1.1  dholland 	ip = VTOI(vp);
   1545  1.1  dholland 	printf("tag VT_UFS, ino %llu, on dev %llu, %llu",
   1546  1.1  dholland 	    (unsigned long long)ip->i_number,
   1547  1.1  dholland 	    (unsigned long long)major(ip->i_dev),
   1548  1.1  dholland 	    (unsigned long long)minor(ip->i_dev));
   1549  1.1  dholland 	printf(" flags 0x%x, nlink %d\n",
   1550  1.1  dholland 	    ip->i_flag, ip->i_nlink);
   1551  1.1  dholland 	printf("\tmode 0%o, owner %d, group %d, size %qd",
   1552  1.1  dholland 	    ip->i_mode, ip->i_uid, ip->i_gid,
   1553  1.1  dholland 	    (long long)ip->i_size);
   1554  1.1  dholland 	if (vp->v_type == VFIFO)
   1555  1.1  dholland 		VOCALL(fifo_vnodeop_p, VOFFSET(vop_print), v);
   1556  1.1  dholland 	printf("\n");
   1557  1.1  dholland 	return (0);
   1558  1.1  dholland }
   1559  1.1  dholland 
   1560  1.1  dholland /*
   1561  1.1  dholland  * Read wrapper for special devices.
   1562  1.1  dholland  */
   1563  1.1  dholland int
   1564  1.1  dholland ufsspec_read(void *v)
   1565  1.1  dholland {
   1566  1.1  dholland 	struct vop_read_args /* {
   1567  1.1  dholland 		struct vnode	*a_vp;
   1568  1.1  dholland 		struct uio	*a_uio;
   1569  1.1  dholland 		int		a_ioflag;
   1570  1.1  dholland 		kauth_cred_t	a_cred;
   1571  1.1  dholland 	} */ *ap = v;
   1572  1.1  dholland 
   1573  1.1  dholland 	/*
   1574  1.1  dholland 	 * Set access flag.
   1575  1.1  dholland 	 */
   1576  1.1  dholland 	if ((ap->a_vp->v_mount->mnt_flag & MNT_NODEVMTIME) == 0)
   1577  1.1  dholland 		VTOI(ap->a_vp)->i_flag |= IN_ACCESS;
   1578  1.1  dholland 	return (VOCALL (spec_vnodeop_p, VOFFSET(vop_read), ap));
   1579  1.1  dholland }
   1580  1.1  dholland 
   1581  1.1  dholland /*
   1582  1.1  dholland  * Write wrapper for special devices.
   1583  1.1  dholland  */
   1584  1.1  dholland int
   1585  1.1  dholland ufsspec_write(void *v)
   1586  1.1  dholland {
   1587  1.1  dholland 	struct vop_write_args /* {
   1588  1.1  dholland 		struct vnode	*a_vp;
   1589  1.1  dholland 		struct uio	*a_uio;
   1590  1.1  dholland 		int		a_ioflag;
   1591  1.1  dholland 		kauth_cred_t	a_cred;
   1592  1.1  dholland 	} */ *ap = v;
   1593  1.1  dholland 
   1594  1.1  dholland 	/*
   1595  1.1  dholland 	 * Set update and change flags.
   1596  1.1  dholland 	 */
   1597  1.1  dholland 	if ((ap->a_vp->v_mount->mnt_flag & MNT_NODEVMTIME) == 0)
   1598  1.1  dholland 		VTOI(ap->a_vp)->i_flag |= IN_MODIFY;
   1599  1.1  dholland 	return (VOCALL (spec_vnodeop_p, VOFFSET(vop_write), ap));
   1600  1.1  dholland }
   1601  1.1  dholland 
   1602  1.1  dholland /*
   1603  1.1  dholland  * Close wrapper for special devices.
   1604  1.1  dholland  *
   1605  1.1  dholland  * Update the times on the inode then do device close.
   1606  1.1  dholland  */
   1607  1.1  dholland int
   1608  1.1  dholland ufsspec_close(void *v)
   1609  1.1  dholland {
   1610  1.1  dholland 	struct vop_close_args /* {
   1611  1.1  dholland 		struct vnode	*a_vp;
   1612  1.1  dholland 		int		a_fflag;
   1613  1.1  dholland 		kauth_cred_t	a_cred;
   1614  1.1  dholland 	} */ *ap = v;
   1615  1.1  dholland 	struct vnode	*vp;
   1616  1.1  dholland 	struct inode	*ip;
   1617  1.1  dholland 
   1618  1.1  dholland 	vp = ap->a_vp;
   1619  1.1  dholland 	ip = VTOI(vp);
   1620  1.1  dholland 	if (vp->v_usecount > 1)
   1621  1.1  dholland 		UFS_ITIMES(vp, NULL, NULL, NULL);
   1622  1.1  dholland 	return (VOCALL (spec_vnodeop_p, VOFFSET(vop_close), ap));
   1623  1.1  dholland }
   1624  1.1  dholland 
   1625  1.1  dholland /*
   1626  1.1  dholland  * Read wrapper for fifo's
   1627  1.1  dholland  */
   1628  1.1  dholland int
   1629  1.1  dholland ufsfifo_read(void *v)
   1630  1.1  dholland {
   1631  1.1  dholland 	struct vop_read_args /* {
   1632  1.1  dholland 		struct vnode	*a_vp;
   1633  1.1  dholland 		struct uio	*a_uio;
   1634  1.1  dholland 		int		a_ioflag;
   1635  1.1  dholland 		kauth_cred_t	a_cred;
   1636  1.1  dholland 	} */ *ap = v;
   1637  1.1  dholland 
   1638  1.1  dholland 	/*
   1639  1.1  dholland 	 * Set access flag.
   1640  1.1  dholland 	 */
   1641  1.1  dholland 	VTOI(ap->a_vp)->i_flag |= IN_ACCESS;
   1642  1.1  dholland 	return (VOCALL (fifo_vnodeop_p, VOFFSET(vop_read), ap));
   1643  1.1  dholland }
   1644  1.1  dholland 
   1645  1.1  dholland /*
   1646  1.1  dholland  * Write wrapper for fifo's.
   1647  1.1  dholland  */
   1648  1.1  dholland int
   1649  1.1  dholland ufsfifo_write(void *v)
   1650  1.1  dholland {
   1651  1.1  dholland 	struct vop_write_args /* {
   1652  1.1  dholland 		struct vnode	*a_vp;
   1653  1.1  dholland 		struct uio	*a_uio;
   1654  1.1  dholland 		int		a_ioflag;
   1655  1.1  dholland 		kauth_cred_t	a_cred;
   1656  1.1  dholland 	} */ *ap = v;
   1657  1.1  dholland 
   1658  1.1  dholland 	/*
   1659  1.1  dholland 	 * Set update and change flags.
   1660  1.1  dholland 	 */
   1661  1.1  dholland 	VTOI(ap->a_vp)->i_flag |= IN_MODIFY;
   1662  1.1  dholland 	return (VOCALL (fifo_vnodeop_p, VOFFSET(vop_write), ap));
   1663  1.1  dholland }
   1664  1.1  dholland 
   1665  1.1  dholland /*
   1666  1.1  dholland  * Close wrapper for fifo's.
   1667  1.1  dholland  *
   1668  1.1  dholland  * Update the times on the inode then do device close.
   1669  1.1  dholland  */
   1670  1.1  dholland int
   1671  1.1  dholland ufsfifo_close(void *v)
   1672  1.1  dholland {
   1673  1.1  dholland 	struct vop_close_args /* {
   1674  1.1  dholland 		struct vnode	*a_vp;
   1675  1.1  dholland 		int		a_fflag;
   1676  1.1  dholland 		kauth_cred_t	a_cred;
   1677  1.1  dholland 	} */ *ap = v;
   1678  1.1  dholland 	struct vnode	*vp;
   1679  1.1  dholland 	struct inode	*ip;
   1680  1.1  dholland 
   1681  1.1  dholland 	vp = ap->a_vp;
   1682  1.1  dholland 	ip = VTOI(vp);
   1683  1.1  dholland 	if (ap->a_vp->v_usecount > 1)
   1684  1.1  dholland 		UFS_ITIMES(vp, NULL, NULL, NULL);
   1685  1.1  dholland 	return (VOCALL (fifo_vnodeop_p, VOFFSET(vop_close), ap));
   1686  1.1  dholland }
   1687  1.1  dholland 
   1688  1.1  dholland /*
   1689  1.1  dholland  * Return POSIX pathconf information applicable to ufs filesystems.
   1690  1.1  dholland  */
   1691  1.1  dholland int
   1692  1.1  dholland ufs_pathconf(void *v)
   1693  1.1  dholland {
   1694  1.1  dholland 	struct vop_pathconf_args /* {
   1695  1.1  dholland 		struct vnode	*a_vp;
   1696  1.1  dholland 		int		a_name;
   1697  1.1  dholland 		register_t	*a_retval;
   1698  1.1  dholland 	} */ *ap = v;
   1699  1.1  dholland 
   1700  1.1  dholland 	switch (ap->a_name) {
   1701  1.1  dholland 	case _PC_LINK_MAX:
   1702  1.1  dholland 		*ap->a_retval = LINK_MAX;
   1703  1.1  dholland 		return (0);
   1704  1.1  dholland 	case _PC_NAME_MAX:
   1705  1.1  dholland 		*ap->a_retval = FFS_MAXNAMLEN;
   1706  1.1  dholland 		return (0);
   1707  1.1  dholland 	case _PC_PATH_MAX:
   1708  1.1  dholland 		*ap->a_retval = PATH_MAX;
   1709  1.1  dholland 		return (0);
   1710  1.1  dholland 	case _PC_PIPE_BUF:
   1711  1.1  dholland 		*ap->a_retval = PIPE_BUF;
   1712  1.1  dholland 		return (0);
   1713  1.1  dholland 	case _PC_CHOWN_RESTRICTED:
   1714  1.1  dholland 		*ap->a_retval = 1;
   1715  1.1  dholland 		return (0);
   1716  1.1  dholland 	case _PC_NO_TRUNC:
   1717  1.1  dholland 		*ap->a_retval = 1;
   1718  1.1  dholland 		return (0);
   1719  1.1  dholland 	case _PC_SYNC_IO:
   1720  1.1  dholland 		*ap->a_retval = 1;
   1721  1.1  dholland 		return (0);
   1722  1.1  dholland 	case _PC_FILESIZEBITS:
   1723  1.1  dholland 		*ap->a_retval = 42;
   1724  1.1  dholland 		return (0);
   1725  1.1  dholland 	case _PC_SYMLINK_MAX:
   1726  1.1  dholland 		*ap->a_retval = MAXPATHLEN;
   1727  1.1  dholland 		return (0);
   1728  1.1  dholland 	case _PC_2_SYMLINKS:
   1729  1.1  dholland 		*ap->a_retval = 1;
   1730  1.1  dholland 		return (0);
   1731  1.1  dholland 	default:
   1732  1.1  dholland 		return (EINVAL);
   1733  1.1  dholland 	}
   1734  1.1  dholland 	/* NOTREACHED */
   1735  1.1  dholland }
   1736  1.1  dholland 
   1737  1.1  dholland /*
   1738  1.1  dholland  * Advisory record locking support
   1739  1.1  dholland  */
   1740  1.1  dholland int
   1741  1.1  dholland ufs_advlock(void *v)
   1742  1.1  dholland {
   1743  1.1  dholland 	struct vop_advlock_args /* {
   1744  1.1  dholland 		struct vnode	*a_vp;
   1745  1.1  dholland 		void *		a_id;
   1746  1.1  dholland 		int		a_op;
   1747  1.1  dholland 		struct flock	*a_fl;
   1748  1.1  dholland 		int		a_flags;
   1749  1.1  dholland 	} */ *ap = v;
   1750  1.1  dholland 	struct inode *ip;
   1751  1.1  dholland 
   1752  1.1  dholland 	ip = VTOI(ap->a_vp);
   1753  1.1  dholland 	return lf_advlock(ap, &ip->i_lockf, ip->i_size);
   1754  1.1  dholland }
   1755  1.1  dholland 
   1756  1.1  dholland /*
   1757  1.1  dholland  * Initialize the vnode associated with a new inode, handle aliased
   1758  1.1  dholland  * vnodes.
   1759  1.1  dholland  */
   1760  1.1  dholland void
   1761  1.1  dholland ufs_vinit(struct mount *mntp, int (**specops)(void *), int (**fifoops)(void *),
   1762  1.1  dholland 	struct vnode **vpp)
   1763  1.1  dholland {
   1764  1.1  dholland 	struct timeval	tv;
   1765  1.1  dholland 	struct inode	*ip;
   1766  1.1  dholland 	struct vnode	*vp;
   1767  1.1  dholland 	dev_t		rdev;
   1768  1.1  dholland 	struct ufsmount	*ump;
   1769  1.1  dholland 
   1770  1.1  dholland 	vp = *vpp;
   1771  1.1  dholland 	ip = VTOI(vp);
   1772  1.1  dholland 	switch(vp->v_type = IFTOVT(ip->i_mode)) {
   1773  1.1  dholland 	case VCHR:
   1774  1.1  dholland 	case VBLK:
   1775  1.1  dholland 		vp->v_op = specops;
   1776  1.1  dholland 		ump = ip->i_ump;
   1777  1.1  dholland 		if (ump->um_fstype == UFS1)
   1778  1.1  dholland 			rdev = (dev_t)ufs_rw32(ip->i_ffs1_rdev,
   1779  1.1  dholland 			    UFS_MPNEEDSWAP(ump));
   1780  1.1  dholland 		else
   1781  1.1  dholland 			rdev = (dev_t)ufs_rw64(ip->i_ffs2_rdev,
   1782  1.1  dholland 			    UFS_MPNEEDSWAP(ump));
   1783  1.1  dholland 		spec_node_init(vp, rdev);
   1784  1.1  dholland 		break;
   1785  1.1  dholland 	case VFIFO:
   1786  1.1  dholland 		vp->v_op = fifoops;
   1787  1.1  dholland 		break;
   1788  1.1  dholland 	case VNON:
   1789  1.1  dholland 	case VBAD:
   1790  1.1  dholland 	case VSOCK:
   1791  1.1  dholland 	case VLNK:
   1792  1.1  dholland 	case VDIR:
   1793  1.1  dholland 	case VREG:
   1794  1.1  dholland 		break;
   1795  1.1  dholland 	}
   1796  1.1  dholland 	if (ip->i_number == UFS_ROOTINO)
   1797  1.1  dholland                 vp->v_vflag |= VV_ROOT;
   1798  1.1  dholland 	/*
   1799  1.1  dholland 	 * Initialize modrev times
   1800  1.1  dholland 	 */
   1801  1.1  dholland 	getmicrouptime(&tv);
   1802  1.1  dholland 	ip->i_modrev = (uint64_t)(uint)tv.tv_sec << 32
   1803  1.1  dholland 			| tv.tv_usec * 4294u;
   1804  1.1  dholland 	*vpp = vp;
   1805  1.1  dholland }
   1806  1.1  dholland 
   1807  1.1  dholland /*
   1808  1.1  dholland  * Allocate a new inode.
   1809  1.1  dholland  */
   1810  1.1  dholland int
   1811  1.1  dholland ufs_makeinode(int mode, struct vnode *dvp, const struct ufs_lookup_results *ulr,
   1812  1.1  dholland 	struct vnode **vpp, struct componentname *cnp)
   1813  1.1  dholland {
   1814  1.1  dholland 	struct inode	*ip, *pdir;
   1815  1.1  dholland 	struct direct	*newdir;
   1816  1.1  dholland 	struct vnode	*tvp;
   1817  1.1  dholland 	int		error;
   1818  1.1  dholland 
   1819  1.1  dholland 	UFS_WAPBL_JUNLOCK_ASSERT(dvp->v_mount);
   1820  1.1  dholland 
   1821  1.1  dholland 	pdir = VTOI(dvp);
   1822  1.1  dholland 
   1823  1.1  dholland 	if ((mode & IFMT) == 0)
   1824  1.1  dholland 		mode |= IFREG;
   1825  1.1  dholland 
   1826  1.1  dholland 	if ((error = UFS_VALLOC(dvp, mode, cnp->cn_cred, vpp)) != 0) {
   1827  1.1  dholland 		vput(dvp);
   1828  1.1  dholland 		return (error);
   1829  1.1  dholland 	}
   1830  1.1  dholland 	tvp = *vpp;
   1831  1.1  dholland 	ip = VTOI(tvp);
   1832  1.1  dholland 	ip->i_gid = pdir->i_gid;
   1833  1.1  dholland 	DIP_ASSIGN(ip, gid, ip->i_gid);
   1834  1.1  dholland 	ip->i_uid = kauth_cred_geteuid(cnp->cn_cred);
   1835  1.1  dholland 	DIP_ASSIGN(ip, uid, ip->i_uid);
   1836  1.1  dholland 	error = UFS_WAPBL_BEGIN1(dvp->v_mount, dvp);
   1837  1.1  dholland 	if (error) {
   1838  1.1  dholland 		/*
   1839  1.1  dholland 		 * Note, we can't VOP_VFREE(tvp) here like we should
   1840  1.1  dholland 		 * because we can't write to the disk.  Instead, we leave
   1841  1.1  dholland 		 * the vnode dangling from the journal.
   1842  1.1  dholland 		 */
   1843  1.1  dholland 		vput(tvp);
   1844  1.1  dholland 		vput(dvp);
   1845  1.1  dholland 		return (error);
   1846  1.1  dholland 	}
   1847  1.1  dholland #if defined(QUOTA) || defined(QUOTA2)
   1848  1.1  dholland 	if ((error = chkiq(ip, 1, cnp->cn_cred, 0))) {
   1849  1.1  dholland 		UFS_VFREE(tvp, ip->i_number, mode);
   1850  1.1  dholland 		UFS_WAPBL_END1(dvp->v_mount, dvp);
   1851  1.1  dholland 		vput(tvp);
   1852  1.1  dholland 		vput(dvp);
   1853  1.1  dholland 		return (error);
   1854  1.1  dholland 	}
   1855  1.1  dholland #endif
   1856  1.1  dholland 	ip->i_flag |= IN_ACCESS | IN_CHANGE | IN_UPDATE;
   1857  1.1  dholland 	ip->i_mode = mode;
   1858  1.1  dholland 	DIP_ASSIGN(ip, mode, mode);
   1859  1.1  dholland 	tvp->v_type = IFTOVT(mode);	/* Rest init'd in getnewvnode(). */
   1860  1.1  dholland 	ip->i_nlink = 1;
   1861  1.1  dholland 	DIP_ASSIGN(ip, nlink, 1);
   1862  1.1  dholland 
   1863  1.1  dholland 	/* Authorize setting SGID if needed. */
   1864  1.1  dholland 	if (ip->i_mode & ISGID) {
   1865  1.1  dholland 		error = kauth_authorize_vnode(cnp->cn_cred, KAUTH_VNODE_WRITE_SECURITY,
   1866  1.1  dholland 		    tvp, NULL, genfs_can_chmod(tvp->v_type, cnp->cn_cred, ip->i_uid,
   1867  1.1  dholland 		    ip->i_gid, mode));
   1868  1.1  dholland 		if (error) {
   1869  1.1  dholland 			ip->i_mode &= ~ISGID;
   1870  1.1  dholland 			DIP_ASSIGN(ip, mode, ip->i_mode);
   1871  1.1  dholland 		}
   1872  1.1  dholland 	}
   1873  1.1  dholland 
   1874  1.1  dholland 	if (cnp->cn_flags & ISWHITEOUT) {
   1875  1.1  dholland 		ip->i_flags |= UF_OPAQUE;
   1876  1.1  dholland 		DIP_ASSIGN(ip, flags, ip->i_flags);
   1877  1.1  dholland 	}
   1878  1.1  dholland 
   1879  1.1  dholland 	/*
   1880  1.1  dholland 	 * Make sure inode goes to disk before directory entry.
   1881  1.1  dholland 	 */
   1882  1.1  dholland 	if ((error = UFS_UPDATE(tvp, NULL, NULL, UPDATE_DIROP)) != 0)
   1883  1.1  dholland 		goto bad;
   1884  1.1  dholland 	newdir = pool_cache_get(ufs_direct_cache, PR_WAITOK);
   1885  1.1  dholland 	ufs_makedirentry(ip, cnp, newdir);
   1886  1.1  dholland 	error = ufs_direnter(dvp, ulr, tvp, newdir, cnp, NULL);
   1887  1.1  dholland 	pool_cache_put(ufs_direct_cache, newdir);
   1888  1.1  dholland 	if (error)
   1889  1.1  dholland 		goto bad;
   1890  1.1  dholland 	vput(dvp);
   1891  1.1  dholland 	*vpp = tvp;
   1892  1.1  dholland 	return (0);
   1893  1.1  dholland 
   1894  1.1  dholland  bad:
   1895  1.1  dholland 	/*
   1896  1.1  dholland 	 * Write error occurred trying to update the inode
   1897  1.1  dholland 	 * or the directory so must deallocate the inode.
   1898  1.1  dholland 	 */
   1899  1.1  dholland 	ip->i_nlink = 0;
   1900  1.1  dholland 	DIP_ASSIGN(ip, nlink, 0);
   1901  1.1  dholland 	ip->i_flag |= IN_CHANGE;
   1902  1.1  dholland 	/* If IN_ADIROP, account for it */
   1903  1.1  dholland 	UFS_UNMARK_VNODE(tvp);
   1904  1.1  dholland 	UFS_WAPBL_UPDATE(tvp, NULL, NULL, 0);
   1905  1.1  dholland 	tvp->v_type = VNON;		/* explodes later if VBLK */
   1906  1.1  dholland 	UFS_WAPBL_END1(dvp->v_mount, dvp);
   1907  1.1  dholland 	vput(tvp);
   1908  1.1  dholland 	vput(dvp);
   1909  1.1  dholland 	return (error);
   1910  1.1  dholland }
   1911  1.1  dholland 
   1912  1.1  dholland /*
   1913  1.1  dholland  * Allocate len bytes at offset off.
   1914  1.1  dholland  */
   1915  1.1  dholland int
   1916  1.1  dholland ufs_gop_alloc(struct vnode *vp, off_t off, off_t len, int flags,
   1917  1.1  dholland     kauth_cred_t cred)
   1918  1.1  dholland {
   1919  1.1  dholland         struct inode *ip = VTOI(vp);
   1920  1.1  dholland         int error, delta, bshift, bsize;
   1921  1.1  dholland         UVMHIST_FUNC("ufs_gop_alloc"); UVMHIST_CALLED(ubchist);
   1922  1.1  dholland 
   1923  1.1  dholland         error = 0;
   1924  1.1  dholland         bshift = vp->v_mount->mnt_fs_bshift;
   1925  1.1  dholland         bsize = 1 << bshift;
   1926  1.1  dholland 
   1927  1.1  dholland         delta = off & (bsize - 1);
   1928  1.1  dholland         off -= delta;
   1929  1.1  dholland         len += delta;
   1930  1.1  dholland 
   1931  1.1  dholland         while (len > 0) {
   1932  1.1  dholland                 bsize = MIN(bsize, len);
   1933  1.1  dholland 
   1934  1.1  dholland                 error = UFS_BALLOC(vp, off, bsize, cred, flags, NULL);
   1935  1.1  dholland                 if (error) {
   1936  1.1  dholland                         goto out;
   1937  1.1  dholland                 }
   1938  1.1  dholland 
   1939  1.1  dholland                 /*
   1940  1.1  dholland                  * increase file size now, UFS_BALLOC() requires that
   1941  1.1  dholland                  * EOF be up-to-date before each call.
   1942  1.1  dholland                  */
   1943  1.1  dholland 
   1944  1.1  dholland                 if (ip->i_size < off + bsize) {
   1945  1.1  dholland                         UVMHIST_LOG(ubchist, "vp %p old 0x%x new 0x%x",
   1946  1.1  dholland                             vp, ip->i_size, off + bsize, 0);
   1947  1.1  dholland                         ip->i_size = off + bsize;
   1948  1.1  dholland 			DIP_ASSIGN(ip, size, ip->i_size);
   1949  1.1  dholland                 }
   1950  1.1  dholland 
   1951  1.1  dholland                 off += bsize;
   1952  1.1  dholland                 len -= bsize;
   1953  1.1  dholland         }
   1954  1.1  dholland 
   1955  1.1  dholland out:
   1956  1.1  dholland 	UFS_WAPBL_UPDATE(vp, NULL, NULL, 0);
   1957  1.1  dholland 	return error;
   1958  1.1  dholland }
   1959  1.1  dholland 
   1960  1.1  dholland void
   1961  1.1  dholland ufs_gop_markupdate(struct vnode *vp, int flags)
   1962  1.1  dholland {
   1963  1.1  dholland 	u_int32_t mask = 0;
   1964  1.1  dholland 
   1965  1.1  dholland 	if ((flags & GOP_UPDATE_ACCESSED) != 0) {
   1966  1.1  dholland 		mask = IN_ACCESS;
   1967  1.1  dholland 	}
   1968  1.1  dholland 	if ((flags & GOP_UPDATE_MODIFIED) != 0) {
   1969  1.1  dholland 		if (vp->v_type == VREG) {
   1970  1.1  dholland 			mask |= IN_CHANGE | IN_UPDATE;
   1971  1.1  dholland 		} else {
   1972  1.1  dholland 			mask |= IN_MODIFY;
   1973  1.1  dholland 		}
   1974  1.1  dholland 	}
   1975  1.1  dholland 	if (mask) {
   1976  1.1  dholland 		struct inode *ip = VTOI(vp);
   1977  1.1  dholland 
   1978  1.1  dholland 		ip->i_flag |= mask;
   1979  1.1  dholland 	}
   1980  1.1  dholland }
   1981