17
17
//! total size of the Node including the header.
18
18
19
19
use crate :: { proto:: Protocol , unsafe_guid} ;
20
+ use core:: slice;
20
21
21
22
/// Header that appears at the start of every [`DevicePath`] node.
22
23
#[ derive( Clone , Copy , Debug , Eq , PartialEq ) ]
@@ -35,7 +36,7 @@ pub struct DevicePathHeader {
35
36
/// This can be opened on a `LoadedImage.device()` handle using the `HandleProtocol` boot service.
36
37
#[ repr( C , packed) ]
37
38
#[ unsafe_guid( "09576e91-6d3f-11d2-8e39-00a0c969723b" ) ]
38
- #[ derive( Protocol ) ]
39
+ #[ derive( Eq , Protocol ) ]
39
40
pub struct DevicePath {
40
41
header : DevicePathHeader ,
41
42
}
@@ -70,6 +71,27 @@ impl DevicePath {
70
71
}
71
72
}
72
73
74
+ impl PartialEq for DevicePath {
75
+ fn eq ( & self , other : & DevicePath ) -> bool {
76
+ // Check for equality with a byte-by-byte comparison of the device
77
+ // paths. Note that this covers the entire payload of the device path
78
+ // using the `length` field in the header, so it's not the same as just
79
+ // comparing the fields of the `DevicePath` struct.
80
+ unsafe {
81
+ let self_bytes = slice:: from_raw_parts (
82
+ self as * const DevicePath as * const u8 ,
83
+ self . length ( ) as usize ,
84
+ ) ;
85
+ let other_bytes = slice:: from_raw_parts (
86
+ other as * const DevicePath as * const u8 ,
87
+ other. length ( ) as usize ,
88
+ ) ;
89
+
90
+ self_bytes == other_bytes
91
+ }
92
+ }
93
+ }
94
+
73
95
/// Iterator over [`DevicePath`] nodes.
74
96
///
75
97
/// Iteration ends when a path is reached where [`DevicePath::is_end_entire`]
0 commit comments