Home | History | Annotate | Line # | Download | only in lfs
lfs_alloc.c revision 1.38
      1  1.38  perseant /*	$NetBSD: lfs_alloc.c,v 1.38 2000/06/27 20:57:12 perseant Exp $	*/
      2   1.2       cgd 
      3  1.17  perseant /*-
      4  1.38  perseant  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
      5  1.17  perseant  * All rights reserved.
      6  1.17  perseant  *
      7  1.17  perseant  * This code is derived from software contributed to The NetBSD Foundation
      8  1.17  perseant  * by Konrad E. Schroder <perseant (at) hhhh.org>.
      9  1.17  perseant  *
     10  1.17  perseant  * Redistribution and use in source and binary forms, with or without
     11  1.17  perseant  * modification, are permitted provided that the following conditions
     12  1.17  perseant  * are met:
     13  1.17  perseant  * 1. Redistributions of source code must retain the above copyright
     14  1.17  perseant  *    notice, this list of conditions and the following disclaimer.
     15  1.17  perseant  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.17  perseant  *    notice, this list of conditions and the following disclaimer in the
     17  1.17  perseant  *    documentation and/or other materials provided with the distribution.
     18  1.17  perseant  * 3. All advertising materials mentioning features or use of this software
     19  1.17  perseant  *    must display the following acknowledgement:
     20  1.17  perseant  *      This product includes software developed by the NetBSD
     21  1.17  perseant  *      Foundation, Inc. and its contributors.
     22  1.17  perseant  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.17  perseant  *    contributors may be used to endorse or promote products derived
     24  1.17  perseant  *    from this software without specific prior written permission.
     25  1.17  perseant  *
     26  1.17  perseant  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.17  perseant  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.17  perseant  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.17  perseant  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.17  perseant  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.17  perseant  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.17  perseant  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.17  perseant  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.17  perseant  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.17  perseant  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.17  perseant  * POSSIBILITY OF SUCH DAMAGE.
     37  1.17  perseant  */
     38   1.1   mycroft /*
     39   1.1   mycroft  * Copyright (c) 1991, 1993
     40   1.1   mycroft  *	The Regents of the University of California.  All rights reserved.
     41   1.1   mycroft  *
     42   1.1   mycroft  * Redistribution and use in source and binary forms, with or without
     43   1.1   mycroft  * modification, are permitted provided that the following conditions
     44   1.1   mycroft  * are met:
     45   1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     46   1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     47   1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     48   1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     49   1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     50   1.1   mycroft  * 3. All advertising materials mentioning features or use of this software
     51   1.1   mycroft  *    must display the following acknowledgement:
     52   1.1   mycroft  *	This product includes software developed by the University of
     53   1.1   mycroft  *	California, Berkeley and its contributors.
     54   1.1   mycroft  * 4. Neither the name of the University nor the names of its contributors
     55   1.1   mycroft  *    may be used to endorse or promote products derived from this software
     56   1.1   mycroft  *    without specific prior written permission.
     57   1.1   mycroft  *
     58   1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59   1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60   1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61   1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62   1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63   1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64   1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65   1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66   1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67   1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68   1.1   mycroft  * SUCH DAMAGE.
     69   1.1   mycroft  *
     70   1.2       cgd  *	@(#)lfs_alloc.c	8.4 (Berkeley) 1/4/94
     71   1.1   mycroft  */
     72  1.12    scottr 
     73  1.13    scottr #if defined(_KERNEL) && !defined(_LKM)
     74  1.12    scottr #include "opt_quota.h"
     75  1.13    scottr #endif
     76   1.1   mycroft 
     77   1.1   mycroft #include <sys/param.h>
     78   1.3  christos #include <sys/systm.h>
     79   1.1   mycroft #include <sys/kernel.h>
     80   1.1   mycroft #include <sys/buf.h>
     81   1.1   mycroft #include <sys/vnode.h>
     82   1.1   mycroft #include <sys/syslog.h>
     83   1.1   mycroft #include <sys/mount.h>
     84   1.1   mycroft #include <sys/malloc.h>
     85  1.15   thorpej #include <sys/pool.h>
     86   1.1   mycroft 
     87   1.1   mycroft #include <vm/vm.h>
     88   1.1   mycroft 
     89   1.1   mycroft #include <ufs/ufs/quota.h>
     90   1.1   mycroft #include <ufs/ufs/inode.h>
     91   1.1   mycroft #include <ufs/ufs/ufsmount.h>
     92   1.3  christos #include <ufs/ufs/ufs_extern.h>
     93   1.1   mycroft 
     94   1.1   mycroft #include <ufs/lfs/lfs.h>
     95   1.1   mycroft #include <ufs/lfs/lfs_extern.h>
     96   1.1   mycroft 
     97  1.38  perseant extern int lfs_dirvcount;
     98  1.17  perseant extern struct lock ufs_hashlock;
     99  1.17  perseant 
    100   1.1   mycroft /* Allocate a new inode. */
    101   1.1   mycroft /* ARGSUSED */
    102   1.1   mycroft int
    103   1.3  christos lfs_valloc(v)
    104   1.3  christos 	void *v;
    105   1.3  christos {
    106   1.1   mycroft 	struct vop_valloc_args /* {
    107  1.17  perseant 				  struct vnode *a_pvp;
    108  1.17  perseant 				  int a_mode;
    109  1.17  perseant 				  struct ucred *a_cred;
    110  1.17  perseant 				  struct vnode **a_vpp;
    111  1.17  perseant 				  } */ *ap = v;
    112   1.1   mycroft 	struct lfs *fs;
    113   1.1   mycroft 	struct buf *bp;
    114   1.1   mycroft 	struct ifile *ifp;
    115   1.1   mycroft 	struct inode *ip;
    116   1.1   mycroft 	struct vnode *vp;
    117  1.11      fvdl 	ufs_daddr_t blkno;
    118   1.1   mycroft 	ino_t new_ino;
    119   1.1   mycroft 	u_long i, max;
    120   1.1   mycroft 	int error;
    121  1.36  perseant 	int new_gen;
    122  1.26  perseant 	extern int lfs_dirvcount;
    123   1.1   mycroft 
    124  1.17  perseant 	fs = VTOI(ap->a_pvp)->i_lfs;
    125  1.38  perseant 	if (fs->lfs_ronly)
    126  1.38  perseant 		return EROFS;
    127  1.38  perseant 	*ap->a_vpp = NULL;
    128  1.17  perseant 
    129  1.17  perseant 	/*
    130  1.34  perseant 	 * Use lfs_seglock here, instead of fs->lfs_freelock, to ensure that
    131  1.34  perseant 	 * the free list is not changed in between the time that the ifile
    132  1.34  perseant 	 * blocks are written to disk and the time that the superblock is
    133  1.34  perseant 	 * written to disk.
    134  1.34  perseant 	 *
    135  1.34  perseant 	 * XXX this sucks.  We should instead encode the head of the free
    136  1.34  perseant 	 * list into the CLEANERINFO block of the Ifile.
    137  1.17  perseant 	 */
    138  1.34  perseant 	lfs_seglock(fs, SEGM_PROT);
    139  1.17  perseant 
    140   1.1   mycroft 	/* Get the head of the freelist. */
    141   1.1   mycroft 	new_ino = fs->lfs_free;
    142  1.17  perseant #ifdef DIAGNOSTIC
    143  1.17  perseant 	if(new_ino == LFS_UNUSED_INUM) {
    144  1.17  perseant #ifdef DEBUG
    145  1.17  perseant 		lfs_dump_super(fs);
    146  1.17  perseant #endif /* DEBUG */
    147  1.17  perseant 		panic("inode 0 allocated [1]");
    148  1.17  perseant 	}
    149  1.17  perseant #endif /* DIAGNOSTIC */
    150   1.1   mycroft #ifdef ALLOCPRINT
    151   1.6  christos 	printf("lfs_ialloc: allocate inode %d\n", new_ino);
    152   1.1   mycroft #endif
    153  1.17  perseant 
    154   1.1   mycroft 	/*
    155   1.1   mycroft 	 * Remove the inode from the free list and write the new start
    156   1.1   mycroft 	 * of the free list into the superblock.
    157   1.1   mycroft 	 */
    158   1.1   mycroft 	LFS_IENTRY(ifp, fs, new_ino, bp);
    159   1.1   mycroft 	if (ifp->if_daddr != LFS_UNUSED_DADDR)
    160  1.17  perseant 		panic("lfs_ialloc: inuse inode %d on the free list", new_ino);
    161   1.1   mycroft 	fs->lfs_free = ifp->if_nextfree;
    162  1.37  perseant 	new_gen = ifp->if_version; /* version was updated by vfree */
    163  1.25  perseant #ifdef LFS_DEBUG_NEXTFREE
    164  1.25  perseant 	ifp->if_nextfree = 0;
    165  1.28  perseant 	VOP_BWRITE(bp);
    166  1.28  perseant #else
    167  1.28  perseant 	brelse(bp);
    168  1.27  perseant #endif
    169  1.30  perseant 
    170   1.1   mycroft 	/* Extend IFILE so that the next lfs_valloc will succeed. */
    171   1.1   mycroft 	if (fs->lfs_free == LFS_UNUSED_INUM) {
    172   1.1   mycroft 		vp = fs->lfs_ivnode;
    173  1.38  perseant 		(void)lfs_vref(vp);
    174  1.38  perseant 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
    175   1.1   mycroft 		ip = VTOI(vp);
    176   1.8    bouyer 		blkno = lblkno(fs, ip->i_ffs_size);
    177  1.29      fvdl 		if ((error = VOP_BALLOC(vp, ip->i_ffs_size, fs->lfs_bsize,
    178  1.38  perseant 					ap->a_cred, 0, &bp)) != 0) {
    179  1.38  perseant 			VOP_UNLOCK(vp, 0);
    180  1.34  perseant 			lfs_segunlock(fs);
    181  1.38  perseant 			fs->lfs_free = new_ino;
    182  1.29      fvdl 			return (error);
    183  1.31  perseant 		}
    184   1.8    bouyer 		ip->i_ffs_size += fs->lfs_bsize;
    185  1.10       chs 		uvm_vnp_setsize(vp, ip->i_ffs_size);
    186  1.10       chs 		(void)uvm_vnp_uncache(vp);
    187  1.38  perseant 		VOP_UNLOCK(vp, 0);
    188   1.1   mycroft 
    189   1.1   mycroft 		i = (blkno - fs->lfs_segtabsz - fs->lfs_cleansz) *
    190  1.17  perseant 			fs->lfs_ifpb;
    191   1.1   mycroft 		fs->lfs_free = i;
    192  1.17  perseant #ifdef DIAGNOSTIC
    193  1.17  perseant 		if(fs->lfs_free == LFS_UNUSED_INUM)
    194  1.17  perseant 			panic("inode 0 allocated [2]");
    195  1.17  perseant #endif /* DIAGNOSTIC */
    196   1.1   mycroft 		max = i + fs->lfs_ifpb;
    197   1.1   mycroft 		for (ifp = (struct ifile *)bp->b_data; i < max; ++ifp) {
    198   1.1   mycroft 			ifp->if_version = 1;
    199   1.1   mycroft 			ifp->if_daddr = LFS_UNUSED_DADDR;
    200   1.1   mycroft 			ifp->if_nextfree = ++i;
    201   1.1   mycroft 		}
    202   1.1   mycroft 		ifp--;
    203   1.1   mycroft 		ifp->if_nextfree = LFS_UNUSED_INUM;
    204  1.38  perseant 		VOP_BWRITE(bp);
    205  1.38  perseant 		lfs_vunref(vp);
    206   1.1   mycroft 	}
    207  1.17  perseant #ifdef DIAGNOSTIC
    208  1.17  perseant 	if(fs->lfs_free == LFS_UNUSED_INUM)
    209  1.17  perseant 		panic("inode 0 allocated [3]");
    210  1.17  perseant #endif /* DIAGNOSTIC */
    211  1.17  perseant 
    212  1.34  perseant 	lfs_segunlock(fs);
    213  1.31  perseant 
    214  1.31  perseant 	lockmgr(&ufs_hashlock, LK_EXCLUSIVE, 0);
    215   1.1   mycroft 	/* Create a vnode to associate with the inode. */
    216  1.26  perseant 	if ((error = lfs_vcreate(ap->a_pvp->v_mount, new_ino, &vp)) != 0) {
    217  1.26  perseant 		lockmgr(&ufs_hashlock, LK_RELEASE, 0);
    218  1.38  perseant 		goto errout;
    219  1.26  perseant 	}
    220  1.17  perseant 
    221   1.1   mycroft 	ip = VTOI(vp);
    222   1.1   mycroft 	/* Zero out the direct and indirect block addresses. */
    223  1.16   thorpej 	bzero(&ip->i_din, sizeof(ip->i_din));
    224   1.8    bouyer 	ip->i_din.ffs_din.di_inumber = new_ino;
    225  1.17  perseant 
    226   1.1   mycroft 	/* Set a new generation number for this inode. */
    227  1.36  perseant 	ip->i_ffs_gen = new_gen;
    228  1.17  perseant 
    229   1.1   mycroft 	/* Insert into the inode hash table. */
    230   1.1   mycroft 	ufs_ihashins(ip);
    231  1.26  perseant 	lockmgr(&ufs_hashlock, LK_RELEASE, 0);
    232  1.17  perseant 
    233  1.14  sommerfe 	error = ufs_vinit(vp->v_mount, lfs_specop_p, lfs_fifoop_p, &vp);
    234   1.3  christos 	if (error) {
    235   1.1   mycroft 		vput(vp);
    236  1.38  perseant 		goto errout;
    237   1.1   mycroft 	}
    238  1.17  perseant 
    239   1.1   mycroft 	*ap->a_vpp = vp;
    240  1.38  perseant #if 1
    241  1.17  perseant 	if(!(vp->v_flag & VDIROP)) {
    242  1.35  perseant 		(void)lfs_vref(vp);
    243  1.26  perseant 		++lfs_dirvcount;
    244  1.17  perseant 	}
    245   1.1   mycroft 	vp->v_flag |= VDIROP;
    246  1.17  perseant 
    247  1.32  perseant 	if(!(ip->i_flag & IN_ADIROP))
    248  1.32  perseant 		++fs->lfs_nadirop;
    249  1.32  perseant 	ip->i_flag |= IN_ADIROP;
    250  1.38  perseant #endif
    251  1.38  perseant 	VREF(ip->i_devvp);
    252   1.1   mycroft 	/* Set superblock modified bit and increment file count. */
    253   1.1   mycroft 	fs->lfs_fmod = 1;
    254   1.1   mycroft 	++fs->lfs_nfiles;
    255   1.1   mycroft 	return (0);
    256  1.38  perseant 
    257  1.38  perseant     errout:
    258  1.38  perseant 	/*
    259  1.38  perseant 	 * Put the new inum back on the free list.
    260  1.38  perseant 	 */
    261  1.38  perseant 	LFS_IENTRY(ifp, fs, new_ino, bp);
    262  1.38  perseant 	ifp->if_daddr = LFS_UNUSED_DADDR;
    263  1.38  perseant 	ifp->if_nextfree = fs->lfs_free;
    264  1.38  perseant 	fs->lfs_free = new_ino;
    265  1.38  perseant 	VOP_BWRITE(bp);
    266  1.38  perseant 
    267  1.38  perseant 	return (error);
    268   1.1   mycroft }
    269   1.1   mycroft 
    270   1.1   mycroft /* Create a new vnode/inode pair and initialize what fields we can. */
    271   1.1   mycroft int
    272   1.1   mycroft lfs_vcreate(mp, ino, vpp)
    273   1.1   mycroft 	struct mount *mp;
    274   1.1   mycroft 	ino_t ino;
    275   1.1   mycroft 	struct vnode **vpp;
    276   1.1   mycroft {
    277   1.3  christos 	extern int (**lfs_vnodeop_p) __P((void *));
    278   1.1   mycroft 	struct inode *ip;
    279   1.1   mycroft 	struct ufsmount *ump;
    280   1.4        pk 	int error;
    281   1.4        pk #ifdef QUOTA
    282   1.4        pk 	int i;
    283   1.4        pk #endif
    284  1.17  perseant 
    285   1.1   mycroft 	/* Create the vnode. */
    286   1.3  christos 	if ((error = getnewvnode(VT_LFS, mp, lfs_vnodeop_p, vpp)) != 0) {
    287   1.1   mycroft 		*vpp = NULL;
    288   1.1   mycroft 		return (error);
    289   1.1   mycroft 	}
    290  1.17  perseant 
    291   1.1   mycroft 	/* Get a pointer to the private mount structure. */
    292   1.1   mycroft 	ump = VFSTOUFS(mp);
    293  1.17  perseant 
    294   1.1   mycroft 	/* Initialize the inode. */
    295  1.15   thorpej 	ip = pool_get(&lfs_inode_pool, PR_WAITOK);
    296   1.1   mycroft 	(*vpp)->v_data = ip;
    297   1.1   mycroft 	ip->i_vnode = *vpp;
    298   1.1   mycroft 	ip->i_devvp = ump->um_devvp;
    299   1.1   mycroft 	ip->i_flag = IN_MODIFIED;
    300   1.1   mycroft 	ip->i_dev = ump->um_dev;
    301   1.8    bouyer 	ip->i_number = ip->i_din.ffs_din.di_inumber = ino;
    302   1.1   mycroft 	ip->i_lfs = ump->um_lfs;
    303   1.1   mycroft #ifdef QUOTA
    304   1.1   mycroft 	for (i = 0; i < MAXQUOTAS; i++)
    305   1.1   mycroft 		ip->i_dquot[i] = NODQUOT;
    306   1.1   mycroft #endif
    307   1.1   mycroft 	ip->i_lockf = 0;
    308   1.1   mycroft 	ip->i_diroff = 0;
    309   1.8    bouyer 	ip->i_ffs_mode = 0;
    310   1.8    bouyer 	ip->i_ffs_size = 0;
    311   1.8    bouyer 	ip->i_ffs_blocks = 0;
    312   1.1   mycroft 	++ump->um_lfs->lfs_uinodes;
    313   1.1   mycroft 	return (0);
    314   1.1   mycroft }
    315   1.1   mycroft 
    316   1.1   mycroft /* Free an inode. */
    317   1.1   mycroft /* ARGUSED */
    318   1.1   mycroft int
    319   1.3  christos lfs_vfree(v)
    320   1.3  christos 	void *v;
    321   1.3  christos {
    322   1.1   mycroft 	struct vop_vfree_args /* {
    323  1.17  perseant 				 struct vnode *a_pvp;
    324  1.17  perseant 				 ino_t a_ino;
    325  1.17  perseant 				 int a_mode;
    326  1.17  perseant 				 } */ *ap = v;
    327   1.1   mycroft 	SEGUSE *sup;
    328   1.1   mycroft 	struct buf *bp;
    329   1.1   mycroft 	struct ifile *ifp;
    330   1.1   mycroft 	struct inode *ip;
    331  1.30  perseant 	struct vnode *vp;
    332   1.1   mycroft 	struct lfs *fs;
    333  1.11      fvdl 	ufs_daddr_t old_iaddr;
    334   1.1   mycroft 	ino_t ino;
    335  1.30  perseant 	extern int lfs_dirvcount;
    336  1.17  perseant 
    337   1.1   mycroft 	/* Get the inode number and file system. */
    338  1.30  perseant 	vp = ap->a_pvp;
    339  1.30  perseant 	ip = VTOI(vp);
    340   1.1   mycroft 	fs = ip->i_lfs;
    341   1.1   mycroft 	ino = ip->i_number;
    342  1.34  perseant 
    343  1.34  perseant #if 0
    344  1.34  perseant 	/*
    345  1.34  perseant 	 * Right now this is unnecessary since we take the seglock.
    346  1.34  perseant 	 * But if the seglock is no longer necessary (e.g. we put the
    347  1.34  perseant 	 * head of the free list into the Ifile) we will need to drain
    348  1.34  perseant 	 * this vnode of any pending writes.
    349  1.34  perseant 	 */
    350  1.34  perseant 	if (WRITEINPROG(vp))
    351  1.34  perseant 		tsleep(vp, (PRIBIO+1), "lfs_vfree", 0);
    352  1.34  perseant #endif
    353  1.34  perseant 	lfs_seglock(fs, SEGM_PROT);
    354  1.17  perseant 
    355  1.30  perseant 	if(vp->v_flag & VDIROP) {
    356  1.30  perseant 		--lfs_dirvcount;
    357  1.30  perseant 		vp->v_flag &= ~VDIROP;
    358  1.30  perseant 		wakeup(&lfs_dirvcount);
    359  1.30  perseant 		lfs_vunref(vp);
    360  1.38  perseant 	}
    361  1.38  perseant 	if (ip->i_flag & IN_ADIROP) {
    362  1.38  perseant 		--fs->lfs_nadirop;
    363  1.38  perseant 		ip->i_flag &= ~IN_ADIROP;
    364  1.30  perseant 	}
    365  1.30  perseant 
    366  1.17  perseant 	if (ip->i_flag & IN_CLEANING) {
    367  1.17  perseant 		--fs->lfs_uinodes;
    368  1.17  perseant 	}
    369  1.33  perseant 	if (ip->i_flag & (IN_MODIFIED | IN_ACCESSED)) {
    370   1.1   mycroft 		--fs->lfs_uinodes;
    371   1.1   mycroft 	}
    372  1.33  perseant 	ip->i_flag &= ~IN_ALLMOD;
    373  1.17  perseant #ifdef DEBUG_LFS
    374  1.17  perseant 	if((int32_t)fs->lfs_uinodes<0) {
    375  1.17  perseant 		printf("U1");
    376  1.17  perseant 		fs->lfs_uinodes=0;
    377  1.17  perseant 	}
    378  1.17  perseant #endif
    379   1.1   mycroft 	/*
    380   1.1   mycroft 	 * Set the ifile's inode entry to unused, increment its version number
    381   1.1   mycroft 	 * and link it into the free chain.
    382   1.1   mycroft 	 */
    383   1.1   mycroft 	LFS_IENTRY(ifp, fs, ino, bp);
    384   1.1   mycroft 	old_iaddr = ifp->if_daddr;
    385   1.1   mycroft 	ifp->if_daddr = LFS_UNUSED_DADDR;
    386   1.1   mycroft 	++ifp->if_version;
    387   1.1   mycroft 	ifp->if_nextfree = fs->lfs_free;
    388   1.1   mycroft 	fs->lfs_free = ino;
    389   1.1   mycroft 	(void) VOP_BWRITE(bp);
    390  1.17  perseant #ifdef DIAGNOSTIC
    391  1.17  perseant 	if(fs->lfs_free == LFS_UNUSED_INUM) {
    392  1.17  perseant 		panic("inode 0 freed");
    393  1.17  perseant 	}
    394  1.17  perseant #endif /* DIAGNOSTIC */
    395   1.1   mycroft 	if (old_iaddr != LFS_UNUSED_DADDR) {
    396   1.1   mycroft 		LFS_SEGENTRY(sup, fs, datosn(fs, old_iaddr), bp);
    397  1.22  perseant #ifdef DIAGNOSTIC
    398  1.17  perseant 		if (sup->su_nbytes < DINODE_SIZE) {
    399  1.23       tls 			printf("lfs_vfree: negative byte count (segment %d short by %d)\n", datosn(fs, old_iaddr), (int)DINODE_SIZE - sup->su_nbytes);
    400  1.22  perseant 			panic("lfs_vfree: negative byte count");
    401  1.17  perseant 			sup->su_nbytes = DINODE_SIZE;
    402  1.17  perseant 		}
    403  1.22  perseant #endif
    404  1.16   thorpej 		sup->su_nbytes -= DINODE_SIZE;
    405   1.1   mycroft 		(void) VOP_BWRITE(bp);
    406   1.1   mycroft 	}
    407  1.17  perseant 
    408   1.1   mycroft 	/* Set superblock modified bit and decrement file count. */
    409   1.1   mycroft 	fs->lfs_fmod = 1;
    410   1.1   mycroft 	--fs->lfs_nfiles;
    411  1.17  perseant 
    412  1.34  perseant 	lfs_segunlock(fs);
    413   1.1   mycroft 	return (0);
    414   1.1   mycroft }
    415