-done:
-/* BEGIN PARANOIA */
- for (level = SINGLE; level <= TRIPLE; level++)
- if (ip->i_ib[level] != oip->i_ib[level])
- panic("itrunc1");
- for (i = 0; i < NDADDR; i++)
- if (ip->i_db[i] != oip->i_db[i])
- panic("itrunc2");
-/* END PARANOIA */
- oip->i_blocks -= blocksreleased;
- if (oip->i_blocks < 0) /* sanity */
- oip->i_blocks = 0;
- oip->i_flag |= ICHG;
-#ifdef QUOTA
- (void) chkdq(oip, -blocksreleased, 0);
-#endif
-}
-
-/*
- * Release blocks associated with the inode ip and
- * stored in the indirect block bn. Blocks are free'd
- * in LIFO order up to (but not including) lastbn. If
- * level is greater than SINGLE, the block is an indirect
- * block and recursive calls to indirtrunc must be used to
- * cleanse other indirect blocks.
- *
- * NB: triple indirect blocks are untested.
- */
-long
-indirtrunc(ip, bn, lastbn, level)
- register struct inode *ip;
- daddr_t bn, lastbn;
- int level;
-{
- register int i;
- struct buf *bp;
- register struct fs *fs = ip->i_fs;
- register daddr_t *bap;
- daddr_t *copy, nb, last;
- long factor;
- int blocksreleased = 0, nblocks;
-
- /*
- * Calculate index in current block of last
- * block to be kept. -1 indicates the entire
- * block so we need not calculate the index.
- */
- factor = 1;
- for (i = SINGLE; i < level; i++)
- factor *= NINDIR(fs);
- last = lastbn;
- if (lastbn > 0)
- last /= factor;
- nblocks = btodb(fs->fs_bsize);
- /*
- * Get buffer of block pointers, zero those
- * entries corresponding to blocks to be free'd,
- * and update on disk copy first.
- */
-#ifdef SECSIZE
- bp = bread(ip->i_dev, fsbtodb(fs, bn), (int)fs->fs_bsize,
- fs->fs_dbsize);
-#else SECSIZE
- bp = bread(ip->i_dev, fsbtodb(fs, bn), (int)fs->fs_bsize);
-#endif SECSIZE
- if (bp->b_flags&B_ERROR) {
- brelse(bp);
- return (0);
- }
- bap = bp->b_un.b_daddr;
- MALLOC(copy, daddr_t *, fs->fs_bsize, M_TEMP, M_WAITOK);
- bcopy((caddr_t)bap, (caddr_t)copy, (u_int)fs->fs_bsize);
- bzero((caddr_t)&bap[last + 1],
- (u_int)(NINDIR(fs) - (last + 1)) * sizeof (daddr_t));
- bwrite(bp);
- bap = copy;
-
- /*
- * Recursively free totally unused blocks.
- */
- for (i = NINDIR(fs) - 1; i > last; i--) {
- nb = bap[i];
- if (nb == 0)
- continue;
- if (level > SINGLE)
- blocksreleased +=
- indirtrunc(ip, nb, (daddr_t)-1, level - 1);
- blkfree(ip, nb, (off_t)fs->fs_bsize);
- blocksreleased += nblocks;
- }
-
- /*
- * Recursively free last partial block.
- */
- if (level > SINGLE && lastbn >= 0) {
- last = lastbn % factor;
- nb = bap[i];
- if (nb != 0)
- blocksreleased += indirtrunc(ip, nb, last, level - 1);
- }
- FREE(copy, M_TEMP);
- return (blocksreleased);
-}
-
-/*
- * Remove any inodes in the inode cache belonging to dev.
- *
- * There should not be any active ones, return error if any are found
- * (nb: this is a user error, not a system err).
- */
-#ifdef QUOTA
-iflush(dev, iq)
- dev_t dev;
- struct inode *iq;
-#else
-iflush(dev)
- dev_t dev;
-#endif
-{
- register struct inode *ip;
-
- for (ip = inode; ip < inodeNINODE; ip++) {
-#ifdef QUOTA
- if (ip != iq && ip->i_dev == dev)
-#else
- if (ip->i_dev == dev)