Skip to content

Commit c9eeb19

Browse files
committed
Add LoadedImage::file_path
1 parent 2844693 commit c9eeb19

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/proto/loaded_image.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! `LoadedImage` protocol.
22
33
use crate::{
4-
data_types::FromSliceWithNulError, proto::Protocol, table::boot::MemoryType, unsafe_guid,
5-
CStr16, Handle, Status,
4+
data_types::FromSliceWithNulError, proto::device_path::DevicePath, proto::Protocol,
5+
table::boot::MemoryType, unsafe_guid, CStr16, Char16, Handle, Status,
66
};
77
use core::{ffi::c_void, mem, slice};
88

@@ -17,7 +17,7 @@ pub struct LoadedImage {
1717

1818
// Source location of the image
1919
device_handle: Handle,
20-
_file_path: *const c_void, // TODO: not supported yet
20+
file_path: *const c_void,
2121
_reserved: *const c_void,
2222

2323
// Image load options
@@ -53,6 +53,19 @@ impl LoadedImage {
5353
self.device_handle
5454
}
5555

56+
/// Return a NULL-terminated Path string including directory and file names.
57+
pub fn file_path(&self) -> &CStr16 {
58+
// file_path is a pointer to the file path portion specific to
59+
// DeviceHandle that the EFI Image was loaded from.
60+
let file_path = self.file_path as *const DevicePath;
61+
62+
unsafe {
63+
// path name follows the DevicePathHeader.
64+
let path_name = file_path.offset(1);
65+
CStr16::from_ptr(path_name.cast::<Char16>())
66+
}
67+
}
68+
5669
/// Get the load options of the image as a [`&CStr16`].
5770
///
5871
/// Load options are typically used to pass command-line options as

0 commit comments

Comments
 (0)