@@ -89,8 +89,9 @@ use crate::mem::PoolAllocation;
8989use crate :: proto:: { unsafe_protocol, ProtocolPointer } ;
9090use core:: ffi:: c_void;
9191use core:: fmt:: { self , Debug , Display , Formatter } ;
92- use core:: ops:: Deref ;
92+ use core:: ops:: { Deref , DerefMut } ;
9393use ptr_meta:: Pointee ;
94+ use uefi_raw:: protocol:: device_path:: DevicePathProtocol ;
9495
9596#[ cfg( feature = "alloc" ) ]
9697use {
@@ -137,15 +138,8 @@ impl Deref for PoolDevicePathNode {
137138
138139/// Header that appears at the start of every [`DevicePathNode`].
139140#[ 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 ,
148- }
141+ #[ repr( transparent) ]
142+ pub struct DevicePathHeader ( DevicePathProtocol ) ;
149143
150144impl < ' a > TryFrom < & ' a [ u8 ] > for & ' a DevicePathHeader {
151145 type Error = ByteConversionError ;
@@ -159,6 +153,20 @@ impl<'a> TryFrom<&'a [u8]> for &'a DevicePathHeader {
159153 }
160154}
161155
156+ impl Deref for DevicePathHeader {
157+ type Target = DevicePathProtocol ;
158+
159+ fn deref ( & self ) -> & Self :: Target {
160+ & self . 0
161+ }
162+ }
163+
164+ impl DerefMut for DevicePathHeader {
165+ fn deref_mut ( & mut self ) -> & mut Self :: Target {
166+ & mut self . 0
167+ }
168+ }
169+
162170/// A single node within a [`DevicePath`].
163171///
164172/// Each node starts with a [`DevicePathHeader`]. The rest of the data
@@ -202,7 +210,7 @@ impl DevicePathNode {
202210 pub unsafe fn from_ffi_ptr < ' a > ( ptr : * const FfiDevicePath ) -> & ' a Self {
203211 let header = unsafe { * ptr. cast :: < DevicePathHeader > ( ) } ;
204212
205- let data_len = usize:: from ( header. length ) - size_of :: < DevicePathHeader > ( ) ;
213+ let data_len = usize:: from ( header. length ( ) ) - size_of :: < DevicePathHeader > ( ) ;
206214 unsafe { & * ptr_meta:: from_raw_parts ( ptr. cast ( ) , data_len) }
207215 }
208216
@@ -216,25 +224,25 @@ impl DevicePathNode {
216224 /// Type of device
217225 #[ must_use]
218226 pub const fn device_type ( & self ) -> DeviceType {
219- self . header . device_type
227+ self . header . 0 . major_type
220228 }
221229
222230 /// Sub type of device
223231 #[ must_use]
224232 pub const fn sub_type ( & self ) -> DeviceSubType {
225- self . header . sub_type
233+ self . header . 0 . sub_type
226234 }
227235
228236 /// Tuple of the node's type and subtype.
229237 #[ must_use]
230238 pub const fn full_type ( & self ) -> ( DeviceType , DeviceSubType ) {
231- ( self . header . device_type , self . header . sub_type )
239+ ( self . header . 0 . major_type , self . header . 0 . sub_type )
232240 }
233241
234242 /// Size (in bytes) of the full [`DevicePathNode`], including the header.
235243 #[ must_use]
236244 pub const fn length ( & self ) -> u16 {
237- self . header . length
245+ self . header . 0 . length ( )
238246 }
239247
240248 /// True if this node ends an entire [`DevicePath`].
@@ -297,7 +305,7 @@ impl<'a> TryFrom<&'a [u8]> for &'a DevicePathNode {
297305
298306 fn try_from ( bytes : & [ u8 ] ) -> Result < Self , Self :: Error > {
299307 let dp = <& DevicePathHeader >:: try_from ( bytes) ?;
300- if usize:: from ( dp. length ) <= bytes. len ( ) {
308+ if usize:: from ( dp. length ( ) ) <= bytes. len ( ) {
301309 unsafe { Ok ( DevicePathNode :: from_ffi_ptr ( bytes. as_ptr ( ) . cast ( ) ) ) }
302310 } else {
303311 Err ( ByteConversionError :: InvalidLength )
0 commit comments