@@ -557,6 +557,40 @@ pub fn protocols_per_handle(handle: Handle) -> Result<ProtocolsPerHandle> {
557
557
} )
558
558
}
559
559
560
+ /// Locates the handle of a device on the device path that supports the specified protocol.
561
+ ///
562
+ /// The `device_path` is updated to point at the remaining part of the [`DevicePath`] after
563
+ /// the part that matched the protocol. For example, it can be used with a device path
564
+ /// that contains a file path to strip off the file system portion of the device path,
565
+ /// leaving the file path and handle to the file system driver needed to access the file.
566
+ ///
567
+ /// If the first node of `device_path` matches the protocol, the `device_path`
568
+ /// is advanced to the device path terminator node. If `device_path` is a
569
+ /// multi-instance device path, the function will operate on the first instance.
570
+ ///
571
+ /// # Errors
572
+ ///
573
+ /// * [`Status::NOT_FOUND`]: no matching handles.
574
+ pub fn locate_device_path < P : ProtocolPointer + ?Sized > (
575
+ device_path : & mut & DevicePath ,
576
+ ) -> Result < Handle > {
577
+ let bt = boot_services_raw_panicking ( ) ;
578
+ let bt = unsafe { bt. as_ref ( ) } ;
579
+
580
+ let mut handle = ptr:: null_mut ( ) ;
581
+ let mut device_path_ptr: * const uefi_raw:: protocol:: device_path:: DevicePathProtocol =
582
+ device_path. as_ffi_ptr ( ) . cast ( ) ;
583
+ unsafe {
584
+ ( bt. locate_device_path ) ( & P :: GUID , & mut device_path_ptr, & mut handle) . to_result_with_val (
585
+ || {
586
+ * device_path = DevicePath :: from_ffi_ptr ( device_path_ptr. cast ( ) ) ;
587
+ // OK to unwrap: handle is non-null for Status::SUCCESS.
588
+ Handle :: from_ptr ( handle) . unwrap ( )
589
+ } ,
590
+ )
591
+ }
592
+ }
593
+
560
594
/// Returns an array of handles that support the requested protocol in a
561
595
/// pool-allocated buffer.
562
596
///
0 commit comments