@@ -6,6 +6,8 @@ use crate::data_types::PhysicalAddress;
66use crate :: mem:: memory_map:: { MemoryMapBackingMemory , MemoryMapKey , MemoryMapMeta , MemoryMapOwned } ;
77use crate :: polyfill:: maybe_uninit_slice_assume_init_ref;
88use crate :: proto:: device_path:: DevicePath ;
9+ use crate :: proto:: loaded_image:: LoadedImage ;
10+ use crate :: proto:: media:: fs:: SimpleFileSystem ;
911use crate :: proto:: { Protocol , ProtocolPointer } ;
1012use crate :: table:: Revision ;
1113use crate :: util:: opt_nonnull_to_ptr;
@@ -22,10 +24,7 @@ use uefi_raw::table::boot::InterfaceType;
2224use { 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
3029pub 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