fsck: prevent working on devices with unsupported features
PATCH 1/1 fsck: prevent working on devices with unsupported features
fsck should never work on devices with unsupported features.
This is a real practical issue as fsck'ing a compressed image with an older version of fsck destroys the entire image.
Non-rolling nature of popular distros such as Ubuntu is making the situation worse.
Implement a long overdue safeguard to cope better with different versions of f2fs-tools.
Signed-off-by Park Ju Hyung <[email protected]>
--- fsck/mount.c | 9 +++++++++ include/f2fs_fs.h | 18 +++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-)
fsck/mount.c +9 -0
@@ -936,6 +936,7 @@ int sanity_check_raw_super(struct f2fs_super_block *sb, enum SB_ADDR sb_addr)int validate_super_block (struct f2fs_sb_info *sbi,enum SB_ADDR sb_addr) {char buf[F2FS_BLKSIZE ]; +__le32 unsupported; sbi->raw_super =malloc (sizeof (struct f2fs_super_block ));if (!sbi->raw_super)
@@ -975,6 +976,14 @@ int validate_super_block(struct f2fs_sb_info *sbi, enum SB_ADDR sb_addr) c.fix_on =1 ; }print_sb_state (sbi->raw_super); + +/* check supported features */ + unsupported =f2fs_get_unsupported_features (sbi->raw_super); +if (unsupported) { +MSG (0 ,"Error: Unsupported features: 0x%x\n" , unsupported); +MSG (0 ,"Error: Please update your f2fs-tools\n" ); +return -EOPNOTSUPP ; + }return 0 ; }
include/f2fs_fs.h +17 -1
@@ -683,6 +683,9 @@ enum {#define MAX_ACTIVE_NODE_LOGS 8#define MAX_ACTIVE_DATA_LOGS 8 +/* +* All features listed here should be appended to F2FS_SUPPORTED_FEATURES +*/ #define F2FS_FEATURE_ENCRYPT 0x0001#define F2FS_FEATURE_BLKZONED 0x0002#define F2FS_FEATURE_ATOMIC_WRITE 0x0004
@@ -696,7 +699,15 @@ enum {#define F2FS_FEATURE_VERITY 0x0400/* reserved */ #define F2FS_FEATURE_SB_CHKSUM 0x0800#define F2FS_FEATURE_CASEFOLD 0x1000 -#define F2FS_FEATURE_COMPRESSION 0x2000 +#define F2FS_FEATURE_COMPRESSION 0x2000 + +/* Currently supported features by this version of f2fs-tools */ +#define F2FS_SUPPORTED_FEATURES \ + (F2FS_FEATURE_ENCRYPT | F2FS_FEATURE_BLKZONED | F2FS_FEATURE_ATOMIC_WRITE | \ + F2FS_FEATURE_EXTRA_ATTR | F2FS_FEATURE_PRJQUOTA | F2FS_FEATURE_INODE_CHKSUM | \ + F2FS_FEATURE_FLEXIBLE_INLINE_XATTR | F2FS_FEATURE_QUOTA_INO | F2FS_FEATURE_INODE_CRTIME | \ + F2FS_FEATURE_LOST_FOUND | F2FS_FEATURE_VERITY | F2FS_FEATURE_SB_CHKSUM | \ + F2FS_FEATURE_CASEFOLD | F2FS_FEATURE_COMPRESSION)#define MAX_VOLUME_NAME 512
@@ -1600,6 +1611,11 @@ static inline int parse_feature(struct feature *table, const char *features)return 0 ; } +static inline __le32 f2fs_get_unsupported_features (struct f2fs_super_block *sb) +{ +return sb->feature & ~F2FS_SUPPORTED_FEATURES ; +} +static inline int parse_root_owner (char *ids,u_int32_t *root_uid,u_int32_t *root_gid) {
Signature · 8 lines
2.31.1 _______________________________________________ Linux-f2fs-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel