ext4: use common file type conversion
Subsystems (2)
RFC PATCH v5 7/9 ext4: use common file type conversion
Deduplicate the ext4 file type conversion implementation and define EXT4_FT_* to match shared FT_* - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in fs_types.h and implemented in fs_types.c
--- fs/ext4/ext4.h | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-)
fs/ext4/ext4.h +12 -25
@@ -1925,16 +1925,16 @@ struct ext4_dir_entry_tail {* Ext4 directory file types. Only the low 3 bits are used. The * other bits are reserved for now. */ -#define EXT4_FT_UNKNOWN 0 -#define EXT4_FT_REG_FILE 1 -#define EXT4_FT_DIR 2 -#define EXT4_FT_CHRDEV 3 -#define EXT4_FT_BLKDEV 4 -#define EXT4_FT_FIFO 5 -#define EXT4_FT_SOCK 6 -#define EXT4_FT_SYMLINK 7 +#define EXT4_FT_UNKNOWN FT_UNKNOWN +#define EXT4_FT_REG_FILE FT_REG_FILE +#define EXT4_FT_DIR FT_DIR +#define EXT4_FT_CHRDEV FT_CHRDEV +#define EXT4_FT_BLKDEV FT_BLKDEV +#define EXT4_FT_FIFO FT_FIFO +#define EXT4_FT_SOCK FT_SOCK +#define EXT4_FT_SYMLINK FT_SYMLINK -#define EXT4_FT_MAX 8 +#define EXT4_FT_MAX FT_MAX#define EXT4_FT_DIR_CSUM 0xDE
@@ -2357,16 +2357,13 @@ static inline void ext4_update_dx_flag(struct inode *inode)if (!ext4_has_feature_dir_index (inode->i_sb))ext4_clear_inode_flag (inode,EXT4_INODE_INDEX ); } -static const unsigned char ext4_filetype_table[] = { -DT_UNKNOWN ,DT_REG ,DT_DIR ,DT_CHR ,DT_BLK ,DT_FIFO ,DT_SOCK ,DT_LNK -};static inline unsigned char get_dtype (struct super_block *sb,int filetype) { -if (!ext4_has_feature_filetype (sb) || filetype >=EXT4_FT_MAX ) +if (!ext4_has_feature_filetype (sb))return DT_UNKNOWN ; -return ext4_filetype_table[filetype]; +return fs_ftype_to_dtype (filetype); }extern int ext4_check_all_de (struct inode *dir,struct buffer_head *bh,void *buf,int buf_size);
@@ -3065,22 +3062,12 @@ extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t,extern int ext4_handle_dirty_dirent_node (handle_t *handle,struct inode *inode,struct buffer_head *bh); -#define S_SHIFT 12 -static const unsigned char ext4_type_by_mode[(S_IFMT >>S_SHIFT ) +1 ] = { - [S_IFREG >>S_SHIFT ] =EXT4_FT_REG_FILE , - [S_IFDIR >>S_SHIFT ] =EXT4_FT_DIR , - [S_IFCHR >>S_SHIFT ] =EXT4_FT_CHRDEV , - [S_IFBLK >>S_SHIFT ] =EXT4_FT_BLKDEV , - [S_IFIFO >>S_SHIFT ] =EXT4_FT_FIFO , - [S_IFSOCK >>S_SHIFT ] =EXT4_FT_SOCK , - [S_IFLNK >>S_SHIFT ] =EXT4_FT_SYMLINK , -};static inline void ext4_set_de_type (struct super_block *sb,struct ext4_dir_entry_2 *de,umode_t mode) {if (ext4_has_feature_filetype (sb)) - de->file_type = ext4_type_by_mode[(mode &S_IFMT )>>S_SHIFT ]; + de->file_type =fs_umode_to_ftype (mode); }/* readpages.c */
Signature · 1 line
2.20.1
Quoted 8 lines · Phillip Potter
Deduplicate the ext4 file type conversion implementation and define EXT4_FT_* to match shared FT_* - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in
fs_types.hand implemented infs_types.cSigned-off-by Amir Goldstein <[email protected]>Signed-off-by Phillip Potter <[email protected]>
Looks good to me. You can add:
Honza
Quoted 80 lines
--- fs/ext4/ext4.h | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-)fs/ext4/ext4.h +12
-25@@ -1925,16 +1925,16 @@ struct ext4_dir_entry_tail {* Ext4 directory file types. Only the low 3 bits are used. The * other bits are reserved for now. */ -#define EXT4_FT_UNKNOWN 0 -#define EXT4_FT_REG_FILE 1 -#define EXT4_FT_DIR 2 -#define EXT4_FT_CHRDEV 3 -#define EXT4_FT_BLKDEV 4 -#define EXT4_FT_FIFO 5 -#define EXT4_FT_SOCK 6 -#define EXT4_FT_SYMLINK 7 +#define EXT4_FT_UNKNOWN FT_UNKNOWN +#define EXT4_FT_REG_FILE FT_REG_FILE +#define EXT4_FT_DIR FT_DIR +#define EXT4_FT_CHRDEV FT_CHRDEV +#define EXT4_FT_BLKDEV FT_BLKDEV +#define EXT4_FT_FIFO FT_FIFO +#define EXT4_FT_SOCK FT_SOCK +#define EXT4_FT_SYMLINK FT_SYMLINK -#define EXT4_FT_MAX 8 +#define EXT4_FT_MAX FT_MAX#define EXT4_FT_DIR_CSUM 0xDE@@ -2357,16 +2357,13 @@ static inline void ext4_update_dx_flag(struct inode *inode)if (!ext4_has_feature_dir_index (inode->i_sb))ext4_clear_inode_flag (inode,EXT4_INODE_INDEX ); } -static const unsigned char ext4_filetype_table[] = { -DT_UNKNOWN ,DT_REG ,DT_DIR ,DT_CHR ,DT_BLK ,DT_FIFO ,DT_SOCK ,DT_LNK -};static inline unsigned char get_dtype (struct super_block *sb,int filetype) { -if (!ext4_has_feature_filetype (sb) || filetype >=EXT4_FT_MAX ) +if (!ext4_has_feature_filetype (sb))return DT_UNKNOWN ; -return ext4_filetype_table[filetype]; +return fs_ftype_to_dtype (filetype); }extern int ext4_check_all_de (struct inode *dir,struct buffer_head *bh,void *buf,int buf_size);@@ -3065,22 +3062,12 @@ extern void initialize_dirent_tail(struct ext4_dir_entry_tail *t,extern int ext4_handle_dirty_dirent_node (handle_t *handle,struct inode *inode,struct buffer_head *bh); -#define S_SHIFT 12 -static const unsigned char ext4_type_by_mode[(S_IFMT >>S_SHIFT ) +1 ] = { - [S_IFREG >>S_SHIFT ] =EXT4_FT_REG_FILE , - [S_IFDIR >>S_SHIFT ] =EXT4_FT_DIR , - [S_IFCHR >>S_SHIFT ] =EXT4_FT_CHRDEV , - [S_IFBLK >>S_SHIFT ] =EXT4_FT_BLKDEV , - [S_IFIFO >>S_SHIFT ] =EXT4_FT_FIFO , - [S_IFSOCK >>S_SHIFT ] =EXT4_FT_SOCK , - [S_IFLNK >>S_SHIFT ] =EXT4_FT_SYMLINK , -};static inline void ext4_set_de_type (struct super_block *sb,struct ext4_dir_entry_2 *de,umode_t mode) {if (ext4_has_feature_filetype (sb)) - de->file_type = ext4_type_by_mode[(mode &S_IFMT )>>S_SHIFT ]; + de->file_type =fs_umode_to_ftype (mode); }/* readpages.c */ Signature · 1 line
2.20.1
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 7 lines · Jan Kara
Quoted 6 lines · Phillip Potter
Deduplicate the ext4 file type conversion implementation and define EXT4_FT_* to match shared FT_* - file systems that use the same file types as defined by POSIX do not need to define their own versions and can use the common helper functions decared in
fs_types.hand implemented infs_types.c
Quoted 9 lines
Quoted 2 lines
Signed-off-by Amir Goldstein <[email protected]>Signed-off-by Phillip Potter <[email protected]>Looks good to me. You can add:
Reviewed-by Jan Kara <[email protected]>Honza
Dear Jan,
Thank you for this, much appreciated.
Regards,
Phil