5
5
use crate :: data_types:: PhysicalAddress ;
6
6
use crate :: mem:: memory_map:: { MemoryMapBackingMemory , MemoryMapKey , MemoryMapMeta , MemoryMapOwned } ;
7
7
use crate :: proto:: device_path:: DevicePath ;
8
+ use crate :: proto:: loaded_image:: LoadedImage ;
9
+ use crate :: proto:: media:: fs:: SimpleFileSystem ;
8
10
use crate :: proto:: { Protocol , ProtocolPointer } ;
9
11
use crate :: table:: Revision ;
10
12
use crate :: util:: opt_nonnull_to_ptr;
@@ -17,10 +19,7 @@ use uefi::{table, Char16, Error, Event, Guid, Handle, Result, Status, StatusExt}
17
19
use uefi_raw:: table:: boot:: InterfaceType ;
18
20
19
21
#[ 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 ;
24
23
25
24
pub use uefi:: table:: boot:: {
26
25
AllocateType , EventNotifyFn , LoadImageSource , OpenProtocolAttributes , OpenProtocolParams ,
@@ -1069,6 +1068,35 @@ pub fn stall(microseconds: usize) {
1069
1068
}
1070
1069
}
1071
1070
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
+
1072
1100
/// Protocol interface [`Guids`][Guid] that are installed on a [`Handle`] as
1073
1101
/// returned by [`protocols_per_handle`].
1074
1102
#[ derive( Debug ) ]
0 commit comments