[PATCH 28/36 v4] debugfs: make punch/truncate cmd support inline data

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Zheng Liu <wenqing.lz@xxxxxxxxxx>

If inode includes inline_data flag, start and end arguments will be ignored.
Meanwhile we truncate inline data.

Signed-off-by: Zheng Liu <wenqing.lz@xxxxxxxxxx>
---
 lib/ext2fs/punch.c |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/lib/ext2fs/punch.c b/lib/ext2fs/punch.c
index b53653a..28967a4 100644
--- a/lib/ext2fs/punch.c
+++ b/lib/ext2fs/punch.c
@@ -281,6 +281,34 @@ errout:
 	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)
+{
+	struct ext2_inode_large large_inode;
+	struct inline_data idata;
+	errcode_t retval;
+	int inline_size;
+
+	retval = ext2fs_read_inode_full(fs, ino, (void *)&large_inode,
+					EXT2_INODE_SIZE(fs->super));
+	if (retval)
+		return retval;
+
+	ext2fs_iget_extra_inode(fs, &large_inode, &idata);
+
+	inline_size = idata.inline_size;
+	retval = inline_data_destory_data(fs, ino, &large_inode, &idata);
+	if (retval)
+		return retval;
+
+	large_inode.i_size = 0;
+	ext2fs_write_inode_full(fs, ino, (void *)&large_inode,
+				EXT2_INODE_SIZE(fs->super));
+
+	return retval;
+}
 	
 /*
  * Deallocate all logical blocks starting at start to end, inclusive.
@@ -307,7 +335,10 @@ extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino,
 			return retval;
 		inode = &inode_buf;
 	}
-	if (inode->i_flags & EXT4_EXTENTS_FL)
+	if (inode->i_flags & EXT4_INLINE_DATA_FL) {
+		retval = ext2fs_punch_inline_data(fs, ino, inode, start, end);
+		return retval;
+	} else if (inode->i_flags & EXT4_EXTENTS_FL)
 		retval = ext2fs_punch_extent(fs, ino, inode, start, end);
 	else {
 		blk_t	count;
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux