diff options
| author | ngkaho1234 <ngkaho1234@gmail.com> | 2016-01-16 13:19:31 +0000 |
|---|---|---|
| committer | ngkaho1234 <ngkaho1234@gmail.com> | 2016-01-16 13:39:02 +0000 |
| commit | 7291e1280f7502e917eb1d1b975f6e055f205e3f (patch) | |
| tree | 45bb5cf7f65b1b472443cbb9da21bd9e1d6fe181 | |
| parent | 723951999f8d6037ef2576064982176338350915 (diff) | |
ext4_dir_idx: ext4_dir_dx_init now only append file when necessary.
| -rw-r--r-- | lwext4/ext4_dir_idx.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/lwext4/ext4_dir_idx.c b/lwext4/ext4_dir_idx.c index e4f5485..3a156b6 100644 --- a/lwext4/ext4_dir_idx.c +++ b/lwext4/ext4_dir_idx.c @@ -344,15 +344,25 @@ int ext4_dir_dx_init(struct ext4_inode_ref *dir, struct ext4_inode_ref *parent) { /* Load block 0, where will be index root located */ ext4_fsblk_t fblock; - uint32_t iblock; + uint32_t iblock = 0; + bool need_append = + (ext4_inode_get_size(&dir->fs->sb, dir->inode) + < EXT4_DIR_DX_INIT_BCNT) + ? true : false; struct ext4_sblock *sb = &dir->fs->sb; uint32_t block_size = ext4_sb_get_block_size(&dir->fs->sb); + struct ext4_block block; + + int rc; + + if (!need_append) + rc = ext4_fs_init_inode_dblk_idx(dir, iblock, &fblock); + else + rc = ext4_fs_append_inode_dblk(dir, &fblock, &iblock); - int rc = ext4_fs_append_inode_dblk(dir, &fblock, &iblock); if (rc != EOK) return rc; - struct ext4_block block; rc = ext4_trans_block_get_noread(dir->fs->bdev, &block, fblock); if (rc != EOK) return rc; @@ -396,7 +406,12 @@ int ext4_dir_dx_init(struct ext4_inode_ref *dir, struct ext4_inode_ref *parent) ext4_dir_dx_climit_set_limit(climit, root_limit); /* Append new block, where will be new entries inserted in the future */ - rc = ext4_fs_append_inode_dblk(dir, &fblock, &iblock); + iblock++; + if (!need_append) + rc = ext4_fs_init_inode_dblk_idx(dir, iblock, &fblock); + else + rc = ext4_fs_append_inode_dblk(dir, &fblock, &iblock); + if (rc != EOK) { ext4_block_set(dir->fs->bdev, &block); return rc; |
