feat(storage-server): add StorageServer<F: FileSystem> with BlockDevice trait, mock adapters, and tests

This commit is contained in:
2026-10-18 03:37:40 +02:00
parent b7bc223a79
commit 7a4600b3a2
13 changed files with 591 additions and 12 deletions

View File

@@ -0,0 +1,46 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct FileHandle(u16);
impl FileHandle {
pub const fn new(id: u16) -> Self {
Self(id)
}
pub const fn raw(&self) -> u16 {
self.0
}
}
#[derive(Debug, Clone, Copy)]
pub struct DirEntry {
pub name: [u8; 32],
pub name_len: u8,
pub size: u32,
pub is_dir: bool,
}
impl DirEntry {
pub fn empty() -> Self {
Self {
name: [0; 32],
name_len: 0,
size: 0,
is_dir: false,
}
}
pub fn name_bytes(&self) -> &[u8] {
&self.name[..self.name_len as usize]
}
}
pub trait FileSystem {
fn open(&mut self, path: &[u8]) -> Option<FileHandle>;
fn read(&mut self, handle: FileHandle, buf: &mut [u8]) -> Option<usize>;
fn write(&mut self, handle: FileHandle, buf: &[u8]) -> Option<usize>;
fn close(&mut self, handle: FileHandle);
fn list_dir(&mut self, path: &[u8], entries: &mut [DirEntry]) -> Option<usize>;
fn create(&mut self, path: &[u8]) -> Option<FileHandle>;
fn delete(&mut self, path: &[u8]) -> bool;
fn file_size(&mut self, handle: FileHandle) -> Option<usize>;
}