diff options
| author | ngkaho1234 <ngkaho1234@gmail.com> | 2015-11-01 14:09:16 +0000 |
|---|---|---|
| committer | gkostka <kostka.grzegorz@gmail.com> | 2015-11-01 15:25:18 +0100 |
| commit | d9dec8dc9f60f42149ca5d55c0de7c8a2d37fc06 (patch) | |
| tree | 7553574e48abe7b326971e6d3fc3469e00286380 | |
| parent | 4e32e2da452116b1cc8f79902fb7ea704726557f (diff) | |
ext4_generic_open2: add EXT4_FINCOM_FILETYPE check
When following the path, we should check whether
EXT4_FINCOM_FILETYPE is enabled.
| -rw-r--r-- | lwext4/ext4.c | 52 | ||||
| -rw-r--r-- | lwext4/ext4_fs.c | 2 | ||||
| -rw-r--r-- | lwext4/ext4_fs.h | 6 |
3 files changed, 49 insertions, 11 deletions
diff --git a/lwext4/ext4.c b/lwext4/ext4.c index 78b5270..789c12d 100644 --- a/lwext4/ext4.c +++ b/lwext4/ext4.c @@ -583,7 +583,7 @@ static int ext4_generic_open2(ext4_file *f, const char *path, int flags, uint32_t *name_off) { bool is_goal = false; - uint8_t inode_type = EXT4_DIRENTRY_UNKNOWN; + uint32_t inode_mode = EXT4_INODE_MODE_DIRECTORY; uint32_t next_inode; int r; @@ -673,20 +673,37 @@ static int ext4_generic_open2(ext4_file *f, const char *path, int flags, *parent_inode = ref.index; next_inode = ext4_dir_entry_ll_get_inode(result.dentry); - inode_type = - ext4_dir_entry_ll_get_inode_type(&mp->fs.sb, result.dentry); + if (ext4_sb_feature_incom(&mp->fs.sb, EXT4_FINCOM_FILETYPE)) { + int inode_type = + ext4_dir_entry_ll_get_inode_type(&mp->fs.sb, + result.dentry); + inode_mode = ext4_fs_correspond_inode_mode(inode_type); + } else { + struct ext4_inode_ref child_ref; + r = ext4_fs_get_inode_ref(&mp->fs, next_inode, + &child_ref); + if (r != EOK) + break; + + inode_mode = ext4_inode_type(&mp->fs.sb, + child_ref.inode); + + ext4_fs_put_inode_ref(&child_ref); + } r = ext4_dir_destroy_result(&ref, &result); if (r != EOK) break; /*If expected file error*/ - if (inode_type != EXT4_DIRENTRY_DIR && !is_goal) { + if (inode_mode != EXT4_INODE_MODE_DIRECTORY && + !is_goal) { r = ENOENT; break; } if (filetype != EXT4_DIRENTRY_UNKNOWN) { - if ((inode_type != filetype) && is_goal) { + if ((inode_mode != ext4_fs_correspond_inode_mode(filetype)) && + is_goal) { r = ENOENT; break; } @@ -717,7 +734,7 @@ static int ext4_generic_open2(ext4_file *f, const char *path, int flags, if (is_goal) { if ((f->flags & O_TRUNC) && - (inode_type == EXT4_DIRENTRY_REG_FILE)) { + (inode_mode == EXT4_INODE_MODE_FILE)) { r = ext4_fs_truncate_inode(&ref, 0); if (r != EOK) { @@ -765,7 +782,7 @@ static int __ext4_create_hardlink(const char *path, bool rename) { bool is_goal = false; - uint8_t inode_type = EXT4_DIRENTRY_DIR; + uint32_t inode_mode = EXT4_INODE_MODE_DIRECTORY; uint32_t next_inode; int r; @@ -820,14 +837,29 @@ static int __ext4_create_hardlink(const char *path, } next_inode = result.dentry->inode; - inode_type = - ext4_dir_entry_ll_get_inode_type(&mp->fs.sb, result.dentry); + if (ext4_sb_feature_incom(&mp->fs.sb, EXT4_FINCOM_FILETYPE)) { + int inode_type = + ext4_dir_entry_ll_get_inode_type(&mp->fs.sb, + result.dentry); + inode_mode = ext4_fs_correspond_inode_mode(inode_type); + } else { + struct ext4_inode_ref child_ref; + r = ext4_fs_get_inode_ref(&mp->fs, next_inode, + &child_ref); + if (r != EOK) + break; + + inode_mode = ext4_inode_type(&mp->fs.sb, + child_ref.inode); + + ext4_fs_put_inode_ref(&child_ref); + } r = ext4_dir_destroy_result(&ref, &result); if (r != EOK) break; - if (inode_type == EXT4_DIRENTRY_REG_FILE) { + if (inode_mode != EXT4_INODE_MODE_DIRECTORY) { if (is_goal) r = EEXIST; else diff --git a/lwext4/ext4_fs.c b/lwext4/ext4_fs.c index 9db0459..3cbce8f 100644 --- a/lwext4/ext4_fs.c +++ b/lwext4/ext4_fs.c @@ -837,7 +837,7 @@ void ext4_fs_inode_blocks_init(struct ext4_fs *fs, struct ext4_inode_ref *inode_ #endif } -static uint32_t ext4_fs_correspond_inode_mode(int filetype) +uint32_t ext4_fs_correspond_inode_mode(int filetype) { switch (filetype) { case EXT4_DIRENTRY_DIR: diff --git a/lwext4/ext4_fs.h b/lwext4/ext4_fs.h index 4ac8358..c0b7d19 100644 --- a/lwext4/ext4_fs.h +++ b/lwext4/ext4_fs.h @@ -145,6 +145,12 @@ void ext4_fs_inode_blocks_init(struct ext4_fs *fs, struct ext4_inode_ref *inode_ */ int ext4_fs_put_inode_ref(struct ext4_inode_ref *ref); +/**@brief Convert filetype to inode mode. + * @param filetype + * @return inode mode + */ +uint32_t ext4_fs_correspond_inode_mode(int filetype); + /**@brief Allocate new i-node in the filesystem. * @param fs Filesystem to allocated i-node on * @param inode_ref Output pointer to return reference to allocated i-node |
