@@ -6,6 +6,8 @@ use crate::data_types::PhysicalAddress;
6
6
use crate :: mem:: memory_map:: { MemoryMapBackingMemory , MemoryMapKey , MemoryMapMeta , MemoryMapOwned } ;
7
7
use crate :: polyfill:: maybe_uninit_slice_assume_init_ref;
8
8
use crate :: proto:: device_path:: DevicePath ;
9
+ use crate :: proto:: loaded_image:: LoadedImage ;
10
+ use crate :: proto:: media:: fs:: SimpleFileSystem ;
9
11
use crate :: proto:: { Protocol , ProtocolPointer } ;
10
12
use crate :: table:: Revision ;
11
13
use crate :: util:: opt_nonnull_to_ptr;
@@ -22,10 +24,7 @@ use uefi_raw::table::boot::InterfaceType;
22
24
use { alloc:: vec:: Vec , uefi:: ResultExt } ;
23
25
24
26
#[ 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 ;
29
28
30
29
pub use uefi:: table:: boot:: {
31
30
AllocateType , EventNotifyFn , LoadImageSource , OpenProtocolAttributes , OpenProtocolParams ,
@@ -1156,6 +1155,32 @@ pub fn stall(microseconds: usize) {
1156
1155
}
1157
1156
}
1158
1157
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
+
1159
1184
/// Protocol interface [`Guids`][Guid] that are installed on a [`Handle`] as
1160
1185
/// returned by [`protocols_per_handle`].
1161
1186
#[ derive( Debug ) ]
0 commit comments