@@ -89,8 +89,9 @@ use crate::mem::PoolAllocation;
89
89
use crate :: proto:: { unsafe_protocol, ProtocolPointer } ;
90
90
use core:: ffi:: c_void;
91
91
use core:: fmt:: { self , Debug , Display , Formatter } ;
92
- use core:: ops:: Deref ;
92
+ use core:: ops:: { Deref , DerefMut } ;
93
93
use ptr_meta:: Pointee ;
94
+ use uefi_raw:: protocol:: device_path:: DevicePathProtocol ;
94
95
95
96
#[ cfg( feature = "alloc" ) ]
96
97
use {
@@ -137,15 +138,8 @@ 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 ,
148
- }
141
+ #[ repr( transparent) ]
142
+ pub struct DevicePathHeader ( DevicePathProtocol ) ;
149
143
150
144
impl < ' a > TryFrom < & ' a [ u8 ] > for & ' a DevicePathHeader {
151
145
type Error = ByteConversionError ;
@@ -159,6 +153,20 @@ impl<'a> TryFrom<&'a [u8]> for &'a DevicePathHeader {
159
153
}
160
154
}
161
155
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
+
162
170
/// A single node within a [`DevicePath`].
163
171
///
164
172
/// Each node starts with a [`DevicePathHeader`]. The rest of the data
@@ -202,7 +210,7 @@ impl DevicePathNode {
202
210
pub unsafe fn from_ffi_ptr < ' a > ( ptr : * const FfiDevicePath ) -> & ' a Self {
203
211
let header = unsafe { * ptr. cast :: < DevicePathHeader > ( ) } ;
204
212
205
- let data_len = usize:: from ( header. length ) - size_of :: < DevicePathHeader > ( ) ;
213
+ let data_len = usize:: from ( header. length ( ) ) - size_of :: < DevicePathHeader > ( ) ;
206
214
unsafe { & * ptr_meta:: from_raw_parts ( ptr. cast ( ) , data_len) }
207
215
}
208
216
@@ -216,25 +224,25 @@ impl DevicePathNode {
216
224
/// Type of device
217
225
#[ must_use]
218
226
pub const fn device_type ( & self ) -> DeviceType {
219
- self . header . device_type
227
+ self . header . 0 . major_type
220
228
}
221
229
222
230
/// Sub type of device
223
231
#[ must_use]
224
232
pub const fn sub_type ( & self ) -> DeviceSubType {
225
- self . header . sub_type
233
+ self . header . 0 . sub_type
226
234
}
227
235
228
236
/// Tuple of the node's type and subtype.
229
237
#[ must_use]
230
238
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 )
232
240
}
233
241
234
242
/// Size (in bytes) of the full [`DevicePathNode`], including the header.
235
243
#[ must_use]
236
244
pub const fn length ( & self ) -> u16 {
237
- self . header . length
245
+ self . header . 0 . length ( )
238
246
}
239
247
240
248
/// True if this node ends an entire [`DevicePath`].
@@ -297,7 +305,7 @@ impl<'a> TryFrom<&'a [u8]> for &'a DevicePathNode {
297
305
298
306
fn try_from ( bytes : & [ u8 ] ) -> Result < Self , Self :: Error > {
299
307
let dp = <& DevicePathHeader >:: try_from ( bytes) ?;
300
- if usize:: from ( dp. length ) <= bytes. len ( ) {
308
+ if usize:: from ( dp. length ( ) ) <= bytes. len ( ) {
301
309
unsafe { Ok ( DevicePathNode :: from_ffi_ptr ( bytes. as_ptr ( ) . cast ( ) ) ) }
302
310
} else {
303
311
Err ( ByteConversionError :: InvalidLength )
0 commit comments