1999-11-09 05:21:05 +03:00
|
|
|
/* $NetBSD: lfs_alloc.c,v 1.27 1999/11/09 02:21:05 perseant Exp $ */
|
1994-06-29 10:39:25 +04:00
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Konrad E. Schroder <perseant@hhhh.org>.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1991, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
1994-06-29 10:39:25 +04:00
|
|
|
* @(#)lfs_alloc.c 8.4 (Berkeley) 1/4/94
|
1994-06-08 15:41:58 +04:00
|
|
|
*/
|
|
|
|
|
1998-06-09 11:46:31 +04:00
|
|
|
#if defined(_KERNEL) && !defined(_LKM)
|
1998-06-08 08:27:50 +04:00
|
|
|
#include "opt_quota.h"
|
1998-06-09 11:46:31 +04:00
|
|
|
#endif
|
1998-06-08 08:27:50 +04:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/param.h>
|
1996-02-10 01:28:45 +03:00
|
|
|
#include <sys/systm.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/malloc.h>
|
1998-09-01 07:26:05 +04:00
|
|
|
#include <sys/pool.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
|
|
|
|
#include <ufs/ufs/quota.h>
|
|
|
|
#include <ufs/ufs/inode.h>
|
|
|
|
#include <ufs/ufs/ufsmount.h>
|
1996-02-10 01:28:45 +03:00
|
|
|
#include <ufs/ufs/ufs_extern.h>
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
#include <ufs/lfs/lfs.h>
|
|
|
|
#include <ufs/lfs/lfs_extern.h>
|
|
|
|
|
1999-03-10 03:20:00 +03:00
|
|
|
extern struct lock ufs_hashlock;
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Allocate a new inode. */
|
|
|
|
/* ARGSUSED */
|
|
|
|
int
|
1996-02-10 01:28:45 +03:00
|
|
|
lfs_valloc(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_valloc_args /* {
|
1999-03-10 03:20:00 +03:00
|
|
|
struct vnode *a_pvp;
|
|
|
|
int a_mode;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
} */ *ap = v;
|
1994-06-08 15:41:58 +04:00
|
|
|
struct lfs *fs;
|
|
|
|
struct buf *bp;
|
|
|
|
struct ifile *ifp;
|
|
|
|
struct inode *ip;
|
|
|
|
struct vnode *vp;
|
1998-03-01 05:20:01 +03:00
|
|
|
ufs_daddr_t blkno;
|
1994-06-08 15:41:58 +04:00
|
|
|
ino_t new_ino;
|
|
|
|
u_long i, max;
|
|
|
|
int error;
|
1999-11-06 23:33:05 +03:00
|
|
|
extern int lfs_dirvcount;
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
fs = VTOI(ap->a_pvp)->i_lfs;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
/*
|
1999-11-06 23:33:05 +03:00
|
|
|
* Prevent a race getting lfs_free. We use
|
|
|
|
* the ufs_hashlock here because we need that anyway for
|
|
|
|
* the hash insertion later.
|
1999-03-10 03:20:00 +03:00
|
|
|
*/
|
1999-11-06 23:33:05 +03:00
|
|
|
lockmgr(&ufs_hashlock, LK_EXCLUSIVE, 0);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
/* Get the head of the freelist. */
|
1994-06-08 15:41:58 +04:00
|
|
|
new_ino = fs->lfs_free;
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if(new_ino == LFS_UNUSED_INUM) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
lfs_dump_super(fs);
|
|
|
|
#endif /* DEBUG */
|
|
|
|
panic("inode 0 allocated [1]");
|
|
|
|
}
|
|
|
|
#endif /* DIAGNOSTIC */
|
1994-06-08 15:41:58 +04:00
|
|
|
#ifdef ALLOCPRINT
|
1996-10-13 01:58:44 +04:00
|
|
|
printf("lfs_ialloc: allocate inode %d\n", new_ino);
|
1994-06-08 15:41:58 +04:00
|
|
|
#endif
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Remove the inode from the free list and write the new start
|
|
|
|
* of the free list into the superblock.
|
|
|
|
*/
|
|
|
|
LFS_IENTRY(ifp, fs, new_ino, bp);
|
|
|
|
if (ifp->if_daddr != LFS_UNUSED_DADDR)
|
1999-03-10 03:20:00 +03:00
|
|
|
panic("lfs_ialloc: inuse inode %d on the free list", new_ino);
|
1994-06-08 15:41:58 +04:00
|
|
|
fs->lfs_free = ifp->if_nextfree;
|
1999-09-04 02:48:51 +04:00
|
|
|
#ifdef LFS_DEBUG_NEXTFREE
|
|
|
|
ifp->if_nextfree = 0;
|
|
|
|
#endif
|
1999-11-09 05:21:05 +03:00
|
|
|
/*
|
|
|
|
* If a vflush is called before the dirop that created us is written,
|
|
|
|
* and then the system crashes, we could be in limbo (allocated but
|
|
|
|
* not connected), and stay that way forever. To detect this
|
|
|
|
* condition easily, we set if_daddr=UNASSIGNED, and walk the free
|
|
|
|
* list at fs mount time (or roll-forward time). Any inodes with
|
|
|
|
* if_daddr==UNASSIGNED have never been written to disk, and will
|
|
|
|
* be silently restored to the free list.
|
|
|
|
*/
|
|
|
|
ifp->if_daddr = UNASSIGNED;
|
|
|
|
VOP_BWRITE(bp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Extend IFILE so that the next lfs_valloc will succeed. */
|
|
|
|
if (fs->lfs_free == LFS_UNUSED_INUM) {
|
|
|
|
vp = fs->lfs_ivnode;
|
1999-03-10 03:20:00 +03:00
|
|
|
VOP_LOCK(vp,LK_EXCLUSIVE);
|
1994-06-08 15:41:58 +04:00
|
|
|
ip = VTOI(vp);
|
1997-06-11 14:09:37 +04:00
|
|
|
blkno = lblkno(fs, ip->i_ffs_size);
|
1998-03-01 05:20:01 +03:00
|
|
|
lfs_balloc(vp, 0, fs->lfs_bsize, blkno, &bp);
|
1997-06-11 14:09:37 +04:00
|
|
|
ip->i_ffs_size += fs->lfs_bsize;
|
1998-02-07 20:28:18 +03:00
|
|
|
uvm_vnp_setsize(vp, ip->i_ffs_size);
|
|
|
|
(void)uvm_vnp_uncache(vp);
|
1994-06-08 15:41:58 +04:00
|
|
|
|
|
|
|
i = (blkno - fs->lfs_segtabsz - fs->lfs_cleansz) *
|
1999-03-10 03:20:00 +03:00
|
|
|
fs->lfs_ifpb;
|
1994-06-08 15:41:58 +04:00
|
|
|
fs->lfs_free = i;
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if(fs->lfs_free == LFS_UNUSED_INUM)
|
|
|
|
panic("inode 0 allocated [2]");
|
|
|
|
#endif /* DIAGNOSTIC */
|
1994-06-08 15:41:58 +04:00
|
|
|
max = i + fs->lfs_ifpb;
|
|
|
|
for (ifp = (struct ifile *)bp->b_data; i < max; ++ifp) {
|
|
|
|
ifp->if_version = 1;
|
|
|
|
ifp->if_daddr = LFS_UNUSED_DADDR;
|
|
|
|
ifp->if_nextfree = ++i;
|
|
|
|
}
|
|
|
|
ifp--;
|
|
|
|
ifp->if_nextfree = LFS_UNUSED_INUM;
|
1999-03-10 03:20:00 +03:00
|
|
|
VOP_UNLOCK(vp,0);
|
|
|
|
if ((error = VOP_BWRITE(bp)) != 0) {
|
|
|
|
lockmgr(&ufs_hashlock, LK_RELEASE, 0);
|
1994-06-08 15:41:58 +04:00
|
|
|
return (error);
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if(fs->lfs_free == LFS_UNUSED_INUM)
|
|
|
|
panic("inode 0 allocated [3]");
|
|
|
|
#endif /* DIAGNOSTIC */
|
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Create a vnode to associate with the inode. */
|
1999-11-06 23:33:05 +03:00
|
|
|
if ((error = lfs_vcreate(ap->a_pvp->v_mount, new_ino, &vp)) != 0) {
|
|
|
|
lockmgr(&ufs_hashlock, LK_RELEASE, 0);
|
1994-06-08 15:41:58 +04:00
|
|
|
return (error);
|
1999-11-06 23:33:05 +03:00
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
ip = VTOI(vp);
|
|
|
|
/* Zero out the direct and indirect block addresses. */
|
1998-10-23 04:32:35 +04:00
|
|
|
bzero(&ip->i_din, sizeof(ip->i_din));
|
1997-06-11 14:09:37 +04:00
|
|
|
ip->i_din.ffs_din.di_inumber = new_ino;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Set a new generation number for this inode. */
|
1997-06-11 14:09:37 +04:00
|
|
|
ip->i_ffs_gen++;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Insert into the inode hash table. */
|
|
|
|
ufs_ihashins(ip);
|
1999-11-06 23:33:05 +03:00
|
|
|
lockmgr(&ufs_hashlock, LK_RELEASE, 0);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1998-06-25 00:58:44 +04:00
|
|
|
error = ufs_vinit(vp->v_mount, lfs_specop_p, lfs_fifoop_p, &vp);
|
1996-02-10 01:28:45 +03:00
|
|
|
if (error) {
|
1994-06-08 15:41:58 +04:00
|
|
|
vput(vp);
|
|
|
|
*ap->a_vpp = NULL;
|
|
|
|
return (error);
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
*ap->a_vpp = vp;
|
1999-03-10 03:20:00 +03:00
|
|
|
if(!(vp->v_flag & VDIROP)) {
|
|
|
|
lfs_vref(vp);
|
1999-11-06 23:33:05 +03:00
|
|
|
++lfs_dirvcount;
|
1999-03-10 03:20:00 +03:00
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
vp->v_flag |= VDIROP;
|
|
|
|
VREF(ip->i_devvp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Set superblock modified bit and increment file count. */
|
|
|
|
fs->lfs_fmod = 1;
|
|
|
|
++fs->lfs_nfiles;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a new vnode/inode pair and initialize what fields we can. */
|
|
|
|
int
|
|
|
|
lfs_vcreate(mp, ino, vpp)
|
|
|
|
struct mount *mp;
|
|
|
|
ino_t ino;
|
|
|
|
struct vnode **vpp;
|
|
|
|
{
|
1996-02-10 01:28:45 +03:00
|
|
|
extern int (**lfs_vnodeop_p) __P((void *));
|
1994-06-08 15:41:58 +04:00
|
|
|
struct inode *ip;
|
|
|
|
struct ufsmount *ump;
|
1996-03-25 15:53:35 +03:00
|
|
|
int error;
|
|
|
|
#ifdef QUOTA
|
|
|
|
int i;
|
|
|
|
#endif
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Create the vnode. */
|
1996-02-10 01:28:45 +03:00
|
|
|
if ((error = getnewvnode(VT_LFS, mp, lfs_vnodeop_p, vpp)) != 0) {
|
1994-06-08 15:41:58 +04:00
|
|
|
*vpp = NULL;
|
|
|
|
return (error);
|
|
|
|
}
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Get a pointer to the private mount structure. */
|
|
|
|
ump = VFSTOUFS(mp);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Initialize the inode. */
|
1998-09-01 07:26:05 +04:00
|
|
|
ip = pool_get(&lfs_inode_pool, PR_WAITOK);
|
1994-06-08 15:41:58 +04:00
|
|
|
(*vpp)->v_data = ip;
|
|
|
|
ip->i_vnode = *vpp;
|
|
|
|
ip->i_devvp = ump->um_devvp;
|
|
|
|
ip->i_flag = IN_MODIFIED;
|
|
|
|
ip->i_dev = ump->um_dev;
|
1997-06-11 14:09:37 +04:00
|
|
|
ip->i_number = ip->i_din.ffs_din.di_inumber = ino;
|
1994-06-08 15:41:58 +04:00
|
|
|
ip->i_lfs = ump->um_lfs;
|
|
|
|
#ifdef QUOTA
|
|
|
|
for (i = 0; i < MAXQUOTAS; i++)
|
|
|
|
ip->i_dquot[i] = NODQUOT;
|
|
|
|
#endif
|
|
|
|
ip->i_lockf = 0;
|
|
|
|
ip->i_diroff = 0;
|
1997-06-11 14:09:37 +04:00
|
|
|
ip->i_ffs_mode = 0;
|
|
|
|
ip->i_ffs_size = 0;
|
|
|
|
ip->i_ffs_blocks = 0;
|
1994-06-08 15:41:58 +04:00
|
|
|
++ump->um_lfs->lfs_uinodes;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free an inode. */
|
|
|
|
/* ARGUSED */
|
|
|
|
int
|
1996-02-10 01:28:45 +03:00
|
|
|
lfs_vfree(v)
|
|
|
|
void *v;
|
|
|
|
{
|
1994-06-08 15:41:58 +04:00
|
|
|
struct vop_vfree_args /* {
|
1999-03-10 03:20:00 +03:00
|
|
|
struct vnode *a_pvp;
|
|
|
|
ino_t a_ino;
|
|
|
|
int a_mode;
|
|
|
|
} */ *ap = v;
|
1994-06-08 15:41:58 +04:00
|
|
|
SEGUSE *sup;
|
|
|
|
struct buf *bp;
|
|
|
|
struct ifile *ifp;
|
|
|
|
struct inode *ip;
|
|
|
|
struct lfs *fs;
|
1998-03-01 05:20:01 +03:00
|
|
|
ufs_daddr_t old_iaddr;
|
1994-06-08 15:41:58 +04:00
|
|
|
ino_t ino;
|
1999-04-16 04:41:58 +04:00
|
|
|
int already_locked;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Get the inode number and file system. */
|
|
|
|
ip = VTOI(ap->a_pvp);
|
|
|
|
fs = ip->i_lfs;
|
|
|
|
ino = ip->i_number;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1999-04-16 04:41:58 +04:00
|
|
|
/* If we already hold ufs_hashlock, don't panic, just do it anyway */
|
|
|
|
already_locked = lockstatus(&ufs_hashlock) && ufs_hashlock.lk_lockholder == curproc->p_pid;
|
1999-03-10 03:20:00 +03:00
|
|
|
while(WRITEINPROG(ap->a_pvp)
|
|
|
|
|| fs->lfs_seglock
|
1999-04-16 04:41:58 +04:00
|
|
|
|| (!already_locked && lockmgr(&ufs_hashlock, LK_EXCLUSIVE|LK_SLEEPFAIL, 0)))
|
1999-03-10 03:20:00 +03:00
|
|
|
{
|
|
|
|
if (WRITEINPROG(ap->a_pvp)) {
|
|
|
|
tsleep(ap->a_pvp, (PRIBIO+1), "lfs_vfree", 0);
|
|
|
|
}
|
|
|
|
if (fs->lfs_seglock) {
|
|
|
|
if (fs->lfs_lockpid == curproc->p_pid) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
tsleep(&fs->lfs_seglock, PRIBIO + 1, "lfs_vfr1", 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ip->i_flag & IN_CLEANING) {
|
|
|
|
--fs->lfs_uinodes;
|
|
|
|
}
|
1994-06-08 15:41:58 +04:00
|
|
|
if (ip->i_flag & IN_MODIFIED) {
|
|
|
|
--fs->lfs_uinodes;
|
|
|
|
}
|
1999-09-04 02:48:51 +04:00
|
|
|
ip->i_flag &= ~(IN_CLEANING | IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE);
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef DEBUG_LFS
|
|
|
|
if((int32_t)fs->lfs_uinodes<0) {
|
|
|
|
printf("U1");
|
|
|
|
fs->lfs_uinodes=0;
|
|
|
|
}
|
|
|
|
#endif
|
1994-06-08 15:41:58 +04:00
|
|
|
/*
|
|
|
|
* Set the ifile's inode entry to unused, increment its version number
|
|
|
|
* and link it into the free chain.
|
|
|
|
*/
|
|
|
|
LFS_IENTRY(ifp, fs, ino, bp);
|
|
|
|
old_iaddr = ifp->if_daddr;
|
|
|
|
ifp->if_daddr = LFS_UNUSED_DADDR;
|
|
|
|
++ifp->if_version;
|
|
|
|
ifp->if_nextfree = fs->lfs_free;
|
|
|
|
fs->lfs_free = ino;
|
|
|
|
(void) VOP_BWRITE(bp);
|
1999-03-10 03:20:00 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if(fs->lfs_free == LFS_UNUSED_INUM) {
|
|
|
|
panic("inode 0 freed");
|
|
|
|
}
|
|
|
|
#endif /* DIAGNOSTIC */
|
1994-06-08 15:41:58 +04:00
|
|
|
if (old_iaddr != LFS_UNUSED_DADDR) {
|
|
|
|
LFS_SEGENTRY(sup, fs, datosn(fs, old_iaddr), bp);
|
1999-06-16 02:25:41 +04:00
|
|
|
#ifdef DIAGNOSTIC
|
1999-03-10 03:20:00 +03:00
|
|
|
if (sup->su_nbytes < DINODE_SIZE) {
|
1999-06-18 02:22:41 +04:00
|
|
|
printf("lfs_vfree: negative byte count (segment %d short by %d)\n", datosn(fs, old_iaddr), (int)DINODE_SIZE - sup->su_nbytes);
|
1999-06-16 02:25:41 +04:00
|
|
|
panic("lfs_vfree: negative byte count");
|
1999-03-10 03:20:00 +03:00
|
|
|
sup->su_nbytes = DINODE_SIZE;
|
|
|
|
}
|
1999-06-16 02:25:41 +04:00
|
|
|
#endif
|
1998-10-23 04:32:35 +04:00
|
|
|
sup->su_nbytes -= DINODE_SIZE;
|
1994-06-08 15:41:58 +04:00
|
|
|
(void) VOP_BWRITE(bp);
|
|
|
|
}
|
1999-04-16 20:23:46 +04:00
|
|
|
if(!already_locked)
|
|
|
|
lockmgr(&ufs_hashlock, LK_RELEASE, 0);
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
/* Set superblock modified bit and decrement file count. */
|
|
|
|
fs->lfs_fmod = 1;
|
|
|
|
--fs->lfs_nfiles;
|
1999-03-10 03:20:00 +03:00
|
|
|
|
1994-06-08 15:41:58 +04:00
|
|
|
return (0);
|
|
|
|
}
|