Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 22f8caa

Browse files
authoredMar 23, 2025
Rollup merge of rust-lang#138662 - Ayush1325:uefi-fs-1, r=nicholasbishop,petrochenkov
Implement some basics in UEFI fs - Just getting some basics out of the way while waiting for rust-lang#138236 to be merged. - Adds `fs::canonicalize`. Should be same as absolute in case of UEFI since there is no symlink support and absolute path is guaranteed to be uniqe according to spec. - Make `fs::lstat` same as `fs::stat`. Should be same since UEFI does not have symlink support. - Implement `OptionOptions`. cc `@nicholasbishop` `@dvdhrm`
2 parents 51e1840 + 80229a2 commit 22f8caa

File tree

1 file changed

+61
-12
lines changed

1 file changed

+61
-12
lines changed
 

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

+61-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use r_efi::protocols::file;
2+
13
use crate::ffi::OsString;
24
use crate::fmt;
35
use crate::hash::Hash;
@@ -22,7 +24,12 @@ pub struct ReadDir(!);
2224
pub struct DirEntry(!);
2325

2426
#[derive(Clone, Debug)]
25-
pub struct OpenOptions {}
27+
pub struct OpenOptions {
28+
mode: u64,
29+
append: bool,
30+
truncate: bool,
31+
create_new: bool,
32+
}
2633

2734
#[derive(Copy, Clone, Debug, Default)]
2835
pub struct FileTimes {}
@@ -141,15 +148,57 @@ impl DirEntry {
141148

142149
impl OpenOptions {
143150
pub fn new() -> OpenOptions {
144-
OpenOptions {}
151+
OpenOptions { mode: 0, append: false, create_new: false, truncate: false }
152+
}
153+
154+
pub fn read(&mut self, read: bool) {
155+
if read {
156+
self.mode |= file::MODE_READ;
157+
} else {
158+
self.mode &= !file::MODE_READ;
159+
}
160+
}
161+
162+
pub fn write(&mut self, write: bool) {
163+
if write {
164+
// Valid Combinations: Read, Read/Write, Read/Write/Create
165+
self.read(true);
166+
self.mode |= file::MODE_WRITE;
167+
} else {
168+
self.mode &= !file::MODE_WRITE;
169+
}
170+
}
171+
172+
pub fn append(&mut self, append: bool) {
173+
// Docs state that `.write(true).append(true)` has the same effect as `.append(true)`
174+
if append {
175+
self.write(true);
176+
}
177+
self.append = append;
145178
}
146179

147-
pub fn read(&mut self, _read: bool) {}
148-
pub fn write(&mut self, _write: bool) {}
149-
pub fn append(&mut self, _append: bool) {}
150-
pub fn truncate(&mut self, _truncate: bool) {}
151-
pub fn create(&mut self, _create: bool) {}
152-
pub fn create_new(&mut self, _create_new: bool) {}
180+
pub fn truncate(&mut self, truncate: bool) {
181+
self.truncate = truncate;
182+
}
183+
184+
pub fn create(&mut self, create: bool) {
185+
if create {
186+
self.mode |= file::MODE_CREATE;
187+
} else {
188+
self.mode &= !file::MODE_CREATE;
189+
}
190+
}
191+
192+
pub fn create_new(&mut self, create_new: bool) {
193+
self.create_new = create_new;
194+
}
195+
196+
const fn is_mode_valid(&self) -> bool {
197+
// Valid Combinations: Read, Read/Write, Read/Write/Create
198+
self.mode == file::MODE_READ
199+
|| self.mode == (file::MODE_READ | file::MODE_WRITE)
200+
|| self.mode == (file::MODE_READ | file::MODE_WRITE | file::MODE_CREATE)
201+
}
153202
}
154203

155204
impl File {
@@ -311,12 +360,12 @@ pub fn stat(_p: &Path) -> io::Result<FileAttr> {
311360
unsupported()
312361
}
313362

314-
pub fn lstat(_p: &Path) -> io::Result<FileAttr> {
315-
unsupported()
363+
pub fn lstat(p: &Path) -> io::Result<FileAttr> {
364+
stat(p)
316365
}
317366

318-
pub fn canonicalize(_p: &Path) -> io::Result<PathBuf> {
319-
unsupported()
367+
pub fn canonicalize(p: &Path) -> io::Result<PathBuf> {
368+
crate::path::absolute(p)
320369
}
321370

322371
pub fn copy(_from: &Path, _to: &Path) -> io::Result<u64> {

0 commit comments

Comments
 (0)
Failed to load comments.