Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: uefi: fs: Implement mkdir #138667

Merged
merged 1 commit into from
Mar 24, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions library/std/src/sys/fs/uefi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct FilePermissions(bool);
pub struct FileType(bool);

#[derive(Debug)]
pub struct DirBuilder {}
pub struct DirBuilder;

impl FileAttr {
pub fn size(&self) -> u64 {
Expand Down Expand Up @@ -248,11 +248,11 @@ impl File {

impl DirBuilder {
pub fn new() -> DirBuilder {
DirBuilder {}
DirBuilder
}

pub fn mkdir(&self, _p: &Path) -> io::Result<()> {
unsupported()
pub fn mkdir(&self, p: &Path) -> io::Result<()> {
uefi_fs::mkdir(p)
}
}

Expand Down Expand Up @@ -452,4 +452,30 @@ mod uefi_fs {
}
}
}

/// An implementation of mkdir to allow creating new directory without having to open the
/// volume twice (once for checking and once for creating)
pub(crate) fn mkdir(path: &Path) -> io::Result<()> {
let absolute = crate::path::absolute(path)?;

let p = helpers::OwnedDevicePath::from_text(absolute.as_os_str())?;
let (vol, mut path_remaining) = File::open_volume_from_device_path(p.borrow())?;

// Check if file exists
match vol.open(&mut path_remaining, file::MODE_READ, 0) {
Ok(_) => {
return Err(io::Error::new(io::ErrorKind::AlreadyExists, "Path already exists"));
}
Err(e) if e.kind() == io::ErrorKind::NotFound => {}
Err(e) => return Err(e),
}

let _ = vol.open(
&mut path_remaining,
file::MODE_READ | file::MODE_WRITE | file::MODE_CREATE,
file::DIRECTORY,
)?;

Ok(())
}
}
Loading