]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
debugfs: handle inline data feature in punch command
authorZheng Liu <wenqing.lz@taobao.com>
Mon, 3 Mar 2014 05:34:40 +0000 (00:34 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 4 Mar 2014 13:46:14 +0000 (08:46 -0500)
Now punch command only can remove all inline data because now
punch command is based on block unit and the size of inline data is
never beyond a block size.

Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/ext2fsP.h
lib/ext2fs/inline_data.c
lib/ext2fs/punch.c

index 436a5d0c269ae4125d7e490ccfb91a63fc073fc9..8b413071f1d407094aa0c7ef3670632be7816e97 100644 (file)
@@ -91,6 +91,7 @@ extern int ext2fs_process_dir_block(ext2_filsys       fs,
 extern errcode_t ext2fs_inline_data_init(ext2_filsys fs, ext2_ino_t ino);
 extern errcode_t ext2fs_inline_data_size(ext2_filsys fs, ext2_ino_t ino,
                                         size_t *size);
+extern errcode_t ext2fs_inline_data_ea_remove(ext2_filsys fs, ext2_ino_t ino);
 extern errcode_t ext2fs_inline_data_expand(ext2_filsys fs, ext2_ino_t ino);
 extern int ext2fs_inline_data_dir_iterate(ext2_filsys fs,
                                          ext2_ino_t ino,
index 913fe1d5292d443e65b22d61814020940beaf974..424c069bdf706078434fd5737440a650a6b3207a 100644 (file)
@@ -242,7 +242,7 @@ out:
        return ret;
 }
 
-static errcode_t ext2fs_inline_data_ea_remove(ext2_filsys fs, ext2_ino_t ino)
+errcode_t ext2fs_inline_data_ea_remove(ext2_filsys fs, ext2_ino_t ino)
 {
        struct ext2_xattr_handle *handle;
        errcode_t retval;
index a3d020ece6a36f51c4e9313aaca2fe3e40c15aa7..95e19d9113936783548d8d0b9e8ec5533fa4a62a 100644 (file)
@@ -423,6 +423,30 @@ errout:
        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)
+{
+       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.
  * If end is ~0, then this is effectively truncate.
@@ -445,7 +469,9 @@ 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)
+               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 {
                blk_t   count;