Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down Expand Up @@ -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"}
6 changes: 3 additions & 3 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ macro_rules! create_memory {
}
static mut INTERNAL_FS_ALLOC: Option<Allocation<InternalStorage>> = 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<Allocation<ExternalStorage>> = 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<Allocation<VolatileStorage>> = None;
unsafe {
VOLATILE_FS_ALLOC = Some(Filesystem::allocate());
VOLATILE_FS_ALLOC = Some(Filesystem::allocate(&VOLATILE_STORAGE));
}

(
Expand Down
40 changes: 29 additions & 11 deletions src/virt/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

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

const BLOCK_SIZE: usize = 512;

impl StoreConfig<'_> {
pub fn ram() -> Self {
Self {
Expand Down Expand Up @@ -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<usize> {
debug!("read: offset: {}, len: {}", offset, buffer.len());
Expand Down Expand Up @@ -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)
Expand Down