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

login
register
mail settings
Submitter Zheng Liu
Date July 31, 2012, 11:48 a.m.
Message ID <1343735309-30579-29-git-send-email-wenqing.lz@taobao.com>
Download mbox | patch
Permalink /patch/174246/
State Superseded
Headers show

Comments

Zheng Liu - July 31, 2012, 11:48 a.m.
From: Zheng Liu <wenqing.lz@taobao.com>

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@taobao.com>
---
 lib/ext2fs/punch.c |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

Patch

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;