Skip to content

Commit 72b2135

Browse files
boot: Add freestanding get_image_file_system
1 parent 058066f commit 72b2135

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

uefi/src/boot.rs

+32-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,35 @@ 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+
/// [`open_protocol_exclusive`]: Self::open_protocol_exclusive
1167+
/// [`locate_device_path`]: Self::locate_device_path
1168+
///
1169+
/// * [`Status::INVALID_PARAMETER`]
1170+
/// * [`Status::UNSUPPORTED`]
1171+
/// * [`Status::ACCESS_DENIED`]
1172+
/// * [`Status::ALREADY_STARTED`]
1173+
/// * [`Status::NOT_FOUND`]
1174+
pub fn get_image_file_system(image_handle: Handle) -> Result<ScopedProtocol<SimpleFileSystem>> {
1175+
let loaded_image = open_protocol_exclusive::<LoadedImage>(image_handle)?;
1176+
1177+
let device_handle = loaded_image
1178+
.device()
1179+
.ok_or(Error::new(Status::UNSUPPORTED, ()))?;
1180+
let device_path = open_protocol_exclusive::<DevicePath>(device_handle)?;
1181+
1182+
let device_handle = locate_device_path::<SimpleFileSystem>(&mut &*device_path)?;
1183+
1184+
open_protocol_exclusive(device_handle)
1185+
}
1186+
11591187
/// Protocol interface [`Guids`][Guid] that are installed on a [`Handle`] as
11601188
/// returned by [`protocols_per_handle`].
11611189
#[derive(Debug)]

uefi/src/table/boot.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1324,11 +1324,11 @@ impl BootServices {
13241324
/// [`open_protocol_exclusive`]: Self::open_protocol_exclusive
13251325
/// [`locate_device_path`]: Self::locate_device_path
13261326
///
1327-
/// * [`uefi::Status::INVALID_PARAMETER`]
1328-
/// * [`uefi::Status::UNSUPPORTED`]
1329-
/// * [`uefi::Status::ACCESS_DENIED`]
1330-
/// * [`uefi::Status::ALREADY_STARTED`]
1331-
/// * [`uefi::Status::NOT_FOUND`]
1327+
/// * [`Status::INVALID_PARAMETER`]
1328+
/// * [`Status::UNSUPPORTED`]
1329+
/// * [`Status::ACCESS_DENIED`]
1330+
/// * [`Status::ALREADY_STARTED`]
1331+
/// * [`Status::NOT_FOUND`]
13321332
pub fn get_image_file_system(
13331333
&self,
13341334
image_handle: Handle,

0 commit comments

Comments
 (0)