Struct UefiFileSystem

Source
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

Source

pub const fn new(fs: ScopedProtocol<SimpleFileSystem>) -> Self

Create a new UefiFileSystem.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn exists_str(&mut self, path: &str) -> BootResult<bool>

Checks if a file exists from a handle to a partition with an &str path.

This is simply a helper function that converts an &str to a CString16 so that it may be used with the Self::exists function.

§Errors

May return an Error if the path could not be converted into a CString16

Source

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.

Source

pub fn read_filtered_dir( &mut self, path: &CStr16, ext: &'static str, ) -> impl Iterator<Item = Box<FileInfo>> + use<>

Returns an iterator of FileInfos 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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn create(&mut self, path: &CStr16) -> Result<(), FsError>

Creates an empty file.

§Errors

May return an Error if the volume could not be opened.

Source

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.

Source

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.

Source

pub fn delete(&mut self, path: &CStr16) -> Result<(), FsError>

Deletes a file.

§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 deleted.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.