Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / lib / ext2fs / punch.c
index 11c7668..4471f46 100644 (file)
@@ -60,7 +60,7 @@ static errcode_t ind_punch(ext2_filsys fs, struct ext2_inode *inode,
 #endif
        incr = 1 << ((EXT2_BLOCK_SIZE_BITS(fs->super)-2)*level);
        for (i=0, offset=0; i < max; i++, p++, offset += incr) {
-               if (offset > count)
+               if (offset >= start + count)
                        break;
                if (*p == 0 || (offset+incr) <= start)
                        continue;
@@ -281,7 +281,7 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino,
                dbg_printf("Free start %llu, free count = %u\n",
                       free_start, free_count);
                while (free_count-- > 0) {
-                       ext2fs_block_alloc_stats(fs, free_start++, -1);
+                       ext2fs_block_alloc_stats2(fs, free_start++, -1);
                        freed++;
                }
        next_extent:
@@ -315,9 +315,6 @@ extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino,
        if (start > end)
                return EINVAL;
 
-       if (start == end)
-               return 0;
-
        /* Read inode structure if necessary */
        if (!inode) {
                retval = ext2fs_read_inode(fs, ino, &inode_buf);
@@ -332,7 +329,7 @@ extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino,
 
                if (start > ~0U)
                        return 0;
-               count = ((end - start) < ~0U) ? (end - start) : ~0U;
+               count = ((end - start + 1) < ~0U) ? (end - start + 1) : ~0U;
                retval = ext2fs_punch_ind(fs, inode, block_buf, 
                                          (blk_t) start, count);
        }