2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)ffs_inode.c 8.13 (Berkeley) 4/21/95
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include "opt_quota.h"
39 #include <sys/param.h>
40 #include <sys/systm.h>
43 #include <sys/malloc.h>
44 #include <sys/mount.h>
46 #include <sys/racct.h>
47 #include <sys/random.h>
48 #include <sys/resourcevar.h>
49 #include <sys/rwlock.h>
51 #include <sys/vmmeter.h>
52 #include <sys/vnode.h>
55 #include <vm/vm_extern.h>
56 #include <vm/vm_object.h>
58 #include <ufs/ufs/extattr.h>
59 #include <ufs/ufs/quota.h>
60 #include <ufs/ufs/ufsmount.h>
61 #include <ufs/ufs/inode.h>
62 #include <ufs/ufs/ufs_extern.h>
64 #include <ufs/ffs/fs.h>
65 #include <ufs/ffs/ffs_extern.h>
67 static int ffs_indirtrunc(struct inode *, ufs2_daddr_t, ufs2_daddr_t,
68 ufs2_daddr_t, int, ufs2_daddr_t *);
71 * Update the access, modified, and inode change times as specified by the
72 * IN_ACCESS, IN_UPDATE, and IN_CHANGE flags respectively. Write the inode
73 * to disk if the IN_MODIFIED flag is set (it may be set initially, or by
74 * the timestamp update). The IN_LAZYMOD flag is set to force a write
75 * later if not now. The IN_LAZYACCESS is set instead of IN_MODIFIED if the fs
76 * is currently being suspended (or is suspended) and vnode has been accessed.
77 * If we write now, then clear IN_MODIFIED, IN_LAZYACCESS and IN_LAZYMOD to
78 * reflect the presumably successful write, and if waitfor is set, then wait
79 * for the write to complete.
82 ffs_update(vp, waitfor)
91 ASSERT_VOP_ELOCKED(vp, "ffs_update");
94 if ((ip->i_flag & IN_MODIFIED) == 0 && waitfor == 0)
96 ip->i_flag &= ~(IN_LAZYACCESS | IN_LAZYMOD | IN_MODIFIED);
98 if (fs->fs_ronly && ITOUMP(ip)->um_fsckpid == 0)
101 * If we are updating a snapshot and another process is currently
102 * writing the buffer containing the inode for this snapshot then
103 * a deadlock can occur when it tries to check the snapshot to see
104 * if that block needs to be copied. Thus when updating a snapshot
105 * we check to see if the buffer is already locked, and if it is
106 * we drop the snapshot lock until the buffer has been written
107 * and is available to us. We have to grab a reference to the
108 * snapshot vnode to prevent it from being removed while we are
109 * waiting for the buffer.
113 flags = GB_LOCK_NOWAIT;
115 error = bread_gb(ITODEVVP(ip),
116 fsbtodb(fs, ino_to_fsba(fs, ip->i_number)),
117 (int) fs->fs_bsize, NOCRED, flags, &bp);
121 KASSERT((IS_SNAPSHOT(ip)), ("EBUSY from non-snapshot"));
123 * Wait for our inode block to become available.
125 * Hold a reference to the vnode to protect against
126 * ffs_snapgone(). Since we hold a reference, it can only
127 * get reclaimed (VI_DOOMED flag) in a forcible downgrade
128 * or unmount. For an unmount, the entire filesystem will be
129 * gone, so we cannot attempt to touch anything associated
130 * with it while the vnode is unlocked; all we can do is
131 * pause briefly and try again. If when we relock the vnode
132 * we discover that it has been reclaimed, updating it is no
133 * longer necessary and we can just return an error.
138 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
140 if ((vp->v_iflag & VI_DOOMED) != 0)
144 if (DOINGSOFTDEP(vp))
145 softdep_update_inodeblock(ip, bp, waitfor);
146 else if (ip->i_effnlink != ip->i_nlink)
147 panic("ffs_update: bad link cnt");
149 *((struct ufs1_dinode *)bp->b_data +
150 ino_to_fsbo(fs, ip->i_number)) = *ip->i_din1;
152 * XXX: FIX? The entropy here is desirable,
153 * but the harvesting may be expensive
155 random_harvest_queue(&(ip->i_din1), sizeof(ip->i_din1), RANDOM_FS_ATIME);
157 ffs_update_dinode_ckhash(fs, ip->i_din2);
158 *((struct ufs2_dinode *)bp->b_data +
159 ino_to_fsbo(fs, ip->i_number)) = *ip->i_din2;
161 * XXX: FIX? The entropy here is desirable,
162 * but the harvesting may be expensive
164 random_harvest_queue(&(ip->i_din2), sizeof(ip->i_din2), RANDOM_FS_ATIME);
168 else if (vm_page_count_severe() || buf_dirty_count_severe()) {
172 if (bp->b_bufsize == fs->fs_bsize)
173 bp->b_flags |= B_CLUSTEROK;
180 #define SINGLE 0 /* index of single indirect block */
181 #define DOUBLE 1 /* index of double indirect block */
182 #define TRIPLE 2 /* index of triple indirect block */
184 * Truncate the inode ip to at most length size, freeing the
188 ffs_truncate(vp, length, flags, cred)
195 ufs2_daddr_t bn, lbn, lastblock, lastiblock[UFS_NIADDR];
196 ufs2_daddr_t indir_lbn[UFS_NIADDR], oldblks[UFS_NDADDR + UFS_NIADDR];
197 ufs2_daddr_t newblks[UFS_NDADDR + UFS_NIADDR];
198 ufs2_daddr_t count, blocksreleased = 0, datablocks, blkno;
202 struct ufsmount *ump;
203 int softdeptrunc, journaltrunc;
204 int needextclean, extblocks;
205 int offset, size, level, nblocks;
206 int i, error, allerror, indiroff, waitforupdate;
211 ump = VFSTOUFS(vp->v_mount);
215 ASSERT_VOP_LOCKED(vp, "ffs_truncate");
219 if (length > fs->fs_maxfilesize)
222 error = getinoquota(ip);
227 * Historically clients did not have to specify which data
228 * they were truncating. So, if not specified, we assume
229 * traditional behavior, e.g., just the normal data.
231 if ((flags & (IO_EXT | IO_NORMAL)) == 0)
233 if (!DOINGSOFTDEP(vp) && !DOINGASYNC(vp))
235 waitforupdate = (flags & IO_SYNC) != 0 || !DOINGASYNC(vp);
237 * If we are truncating the extended-attributes, and cannot
238 * do it with soft updates, then do it slowly here. If we are
239 * truncating both the extended attributes and the file contents
240 * (e.g., the file is being unlinked), then pick it off with
241 * soft updates below.
246 journaltrunc = DOINGSUJ(vp);
247 if (journaltrunc == 0 && DOINGSOFTDEP(vp) && length == 0)
248 softdeptrunc = !softdep_slowdown(vp);
250 datablocks = DIP(ip, i_blocks);
251 if (fs->fs_magic == FS_UFS2_MAGIC && ip->i_din2->di_extsize > 0) {
252 extblocks = btodb(fragroundup(fs, ip->i_din2->di_extsize));
253 datablocks -= extblocks;
255 if ((flags & IO_EXT) && extblocks > 0) {
257 panic("ffs_truncate: partial trunc of extdata");
258 if (softdeptrunc || journaltrunc) {
259 if ((flags & IO_NORMAL) == 0)
263 if ((error = ffs_syncvnode(vp, MNT_WAIT, 0)) != 0)
266 (void) chkdq(ip, -extblocks, NOCRED, 0);
268 vinvalbuf(vp, V_ALT, 0, 0);
270 OFF_TO_IDX(lblktosize(fs, -extblocks)), 0);
271 osize = ip->i_din2->di_extsize;
272 ip->i_din2->di_blocks -= extblocks;
273 ip->i_din2->di_extsize = 0;
274 for (i = 0; i < UFS_NXADDR; i++) {
275 oldblks[i] = ip->i_din2->di_extb[i];
276 ip->i_din2->di_extb[i] = 0;
278 ip->i_flag |= IN_CHANGE;
279 if ((error = ffs_update(vp, waitforupdate)))
281 for (i = 0; i < UFS_NXADDR; i++) {
284 ffs_blkfree(ump, fs, ITODEVVP(ip), oldblks[i],
285 sblksize(fs, osize, i), ip->i_number,
286 vp->v_type, NULL, SINGLETON_KEY);
290 if ((flags & IO_NORMAL) == 0)
292 if (vp->v_type == VLNK &&
293 (ip->i_size < vp->v_mount->mnt_maxsymlinklen ||
297 panic("ffs_truncate: partial truncate of symlink");
299 bzero(SHORTLINK(ip), (u_int)ip->i_size);
301 DIP_SET(ip, i_size, 0);
302 ip->i_flag |= IN_CHANGE | IN_UPDATE;
305 return (ffs_update(vp, waitforupdate));
307 if (ip->i_size == length) {
308 ip->i_flag |= IN_CHANGE | IN_UPDATE;
311 return (ffs_update(vp, 0));
314 panic("ffs_truncate: read-only filesystem");
317 vp->v_lasta = vp->v_clen = vp->v_cstart = vp->v_lastw = 0;
320 * Lengthen the size of the file. We must ensure that the
321 * last byte of the file is allocated. Since the smallest
322 * value of osize is 0, length will be at least 1.
324 if (osize < length) {
325 vnode_pager_setsize(vp, length);
327 error = UFS_BALLOC(vp, length - 1, 1, cred, flags, &bp);
329 vnode_pager_setsize(vp, osize);
333 DIP_SET(ip, i_size, length);
334 if (bp->b_bufsize == fs->fs_bsize)
335 bp->b_flags |= B_CLUSTEROK;
338 else if (DOINGASYNC(vp))
342 ip->i_flag |= IN_CHANGE | IN_UPDATE;
343 return (ffs_update(vp, waitforupdate));
346 * Lookup block number for a given offset. Zero length files
347 * have no blocks, so return a blkno of -1.
349 lbn = lblkno(fs, length - 1);
352 } else if (lbn < UFS_NDADDR) {
353 blkno = DIP(ip, i_db[lbn]);
355 error = UFS_BALLOC(vp, lblktosize(fs, (off_t)lbn), fs->fs_bsize,
356 cred, BA_METAONLY, &bp);
359 indiroff = (lbn - UFS_NDADDR) % NINDIR(fs);
361 blkno = ((ufs1_daddr_t *)(bp->b_data))[indiroff];
363 blkno = ((ufs2_daddr_t *)(bp->b_data))[indiroff];
365 * If the block number is non-zero, then the indirect block
366 * must have been previously allocated and need not be written.
367 * If the block number is zero, then we may have allocated
368 * the indirect block and hence need to write it out.
372 else if (flags & IO_SYNC)
378 * If the block number at the new end of the file is zero,
379 * then we must allocate it to ensure that the last block of
380 * the file is allocated. Soft updates does not handle this
381 * case, so here we have to clean up the soft updates data
382 * structures describing the allocation past the truncation
383 * point. Finding and deallocating those structures is a lot of
384 * work. Since partial truncation with a hole at the end occurs
385 * rarely, we solve the problem by syncing the file so that it
386 * will have no soft updates data structures left.
388 if (blkno == 0 && (error = ffs_syncvnode(vp, MNT_WAIT, 0)) != 0)
390 if (blkno != 0 && DOINGSOFTDEP(vp)) {
391 if (softdeptrunc == 0 && journaltrunc == 0) {
393 * If soft updates cannot handle this truncation,
394 * clean up soft dependency data structures and
395 * fall through to the synchronous truncation.
397 if ((error = ffs_syncvnode(vp, MNT_WAIT, 0)) != 0)
400 flags = IO_NORMAL | (needextclean ? IO_EXT: 0);
402 softdep_journal_freeblocks(ip, cred, length,
405 softdep_setup_freeblocks(ip, length, flags);
406 ASSERT_VOP_LOCKED(vp, "ffs_truncate1");
407 if (journaltrunc == 0) {
408 ip->i_flag |= IN_CHANGE | IN_UPDATE;
409 error = ffs_update(vp, 0);
415 * Shorten the size of the file. If the last block of the
416 * shortened file is unallocated, we must allocate it.
417 * Additionally, if the file is not being truncated to a
418 * block boundary, the contents of the partial block
419 * following the end of the file must be zero'ed in
420 * case it ever becomes accessible again because of
421 * subsequent file growth. Directories however are not
422 * zero'ed as they should grow back initialized to empty.
424 offset = blkoff(fs, length);
425 if (blkno != 0 && offset == 0) {
427 DIP_SET(ip, i_size, length);
429 lbn = lblkno(fs, length);
431 error = UFS_BALLOC(vp, length - 1, 1, cred, flags, &bp);
435 * When we are doing soft updates and the UFS_BALLOC
436 * above fills in a direct block hole with a full sized
437 * block that will be truncated down to a fragment below,
438 * we must flush out the block dependency with an FSYNC
439 * so that we do not get a soft updates inconsistency
440 * when we create the fragment below.
442 if (DOINGSOFTDEP(vp) && lbn < UFS_NDADDR &&
443 fragroundup(fs, blkoff(fs, length)) < fs->fs_bsize &&
444 (error = ffs_syncvnode(vp, MNT_WAIT, 0)) != 0)
447 DIP_SET(ip, i_size, length);
448 size = blksize(fs, ip, lbn);
449 if (vp->v_type != VDIR && offset != 0)
450 bzero((char *)bp->b_data + offset,
451 (u_int)(size - offset));
452 /* Kirk's code has reallocbuf(bp, size, 1) here */
454 if (bp->b_bufsize == fs->fs_bsize)
455 bp->b_flags |= B_CLUSTEROK;
458 else if (DOINGASYNC(vp))
464 * Calculate index into inode's block list of
465 * last direct and indirect blocks (if any)
466 * which we want to keep. Lastblock is -1 when
467 * the file is truncated to 0.
469 lastblock = lblkno(fs, length + fs->fs_bsize - 1) - 1;
470 lastiblock[SINGLE] = lastblock - UFS_NDADDR;
471 lastiblock[DOUBLE] = lastiblock[SINGLE] - NINDIR(fs);
472 lastiblock[TRIPLE] = lastiblock[DOUBLE] - NINDIR(fs) * NINDIR(fs);
473 nblocks = btodb(fs->fs_bsize);
475 * Update file and block pointers on disk before we start freeing
476 * blocks. If we crash before free'ing blocks below, the blocks
477 * will be returned to the free list. lastiblock values are also
478 * normalized to -1 for calls to ffs_indirtrunc below.
480 for (level = TRIPLE; level >= SINGLE; level--) {
481 oldblks[UFS_NDADDR + level] = DIP(ip, i_ib[level]);
482 if (lastiblock[level] < 0) {
483 DIP_SET(ip, i_ib[level], 0);
484 lastiblock[level] = -1;
487 for (i = 0; i < UFS_NDADDR; i++) {
488 oldblks[i] = DIP(ip, i_db[i]);
490 DIP_SET(ip, i_db[i], 0);
492 ip->i_flag |= IN_CHANGE | IN_UPDATE;
493 allerror = ffs_update(vp, waitforupdate);
496 * Having written the new inode to disk, save its new configuration
497 * and put back the old block pointers long enough to process them.
498 * Note that we save the new block configuration so we can check it
501 for (i = 0; i < UFS_NDADDR; i++) {
502 newblks[i] = DIP(ip, i_db[i]);
503 DIP_SET(ip, i_db[i], oldblks[i]);
505 for (i = 0; i < UFS_NIADDR; i++) {
506 newblks[UFS_NDADDR + i] = DIP(ip, i_ib[i]);
507 DIP_SET(ip, i_ib[i], oldblks[UFS_NDADDR + i]);
510 DIP_SET(ip, i_size, osize);
512 error = vtruncbuf(vp, length, fs->fs_bsize);
513 if (error && (allerror == 0))
517 * Indirect blocks first.
519 indir_lbn[SINGLE] = -UFS_NDADDR;
520 indir_lbn[DOUBLE] = indir_lbn[SINGLE] - NINDIR(fs) - 1;
521 indir_lbn[TRIPLE] = indir_lbn[DOUBLE] - NINDIR(fs) * NINDIR(fs) - 1;
522 for (level = TRIPLE; level >= SINGLE; level--) {
523 bn = DIP(ip, i_ib[level]);
525 error = ffs_indirtrunc(ip, indir_lbn[level],
526 fsbtodb(fs, bn), lastiblock[level], level, &count);
529 blocksreleased += count;
530 if (lastiblock[level] < 0) {
531 DIP_SET(ip, i_ib[level], 0);
532 ffs_blkfree(ump, fs, ump->um_devvp, bn,
533 fs->fs_bsize, ip->i_number,
534 vp->v_type, NULL, SINGLETON_KEY);
535 blocksreleased += nblocks;
538 if (lastiblock[level] >= 0)
543 * All whole direct blocks or frags.
545 key = ffs_blkrelease_start(ump, ump->um_devvp, ip->i_number);
546 for (i = UFS_NDADDR - 1; i > lastblock; i--) {
549 bn = DIP(ip, i_db[i]);
552 DIP_SET(ip, i_db[i], 0);
553 bsize = blksize(fs, ip, i);
554 ffs_blkfree(ump, fs, ump->um_devvp, bn, bsize, ip->i_number,
555 vp->v_type, NULL, key);
556 blocksreleased += btodb(bsize);
558 ffs_blkrelease_finish(ump, key);
563 * Finally, look for a change in size of the
564 * last direct block; release any frags.
566 bn = DIP(ip, i_db[lastblock]);
568 long oldspace, newspace;
571 * Calculate amount of space we're giving
572 * back as old block size minus new block size.
574 oldspace = blksize(fs, ip, lastblock);
576 DIP_SET(ip, i_size, length);
577 newspace = blksize(fs, ip, lastblock);
579 panic("ffs_truncate: newspace");
580 if (oldspace - newspace > 0) {
582 * Block number of space to be free'd is
583 * the old block # plus the number of frags
584 * required for the storage we're keeping.
586 bn += numfrags(fs, newspace);
587 ffs_blkfree(ump, fs, ump->um_devvp, bn,
588 oldspace - newspace, ip->i_number, vp->v_type,
589 NULL, SINGLETON_KEY);
590 blocksreleased += btodb(oldspace - newspace);
595 for (level = SINGLE; level <= TRIPLE; level++)
596 if (newblks[UFS_NDADDR + level] != DIP(ip, i_ib[level]))
597 panic("ffs_truncate1: level %d newblks %jd != i_ib %jd",
598 level, (intmax_t)newblks[UFS_NDADDR + level],
599 (intmax_t)DIP(ip, i_ib[level]));
600 for (i = 0; i < UFS_NDADDR; i++)
601 if (newblks[i] != DIP(ip, i_db[i]))
602 panic("ffs_truncate2: blkno %d newblks %jd != i_db %jd",
603 i, (intmax_t)newblks[UFS_NDADDR + level],
604 (intmax_t)DIP(ip, i_ib[level]));
607 (fs->fs_magic != FS_UFS2_MAGIC || ip->i_din2->di_extsize == 0) &&
608 (bo->bo_dirty.bv_cnt > 0 || bo->bo_clean.bv_cnt > 0))
609 panic("ffs_truncate3: vp = %p, buffers: dirty = %d, clean = %d",
610 vp, bo->bo_dirty.bv_cnt, bo->bo_clean.bv_cnt);
612 #endif /* INVARIANTS */
614 * Put back the real size.
617 DIP_SET(ip, i_size, length);
618 if (DIP(ip, i_blocks) >= blocksreleased)
619 DIP_SET(ip, i_blocks, DIP(ip, i_blocks) - blocksreleased);
621 DIP_SET(ip, i_blocks, 0);
622 ip->i_flag |= IN_CHANGE;
624 (void) chkdq(ip, -blocksreleased, NOCRED, 0);
630 softdep_journal_freeblocks(ip, cred, length, IO_EXT);
632 softdep_setup_freeblocks(ip, length, IO_EXT);
633 return (ffs_update(vp, waitforupdate));
637 * Release blocks associated with the inode ip and stored in the indirect
638 * block bn. Blocks are free'd in LIFO order up to (but not including)
639 * lastbn. If level is greater than SINGLE, the block is an indirect block
640 * and recursive calls to indirtrunc must be used to cleanse other indirect
644 ffs_indirtrunc(ip, lbn, dbn, lastbn, level, countp)
646 ufs2_daddr_t lbn, lastbn;
649 ufs2_daddr_t *countp;
653 struct ufsmount *ump;
657 int i, nblocks, error = 0, allerror = 0;
658 ufs2_daddr_t nb, nlbn, last;
659 ufs2_daddr_t blkcount, factor, blocksreleased = 0;
660 ufs1_daddr_t *bap1 = NULL;
661 ufs2_daddr_t *bap2 = NULL;
662 #define BAP(ip, i) (I_IS_UFS1(ip) ? bap1[i] : bap2[i])
668 * Calculate index in current block of last
669 * block to be kept. -1 indicates the entire
670 * block so we need not calculate the index.
672 factor = lbn_offset(fs, level);
676 nblocks = btodb(fs->fs_bsize);
678 * Get buffer of block pointers, zero those entries corresponding
679 * to blocks to be free'd, and update on disk copy first. Since
680 * double(triple) indirect before single(double) indirect, calls
681 * to bmap on these blocks will fail. However, we already have
682 * the on disk address, so we have to set the b_blkno field
683 * explicitly instead of letting bread do everything for us.
686 bp = getblk(vp, lbn, (int)fs->fs_bsize, 0, 0, 0);
687 if ((bp->b_flags & B_CACHE) == 0) {
691 racct_add_buf(curproc, bp, 0);
692 PROC_UNLOCK(curproc);
695 curthread->td_ru.ru_inblock++; /* pay for read */
696 bp->b_iocmd = BIO_READ;
697 bp->b_flags &= ~B_INVAL;
698 bp->b_ioflags &= ~BIO_ERROR;
699 if (bp->b_bcount > bp->b_bufsize)
700 panic("ffs_indirtrunc: bad buffer size");
702 vfs_busy_pages(bp, 0);
703 bp->b_iooffset = dbtob(bp->b_blkno);
714 bap1 = (ufs1_daddr_t *)bp->b_data;
716 bap2 = (ufs2_daddr_t *)bp->b_data;
718 copy = malloc(fs->fs_bsize, M_TEMP, M_WAITOK);
719 bcopy((caddr_t)bp->b_data, copy, (u_int)fs->fs_bsize);
720 for (i = last + 1; i < NINDIR(fs); i++)
725 if (DOINGASYNC(vp)) {
733 bap1 = (ufs1_daddr_t *)copy;
735 bap2 = (ufs2_daddr_t *)copy;
739 * Recursively free totally unused blocks.
741 key = ffs_blkrelease_start(ump, ITODEVVP(ip), ip->i_number);
742 for (i = NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last;
743 i--, nlbn += factor) {
747 if (level > SINGLE) {
748 if ((error = ffs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
749 (ufs2_daddr_t)-1, level - 1, &blkcount)) != 0)
751 blocksreleased += blkcount;
753 ffs_blkfree(ump, fs, ITODEVVP(ip), nb, fs->fs_bsize,
754 ip->i_number, vp->v_type, NULL, key);
755 blocksreleased += nblocks;
757 ffs_blkrelease_finish(ump, key);
760 * Recursively free last partial block.
762 if (level > SINGLE && lastbn >= 0) {
763 last = lastbn % factor;
766 error = ffs_indirtrunc(ip, nlbn, fsbtodb(fs, nb),
767 last, level - 1, &blkcount);
770 blocksreleased += blkcount;
776 bp->b_flags |= B_INVAL | B_NOCACHE;
780 *countp = blocksreleased;
785 ffs_rdonly(struct inode *ip)
788 return (ITOFS(ip)->fs_ronly != 0);