ext4: Improve feature checking
PATCH v3 1/1 ext4: Improve feature checking
Evaluate the filesystem incompat and ro_compat bit fields to judge whether the filesystem can be read or written.
For the read side only a scary warning is shown so far.
I'd love to abort mounting too, but I fear this will break some setups where the driver works by chance.
---
Changes since v2:
- Add EXT4_FEATURE_RO_COMPAT_GDT_CSUM to EXT4_FEATURE_RO_COMPAT_SUPP set
--- fs/ext4/ext4_common.c | 14 ++++++++++++ fs/ext4/ext4_write.c | 12 ++++++++-- include/ext4fs.h | 53 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 3 deletions(-)
fs/ext4/ext4_common.c +14 -0
@@ -2383,6 +2383,20 @@ int ext4fs_mount(void) fs->inodesz =128 ; fs->gdsize =32 ; }else { +int missing =__le32_to_cpu (data->sblock.feature_incompat) & + ~(EXT4_FEATURE_INCOMPAT_SUPP | +EXT4_FEATURE_INCOMPAT_SUPP_LAZY_RO ); + +if (missing) { +/* +* This code used to be relaxed about feature flags. +* We don't stop the mount to avoid breaking existing setups. +* But, incompatible features can cause serious read errors. +*/ +log_err ("fs uses incompatible features: %08x, ignoring\n" , + missing); + } + debug("EXT4 features COMPAT: %08x INCOMPAT: %08x RO_COMPAT: %08x\n", __le32_to_cpu(data->sblock.feature_compatibility), __le32_to_cpu(data->sblock.feature_incompat),
fs/ext4/ext4_write.c +10 -2
@@ -866,6 +866,7 @@ int ext4fs_write(const char *fname, const char *buffer,ALLOC_CACHE_ALIGN_BUFFER (char, filename,256 );bool store_link_in_inode = false;memset (filename,0x00 ,256 ); +int missing_feat;if (type !=FILETYPE_REG && type !=FILETYPE_SYMLINK )return -1 ;
@@ -879,8 +880,15 @@ int ext4fs_write(const char *fname, const char *buffer,return -1 ; } -if (le32_to_cpu (fs->sb->feature_ro_compat) &EXT4_FEATURE_RO_COMPAT_METADATA_CSUM ) { -printf ("Unsupported feature metadata_csum found, not writing.\n" ); + missing_feat =le32_to_cpu (fs->sb->feature_incompat) & ~EXT4_FEATURE_INCOMPAT_SUPP ; +if (missing_feat) { +log_err ("Unsupported features found %08x, not writing.\n" , missing_feat); +return -1 ; + } + + missing_feat =le32_to_cpu (fs->sb->feature_ro_compat) & ~EXT4_FEATURE_RO_COMPAT_SUPP ; +if (missing_feat) { +log_err ("Unsupported RO compat features found %08x, not writing.\n" , missing_feat);return -1 ; }
include/ext4fs.h +52 -1
64 lines not on this page · raw message
Signature · 1 line
2.35.3
Quoted 8 lines · Richard Weinberger
Evaluate the filesystem incompat and
ro_compatbit fields to judge whether the filesystem can be read or written.
For the read side only a scary warning is shown so far.
I'd love to abort mounting too, but I fear this will break some setups where the driver works by chance.[...]
Applied to u-boot/next, thanks!
Signature · 1 line
Tom