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