Skip to content

Commit ef4b6b4

Browse files
boot: Add freestanding get_image_file_system
1 parent a7d321b commit ef4b6b4

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

uefi/src/boot.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
use crate::data_types::PhysicalAddress;
66
use crate::mem::memory_map::{MemoryMapBackingMemory, MemoryMapKey, MemoryMapMeta, MemoryMapOwned};
77
use crate::proto::device_path::DevicePath;
8+
use crate::proto::loaded_image::LoadedImage;
9+
use crate::proto::media::fs::SimpleFileSystem;
810
use crate::proto::{Protocol, ProtocolPointer};
911
use crate::table::Revision;
1012
use crate::util::opt_nonnull_to_ptr;
@@ -17,10 +19,7 @@ use uefi::{table, Char16, Error, Event, Guid, Handle, Result, Status, StatusExt}
1719
use uefi_raw::table::boot::InterfaceType;
1820

1921
#[cfg(doc)]
20-
use {
21-
crate::proto::device_path::LoadedImageDevicePath, crate::proto::loaded_image::LoadedImage,
22-
crate::proto::media::fs::SimpleFileSystem,
23-
};
22+
use crate::proto::device_path::LoadedImageDevicePath;
2423

2524
pub use uefi::table::boot::{
2625
AllocateType, EventNotifyFn, LoadImageSource, OpenProtocolAttributes, OpenProtocolParams,
@@ -1069,6 +1068,35 @@ pub fn stall(microseconds: usize) {
10691068
}
10701069
}
10711070

1071+
/// Retrieves a [`SimpleFileSystem`] protocol associated with the device the given
1072+
/// image was loaded from.
1073+
///
1074+
/// # Errors
1075+
///
1076+
/// This function can return errors from [`open_protocol_exclusive`] and
1077+
/// [`locate_device_path`]. See those functions for more details.
1078+
///
1079+
/// [`open_protocol_exclusive`]: Self::open_protocol_exclusive
1080+
/// [`locate_device_path`]: Self::locate_device_path
1081+
///
1082+
/// * [`Status::INVALID_PARAMETER`]
1083+
/// * [`Status::UNSUPPORTED`]
1084+
/// * [`Status::ACCESS_DENIED`]
1085+
/// * [`Status::ALREADY_STARTED`]
1086+
/// * [`Status::NOT_FOUND`]
1087+
pub fn get_image_file_system(image_handle: Handle) -> Result<ScopedProtocol<SimpleFileSystem>> {
1088+
let loaded_image = open_protocol_exclusive::<LoadedImage>(image_handle)?;
1089+
1090+
let device_handle = loaded_image
1091+
.device()
1092+
.ok_or(Error::new(Status::UNSUPPORTED, ()))?;
1093+
let device_path = open_protocol_exclusive::<DevicePath>(device_handle)?;
1094+
1095+
let device_handle = locate_device_path::<SimpleFileSystem>(&mut &*device_path)?;
1096+
1097+
open_protocol_exclusive(device_handle)
1098+
}
1099+
10721100
/// Protocol interface [`Guids`][Guid] that are installed on a [`Handle`] as
10731101
/// returned by [`protocols_per_handle`].
10741102
#[derive(Debug)]

0 commit comments

Comments
 (0)