diff --git a/Cargo.toml b/Cargo.toml index 57dc5f996cd..16353392363 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/trussed-dev/trussed" [workspace.dependencies] heapless-bytes = "0.3" -littlefs2-core = { version = "0.1", features = ["serde"] } +littlefs2-core = { version = "0.1.1", features = ["serde"] } postcard = "0.7.0" rand_core = "0.6" serde = { version = "1.0", default-features = false, features = ["derive"] } @@ -203,3 +203,6 @@ rustdoc-args = ["--cfg", "docsrs"] [patch.crates-io] trussed-core.path = "core" +littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "d0ebffac28f264990e8eedea98074005f318f0f4"} +littlefs2-core = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "d0ebffac28f264990e8eedea98074005f318f0f4"} +littlefs2-sys = { git = "https://github.com/trussed-dev/littlefs2-sys.git", rev = "1cfd35c9974b877761e8bb45417f7ad2a61bedad"} diff --git a/src/tests.rs b/src/tests.rs index 796250f97dd..905f22c6d07 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -89,19 +89,19 @@ macro_rules! create_memory { } static mut INTERNAL_FS_ALLOC: Option> = None; unsafe { - INTERNAL_FS_ALLOC = Some(Filesystem::allocate()); + INTERNAL_FS_ALLOC = Some(Filesystem::allocate(INTERNAL_STORAGE.as_ref().unwrap())); } static mut EXTERNAL_STORAGE: ExternalStorage = ExternalStorage::new(); static mut EXTERNAL_FS_ALLOC: Option> = None; unsafe { - EXTERNAL_FS_ALLOC = Some(Filesystem::allocate()); + EXTERNAL_FS_ALLOC = Some(Filesystem::allocate(&EXTERNAL_STORAGE)); } static mut VOLATILE_STORAGE: VolatileStorage = VolatileStorage::new(); static mut VOLATILE_FS_ALLOC: Option> = None; unsafe { - VOLATILE_FS_ALLOC = Some(Filesystem::allocate()); + VOLATILE_FS_ALLOC = Some(Filesystem::allocate(&VOLATILE_STORAGE)); } ( diff --git a/src/virt/store.rs b/src/virt/store.rs index e2ba2dee2d7..f2a5079d422 100644 --- a/src/virt/store.rs +++ b/src/virt/store.rs @@ -4,7 +4,6 @@ use std::{ path::PathBuf, }; -use generic_array::typenum::{U512, U8}; use littlefs2::{const_ram_storage, driver::Storage, object_safe::DynStorageAlloc}; use littlefs2_core::{DynFilesystem, Error, Result}; @@ -16,6 +15,8 @@ pub struct StoreConfig<'a> { pub volatile: StorageConfig<'a>, } +const BLOCK_SIZE: usize = 512; + impl StoreConfig<'_> { pub fn ram() -> Self { Self { @@ -97,15 +98,32 @@ const_ram_storage!(RamStorage, STORAGE_SIZE); struct FilesystemStorage(PathBuf); impl Storage for FilesystemStorage { - const READ_SIZE: usize = 16; - const WRITE_SIZE: usize = 16; - const BLOCK_SIZE: usize = 512; + fn read_size(&self) -> usize { + 16 + } + fn write_size(&self) -> usize { + 16 + } + fn block_size(&self) -> usize { + BLOCK_SIZE + } + fn block_count(&self) -> usize { + 128 + } + fn block_cycles(&self) -> isize { + -1 + } + + fn cache_size(&self) -> usize { + 512 + } - const BLOCK_COUNT: usize = 128; - const BLOCK_CYCLES: isize = -1; + fn lookahead_size(&self) -> usize { + 8 + } - type CACHE_SIZE = U512; - type LOOKAHEAD_SIZE = U8; + type CACHE_BUFFER = [u8; 512]; + type LOOKAHEAD_BUFFER = [u8; 64]; fn read(&mut self, offset: usize, buffer: &mut [u8]) -> Result { debug!("read: offset: {}, len: {}", offset, buffer.len()); @@ -136,10 +154,10 @@ impl Storage for FilesystemStorage { } let mut file = OpenOptions::new().write(true).open(&self.0).unwrap(); file.seek(SeekFrom::Start(offset as _)).unwrap(); - let zero_block = [0xFFu8; Self::BLOCK_SIZE]; - for _ in 0..(len / Self::BLOCK_SIZE) { + let zero_block = [0xFFu8; BLOCK_SIZE]; + for _ in 0..(len / BLOCK_SIZE) { let bytes_written = file.write(&zero_block).unwrap(); - assert_eq!(bytes_written, Self::BLOCK_SIZE); + assert_eq!(bytes_written, BLOCK_SIZE); } file.flush().unwrap(); Ok(len)