diff options
author | Eric Sandeen <sandeen@redhat.com> | 2013-07-28 22:31:44 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2013-07-28 22:32:15 -0400 |
commit | a17e9f304bcce0d30578f91bba7456d84a113423 (patch) | |
tree | f9a7fb8c87113ff2e784918f4b2e34e9d3e5f8ea | |
parent | c8ec2bad18fdaa842f786f3b37c9320a3411aea3 (diff) | |
download | e2fsprogs-a17e9f304bcce0d30578f91bba7456d84a113423.tar.gz e2fsprogs-a17e9f304bcce0d30578f91bba7456d84a113423.tar.xz e2fsprogs-a17e9f304bcce0d30578f91bba7456d84a113423.zip |
debugfs: properly set up extent header in do_write
do_write doesn't fully set up the first extent header on a new
inode, so if we write a 0-length file, and don't write any data
to the new file, we end up creating something that looks corrupt
to kernelspace:
EXT4-fs error (device loop0): ext4_ext_check_inode:464: inode #12: comm ls: bad header/extent: invalid magic - magic 0, entries 0, max 0(0), depth 0(0)
Do something similar to ext4_ext_tree_init() here, and
fill out the first extent header upon creation to avoid this.
Reported-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Tested-by: Robert Yang <liezhi.yang@windriver.com>
-rw-r--r-- | debugfs/debugfs.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index 2a1525a8..cf559df1 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -1665,8 +1665,19 @@ void do_write(int argc, char *argv[]) inode.i_links_count = 1; inode.i_size = statbuf.st_size; if (current_fs->super->s_feature_incompat & - EXT3_FEATURE_INCOMPAT_EXTENTS) + EXT3_FEATURE_INCOMPAT_EXTENTS) { + int i; + struct ext3_extent_header *eh; + + eh = (struct ext3_extent_header *) &inode.i_block[0]; + eh->eh_depth = 0; + eh->eh_entries = 0; + eh->eh_magic = EXT3_EXT_MAGIC; + i = (sizeof(inode.i_block) - sizeof(*eh)) / + sizeof(struct ext3_extent); + eh->eh_max = ext2fs_cpu_to_le16(i); inode.i_flags |= EXT4_EXTENTS_FL; + } if (debugfs_write_new_inode(newfile, &inode, argv[0])) { close(fd); return; |