1
1
use crate :: ffi:: OsString ;
2
2
use crate :: fmt;
3
- use crate :: hash:: { Hash , Hasher } ;
3
+ use crate :: hash:: Hash ;
4
4
use crate :: io:: { self , BorrowedCursor , IoSlice , IoSliceMut , SeekFrom } ;
5
5
use crate :: path:: { Path , PathBuf } ;
6
6
use crate :: sys:: time:: SystemTime ;
7
7
use crate :: sys:: unsupported;
8
8
9
+ #[ expect( dead_code) ]
10
+ const FILE_PERMISSIONS_MASK : u64 = r_efi:: protocols:: file:: READ_ONLY ;
11
+
9
12
pub struct File ( !) ;
10
13
11
- pub struct FileAttr ( !) ;
14
+ #[ derive( Clone ) ]
15
+ pub struct FileAttr {
16
+ attr : u64 ,
17
+ size : u64 ,
18
+ }
12
19
13
20
pub struct ReadDir ( !) ;
14
21
@@ -20,42 +27,40 @@ pub struct OpenOptions {}
20
27
#[ derive( Copy , Clone , Debug , Default ) ]
21
28
pub struct FileTimes { }
22
29
23
- pub struct FilePermissions ( !) ;
30
+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
31
+ // Bool indicates if file is readonly
32
+ pub struct FilePermissions ( bool ) ;
24
33
25
- pub struct FileType ( !) ;
34
+ #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
35
+ // Bool indicates if directory
36
+ pub struct FileType ( bool ) ;
26
37
27
38
#[ derive( Debug ) ]
28
39
pub struct DirBuilder { }
29
40
30
41
impl FileAttr {
31
42
pub fn size ( & self ) -> u64 {
32
- self . 0
43
+ self . size
33
44
}
34
45
35
46
pub fn perm ( & self ) -> FilePermissions {
36
- self . 0
47
+ FilePermissions :: from_attr ( self . attr )
37
48
}
38
49
39
50
pub fn file_type ( & self ) -> FileType {
40
- self . 0
51
+ FileType :: from_attr ( self . attr )
41
52
}
42
53
43
54
pub fn modified ( & self ) -> io:: Result < SystemTime > {
44
- self . 0
55
+ unsupported ( )
45
56
}
46
57
47
58
pub fn accessed ( & self ) -> io:: Result < SystemTime > {
48
- self . 0
59
+ unsupported ( )
49
60
}
50
61
51
62
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 ( )
59
64
}
60
65
}
61
66
@@ -64,28 +69,17 @@ impl FilePermissions {
64
69
self . 0
65
70
}
66
71
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
69
74
}
70
- }
71
75
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 )
75
78
}
76
- }
77
-
78
- impl PartialEq for FilePermissions {
79
- fn eq ( & self , _other : & FilePermissions ) -> bool {
80
- self . 0
81
- }
82
- }
83
79
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 }
89
83
}
90
84
}
91
85
@@ -100,39 +94,16 @@ impl FileType {
100
94
}
101
95
102
96
pub fn is_file ( & self ) -> bool {
103
- self . 0
97
+ ! self . is_dir ( )
104
98
}
105
99
100
+ // Symlinks are not supported in UEFI
106
101
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
114
103
}
115
- }
116
-
117
- impl Copy for FileType { }
118
104
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 )
136
107
}
137
108
}
138
109
@@ -303,8 +274,8 @@ pub fn rename(_old: &Path, _new: &Path) -> io::Result<()> {
303
274
unsupported ( )
304
275
}
305
276
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 ( )
308
279
}
309
280
310
281
pub fn rmdir ( _p : & Path ) -> io:: Result < ( ) > {
0 commit comments