Skip to content

Commit 9390ee3

Browse files
Add config flag to disable block count check on mount
When the block count check was added to `lfs_mount` in [#584][] it was mentionned to have a mount flag to disable this check in the future. Therefore, this PR: - Adds a new `flags` field to lfs_config - Defines a new `lfs_fs_flags` enum that contains these flags - Defines one flag `LFS_CFG_DISABLE_BLOCK_COUNT_CHECK` that disables the check inserted in [#584][] [#584]: #584
1 parent 16ceb67 commit 9390ee3

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lfs.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4596,15 +4596,21 @@ static int lfs_mount_(lfs_t *lfs, const struct lfs_config *cfg) {
45964596
}
45974597

45984598
// this is where we get the block_count from disk if block_count=0
4599-
if (lfs->cfg->block_count
4599+
4600+
if ((lfs->cfg->flags & LFS_CFG_DISABLE_BLOCK_COUNT_CHECK) == 0
4601+
&& lfs->cfg->block_count
46004602
&& superblock.block_count != lfs->cfg->block_count) {
46014603
LFS_ERROR("Invalid block count (%"PRIu32" != %"PRIu32")",
46024604
superblock.block_count, lfs->cfg->block_count);
46034605
err = LFS_ERR_INVAL;
46044606
goto cleanup;
46054607
}
46064608

4607-
lfs->block_count = superblock.block_count;
4609+
if (lfs->cfg->block_count) {
4610+
lfs->block_count = lfs->cfg->block_count;
4611+
} else {
4612+
lfs->block_count = superblock.block_count;
4613+
}
46084614

46094615
if (superblock.block_size != lfs->cfg->block_size) {
46104616
LFS_ERROR("Invalid block size (%"PRIu32" != %"PRIu32")",

lfs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ struct lfs_config {
283283
// Set to -1 to disable inlined files.
284284
lfs_size_t inline_max;
285285

286+
// Configuration flags for the filesystem
287+
//
288+
// See variants of lfs_fs_flags
289+
uint32_t flags;
290+
286291
#ifdef LFS_MULTIVERSION
287292
// On-disk version to use when writing in the form of 16-bit major version
288293
// + 16-bit minor version. This limiting metadata to what is supported by
@@ -292,6 +297,10 @@ struct lfs_config {
292297
#endif
293298
};
294299

300+
enum lfs_fs_flags {
301+
LFS_CFG_DISABLE_BLOCK_COUNT_CHECK = 1, // Allow mounting a filesystem with a different block count in the config and the superblock
302+
};
303+
295304
// File info structure
296305
struct lfs_info {
297306
// Type of the file, either LFS_TYPE_REG or LFS_TYPE_DIR

tests/test_superblocks.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,13 @@ code = '''
465465
lfs_unmount(&lfs) => 0;
466466
467467
if (KNOWN_BLOCK_COUNT) {
468+
cfg->block_count = BLOCK_COUNT_2 + 1;
469+
lfs_mount(&lfs, cfg) => LFS_ERR_INVAL;
470+
cfg->flags |= LFS_CFG_DISABLE_BLOCK_COUNT_CHECK;
471+
lfs_mount(&lfs, cfg) => 0;
472+
lfs_unmount(&lfs) => 0;
468473
cfg->block_count = BLOCK_COUNT_2;
474+
cfg->flags &= ~LFS_CFG_DISABLE_BLOCK_COUNT_CHECK;
469475
} else {
470476
cfg->block_count = 0;
471477
}

0 commit comments

Comments
 (0)