pub struct UefiFileSystem(/* private fields */);
Expand description
A rust-ier wrapper around SimpleFileSystem
.
This is similar to uefi::fs::FileSystem
, with different design decisions.
Implementations§
Source§impl UefiFileSystem
impl UefiFileSystem
Sourcepub const fn new(fs: ScopedProtocol<SimpleFileSystem>) -> Self
pub const fn new(fs: ScopedProtocol<SimpleFileSystem>) -> Self
Create a new UefiFileSystem
.
Sourcepub fn from_handle(handle: Handle) -> BootResult<Self>
pub fn from_handle(handle: Handle) -> BootResult<Self>
Create a new UefiFileSystem
from a handle that supports SimpleFileSystem
.
§Errors
May return an Error
if the handle does not actually support SimpleFileSystem
.
Sourcepub fn from_image_fs() -> BootResult<Self>
pub fn from_image_fs() -> BootResult<Self>
Create a new UefiFileSystem
from the same filesystem as the boot manager.
This is mainly used when the boot manager wants to read from a file on the same filesystem as itself (for example,
the BootConfig
file).
§Errors
May return an Error
if the boot image’s filesystem does not support SimpleFileSystem
for some reason.
Sourcepub fn get_volume_label(&mut self) -> Result<CString16, FsError>
pub fn get_volume_label(&mut self) -> Result<CString16, FsError>
Gets the volume label from a SimpleFileSystem
§Errors
May return an Error
if the volume could not be opened, or the volume does not support FileSystemVolumeLabel
Sourcepub fn exists(&mut self, path: &CStr16) -> bool
pub fn exists(&mut self, path: &CStr16) -> bool
Checks if a file exists from a Handle
to a partition.
It makes no distinction between whether a file could not be verified to exist or a file that really
does not exist. Both will return false
. This means that if the volume could not be opened, it will return
false
as the file cannot be verified to exist.
This method may introduce the risk of TOCTOU bugs. While this is a little bit less likely to happen considering
the single threaded nature of UEFI, it is still risky to check the existence of a file using exists
before opening
it. In that specific situation, consider opening the file and handling the FsError::OpenErr
separately.
Sourcepub fn exists_str(&mut self, path: &str) -> BootResult<bool>
pub fn exists_str(&mut self, path: &str) -> BootResult<bool>
Sourcepub fn read_dir(&mut self, path: &CStr16) -> Result<UefiDirectoryIter, FsError>
pub fn read_dir(&mut self, path: &CStr16) -> Result<UefiDirectoryIter, FsError>
Returns a UefiDirectoryIter
of files in the path from a handle to a partition.
§Errors
May return an Error
if the path does not exist.
Sourcepub fn read_filtered_dir(
&mut self,
path: &CStr16,
ext: &'static str,
) -> impl Iterator<Item = Box<FileInfo>> + use<>
pub fn read_filtered_dir( &mut self, path: &CStr16, ext: &'static str, ) -> impl Iterator<Item = Box<FileInfo>> + use<>
Returns an iterator of FileInfo
s that filter out non-matching files.
This applies several filters to ensure that the file matches as expected. “.” and “..” are displayed in directory lists, so they are filtered out. Then, the filename’s suffix is compared to the provided extension and filtered out if they don’t match. Finally, the file is filtered if it is empty.
Sourcepub fn read_into(
&mut self,
path: &CStr16,
buf: &mut [u8],
) -> Result<usize, FsError>
pub fn read_into( &mut self, path: &CStr16, buf: &mut [u8], ) -> Result<usize, FsError>
Attempts to read as much as possible of a file into a byte buffer. On success it will also return the amount of bytes read.
You may want to use core::str::from_utf8
to convert the content into an &str.
§Errors
May return an Error
if the volume couldn’t be opened, the path does not point to a valid file,
the file could not be read for any reason, or the buffer was too small. If the buffer was too small,
the amount of bytes required is returned.
Sourcepub fn read(&mut self, path: &CStr16) -> Result<Vec<u8>, FsError>
pub fn read(&mut self, path: &CStr16) -> Result<Vec<u8>, FsError>
Reads the entire content of a file into a Vec<u8>
.
You may want to use core::str::from_utf8
to convert the content into an &str.
§Errors
May return an Error
if the volume couldn’t be opened, the path does not point to a valid file, or
the file could not be read for any reason.
Sourcepub fn copy(&mut self, src: &CStr16, dst: &CStr16) -> Result<(), FsError>
pub fn copy(&mut self, src: &CStr16, dst: &CStr16) -> Result<(), FsError>
Copy a file onto another file.
This implements buffered reading and writing, with a fixed size of 4 KiB. This buffer is a stack allocated array that is small enough to avoid stack overflow while still being suitable for operations like renaming boot counter files.
§Errors
May return an Error
if the volume couldn’t be opened, any of the two paths don’t point to a valid file, or
the source file could not be read.
Sourcepub fn rename(&mut self, src: &CStr16, dst: &CStr16) -> Result<(), FsError>
pub fn rename(&mut self, src: &CStr16, dst: &CStr16) -> Result<(), FsError>
Renames a file into another file.
This essentially copies a file into another file, then deletes the original file.
§Errors
May return an Error
if the volume couldn’t be opened, any of the two paths don’t point to a valid file,
the source file could not be read, or the source file could not be deleted.
Sourcepub fn write(&mut self, path: &CStr16, buffer: &[u8]) -> Result<(), FsError>
pub fn write(&mut self, path: &CStr16, buffer: &[u8]) -> Result<(), FsError>
Writes a byte slice into a file.
§Errors
May return an Error
if the volume couldn’t be opened, or the file does not exist.
Sourcepub fn append(&mut self, path: &CStr16, buffer: &[u8]) -> BootResult<()>
pub fn append(&mut self, path: &CStr16, buffer: &[u8]) -> BootResult<()>
Appends a byte slice onto a file.
This is similar to using Self::write
only that instead of replacing the content of a file from the beginning,
it adds new content onto the end of a file.
§Errors
May return an Error
if the volume couldn’t be opened, or the file does not exist.