Skip to content

Commit 942e316

Browse files
authored
Merge pull request #1322 from nicholasbishop/bishop-get-fs
boot: Add freestanding get_image_file_system
2 parents 058066f + 72790ef commit 942e316

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

uefi-test-runner/src/main.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,8 @@ fn efi_main(image: Handle, mut st: SystemTable<Boot>) -> Status {
4848
// Check the `uefi::system` module.
4949
check_system(&st);
5050

51-
// Test all the boot services.
52-
let bt = st.boot_services();
53-
5451
// Try retrieving a handle to the file system the image was booted from.
55-
bt.get_image_file_system(image)
56-
.expect("Failed to retrieve boot file system");
52+
uefi::boot::get_image_file_system(image).expect("Failed to retrieve boot file system");
5753

5854
boot::test(&st);
5955

uefi/src/boot.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::data_types::PhysicalAddress;
66
use crate::mem::memory_map::{MemoryMapBackingMemory, MemoryMapKey, MemoryMapMeta, MemoryMapOwned};
77
use crate::polyfill::maybe_uninit_slice_assume_init_ref;
88
use crate::proto::device_path::DevicePath;
9+
use crate::proto::loaded_image::LoadedImage;
10+
use crate::proto::media::fs::SimpleFileSystem;
911
use crate::proto::{Protocol, ProtocolPointer};
1012
use crate::table::Revision;
1113
use crate::util::opt_nonnull_to_ptr;
@@ -22,10 +24,7 @@ use uefi_raw::table::boot::InterfaceType;
2224
use {alloc::vec::Vec, uefi::ResultExt};
2325

2426
#[cfg(doc)]
25-
use {
26-
crate::proto::device_path::LoadedImageDevicePath, crate::proto::loaded_image::LoadedImage,
27-
crate::proto::media::fs::SimpleFileSystem,
28-
};
27+
use crate::proto::device_path::LoadedImageDevicePath;
2928

3029
pub use uefi::table::boot::{
3130
AllocateType, EventNotifyFn, LoadImageSource, OpenProtocolAttributes, OpenProtocolParams,
@@ -1156,6 +1155,32 @@ pub fn stall(microseconds: usize) {
11561155
}
11571156
}
11581157

1158+
/// Retrieves a [`SimpleFileSystem`] protocol associated with the device the given
1159+
/// image was loaded from.
1160+
///
1161+
/// # Errors
1162+
///
1163+
/// This function can return errors from [`open_protocol_exclusive`] and
1164+
/// [`locate_device_path`]. See those functions for more details.
1165+
///
1166+
/// * [`Status::INVALID_PARAMETER`]
1167+
/// * [`Status::UNSUPPORTED`]
1168+
/// * [`Status::ACCESS_DENIED`]
1169+
/// * [`Status::ALREADY_STARTED`]
1170+
/// * [`Status::NOT_FOUND`]
1171+
pub fn get_image_file_system(image_handle: Handle) -> Result<ScopedProtocol<SimpleFileSystem>> {
1172+
let loaded_image = open_protocol_exclusive::<LoadedImage>(image_handle)?;
1173+
1174+
let device_handle = loaded_image
1175+
.device()
1176+
.ok_or(Error::new(Status::UNSUPPORTED, ()))?;
1177+
let device_path = open_protocol_exclusive::<DevicePath>(device_handle)?;
1178+
1179+
let device_handle = locate_device_path::<SimpleFileSystem>(&mut &*device_path)?;
1180+
1181+
open_protocol_exclusive(device_handle)
1182+
}
1183+
11591184
/// Protocol interface [`Guids`][Guid] that are installed on a [`Handle`] as
11601185
/// returned by [`protocols_per_handle`].
11611186
#[derive(Debug)]

0 commit comments

Comments
 (0)