Skip to content

Commit 3ffb74b

Browse files
authored
Rollup merge of rust-lang#138269 - Ayush1325:uefi-fs-permission, r=joboet
uefi: fs: Implement FileType, FilePermissions and FileAttr - In UEFI, both FileType and FilePermissions are represented by the attr bitfield. - Using simple bools here since both are represented by a single bit. - Add `FILE_PERMISSION` mask for constructing attribute while change permissions. cc `@nicholasbishop`
2 parents 6a323ba + e0a9dd3 commit 3ffb74b

File tree

1 file changed

+35
-64
lines changed

1 file changed

+35
-64
lines changed

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

+35-64
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
use crate::ffi::OsString;
22
use crate::fmt;
3-
use crate::hash::{Hash, Hasher};
3+
use crate::hash::Hash;
44
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
55
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

11-
pub struct FileAttr(!);
14+
#[derive(Clone)]
15+
pub struct FileAttr {
16+
attr: u64,
17+
size: u64,
18+
}
1219

1320
pub struct ReadDir(!);
1421

@@ -20,42 +27,40 @@ pub struct OpenOptions {}
2027
#[derive(Copy, Clone, Debug, Default)]
2128
pub struct FileTimes {}
2229

23-
pub struct FilePermissions(!);
30+
#[derive(Clone, PartialEq, Eq, Debug)]
31+
// Bool indicates if file is readonly
32+
pub struct FilePermissions(bool);
2433

25-
pub struct FileType(!);
34+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
35+
// Bool indicates if directory
36+
pub struct FileType(bool);
2637

2738
#[derive(Debug)]
2839
pub struct DirBuilder {}
2940

3041
impl FileAttr {
3142
pub fn size(&self) -> u64 {
32-
self.0
43+
self.size
3344
}
3445

3546
pub fn perm(&self) -> FilePermissions {
36-
self.0
47+
FilePermissions::from_attr(self.attr)
3748
}
3849

3950
pub fn file_type(&self) -> FileType {
40-
self.0
51+
FileType::from_attr(self.attr)
4152
}
4253

4354
pub fn modified(&self) -> io::Result<SystemTime> {
44-
self.0
55+
unsupported()
4556
}
4657

4758
pub fn accessed(&self) -> io::Result<SystemTime> {
48-
self.0
59+
unsupported()
4960
}
5061

5162
pub fn created(&self) -> io::Result<SystemTime> {
52-
self.0
53-
}
54-
}
55-
56-
impl Clone for FileAttr {
57-
fn clone(&self) -> FileAttr {
58-
self.0
63+
unsupported()
5964
}
6065
}
6166

@@ -64,28 +69,17 @@ 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+
const fn from_attr(attr: u64) -> Self {
77+
Self(attr & r_efi::protocols::file::READ_ONLY != 0)
7578
}
76-
}
77-
78-
impl PartialEq for FilePermissions {
79-
fn eq(&self, _other: &FilePermissions) -> bool {
80-
self.0
81-
}
82-
}
8379

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
80+
#[expect(dead_code)]
81+
const fn to_attr(&self) -> u64 {
82+
if self.0 { r_efi::protocols::file::READ_ONLY } else { 0 }
8983
}
9084
}
9185

@@ -100,39 +94,16 @@ impl FileType {
10094
}
10195

10296
pub fn is_file(&self) -> bool {
103-
self.0
97+
!self.is_dir()
10498
}
10599

100+
// Symlinks are not supported in UEFI
106101
pub fn is_symlink(&self) -> bool {
107-
self.0
108-
}
109-
}
110-
111-
impl Clone for FileType {
112-
fn clone(&self) -> FileType {
113-
self.0
102+
false
114103
}
115-
}
116-
117-
impl Copy for FileType {}
118104

119-
impl PartialEq for FileType {
120-
fn eq(&self, _other: &FileType) -> bool {
121-
self.0
122-
}
123-
}
124-
125-
impl Eq for FileType {}
126-
127-
impl Hash for FileType {
128-
fn hash<H: Hasher>(&self, _h: &mut H) {
129-
self.0
130-
}
131-
}
132-
133-
impl fmt::Debug for FileType {
134-
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
135-
self.0
105+
const fn from_attr(attr: u64) -> Self {
106+
Self(attr & r_efi::protocols::file::DIRECTORY != 0)
136107
}
137108
}
138109

@@ -303,8 +274,8 @@ pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
303274
unsupported()
304275
}
305276

306-
pub fn set_perm(_p: &Path, perm: FilePermissions) -> io::Result<()> {
307-
match perm.0 {}
277+
pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
278+
unsupported()
308279
}
309280

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

0 commit comments

Comments
 (0)