- ip->i_db[i] = (daddr_t)0;
-#ifndef QUOTA
- fre(ip, bn, (off_t)blksize(fs, ip, i));
-#else
- { int size;
- fre(ip, bn, size = (off_t)blksize(fs, ip, i));
- cnt += size / DEV_BSIZE;
- }
+ ip->i_db[i] = 0;
+ size = (off_t)blksize(fs, ip, i);
+ free(ip, bn, size);
+#ifdef QUOTA
+ blocksreleased += size / DEV_BSIZE;
+#endif
+ }
+ /*
+ * Finally, look for a change in size of the
+ * last direct block; release any frags.
+ */
+ if (lastblock >= 0 && ip->i_db[lastblock] != 0) {
+ /*
+ * Calculate amount of space we're giving
+ * back as old block size minus new block size.
+ */
+ i = blksize(fs, ip, lastblock);
+ ip->i_size = length;
+ i = i - blksize(fs, ip, lastblock);
+ if (i > 0) {
+ /*
+ * Block number of space to be free'd is
+ * the old block # plus the number of frags
+ * required for the storage we're keeping.
+ */
+ bn = ip->i_db[lastblock] +
+ numfrags(fs, fs->fs_bsize - i);
+ free(ip, bn, i);
+#ifdef QUOTA
+ blocksreleased += i / DEV_BSIZE;