ref: 2365ef6f64615805b2b35652aa77cb54377fc73f
parent: 4c6115ffe7fddaab8fa1c12e7cce7c7902ceb36f
author: ngkaho1234 <[email protected]>
date: Tue Oct 27 05:02:12 EDT 2015
Refactor the workflow of ext4_link to prepare for METADATA_CSUM.
--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -198,22 +198,7 @@
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 */
if (ext4_sb_has_feature_compatible(
@@ -225,8 +210,25 @@
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;