Skip to content

Commit

Permalink
libext2fs: refactor extent head creation
Browse files Browse the repository at this point in the history
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 <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  • Loading branch information
djwong authored and tytso committed Dec 3, 2014
1 parent 44765c4 commit 3548bb6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
19 changes: 8 additions & 11 deletions lib/ext2fs/inline_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 7 additions & 11 deletions misc/create_inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3548bb6

Please sign in to comment.