@@ -83,6 +83,7 @@ mod device_path_gen;
83
83
pub use device_path_gen:: {
84
84
acpi, bios_boot_spec, end, hardware, media, messaging, DevicePathNodeEnum ,
85
85
} ;
86
+ pub use uefi_raw:: protocol:: device_path:: DevicePathProtocol as RawDevicePathProtocol ;
86
87
pub use uefi_raw:: protocol:: device_path:: { DeviceSubType , DeviceType } ;
87
88
88
89
use crate :: mem:: PoolAllocation ;
@@ -137,14 +138,25 @@ impl Deref for PoolDevicePathNode {
137
138
138
139
/// Header that appears at the start of every [`DevicePathNode`].
139
140
#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
140
- #[ repr( C , packed) ]
141
- pub struct DevicePathHeader {
142
- /// Type of device
143
- pub device_type : DeviceType ,
144
- /// Sub type of device
145
- pub sub_type : DeviceSubType ,
146
- /// Size (in bytes) of the [`DevicePathNode`], including this header.
147
- pub length : u16 ,
141
+ #[ repr( transparent) ]
142
+ pub struct DevicePathHeader ( pub RawDevicePathProtocol ) ;
143
+
144
+ impl DevicePathHeader {
145
+ /// Returns the [`DeviceType`].
146
+ pub const fn major_type ( & self ) -> DeviceType {
147
+ self . 0 . major_type
148
+ }
149
+
150
+ /// Returns the [`DeviceSubType`].
151
+ pub const fn sub_type ( & self ) -> DeviceSubType {
152
+ self . 0 . sub_type
153
+ }
154
+
155
+ /// Returns the total length of the device path.
156
+ #[ must_use]
157
+ pub const fn length ( & self ) -> u16 {
158
+ self . 0 . length ( )
159
+ }
148
160
}
149
161
150
162
impl < ' a > TryFrom < & ' a [ u8 ] > for & ' a DevicePathHeader {
@@ -202,7 +214,7 @@ impl DevicePathNode {
202
214
pub unsafe fn from_ffi_ptr < ' a > ( ptr : * const FfiDevicePath ) -> & ' a Self {
203
215
let header = unsafe { * ptr. cast :: < DevicePathHeader > ( ) } ;
204
216
205
- let data_len = usize:: from ( header. length ) - size_of :: < DevicePathHeader > ( ) ;
217
+ let data_len = usize:: from ( header. length ( ) ) - size_of :: < DevicePathHeader > ( ) ;
206
218
unsafe { & * ptr_meta:: from_raw_parts ( ptr. cast ( ) , data_len) }
207
219
}
208
220
@@ -216,25 +228,25 @@ impl DevicePathNode {
216
228
/// Type of device
217
229
#[ must_use]
218
230
pub const fn device_type ( & self ) -> DeviceType {
219
- self . header . device_type
231
+ self . header . 0 . major_type
220
232
}
221
233
222
234
/// Sub type of device
223
235
#[ must_use]
224
236
pub const fn sub_type ( & self ) -> DeviceSubType {
225
- self . header . sub_type
237
+ self . header . 0 . sub_type
226
238
}
227
239
228
240
/// Tuple of the node's type and subtype.
229
241
#[ must_use]
230
242
pub const fn full_type ( & self ) -> ( DeviceType , DeviceSubType ) {
231
- ( self . header . device_type , self . header . sub_type )
243
+ ( self . header . 0 . major_type , self . header . 0 . sub_type )
232
244
}
233
245
234
246
/// Size (in bytes) of the full [`DevicePathNode`], including the header.
235
247
#[ must_use]
236
248
pub const fn length ( & self ) -> u16 {
237
- self . header . length
249
+ self . header . 0 . length ( )
238
250
}
239
251
240
252
/// True if this node ends an entire [`DevicePath`].
@@ -297,7 +309,7 @@ impl<'a> TryFrom<&'a [u8]> for &'a DevicePathNode {
297
309
298
310
fn try_from ( bytes : & [ u8 ] ) -> Result < Self , Self :: Error > {
299
311
let dp = <& DevicePathHeader >:: try_from ( bytes) ?;
300
- if usize:: from ( dp. length ) <= bytes. len ( ) {
312
+ if usize:: from ( dp. length ( ) ) <= bytes. len ( ) {
301
313
unsafe { Ok ( DevicePathNode :: from_ffi_ptr ( bytes. as_ptr ( ) . cast ( ) ) ) }
302
314
} else {
303
315
Err ( ByteConversionError :: InvalidLength )
0 commit comments