#include "ext2_fs.h"
#include "ext2fs.h"
+#include "ext2fsP.h"
#undef PUNCH_DEBUG
}
/* Free whole clusters from the middle of the range. */
- while (free_count > 0 && free_count >= EXT2FS_CLUSTER_RATIO(fs)) {
+ while (free_count > 0 && free_count >= (unsigned) EXT2FS_CLUSTER_RATIO(fs)) {
ext2fs_block_alloc_stats2(fs, free_start, -1);
freed_now++;
cluster_freed = EXT2FS_CLUSTER_RATIO(fs);
goto errout;
retval = 0;
- /* Jump forward to the next extent. */
- ext2fs_extent_goto(handle, next_lblk);
+ /*
+ * Jump forward to the next extent. If there are
+ * errors, the ext2fs_extent_get down below will
+ * capture them for us.
+ */
+ (void)ext2fs_extent_goto(handle, next_lblk);
op = EXT2_EXTENT_CURRENT;
}
if (retval)
ext2fs_extent_free(handle);
return retval;
}
+
+static errcode_t ext2fs_punch_inline_data(ext2_filsys fs, ext2_ino_t ino,
+ struct ext2_inode *inode,
+ blk64_t start,
+ blk64_t end EXT2FS_ATTR((unused)))
+{
+ errcode_t retval;
+
+ /*
+ * In libext2fs ext2fs_punch is based on block unit. So that
+ * means that if start > 0 we don't need to do nothing. Due
+ * to this we will remove all inline data in ext2fs_punch()
+ * now.
+ */
+ if (start > 0)
+ return 0;
+
+ memset((char *)inode->i_block, 0, EXT4_MIN_INLINE_DATA_SIZE);
+ inode->i_size = 0;
+ retval = ext2fs_write_inode(fs, ino, inode);
+ if (retval)
+ return retval;
+
+ return ext2fs_inline_data_ea_remove(fs, ino);
+}
/*
* Deallocate all logical _blocks_ starting at start to end, inclusive.
return retval;
inode = &inode_buf;
}
- if (inode->i_flags & EXT4_EXTENTS_FL)
+ if (inode->i_flags & EXT4_INLINE_DATA_FL)
+ return ext2fs_punch_inline_data(fs, ino, inode, start, end);
+ else if (inode->i_flags & EXT4_EXTENTS_FL)
retval = ext2fs_punch_extent(fs, ino, inode, start, end);
else
retval = ext2fs_punch_ind(fs, inode, block_buf, start, end);