Do not verify checksum upon seeking in the directory.
[lwext4.git] / lwext4 / ext4.c
index 8283657e8545c0a255476b800c2adda42a83ec53..ac379b95a0199052c5e216cf4d9b006f7731f039 100644 (file)
@@ -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;
@@ -1843,9 +1844,8 @@ static int ext4_fsymlink_set(ext4_file *f, const void *buf, uint32_t size)
 
        /*If the size of symlink is smaller than 60 bytes*/
        if (size < sizeof(ref.inode->blocks)) {
-               char *content = (char *)ref.inode->blocks;
-               memset(content, 0, sizeof(ref.inode->blocks));
-               memcpy(content, buf, size);
+               memset(ref.inode->blocks, 0, sizeof(ref.inode->blocks));
+               memcpy(ref.inode->blocks, buf, size);
                ext4_inode_clear_flag(ref.inode, EXT4_INODE_FLAG_EXTENTS);
        } else {
                ext4_fs_inode_blocks_init(&f->mp->fs, &ref);
@@ -1923,8 +1923,6 @@ int ext4_readlink(const char *path, char *buf, size_t bufsize, size_t *rcnt)
        if (!buf)
                return EINVAL;
 
-       memset(buf, 0, sizeof(bufsize));
-
        filetype = EXT4_DIRENTRY_SYMLINK;
 
        EXT4_MP_LOCK(mp);