diff --git a/Modules/ABI/src/Time.rs b/Modules/ABI/src/Time.rs index ee27b68..8a931c7 100644 --- a/Modules/ABI/src/Time.rs +++ b/Modules/ABI/src/Time.rs @@ -12,6 +12,9 @@ use Time::Get_instance; #[no_mangle] pub unsafe extern "C" fn Xila_instant_since_startup_microseconds(Results: *mut u128) { unsafe { - *Results = Get_instance().Get_current_time_since_startup().as_micros(); + *Results = Get_instance() + .Get_current_time_since_startup() + .unwrap_or_default() + .As_microseconds(); } } diff --git a/Modules/File_system/Cargo.toml b/Modules/File_system/Cargo.toml index 4c7c10b..be34872 100644 --- a/Modules/File_system/Cargo.toml +++ b/Modules/File_system/Cargo.toml @@ -10,7 +10,6 @@ Shared = { path = "../Shared" } [dev-dependencies] Drivers = { path = "../Drivers" } -Time = { path = "../Time" } [features] std = [] diff --git a/Modules/File_system/src/Error.rs b/Modules/File_system/src/Error.rs index b234f5c..8e5fb5f 100644 --- a/Modules/File_system/src/Error.rs +++ b/Modules/File_system/src/Error.rs @@ -2,7 +2,7 @@ use std::{num::NonZeroU32, sync::PoisonError}; pub type Result_type = std::result::Result; -#[derive(Debug, PartialEq, Clone, Copy)] +#[derive(Debug, PartialEq, Clone, Copy, Eq)] #[repr(C)] pub enum Error_type { Failed_to_initialize_file_system = 1, @@ -43,6 +43,7 @@ pub enum Error_type { Corrupted, No_memory, No_space_left, + Time_error, Other, } diff --git a/Modules/File_system/src/Time.rs b/Modules/File_system/src/Time.rs index db85957..734b68b 100644 --- a/Modules/File_system/src/Time.rs +++ b/Modules/File_system/src/Time.rs @@ -1,4 +1,4 @@ -use std::time::Duration; +use Shared::Duration_type; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] @@ -12,16 +12,16 @@ impl Time_type { } } -impl From for Time_type { - fn from(Duration: Duration) -> Self { +impl From for Time_type { + fn from(Duration: Duration_type) -> Self { Self { - Seconds: Duration.as_secs(), + Seconds: Duration.As_seconds(), } } } -impl From for Duration { +impl From for Duration_type { fn from(Time: Time_type) -> Self { - Self::from_secs(Time.Seconds) + Duration_type::New(Time.Seconds, 0) } } diff --git a/Modules/Graphics/src/Manager.rs b/Modules/Graphics/src/Manager.rs index de2c98b..48bf548 100644 --- a/Modules/Graphics/src/Manager.rs +++ b/Modules/Graphics/src/Manager.rs @@ -44,7 +44,10 @@ impl Drop for Manager_type { } extern "C" fn Binding_tick_callback_function() -> u32 { - Time::Get_instance().Get_current_time().as_millis() as u32 + Time::Get_instance() + .Get_current_time() + .unwrap_or_default() + .As_milliseconds() as u32 } impl Manager_type { diff --git a/Modules/LittleFS/src/File.rs b/Modules/LittleFS/src/File.rs index 52eab74..48dedb4 100644 --- a/Modules/LittleFS/src/File.rs +++ b/Modules/LittleFS/src/File.rs @@ -62,7 +62,10 @@ impl File_type { Cache_size: usize, ) -> Result_type { // - Create or get the metadata - let Current_time: Time_type = Time::Get_instance().Get_current_time().into(); + let Current_time: Time_type = Time::Get_instance() + .Get_current_time() + .map_err(|_| Error_type::Time_error)? + .into(); let Metadata = if Flags.Get_open().Get_create() { Metadata_type::Get_default(Task, Type_type::File, Current_time) diff --git a/Modules/LittleFS/src/File_system.rs b/Modules/LittleFS/src/File_system.rs index 039cd89..fd364e3 100644 --- a/Modules/LittleFS/src/File_system.rs +++ b/Modules/LittleFS/src/File_system.rs @@ -362,10 +362,10 @@ impl File_system_traits for File_system_type { let (File_system, Open_files, Open_directories) = Self::Borrow_mutable_inner_2_splited(&mut Inner); - let Current_time: Time_type = Time::Get_instance().Get_current_time().into(); - // TODO : Find a way to get the metadata of the directories if Open_directories.get_mut(&File).is_some() { + let Current_time: Time_type = Time::Get_instance().Get_current_time().unwrap().into(); + Ok(Statistics_type::New( File_system_identifier_type::New(0), Inode_type::New(0), @@ -476,7 +476,10 @@ impl File_system_traits for File_system_type { Directory_type::Create_directory(&mut Inner.File_system, Path)?; - let Current_time: Time_type = Time::Get_instance().Get_current_time().into(); + let Current_time: Time_type = Time::Get_instance() + .Get_current_time() + .map_err(|_| Error_type::Time_error)? + .into(); let Metadata = Metadata_type::Get_default(Task, Type_type::Directory, Current_time) .ok_or(Error_type::Invalid_parameter)?; @@ -534,7 +537,7 @@ mod Tests { use std::sync::Arc; - use File_system::Tests::Memory_device_type; + use File_system::{Create_device, Tests::Memory_device_type}; use super::*; @@ -549,7 +552,7 @@ mod Tests { let _ = Task::Get_instance().Register_task(); } - let _ = Time::Initialize(Box::new(Drivers::Native::Time_driver_type::New())); + let _ = Time::Initialize(Create_device!(Drivers::Native::Time_driver_type::New())); let Mock_device = Memory_device_type::<512>::New(2048 * 512); diff --git a/Modules/Virtual_file_system/Tests/Integration.rs b/Modules/Virtual_file_system/Tests/Integration.rs index b8f3230..3457624 100644 --- a/Modules/Virtual_file_system/Tests/Integration.rs +++ b/Modules/Virtual_file_system/Tests/Integration.rs @@ -19,7 +19,7 @@ fn Initialize() -> (Task_identifier_type, Virtual_file_system_type) { let _ = Users::Initialize(); - let _ = Time::Initialize(Box::new(Drivers::Native::Time_driver_type::New())); + let _ = Time::Initialize(Create_device!(Drivers::Native::Time_driver_type::New())); let Task = Task_instance .Get_current_task_identifier() diff --git a/Modules/Virtual_file_system/src/File_system.rs b/Modules/Virtual_file_system/src/File_system.rs index d5cc452..f606601 100644 --- a/Modules/Virtual_file_system/src/File_system.rs +++ b/Modules/Virtual_file_system/src/File_system.rs @@ -547,7 +547,10 @@ impl Virtual_file_system_type { Type_type::Character_device }; - let Current_time: Time_type = Time::Get_instance().Get_current_time().into(); + let Current_time: Time_type = Time::Get_instance() + .Get_current_time() + .map_err(|_| Error_type::Time_error)? + .into(); // Set the metadata of the special file. let mut Metadata = Metadata_type::Get_default(Task, Type, Current_time) @@ -579,7 +582,10 @@ impl Virtual_file_system_type { let Inode = self.Pipe_file_system.Create_named_pipe(Size)?; - let Current_time: Time_type = Time::Get_instance().Get_current_time().into(); + let Current_time: Time_type = Time::Get_instance() + .Get_current_time() + .map_err(|_| Error_type::Time_error)? + .into(); let mut Metadata = Metadata_type::Get_default(Task, Type_type::Pipe, Current_time) .ok_or(Error_type::Invalid_parameter)?; diff --git a/Modules/Virtual_machine/Tests/Test.rs b/Modules/Virtual_machine/Tests/Test.rs index 1991f28..9f48c5a 100644 --- a/Modules/Virtual_machine/Tests/Test.rs +++ b/Modules/Virtual_machine/Tests/Test.rs @@ -86,7 +86,7 @@ fn Integration_test() { Users::Initialize().expect("Failed to initialize users manager"); - Time::Initialize(Box::new(Drivers::Native::Time_driver_type::New())) + Time::Initialize(Create_device!(Drivers::Native::Time_driver_type::New())) .expect("Failed to initialize time manager"); let Device = Create_device!(Memory_device_type::<512>::New(1024 * 512));