Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e3d5afb

Browse files
Merge pull request #1613 from rust-osdev/dvcp
uefi: remove duplication in DevicePathHeader; use uefi-raw
2 parents ae01a75 + 762905a commit e3d5afb

File tree

7 files changed

+427
-401
lines changed

7 files changed

+427
-401
lines changed

‎uefi-raw/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
- Added `DevicePathUtilitiesProtocol`.
1515
- Added `UsbIoProtocol`.
1616
- Added `Usb2HostControllerProtocol`.
17+
- Added `DevicePathProtocol::length()` properly constructing the `u16` value
18+
19+
## Changed
20+
- `DevicePathProtocol` now derives
21+
`Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash`
1722

1823

1924
# uefi-raw - 0.10.0 (2025年02月07日)

‎uefi-raw/src/protocol/device_path.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,29 @@ pub use device_path_gen::{acpi, bios_boot_spec, end, hardware, media, messaging}
88

99
/// Device path protocol.
1010
///
11-
/// A device path contains one or more device path instances made of up
11+
/// A device path contains one or more device path instances made up of
1212
/// variable-length nodes.
1313
///
1414
/// Note that the fields in this struct define the header at the start of each
1515
/// node; a device path is typically larger than these four bytes.
16-
#[derive(Debug)]
16+
#[derive(Clone,Copy,Debug,Eq,PartialEq,Ord,PartialOrd,Hash)]
1717
#[repr(C)]
1818
pub struct DevicePathProtocol {
1919
pub major_type: DeviceType,
2020
pub sub_type: DeviceSubType,
21+
/// Total length of the type including the fixed header as u16 in LE order.
2122
pub length: [u8; 2],
2223
// followed by payload (dynamically sized)
2324
}
2425

2526
impl DevicePathProtocol {
2627
pub const GUID: Guid = guid!("09576e91-6d3f-11d2-8e39-00a0c969723b");
28+
29+
/// Returns the total length of the device path node.
30+
#[must_use]
31+
pub const fn length(&self) -> u16 {
32+
u16::from_le_bytes(self.length)
33+
}
2734
}
2835

2936
newtype_enum! {
@@ -252,3 +259,17 @@ pub struct DevicePathUtilitiesProtocol {
252259
impl DevicePathUtilitiesProtocol {
253260
pub const GUID: Guid = guid!("0379be4e-d706-437d-b037-edb82fb772a4");
254261
}
262+
263+
#[cfg(test)]
264+
mod tests {
265+
use super::*;
266+
use core::mem;
267+
268+
/// Test that ensures the struct is packed. Thus, we don't need to
269+
/// explicitly specify `packed`.
270+
#[test]
271+
fn abi() {
272+
assert_eq!(mem::size_of::<DevicePathProtocol>(), 4);
273+
assert_eq!(mem::align_of::<DevicePathProtocol>(), 1);
274+
}
275+
}

‎uefi/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
`proto::device_path::text` to `proto::device_path`.
2828
- **Breaking:** `exit_boot_services` now consumes a `Option<MemoryType>` which
2929
defaults to the recommended value of `MemoryType::LOADER_DATA`.
30+
- **Breaking:** Removed duplication in `DevicePathHeader`. Instead of public fields,
31+
there is now a public constructor combined with public getters.
3032
- `boot::memory_map()` will never return `Status::BUFFER_TOO_SMALL` from now on,
3133
as this is considered a hard internal error where users can't do anything
3234
about it anyway. It will panic instead.

‎uefi/src/proto/device_path/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub unsafe trait BuildNode {
225225

226226
unsafe impl BuildNode for &DevicePathNode {
227227
fn size_in_bytes(&self) -> Result<u16, BuildError> {
228-
Ok(self.header.length)
228+
Ok(self.header.length())
229229
}
230230

231231
fn write_data(&self, out: &mut [MaybeUninit<u8>]) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /