Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/virtual file system #15

Merged
merged 39 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ce5151e
Delegate concurrency management to file systems implementations for f…
AlixANNERAUD Jul 1, 2024
9adaf49
Refactor virtual file system
AlixANNERAUD Jul 1, 2024
707e11e
Rename Pipe_file_system_type into Manager_type and reuse it for all v…
AlixANNERAUD Jul 2, 2024
59a1e5c
Move pipe to its folder
AlixANNERAUD Jul 3, 2024
759a59d
Use VecDeque for Pipe_type instead of Ring_buffer_type for Pipe
AlixANNERAUD Jul 3, 2024
0b95e55
Refactor Flags_type conversion to use implicit casting
AlixANNERAUD Jul 6, 2024
c1e1577
Refactor Pipe.rs to use Error_type::Ressource_busy instead of Error_t…
AlixANNERAUD Jul 6, 2024
249643b
Derive Debug trait for Pipe_type
AlixANNERAUD Jul 6, 2024
6dc762d
Use BTreeMap / BTreeSet instead of HashMap / HashSet for ordered iden…
AlixANNERAUD Jul 6, 2024
d31fe9c
Add Is_empty and Is_canonical to Path_reference_type
AlixANNERAUD Jul 6, 2024
f34828b
Differentiate absolute and relative path stripping
AlixANNERAUD Jul 6, 2024
74faa8a
Path_owned_type is now transparent and derive Hash and PartialEq
AlixANNERAUD Jul 6, 2024
5974c79
An empty path is now considered valid
AlixANNERAUD Jul 6, 2024
2020c6e
Refactor File_system_identifier_type to use u16 instead of u8
AlixANNERAUD Jul 6, 2024
582ebda
Derive Ord and PartialOrd for File system identifier types that are u…
AlixANNERAUD Jul 6, 2024
2ec9cad
Permission_type and Permissions_type now use u16, are transparent and…
AlixANNERAUD Jul 6, 2024
1efda40
Add New_write_execute and New_read_execute for Permission_type
AlixANNERAUD Jul 6, 2024
2cfc632
Add Include() for Permission_type
AlixANNERAUD Jul 6, 2024
f598388
Rename Result<> to Result_type<>
AlixANNERAUD Jul 6, 2024
be78b47
Make File_system_trait more general and refactor some function signature
AlixANNERAUD Jul 6, 2024
6338a6a
Implement File_system_trait for Pipe Manager_type
AlixANNERAUD Jul 6, 2024
73ba5dd
Fix bugs in native file system drivers
AlixANNERAUD Jul 6, 2024
d5cd3bc
Implement Debug for File_type
AlixANNERAUD Jul 6, 2024
dd13ea4
Write device trait
AlixANNERAUD Jul 6, 2024
631f26a
Implement file system for device
AlixANNERAUD Jul 6, 2024
d35ee42
Add Device module and export Device_trait
AlixANNERAUD Jul 6, 2024
437ee37
Refactor Virtual file system to handle device and file as regular fil…
AlixANNERAUD Jul 6, 2024
fcb48b0
Use static mut for Virtual file system singleton instead of Arc (more…
AlixANNERAUD Jul 6, 2024
e50bc5c
Export all generics to the root of File system
AlixANNERAUD Jul 6, 2024
e858e1f
Update Virtual file system integration test
AlixANNERAUD Jul 6, 2024
d8f0344
Update native screen drivers to use new device file type instead of r…
AlixANNERAUD Jul 6, 2024
f6a36e8
Update SDL2 in Screen
AlixANNERAUD Jul 6, 2024
c2b7a64
Remove unused traits and types, move the remaining into their own fil…
AlixANNERAUD Jul 6, 2024
65c2b35
Refactor Error_type to include Poisoned_lock variant and implement Fr…
AlixANNERAUD Jul 6, 2024
5fd20ad
Refactor Graphics to use new Device file for Input_type, add Error_ty…
AlixANNERAUD Jul 6, 2024
03f48bc
Add opt-level = 0 as comment into main Cargo.toml
AlixANNERAUD Jul 6, 2024
e88b6dc
Update file system bindings and its unit test
AlixANNERAUD Jul 6, 2024
23f566b
Fix task bindings unit test warnings
AlixANNERAUD Jul 6, 2024
0d95d49
Disable graphics bindings and its integration test
AlixANNERAUD Jul 6, 2024
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ opt-level = "s" # Optimize binary size
[profile.dev]
debug = true # Symbols are nice and they don't increase the size on Flash.
opt-level = "z" # Optimize binary size and turn off loop vectorization.
# opt-level = 0 # Disable optimizations to speed up compilation and in case of bugs.

[features]
ESP32 = ["Xtensa"]
Expand Down
6 changes: 3 additions & 3 deletions Modules/Bindings/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ path = "Tests/File_system.rs"
name = "Task_bindings_tests"
path = "Tests/Task.rs"

[[test]]
name = "Graphics_bindings_tests"
path = "Tests/Graphics.rs"
# [[test]]
# name = "Graphics_bindings_tests"
# path = "Tests/Graphics.rs"

15 changes: 5 additions & 10 deletions Modules/Bindings/Tests/File_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
#![allow(non_upper_case_globals)]

use Bindings::File_system_bindings;
use File_system::{
Drivers::Native::File_system_type,
Prelude::{Path_type, Virtual_file_system_type},
};
use File_system::{Drivers::Native::File_system_type, Prelude::Path_type};
use Virtual_machine::{Data_type, Instantiate_test_environment, WasmValue};

#[test]
Expand All @@ -16,17 +13,15 @@ fn Integration_test() {
);

let Virtual_file_system =
Virtual_file_system_type::New(Task::Manager_type::New(), Users::Manager_type::New());
File_system::Initialize(Task::Manager_type::New(), Users::Manager_type::New())
.expect("Failed to initialize file system");

let Native_file_system = File_system_type::New().expect("Failed to create file system");

let _ = Virtual_file_system.Mount(Box::new(Native_file_system), Path_type::Get_root());

let (_Runtime, _Module, Instance) = Instantiate_test_environment(
Binary_buffer,
File_system_bindings::New(Virtual_file_system.clone()),
&Data_type::New(),
);
let (_Runtime, _Module, Instance) =
Instantiate_test_environment(Binary_buffer, File_system_bindings, &Data_type::New());

assert_eq!(
Instance
Expand Down
6 changes: 1 addition & 5 deletions Modules/Bindings/Tests/Task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]

use Bindings::{File_system_bindings, Task_bindings};
use File_system::{
Drivers::Native::File_system_type,
Prelude::{Path_type, Virtual_file_system_type},
};
use Bindings::Task_bindings;
use Virtual_machine::{Data_type, Instantiate_test_environment, WasmValue};

#[test]
Expand Down
55 changes: 24 additions & 31 deletions Modules/Bindings/src/File_system.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
use std::mem::MaybeUninit;

use Binding_tool::Bind_function_native;
use File_system::Prelude::*;
use Virtual_machine::{Function_descriptor_type, Function_descriptors, Registrable_trait};
pub struct File_system_bindings {}

impl Registrable_trait for File_system_bindings {
fn Get_functions(&self) -> &[Function_descriptor_type] {
&File_system_bindings_functions
}
}
pub struct File_system_bindings;

impl File_system_bindings {
pub fn New(File_system: Virtual_file_system_type) -> Self {
unsafe {
Virtual_file_system.write(File_system);
}

pub fn New() -> Self {
Self {}
}
}

fn Get_virtual_file_system() -> &'static Virtual_file_system_type {
unsafe { Virtual_file_system.assume_init_ref() }
impl Registrable_trait for File_system_bindings {
fn Get_functions(&self) -> &[Function_descriptor_type] {
&File_system_bindings_functions
}
}

const File_system_bindings_functions: [Function_descriptor_type; 8] = Function_descriptors!(
Expand All @@ -36,18 +27,20 @@ const File_system_bindings_functions: [Function_descriptor_type; 8] = Function_d
Delete_binding
);

static mut Virtual_file_system: MaybeUninit<Virtual_file_system_type> = MaybeUninit::uninit();

fn New_path(Path: &str) -> Result<&Path_type> {
fn New_path(Path: &str) -> Result_type<&Path_type> {
Path_type::New(Path).ok_or(Error_type::Invalid_path)
}

fn Get_virtual_file_system() -> &'static Virtual_file_system_type {
File_system::Get_instance().expect("File system not initialized")
}

#[Bind_function_native(Prefix = "File_system")]
fn Open(
Path: &str,
Flags: Flags_type,
File_identifier: &mut Unique_file_identifier_type,
) -> Result<()> {
) -> Result_type<()> {
let Path = New_path(Path)?;

*File_identifier = Get_virtual_file_system().Open(Path, Flags)?;
Expand All @@ -56,7 +49,7 @@ fn Open(
}

#[Bind_function_native(Prefix = "File_system")]
fn Close_file(File_identifier: Unique_file_identifier_type) -> Result<()> {
fn Close_file(File_identifier: Unique_file_identifier_type) -> Result_type<()> {
Get_virtual_file_system().Close(File_identifier)
}

Expand All @@ -65,7 +58,7 @@ fn Read(
File_identifier: Unique_file_identifier_type,
Buffer: &mut [u8],
Read_size: &mut Size_type,
) -> Result<()> {
) -> Result_type<()> {
*Read_size = Get_virtual_file_system().Read(File_identifier, Buffer)?;

Ok(())
Expand All @@ -76,19 +69,19 @@ fn Write(
File_identifier: Unique_file_identifier_type,
Buffer: &[u8],
Write_size: &mut Size_type,
) -> Result<()> {
) -> Result_type<()> {
*Write_size = Get_virtual_file_system().Write(File_identifier, Buffer)?;

Ok(())
}

#[Bind_function_native(Prefix = "File_system")]
fn Flush(File_identifier: Unique_file_identifier_type) -> Result<()> {
fn Flush(File_identifier: Unique_file_identifier_type) -> Result_type<()> {
Get_virtual_file_system().Flush(File_identifier)
}

#[Bind_function_native(Prefix = "File_system")]
fn Get_file_type(Path: &str, Type: &mut u32) -> Result<()> {
fn Get_file_type(Path: &str, Type: &mut u32) -> Result_type<()> {
let Path = New_path(Path)?;

*Type = Get_virtual_file_system().Get_type(Path)? as u32;
Expand All @@ -97,7 +90,7 @@ fn Get_file_type(Path: &str, Type: &mut u32) -> Result<()> {
}

#[Bind_function_native(Prefix = "File_system")]
fn Get_file_size(Path: &str, Size: &mut Size_type) -> Result<()> {
fn Get_file_size(Path: &str, Size: &mut Size_type) -> Result_type<()> {
let Path = New_path(Path)?;

*Size = Get_virtual_file_system().Get_size(Path)?;
Expand All @@ -110,14 +103,14 @@ fn Set_position(
File_identifier: Unique_file_identifier_type,
Position: &Position_type,
Result_value: &mut Size_type,
) -> Result<()> {
) -> Result_type<()> {
*Result_value = Get_virtual_file_system().Set_position(File_identifier, Position)?;

Ok(())
}

#[Bind_function_native(Prefix = "File_system")]
fn Delete_file(Path: &str, Recursive: bool) -> Result<()> {
fn Delete_file(Path: &str, Recursive: bool) -> Result_type<()> {
let Path = New_path(Path)?;

Get_virtual_file_system().Delete(Path, Recursive)?;
Expand All @@ -126,7 +119,7 @@ fn Delete_file(Path: &str, Recursive: bool) -> Result<()> {
}

#[Bind_function_native(Prefix = "File_system")]
fn Create_file(Path: &str) -> Result<()> {
fn Create_file(Path: &str) -> Result_type<()> {
let Path = New_path(Path)?;

Get_virtual_file_system()
Expand All @@ -137,7 +130,7 @@ fn Create_file(Path: &str) -> Result<()> {
}

#[Bind_function_native(Prefix = "File_system")]
fn Create_directory(Path: &str, Recursive: bool) -> Result<()> {
fn Create_directory(Path: &str, Recursive: bool) -> Result_type<()> {
let Path = New_path(Path)?;

Get_virtual_file_system().Create_directory(Path, Recursive)?;
Expand All @@ -146,7 +139,7 @@ fn Create_directory(Path: &str, Recursive: bool) -> Result<()> {
}

#[Bind_function_native(Prefix = "File_system")]
fn Delete(Path: &str, Recursive: bool) -> Result<()> {
fn Delete(Path: &str, Recursive: bool) -> Result_type<()> {
let Path = New_path(Path)?;

Get_virtual_file_system().Delete(Path, Recursive)?;
Expand All @@ -155,7 +148,7 @@ fn Delete(Path: &str, Recursive: bool) -> Result<()> {
}

#[Bind_function_native(Prefix = "File_system")]
fn Exists(Path: &str, Exists: &mut bool) -> Result<()> {
fn Exists(Path: &str, Exists: &mut bool) -> Result_type<()> {
let Path = New_path(Path)?;

*Exists = Get_virtual_file_system().Exists(Path)?;
Expand Down
4 changes: 2 additions & 2 deletions Modules/Bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pub use File_system::*;
mod Task;
pub use Task::*;

mod Graphics;
pub use Graphics::*;
//mod Graphics;
//pub use Graphics::*;
Loading
Loading