Skip to content

Commit e21995b

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

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub struct File(!);
1818
pub struct FileAttr {
1919
attr: u64,
2020
size: u64,
21+
created: r_efi::efi::Time,
22+
times: FileTimes,
2123
}
2224

2325
pub struct ReadDir(!);
@@ -33,7 +35,10 @@ pub struct OpenOptions {
3335
}
3436

3537
#[derive(Copy, Clone, Debug, Default)]
36-
pub struct FileTimes {}
38+
pub struct FileTimes {
39+
accessed: r_efi::efi::Time,
40+
modified: r_efi::efi::Time,
41+
}
3742

3843
#[derive(Clone, PartialEq, Eq, Debug)]
3944
// Bool indicates if file is readonly
@@ -60,15 +65,15 @@ impl FileAttr {
6065
}
6166

6267
pub fn modified(&self) -> io::Result<SystemTime> {
63-
unsupported()
68+
Ok(SystemTime::from_uefi(self.times.modified))
6469
}
6570

6671
pub fn accessed(&self) -> io::Result<SystemTime> {
67-
unsupported()
72+
Ok(SystemTime::from_uefi(self.times.accessed))
6873
}
6974

7075
pub fn created(&self) -> io::Result<SystemTime> {
71-
unsupported()
76+
Ok(SystemTime::from_uefi(self.created))
7277
}
7378
}
7479

@@ -92,8 +97,15 @@ impl FilePermissions {
9297
}
9398

9499
impl FileTimes {
95-
pub fn set_accessed(&mut self, _t: SystemTime) {}
96-
pub fn set_modified(&mut self, _t: SystemTime) {}
100+
pub fn set_accessed(&mut self, t: SystemTime) {
101+
self.accessed =
102+
t.to_uefi(self.accessed.timezone, self.accessed.daylight).expect("Invalid Time");
103+
}
104+
105+
pub fn set_modified(&mut self, t: SystemTime) {
106+
self.modified =
107+
t.to_uefi(self.modified.timezone, self.modified.daylight).expect("Invalid Time");
108+
}
97109
}
98110

99111
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)