From 7754945c275b3c7d59a272aa5a61f65de2985045 Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Sat, 7 Dec 2024 12:57:26 +0200 Subject: [PATCH] alnyan/yggdrasil: sync with ABI updates --- library/std/src/os/yggdrasil/fs.rs | 18 +++++++- library/std/src/sys/pal/yggdrasil/fs/mod.rs | 12 ++++++ library/std/src/sys/pal/yggdrasil/time.rs | 47 ++++++++++----------- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/library/std/src/os/yggdrasil/fs.rs b/library/std/src/os/yggdrasil/fs.rs index 1aaa4d4dc6a..d9448f4d25e 100644 --- a/library/std/src/os/yggdrasil/fs.rs +++ b/library/std/src/os/yggdrasil/fs.rs @@ -1,16 +1,32 @@ #![unstable(feature = "yggdrasil_os", issue = "none")] +use yggdrasil_rt::io::FileMode; + use crate::fs::Metadata; use crate::sys_common::AsInner; -use yggdrasil_rt::io::FileMode; #[unstable(feature = "yggdrasil_os", issue = "none")] pub trait MetadataExt { fn mode_ext(&self) -> FileMode; + fn inode(&self) -> Option; + fn block_count(&self) -> u64; + fn block_size(&self) -> u64; } impl MetadataExt for Metadata { fn mode_ext(&self) -> FileMode { self.as_inner().mode_ext() } + + fn inode(&self) -> Option { + self.as_inner().inode() + } + + fn block_count(&self) -> u64 { + self.as_inner().block_count() + } + + fn block_size(&self) -> u64 { + self.as_inner().block_size() + } } diff --git a/library/std/src/sys/pal/yggdrasil/fs/mod.rs b/library/std/src/sys/pal/yggdrasil/fs/mod.rs index 6933114c423..ee2de9d744f 100644 --- a/library/std/src/sys/pal/yggdrasil/fs/mod.rs +++ b/library/std/src/sys/pal/yggdrasil/fs/mod.rs @@ -44,6 +44,18 @@ impl FileAttr { self.0.mode } + pub fn inode(&self) -> Option { + self.0.inode + } + + pub fn block_count(&self) -> u64 { + self.0.block_count + } + + pub fn block_size(&self) -> u64 { + self.0.block_size + } + pub fn modified(&self) -> io::Result { Err(crate::io::const_io_error!( crate::io::ErrorKind::Unsupported, diff --git a/library/std/src/sys/pal/yggdrasil/time.rs b/library/std/src/sys/pal/yggdrasil/time.rs index 5215762487a..f80e79c4584 100644 --- a/library/std/src/sys/pal/yggdrasil/time.rs +++ b/library/std/src/sys/pal/yggdrasil/time.rs @@ -1,26 +1,16 @@ #![allow(dead_code)] -use yggdrasil_rt::time::Timespec as SysTimespec; +use yggdrasil_rt::time::{self as rt, SystemTime as SysTimespec}; use crate::ops::{Add, AddAssign, Sub, SubAssign}; use crate::time::Duration; -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] -#[repr(transparent)] -struct Timespec(SysTimespec); - -impl Timespec { - pub const fn zero() -> Self { - Self(SysTimespec::ZERO) - } -} - #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] -pub struct Instant(Timespec); +pub struct Instant(SysTimespec); impl Instant { pub fn now() -> Self { - todo!() + Self(rt::get_monotonic_time().expect("Could not retrieve monotonic time value")) } pub fn elapsed(&self) -> Duration { @@ -35,8 +25,15 @@ impl Instant { todo!() } - pub fn checked_sub_instant(&self, _other: &Instant) -> Option { - todo!() + pub fn checked_sub_instant(&self, other: &Instant) -> Option { + let mut s = u64::checked_sub(self.0.seconds, other.0.seconds)?; + let ns = if self.0.nanoseconds >= other.0.nanoseconds { + self.0.nanoseconds - other.0.nanoseconds + } else { + s = u64::checked_sub(s, 1)?; + 1000000000 + self.0.nanoseconds - other.0.nanoseconds + }; + Some(Duration::new(s, ns as u32)) } pub fn checked_add_duration(&self, _other: &Duration) -> Option { @@ -60,41 +57,43 @@ impl Add for Instant { type Output = Instant; fn add(self, _other: Duration) -> Instant { - todo!() + todo!("Instant::add(duration)") } } impl AddAssign for Instant { fn add_assign(&mut self, _other: Duration) { - todo!() + todo!("Instant::add_assign(duration)") } } impl Sub for Instant { type Output = Instant; fn sub(self, _other: Duration) -> Instant { - todo!() + todo!("Instant:sub(duration)") } } impl SubAssign for Instant { - fn sub_assign(&mut self, _other: Duration) { - todo!() + fn sub_assign(&mut self, other: Duration) { + todo!("Instant::sub_assign(duration)") } } impl Sub for Instant { type Output = Duration; - fn sub(self, _other: Instant) -> Duration { - todo!() + fn sub(self, other: Instant) -> Duration { + let d0 = Duration::new(self.0.seconds, self.0.nanoseconds as _); + let d1 = Duration::new(other.0.seconds, other.0.nanoseconds as _); + Duration::saturating_sub(d0, d1) } } #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] -pub struct SystemTime(Timespec); +pub struct SystemTime(SysTimespec); -pub const UNIX_EPOCH: SystemTime = SystemTime(Timespec::zero()); +pub const UNIX_EPOCH: SystemTime = SystemTime(SysTimespec::ZERO); impl SystemTime { pub fn now() -> Self {