From 2365ef6f64615805b2b35652aa77cb54377fc73f Mon Sep 17 00:00:00 2001 From: ngkaho1234 Date: Tue, 27 Oct 2015 09:02:12 +0000 Subject: [PATCH] Refactor the workflow of ext4_link to prepare for METADATA_CSUM. --- lwext4/ext4.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/lwext4/ext4.c b/lwext4/ext4.c index 78b9203..9ca9e5b 100644 --- a/lwext4/ext4.c +++ b/lwext4/ext4.c @@ -198,21 +198,6 @@ static int ext4_link(struct ext4_mountpoint *mp, struct ext4_inode_ref *parent, if (ext4_inode_is_type(&mp->fs.sb, child->inode, EXT4_INODE_MODE_DIRECTORY) && !rename) { - rc = ext4_dir_add_entry(child, ".", strlen("."), child); - if (rc != EOK) { - ext4_dir_remove_entry(parent, name, strlen(name)); - return rc; - } - - rc = ext4_dir_add_entry(child, "..", strlen(".."), parent); - if (rc != EOK) { - ext4_dir_remove_entry(parent, name, strlen(name)); - ext4_dir_remove_entry(child, ".", strlen(".")); - return rc; - } - - /*New empty directory. Two links (. and ..) */ - ext4_inode_set_links_count(child->inode, 2); #if CONFIG_DIR_INDEX_ENABLE /* Initialize directory index if supported */ @@ -225,8 +210,25 @@ static int ext4_link(struct ext4_mountpoint *mp, struct ext4_inode_ref *parent, ext4_inode_set_flag(child->inode, EXT4_INODE_FLAG_INDEX); child->dirty = true; - } + } else #endif + { + rc = ext4_dir_add_entry(child, ".", strlen("."), child); + if (rc != EOK) { + ext4_dir_remove_entry(parent, name, strlen(name)); + return rc; + } + + rc = ext4_dir_add_entry(child, "..", strlen(".."), parent); + if (rc != EOK) { + ext4_dir_remove_entry(parent, name, strlen(name)); + ext4_dir_remove_entry(child, ".", strlen(".")); + return rc; + } + } + + /*New empty directory. Two links (. and ..) */ + ext4_inode_set_links_count(child->inode, 2); ext4_fs_inode_links_count_inc(parent); child->dirty = true;