Skip to content

Commit 48330eb

Browse files
committed
uefi: fs: Add file times plumbing
- Add FileTimes implementation. Signed-off-by: Ayush Singh <[email protected]>
1 parent d9dba3a commit 48330eb

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

library/std/src/sys/fs/uefi.rs

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,28 @@ use crate::sys::unsupported;
1212
#[expect(dead_code)]
1313
const FILE_PERMISSIONS_MASK: u64 = r_efi::protocols::file::READ_ONLY;
1414

15+
const ZERO_TIME: r_efi::efi::Time = r_efi::efi::Time {
16+
year: 0,
17+
month: 0,
18+
day: 0,
19+
hour: 0,
20+
minute: 0,
21+
second: 0,
22+
nanosecond: 0,
23+
timezone: 0,
24+
daylight: 0,
25+
pad1: 0,
26+
pad2: 0,
27+
};
28+
1529
pub struct File(!);
1630

1731
#[derive(Clone)]
1832
pub struct FileAttr {
1933
attr: u64,
2034
size: u64,
35+
created: r_efi::efi::Time,
36+
times: FileTimes,
2137
}
2238

2339
pub struct ReadDir(!);
@@ -32,8 +48,11 @@ pub struct OpenOptions {
3248
create_new: bool,
3349
}
3450

35-
#[derive(Copy, Clone, Debug, Default)]
36-
pub struct FileTimes {}
51+
#[derive(Copy, Clone, Debug)]
52+
pub struct FileTimes {
53+
accessed: r_efi::efi::Time,
54+
modified: r_efi::efi::Time,
55+
}
3756

3857
#[derive(Clone, PartialEq, Eq, Debug)]
3958
// Bool indicates if file is readonly
@@ -60,15 +79,15 @@ impl FileAttr {
6079
}
6180

6281
pub fn modified(&self) -> io::Result<SystemTime> {
63-
unsupported()
82+
Ok(SystemTime::from_uefi(self.times.modified))
6483
}
6584

6685
pub fn accessed(&self) -> io::Result<SystemTime> {
67-
unsupported()
86+
Ok(SystemTime::from_uefi(self.times.accessed))
6887
}
6988

7089
pub fn created(&self) -> io::Result<SystemTime> {
71-
unsupported()
90+
Ok(SystemTime::from_uefi(self.created))
7291
}
7392
}
7493

@@ -92,8 +111,21 @@ impl FilePermissions {
92111
}
93112

94113
impl FileTimes {
95-
pub fn set_accessed(&mut self, _t: SystemTime) {}
96-
pub fn set_modified(&mut self, _t: SystemTime) {}
114+
pub fn set_accessed(&mut self, t: SystemTime) {
115+
self.accessed =
116+
t.to_uefi(self.accessed.timezone, self.accessed.daylight).expect("Invalid Time");
117+
}
118+
119+
pub fn set_modified(&mut self, t: SystemTime) {
120+
self.modified =
121+
t.to_uefi(self.modified.timezone, self.modified.daylight).expect("Invalid Time");
122+
}
123+
}
124+
125+
impl Default for FileTimes {
126+
fn default() -> Self {
127+
Self { modified: ZERO_TIME, accessed: ZERO_TIME }
128+
}
97129
}
98130

99131
impl FileType {

library/std/src/sys/pal/uefi/time.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ impl SystemTime {
7070
Self(system_time_internal::from_uefi(&t))
7171
}
7272

73-
#[expect(dead_code)]
7473
pub(crate) const fn to_uefi(self, timezone: i16, daylight: u8) -> Option<r_efi::efi::Time> {
7574
system_time_internal::to_uefi(&self.0, timezone, daylight)
7675
}

0 commit comments

Comments
 (0)