X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lwext4%2Fext4.c;h=ac379b95a0199052c5e216cf4d9b006f7731f039;hb=e5f33a98b0385a0281138abb60645db92f309e8a;hp=78b920379639e62a2cc27aab850a266c689cbeb2;hpb=31219e3b9ed046551de6931c0705a04c4a1c5282;p=lwext4.git diff --git a/lwext4/ext4.c b/lwext4/ext4.c index 78b9203..ac379b9 100644 --- a/lwext4/ext4.c +++ b/lwext4/ext4.c @@ -198,35 +198,36 @@ 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 */ - if (ext4_sb_has_feature_compatible( - &mp->fs.sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) { - rc = ext4_dir_dx_init(child); + if (ext4_sb_feature_com(&mp->fs.sb, EXT4_FCOM_DIR_INDEX)) { + rc = ext4_dir_dx_init(child, parent); if (rc != EOK) return rc; 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;