Skip to content

Commit c7c7f95

Browse files
Update littlefs2
1 parent e107ed3 commit c7c7f95

File tree

3 files changed

+37
-16
lines changed

3 files changed

+37
-16
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repository = "https://github.com/trussed-dev/trussed"
1010

1111
[workspace.dependencies]
1212
heapless-bytes = "0.3"
13-
littlefs2-core = { version = "0.1", features = ["serde"] }
13+
littlefs2-core = { version = "0.1.1", features = ["serde"] }
1414
postcard = "0.7.0"
1515
rand_core = "0.6"
1616
serde = { version = "1.0", default-features = false, features = ["derive"] }
@@ -203,3 +203,6 @@ rustdoc-args = ["--cfg", "docsrs"]
203203

204204
[patch.crates-io]
205205
trussed-core.path = "core"
206+
littlefs2 = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "d0ebffac28f264990e8eedea98074005f318f0f4"}
207+
littlefs2-core = { git = "https://github.com/trussed-dev/littlefs2.git", rev = "d0ebffac28f264990e8eedea98074005f318f0f4"}
208+
littlefs2-sys = { git = "https://github.com/trussed-dev/littlefs2-sys.git", rev = "1cfd35c9974b877761e8bb45417f7ad2a61bedad"}

src/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,19 @@ macro_rules! create_memory {
8989
}
9090
static mut INTERNAL_FS_ALLOC: Option<Allocation<InternalStorage>> = None;
9191
unsafe {
92-
INTERNAL_FS_ALLOC = Some(Filesystem::allocate());
92+
INTERNAL_FS_ALLOC = Some(Filesystem::allocate(INTERNAL_STORAGE.as_ref().unwrap()));
9393
}
9494

9595
static mut EXTERNAL_STORAGE: ExternalStorage = ExternalStorage::new();
9696
static mut EXTERNAL_FS_ALLOC: Option<Allocation<ExternalStorage>> = None;
9797
unsafe {
98-
EXTERNAL_FS_ALLOC = Some(Filesystem::allocate());
98+
EXTERNAL_FS_ALLOC = Some(Filesystem::allocate(&EXTERNAL_STORAGE));
9999
}
100100

101101
static mut VOLATILE_STORAGE: VolatileStorage = VolatileStorage::new();
102102
static mut VOLATILE_FS_ALLOC: Option<Allocation<VolatileStorage>> = None;
103103
unsafe {
104-
VOLATILE_FS_ALLOC = Some(Filesystem::allocate());
104+
VOLATILE_FS_ALLOC = Some(Filesystem::allocate(&VOLATILE_STORAGE));
105105
}
106106

107107
(

src/virt/store.rs

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ use std::{
44
path::PathBuf,
55
};
66

7-
use generic_array::typenum::{U512, U8};
87
use littlefs2::{const_ram_storage, driver::Storage, object_safe::DynStorageAlloc};
9-
use littlefs2_core::{DynFilesystem, Error, Result};
8+
use littlefs2_core::{DynFilesystem, Result};
109

1110
use crate::store;
1211

@@ -16,6 +15,8 @@ pub struct StoreConfig<'a> {
1615
pub volatile: StorageConfig<'a>,
1716
}
1817

18+
const BLOCK_SIZE: usize = 512;
19+
1920
impl StoreConfig<'_> {
2021
pub fn ram() -> Self {
2122
Self {
@@ -97,15 +98,32 @@ const_ram_storage!(RamStorage, STORAGE_SIZE);
9798
struct FilesystemStorage(PathBuf);
9899

99100
impl Storage for FilesystemStorage {
100-
const READ_SIZE: usize = 16;
101-
const WRITE_SIZE: usize = 16;
102-
const BLOCK_SIZE: usize = 512;
101+
fn read_size(&self) -> usize {
102+
16
103+
}
104+
fn write_size(&self) -> usize {
105+
16
106+
}
107+
fn block_size(&self) -> usize {
108+
BLOCK_SIZE
109+
}
110+
fn block_count(&self) -> usize {
111+
128
112+
}
113+
fn block_cycles(&self) -> isize {
114+
-1
115+
}
116+
117+
fn cache_size(&self) -> usize {
118+
512
119+
}
103120

104-
const BLOCK_COUNT: usize = 128;
105-
const BLOCK_CYCLES: isize = -1;
121+
fn lookahead_size(&self) -> usize {
122+
8
123+
}
106124

107-
type CACHE_SIZE = U512;
108-
type LOOKAHEAD_SIZE = U8;
125+
type CACHE_BUFFER = [u8; 512];
126+
type LOOKAHEAD_BUFFER = [u8; 64];
109127

110128
fn read(&mut self, offset: usize, buffer: &mut [u8]) -> Result<usize> {
111129
debug!("read: offset: {}, len: {}", offset, buffer.len());
@@ -136,10 +154,10 @@ impl Storage for FilesystemStorage {
136154
}
137155
let mut file = OpenOptions::new().write(true).open(&self.0).unwrap();
138156
file.seek(SeekFrom::Start(offset as _)).unwrap();
139-
let zero_block = [0xFFu8; Self::BLOCK_SIZE];
140-
for _ in 0..(len / Self::BLOCK_SIZE) {
157+
let zero_block = [0xFFu8; BLOCK_SIZE];
158+
for _ in 0..(len / BLOCK_SIZE) {
141159
let bytes_written = file.write(&zero_block).unwrap();
142-
assert_eq!(bytes_written, Self::BLOCK_SIZE);
160+
assert_eq!(bytes_written, BLOCK_SIZE);
143161
}
144162
file.flush().unwrap();
145163
Ok(len)

0 commit comments

Comments
 (0)