Skip to content

Commit 1833737

Browse files
committed
uefi: fs: Implement FilePermission
- UEFI file permissions are indicated using a u64 bitfield used for readonly/filetype, etc. - Using normal bool with to and from attribute conversions to FilePermission from overriding some other bitfields. Signed-off-by: Ayush Singh <[email protected]>
1 parent 2b4694a commit 1833737

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

Diff for: library/std/src/sys/fs/uefi.rs

+16-21
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use crate::path::{Path, PathBuf};
66
use crate::sys::time::SystemTime;
77
use crate::sys::unsupported;
88

9+
#[expect(dead_code)]
10+
const FILE_PERMISSIONS_MASK: u64 = r_efi::protocols::file::READ_ONLY;
11+
912
pub struct File(!);
1013

1114
pub struct FileAttr(!);
@@ -20,7 +23,9 @@ pub struct OpenOptions {}
2023
#[derive(Copy, Clone, Debug, Default)]
2124
pub struct FileTimes {}
2225

23-
pub struct FilePermissions(!);
26+
#[derive(Clone, PartialEq, Eq, Debug)]
27+
// Bool indicates if file is readonly
28+
pub struct FilePermissions(bool);
2429

2530
pub struct FileType(!);
2631

@@ -64,28 +69,18 @@ impl FilePermissions {
6469
self.0
6570
}
6671

67-
pub fn set_readonly(&mut self, _readonly: bool) {
68-
self.0
72+
pub fn set_readonly(&mut self, readonly: bool) {
73+
self.0 = readonly
6974
}
70-
}
7175

72-
impl Clone for FilePermissions {
73-
fn clone(&self) -> FilePermissions {
74-
self.0
76+
#[expect(dead_code)]
77+
const fn from_attr(attr: u64) -> Self {
78+
Self(attr & r_efi::protocols::file::READ_ONLY != 0)
7579
}
76-
}
7780

78-
impl PartialEq for FilePermissions {
79-
fn eq(&self, _other: &FilePermissions) -> bool {
80-
self.0
81-
}
82-
}
83-
84-
impl Eq for FilePermissions {}
85-
86-
impl fmt::Debug for FilePermissions {
87-
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
88-
self.0
81+
#[expect(dead_code)]
82+
const fn to_attr(&self) -> u64 {
83+
if self.0 { r_efi::protocols::file::READ_ONLY } else { 0 }
8984
}
9085
}
9186

@@ -303,8 +298,8 @@ pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
303298
unsupported()
304299
}
305300

306-
pub fn set_perm(_p: &Path, perm: FilePermissions) -> io::Result<()> {
307-
match perm.0 {}
301+
pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
302+
unsupported()
308303
}
309304

310305
pub fn rmdir(_p: &Path) -> io::Result<()> {

0 commit comments

Comments
 (0)