Skip to content

Commit d3d17fe

Browse files
authored
Feature/Graphical shell (#57)
* Add Null device implementation for file system operations * Add Shortcut module and enhance file system interactions * Implement device mounting for graphical and command line shells, add shortcut handling, and update user/group paths * Refactor device handling, update shortcut structure, and enhance error reporting * Refactor integration tests to use new mounting functions and update shortcut paths * Update function return types to use Vec<WasmValue> for better handling of multiple values * Update integration tests to assert array return types for WasmValue * Update test to use .img file extension for drive device * Update workflow to use apt update before installing gcc-multilib * Fix workflow to use sudo for installing gcc-multilib
1 parent 03f55ac commit d3d17fe

File tree

45 files changed

+1095
-210
lines changed

Some content is hidden

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

45 files changed

+1095
-210
lines changed

.github/workflows/Check.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
ldproxy: true
4949

5050
- name: Setup | Install necessary dependencies
51-
run: sudo apt-get install -y gcc-multilib
51+
run: sudo apt update && sudo apt install -y gcc-multilib
5252

5353
- name: Setup | Build and source build tool
5454
run: source Export.sh

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
/.embuild
33
/target
44
Cargo.lock
5-
/Garbage
5+
/Garbage
6+
7+
*.img

Cargo.toml

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ Command_line_shell = { path = "Modules/Executables/Shell/Command_line", optional
2424
Executable = { path = "Modules/Executable", optional = true }
2525
File_system = { path = "Modules/File_system", optional = true }
2626
Host_bindings = { path = "Modules/Bindings/Host", optional = true }
27+
Graphical_shell = { path = "Modules/Executables/Shell/Graphical", optional = true }
28+
Terminal = { path = "Modules/Executables/Terminal", optional = true }
29+
Authentication = { path = "Modules/Authentication", optional = true }
2730

2831
[build-dependencies]
2932
Target = { path = "Modules/Target", optional = true }
@@ -47,6 +50,9 @@ Host = [
4750
"dep:Executable",
4851
"dep:File_system",
4952
"dep:Host_bindings",
53+
"dep:Graphical_shell",
54+
"dep:Terminal",
55+
"dep:Authentication",
5056
]
5157
WASM = ["dep:WASM_bindings"]
5258

@@ -78,7 +84,7 @@ members = [
7884
"Modules/Executables/WASM",
7985
"Modules/Executables/Shell/Graphical",
8086
"Modules/Executables/Terminal",
81-
"Modules/Authentication"
87+
"Modules/Authentication",
8288
]
8389
exclude = [
8490
"Modules/Virtual_machine/Tests/WASM_test",

Examples/Native.rs

+92-38
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#![allow(non_snake_case)]
33
#![allow(non_upper_case_globals)]
44

5-
use Command_line_shell::Shell_executable_type;
5+
use Executable::Mount_static_executables;
66
use Executable::Standard_type;
7-
use File_system::{Create_device, Create_file_system, Mode_type};
8-
use WASM::WASM_device_type;
7+
use File_system::{Create_device, Create_file_system};
8+
use Virtual_file_system::Mount_static_devices;
99

1010
fn main() {
1111
// - Initialize the system
@@ -18,18 +18,24 @@ fn main() {
1818
// - Initialize the graphics manager
1919
// - - Initialize the graphics driver
2020
const Resolution: Graphics::Point_type = Graphics::Point_type::New(800, 600);
21-
let (Screen, Pointer) = Drivers::Native::Window_screen::New(Resolution).unwrap();
21+
let (Screen_device, Pointer_device, Keyboard_device) =
22+
Drivers::Native::Window_screen::New(Resolution).unwrap();
2223
// - - Initialize the graphics manager
23-
Graphics::Initialize();
24-
// - - Add a screen
25-
const Buffer_size: usize = Graphics::Get_recommended_buffer_size(&Resolution);
26-
let _ = Graphics::Get_instance()
27-
.Create_display::<Buffer_size>(Screen, Pointer, true)
24+
Graphics::Initialize(
25+
Screen_device,
26+
Pointer_device,
27+
Graphics::Input_type_type::Pointer,
28+
Graphics::Get_minimal_buffer_size(&Resolution),
29+
true,
30+
);
31+
32+
Graphics::Get_instance()
33+
.Add_input_device(Keyboard_device, Graphics::Input_type_type::Keypad)
2834
.unwrap();
2935

3036
// - Initialize the file system
3137
// Create a memory device
32-
let Drive = Create_device!(Drivers::Native::File_drive_device_type::New(&"./Drive"));
38+
let Drive = Create_device!(Drivers::Native::File_drive_device_type::New(&"./Drive.img"));
3339
// Mount the file system
3440
let File_system = match LittleFS::File_system_type::New(Drive.clone(), 256) {
3541
Ok(File_system) => File_system,
@@ -45,50 +51,98 @@ fn main() {
4551
}
4652
};
4753
// Initialize the virtual file system
48-
Virtual_file_system::Initialize(Create_file_system!(File_system));
54+
Virtual_file_system::Initialize(Create_file_system!(File_system)).unwrap();
4955

5056
// - - Mount the devices
5157
let Task = Task::Get_instance().Get_current_task_identifier().unwrap();
5258

53-
Virtual_file_system::Get_instance()
54-
.Mount_static_device(Task, &"/Shell", Create_device!(Shell_executable_type))
55-
.unwrap();
59+
// - - Create the default system hierarchy
60+
let _ =
61+
Virtual_file_system::Create_default_hierarchy(Virtual_file_system::Get_instance(), Task);
5662

57-
Virtual_file_system::Get_instance()
58-
.Mount_static_device(Task, &"/WASM", Create_device!(WASM_device_type))
59-
.unwrap();
63+
// - - Mount the devices
64+
Virtual_file_system::Clean_devices(Virtual_file_system::Get_instance()).unwrap();
6065

61-
let _ = Virtual_file_system::Get_instance().Create_directory(&"/Devices", Task);
66+
Mount_static_devices!(
67+
Virtual_file_system::Get_instance(),
68+
Task,
69+
&[
70+
(
71+
&"/Devices/Standard_in",
72+
Drivers::Native::Console::Standard_in_device_type
73+
),
74+
(
75+
&"/Devices/Standard_out",
76+
Drivers::Native::Console::Standard_out_device_type
77+
),
78+
(
79+
&"/Devices/Standard_error",
80+
Drivers::Native::Console::Standard_error_device_type
81+
),
82+
(&"/Devices/Time", Drivers::Native::Time_driver_type),
83+
(&"/Devices/Random", Drivers::Native::Random_device_type),
84+
(&"/Devices/Null", Drivers::Common::Null_device_type)
85+
]
86+
)
87+
.unwrap();
6288

63-
Drivers::Native::Console::Mount_devices(Task, Virtual_file_system::Get_instance()).unwrap();
6489
// Initialize the virtual machine
6590
Virtual_machine::Initialize(&[&Host_bindings::Graphics_bindings]);
6691

92+
// Mount static executables
93+
94+
let Virtual_file_system = Virtual_file_system::Get_instance();
95+
96+
Mount_static_executables!(
97+
Virtual_file_system,
98+
Task,
99+
&[
100+
(
101+
&"/Binaries/Graphical_shell",
102+
Graphical_shell::Shell_executable_type
103+
),
104+
(
105+
&"/Binaries/Command_line_shell",
106+
Command_line_shell::Shell_executable_type
107+
),
108+
(
109+
&"/Binaries/Terminal",
110+
Terminal::Terminal_executable_type::New(Virtual_file_system::Get_instance(), Task)
111+
.unwrap()
112+
),
113+
(&"/Binaries/WASM", WASM::WASM_device_type)
114+
]
115+
)
116+
.unwrap();
117+
67118
// - Execute the shell
68119
// - - Open the standard input, output and error
69-
let Standard_in = Virtual_file_system::Get_instance()
70-
.Open(&"/Devices/Standard_in", Mode_type::Read_only.into(), Task)
71-
.unwrap();
120+
let Standard = Standard_type::Open(
121+
&"/Devices/Standard_in",
122+
&"/Devices/Standard_out",
123+
&"/Devices/Standard_error",
124+
Task,
125+
Virtual_file_system::Get_instance(),
126+
)
127+
.unwrap();
72128

73-
let Standard_out = Virtual_file_system::Get_instance()
74-
.Open(&"/Devices/Standard_out", Mode_type::Write_only.into(), Task)
75-
.unwrap();
129+
// - - Create the default user
130+
let Group_identifier = Users::Group_identifier_type::New(1000);
76131

77-
let Standard_error = Virtual_file_system::Get_instance()
78-
.Open(
79-
&"/Devices/Standard_error",
80-
Mode_type::Write_only.into(),
81-
Task,
82-
)
83-
.unwrap();
132+
let _ = Authentication::Create_group(
133+
Virtual_file_system::Get_instance(),
134+
"alix_anneraud",
135+
Some(Group_identifier),
136+
);
84137

85-
let Standard = Standard_type::New(
86-
Standard_in,
87-
Standard_out,
88-
Standard_error,
89-
Task,
138+
let _ = Authentication::Create_user(
90139
Virtual_file_system::Get_instance(),
140+
"alix_anneraud",
141+
"password",
142+
Group_identifier,
143+
None,
91144
);
145+
92146
// - - Set the environment variables
93147
Task::Get_instance()
94148
.Set_environment_variable(Task, "Paths", "/")
@@ -98,7 +152,7 @@ fn main() {
98152
.Set_environment_variable(Task, "Host", "xila")
99153
.unwrap();
100154
// - - Execute the shell
101-
let _ = Executable::Execute("/Shell", "".to_string(), Standard)
155+
let _ = Executable::Execute("/Binaries/Graphical_shell", "".to_string(), Standard)
102156
.unwrap()
103157
.Join()
104158
.unwrap();

Modules/ABI/src/File_system.rs

-6
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,7 @@ pub unsafe extern "C" fn Xila_file_system_get_statistics(
7676
File: Unique_file_identifier_type,
7777
Statistics: *mut Statistics_type,
7878
) -> u32 {
79-
println!("Getting file statistics : {:?}", File);
80-
8179
Into_u32(move || {
82-
println!("Getting file statistics : {:?}", File);
83-
8480
let Task_identifier = Get_task_manager_instance()
8581
.Get_current_task_identifier()
8682
.map_err(|_| Error_type::Failed_to_get_task_informations)?;
@@ -92,8 +88,6 @@ pub unsafe extern "C" fn Xila_file_system_get_statistics(
9288
.Get_statistics(File, Task_identifier)
9389
.expect("Failed to get file statistics.");
9490

95-
println!("Statistics : {:?}", *Statistics);
96-
9791
Ok(())
9892
})
9993
}

Modules/Authentication/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ Users = { path = "../Users" }
99
Task = { path = "../Task" }
1010
File_system = { path = "../File_system" }
1111
sha2 = { version = "0.10", features = ["asm"] }
12-
miniserde = "0.1.41"
12+
miniserde = "0.1"

Modules/Authentication/src/Error.rs

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub enum Error_type {
1414
Failed_to_get_new_user_identifier(Users::Error_type),
1515
Failed_to_create_user(Users::Error_type),
1616
Failed_to_write_user_file(File_system::Error_type),
17+
Failed_to_create_users_directory(File_system::Error_type),
1718
Failed_to_read_group_directory(File_system::Error_type),
1819
Failed_to_get_group_file_path,
1920
Failed_to_open_group_file(File_system::Error_type),
@@ -23,6 +24,7 @@ pub enum Error_type {
2324
Failed_to_get_new_group_identifier(Users::Error_type),
2425
Failed_to_create_group(Users::Error_type),
2526
Failed_to_write_group_file(File_system::Error_type),
27+
Failed_to_create_groups_directory(File_system::Error_type),
2628
Invalid_password,
2729
Failed_to_open_random_device(File_system::Error_type),
2830
Failed_to_read_random_device(File_system::Error_type),
@@ -57,6 +59,9 @@ impl Display for Error_type {
5759
Self::Failed_to_add_user(Error) => {
5860
write!(Formatter, "Failed to add user: {}", Error)
5961
}
62+
Self::Failed_to_create_users_directory(Error) => {
63+
write!(Formatter, "Failed to create users directory: {}", Error)
64+
}
6065
Self::Failed_to_read_group_directory(Error) => {
6166
write!(Formatter, "Failed to read group directory: {}", Error)
6267
}
@@ -75,6 +80,9 @@ impl Display for Error_type {
7580
Self::Failed_to_add_group(Error) => {
7681
write!(Formatter, "Failed to add group: {}", Error)
7782
}
83+
Self::Failed_to_create_groups_directory(Error) => {
84+
write!(Formatter, "Failed to create group directory: {}", Error)
85+
}
7886
Self::Invalid_password => {
7987
write!(Formatter, "Invalid password")
8088
}

Modules/Authentication/src/Group.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Users::{
44
Group_identifier_inner_type, Group_identifier_type, User_identifier_inner_type,
55
User_identifier_type,
66
};
7-
use Virtual_file_system::{File_type, Virtual_file_system_type};
7+
use Virtual_file_system::{Directory_type, File_type, Virtual_file_system_type};
88

99
use crate::{Error_type, Group_folder_path, Result_type};
1010

@@ -104,6 +104,11 @@ pub fn Create_group<'a>(
104104
vec![],
105105
);
106106

107+
match Directory_type::Create(Virtual_file_system, Group_folder_path) {
108+
Ok(_) | Err(File_system::Error_type::Already_exists) => {}
109+
Err(Error) => Err(Error_type::Failed_to_create_groups_directory(Error))?,
110+
};
111+
107112
let Group_file_path = Get_group_file_path(Group_name)?;
108113

109114
let Group_file = File_type::Open(

Modules/Authentication/src/User.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Users::{
44
Group_identifier_inner_type, Group_identifier_type, User_identifier_inner_type,
55
User_identifier_type,
66
};
7-
use Virtual_file_system::{File_type, Virtual_file_system_type};
7+
use Virtual_file_system::{Directory_type, File_type, Virtual_file_system_type};
88

99
use crate::{
1010
Error_type,
@@ -145,6 +145,11 @@ pub fn Create_user<'a>(
145145
Salt,
146146
);
147147

148+
match Directory_type::Create(Virtual_file_system, Users_folder_path) {
149+
Ok(_) | Err(File_system::Error_type::Already_exists) => {}
150+
Err(Error) => Err(Error_type::Failed_to_create_users_directory(Error))?,
151+
}
152+
148153
let User_file_path = Path_type::New(Users_folder_path)
149154
.to_owned()
150155
.Append(User_name)

Modules/Authentication/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ pub use Error::*;
1111
pub use Group::*;
1212
pub use User::*;
1313

14-
const Users_folder_path: &str = "/Xila/Users";
15-
const Group_folder_path: &str = "/Xila/Groups";
14+
const Users_folder_path: &str = "/System/Users";
15+
const Group_folder_path: &str = "/System/Groups";
1616
const Random_device_path: &str = "/Devices/Random";
1717

1818
pub fn Load_all_users_and_groups() -> Result_type<()> {

Modules/Drivers/src/Common/Null.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use File_system::{Device_trait, Size_type};
2+
3+
pub struct Null_device_type;
4+
5+
impl Device_trait for Null_device_type {
6+
fn Read(&self, Buffer: &mut [u8]) -> File_system::Result_type<File_system::Size_type> {
7+
Ok(Size_type::New(Buffer.len() as u64))
8+
}
9+
10+
fn Write(&self, Buffer: &[u8]) -> File_system::Result_type<File_system::Size_type> {
11+
Ok(Size_type::New(Buffer.len() as u64))
12+
}
13+
14+
fn Get_size(&self) -> File_system::Result_type<File_system::Size_type> {
15+
Ok(Size_type::New(0))
16+
}
17+
18+
fn Set_position(
19+
&self,
20+
_: &File_system::Position_type,
21+
) -> File_system::Result_type<File_system::Size_type> {
22+
Ok(Size_type::New(0))
23+
}
24+
25+
fn Flush(&self) -> File_system::Result_type<()> {
26+
Ok(())
27+
}
28+
}

Modules/Drivers/src/Common/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
mod Null;
2+
3+
pub use Null::*;

Modules/Drivers/src/Native/Devices/Drive_file.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ mod Tests {
8585

8686
#[test]
8787
fn Test_read_write() {
88-
let File = File_drive_device_type::New(&"./Test");
88+
let File = File_drive_device_type::New(&"./Test.img");
8989

9090
let Data = [1, 2, 3, 4, 5];
9191

Modules/Drivers/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pub mod Espressif;
1111
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "windows"))]
1212
pub mod Native;
1313

14+
pub mod Common;
15+
1416
pub fn Mount_devices(
1517
Task: Task_identifier_type,
1618
Virtual_file_systems: &Virtual_file_system_type,

0 commit comments

Comments
 (0)