Skip to content

Commit ce3b344

Browse files
device path: add header struct (#263)
1 parent 8eb1948 commit ce3b344

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

src/proto/device_path.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,43 @@
1818
1919
use crate::{proto::Protocol, unsafe_guid};
2020

21+
/// Header that appears at the start of every [`DevicePath`] node.
22+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
23+
#[repr(C, packed)]
24+
pub struct DevicePathHeader {
25+
/// Type of device
26+
pub device_type: DeviceType,
27+
/// Sub type of device
28+
pub sub_type: DeviceSubType,
29+
/// Size (in bytes) of the full [`DevicePath`] instance, including this header.
30+
pub length: u16,
31+
}
32+
2133
/// Device path protocol.
2234
///
2335
/// This can be opened on a `LoadedImage.device()` handle using the `HandleProtocol` boot service.
2436
#[repr(C, packed)]
2537
#[unsafe_guid("09576e91-6d3f-11d2-8e39-00a0c969723b")]
2638
#[derive(Protocol)]
2739
pub struct DevicePath {
40+
header: DevicePathHeader,
41+
}
42+
43+
impl DevicePath {
2844
/// Type of device
29-
pub device_type: DeviceType,
45+
pub fn device_type(&self) -> DeviceType {
46+
self.header.device_type
47+
}
48+
3049
/// Sub type of device
31-
pub sub_type: DeviceSubType,
32-
/// Data related to device path
33-
///
34-
/// The `device_type` and `sub_type` determine the kind of data, and its size.
35-
pub length: u16,
50+
pub fn sub_type(&self) -> DeviceSubType {
51+
self.header.sub_type
52+
}
53+
54+
/// Size (in bytes) of the full [`DevicePath`] instance, including the header.
55+
pub fn length(&self) -> u16 {
56+
self.header.length
57+
}
3658
}
3759

3860
newtype_enum! {
@@ -191,10 +213,8 @@ impl DeviceSubType {
191213
/// ACPI Device Path
192214
#[repr(C, packed)]
193215
pub struct AcpiDevicePath {
194-
/// Type of device, which is ACPI Device Path
195-
pub device_type: DeviceType,
196-
/// Sub type of the device, which is ACPI Device Path
197-
pub sub_type: DeviceSubType,
216+
header: DevicePathHeader,
217+
198218
/// Device's PnP hardware ID stored in a numeric 32-bit compressed EISA-type ID. This value must match the
199219
/// corresponding _HID in the ACPI name space.
200220
pub hid: u32,

0 commit comments

Comments
 (0)