Extended lfsr_format with some gc flags
These fall out quite naturally when you consider that we call
lfsr_mountinited internally to check that our format was successful.
That being said... they don't really do anything right now since we only
write a single mdir:
- LFS_F_COMPACT - The only gc operation that _might_ actually do
something is LFS_F_COMPACT, but only if our fs config exceeds >1/2 the
block size. But I'm not sure littlefs will even be able to write file
metadata if this happens...
- LFS_F_CKMETA - We already check the only mdir by calling
lfsr_mountinited, which implicitly fetches the mrootanchor.
- LFS_F_CKDATA - We uh, don't have any data immediately after
lfsr_format. But I guess it doesn't hurt to keep this around for
consistency, it at least implies CKMETA.
Hopefully these flags will be more interesting if/when we start adding
auxiliary trees to the filesystem, otherwise they may be worth reverting
in the future...
Until then, they at least provide some consistency, and I guess a way to
triply check that format was successful.
---
This could probably be better deduplicated, but calling lfsr_fs_gc from
both lfsr_mount and lfsr_format provides a bit better code organization:
code stack
before: 36448 2680
after: 36480 (+0.1%) 2680 (+0.0%)
This commit is contained in:
@@ -13373,21 +13373,6 @@ int lfsr_mount(lfs_t *lfs, uint32_t flags,
|
||||
goto failed;
|
||||
}
|
||||
|
||||
// TODO this should use any configured values
|
||||
LFS_DEBUG("Mounted littlefs v%"PRId32".%"PRId32" "
|
||||
"%"PRId32"x%"PRId32" "
|
||||
"0x{%"PRIx32",%"PRIx32"}.%"PRIx32" "
|
||||
"w%"PRId32".%"PRId32,
|
||||
LFS_DISK_VERSION_MAJOR,
|
||||
LFS_DISK_VERSION_MINOR,
|
||||
lfs->cfg->block_size,
|
||||
lfs->block_count,
|
||||
lfs->mroot.rbyd.blocks[0],
|
||||
lfs->mroot.rbyd.blocks[1],
|
||||
lfsr_rbyd_trunk(&lfs->mroot.rbyd),
|
||||
lfsr_mtree_weight_(&lfs->mtree) >> lfs->mdir_bits,
|
||||
1 << lfs->mdir_bits);
|
||||
|
||||
// run gc if requested
|
||||
if (flags & (
|
||||
LFS_M_MTREEONLY
|
||||
@@ -13409,6 +13394,21 @@ int lfsr_mount(lfs_t *lfs, uint32_t flags,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO this should use any configured values
|
||||
LFS_DEBUG("Mounted littlefs v%"PRId32".%"PRId32" "
|
||||
"%"PRId32"x%"PRId32" "
|
||||
"0x{%"PRIx32",%"PRIx32"}.%"PRIx32" "
|
||||
"w%"PRId32".%"PRId32,
|
||||
LFS_DISK_VERSION_MAJOR,
|
||||
LFS_DISK_VERSION_MINOR,
|
||||
lfs->cfg->block_size,
|
||||
lfs->block_count,
|
||||
lfs->mroot.rbyd.blocks[0],
|
||||
lfs->mroot.rbyd.blocks[1],
|
||||
lfsr_rbyd_trunk(&lfs->mroot.rbyd),
|
||||
lfsr_mtree_weight_(&lfs->mtree) >> lfs->mdir_bits,
|
||||
1 << lfs->mdir_bits);
|
||||
|
||||
return 0;
|
||||
|
||||
failed:;
|
||||
@@ -13493,12 +13493,6 @@ static int lfsr_formatinited(lfs_t *lfs) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// test that mount works with our formatted disk
|
||||
err = lfsr_mountinited(lfs);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -13508,7 +13502,11 @@ int lfsr_format(lfs_t *lfs, uint32_t flags,
|
||||
LFS_ASSERT((flags & ~(
|
||||
LFS_F_RDWR
|
||||
| LFS_F_CKPROGS
|
||||
| LFS_IFDEF_CKREADS(LFS_F_CKREADS, 0))) == 0);
|
||||
| LFS_IFDEF_CKREADS(LFS_F_CKREADS, 0)
|
||||
| LFS_F_MTREEONLY
|
||||
| LFS_F_COMPACT
|
||||
| LFS_F_CKMETA
|
||||
| LFS_F_CKDATA)) == 0);
|
||||
// some flags don't make sense when only traversing the mtree
|
||||
LFS_ASSERT(!lfsr_t_ismtreeonly(flags) || !lfsr_t_isckdata(flags));
|
||||
|
||||
@@ -13526,12 +13524,38 @@ int lfsr_format(lfs_t *lfs, uint32_t flags,
|
||||
|
||||
err = lfsr_formatinited(lfs);
|
||||
if (err) {
|
||||
// make sure we clean up on error
|
||||
lfs_deinit(lfs);
|
||||
return err;
|
||||
goto failed;
|
||||
}
|
||||
|
||||
// test that mount works with our formatted disk
|
||||
err = lfsr_mountinited(lfs);
|
||||
if (err) {
|
||||
goto failed;
|
||||
}
|
||||
|
||||
// run gc if requested
|
||||
if (flags & (
|
||||
LFS_F_MTREEONLY
|
||||
| LFS_F_COMPACT
|
||||
| LFS_F_CKMETA
|
||||
| LFS_F_CKDATA)) {
|
||||
err = lfsr_fs_gc(lfs, -1,
|
||||
flags & (
|
||||
LFS_F_MTREEONLY
|
||||
| LFS_F_COMPACT
|
||||
| LFS_F_CKMETA
|
||||
| LFS_F_CKDATA));
|
||||
if (err) {
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
||||
return lfs_deinit(lfs);
|
||||
|
||||
failed:;
|
||||
// make sure we clean up on error
|
||||
lfs_deinit(lfs);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user