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

uefi: fs: Implement FileType, FilePermissions and FileAttr #138269

Merged
merged 3 commits into from
Mar 12, 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
99 changes: 35 additions & 64 deletions library/std/src/sys/fs/uefi.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
use crate::ffi::OsString;
use crate::fmt;
use crate::hash::{Hash, Hasher};
use crate::hash::Hash;
use crate::io::{self, BorrowedCursor, IoSlice, IoSliceMut, SeekFrom};
use crate::path::{Path, PathBuf};
use crate::sys::time::SystemTime;
use crate::sys::unsupported;

#[expect(dead_code)]
const FILE_PERMISSIONS_MASK: u64 = r_efi::protocols::file::READ_ONLY;

pub struct File(!);

pub struct FileAttr(!);
#[derive(Clone)]
pub struct FileAttr {
attr: u64,
size: u64,
}

pub struct ReadDir(!);

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

pub struct FilePermissions(!);
#[derive(Clone, PartialEq, Eq, Debug)]
// Bool indicates if file is readonly
pub struct FilePermissions(bool);

pub struct FileType(!);
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
// Bool indicates if directory
pub struct FileType(bool);

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

impl FileAttr {
pub fn size(&self) -> u64 {
self.0
self.size
}

pub fn perm(&self) -> FilePermissions {
self.0
FilePermissions::from_attr(self.attr)
}

pub fn file_type(&self) -> FileType {
self.0
FileType::from_attr(self.attr)
}

pub fn modified(&self) -> io::Result<SystemTime> {
self.0
unsupported()
}

pub fn accessed(&self) -> io::Result<SystemTime> {
self.0
unsupported()
}

pub fn created(&self) -> io::Result<SystemTime> {
self.0
}
}

impl Clone for FileAttr {
fn clone(&self) -> FileAttr {
self.0
unsupported()
}
}

Expand All @@ -64,28 +69,17 @@ impl FilePermissions {
self.0
}

pub fn set_readonly(&mut self, _readonly: bool) {
self.0
pub fn set_readonly(&mut self, readonly: bool) {
self.0 = readonly
}
}

impl Clone for FilePermissions {
fn clone(&self) -> FilePermissions {
self.0
const fn from_attr(attr: u64) -> Self {
Self(attr & r_efi::protocols::file::READ_ONLY != 0)
}
}

impl PartialEq for FilePermissions {
fn eq(&self, _other: &FilePermissions) -> bool {
self.0
}
}

impl Eq for FilePermissions {}

impl fmt::Debug for FilePermissions {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0
#[expect(dead_code)]
const fn to_attr(&self) -> u64 {
if self.0 { r_efi::protocols::file::READ_ONLY } else { 0 }
}
}

Expand All @@ -100,39 +94,16 @@ impl FileType {
}

pub fn is_file(&self) -> bool {
self.0
!self.is_dir()
}

// Symlinks are not supported in UEFI
pub fn is_symlink(&self) -> bool {
self.0
}
}

impl Clone for FileType {
fn clone(&self) -> FileType {
self.0
false
}
}

impl Copy for FileType {}

impl PartialEq for FileType {
fn eq(&self, _other: &FileType) -> bool {
self.0
}
}

impl Eq for FileType {}

impl Hash for FileType {
fn hash<H: Hasher>(&self, _h: &mut H) {
self.0
}
}

impl fmt::Debug for FileType {
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.0
const fn from_attr(attr: u64) -> Self {
Self(attr & r_efi::protocols::file::DIRECTORY != 0)
}
}

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

pub fn set_perm(_p: &Path, perm: FilePermissions) -> io::Result<()> {
match perm.0 {}
pub fn set_perm(_p: &Path, _perm: FilePermissions) -> io::Result<()> {
unsupported()
}

pub fn rmdir(_p: &Path) -> io::Result<()> {
Expand Down
Loading