Skip to content

Commit dbbf9c8

Browse files
committed
Implement device mounting for graphical and command line shells, add shortcut handling, and update user/group paths
1 parent ef34392 commit dbbf9c8

File tree

22 files changed

+446
-123
lines changed

22 files changed

+446
-123
lines changed

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",

Drive

12.9 MB
Binary file not shown.

Examples/Native.rs

+81-37
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,13 +18,19 @@ 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
@@ -45,50 +51,88 @@ 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+
Graphical_shell::Shell_executable_type,
101+
Command_line_shell::Shell_executable_type,
102+
Terminal::Terminal_executable_type,
103+
WASM::WASM_device_type
104+
]
105+
)
106+
.unwrap();
107+
67108
// - Execute the shell
68109
// - - 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();
110+
let Standard = Standard_type::Open(
111+
&"/Devices/Standard_in",
112+
&"/Devices/Standard_out",
113+
&"/Devices/Standard_error",
114+
Task,
115+
Virtual_file_system::Get_instance(),
116+
)
117+
.unwrap();
72118

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

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();
122+
let _ = Authentication::Create_group(
123+
Virtual_file_system::Get_instance(),
124+
"alix_anneraud",
125+
Some(Group_identifier),
126+
);
84127

85-
let Standard = Standard_type::New(
86-
Standard_in,
87-
Standard_out,
88-
Standard_error,
89-
Task,
128+
let _ = Authentication::Create_user(
90129
Virtual_file_system::Get_instance(),
130+
"alix_anneraud",
131+
"password",
132+
Group_identifier,
133+
None,
91134
);
135+
92136
// - - Set the environment variables
93137
Task::Get_instance()
94138
.Set_environment_variable(Task, "Paths", "/")
@@ -98,7 +142,7 @@ fn main() {
98142
.Set_environment_variable(Task, "Host", "xila")
99143
.unwrap();
100144
// - - Execute the shell
101-
let _ = Executable::Execute("/Shell", "".to_string(), Standard)
145+
let _ = Executable::Execute("/Binaries/Graphical_shell", "".to_string(), Standard)
102146
.unwrap()
103147
.Join()
104148
.unwrap();

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<()> {
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use File_system::Device_trait;
2+
use Task::Task_identifier_type;
3+
use Virtual_file_system::Virtual_file_system_type;
4+
5+
pub trait Device_executable_trait: Device_trait {
6+
fn Mount<'a>(
7+
Virtual_file_system: &'a Virtual_file_system_type<'a>,
8+
Task: Task_identifier_type,
9+
) -> Result<(), String>;
10+
}
11+
12+
#[macro_export]
13+
macro_rules! Mount_static_executables {
14+
15+
( $Virtual_file_system:expr, $Task_identifier:expr, &[ $( ($Path:expr, $Device:expr) ),* $(,)? ] ) => {
16+
17+
|| -> Result<(), File_system::Error_type>
18+
{
19+
use File_system::Create_device;
20+
21+
$(
22+
$Virtual_file_system.Mount_static_device($Task_identifier, $Path, Create_device!($Device))?;
23+
$Virtual_file_system.Set_permissions($Task_identifier, $Path, Permissions_type::Executable )?;
24+
)*
25+
26+
27+
28+
Ok(())
29+
}()
30+
};
31+
32+
}

Modules/Executable/src/Standard.rs

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use File_system::{File_identifier_type, Size_type, Unique_file_identifier_type};
1+
use File_system::{
2+
File_identifier_type, Mode_type, Path_type, Size_type, Unique_file_identifier_type,
3+
};
24
use Task::Task_identifier_type;
35
use Virtual_file_system::Virtual_file_system_type;
46

@@ -25,6 +27,31 @@ impl Drop for Standard_type {
2527
}
2628

2729
impl Standard_type {
30+
pub fn Open(
31+
Standard_in: &impl AsRef<Path_type>,
32+
Standard_out: &impl AsRef<Path_type>,
33+
Standard_error: &impl AsRef<Path_type>,
34+
Task: Task_identifier_type,
35+
Virtual_file_system: &'static Virtual_file_system_type,
36+
) -> Result_type<Self> {
37+
let Standard_in =
38+
Virtual_file_system.Open(Standard_in, Mode_type::Read_only.into(), Task)?;
39+
40+
let Standard_out =
41+
Virtual_file_system.Open(Standard_out, Mode_type::Write_only.into(), Task)?;
42+
43+
let Standard_error =
44+
Virtual_file_system.Open(Standard_error, Mode_type::Write_only.into(), Task)?;
45+
46+
Ok(Self::New(
47+
Standard_in,
48+
Standard_out,
49+
Standard_error,
50+
Task,
51+
Virtual_file_system,
52+
))
53+
}
54+
2855
pub fn New(
2956
Standard_in: Unique_file_identifier_type,
3057
Standard_out: Unique_file_identifier_type,

Modules/Executable/src/lib.rs

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

5+
mod Device_trait;
56
mod Error;
67
mod Read_data;
78
mod Standard;
89

10+
pub use Device_trait::*;
911
pub use Error::*;
1012
pub use Read_data::*;
1113
pub use Standard::*;

Modules/Executables/Shell/Command_line/src/Device.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
1-
use Executable::Read_data_type;
2-
use File_system::Device_trait;
1+
use Executable::{Device_executable_trait, Read_data_type};
2+
use File_system::{Create_device, Device_trait};
3+
use Task::Task_identifier_type;
4+
use Virtual_file_system::Virtual_file_system_type;
35

46
use crate::Main::Main;
57

68
pub struct Shell_executable_type;
79

10+
impl Device_executable_trait for Shell_executable_type {
11+
fn Mount<'a>(
12+
Virtual_file_system: &'a Virtual_file_system_type<'a>,
13+
Task: Task_identifier_type,
14+
) -> Result<(), String> {
15+
Virtual_file_system
16+
.Mount_static_device(
17+
Task,
18+
&"/Binaries/Command_line_shell",
19+
Create_device!(Shell_executable_type),
20+
)
21+
.map_err(|Error| Error.to_string())?;
22+
23+
Ok(())
24+
}
25+
}
26+
827
impl Device_trait for Shell_executable_type {
928
fn Read(&self, Buffer: &mut [u8]) -> File_system::Result_type<File_system::Size_type> {
1029
let Read_data: &mut Read_data_type = Buffer

Modules/Executables/Shell/Graphical/Cargo.toml

-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ Shared = { path = "../../../Shared" }
1414
Time = { path = "../../../Time" }
1515
Authentication = { path = "../../../Authentication" }
1616
miniserde = "0.1"
17-
Command_line_shell = { path = "../Command_line" }
1817

1918
[dev-dependencies]
2019
Drivers = { path = "../../../Drivers" }
2120
Time = { path = "../../../Time" }
2221
LittleFS = { path = "../../../LittleFS" }
23-
Terminal = { path = "../../Terminal" }
2422

2523
[[test]]
2624
name = "Integration_test"

Modules/Executables/Shell/Graphical/Tests/Integration_test.rs

+24-20
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fn main() {
1313
use Drivers::Native::Window_screen;
1414
use File_system::{Flags_type, Open_type, Permissions_type};
1515
use Graphics::{Get_minimal_buffer_size, Input_type_type, Point_type};
16-
use Terminal::Terminal_executable_type;
1716
use Users::Group_identifier_type;
17+
1818
use Virtual_file_system::File_type;
1919

2020
// - Initialize the task manager.
@@ -106,27 +106,31 @@ fn main() {
106106
)
107107
.unwrap();
108108

109-
Virtual_file_system::Get_instance()
110-
.Mount_static_device(
111-
Task,
112-
&"/Binaries/Terminal",
113-
Create_device!(Terminal_executable_type),
109+
// Add fake shortcuts.
110+
for i in 0..20 {
111+
File_type::Open(
112+
Virtual_file_system::Get_instance(),
113+
format!("/Configuration/Graphical_shell/Shortcuts/Test{}.json", i).as_str(),
114+
Flags_type::New(Mode_type::Write_only, Some(Open_type::Create), None),
115+
)
116+
.unwrap()
117+
.Write(
118+
format!(
119+
r#"
120+
{{
121+
"Name": "Test{}",
122+
"Command": "/Binaries/?",
123+
"Arguments": "",
124+
"Terminal": false,
125+
"Icon_string": "T!"
126+
}}
127+
"#,
128+
i
129+
)
130+
.as_bytes(),
114131
)
115132
.unwrap();
116-
117-
Virtual_file_system::Get_instance()
118-
.Set_permissions("/Binaries/Terminal", Permissions_type::Executable)
119-
.unwrap();
120-
121-
// Write terminal shortcut.
122-
File_type::Open(
123-
Virtual_file_system::Get_instance(),
124-
"/Configuration/Graphical_shell/Shortcuts/Terminal",
125-
Flags_type::New(Mode_type::Write_only, Some(Open_type::Create), None),
126-
)
127-
.unwrap()
128-
.Write(Terminal::Shortcut.as_bytes())
129-
.unwrap();
133+
}
130134

131135
let Group_identifier = Group_identifier_type::New(1000);
132136

0 commit comments

Comments
 (0)