Skip to content

Commit 452b9c6

Browse files
necauquanicholasbishop
authored andcommitted
Fix locate_device_path impl according to how it's supposed to be used
1 parent 3f8082b commit 452b9c6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/table/boot.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub struct BootServices {
7979
) -> Status,
8080
locate_device_path: unsafe extern "efiapi" fn(
8181
proto: &Guid,
82-
device_path: &mut *mut DevicePath,
82+
device_path: &mut &DevicePath,
8383
out_handle: *mut Handle,
8484
) -> Status,
8585
install_configuration_table: usize,
@@ -531,12 +531,19 @@ impl BootServices {
531531
}
532532

533533
/// Locates the handle to a device on the device path that supports the specified protocol.
534-
pub fn locate_device_path<P: Protocol>(&self, device_path: &mut DevicePath) -> Result<Handle> {
534+
///
535+
/// The `device_path` is updated to point at the remaining part of the [`DevicePath`] after
536+
/// the part that matched the protocol. For example, it can be used with a device path
537+
/// that contains a file path to strip off the file system portion of the device path,
538+
/// leaving the file path and handle to the file system driver needed to access the file.
539+
///
540+
/// If the first node of `device_path` matches the
541+
/// protocol, the `device_path` is advanced to the device path terminator node. If `device_path`
542+
/// is a multi-instance device path, the function will operate on the first instance.
543+
pub fn locate_device_path<P: Protocol>(&self, device_path: &mut &DevicePath) -> Result<Handle> {
535544
unsafe {
536545
let mut handle = Handle::uninitialized();
537-
let mut device_path_ptr = device_path as *mut DevicePath;
538-
(self.locate_device_path)(&P::GUID, &mut device_path_ptr, &mut handle)
539-
.into_with_val(|| handle)
546+
(self.locate_device_path)(&P::GUID, device_path, &mut handle).into_with_val(|| handle)
540547
}
541548
}
542549

@@ -777,10 +784,10 @@ impl BootServices {
777784
let device_path = self
778785
.handle_protocol::<DevicePath>(device_handle)?
779786
.expect("Failed to retrieve `DevicePath` protocol from image's device handle");
780-
let device_path = unsafe { &mut *device_path.get() };
787+
let mut device_path = unsafe { &*device_path.get() };
781788

782789
let device_handle = self
783-
.locate_device_path::<SimpleFileSystem>(device_path)?
790+
.locate_device_path::<SimpleFileSystem>(&mut device_path)?
784791
.expect("Failed to locate `SimpleFileSystem` protocol on device path");
785792

786793
self.handle_protocol::<SimpleFileSystem>(device_handle)

0 commit comments

Comments
 (0)