Home | History | Annotate | Line # | Download | only in lfs
lfs_alloc.c revision 1.25.6.1
      1  1.25.6.1  wrstuden /*	$NetBSD: lfs_alloc.c,v 1.25.6.1 1999/12/27 18:36:39 wrstuden Exp $	*/
      2       1.2       cgd 
      3      1.17  perseant /*-
      4      1.17  perseant  * Copyright (c) 1999 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.17  perseant extern struct lock ufs_hashlock;
     98      1.17  perseant 
     99       1.1   mycroft /* Allocate a new inode. */
    100       1.1   mycroft /* ARGSUSED */
    101       1.1   mycroft int
    102       1.3  christos lfs_valloc(v)
    103       1.3  christos 	void *v;
    104       1.3  christos {
    105       1.1   mycroft 	struct vop_valloc_args /* {
    106      1.17  perseant 				  struct vnode *a_pvp;
    107      1.17  perseant 				  int a_mode;
    108      1.17  perseant 				  struct ucred *a_cred;
    109      1.17  perseant 				  struct vnode **a_vpp;
    110      1.17  perseant 				  } */ *ap = v;
    111       1.1   mycroft 	struct lfs *fs;
    112       1.1   mycroft 	struct buf *bp;
    113       1.1   mycroft 	struct ifile *ifp;
    114       1.1   mycroft 	struct inode *ip;
    115       1.1   mycroft 	struct vnode *vp;
    116      1.11      fvdl 	ufs_daddr_t blkno;
    117       1.1   mycroft 	ino_t new_ino;
    118       1.1   mycroft 	u_long i, max;
    119       1.1   mycroft 	int error;
    120  1.25.6.1  wrstuden 	extern int lfs_dirvcount;
    121       1.1   mycroft 
    122      1.17  perseant 	fs = VTOI(ap->a_pvp)->i_lfs;
    123      1.17  perseant 
    124      1.17  perseant 	/*
    125  1.25.6.1  wrstuden 	 * Prevent a race getting lfs_free.  We use
    126  1.25.6.1  wrstuden 	 * the ufs_hashlock here because we need that anyway for
    127  1.25.6.1  wrstuden 	 * the hash insertion later.
    128      1.17  perseant 	 */
    129  1.25.6.1  wrstuden 	lockmgr(&ufs_hashlock, LK_EXCLUSIVE, 0);
    130      1.17  perseant 
    131       1.1   mycroft 	/* Get the head of the freelist. */
    132       1.1   mycroft 	new_ino = fs->lfs_free;
    133      1.17  perseant #ifdef DIAGNOSTIC
    134      1.17  perseant 	if(new_ino == LFS_UNUSED_INUM) {
    135      1.17  perseant #ifdef DEBUG
    136      1.17  perseant 		lfs_dump_super(fs);
    137      1.17  perseant #endif /* DEBUG */
    138      1.17  perseant 		panic("inode 0 allocated [1]");
    139      1.17  perseant 	}
    140      1.17  perseant #endif /* DIAGNOSTIC */
    141       1.1   mycroft #ifdef ALLOCPRINT
    142       1.6  christos 	printf("lfs_ialloc: allocate inode %d\n", new_ino);
    143       1.1   mycroft #endif
    144      1.17  perseant 
    145       1.1   mycroft 	/*
    146       1.1   mycroft 	 * Remove the inode from the free list and write the new start
    147       1.1   mycroft 	 * of the free list into the superblock.
    148       1.1   mycroft 	 */
    149       1.1   mycroft 	LFS_IENTRY(ifp, fs, new_ino, bp);
    150       1.1   mycroft 	if (ifp->if_daddr != LFS_UNUSED_DADDR)
    151      1.17  perseant 		panic("lfs_ialloc: inuse inode %d on the free list", new_ino);
    152       1.1   mycroft 	fs->lfs_free = ifp->if_nextfree;
    153      1.25  perseant #ifdef LFS_DEBUG_NEXTFREE
    154      1.25  perseant 	ifp->if_nextfree = 0;
    155      1.25  perseant 	VOP_BWRITE(bp);
    156      1.25  perseant #else
    157       1.1   mycroft 	brelse(bp);
    158      1.25  perseant #endif
    159  1.25.6.1  wrstuden 
    160       1.1   mycroft 	/* Extend IFILE so that the next lfs_valloc will succeed. */
    161       1.1   mycroft 	if (fs->lfs_free == LFS_UNUSED_INUM) {
    162       1.1   mycroft 		vp = fs->lfs_ivnode;
    163      1.17  perseant 		VOP_LOCK(vp,LK_EXCLUSIVE);
    164       1.1   mycroft 		ip = VTOI(vp);
    165       1.8    bouyer 		blkno = lblkno(fs, ip->i_ffs_size);
    166  1.25.6.1  wrstuden 		if ((error = VOP_BALLOC(vp, ip->i_ffs_size, fs->lfs_bsize,
    167  1.25.6.1  wrstuden 		    NULL, 0, &bp)) != 0)
    168  1.25.6.1  wrstuden 			return (error);
    169       1.8    bouyer 		ip->i_ffs_size += fs->lfs_bsize;
    170      1.10       chs 		uvm_vnp_setsize(vp, ip->i_ffs_size);
    171      1.10       chs 		(void)uvm_vnp_uncache(vp);
    172       1.1   mycroft 
    173       1.1   mycroft 		i = (blkno - fs->lfs_segtabsz - fs->lfs_cleansz) *
    174      1.17  perseant 			fs->lfs_ifpb;
    175       1.1   mycroft 		fs->lfs_free = i;
    176      1.17  perseant #ifdef DIAGNOSTIC
    177      1.17  perseant 		if(fs->lfs_free == LFS_UNUSED_INUM)
    178      1.17  perseant 			panic("inode 0 allocated [2]");
    179      1.17  perseant #endif /* DIAGNOSTIC */
    180       1.1   mycroft 		max = i + fs->lfs_ifpb;
    181       1.1   mycroft 		for (ifp = (struct ifile *)bp->b_data; i < max; ++ifp) {
    182       1.1   mycroft 			ifp->if_version = 1;
    183       1.1   mycroft 			ifp->if_daddr = LFS_UNUSED_DADDR;
    184       1.1   mycroft 			ifp->if_nextfree = ++i;
    185       1.1   mycroft 		}
    186       1.1   mycroft 		ifp--;
    187       1.1   mycroft 		ifp->if_nextfree = LFS_UNUSED_INUM;
    188      1.17  perseant 		VOP_UNLOCK(vp,0);
    189      1.17  perseant 		if ((error = VOP_BWRITE(bp)) != 0) {
    190      1.17  perseant 			lockmgr(&ufs_hashlock, LK_RELEASE, 0);
    191       1.1   mycroft 			return (error);
    192      1.17  perseant 		}
    193       1.1   mycroft 	}
    194      1.17  perseant 
    195      1.17  perseant #ifdef DIAGNOSTIC
    196      1.17  perseant 	if(fs->lfs_free == LFS_UNUSED_INUM)
    197      1.17  perseant 		panic("inode 0 allocated [3]");
    198      1.17  perseant #endif /* DIAGNOSTIC */
    199      1.17  perseant 
    200       1.1   mycroft 	/* Create a vnode to associate with the inode. */
    201  1.25.6.1  wrstuden 	if ((error = lfs_vcreate(ap->a_pvp->v_mount, new_ino, &vp)) != 0) {
    202  1.25.6.1  wrstuden 		lockmgr(&ufs_hashlock, LK_RELEASE, 0);
    203       1.1   mycroft 		return (error);
    204  1.25.6.1  wrstuden 	}
    205      1.17  perseant 
    206       1.1   mycroft 	ip = VTOI(vp);
    207       1.1   mycroft 	/* Zero out the direct and indirect block addresses. */
    208      1.16   thorpej 	bzero(&ip->i_din, sizeof(ip->i_din));
    209       1.8    bouyer 	ip->i_din.ffs_din.di_inumber = new_ino;
    210      1.17  perseant 
    211       1.1   mycroft 	/* Set a new generation number for this inode. */
    212       1.8    bouyer 	ip->i_ffs_gen++;
    213      1.17  perseant 
    214       1.1   mycroft 	/* Insert into the inode hash table. */
    215       1.1   mycroft 	ufs_ihashins(ip);
    216  1.25.6.1  wrstuden 	lockmgr(&ufs_hashlock, LK_RELEASE, 0);
    217      1.17  perseant 
    218      1.14  sommerfe 	error = ufs_vinit(vp->v_mount, lfs_specop_p, lfs_fifoop_p, &vp);
    219       1.3  christos 	if (error) {
    220       1.1   mycroft 		vput(vp);
    221       1.1   mycroft 		*ap->a_vpp = NULL;
    222       1.1   mycroft 		return (error);
    223       1.1   mycroft 	}
    224      1.17  perseant 
    225       1.1   mycroft 	*ap->a_vpp = vp;
    226      1.17  perseant 	if(!(vp->v_flag & VDIROP)) {
    227      1.17  perseant 		lfs_vref(vp);
    228  1.25.6.1  wrstuden 		++lfs_dirvcount;
    229      1.17  perseant 	}
    230       1.1   mycroft 	vp->v_flag |= VDIROP;
    231       1.1   mycroft 	VREF(ip->i_devvp);
    232      1.17  perseant 
    233       1.1   mycroft 	/* Set superblock modified bit and increment file count. */
    234       1.1   mycroft 	fs->lfs_fmod = 1;
    235       1.1   mycroft 	++fs->lfs_nfiles;
    236       1.1   mycroft 	return (0);
    237       1.1   mycroft }
    238       1.1   mycroft 
    239       1.1   mycroft /* Create a new vnode/inode pair and initialize what fields we can. */
    240       1.1   mycroft int
    241       1.1   mycroft lfs_vcreate(mp, ino, vpp)
    242       1.1   mycroft 	struct mount *mp;
    243       1.1   mycroft 	ino_t ino;
    244       1.1   mycroft 	struct vnode **vpp;
    245       1.1   mycroft {
    246       1.3  christos 	extern int (**lfs_vnodeop_p) __P((void *));
    247       1.1   mycroft 	struct inode *ip;
    248       1.1   mycroft 	struct ufsmount *ump;
    249       1.4        pk 	int error;
    250       1.4        pk #ifdef QUOTA
    251       1.4        pk 	int i;
    252       1.4        pk #endif
    253      1.17  perseant 
    254       1.1   mycroft 	/* Create the vnode. */
    255       1.3  christos 	if ((error = getnewvnode(VT_LFS, mp, lfs_vnodeop_p, vpp)) != 0) {
    256       1.1   mycroft 		*vpp = NULL;
    257       1.1   mycroft 		return (error);
    258       1.1   mycroft 	}
    259      1.17  perseant 
    260       1.1   mycroft 	/* Get a pointer to the private mount structure. */
    261       1.1   mycroft 	ump = VFSTOUFS(mp);
    262      1.17  perseant 
    263       1.1   mycroft 	/* Initialize the inode. */
    264      1.15   thorpej 	ip = pool_get(&lfs_inode_pool, PR_WAITOK);
    265       1.1   mycroft 	(*vpp)->v_data = ip;
    266       1.1   mycroft 	ip->i_vnode = *vpp;
    267       1.1   mycroft 	ip->i_devvp = ump->um_devvp;
    268       1.1   mycroft 	ip->i_flag = IN_MODIFIED;
    269       1.1   mycroft 	ip->i_dev = ump->um_dev;
    270       1.8    bouyer 	ip->i_number = ip->i_din.ffs_din.di_inumber = ino;
    271       1.1   mycroft 	ip->i_lfs = ump->um_lfs;
    272       1.1   mycroft #ifdef QUOTA
    273       1.1   mycroft 	for (i = 0; i < MAXQUOTAS; i++)
    274       1.1   mycroft 		ip->i_dquot[i] = NODQUOT;
    275       1.1   mycroft #endif
    276       1.1   mycroft 	ip->i_lockf = 0;
    277       1.1   mycroft 	ip->i_diroff = 0;
    278       1.8    bouyer 	ip->i_ffs_mode = 0;
    279       1.8    bouyer 	ip->i_ffs_size = 0;
    280       1.8    bouyer 	ip->i_ffs_blocks = 0;
    281       1.1   mycroft 	++ump->um_lfs->lfs_uinodes;
    282       1.1   mycroft 	return (0);
    283       1.1   mycroft }
    284       1.1   mycroft 
    285       1.1   mycroft /* Free an inode. */
    286       1.1   mycroft /* ARGUSED */
    287       1.1   mycroft int
    288       1.3  christos lfs_vfree(v)
    289       1.3  christos 	void *v;
    290       1.3  christos {
    291       1.1   mycroft 	struct vop_vfree_args /* {
    292      1.17  perseant 				 struct vnode *a_pvp;
    293      1.17  perseant 				 ino_t a_ino;
    294      1.17  perseant 				 int a_mode;
    295      1.17  perseant 				 } */ *ap = v;
    296       1.1   mycroft 	SEGUSE *sup;
    297       1.1   mycroft 	struct buf *bp;
    298       1.1   mycroft 	struct ifile *ifp;
    299       1.1   mycroft 	struct inode *ip;
    300  1.25.6.1  wrstuden 	struct vnode *vp;
    301       1.1   mycroft 	struct lfs *fs;
    302      1.11      fvdl 	ufs_daddr_t old_iaddr;
    303       1.1   mycroft 	ino_t ino;
    304      1.20  perseant 	int already_locked;
    305  1.25.6.1  wrstuden 	extern int lfs_dirvcount;
    306      1.17  perseant 
    307       1.1   mycroft 	/* Get the inode number and file system. */
    308  1.25.6.1  wrstuden 	vp = ap->a_pvp;
    309  1.25.6.1  wrstuden 	ip = VTOI(vp);
    310       1.1   mycroft 	fs = ip->i_lfs;
    311       1.1   mycroft 	ino = ip->i_number;
    312      1.17  perseant 
    313      1.20  perseant 	/* If we already hold ufs_hashlock, don't panic, just do it anyway */
    314      1.20  perseant 	already_locked = lockstatus(&ufs_hashlock) && ufs_hashlock.lk_lockholder == curproc->p_pid;
    315  1.25.6.1  wrstuden 	while(WRITEINPROG(vp)
    316      1.17  perseant 	      || fs->lfs_seglock
    317      1.20  perseant 	      || (!already_locked && lockmgr(&ufs_hashlock, LK_EXCLUSIVE|LK_SLEEPFAIL, 0)))
    318      1.17  perseant 	{
    319  1.25.6.1  wrstuden 		if (WRITEINPROG(vp)) {
    320  1.25.6.1  wrstuden 			tsleep(vp, (PRIBIO+1), "lfs_vfree", 0);
    321      1.17  perseant 		}
    322      1.17  perseant 		if (fs->lfs_seglock) {
    323      1.17  perseant 			if (fs->lfs_lockpid == curproc->p_pid) {
    324      1.17  perseant 				break;
    325      1.17  perseant 			} else {
    326      1.17  perseant 				tsleep(&fs->lfs_seglock, PRIBIO + 1, "lfs_vfr1", 0);
    327      1.17  perseant 			}
    328      1.17  perseant 		}
    329      1.17  perseant 	}
    330      1.17  perseant 
    331  1.25.6.1  wrstuden 	if(vp->v_flag & VDIROP) {
    332  1.25.6.1  wrstuden 		--lfs_dirvcount;
    333  1.25.6.1  wrstuden 		vp->v_flag &= ~VDIROP;
    334  1.25.6.1  wrstuden 		wakeup(&lfs_dirvcount);
    335  1.25.6.1  wrstuden 		lfs_vunref(vp);
    336  1.25.6.1  wrstuden 	}
    337  1.25.6.1  wrstuden 
    338      1.17  perseant 	if (ip->i_flag & IN_CLEANING) {
    339      1.17  perseant 		--fs->lfs_uinodes;
    340      1.17  perseant 	}
    341       1.1   mycroft 	if (ip->i_flag & IN_MODIFIED) {
    342       1.1   mycroft 		--fs->lfs_uinodes;
    343       1.1   mycroft 	}
    344      1.25  perseant 	ip->i_flag &= ~(IN_CLEANING | IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE);
    345      1.17  perseant #ifdef DEBUG_LFS
    346      1.17  perseant 	if((int32_t)fs->lfs_uinodes<0) {
    347      1.17  perseant 		printf("U1");
    348      1.17  perseant 		fs->lfs_uinodes=0;
    349      1.17  perseant 	}
    350      1.17  perseant #endif
    351       1.1   mycroft 	/*
    352       1.1   mycroft 	 * Set the ifile's inode entry to unused, increment its version number
    353       1.1   mycroft 	 * and link it into the free chain.
    354       1.1   mycroft 	 */
    355       1.1   mycroft 	LFS_IENTRY(ifp, fs, ino, bp);
    356       1.1   mycroft 	old_iaddr = ifp->if_daddr;
    357       1.1   mycroft 	ifp->if_daddr = LFS_UNUSED_DADDR;
    358       1.1   mycroft 	++ifp->if_version;
    359       1.1   mycroft 	ifp->if_nextfree = fs->lfs_free;
    360       1.1   mycroft 	fs->lfs_free = ino;
    361       1.1   mycroft 	(void) VOP_BWRITE(bp);
    362      1.17  perseant #ifdef DIAGNOSTIC
    363      1.17  perseant 	if(fs->lfs_free == LFS_UNUSED_INUM) {
    364      1.17  perseant 		panic("inode 0 freed");
    365      1.17  perseant 	}
    366      1.17  perseant #endif /* DIAGNOSTIC */
    367       1.1   mycroft 	if (old_iaddr != LFS_UNUSED_DADDR) {
    368       1.1   mycroft 		LFS_SEGENTRY(sup, fs, datosn(fs, old_iaddr), bp);
    369      1.22  perseant #ifdef DIAGNOSTIC
    370      1.17  perseant 		if (sup->su_nbytes < DINODE_SIZE) {
    371      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);
    372      1.22  perseant 			panic("lfs_vfree: negative byte count");
    373      1.17  perseant 			sup->su_nbytes = DINODE_SIZE;
    374      1.17  perseant 		}
    375      1.22  perseant #endif
    376      1.16   thorpej 		sup->su_nbytes -= DINODE_SIZE;
    377       1.1   mycroft 		(void) VOP_BWRITE(bp);
    378       1.1   mycroft 	}
    379      1.21  perseant 	if(!already_locked)
    380      1.21  perseant 		lockmgr(&ufs_hashlock, LK_RELEASE, 0);
    381      1.17  perseant 
    382       1.1   mycroft 	/* Set superblock modified bit and decrement file count. */
    383       1.1   mycroft 	fs->lfs_fmod = 1;
    384       1.1   mycroft 	--fs->lfs_nfiles;
    385      1.17  perseant 
    386       1.1   mycroft 	return (0);
    387       1.1   mycroft }
    388