Skip to content

Commit

Permalink
Make metadata_max configurable through the Storage trait
Browse files Browse the repository at this point in the history
  • Loading branch information
sosthene-nitrokey committed Jun 12, 2023
1 parent 50855f9 commit f1c9abe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ pub trait Storage {
/// Value zero is invalid, must be positive or -1.
const BLOCK_CYCLES: isize = -1;

// Optional upper limit on total space given to metadata pairs in bytes. On
// devices with large blocks (e.g. 128kB) setting this to a low size (2-8kB)
// can help bound the metadata compaction time. Must be <= block_size.
// Defaults to block_size when zero.
const METADATA_MAX: u32 = 0;

/// littlefs uses a read cache, a write cache, and one cache per per file.
/// Must be a multiple of `READ_SIZE` and `WRITE_SIZE`.
/// Must be a factor of `BLOCK_SIZE`.
Expand Down
3 changes: 2 additions & 1 deletion src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ impl<Storage: driver::Storage> Allocation<Storage> {
let lookahead_size: u32 = 8 * <Storage as driver::Storage>::LOOKAHEAD_SIZE::U32;
let block_cycles: i32 = Storage::BLOCK_CYCLES as _;
let block_count: u32 = Storage::BLOCK_COUNT as _;
let metadata_max = Storage::METADATA_MAX;

debug_assert!(block_cycles >= -1);
debug_assert!(block_cycles != 0);
Expand Down Expand Up @@ -132,7 +133,7 @@ impl<Storage: driver::Storage> Allocation<Storage> {
name_max: filename_max_plus_one.wrapping_sub(1),
file_max,
attr_max,
metadata_max: 0,
metadata_max,
};

Self {
Expand Down
4 changes: 2 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ ram_storage!(

#[test]
fn version() {
assert_eq!(crate::version().format, (2, 0));
assert_eq!(crate::version().backend, (2, 2));
assert_eq!(crate::version().format, (2, 1));
assert_eq!(crate::version().backend, (2, 6));
}

#[test]
Expand Down

0 comments on commit f1c9abe

Please sign in to comment.