Skip to content

Commit

Permalink
remove previous block_count detection from lfs_format
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianPugh committed Aug 20, 2023
1 parent d6098bd commit 23089d5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 37 deletions.
15 changes: 1 addition & 14 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4416,20 +4416,7 @@ static int lfs_rawformat(lfs_t *lfs, const struct lfs_config *cfg) {
return err;
}

if (cfg->block_count == 0) {
// Attempt to read a (possibly) prior superblock
lfs_superblock_t superblock;
err = lfs_scan_for_superblock(lfs, &superblock);
if (err) {
goto cleanup;
}
lfs->block_count = superblock.block_count;

err = lfs_validate_superblock(lfs, &superblock);
if (err) {
goto cleanup;
}
}
LFS_ASSERT(cfg->block_count != 0);

// create free lookahead
memset(lfs->free.buffer, 0, lfs->cfg->lookahead_size);
Expand Down
23 changes: 0 additions & 23 deletions tests/test_superblocks.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,6 @@ code = '''
lfs_format(&lfs, cfg) => 0;
'''

# formatting from interpretting a previous superblock block_count
[cases.test_superblocks_format_unknown_block_count]
code = '''
lfs_t lfs;
lfs_format(&lfs, cfg) => 0;
assert(lfs.block_count == cfg->block_count);

memset(&lfs, 0, sizeof(lfs));
struct lfs_config tweaked_cfg = *cfg;
tweaked_cfg.block_count = 0;
lfs_format(&lfs, &tweaked_cfg) => 0;
assert(lfs.block_count == cfg->block_count);
'''

# formatting from interpretting a non-existent previous superblock block_count
[cases.test_superblocks_format_unknown_block_count_failure]
code = '''
lfs_t lfs;
struct lfs_config tweaked_cfg = *cfg;
tweaked_cfg.block_count = 0;
lfs_format(&lfs, &tweaked_cfg) => LFS_ERR_CORRUPT;
'''

# mount/unmount
[cases.test_superblocks_mount]
code = '''
Expand Down

0 comments on commit 23089d5

Please sign in to comment.