Module uefi::fs

source ·
Available on crate feature alloc only.
Expand description

A high-level file system API for UEFI applications close to the std::fs module from Rust’s standard library. The main export of this module is FileSystem.

§Difference to typical File System Abstractions

Users perform actions on dedicated volumes: For example, the boot volume, such as a CD-rom, USB-stick, or any other storage device.

Unlike in the API of typical UNIX file system abstractions, there is no virtual file system. Unlike in Windows, there is no way to access volumes by a dedicated name.

§Paths

All paths are absolute and follow the FAT-like file system conventions for paths. Thus, there is no current working directory and path components like . and .. are not supported. In other words, the current working directory is always /, i.e., the root, of the opened volume.

Symlinks or hard-links are not supported but only directories and regular files with plain linear paths to them. For more information, see Path and PathBuf.

§Use &str as Path

A &str known at compile time can be converted to a Path using the cstr16! macro. During runtime, you can create a path like this:

use uefi::CString16;
use uefi::fs::{FileSystem, FileSystemResult};
use uefi::prelude::BootServices;
use uefi::proto::media::fs::SimpleFileSystem;
use uefi::table::boot::ScopedProtocol;

fn read_file(bs: BootServices, path: &str) -> FileSystemResult<Vec<u8>> {
    let path: CString16 = CString16::try_from(path).unwrap();
    let fs: ScopedProtocol<SimpleFileSystem> = bs.get_image_file_system(bs.image_handle()).unwrap();
    let mut fs = FileSystem::new(fs);
    fs.read(path.as_ref())
}

§API Hints

There is no File abstraction as in the Rust std library. Instead, it is intended to work with the file system via dedicated functions, similar to the public functions of the std::fs module.

There is no automatic synchronization of the file system for concurrent accesses. This is in the responsibility of the user.

Structs§

  • Iterator over the components of a path. For example, the path \\a\\b\\c has the components [a, b, c]. This is a more basic approach than the components type of the standard library.
  • High-level file-system abstraction for UEFI volumes with an API that is close to std::fs. It acts as convenient accessor around the SimpleFileSystemProtocol.
  • UEFI-error with context when working with the underlying UEFI file protocol.
  • A path similar to the Path of the standard library, but based on CStr16 strings and SEPARATOR as separator.
  • A path buffer similar to the PathBuf of the standard library, but based on CString16 strings and SEPARATOR as separator.
  • Iterates over the entries of an UEFI directory. It returns boxed values of type UefiFileInfo.

Enums§

Constants§

Type Aliases§