Skip to content

Commit fdf1a1b

Browse files
Make metadata_max configurable through the Storage trait
1 parent 00ac932 commit fdf1a1b

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/driver.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ pub trait Storage {
4444
/// Value zero is invalid, must be positive or -1.
4545
const BLOCK_CYCLES: isize = -1;
4646

47+
// Optional upper limit on total space given to metadata pairs in bytes. On
48+
// devices with large blocks (e.g. 128kB) setting this to a low size (2-8kB)
49+
// can help bound the metadata compaction time. Must be <= block_size.
50+
// Defaults to block_size when zero.
51+
const METADATA_MAX: u32 = 0;
52+
4753
/// littlefs uses a read cache, a write cache, and one cache per per file.
4854
/// Must be a multiple of `READ_SIZE` and `WRITE_SIZE`.
4955
/// Must be a factor of `BLOCK_SIZE`.

src/fs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl<Storage: driver::Storage> Allocation<Storage> {
6161
let lookahead_size: u32 = 8 * <Storage as driver::Storage>::LOOKAHEAD_SIZE::U32;
6262
let block_cycles: i32 = Storage::BLOCK_CYCLES as _;
6363
let block_count: u32 = Storage::BLOCK_COUNT as _;
64+
let metadata_max = Storage::METADATA_MAX;
6465

6566
debug_assert!(block_cycles >= -1);
6667
debug_assert!(block_cycles != 0);
@@ -132,7 +133,7 @@ impl<Storage: driver::Storage> Allocation<Storage> {
132133
name_max: filename_max_plus_one.wrapping_sub(1),
133134
file_max,
134135
attr_max,
135-
metadata_max: 0,
136+
metadata_max,
136137
};
137138

138139
Self {

src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ ram_storage!(
4141

4242
#[test]
4343
fn version() {
44-
assert_eq!(crate::version().format, (2, 0));
45-
assert_eq!(crate::version().backend, (2, 2));
44+
assert_eq!(crate::version().format, (2, 1));
45+
assert_eq!(crate::version().backend, (2, 6));
4646
}
4747

4848
#[test]

0 commit comments

Comments
 (0)