Skip to content

uefi: remove duplication in DevicePathHeader; use uefi-raw #1613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions uefi-raw/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
- Added `DevicePathUtilitiesProtocol`.
- Added `UsbIoProtocol`.
- Added `Usb2HostControllerProtocol`.
- Added `DevicePathProtocol::length()` properly constructing the `u16` value

## Changed
- `DevicePathProtocol` now derives
`Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash`


# uefi-raw - 0.10.0 (2025-02-07)
Expand Down
25 changes: 23 additions & 2 deletions uefi-raw/src/protocol/device_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,29 @@ pub use device_path_gen::{acpi, bios_boot_spec, end, hardware, media, messaging}

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

impl DevicePathProtocol {
pub const GUID: Guid = guid!("09576e91-6d3f-11d2-8e39-00a0c969723b");

/// Returns the total length of the device path node.
#[must_use]
pub const fn length(&self) -> u16 {
u16::from_le_bytes(self.length)
}
}

newtype_enum! {
Expand Down Expand Up @@ -252,3 +259,17 @@ pub struct DevicePathUtilitiesProtocol {
impl DevicePathUtilitiesProtocol {
pub const GUID: Guid = guid!("0379be4e-d706-437d-b037-edb82fb772a4");
}

#[cfg(test)]
mod tests {
use super::*;
use core::mem;

/// Test that ensures the struct is packed. Thus, we don't need to
/// explicitly specify `packed`.
#[test]
fn abi() {
assert_eq!(mem::size_of::<DevicePathProtocol>(), 4);
assert_eq!(mem::align_of::<DevicePathProtocol>(), 1);
}
}
2 changes: 2 additions & 0 deletions uefi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
`proto::device_path::text` to `proto::device_path`.
- **Breaking:** `exit_boot_services` now consumes a `Option<MemoryType>` which
defaults to the recommended value of `MemoryType::LOADER_DATA`.
- **Breaking:** Removed duplication in `DevicePathHeader`. Instead of public fields,
there is now a public constructor combined with public getters.
- `boot::memory_map()` will never return `Status::BUFFER_TOO_SMALL` from now on,
as this is considered a hard internal error where users can't do anything
about it anyway. It will panic instead.
Expand Down
2 changes: 1 addition & 1 deletion uefi/src/proto/device_path/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub unsafe trait BuildNode {

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

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