From: Darrick J. Wong Date: Wed, 3 Dec 2014 03:55:04 +0000 (-0500) Subject: libext2fs: refactor extent head creation X-Git-Tag: v1.43-WIP-2015-05-18~128 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3548bb64b5690608720120b56beeafaecc68d68b;p=thirdparty%2Fe2fsprogs.git libext2fs: refactor extent head creation Don't open-code the creation of the extent tree header, since ext2fs_extent_open2() knows how to take care of this. Signed-off-by: Darrick J. Wong Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/inline_data.c b/lib/ext2fs/inline_data.c index 88e08e765..6260c5f35 100644 --- a/lib/ext2fs/inline_data.c +++ b/lib/ext2fs/inline_data.c @@ -412,19 +412,16 @@ ext2fs_inline_data_file_expand(ext2_filsys fs, ext2_ino_t ino, errcode_t retval; /* Update inode */ + memset(inode->i_block, 0, sizeof(inode->i_block)); if (EXT2_HAS_INCOMPAT_FEATURE(fs->super, 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 = ext2fs_cpu_to_le16(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; + ext2_extent_handle_t handle; + + inode->i_flags &= ~EXT4_EXTENTS_FL; + retval = ext2fs_extent_open2(fs, ino, inode, &handle); + if (retval) + return retval; + ext2fs_extent_free(handle); } inode->i_flags &= ~EXT4_INLINE_DATA_FL; inode->i_size = 0; diff --git a/misc/create_inode.c b/misc/create_inode.c index cf7c0970a..a024d1cc6 100644 --- a/misc/create_inode.c +++ b/misc/create_inode.c @@ -518,17 +518,13 @@ errcode_t do_write_internal(ext2_filsys fs, ext2_ino_t cwd, const char *src, inode.i_flags |= EXT4_INLINE_DATA_FL; } else if (fs->super->s_feature_incompat & 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 = ext2fs_cpu_to_le16(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; + ext2_extent_handle_t handle; + + inode.i_flags &= ~EXT4_EXTENTS_FL; + retval = ext2fs_extent_open2(fs, newfile, &inode, &handle); + if (retval) + return retval; + ext2fs_extent_free(handle); } retval = ext2fs_write_new_inode(fs, newfile, &inode);