Changed block_size search to use erase_count when block_size is zero

This hopefully helps make it more clear that we are using erase_size as the
unit during the block_size search. However this does mean you need to
set erase_count to zero to allow any littlefs size, which might be a bit
confusing:

  block_size  block_count  erase_size  erase_count
  known       known        known       known       => known bs, O(1)
  known       unknown      known       known       => known bs, O(1)
  unknown     unknown      known       known       => bs search, O(d(n))
  unknown     unknown      known       unknown     => bs search, O(n)
This commit is contained in:
Christopher Haster
2022-11-11 00:53:44 -06:00
parent 75f80aabd7
commit 03beff6c54
2 changed files with 21 additions and 19 deletions
+8 -7
View File
@@ -209,6 +209,11 @@ struct lfs_config {
//
// If zero, the block_count is used as the erase_count. This is mostly for
// backwards compatibility.
//
// If zero and block_count is zero, this is treated as unknown.
//
// If non-zero, littlefs will assume block_size is a factor of
// erase_size*erase_count to speed up mount when no superblock is found.
lfs_size_t erase_count;
// Size of a logical block in bytes. This does not impact RAM consumption
@@ -223,18 +228,14 @@ struct lfs_config {
// block_size, but it can take time to fail if a superblock is not found:
//
// - O(block_size) if a superblock is found
// - O(d(block_count)) if block_count is non-zero
// - O(log(block_count)) if block_count is a power of 2
// - O(erase_count) if block_count is zero
// - O(d(erase_count)) if erase_count is non-zero
// - O(log(erase_count)) if erase_count is a power of 2
// - O(erase_count) if erase_count is zero
lfs_size_t block_size;
// Number of logical blocks on the device.
//
// If zero, littlefs uses the block_count stored in the superblock.
//
// If non-zero and block_size is zero, littlefs will assume block_size
// is a factor of erase_size*block_count to speed up mount when no
// superblock is found.
lfs_size_t block_count;
// Number of erase cycles before littlefs evicts metadata logs and moves