Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions uefi-test-runner/src/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ fn test_load_image(bt: &BootServices) {

// Variant A: FromBuffer
{
let fs = bt
.get_image_file_system(bt.image_handle())
.expect("should open file system");
let fs = boot::get_image_file_system(bt.image_handle()).expect("should open file system");
let path = CString16::try_from(image_device_path_file_path.as_str()).unwrap();
let image_data = FileSystem::new(fs)
.read(&*path)
Expand Down
2 changes: 1 addition & 1 deletion uefi-test-runner/src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

use alloc::string::{String, ToString};
use alloc::vec::Vec;
use uefi::boot::ScopedProtocol;
use uefi::fs::{FileSystem, IoError, IoErrorContext, PathBuf};
use uefi::proto::media::fs::SimpleFileSystem;
use uefi::table::boot::ScopedProtocol;
use uefi::{cstr16, fs, Status};

/// Tests functionality from the `uefi::fs` module. This test relies on a
Expand Down
10 changes: 4 additions & 6 deletions uefi-test-runner/src/proto/media.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use alloc::string::ToString;
use core::cell::RefCell;
use core::ptr::NonNull;
use uefi::boot;
use uefi::boot::{
self, EventType, OpenProtocolAttributes, OpenProtocolParams, ScopedProtocol, Tpl,
};
use uefi::data_types::Align;
use uefi::prelude::*;
use uefi::proto::media::block::BlockIO;
Expand All @@ -11,9 +13,6 @@ use uefi::proto::media::file::{
};
use uefi::proto::media::fs::SimpleFileSystem;
use uefi::proto::media::partition::{MbrOsType, PartitionInfo};
use uefi::table::boot::{
EventType, OpenProtocolAttributes, OpenProtocolParams, ScopedProtocol, Tpl,
};
use uefi::table::runtime::{Daylight, Time, TimeParams};

/// Test directory entry iteration.
Expand Down Expand Up @@ -370,8 +369,7 @@ fn find_test_disk(bt: &BootServices) -> (Handle, ScopedProtocol<SimpleFileSystem
assert_eq!(handles.len(), 2);

for handle in handles {
let mut sfs = bt
.open_protocol_exclusive::<SimpleFileSystem>(handle)
let mut sfs = boot::open_protocol_exclusive::<SimpleFileSystem>(handle)
.expect("Failed to get simple file system");
let mut root_directory = sfs.open_volume().unwrap();

Expand Down
3 changes: 3 additions & 0 deletions uefi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Changed
- **Breaking:** Deleted deprecated function `helpers::system_table`.
- **Breaking:** `FileSystem` no longer has a lifetime parameter, and the
deprecated conversion from `uefi::table::boot::ScopedProtocol` has been
removed.


# uefi - 0.32.0 (2024-09-09)
Expand Down
40 changes: 8 additions & 32 deletions uefi/src/fs/file_system/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,21 @@ use alloc::vec;
use alloc::vec::Vec;
use core::fmt;
use core::fmt::{Debug, Formatter};
use core::ops::Deref;
use uefi::boot::ScopedProtocol;

/// Return type for public [`FileSystem`] operations.
pub type FileSystemResult<T> = Result<T, Error>;

/// Contents of the `FileSystem` struct, allowing either variant of
/// `ScopedProtocol` to be used. This is temporary; once `BootServices` and the
/// associated `ScopedProtocol<'a>` structs are removed this inner type can be
/// removed as well.
enum FileSystemInner<'a> {
#[allow(deprecated)]
WithLifetime(uefi::table::boot::ScopedProtocol<'a, SimpleFileSystemProtocol>),
WithoutLifetime(uefi::boot::ScopedProtocol<SimpleFileSystemProtocol>),
}

/// 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`].
///
/// Please refer to the [module documentation] for more information.
///
/// [module documentation]: uefi::fs
pub struct FileSystem<'a>(FileSystemInner<'a>);
pub struct FileSystem(ScopedProtocol<SimpleFileSystemProtocol>);

impl<'a> FileSystem<'a> {
impl FileSystem {
/// Constructor.
#[must_use]
pub fn new(proto: impl Into<Self>) -> Self {
Expand Down Expand Up @@ -396,11 +386,7 @@ impl<'a> FileSystem<'a> {

/// Opens a fresh handle to the root directory of the volume.
fn open_root(&mut self) -> FileSystemResult<UefiDirectoryHandle> {
match &mut self.0 {
FileSystemInner::WithLifetime(proto) => proto.open_volume(),
FileSystemInner::WithoutLifetime(proto) => proto.open_volume(),
}
.map_err(|err| {
self.0.open_volume().map_err(|err| {
Error::Io(IoError {
path: {
let mut path = PathBuf::new();
Expand Down Expand Up @@ -445,25 +431,15 @@ impl<'a> FileSystem<'a> {
}
}

impl<'a> Debug for FileSystem<'a> {
impl Debug for FileSystem {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let ptr: *const _ = match &self.0 {
FileSystemInner::WithLifetime(proto) => proto.deref(),
FileSystemInner::WithoutLifetime(proto) => proto.deref(),
};
let ptr: *const _ = &self.0;
f.debug_tuple("FileSystem").field(&ptr).finish()
}
}

#[allow(deprecated)]
impl<'a> From<uefi::table::boot::ScopedProtocol<'a, SimpleFileSystemProtocol>> for FileSystem<'a> {
fn from(proto: uefi::table::boot::ScopedProtocol<'a, SimpleFileSystemProtocol>) -> Self {
Self(FileSystemInner::WithLifetime(proto))
}
}

impl<'a> From<uefi::boot::ScopedProtocol<SimpleFileSystemProtocol>> for FileSystem<'a> {
impl From<uefi::boot::ScopedProtocol<SimpleFileSystemProtocol>> for FileSystem {
fn from(proto: uefi::boot::ScopedProtocol<SimpleFileSystemProtocol>) -> Self {
Self(FileSystemInner::WithoutLifetime(proto))
Self(proto)
}
}