@@ -633,6 +633,40 @@ pub fn protocols_per_handle(handle: Handle) -> Result<ProtocolsPerHandle> {
633
633
} )
634
634
}
635
635
636
+ /// Locates the handle of a device on the device path that supports the specified protocol.
637
+ ///
638
+ /// The `device_path` is updated to point at the remaining part of the [`DevicePath`] after
639
+ /// the part that matched the protocol. For example, it can be used with a device path
640
+ /// that contains a file path to strip off the file system portion of the device path,
641
+ /// leaving the file path and handle to the file system driver needed to access the file.
642
+ ///
643
+ /// If the first node of `device_path` matches the protocol, the `device_path`
644
+ /// is advanced to the device path terminator node. If `device_path` is a
645
+ /// multi-instance device path, the function will operate on the first instance.
646
+ ///
647
+ /// # Errors
648
+ ///
649
+ /// * [`Status::NOT_FOUND`]: no matching handles.
650
+ pub fn locate_device_path < P : ProtocolPointer + ?Sized > (
651
+ device_path : & mut & DevicePath ,
652
+ ) -> Result < Handle > {
653
+ let bt = boot_services_raw_panicking ( ) ;
654
+ let bt = unsafe { bt. as_ref ( ) } ;
655
+
656
+ let mut handle = ptr:: null_mut ( ) ;
657
+ let mut device_path_ptr: * const uefi_raw:: protocol:: device_path:: DevicePathProtocol =
658
+ device_path. as_ffi_ptr ( ) . cast ( ) ;
659
+ unsafe {
660
+ ( bt. locate_device_path ) ( & P :: GUID , & mut device_path_ptr, & mut handle) . to_result_with_val (
661
+ || {
662
+ * device_path = DevicePath :: from_ffi_ptr ( device_path_ptr. cast ( ) ) ;
663
+ // OK to unwrap: handle is non-null for Status::SUCCESS.
664
+ Handle :: from_ptr ( handle) . unwrap ( )
665
+ } ,
666
+ )
667
+ }
668
+ }
669
+
636
670
/// Returns an array of handles that support the requested protocol in a
637
671
/// pool-allocated buffer.
638
672
///
0 commit comments