From 3efb8e44f30fb9ad61067d84c89d7444c76b866c Mon Sep 17 00:00:00 2001 From: Colin Foster Date: Wed, 21 Jul 2021 08:56:21 -0700 Subject: [PATCH] Fail mount when the block size changes When the on-disk block size doesn't match the config block size, it is possible to get file corruption. For instance, if the num blocks was 0x200 and we re-mount with 0x100 files could be corrupt. If we re-mount with a larger number of blocks things should be safer, but could be handled with a resize option or perhaps a mount flag to ignore this parameter. --- lfs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lfs.c b/lfs.c index d976389..c0092ca 100644 --- a/lfs.c +++ b/lfs.c @@ -3761,6 +3761,12 @@ static int lfs_rawmount(lfs_t *lfs, const struct lfs_config *cfg) { lfs->attr_max = superblock.attr_max; } + + if (superblock.block_count != lfs->cfg->block_count) + { + err = LFS_ERR_CORRUPT; + goto cleanup; + } } // has gstate?