Skip to content

Commit 5ecc6e2

Browse files
authored
129 refactor virtual file system (#131)
1 parent 3eb476a commit 5ecc6e2

226 files changed

Lines changed: 13266 additions & 14650 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ wasm_c_bindings = ["wasm", "wasm_bindings/c_bindings"]
8080

8181

8282
[workspace.dependencies]
83-
# - Internal crates
83+
# - Modules
8484
wasm_bindings = { path = "modules/bindings/wasm" }
8585

8686
abi_context = { path = "modules/abi/context" }
@@ -108,6 +108,7 @@ network = { path = "modules/network" }
108108
peripherals = { path = "modules/peripherals" }
109109
bootsplash = { path = "modules/bootsplash" }
110110
internationalization = { path = "modules/internationalization" }
111+
testing = { path = "modules/testing" }
111112

112113
# - Drivers
113114
drivers_core = { path = "drivers/core" }
@@ -173,6 +174,7 @@ members = [
173174
"executables/shell/command_line",
174175
"modules/executable",
175176
"executables/wasm",
177+
"executables/wasm/tests/wasm_test",
176178
"executables/shell/graphical",
177179
"executables/terminal",
178180
"executables/settings",
@@ -196,6 +198,7 @@ members = [
196198
"modules/internationalization",
197199
"modules/internationalization/macros",
198200
"modules/graphics/fonts_generator",
201+
"modules/testing",
199202
]
200203

201204
[patch.crates-io]

drivers/core/src/null.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
1-
use file_system::{DeviceTrait, Size};
1+
use file_system::{CharacterDevice, DirectBaseOperations, MountOperations, Size};
22

33
pub struct NullDevice;
44

5-
impl DeviceTrait for NullDevice {
6-
fn read(&self, buffer: &mut [u8]) -> file_system::Result<file_system::Size> {
7-
Ok(Size::new(buffer.len() as u64))
5+
impl DirectBaseOperations for NullDevice {
6+
fn read(&self, buffer: &mut [u8], _: Size) -> file_system::Result<usize> {
7+
Ok(buffer.len() as _)
88
}
99

10-
fn write(&self, buffer: &[u8]) -> file_system::Result<file_system::Size> {
11-
Ok(Size::new(buffer.len() as u64))
12-
}
13-
14-
fn get_size(&self) -> file_system::Result<file_system::Size> {
15-
Ok(Size::new(0))
10+
fn write(&self, buffer: &[u8], _: Size) -> file_system::Result<usize> {
11+
Ok(buffer.len() as _)
1612
}
13+
}
1714

18-
fn set_position(&self, _: &file_system::Position) -> file_system::Result<file_system::Size> {
19-
Ok(Size::new(0))
20-
}
15+
impl MountOperations for NullDevice {}
2116

22-
fn flush(&self) -> file_system::Result<()> {
23-
Ok(())
24-
}
25-
}
17+
impl CharacterDevice for NullDevice {}

drivers/native/src/devices/window_screen/keyboard.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use file_system::{DeviceTrait, Size};
1+
use file_system::{DirectBaseOperations, DirectCharacterDevice, MountOperations, Size};
22
use graphics::{InputData, Key, State};
33
use synchronization::{
44
blocking_mutex::raw::{CriticalSectionRawMutex, RawMutex},
@@ -18,8 +18,8 @@ where
1818
}
1919
}
2020

21-
impl<const N: usize> DeviceTrait for KeyboardDevice<CriticalSectionRawMutex, N> {
22-
fn read(&self, buffer: &mut [u8]) -> file_system::Result<Size> {
21+
impl<const N: usize> DirectBaseOperations for KeyboardDevice<CriticalSectionRawMutex, N> {
22+
fn read(&self, buffer: &mut [u8], _: Size) -> file_system::Result<usize> {
2323
// - Cast
2424
let data: &mut InputData = buffer
2525
.try_into()
@@ -32,22 +32,14 @@ impl<const N: usize> DeviceTrait for KeyboardDevice<CriticalSectionRawMutex, N>
3232

3333
data.set_continue(!self.0.is_empty());
3434

35-
Ok(size_of::<InputData>().into())
35+
Ok(size_of::<InputData>())
3636
}
3737

38-
fn write(&self, _: &[u8]) -> file_system::Result<Size> {
38+
fn write(&self, _: &[u8], _: Size) -> file_system::Result<usize> {
3939
Err(file_system::Error::UnsupportedOperation)
4040
}
41+
}
4142

42-
fn get_size(&self) -> file_system::Result<Size> {
43-
Ok(size_of::<InputData>().into())
44-
}
43+
impl<const N: usize> MountOperations for KeyboardDevice<CriticalSectionRawMutex, N> {}
4544

46-
fn set_position(&self, _: &file_system::Position) -> file_system::Result<Size> {
47-
Err(file_system::Error::UnsupportedOperation)
48-
}
49-
50-
fn flush(&self) -> file_system::Result<()> {
51-
Ok(())
52-
}
53-
}
45+
impl<const N: usize> DirectCharacterDevice for KeyboardDevice<CriticalSectionRawMutex, N> {}

drivers/native/src/devices/window_screen/mod.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ mod pointer;
55
mod screen;
66
mod window;
77

8-
use file_system::{Device, create_device};
98
use graphics::{InputData, Key, Point, State};
109
use synchronization::rwlock::RwLock;
1110
use synchronization::{blocking_mutex::raw::CriticalSectionRawMutex, channel::Channel};
@@ -23,7 +22,17 @@ static POINTER_RWLOCK: RwLock<CriticalSectionRawMutex, InputData> =
2322
RwLock::new(InputData::default_constant());
2423
static INNER_WINDOW: InnerWindow = InnerWindow::new();
2524

26-
pub async fn new(resolution: Point) -> Result<(Device, Device, Device, Runner<'static>), String> {
25+
pub async fn new(
26+
resolution: Point,
27+
) -> Result<
28+
(
29+
ScreenDevice<'static>,
30+
PointerDevice,
31+
KeyboardDevice<CriticalSectionRawMutex, 64>,
32+
Runner<'static>,
33+
),
34+
String,
35+
> {
2736
let window = Window::new(
2837
resolution,
2938
&INNER_WINDOW,
@@ -39,10 +48,5 @@ pub async fn new(resolution: Point) -> Result<(Device, Device, Device, Runner<'s
3948

4049
let keyboard_device = KeyboardDevice::new(KEYBOARD_CHANNEL.receiver());
4150

42-
Ok((
43-
create_device!(screen_device),
44-
create_device!(pointer_device),
45-
create_device!(keyboard_device),
46-
event_loop,
47-
))
51+
Ok((screen_device, pointer_device, keyboard_device, event_loop))
4852
}
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use file_system::{DeviceTrait, Size};
1+
use file_system::{DirectBaseOperations, DirectCharacterDevice, MountOperations, Size};
22
use graphics::InputData;
33
use synchronization::{blocking_mutex::raw::CriticalSectionRawMutex, rwlock::RwLock};
44

@@ -10,8 +10,8 @@ impl PointerDevice {
1010
}
1111
}
1212

13-
impl DeviceTrait for PointerDevice {
14-
fn read(&self, buffer: &mut [u8]) -> file_system::Result<Size> {
13+
impl DirectBaseOperations for PointerDevice {
14+
fn read(&self, buffer: &mut [u8], _: Size) -> file_system::Result<usize> {
1515
// - Cast the pointer data to the buffer.
1616
let data: &mut InputData = buffer
1717
.try_into()
@@ -23,22 +23,14 @@ impl DeviceTrait for PointerDevice {
2323
*data = *guard;
2424
}
2525

26-
Ok(size_of::<InputData>().into())
26+
Ok(size_of::<InputData>())
2727
}
2828

29-
fn write(&self, _: &[u8]) -> file_system::Result<Size> {
29+
fn write(&self, _: &[u8], _: Size) -> file_system::Result<usize> {
3030
Err(file_system::Error::UnsupportedOperation)
3131
}
32+
}
3233

33-
fn get_size(&self) -> file_system::Result<Size> {
34-
Ok(size_of::<InputData>().into())
35-
}
34+
impl MountOperations for PointerDevice {}
3635

37-
fn set_position(&self, _: &file_system::Position) -> file_system::Result<Size> {
38-
Err(file_system::Error::UnsupportedOperation)
39-
}
40-
41-
fn flush(&self) -> file_system::Result<()> {
42-
Ok(())
43-
}
44-
}
36+
impl DirectCharacterDevice for PointerDevice {}
Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use file_system::{DeviceTrait, Size};
1+
use file_system::{DirectBaseOperations, DirectCharacterDevice, MountOperations, Size};
22
use graphics::{ScreenReadData, ScreenWriteData};
33

44
use crate::window_screen::inner_window::InnerWindow;
@@ -15,8 +15,8 @@ impl<'a> ScreenDevice<'a> {
1515
}
1616
}
1717

18-
impl<'a> DeviceTrait for ScreenDevice<'a> {
19-
fn read(&self, buffer: &mut [u8]) -> file_system::Result<file_system::Size> {
18+
impl<'a> DirectBaseOperations for ScreenDevice<'a> {
19+
fn read(&self, buffer: &mut [u8], _: Size) -> file_system::Result<usize> {
2020
let data: &mut ScreenReadData = buffer
2121
.try_into()
2222
.map_err(|_| file_system::Error::InvalidParameter)?;
@@ -25,28 +25,20 @@ impl<'a> DeviceTrait for ScreenDevice<'a> {
2525

2626
data.set_resolution(resolution);
2727

28-
Ok(Size::new(size_of::<Self>() as u64))
28+
Ok(size_of::<Self>() as _)
2929
}
3030

31-
fn write(&self, buffer: &[u8]) -> file_system::Result<file_system::Size> {
31+
fn write(&self, buffer: &[u8], _: Size) -> file_system::Result<usize> {
3232
let data: &ScreenWriteData = buffer
3333
.try_into()
3434
.map_err(|_| file_system::Error::InvalidParameter)?;
3535

3636
futures::block_on(self.0.draw(data)).unwrap();
3737

38-
Ok(Size::new(size_of::<Self>() as u64))
39-
}
40-
41-
fn get_size(&self) -> file_system::Result<file_system::Size> {
42-
Ok(Size::new(size_of::<Self>() as u64))
38+
Ok(size_of::<Self>() as _)
4339
}
40+
}
4441

45-
fn set_position(&self, _: &file_system::Position) -> file_system::Result<file_system::Size> {
46-
Err(file_system::Error::UnsupportedOperation)
47-
}
42+
impl MountOperations for ScreenDevice<'_> {}
4843

49-
fn flush(&self) -> file_system::Result<()> {
50-
Ok(())
51-
}
52-
}
44+
impl DirectCharacterDevice for ScreenDevice<'_> {}

drivers/native/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,5 @@
33
extern crate alloc;
44

55
mod devices;
6-
mod time;
76

87
pub use devices::*;
9-
10-
pub use time::*;

drivers/native/src/time.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,27 @@
1-
use file_system::{DeviceTrait, Size};
1+
use file_system::{DirectBaseOperations, DirectCharacterDevice, MountOperations, Size};
22

33
pub struct RandomDevice;
44

5-
impl Default for RandomDevice {
6-
fn default() -> Self {
7-
Self::new()
8-
}
9-
}
10-
11-
impl RandomDevice {
12-
pub fn new() -> Self {
13-
Self
14-
}
15-
}
16-
17-
impl DeviceTrait for RandomDevice {
18-
fn read(&self, buffer: &mut [u8]) -> file_system::Result<file_system::Size> {
5+
impl DirectBaseOperations for RandomDevice {
6+
fn read(&self, buffer: &mut [u8], _: Size) -> file_system::Result<usize> {
197
getrandom::fill(buffer).map_err(|_| file_system::Error::Other)?;
208

21-
Ok(buffer.len().into())
9+
Ok(buffer.len())
2210
}
2311

24-
fn write(&self, _buffer: &[u8]) -> file_system::Result<file_system::Size> {
12+
fn write(&self, _: &[u8], _: Size) -> file_system::Result<usize> {
2513
Err(file_system::Error::UnsupportedOperation)
2614
}
2715

28-
fn get_size(&self) -> file_system::Result<file_system::Size> {
29-
Ok(Size::new(0))
30-
}
31-
3216
fn set_position(
3317
&self,
18+
_: Size,
3419
_position: &file_system::Position,
3520
) -> file_system::Result<file_system::Size> {
3621
Err(file_system::Error::UnsupportedOperation)
3722
}
38-
39-
fn flush(&self) -> file_system::Result<()> {
40-
Ok(())
41-
}
4223
}
24+
25+
impl MountOperations for RandomDevice {}
26+
27+
impl DirectCharacterDevice for RandomDevice {}

drivers/std/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ embassy-executor = { workspace = true, default-features = false, features = [
2525

2626
[dev-dependencies]
2727
little_fs = { workspace = true }
28+
abi_definitions = { workspace = true }
29+
critical-section = { workspace = true, features = ["std"] }

0 commit comments

Comments
 (0)