interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / uefi / src / proto / device_path / device_path_gen.rs

6240 lines · 236640 bytes Raw Blame History
1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3// DO NOT EDIT
4//
5// This file was automatically generated with:
6// `cargo xtask gen-code`
7//
8// See `/xtask/src/device_path/README.md` for more details.
9#![allow(clippy::missing_const_for_fn)]
10
11use crate::data_types::UnalignedSlice;
12use crate::mem::memory_map::MemoryType;
13use crate::polyfill::maybe_uninit_slice_as_mut_ptr;
14use crate::proto::device_path::{
15 self, DevicePathHeader, DevicePathNode, DeviceSubType, DeviceType, NodeConversionError,
16};
17use crate::{Guid, guid};
18use bitflags::bitflags;
19use core::{fmt, mem, slice};
20use ptr_meta::Pointee;
21use uefi_raw::IpAddress;
22/// Device path nodes for [`DeviceType::END`].
23pub mod end {
24 use super::*;
25 /// Node that terminates a [`DevicePathInstance`].
26 ///
27 /// [`DevicePathInstance`]: device_path::DevicePathInstance
28 #[repr(C, packed)]
29 pub struct Instance {
30 pub(super) header: DevicePathHeader,
31 }
32
33 impl Instance {}
34
35 impl fmt::Debug for Instance {
36 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37 f.debug_struct("Instance").finish()
38 }
39 }
40
41 impl TryFrom<&DevicePathNode> for &Instance {
42 type Error = NodeConversionError;
43 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
44 if node.device_type() != DeviceType::END
45 || node.sub_type() != DeviceSubType::END_INSTANCE
46 {
47 return Err(NodeConversionError::DifferentType);
48 }
49
50 if size_of_val(node) != size_of::<Instance>() {
51 return Err(NodeConversionError::InvalidLength);
52 }
53
54 let node: *const DevicePathNode = node;
55 let node: *const Instance = node.cast();
56 #[expect(clippy::undocumented_unsafe_blocks)]
57 Ok(unsafe { &*node })
58 }
59 }
60
61 /// Node that terminates an entire [`DevicePath`].
62 ///
63 /// [`DevicePath`]: device_path::DevicePath
64 #[repr(C, packed)]
65 pub struct Entire {
66 pub(super) header: DevicePathHeader,
67 }
68
69 impl Entire {}
70
71 impl fmt::Debug for Entire {
72 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
73 f.debug_struct("Entire").finish()
74 }
75 }
76
77 impl TryFrom<&DevicePathNode> for &Entire {
78 type Error = NodeConversionError;
79 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
80 if node.device_type() != DeviceType::END || node.sub_type() != DeviceSubType::END_ENTIRE
81 {
82 return Err(NodeConversionError::DifferentType);
83 }
84
85 if size_of_val(node) != size_of::<Entire>() {
86 return Err(NodeConversionError::InvalidLength);
87 }
88
89 let node: *const DevicePathNode = node;
90 let node: *const Entire = node.cast();
91 #[expect(clippy::undocumented_unsafe_blocks)]
92 Ok(unsafe { &*node })
93 }
94 }
95}
96
97/// Device path nodes for [`DeviceType::HARDWARE`].
98pub mod hardware {
99 use super::*;
100 /// PCI hardware device path node.
101 #[repr(C, packed)]
102 pub struct Pci {
103 pub(super) header: DevicePathHeader,
104 pub(super) function: u8,
105 pub(super) device: u8,
106 }
107
108 impl Pci {
109 /// PCI function number.
110 #[must_use]
111 pub fn function(&self) -> u8 {
112 self.function
113 }
114
115 /// PCI device number.
116 #[must_use]
117 pub fn device(&self) -> u8 {
118 self.device
119 }
120 }
121
122 impl fmt::Debug for Pci {
123 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124 f.debug_struct("Pci")
125 .field("function", &{ self.function })
126 .field("device", &{ self.device })
127 .finish()
128 }
129 }
130
131 impl TryFrom<&DevicePathNode> for &Pci {
132 type Error = NodeConversionError;
133 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
134 if node.device_type() != DeviceType::HARDWARE
135 || node.sub_type() != DeviceSubType::HARDWARE_PCI
136 {
137 return Err(NodeConversionError::DifferentType);
138 }
139
140 if size_of_val(node) != size_of::<Pci>() {
141 return Err(NodeConversionError::InvalidLength);
142 }
143
144 let node: *const DevicePathNode = node;
145 let node: *const Pci = node.cast();
146 #[expect(clippy::undocumented_unsafe_blocks)]
147 Ok(unsafe { &*node })
148 }
149 }
150
151 /// PCCARD hardware device path node.
152 #[repr(C, packed)]
153 pub struct Pccard {
154 pub(super) header: DevicePathHeader,
155 pub(super) function: u8,
156 }
157
158 impl Pccard {
159 /// Function number starting from 0.
160 #[must_use]
161 pub fn function(&self) -> u8 {
162 self.function
163 }
164 }
165
166 impl fmt::Debug for Pccard {
167 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
168 f.debug_struct("Pccard")
169 .field("function", &{ self.function })
170 .finish()
171 }
172 }
173
174 impl TryFrom<&DevicePathNode> for &Pccard {
175 type Error = NodeConversionError;
176 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
177 if node.device_type() != DeviceType::HARDWARE
178 || node.sub_type() != DeviceSubType::HARDWARE_PCCARD
179 {
180 return Err(NodeConversionError::DifferentType);
181 }
182
183 if size_of_val(node) != size_of::<Pccard>() {
184 return Err(NodeConversionError::InvalidLength);
185 }
186
187 let node: *const DevicePathNode = node;
188 let node: *const Pccard = node.cast();
189 #[expect(clippy::undocumented_unsafe_blocks)]
190 Ok(unsafe { &*node })
191 }
192 }
193
194 /// Memory mapped hardware device path node.
195 #[repr(C, packed)]
196 pub struct MemoryMapped {
197 pub(super) header: DevicePathHeader,
198 pub(super) memory_type: MemoryType,
199 pub(super) start_address: u64,
200 pub(super) end_address: u64,
201 }
202
203 impl MemoryMapped {
204 /// Memory type.
205 #[must_use]
206 pub fn memory_type(&self) -> MemoryType {
207 self.memory_type
208 }
209
210 /// Starting memory address.
211 #[must_use]
212 pub fn start_address(&self) -> u64 {
213 self.start_address
214 }
215
216 /// Ending memory address.
217 #[must_use]
218 pub fn end_address(&self) -> u64 {
219 self.end_address
220 }
221 }
222
223 impl fmt::Debug for MemoryMapped {
224 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
225 f.debug_struct("MemoryMapped")
226 .field("memory_type", &{ self.memory_type })
227 .field("start_address", &{ self.start_address })
228 .field("end_address", &{ self.end_address })
229 .finish()
230 }
231 }
232
233 impl TryFrom<&DevicePathNode> for &MemoryMapped {
234 type Error = NodeConversionError;
235 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
236 if node.device_type() != DeviceType::HARDWARE
237 || node.sub_type() != DeviceSubType::HARDWARE_MEMORY_MAPPED
238 {
239 return Err(NodeConversionError::DifferentType);
240 }
241
242 if size_of_val(node) != size_of::<MemoryMapped>() {
243 return Err(NodeConversionError::InvalidLength);
244 }
245
246 let node: *const DevicePathNode = node;
247 let node: *const MemoryMapped = node.cast();
248 #[expect(clippy::undocumented_unsafe_blocks)]
249 Ok(unsafe { &*node })
250 }
251 }
252
253 /// Vendor-defined hardware device path node.
254 #[repr(C, packed)]
255 #[derive(Pointee)]
256 pub struct Vendor {
257 pub(super) header: DevicePathHeader,
258 pub(super) vendor_guid: Guid,
259 pub(super) vendor_defined_data: [u8],
260 }
261
262 impl Vendor {
263 /// Vendor-assigned GUID that defines the data that follows.
264 #[must_use]
265 pub fn vendor_guid(&self) -> Guid {
266 self.vendor_guid
267 }
268
269 /// Vendor-defined data.
270 #[must_use]
271 pub fn vendor_defined_data(&self) -> &[u8] {
272 &self.vendor_defined_data
273 }
274 }
275
276 impl fmt::Debug for Vendor {
277 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
278 f.debug_struct("Vendor")
279 .field("vendor_guid", &{ self.vendor_guid })
280 .field("vendor_defined_data", &{
281 let ptr = &raw const self.vendor_defined_data;
282 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
283 let byte_len = size_of::<u8>() * len;
284 #[expect(clippy::undocumented_unsafe_blocks)]
285 unsafe {
286 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
287 }
288 })
289 .finish()
290 }
291 }
292
293 impl TryFrom<&DevicePathNode> for &Vendor {
294 type Error = NodeConversionError;
295 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
296 if node.device_type() != DeviceType::HARDWARE
297 || node.sub_type() != DeviceSubType::HARDWARE_VENDOR
298 {
299 return Err(NodeConversionError::DifferentType);
300 }
301
302 let static_size = 20usize;
303 let dst_size = size_of_val(node)
304 .checked_sub(static_size)
305 .ok_or(NodeConversionError::InvalidLength)?;
306 let elem_size = size_of::<u8>();
307 if dst_size % elem_size != 0 {
308 return Err(NodeConversionError::InvalidLength);
309 }
310
311 let node: *const DevicePathNode = node;
312 let node: *const Vendor = ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
313 #[expect(clippy::undocumented_unsafe_blocks)]
314 Ok(unsafe { &*node })
315 }
316 }
317
318 /// Controller hardware device path node.
319 #[repr(C, packed)]
320 pub struct Controller {
321 pub(super) header: DevicePathHeader,
322 pub(super) controller_number: u32,
323 }
324
325 impl Controller {
326 /// Controller number.
327 #[must_use]
328 pub fn controller_number(&self) -> u32 {
329 self.controller_number
330 }
331 }
332
333 impl fmt::Debug for Controller {
334 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
335 f.debug_struct("Controller")
336 .field("controller_number", &{ self.controller_number })
337 .finish()
338 }
339 }
340
341 impl TryFrom<&DevicePathNode> for &Controller {
342 type Error = NodeConversionError;
343 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
344 if node.device_type() != DeviceType::HARDWARE
345 || node.sub_type() != DeviceSubType::HARDWARE_CONTROLLER
346 {
347 return Err(NodeConversionError::DifferentType);
348 }
349
350 if size_of_val(node) != size_of::<Controller>() {
351 return Err(NodeConversionError::InvalidLength);
352 }
353
354 let node: *const DevicePathNode = node;
355 let node: *const Controller = node.cast();
356 #[expect(clippy::undocumented_unsafe_blocks)]
357 Ok(unsafe { &*node })
358 }
359 }
360
361 /// Baseboard Management Controller (BMC) host interface hardware
362 /// device path node.
363 #[repr(C, packed)]
364 pub struct Bmc {
365 pub(super) header: DevicePathHeader,
366 pub(super) interface_type: device_path::hardware::BmcInterfaceType,
367 pub(super) base_address: u64,
368 }
369
370 impl Bmc {
371 /// Host interface type.
372 #[must_use]
373 pub fn interface_type(&self) -> device_path::hardware::BmcInterfaceType {
374 self.interface_type
375 }
376
377 /// Base address of the BMC. If the least-significant bit of the
378 /// field is a 1 then the address is in I/O space, otherwise the
379 /// address is memory-mapped.
380 #[must_use]
381 pub fn base_address(&self) -> u64 {
382 self.base_address
383 }
384 }
385
386 impl fmt::Debug for Bmc {
387 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
388 f.debug_struct("Bmc")
389 .field("interface_type", &{ self.interface_type })
390 .field("base_address", &{ self.base_address })
391 .finish()
392 }
393 }
394
395 impl TryFrom<&DevicePathNode> for &Bmc {
396 type Error = NodeConversionError;
397 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
398 if node.device_type() != DeviceType::HARDWARE
399 || node.sub_type() != DeviceSubType::HARDWARE_BMC
400 {
401 return Err(NodeConversionError::DifferentType);
402 }
403
404 if size_of_val(node) != size_of::<Bmc>() {
405 return Err(NodeConversionError::InvalidLength);
406 }
407
408 let node: *const DevicePathNode = node;
409 let node: *const Bmc = node.cast();
410 #[expect(clippy::undocumented_unsafe_blocks)]
411 Ok(unsafe { &*node })
412 }
413 }
414
415 newtype_enum! { # [doc = " Baseboard Management Controller (BMC) host interface type."] pub enum BmcInterfaceType : u8 => { # [doc = " Unknown."] UNKNOWN = 0x00 , # [doc = " Keyboard controller style."] KEYBOARD_CONTROLLER_STYLE = 0x01 , # [doc = " Server management interface chip."] SERVER_MANAGEMENT_INTERFACE_CHIP = 0x02 , # [doc = " Block transfer."] BLOCK_TRANSFER = 0x03 , }
416
417 }
418}
419
420/// Device path nodes for [`DeviceType::ACPI`].
421pub mod acpi {
422 use super::*;
423 /// ACPI device path node.
424 #[repr(C, packed)]
425 pub struct Acpi {
426 pub(super) header: DevicePathHeader,
427 pub(super) hid: u32,
428 pub(super) uid: u32,
429 }
430
431 impl Acpi {
432 /// Device's PnP hardware ID stored in a numeric 32-bit
433 /// compressed EISA-type ID.
434 #[must_use]
435 pub fn hid(&self) -> u32 {
436 self.hid
437 }
438
439 /// Unique ID that is required by ACPI if two devices have the
440 /// same HID.
441 #[must_use]
442 pub fn uid(&self) -> u32 {
443 self.uid
444 }
445 }
446
447 impl fmt::Debug for Acpi {
448 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
449 f.debug_struct("Acpi")
450 .field("hid", &{ self.hid })
451 .field("uid", &{ self.uid })
452 .finish()
453 }
454 }
455
456 impl TryFrom<&DevicePathNode> for &Acpi {
457 type Error = NodeConversionError;
458 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
459 if node.device_type() != DeviceType::ACPI || node.sub_type() != DeviceSubType::ACPI {
460 return Err(NodeConversionError::DifferentType);
461 }
462
463 if size_of_val(node) != size_of::<Acpi>() {
464 return Err(NodeConversionError::InvalidLength);
465 }
466
467 let node: *const DevicePathNode = node;
468 let node: *const Acpi = node.cast();
469 #[expect(clippy::undocumented_unsafe_blocks)]
470 Ok(unsafe { &*node })
471 }
472 }
473
474 /// Expanded ACPI device path node.
475 #[repr(C, packed)]
476 #[derive(Pointee)]
477 pub struct Expanded {
478 pub(super) header: DevicePathHeader,
479 pub(super) hid: u32,
480 pub(super) uid: u32,
481 pub(super) cid: u32,
482 pub(super) data: [u8],
483 }
484
485 impl Expanded {
486 /// Device's PnP hardware ID stored in a numeric 32-bit compressed
487 /// EISA-type ID.
488 #[must_use]
489 pub fn hid(&self) -> u32 {
490 self.hid
491 }
492
493 /// Unique ID that is required by ACPI if two devices have the
494 /// same HID.
495 #[must_use]
496 pub fn uid(&self) -> u32 {
497 self.uid
498 }
499
500 /// Device's compatible PnP hardware ID stored in a numeric 32-bit
501 /// compressed EISA-type ID.
502 #[must_use]
503 pub fn cid(&self) -> u32 {
504 self.cid
505 }
506
507 /// Device's PnP hardware ID stored as a null-terminated ASCII
508 /// string. This value must match the corresponding HID in the
509 /// ACPI name space. If the length of this string not including
510 /// the null-terminator is 0, then the numeric HID is used.
511 #[must_use]
512 pub fn hid_str(&self) -> &[u8] {
513 self.get_hid_str()
514 }
515
516 /// Unique ID that is required by ACPI if two devices have the
517 /// same HID. This value is stored as a null-terminated ASCII
518 /// string. If the length of this string not including the
519 /// null-terminator is 0, then the numeric UID is used.
520 #[must_use]
521 pub fn uid_str(&self) -> &[u8] {
522 self.get_uid_str()
523 }
524
525 /// Device's compatible PnP hardware ID stored as a
526 /// null-terminated ASCII string. If the length of this string
527 /// not including the null-terminator is 0, then the numeric CID
528 /// is used.
529 #[must_use]
530 pub fn cid_str(&self) -> &[u8] {
531 self.get_cid_str()
532 }
533 }
534
535 impl fmt::Debug for Expanded {
536 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
537 f.debug_struct("Expanded")
538 .field("hid", &{ self.hid })
539 .field("uid", &{ self.uid })
540 .field("cid", &{ self.cid })
541 .field("data", &&self.data)
542 .finish()
543 }
544 }
545
546 impl TryFrom<&DevicePathNode> for &Expanded {
547 type Error = NodeConversionError;
548 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
549 if node.device_type() != DeviceType::ACPI
550 || node.sub_type() != DeviceSubType::ACPI_EXPANDED
551 {
552 return Err(NodeConversionError::DifferentType);
553 }
554
555 let static_size = 16usize;
556 let dst_size = size_of_val(node)
557 .checked_sub(static_size)
558 .ok_or(NodeConversionError::InvalidLength)?;
559 let elem_size = size_of::<u8>();
560 if dst_size % elem_size != 0 {
561 return Err(NodeConversionError::InvalidLength);
562 }
563
564 let node: *const DevicePathNode = node;
565 let node: *const Expanded = ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
566 #[expect(clippy::undocumented_unsafe_blocks)]
567 Ok(unsafe { &*node })
568 }
569 }
570
571 /// ADR ACPI device path node.
572 #[repr(C, packed)]
573 #[derive(Pointee)]
574 pub struct Adr {
575 pub(super) header: DevicePathHeader,
576 pub(super) adr: [u32],
577 }
578
579 impl Adr {
580 /// ADR values. For video output devices the value of this field
581 /// comes from Table B-2 ACPI 3.0 specification. At least one
582 /// ADR value is required.
583 #[must_use]
584 pub fn adr(&self) -> UnalignedSlice<'_, u32> {
585 let ptr: *const [u32] = &raw const self.adr;
586 let (ptr, len): (*const (), usize) = ptr_meta::to_raw_parts(ptr);
587 #[expect(clippy::undocumented_unsafe_blocks)]
588 unsafe {
589 UnalignedSlice::new(ptr.cast::<u32>(), len)
590 }
591 }
592 }
593
594 impl fmt::Debug for Adr {
595 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
596 f.debug_struct("Adr")
597 .field("adr", &{
598 let ptr = &raw const self.adr;
599 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
600 let byte_len = size_of::<u32>() * len;
601 #[expect(clippy::undocumented_unsafe_blocks)]
602 unsafe {
603 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
604 }
605 })
606 .finish()
607 }
608 }
609
610 impl TryFrom<&DevicePathNode> for &Adr {
611 type Error = NodeConversionError;
612 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
613 if node.device_type() != DeviceType::ACPI || node.sub_type() != DeviceSubType::ACPI_ADR
614 {
615 return Err(NodeConversionError::DifferentType);
616 }
617
618 let static_size = 4usize;
619 let dst_size = size_of_val(node)
620 .checked_sub(static_size)
621 .ok_or(NodeConversionError::InvalidLength)?;
622 let elem_size = size_of::<u32>();
623 if dst_size % elem_size != 0 {
624 return Err(NodeConversionError::InvalidLength);
625 }
626
627 let node: *const DevicePathNode = node;
628 let node: *const Adr = ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
629 #[expect(clippy::undocumented_unsafe_blocks)]
630 Ok(unsafe { &*node })
631 }
632 }
633
634 /// NVDIMM ACPI device path node.
635 #[repr(C, packed)]
636 pub struct Nvdimm {
637 pub(super) header: DevicePathHeader,
638 pub(super) nfit_device_handle: u32,
639 }
640
641 impl Nvdimm {
642 /// NFIT device handle.
643 #[must_use]
644 pub fn nfit_device_handle(&self) -> u32 {
645 self.nfit_device_handle
646 }
647 }
648
649 impl fmt::Debug for Nvdimm {
650 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
651 f.debug_struct("Nvdimm")
652 .field("nfit_device_handle", &{ self.nfit_device_handle })
653 .finish()
654 }
655 }
656
657 impl TryFrom<&DevicePathNode> for &Nvdimm {
658 type Error = NodeConversionError;
659 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
660 if node.device_type() != DeviceType::ACPI
661 || node.sub_type() != DeviceSubType::ACPI_NVDIMM
662 {
663 return Err(NodeConversionError::DifferentType);
664 }
665
666 if size_of_val(node) != size_of::<Nvdimm>() {
667 return Err(NodeConversionError::InvalidLength);
668 }
669
670 let node: *const DevicePathNode = node;
671 let node: *const Nvdimm = node.cast();
672 #[expect(clippy::undocumented_unsafe_blocks)]
673 Ok(unsafe { &*node })
674 }
675 }
676
677 impl Expanded {
678 fn get_hid_str(&self) -> &[u8] {
679 get_acpi_expanded_substr(&self.data, 0)
680 }
681
682 fn get_uid_str(&self) -> &[u8] {
683 get_acpi_expanded_substr(&self.data, 1)
684 }
685
686 fn get_cid_str(&self) -> &[u8] {
687 get_acpi_expanded_substr(&self.data, 2)
688 }
689 }
690
691 /// Get the indices of the three nulls in the combined hid/uid/cid
692 /// string. This never fails; if some nulls are missing then `None`
693 /// is returned for those indices. If more than three nulls are
694 /// present then the extra ones are ignored.
695 fn acpi_expanded_null_indices(data: &[u8]) -> [Option<usize>; 3] {
696 let mut iter = data
697 .iter()
698 .copied()
699 .enumerate()
700 .filter_map(|(index, byte)| if byte == 0 { Some(index) } else { None })
701 .fuse();
702 [iter.next(), iter.next(), iter.next()]
703 }
704
705 /// Get the hid, uid, or cid string from the combined string. The
706 /// returned string includes the trailing null if possible; if the
707 /// substring was not properly null terminated then it ends at the
708 /// end of `data`.
709 ///
710 /// This never fails; if there aren't enough nulls in the input
711 /// string then an empty slice may be returned.
712 fn get_acpi_expanded_substr(data: &[u8], string_index: usize) -> &[u8] {
713 let [n0, n1, n2] = acpi_expanded_null_indices(data);
714 let mut start = data.len();
715 let mut end = start;
716 match string_index {
717 0 => {
718 start = 0;
719 if let Some(n0) = n0 {
720 end = n0 + 1;
721 }
722 }
723
724 1 => {
725 if let Some(n0) = n0 {
726 start = n0 + 1;
727 if let Some(n1) = n1 {
728 end = n1 + 1;
729 }
730 }
731 }
732
733 2 => {
734 if let Some(n1) = n1 {
735 start = n1 + 1;
736 if let Some(n2) = n2 {
737 end = n2 + 1;
738 }
739 }
740 }
741
742 _ => {
743 unreachable!("invalid string index")
744 }
745 }
746
747 data.get(start..end).unwrap_or(&[])
748 }
749
750 #[cfg(test)]
751 mod tests {
752 use super::*;
753 #[test]
754 fn test_get_acpi_expanded_substr() {
755 let s = b"ab\0cd\0ef\0";
756 assert_eq!(get_acpi_expanded_substr(s, 0), b"ab\0");
757 assert_eq!(get_acpi_expanded_substr(s, 1), b"cd\0");
758 assert_eq!(get_acpi_expanded_substr(s, 2), b"ef\0");
759 let s = b"\0\0\0";
760 assert_eq!(get_acpi_expanded_substr(s, 0), b"\0");
761 assert_eq!(get_acpi_expanded_substr(s, 1), b"\0");
762 assert_eq!(get_acpi_expanded_substr(s, 2), b"\0");
763 let s = b"ab\0cd\0";
764 assert_eq!(get_acpi_expanded_substr(s, 0), b"ab\0");
765 assert_eq!(get_acpi_expanded_substr(s, 1), b"cd\0");
766 assert_eq!(get_acpi_expanded_substr(s, 2), b"");
767 let s = b"ab\0";
768 assert_eq!(get_acpi_expanded_substr(s, 0), b"ab\0");
769 assert_eq!(get_acpi_expanded_substr(s, 1), b"");
770 assert_eq!(get_acpi_expanded_substr(s, 2), b"");
771 let s = b"ab\0cd\0ef";
772 assert_eq!(get_acpi_expanded_substr(s, 0), b"ab\0");
773 assert_eq!(get_acpi_expanded_substr(s, 1), b"cd\0");
774 assert_eq!(get_acpi_expanded_substr(s, 2), b"ef");
775 let s = b"ab\0cd";
776 assert_eq!(get_acpi_expanded_substr(s, 0), b"ab\0");
777 assert_eq!(get_acpi_expanded_substr(s, 1), b"cd");
778 assert_eq!(get_acpi_expanded_substr(s, 2), b"");
779 let s = b"ab";
780 assert_eq!(get_acpi_expanded_substr(s, 0), b"ab");
781 assert_eq!(get_acpi_expanded_substr(s, 1), b"");
782 assert_eq!(get_acpi_expanded_substr(s, 2), b"");
783 let s = b"";
784 assert_eq!(get_acpi_expanded_substr(s, 0), b"");
785 assert_eq!(get_acpi_expanded_substr(s, 1), b"");
786 assert_eq!(get_acpi_expanded_substr(s, 2), b"");
787 }
788 }
789}
790
791/// Device path nodes for [`DeviceType::MESSAGING`].
792pub mod messaging {
793 use super::*;
794 /// ATAPI messaging device path node.
795 #[repr(C, packed)]
796 pub struct Atapi {
797 pub(super) header: DevicePathHeader,
798 pub(super) primary_secondary: device_path::messaging::PrimarySecondary,
799 pub(super) master_slave: device_path::messaging::MasterSlave,
800 pub(super) logical_unit_number: u16,
801 }
802
803 impl Atapi {
804 /// Whether the ATAPI device is primary or secondary.
805 #[must_use]
806 pub fn primary_secondary(&self) -> device_path::messaging::PrimarySecondary {
807 self.primary_secondary
808 }
809
810 /// Whether the ATAPI device is master or slave.
811 #[must_use]
812 pub fn master_slave(&self) -> device_path::messaging::MasterSlave {
813 self.master_slave
814 }
815
816 /// Logical Unit Number (LUN).
817 #[must_use]
818 pub fn logical_unit_number(&self) -> u16 {
819 self.logical_unit_number
820 }
821 }
822
823 impl fmt::Debug for Atapi {
824 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
825 f.debug_struct("Atapi")
826 .field("primary_secondary", &{ self.primary_secondary })
827 .field("master_slave", &{ self.master_slave })
828 .field("logical_unit_number", &{ self.logical_unit_number })
829 .finish()
830 }
831 }
832
833 impl TryFrom<&DevicePathNode> for &Atapi {
834 type Error = NodeConversionError;
835 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
836 if node.device_type() != DeviceType::MESSAGING
837 || node.sub_type() != DeviceSubType::MESSAGING_ATAPI
838 {
839 return Err(NodeConversionError::DifferentType);
840 }
841
842 if size_of_val(node) != size_of::<Atapi>() {
843 return Err(NodeConversionError::InvalidLength);
844 }
845
846 let node: *const DevicePathNode = node;
847 let node: *const Atapi = node.cast();
848 #[expect(clippy::undocumented_unsafe_blocks)]
849 Ok(unsafe { &*node })
850 }
851 }
852
853 /// SCSI messaging device path node.
854 #[repr(C, packed)]
855 pub struct Scsi {
856 pub(super) header: DevicePathHeader,
857 pub(super) target_id: u16,
858 pub(super) logical_unit_number: u16,
859 }
860
861 impl Scsi {
862 /// Target ID on the SCSI bus.
863 #[must_use]
864 pub fn target_id(&self) -> u16 {
865 self.target_id
866 }
867
868 /// Logical Unit Number.
869 #[must_use]
870 pub fn logical_unit_number(&self) -> u16 {
871 self.logical_unit_number
872 }
873 }
874
875 impl fmt::Debug for Scsi {
876 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
877 f.debug_struct("Scsi")
878 .field("target_id", &{ self.target_id })
879 .field("logical_unit_number", &{ self.logical_unit_number })
880 .finish()
881 }
882 }
883
884 impl TryFrom<&DevicePathNode> for &Scsi {
885 type Error = NodeConversionError;
886 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
887 if node.device_type() != DeviceType::MESSAGING
888 || node.sub_type() != DeviceSubType::MESSAGING_SCSI
889 {
890 return Err(NodeConversionError::DifferentType);
891 }
892
893 if size_of_val(node) != size_of::<Scsi>() {
894 return Err(NodeConversionError::InvalidLength);
895 }
896
897 let node: *const DevicePathNode = node;
898 let node: *const Scsi = node.cast();
899 #[expect(clippy::undocumented_unsafe_blocks)]
900 Ok(unsafe { &*node })
901 }
902 }
903
904 /// Fibre channel messaging device path node.
905 #[repr(C, packed)]
906 pub struct FibreChannel {
907 pub(super) header: DevicePathHeader,
908 pub(super) _reserved: u32,
909 pub(super) world_wide_name: u64,
910 pub(super) logical_unit_number: u64,
911 }
912
913 impl FibreChannel {
914 /// Fibre Channel World Wide Name.
915 #[must_use]
916 pub fn world_wide_name(&self) -> u64 {
917 self.world_wide_name
918 }
919
920 /// Fibre Channel Logical Unit Number.
921 #[must_use]
922 pub fn logical_unit_number(&self) -> u64 {
923 self.logical_unit_number
924 }
925 }
926
927 impl fmt::Debug for FibreChannel {
928 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
929 f.debug_struct("FibreChannel")
930 .field("_reserved", &{ self._reserved })
931 .field("world_wide_name", &{ self.world_wide_name })
932 .field("logical_unit_number", &{ self.logical_unit_number })
933 .finish()
934 }
935 }
936
937 impl TryFrom<&DevicePathNode> for &FibreChannel {
938 type Error = NodeConversionError;
939 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
940 if node.device_type() != DeviceType::MESSAGING
941 || node.sub_type() != DeviceSubType::MESSAGING_FIBRE_CHANNEL
942 {
943 return Err(NodeConversionError::DifferentType);
944 }
945
946 if size_of_val(node) != size_of::<FibreChannel>() {
947 return Err(NodeConversionError::InvalidLength);
948 }
949
950 let node: *const DevicePathNode = node;
951 let node: *const FibreChannel = node.cast();
952 #[expect(clippy::undocumented_unsafe_blocks)]
953 Ok(unsafe { &*node })
954 }
955 }
956
957 /// Fibre channel extended messaging device path node.
958 #[repr(C, packed)]
959 pub struct FibreChannelEx {
960 pub(super) header: DevicePathHeader,
961 pub(super) _reserved: u32,
962 pub(super) world_wide_name: [u8; 8usize],
963 pub(super) logical_unit_number: [u8; 8usize],
964 }
965
966 impl FibreChannelEx {
967 /// Fibre Channel end device port name (aka World Wide Name).
968 #[must_use]
969 pub fn world_wide_name(&self) -> [u8; 8usize] {
970 self.world_wide_name
971 }
972
973 /// Fibre Channel Logical Unit Number.
974 #[must_use]
975 pub fn logical_unit_number(&self) -> [u8; 8usize] {
976 self.logical_unit_number
977 }
978 }
979
980 impl fmt::Debug for FibreChannelEx {
981 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
982 f.debug_struct("FibreChannelEx")
983 .field("_reserved", &{ self._reserved })
984 .field("world_wide_name", &{ self.world_wide_name })
985 .field("logical_unit_number", &{ self.logical_unit_number })
986 .finish()
987 }
988 }
989
990 impl TryFrom<&DevicePathNode> for &FibreChannelEx {
991 type Error = NodeConversionError;
992 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
993 if node.device_type() != DeviceType::MESSAGING
994 || node.sub_type() != DeviceSubType::MESSAGING_FIBRE_CHANNEL_EX
995 {
996 return Err(NodeConversionError::DifferentType);
997 }
998
999 if size_of_val(node) != size_of::<FibreChannelEx>() {
1000 return Err(NodeConversionError::InvalidLength);
1001 }
1002
1003 let node: *const DevicePathNode = node;
1004 let node: *const FibreChannelEx = node.cast();
1005 #[expect(clippy::undocumented_unsafe_blocks)]
1006 Ok(unsafe { &*node })
1007 }
1008 }
1009
1010 /// 1394 messaging device path node.
1011 #[repr(C, packed)]
1012 pub struct Ieee1394 {
1013 pub(super) header: DevicePathHeader,
1014 pub(super) _reserved: u32,
1015 pub(super) guid: [u8; 8usize],
1016 }
1017
1018 impl Ieee1394 {
1019 /// 1394 Global Unique ID. Note that this is not the same as a
1020 /// UEFI GUID.
1021 #[must_use]
1022 pub fn guid(&self) -> [u8; 8usize] {
1023 self.guid
1024 }
1025 }
1026
1027 impl fmt::Debug for Ieee1394 {
1028 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1029 f.debug_struct("Ieee1394")
1030 .field("_reserved", &{ self._reserved })
1031 .field("guid", &{ self.guid })
1032 .finish()
1033 }
1034 }
1035
1036 impl TryFrom<&DevicePathNode> for &Ieee1394 {
1037 type Error = NodeConversionError;
1038 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1039 if node.device_type() != DeviceType::MESSAGING
1040 || node.sub_type() != DeviceSubType::MESSAGING_1394
1041 {
1042 return Err(NodeConversionError::DifferentType);
1043 }
1044
1045 if size_of_val(node) != size_of::<Ieee1394>() {
1046 return Err(NodeConversionError::InvalidLength);
1047 }
1048
1049 let node: *const DevicePathNode = node;
1050 let node: *const Ieee1394 = node.cast();
1051 #[expect(clippy::undocumented_unsafe_blocks)]
1052 Ok(unsafe { &*node })
1053 }
1054 }
1055
1056 /// USB messaging device path node.
1057 #[repr(C, packed)]
1058 pub struct Usb {
1059 pub(super) header: DevicePathHeader,
1060 pub(super) parent_port_number: u8,
1061 pub(super) interface: u8,
1062 }
1063
1064 impl Usb {
1065 /// USB parent port number.
1066 #[must_use]
1067 pub fn parent_port_number(&self) -> u8 {
1068 self.parent_port_number
1069 }
1070
1071 /// USB interface number.
1072 #[must_use]
1073 pub fn interface(&self) -> u8 {
1074 self.interface
1075 }
1076 }
1077
1078 impl fmt::Debug for Usb {
1079 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1080 f.debug_struct("Usb")
1081 .field("parent_port_number", &{ self.parent_port_number })
1082 .field("interface", &{ self.interface })
1083 .finish()
1084 }
1085 }
1086
1087 impl TryFrom<&DevicePathNode> for &Usb {
1088 type Error = NodeConversionError;
1089 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1090 if node.device_type() != DeviceType::MESSAGING
1091 || node.sub_type() != DeviceSubType::MESSAGING_USB
1092 {
1093 return Err(NodeConversionError::DifferentType);
1094 }
1095
1096 if size_of_val(node) != size_of::<Usb>() {
1097 return Err(NodeConversionError::InvalidLength);
1098 }
1099
1100 let node: *const DevicePathNode = node;
1101 let node: *const Usb = node.cast();
1102 #[expect(clippy::undocumented_unsafe_blocks)]
1103 Ok(unsafe { &*node })
1104 }
1105 }
1106
1107 /// SATA messaging device path node.
1108 #[repr(C, packed)]
1109 pub struct Sata {
1110 pub(super) header: DevicePathHeader,
1111 pub(super) hba_port_number: u16,
1112 pub(super) port_multiplier_port_number: u16,
1113 pub(super) logical_unit_number: u16,
1114 }
1115
1116 impl Sata {
1117 /// The HBA port number that facilitates the connection to the
1118 /// device or a port multiplier. The value 0xffff is reserved.
1119 #[must_use]
1120 pub fn hba_port_number(&self) -> u16 {
1121 self.hba_port_number
1122 }
1123
1124 /// the port multiplier port number that facilitates the
1125 /// connection to the device. Must be set to 0xffff if the
1126 /// device is directly connected to the HBA.
1127 #[must_use]
1128 pub fn port_multiplier_port_number(&self) -> u16 {
1129 self.port_multiplier_port_number
1130 }
1131
1132 /// Logical unit number.
1133 #[must_use]
1134 pub fn logical_unit_number(&self) -> u16 {
1135 self.logical_unit_number
1136 }
1137 }
1138
1139 impl fmt::Debug for Sata {
1140 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1141 f.debug_struct("Sata")
1142 .field("hba_port_number", &{ self.hba_port_number })
1143 .field("port_multiplier_port_number", &{
1144 self.port_multiplier_port_number
1145 })
1146 .field("logical_unit_number", &{ self.logical_unit_number })
1147 .finish()
1148 }
1149 }
1150
1151 impl TryFrom<&DevicePathNode> for &Sata {
1152 type Error = NodeConversionError;
1153 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1154 if node.device_type() != DeviceType::MESSAGING
1155 || node.sub_type() != DeviceSubType::MESSAGING_SATA
1156 {
1157 return Err(NodeConversionError::DifferentType);
1158 }
1159
1160 if size_of_val(node) != size_of::<Sata>() {
1161 return Err(NodeConversionError::InvalidLength);
1162 }
1163
1164 let node: *const DevicePathNode = node;
1165 let node: *const Sata = node.cast();
1166 #[expect(clippy::undocumented_unsafe_blocks)]
1167 Ok(unsafe { &*node })
1168 }
1169 }
1170
1171 /// USB World Wide ID (WWID) messaging device path node.
1172 #[repr(C, packed)]
1173 #[derive(Pointee)]
1174 pub struct UsbWwid {
1175 pub(super) header: DevicePathHeader,
1176 pub(super) interface_number: u16,
1177 pub(super) device_vendor_id: u16,
1178 pub(super) device_product_id: u16,
1179 pub(super) serial_number: [u16],
1180 }
1181
1182 impl UsbWwid {
1183 /// USB interface number.
1184 #[must_use]
1185 pub fn interface_number(&self) -> u16 {
1186 self.interface_number
1187 }
1188
1189 /// USB vendor ID.
1190 #[must_use]
1191 pub fn device_vendor_id(&self) -> u16 {
1192 self.device_vendor_id
1193 }
1194
1195 /// USB product ID.
1196 #[must_use]
1197 pub fn device_product_id(&self) -> u16 {
1198 self.device_product_id
1199 }
1200
1201 /// Last 64 (or fewer) characters of the USB Serial number.
1202 #[must_use]
1203 pub fn serial_number(&self) -> UnalignedSlice<'_, u16> {
1204 let ptr: *const [u16] = &raw const self.serial_number;
1205 let (ptr, len): (*const (), usize) = ptr_meta::to_raw_parts(ptr);
1206 #[expect(clippy::undocumented_unsafe_blocks)]
1207 unsafe {
1208 UnalignedSlice::new(ptr.cast::<u16>(), len)
1209 }
1210 }
1211 }
1212
1213 impl fmt::Debug for UsbWwid {
1214 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1215 f.debug_struct("UsbWwid")
1216 .field("interface_number", &{ self.interface_number })
1217 .field("device_vendor_id", &{ self.device_vendor_id })
1218 .field("device_product_id", &{ self.device_product_id })
1219 .field("serial_number", &{
1220 let ptr = &raw const self.serial_number;
1221 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
1222 let byte_len = size_of::<u16>() * len;
1223 #[expect(clippy::undocumented_unsafe_blocks)]
1224 unsafe {
1225 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
1226 }
1227 })
1228 .finish()
1229 }
1230 }
1231
1232 impl TryFrom<&DevicePathNode> for &UsbWwid {
1233 type Error = NodeConversionError;
1234 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1235 if node.device_type() != DeviceType::MESSAGING
1236 || node.sub_type() != DeviceSubType::MESSAGING_USB_WWID
1237 {
1238 return Err(NodeConversionError::DifferentType);
1239 }
1240
1241 let static_size = 10usize;
1242 let dst_size = size_of_val(node)
1243 .checked_sub(static_size)
1244 .ok_or(NodeConversionError::InvalidLength)?;
1245 let elem_size = size_of::<u16>();
1246 if dst_size % elem_size != 0 {
1247 return Err(NodeConversionError::InvalidLength);
1248 }
1249
1250 let node: *const DevicePathNode = node;
1251 let node: *const UsbWwid = ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
1252 #[expect(clippy::undocumented_unsafe_blocks)]
1253 Ok(unsafe { &*node })
1254 }
1255 }
1256
1257 /// Device logical unit messaging device path node.
1258 #[repr(C, packed)]
1259 pub struct DeviceLogicalUnit {
1260 pub(super) header: DevicePathHeader,
1261 pub(super) logical_unit_number: u8,
1262 }
1263
1264 impl DeviceLogicalUnit {
1265 /// Logical Unit Number.
1266 #[must_use]
1267 pub fn logical_unit_number(&self) -> u8 {
1268 self.logical_unit_number
1269 }
1270 }
1271
1272 impl fmt::Debug for DeviceLogicalUnit {
1273 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1274 f.debug_struct("DeviceLogicalUnit")
1275 .field("logical_unit_number", &{ self.logical_unit_number })
1276 .finish()
1277 }
1278 }
1279
1280 impl TryFrom<&DevicePathNode> for &DeviceLogicalUnit {
1281 type Error = NodeConversionError;
1282 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1283 if node.device_type() != DeviceType::MESSAGING
1284 || node.sub_type() != DeviceSubType::MESSAGING_DEVICE_LOGICAL_UNIT
1285 {
1286 return Err(NodeConversionError::DifferentType);
1287 }
1288
1289 if size_of_val(node) != size_of::<DeviceLogicalUnit>() {
1290 return Err(NodeConversionError::InvalidLength);
1291 }
1292
1293 let node: *const DevicePathNode = node;
1294 let node: *const DeviceLogicalUnit = node.cast();
1295 #[expect(clippy::undocumented_unsafe_blocks)]
1296 Ok(unsafe { &*node })
1297 }
1298 }
1299
1300 /// USB class messaging device path node.
1301 #[repr(C, packed)]
1302 pub struct UsbClass {
1303 pub(super) header: DevicePathHeader,
1304 pub(super) vendor_id: u16,
1305 pub(super) product_id: u16,
1306 pub(super) device_class: u8,
1307 pub(super) device_subclass: u8,
1308 pub(super) device_protocol: u8,
1309 }
1310
1311 impl UsbClass {
1312 /// USB vendor ID.
1313 #[must_use]
1314 pub fn vendor_id(&self) -> u16 {
1315 self.vendor_id
1316 }
1317
1318 /// USB product ID.
1319 #[must_use]
1320 pub fn product_id(&self) -> u16 {
1321 self.product_id
1322 }
1323
1324 /// USB device class.
1325 #[must_use]
1326 pub fn device_class(&self) -> u8 {
1327 self.device_class
1328 }
1329
1330 /// USB device subclass.
1331 #[must_use]
1332 pub fn device_subclass(&self) -> u8 {
1333 self.device_subclass
1334 }
1335
1336 /// USB device protocol.
1337 #[must_use]
1338 pub fn device_protocol(&self) -> u8 {
1339 self.device_protocol
1340 }
1341 }
1342
1343 impl fmt::Debug for UsbClass {
1344 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1345 f.debug_struct("UsbClass")
1346 .field("vendor_id", &{ self.vendor_id })
1347 .field("product_id", &{ self.product_id })
1348 .field("device_class", &{ self.device_class })
1349 .field("device_subclass", &{ self.device_subclass })
1350 .field("device_protocol", &{ self.device_protocol })
1351 .finish()
1352 }
1353 }
1354
1355 impl TryFrom<&DevicePathNode> for &UsbClass {
1356 type Error = NodeConversionError;
1357 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1358 if node.device_type() != DeviceType::MESSAGING
1359 || node.sub_type() != DeviceSubType::MESSAGING_USB_CLASS
1360 {
1361 return Err(NodeConversionError::DifferentType);
1362 }
1363
1364 if size_of_val(node) != size_of::<UsbClass>() {
1365 return Err(NodeConversionError::InvalidLength);
1366 }
1367
1368 let node: *const DevicePathNode = node;
1369 let node: *const UsbClass = node.cast();
1370 #[expect(clippy::undocumented_unsafe_blocks)]
1371 Ok(unsafe { &*node })
1372 }
1373 }
1374
1375 /// I2O messaging device path node.
1376 #[repr(C, packed)]
1377 pub struct I2o {
1378 pub(super) header: DevicePathHeader,
1379 pub(super) target_id: u32,
1380 }
1381
1382 impl I2o {
1383 /// Target ID (TID).
1384 #[must_use]
1385 pub fn target_id(&self) -> u32 {
1386 self.target_id
1387 }
1388 }
1389
1390 impl fmt::Debug for I2o {
1391 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1392 f.debug_struct("I2o")
1393 .field("target_id", &{ self.target_id })
1394 .finish()
1395 }
1396 }
1397
1398 impl TryFrom<&DevicePathNode> for &I2o {
1399 type Error = NodeConversionError;
1400 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1401 if node.device_type() != DeviceType::MESSAGING
1402 || node.sub_type() != DeviceSubType::MESSAGING_I2O
1403 {
1404 return Err(NodeConversionError::DifferentType);
1405 }
1406
1407 if size_of_val(node) != size_of::<I2o>() {
1408 return Err(NodeConversionError::InvalidLength);
1409 }
1410
1411 let node: *const DevicePathNode = node;
1412 let node: *const I2o = node.cast();
1413 #[expect(clippy::undocumented_unsafe_blocks)]
1414 Ok(unsafe { &*node })
1415 }
1416 }
1417
1418 /// MAC address messaging device path node.
1419 #[repr(C, packed)]
1420 pub struct MacAddress {
1421 pub(super) header: DevicePathHeader,
1422 pub(super) mac_address: [u8; 32usize],
1423 pub(super) interface_type: u8,
1424 }
1425
1426 impl MacAddress {
1427 /// MAC address for a network interface, padded with zeros.
1428 #[must_use]
1429 pub fn mac_address(&self) -> [u8; 32usize] {
1430 self.mac_address
1431 }
1432
1433 /// Network interface type. See
1434 /// <https://www.iana.org/assignments/smi-numbers/smi-numbers.xhtml#smi-numbers-5>
1435 #[must_use]
1436 pub fn interface_type(&self) -> u8 {
1437 self.interface_type
1438 }
1439 }
1440
1441 impl fmt::Debug for MacAddress {
1442 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1443 f.debug_struct("MacAddress")
1444 .field("mac_address", &{ self.mac_address })
1445 .field("interface_type", &{ self.interface_type })
1446 .finish()
1447 }
1448 }
1449
1450 impl TryFrom<&DevicePathNode> for &MacAddress {
1451 type Error = NodeConversionError;
1452 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1453 if node.device_type() != DeviceType::MESSAGING
1454 || node.sub_type() != DeviceSubType::MESSAGING_MAC_ADDRESS
1455 {
1456 return Err(NodeConversionError::DifferentType);
1457 }
1458
1459 if size_of_val(node) != size_of::<MacAddress>() {
1460 return Err(NodeConversionError::InvalidLength);
1461 }
1462
1463 let node: *const DevicePathNode = node;
1464 let node: *const MacAddress = node.cast();
1465 #[expect(clippy::undocumented_unsafe_blocks)]
1466 Ok(unsafe { &*node })
1467 }
1468 }
1469
1470 /// IPv4 messaging device path node.
1471 #[repr(C, packed)]
1472 pub struct Ipv4 {
1473 pub(super) header: DevicePathHeader,
1474 pub(super) local_ip_address: [u8; 4usize],
1475 pub(super) remote_ip_address: [u8; 4usize],
1476 pub(super) local_port: u16,
1477 pub(super) remote_port: u16,
1478 pub(super) protocol: u16,
1479 pub(super) ip_address_origin: device_path::messaging::Ipv4AddressOrigin,
1480 pub(super) gateway_ip_address: [u8; 4usize],
1481 pub(super) subnet_mask: [u8; 4usize],
1482 }
1483
1484 impl Ipv4 {
1485 /// Local IPv4 address.
1486 #[must_use]
1487 pub fn local_ip_address(&self) -> [u8; 4usize] {
1488 self.local_ip_address
1489 }
1490
1491 /// Remote IPv4 address.
1492 #[must_use]
1493 pub fn remote_ip_address(&self) -> [u8; 4usize] {
1494 self.remote_ip_address
1495 }
1496
1497 /// Local port number.
1498 #[must_use]
1499 pub fn local_port(&self) -> u16 {
1500 self.local_port
1501 }
1502
1503 /// Remote port number.
1504 #[must_use]
1505 pub fn remote_port(&self) -> u16 {
1506 self.remote_port
1507 }
1508
1509 /// Network protocol. See
1510 /// <https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml>
1511 #[must_use]
1512 pub fn protocol(&self) -> u16 {
1513 self.protocol
1514 }
1515
1516 /// Whether the source IP address is static or assigned via DHCP.
1517 #[must_use]
1518 pub fn ip_address_origin(&self) -> device_path::messaging::Ipv4AddressOrigin {
1519 self.ip_address_origin
1520 }
1521
1522 /// Gateway IP address.
1523 #[must_use]
1524 pub fn gateway_ip_address(&self) -> [u8; 4usize] {
1525 self.gateway_ip_address
1526 }
1527
1528 /// Subnet mask.
1529 #[must_use]
1530 pub fn subnet_mask(&self) -> [u8; 4usize] {
1531 self.subnet_mask
1532 }
1533 }
1534
1535 impl fmt::Debug for Ipv4 {
1536 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1537 f.debug_struct("Ipv4")
1538 .field("local_ip_address", &{ self.local_ip_address })
1539 .field("remote_ip_address", &{ self.remote_ip_address })
1540 .field("local_port", &{ self.local_port })
1541 .field("remote_port", &{ self.remote_port })
1542 .field("protocol", &{ self.protocol })
1543 .field("ip_address_origin", &{ self.ip_address_origin })
1544 .field("gateway_ip_address", &{ self.gateway_ip_address })
1545 .field("subnet_mask", &{ self.subnet_mask })
1546 .finish()
1547 }
1548 }
1549
1550 impl TryFrom<&DevicePathNode> for &Ipv4 {
1551 type Error = NodeConversionError;
1552 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1553 if node.device_type() != DeviceType::MESSAGING
1554 || node.sub_type() != DeviceSubType::MESSAGING_IPV4
1555 {
1556 return Err(NodeConversionError::DifferentType);
1557 }
1558
1559 if size_of_val(node) != size_of::<Ipv4>() {
1560 return Err(NodeConversionError::InvalidLength);
1561 }
1562
1563 let node: *const DevicePathNode = node;
1564 let node: *const Ipv4 = node.cast();
1565 #[expect(clippy::undocumented_unsafe_blocks)]
1566 Ok(unsafe { &*node })
1567 }
1568 }
1569
1570 /// IPv6 messaging device path node.
1571 #[repr(C, packed)]
1572 pub struct Ipv6 {
1573 pub(super) header: DevicePathHeader,
1574 pub(super) local_ip_address: [u8; 16usize],
1575 pub(super) remote_ip_address: [u8; 16usize],
1576 pub(super) local_port: u16,
1577 pub(super) remote_port: u16,
1578 pub(super) protocol: u16,
1579 pub(super) ip_address_origin: device_path::messaging::Ipv6AddressOrigin,
1580 pub(super) prefix_length: u8,
1581 pub(super) gateway_ip_address: [u8; 16usize],
1582 }
1583
1584 impl Ipv6 {
1585 /// Local Ipv6 address.
1586 #[must_use]
1587 pub fn local_ip_address(&self) -> [u8; 16usize] {
1588 self.local_ip_address
1589 }
1590
1591 /// Remote Ipv6 address.
1592 #[must_use]
1593 pub fn remote_ip_address(&self) -> [u8; 16usize] {
1594 self.remote_ip_address
1595 }
1596
1597 /// Local port number.
1598 #[must_use]
1599 pub fn local_port(&self) -> u16 {
1600 self.local_port
1601 }
1602
1603 /// Remote port number.
1604 #[must_use]
1605 pub fn remote_port(&self) -> u16 {
1606 self.remote_port
1607 }
1608
1609 /// Network protocol. See
1610 /// <https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml>
1611 #[must_use]
1612 pub fn protocol(&self) -> u16 {
1613 self.protocol
1614 }
1615
1616 /// Origin of the local IP address.
1617 #[must_use]
1618 pub fn ip_address_origin(&self) -> device_path::messaging::Ipv6AddressOrigin {
1619 self.ip_address_origin
1620 }
1621
1622 /// Prefix length.
1623 #[must_use]
1624 pub fn prefix_length(&self) -> u8 {
1625 self.prefix_length
1626 }
1627
1628 /// Gateway IP address.
1629 #[must_use]
1630 pub fn gateway_ip_address(&self) -> [u8; 16usize] {
1631 self.gateway_ip_address
1632 }
1633 }
1634
1635 impl fmt::Debug for Ipv6 {
1636 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1637 f.debug_struct("Ipv6")
1638 .field("local_ip_address", &{ self.local_ip_address })
1639 .field("remote_ip_address", &{ self.remote_ip_address })
1640 .field("local_port", &{ self.local_port })
1641 .field("remote_port", &{ self.remote_port })
1642 .field("protocol", &{ self.protocol })
1643 .field("ip_address_origin", &{ self.ip_address_origin })
1644 .field("prefix_length", &{ self.prefix_length })
1645 .field("gateway_ip_address", &{ self.gateway_ip_address })
1646 .finish()
1647 }
1648 }
1649
1650 impl TryFrom<&DevicePathNode> for &Ipv6 {
1651 type Error = NodeConversionError;
1652 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1653 if node.device_type() != DeviceType::MESSAGING
1654 || node.sub_type() != DeviceSubType::MESSAGING_IPV6
1655 {
1656 return Err(NodeConversionError::DifferentType);
1657 }
1658
1659 if size_of_val(node) != size_of::<Ipv6>() {
1660 return Err(NodeConversionError::InvalidLength);
1661 }
1662
1663 let node: *const DevicePathNode = node;
1664 let node: *const Ipv6 = node.cast();
1665 #[expect(clippy::undocumented_unsafe_blocks)]
1666 Ok(unsafe { &*node })
1667 }
1668 }
1669
1670 /// VLAN messaging device path node.
1671 #[repr(C, packed)]
1672 pub struct Vlan {
1673 pub(super) header: DevicePathHeader,
1674 pub(super) vlan_id: u16,
1675 }
1676
1677 impl Vlan {
1678 /// VLAN identifier (0-4094).
1679 #[must_use]
1680 pub fn vlan_id(&self) -> u16 {
1681 self.vlan_id
1682 }
1683 }
1684
1685 impl fmt::Debug for Vlan {
1686 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1687 f.debug_struct("Vlan")
1688 .field("vlan_id", &{ self.vlan_id })
1689 .finish()
1690 }
1691 }
1692
1693 impl TryFrom<&DevicePathNode> for &Vlan {
1694 type Error = NodeConversionError;
1695 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1696 if node.device_type() != DeviceType::MESSAGING
1697 || node.sub_type() != DeviceSubType::MESSAGING_VLAN
1698 {
1699 return Err(NodeConversionError::DifferentType);
1700 }
1701
1702 if size_of_val(node) != size_of::<Vlan>() {
1703 return Err(NodeConversionError::InvalidLength);
1704 }
1705
1706 let node: *const DevicePathNode = node;
1707 let node: *const Vlan = node.cast();
1708 #[expect(clippy::undocumented_unsafe_blocks)]
1709 Ok(unsafe { &*node })
1710 }
1711 }
1712
1713 /// InfiniBand messaging device path node.
1714 #[repr(C, packed)]
1715 pub struct Infiniband {
1716 pub(super) header: DevicePathHeader,
1717 pub(super) resource_flags: device_path::messaging::InfinibandResourceFlags,
1718 pub(super) port_gid: [u8; 16usize],
1719 pub(super) ioc_guid_or_service_id: u64,
1720 pub(super) target_port_id: u64,
1721 pub(super) device_id: u64,
1722 }
1723
1724 impl Infiniband {
1725 /// Flags to identify/manage InfiniBand elements.
1726 #[must_use]
1727 pub fn resource_flags(&self) -> device_path::messaging::InfinibandResourceFlags {
1728 self.resource_flags
1729 }
1730
1731 /// 128-bit Global Identifier for remote fabric port. Note that
1732 /// this is not the same as a UEFI GUID.
1733 #[must_use]
1734 pub fn port_gid(&self) -> [u8; 16usize] {
1735 self.port_gid
1736 }
1737
1738 /// IOC GUID if bit 0 of `resource_flags` is unset, or Service
1739 /// ID if bit 0 of `resource_flags` is set.
1740 #[must_use]
1741 pub fn ioc_guid_or_service_id(&self) -> u64 {
1742 self.ioc_guid_or_service_id
1743 }
1744
1745 /// 64-bit persistent ID of remote IOC port.
1746 #[must_use]
1747 pub fn target_port_id(&self) -> u64 {
1748 self.target_port_id
1749 }
1750
1751 /// 64-bit persistent ID of remote device..
1752 #[must_use]
1753 pub fn device_id(&self) -> u64 {
1754 self.device_id
1755 }
1756 }
1757
1758 impl fmt::Debug for Infiniband {
1759 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1760 f.debug_struct("Infiniband")
1761 .field("resource_flags", &{ self.resource_flags })
1762 .field("port_gid", &{ self.port_gid })
1763 .field("ioc_guid_or_service_id", &{ self.ioc_guid_or_service_id })
1764 .field("target_port_id", &{ self.target_port_id })
1765 .field("device_id", &{ self.device_id })
1766 .finish()
1767 }
1768 }
1769
1770 impl TryFrom<&DevicePathNode> for &Infiniband {
1771 type Error = NodeConversionError;
1772 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1773 if node.device_type() != DeviceType::MESSAGING
1774 || node.sub_type() != DeviceSubType::MESSAGING_INFINIBAND
1775 {
1776 return Err(NodeConversionError::DifferentType);
1777 }
1778
1779 if size_of_val(node) != size_of::<Infiniband>() {
1780 return Err(NodeConversionError::InvalidLength);
1781 }
1782
1783 let node: *const DevicePathNode = node;
1784 let node: *const Infiniband = node.cast();
1785 #[expect(clippy::undocumented_unsafe_blocks)]
1786 Ok(unsafe { &*node })
1787 }
1788 }
1789
1790 /// UART messaging device path node.
1791 #[repr(C, packed)]
1792 pub struct Uart {
1793 pub(super) header: DevicePathHeader,
1794 pub(super) _reserved: u32,
1795 pub(super) baud_rate: u64,
1796 pub(super) data_bits: u8,
1797 pub(super) parity: device_path::messaging::Parity,
1798 pub(super) stop_bits: device_path::messaging::StopBits,
1799 }
1800
1801 impl Uart {
1802 /// Baud rate setting, or 0 to use the device's default.
1803 #[must_use]
1804 pub fn baud_rate(&self) -> u64 {
1805 self.baud_rate
1806 }
1807
1808 /// Number of data bits, or 0 to use the device's default.
1809 #[must_use]
1810 pub fn data_bits(&self) -> u8 {
1811 self.data_bits
1812 }
1813
1814 /// Parity setting.
1815 #[must_use]
1816 pub fn parity(&self) -> device_path::messaging::Parity {
1817 self.parity
1818 }
1819
1820 /// Number of stop bits.
1821 #[must_use]
1822 pub fn stop_bits(&self) -> device_path::messaging::StopBits {
1823 self.stop_bits
1824 }
1825 }
1826
1827 impl fmt::Debug for Uart {
1828 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1829 f.debug_struct("Uart")
1830 .field("_reserved", &{ self._reserved })
1831 .field("baud_rate", &{ self.baud_rate })
1832 .field("data_bits", &{ self.data_bits })
1833 .field("parity", &{ self.parity })
1834 .field("stop_bits", &{ self.stop_bits })
1835 .finish()
1836 }
1837 }
1838
1839 impl TryFrom<&DevicePathNode> for &Uart {
1840 type Error = NodeConversionError;
1841 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1842 if node.device_type() != DeviceType::MESSAGING
1843 || node.sub_type() != DeviceSubType::MESSAGING_UART
1844 {
1845 return Err(NodeConversionError::DifferentType);
1846 }
1847
1848 if size_of_val(node) != size_of::<Uart>() {
1849 return Err(NodeConversionError::InvalidLength);
1850 }
1851
1852 let node: *const DevicePathNode = node;
1853 let node: *const Uart = node.cast();
1854 #[expect(clippy::undocumented_unsafe_blocks)]
1855 Ok(unsafe { &*node })
1856 }
1857 }
1858
1859 /// Vendor-defined messaging device path node.
1860 #[repr(C, packed)]
1861 #[derive(Pointee)]
1862 pub struct Vendor {
1863 pub(super) header: DevicePathHeader,
1864 pub(super) vendor_guid: Guid,
1865 pub(super) vendor_defined_data: [u8],
1866 }
1867
1868 impl Vendor {
1869 /// Vendor-assigned GUID that defines the data that follows.
1870 #[must_use]
1871 pub fn vendor_guid(&self) -> Guid {
1872 self.vendor_guid
1873 }
1874
1875 /// Vendor-defined data.
1876 #[must_use]
1877 pub fn vendor_defined_data(&self) -> &[u8] {
1878 &self.vendor_defined_data
1879 }
1880 }
1881
1882 impl fmt::Debug for Vendor {
1883 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1884 f.debug_struct("Vendor")
1885 .field("vendor_guid", &{ self.vendor_guid })
1886 .field("vendor_defined_data", &{
1887 let ptr = &raw const self.vendor_defined_data;
1888 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
1889 let byte_len = size_of::<u8>() * len;
1890 #[expect(clippy::undocumented_unsafe_blocks)]
1891 unsafe {
1892 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
1893 }
1894 })
1895 .finish()
1896 }
1897 }
1898
1899 impl TryFrom<&DevicePathNode> for &Vendor {
1900 type Error = NodeConversionError;
1901 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1902 if node.device_type() != DeviceType::MESSAGING
1903 || node.sub_type() != DeviceSubType::MESSAGING_VENDOR
1904 {
1905 return Err(NodeConversionError::DifferentType);
1906 }
1907
1908 let static_size = 20usize;
1909 let dst_size = size_of_val(node)
1910 .checked_sub(static_size)
1911 .ok_or(NodeConversionError::InvalidLength)?;
1912 let elem_size = size_of::<u8>();
1913 if dst_size % elem_size != 0 {
1914 return Err(NodeConversionError::InvalidLength);
1915 }
1916
1917 let node: *const DevicePathNode = node;
1918 let node: *const Vendor = ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
1919 #[expect(clippy::undocumented_unsafe_blocks)]
1920 Ok(unsafe { &*node })
1921 }
1922 }
1923
1924 /// Serial Attached SCSI (SAS) extended messaging device path node.
1925 #[repr(C, packed)]
1926 pub struct SasEx {
1927 pub(super) header: DevicePathHeader,
1928 pub(super) sas_address: [u8; 8usize],
1929 pub(super) logical_unit_number: [u8; 8usize],
1930 pub(super) info: u16,
1931 pub(super) relative_target_port: u16,
1932 }
1933
1934 impl SasEx {
1935 /// SAS address.
1936 #[must_use]
1937 pub fn sas_address(&self) -> [u8; 8usize] {
1938 self.sas_address
1939 }
1940
1941 /// Logical Unit Number.
1942 #[must_use]
1943 pub fn logical_unit_number(&self) -> [u8; 8usize] {
1944 self.logical_unit_number
1945 }
1946
1947 /// Information about the device and its interconnect.
1948 #[must_use]
1949 pub fn info(&self) -> u16 {
1950 self.info
1951 }
1952
1953 /// Relative Target Port (RTP).
1954 #[must_use]
1955 pub fn relative_target_port(&self) -> u16 {
1956 self.relative_target_port
1957 }
1958 }
1959
1960 impl fmt::Debug for SasEx {
1961 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1962 f.debug_struct("SasEx")
1963 .field("sas_address", &{ self.sas_address })
1964 .field("logical_unit_number", &{ self.logical_unit_number })
1965 .field("info", &{ self.info })
1966 .field("relative_target_port", &{ self.relative_target_port })
1967 .finish()
1968 }
1969 }
1970
1971 impl TryFrom<&DevicePathNode> for &SasEx {
1972 type Error = NodeConversionError;
1973 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
1974 if node.device_type() != DeviceType::MESSAGING
1975 || node.sub_type() != DeviceSubType::MESSAGING_SCSI_SAS_EX
1976 {
1977 return Err(NodeConversionError::DifferentType);
1978 }
1979
1980 if size_of_val(node) != size_of::<SasEx>() {
1981 return Err(NodeConversionError::InvalidLength);
1982 }
1983
1984 let node: *const DevicePathNode = node;
1985 let node: *const SasEx = node.cast();
1986 #[expect(clippy::undocumented_unsafe_blocks)]
1987 Ok(unsafe { &*node })
1988 }
1989 }
1990
1991 /// iSCSI messaging device path node.
1992 #[repr(C, packed)]
1993 #[derive(Pointee)]
1994 pub struct Iscsi {
1995 pub(super) header: DevicePathHeader,
1996 pub(super) protocol: device_path::messaging::IscsiProtocol,
1997 pub(super) options: device_path::messaging::IscsiLoginOptions,
1998 pub(super) logical_unit_number: [u8; 8usize],
1999 pub(super) target_portal_group_tag: u16,
2000 pub(super) iscsi_target_name: [u8],
2001 }
2002
2003 impl Iscsi {
2004 /// Network protocol.
2005 #[must_use]
2006 pub fn protocol(&self) -> device_path::messaging::IscsiProtocol {
2007 self.protocol
2008 }
2009
2010 /// iSCSI login options (bitfield).
2011 #[must_use]
2012 pub fn options(&self) -> device_path::messaging::IscsiLoginOptions {
2013 self.options
2014 }
2015
2016 /// iSCSI Logical Unit Number.
2017 #[must_use]
2018 pub fn logical_unit_number(&self) -> [u8; 8usize] {
2019 self.logical_unit_number
2020 }
2021
2022 /// iSCSI Target Portal group tag the initiator intends to
2023 /// establish a session with.
2024 #[must_use]
2025 pub fn target_portal_group_tag(&self) -> u16 {
2026 self.target_portal_group_tag
2027 }
2028
2029 /// iSCSI Node Target name.
2030 ///
2031 /// The UEFI Specification does not specify how the string is
2032 /// encoded, but gives one example that appears to be
2033 /// null-terminated ASCII.
2034 #[must_use]
2035 pub fn iscsi_target_name(&self) -> &[u8] {
2036 &self.iscsi_target_name
2037 }
2038 }
2039
2040 impl fmt::Debug for Iscsi {
2041 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2042 f.debug_struct("Iscsi")
2043 .field("protocol", &{ self.protocol })
2044 .field("options", &{ self.options })
2045 .field("logical_unit_number", &{ self.logical_unit_number })
2046 .field("target_portal_group_tag", &{ self.target_portal_group_tag })
2047 .field("iscsi_target_name", &{
2048 let ptr = &raw const self.iscsi_target_name;
2049 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
2050 let byte_len = size_of::<u8>() * len;
2051 #[expect(clippy::undocumented_unsafe_blocks)]
2052 unsafe {
2053 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
2054 }
2055 })
2056 .finish()
2057 }
2058 }
2059
2060 impl TryFrom<&DevicePathNode> for &Iscsi {
2061 type Error = NodeConversionError;
2062 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2063 if node.device_type() != DeviceType::MESSAGING
2064 || node.sub_type() != DeviceSubType::MESSAGING_ISCSI
2065 {
2066 return Err(NodeConversionError::DifferentType);
2067 }
2068
2069 let static_size = 18usize;
2070 let dst_size = size_of_val(node)
2071 .checked_sub(static_size)
2072 .ok_or(NodeConversionError::InvalidLength)?;
2073 let elem_size = size_of::<u8>();
2074 if dst_size % elem_size != 0 {
2075 return Err(NodeConversionError::InvalidLength);
2076 }
2077
2078 let node: *const DevicePathNode = node;
2079 let node: *const Iscsi = ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
2080 #[expect(clippy::undocumented_unsafe_blocks)]
2081 Ok(unsafe { &*node })
2082 }
2083 }
2084
2085 /// NVM Express namespace messaging device path node.
2086 #[repr(C, packed)]
2087 pub struct NvmeNamespace {
2088 pub(super) header: DevicePathHeader,
2089 pub(super) namespace_identifier: u32,
2090 pub(super) ieee_extended_unique_identifier: u64,
2091 }
2092
2093 impl NvmeNamespace {
2094 /// Namespace identifier (NSID). The values 0 and 0xffff_ffff
2095 /// are invalid.
2096 #[must_use]
2097 pub fn namespace_identifier(&self) -> u32 {
2098 self.namespace_identifier
2099 }
2100
2101 /// IEEE Extended Unique Identifier (EUI-64), or 0 if the device
2102 /// does not have a EUI-64.
2103 #[must_use]
2104 pub fn ieee_extended_unique_identifier(&self) -> u64 {
2105 self.ieee_extended_unique_identifier
2106 }
2107 }
2108
2109 impl fmt::Debug for NvmeNamespace {
2110 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2111 f.debug_struct("NvmeNamespace")
2112 .field("namespace_identifier", &{ self.namespace_identifier })
2113 .field("ieee_extended_unique_identifier", &{
2114 self.ieee_extended_unique_identifier
2115 })
2116 .finish()
2117 }
2118 }
2119
2120 impl TryFrom<&DevicePathNode> for &NvmeNamespace {
2121 type Error = NodeConversionError;
2122 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2123 if node.device_type() != DeviceType::MESSAGING
2124 || node.sub_type() != DeviceSubType::MESSAGING_NVME_NAMESPACE
2125 {
2126 return Err(NodeConversionError::DifferentType);
2127 }
2128
2129 if size_of_val(node) != size_of::<NvmeNamespace>() {
2130 return Err(NodeConversionError::InvalidLength);
2131 }
2132
2133 let node: *const DevicePathNode = node;
2134 let node: *const NvmeNamespace = node.cast();
2135 #[expect(clippy::undocumented_unsafe_blocks)]
2136 Ok(unsafe { &*node })
2137 }
2138 }
2139
2140 /// Uniform Resource Identifier (URI) messaging device path node.
2141 #[repr(C, packed)]
2142 #[derive(Pointee)]
2143 pub struct Uri {
2144 pub(super) header: DevicePathHeader,
2145 pub(super) value: [u8],
2146 }
2147
2148 impl Uri {
2149 /// URI as defined by [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986).
2150 #[must_use]
2151 pub fn value(&self) -> &[u8] {
2152 &self.value
2153 }
2154 }
2155
2156 impl fmt::Debug for Uri {
2157 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2158 f.debug_struct("Uri")
2159 .field("value", &{
2160 let ptr = &raw const self.value;
2161 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
2162 let byte_len = size_of::<u8>() * len;
2163 #[expect(clippy::undocumented_unsafe_blocks)]
2164 unsafe {
2165 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
2166 }
2167 })
2168 .finish()
2169 }
2170 }
2171
2172 impl TryFrom<&DevicePathNode> for &Uri {
2173 type Error = NodeConversionError;
2174 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2175 if node.device_type() != DeviceType::MESSAGING
2176 || node.sub_type() != DeviceSubType::MESSAGING_URI
2177 {
2178 return Err(NodeConversionError::DifferentType);
2179 }
2180
2181 let static_size = 4usize;
2182 let dst_size = size_of_val(node)
2183 .checked_sub(static_size)
2184 .ok_or(NodeConversionError::InvalidLength)?;
2185 let elem_size = size_of::<u8>();
2186 if dst_size % elem_size != 0 {
2187 return Err(NodeConversionError::InvalidLength);
2188 }
2189
2190 let node: *const DevicePathNode = node;
2191 let node: *const Uri = ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
2192 #[expect(clippy::undocumented_unsafe_blocks)]
2193 Ok(unsafe { &*node })
2194 }
2195 }
2196
2197 /// Universal Flash Storage (UFS) messaging device path node.
2198 #[repr(C, packed)]
2199 pub struct Ufs {
2200 pub(super) header: DevicePathHeader,
2201 pub(super) target_id: u8,
2202 pub(super) logical_unit_number: u8,
2203 }
2204
2205 impl Ufs {
2206 /// Target ID on the UFS interface (PUN).
2207 #[must_use]
2208 pub fn target_id(&self) -> u8 {
2209 self.target_id
2210 }
2211
2212 /// Logical Unit Number (LUN).
2213 #[must_use]
2214 pub fn logical_unit_number(&self) -> u8 {
2215 self.logical_unit_number
2216 }
2217 }
2218
2219 impl fmt::Debug for Ufs {
2220 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2221 f.debug_struct("Ufs")
2222 .field("target_id", &{ self.target_id })
2223 .field("logical_unit_number", &{ self.logical_unit_number })
2224 .finish()
2225 }
2226 }
2227
2228 impl TryFrom<&DevicePathNode> for &Ufs {
2229 type Error = NodeConversionError;
2230 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2231 if node.device_type() != DeviceType::MESSAGING
2232 || node.sub_type() != DeviceSubType::MESSAGING_UFS
2233 {
2234 return Err(NodeConversionError::DifferentType);
2235 }
2236
2237 if size_of_val(node) != size_of::<Ufs>() {
2238 return Err(NodeConversionError::InvalidLength);
2239 }
2240
2241 let node: *const DevicePathNode = node;
2242 let node: *const Ufs = node.cast();
2243 #[expect(clippy::undocumented_unsafe_blocks)]
2244 Ok(unsafe { &*node })
2245 }
2246 }
2247
2248 /// Secure Digital (SD) messaging device path node.
2249 #[repr(C, packed)]
2250 pub struct Sd {
2251 pub(super) header: DevicePathHeader,
2252 pub(super) slot_number: u8,
2253 }
2254
2255 impl Sd {
2256 /// Slot number.
2257 #[must_use]
2258 pub fn slot_number(&self) -> u8 {
2259 self.slot_number
2260 }
2261 }
2262
2263 impl fmt::Debug for Sd {
2264 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2265 f.debug_struct("Sd")
2266 .field("slot_number", &{ self.slot_number })
2267 .finish()
2268 }
2269 }
2270
2271 impl TryFrom<&DevicePathNode> for &Sd {
2272 type Error = NodeConversionError;
2273 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2274 if node.device_type() != DeviceType::MESSAGING
2275 || node.sub_type() != DeviceSubType::MESSAGING_SD
2276 {
2277 return Err(NodeConversionError::DifferentType);
2278 }
2279
2280 if size_of_val(node) != size_of::<Sd>() {
2281 return Err(NodeConversionError::InvalidLength);
2282 }
2283
2284 let node: *const DevicePathNode = node;
2285 let node: *const Sd = node.cast();
2286 #[expect(clippy::undocumented_unsafe_blocks)]
2287 Ok(unsafe { &*node })
2288 }
2289 }
2290
2291 /// Bluetooth messaging device path node.
2292 #[repr(C, packed)]
2293 pub struct Bluetooth {
2294 pub(super) header: DevicePathHeader,
2295 pub(super) device_address: [u8; 6usize],
2296 }
2297
2298 impl Bluetooth {
2299 /// 48-bit bluetooth device address.
2300 #[must_use]
2301 pub fn device_address(&self) -> [u8; 6usize] {
2302 self.device_address
2303 }
2304 }
2305
2306 impl fmt::Debug for Bluetooth {
2307 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2308 f.debug_struct("Bluetooth")
2309 .field("device_address", &{ self.device_address })
2310 .finish()
2311 }
2312 }
2313
2314 impl TryFrom<&DevicePathNode> for &Bluetooth {
2315 type Error = NodeConversionError;
2316 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2317 if node.device_type() != DeviceType::MESSAGING
2318 || node.sub_type() != DeviceSubType::MESSAGING_BLUETOOTH
2319 {
2320 return Err(NodeConversionError::DifferentType);
2321 }
2322
2323 if size_of_val(node) != size_of::<Bluetooth>() {
2324 return Err(NodeConversionError::InvalidLength);
2325 }
2326
2327 let node: *const DevicePathNode = node;
2328 let node: *const Bluetooth = node.cast();
2329 #[expect(clippy::undocumented_unsafe_blocks)]
2330 Ok(unsafe { &*node })
2331 }
2332 }
2333
2334 /// Wi-Fi messaging device path node.
2335 #[repr(C, packed)]
2336 pub struct Wifi {
2337 pub(super) header: DevicePathHeader,
2338 pub(super) ssid: [u8; 32usize],
2339 }
2340
2341 impl Wifi {
2342 /// Service set identifier (SSID).
2343 #[must_use]
2344 pub fn ssid(&self) -> [u8; 32usize] {
2345 self.ssid
2346 }
2347 }
2348
2349 impl fmt::Debug for Wifi {
2350 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2351 f.debug_struct("Wifi")
2352 .field("ssid", &{ self.ssid })
2353 .finish()
2354 }
2355 }
2356
2357 impl TryFrom<&DevicePathNode> for &Wifi {
2358 type Error = NodeConversionError;
2359 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2360 if node.device_type() != DeviceType::MESSAGING
2361 || node.sub_type() != DeviceSubType::MESSAGING_WIFI
2362 {
2363 return Err(NodeConversionError::DifferentType);
2364 }
2365
2366 if size_of_val(node) != size_of::<Wifi>() {
2367 return Err(NodeConversionError::InvalidLength);
2368 }
2369
2370 let node: *const DevicePathNode = node;
2371 let node: *const Wifi = node.cast();
2372 #[expect(clippy::undocumented_unsafe_blocks)]
2373 Ok(unsafe { &*node })
2374 }
2375 }
2376
2377 /// Embedded Multi-Media Card (eMMC) messaging device path node.
2378 #[repr(C, packed)]
2379 pub struct Emmc {
2380 pub(super) header: DevicePathHeader,
2381 pub(super) slot_number: u8,
2382 }
2383
2384 impl Emmc {
2385 /// Slot number.
2386 #[must_use]
2387 pub fn slot_number(&self) -> u8 {
2388 self.slot_number
2389 }
2390 }
2391
2392 impl fmt::Debug for Emmc {
2393 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2394 f.debug_struct("Emmc")
2395 .field("slot_number", &{ self.slot_number })
2396 .finish()
2397 }
2398 }
2399
2400 impl TryFrom<&DevicePathNode> for &Emmc {
2401 type Error = NodeConversionError;
2402 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2403 if node.device_type() != DeviceType::MESSAGING
2404 || node.sub_type() != DeviceSubType::MESSAGING_EMMC
2405 {
2406 return Err(NodeConversionError::DifferentType);
2407 }
2408
2409 if size_of_val(node) != size_of::<Emmc>() {
2410 return Err(NodeConversionError::InvalidLength);
2411 }
2412
2413 let node: *const DevicePathNode = node;
2414 let node: *const Emmc = node.cast();
2415 #[expect(clippy::undocumented_unsafe_blocks)]
2416 Ok(unsafe { &*node })
2417 }
2418 }
2419
2420 /// BluetoothLE messaging device path node.
2421 #[repr(C, packed)]
2422 pub struct BluetoothLe {
2423 pub(super) header: DevicePathHeader,
2424 pub(super) device_address: [u8; 6usize],
2425 pub(super) address_type: device_path::messaging::BluetoothLeAddressType,
2426 }
2427
2428 impl BluetoothLe {
2429 /// 48-bit bluetooth device address.
2430 #[must_use]
2431 pub fn device_address(&self) -> [u8; 6usize] {
2432 self.device_address
2433 }
2434
2435 /// Address type.
2436 #[must_use]
2437 pub fn address_type(&self) -> device_path::messaging::BluetoothLeAddressType {
2438 self.address_type
2439 }
2440 }
2441
2442 impl fmt::Debug for BluetoothLe {
2443 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2444 f.debug_struct("BluetoothLe")
2445 .field("device_address", &{ self.device_address })
2446 .field("address_type", &{ self.address_type })
2447 .finish()
2448 }
2449 }
2450
2451 impl TryFrom<&DevicePathNode> for &BluetoothLe {
2452 type Error = NodeConversionError;
2453 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2454 if node.device_type() != DeviceType::MESSAGING
2455 || node.sub_type() != DeviceSubType::MESSAGING_BLUETOOTH_LE
2456 {
2457 return Err(NodeConversionError::DifferentType);
2458 }
2459
2460 if size_of_val(node) != size_of::<BluetoothLe>() {
2461 return Err(NodeConversionError::InvalidLength);
2462 }
2463
2464 let node: *const DevicePathNode = node;
2465 let node: *const BluetoothLe = node.cast();
2466 #[expect(clippy::undocumented_unsafe_blocks)]
2467 Ok(unsafe { &*node })
2468 }
2469 }
2470
2471 /// DNS messaging device path node.
2472 #[repr(C, packed)]
2473 #[derive(Pointee)]
2474 pub struct Dns {
2475 pub(super) header: DevicePathHeader,
2476 pub(super) address_type: device_path::messaging::DnsAddressType,
2477 pub(super) addresses: [IpAddress],
2478 }
2479
2480 impl Dns {
2481 /// Whether the addresses are IPv4 or IPv6.
2482 #[must_use]
2483 pub fn address_type(&self) -> device_path::messaging::DnsAddressType {
2484 self.address_type
2485 }
2486
2487 /// One or more instances of the DNS server address.
2488 #[must_use]
2489 pub fn addresses(&self) -> UnalignedSlice<'_, IpAddress> {
2490 let ptr: *const [IpAddress] = &raw const self.addresses;
2491 let (ptr, len): (*const (), usize) = ptr_meta::to_raw_parts(ptr);
2492 #[expect(clippy::undocumented_unsafe_blocks)]
2493 unsafe {
2494 UnalignedSlice::new(ptr.cast::<IpAddress>(), len)
2495 }
2496 }
2497 }
2498
2499 impl fmt::Debug for Dns {
2500 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2501 f.debug_struct("Dns")
2502 .field("address_type", &{ self.address_type })
2503 .field("addresses", &{
2504 let ptr = &raw const self.addresses;
2505 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
2506 let byte_len = size_of::<IpAddress>() * len;
2507 #[expect(clippy::undocumented_unsafe_blocks)]
2508 unsafe {
2509 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
2510 }
2511 })
2512 .finish()
2513 }
2514 }
2515
2516 impl TryFrom<&DevicePathNode> for &Dns {
2517 type Error = NodeConversionError;
2518 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2519 if node.device_type() != DeviceType::MESSAGING
2520 || node.sub_type() != DeviceSubType::MESSAGING_DNS
2521 {
2522 return Err(NodeConversionError::DifferentType);
2523 }
2524
2525 let static_size = 5usize;
2526 let dst_size = size_of_val(node)
2527 .checked_sub(static_size)
2528 .ok_or(NodeConversionError::InvalidLength)?;
2529 let elem_size = size_of::<IpAddress>();
2530 if dst_size % elem_size != 0 {
2531 return Err(NodeConversionError::InvalidLength);
2532 }
2533
2534 let node: *const DevicePathNode = node;
2535 let node: *const Dns = ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
2536 #[expect(clippy::undocumented_unsafe_blocks)]
2537 Ok(unsafe { &*node })
2538 }
2539 }
2540
2541 /// NVDIMM namespace messaging device path node.
2542 #[repr(C, packed)]
2543 pub struct NvdimmNamespace {
2544 pub(super) header: DevicePathHeader,
2545 pub(super) uuid: [u8; 16usize],
2546 }
2547
2548 impl NvdimmNamespace {
2549 /// Namespace unique label identifier.
2550 #[must_use]
2551 pub fn uuid(&self) -> [u8; 16usize] {
2552 self.uuid
2553 }
2554 }
2555
2556 impl fmt::Debug for NvdimmNamespace {
2557 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2558 f.debug_struct("NvdimmNamespace")
2559 .field("uuid", &{ self.uuid })
2560 .finish()
2561 }
2562 }
2563
2564 impl TryFrom<&DevicePathNode> for &NvdimmNamespace {
2565 type Error = NodeConversionError;
2566 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2567 if node.device_type() != DeviceType::MESSAGING
2568 || node.sub_type() != DeviceSubType::MESSAGING_NVDIMM_NAMESPACE
2569 {
2570 return Err(NodeConversionError::DifferentType);
2571 }
2572
2573 if size_of_val(node) != size_of::<NvdimmNamespace>() {
2574 return Err(NodeConversionError::InvalidLength);
2575 }
2576
2577 let node: *const DevicePathNode = node;
2578 let node: *const NvdimmNamespace = node.cast();
2579 #[expect(clippy::undocumented_unsafe_blocks)]
2580 Ok(unsafe { &*node })
2581 }
2582 }
2583
2584 /// REST service messaging device path node.
2585 #[repr(C, packed)]
2586 #[derive(Pointee)]
2587 pub struct RestService {
2588 pub(super) header: DevicePathHeader,
2589 pub(super) service_type: device_path::messaging::RestServiceType,
2590 pub(super) access_mode: device_path::messaging::RestServiceAccessMode,
2591 pub(super) vendor_guid_and_data: [u8],
2592 }
2593
2594 impl RestService {
2595 /// Type of REST service.
2596 #[must_use]
2597 pub fn service_type(&self) -> device_path::messaging::RestServiceType {
2598 self.service_type
2599 }
2600
2601 /// Whether the service is in-band or out-of-band.
2602 #[must_use]
2603 pub fn access_mode(&self) -> device_path::messaging::RestServiceAccessMode {
2604 self.access_mode
2605 }
2606 }
2607
2608 impl fmt::Debug for RestService {
2609 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2610 f.debug_struct("RestService")
2611 .field("service_type", &{ self.service_type })
2612 .field("access_mode", &{ self.access_mode })
2613 .field("vendor_guid_and_data", &{
2614 let ptr = &raw const self.vendor_guid_and_data;
2615 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
2616 let byte_len = size_of::<u8>() * len;
2617 #[expect(clippy::undocumented_unsafe_blocks)]
2618 unsafe {
2619 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
2620 }
2621 })
2622 .finish()
2623 }
2624 }
2625
2626 impl TryFrom<&DevicePathNode> for &RestService {
2627 type Error = NodeConversionError;
2628 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2629 if node.device_type() != DeviceType::MESSAGING
2630 || node.sub_type() != DeviceSubType::MESSAGING_REST_SERVICE
2631 {
2632 return Err(NodeConversionError::DifferentType);
2633 }
2634
2635 let static_size = 6usize;
2636 let dst_size = size_of_val(node)
2637 .checked_sub(static_size)
2638 .ok_or(NodeConversionError::InvalidLength)?;
2639 let elem_size = size_of::<u8>();
2640 if dst_size % elem_size != 0 {
2641 return Err(NodeConversionError::InvalidLength);
2642 }
2643
2644 let node: *const DevicePathNode = node;
2645 let node: *const RestService =
2646 ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
2647 #[expect(clippy::undocumented_unsafe_blocks)]
2648 Ok(unsafe { &*node })
2649 }
2650 }
2651
2652 /// NVME over Fabric (NVMe-oF) namespace messaging device path node.
2653 #[repr(C, packed)]
2654 #[derive(Pointee)]
2655 pub struct NvmeOfNamespace {
2656 pub(super) header: DevicePathHeader,
2657 pub(super) nidt: u8,
2658 pub(super) nid: [u8; 16usize],
2659 pub(super) subsystem_nqn: [u8],
2660 }
2661
2662 impl NvmeOfNamespace {
2663 /// Namespace Identifier Type (NIDT).
2664 #[must_use]
2665 pub fn nidt(&self) -> u8 {
2666 self.nidt
2667 }
2668
2669 /// Namespace Identifier (NID).
2670 #[must_use]
2671 pub fn nid(&self) -> [u8; 16usize] {
2672 self.nid
2673 }
2674
2675 /// Unique identifier of an NVM subsystem stored as a
2676 /// null-terminated UTF-8 string. Maximum length of 224 bytes.
2677 #[must_use]
2678 pub fn subsystem_nqn(&self) -> &[u8] {
2679 &self.subsystem_nqn
2680 }
2681 }
2682
2683 impl fmt::Debug for NvmeOfNamespace {
2684 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2685 f.debug_struct("NvmeOfNamespace")
2686 .field("nidt", &{ self.nidt })
2687 .field("nid", &{ self.nid })
2688 .field("subsystem_nqn", &{
2689 let ptr = &raw const self.subsystem_nqn;
2690 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
2691 let byte_len = size_of::<u8>() * len;
2692 #[expect(clippy::undocumented_unsafe_blocks)]
2693 unsafe {
2694 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
2695 }
2696 })
2697 .finish()
2698 }
2699 }
2700
2701 impl TryFrom<&DevicePathNode> for &NvmeOfNamespace {
2702 type Error = NodeConversionError;
2703 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2704 if node.device_type() != DeviceType::MESSAGING
2705 || node.sub_type() != DeviceSubType::MESSAGING_NVME_OF_NAMESPACE
2706 {
2707 return Err(NodeConversionError::DifferentType);
2708 }
2709
2710 let static_size = 21usize;
2711 let dst_size = size_of_val(node)
2712 .checked_sub(static_size)
2713 .ok_or(NodeConversionError::InvalidLength)?;
2714 let elem_size = size_of::<u8>();
2715 if dst_size % elem_size != 0 {
2716 return Err(NodeConversionError::InvalidLength);
2717 }
2718
2719 let node: *const DevicePathNode = node;
2720 let node: *const NvmeOfNamespace =
2721 ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
2722 #[expect(clippy::undocumented_unsafe_blocks)]
2723 Ok(unsafe { &*node })
2724 }
2725 }
2726
2727 newtype_enum! { # [doc = " Whether the ATAPI device is primary or secondary."] pub enum PrimarySecondary : u8 => { # [doc = " Primary."] PRIMARY = 0x00 , # [doc = " Secondary."] SECONDARY = 0x01 , }
2728
2729 }
2730
2731 newtype_enum! { # [doc = " Whether the ATAPI device is master or slave."] pub enum MasterSlave : u8 => { # [doc = " Master mode."] MASTER = 0x00 , # [doc = " Slave mode."] SLAVE = 0x01 , }
2732
2733 }
2734
2735 newtype_enum! { # [doc = " Origin of the source IP address."] pub enum Ipv4AddressOrigin : u8 => { # [doc = " Source IP address was assigned through DHCP."] DHCP = 0x00 , # [doc = " Source IP address is statically bound."] STATIC = 0x01 , }
2736
2737 }
2738
2739 newtype_enum! { # [doc = " Origin of the local IP address."] pub enum Ipv6AddressOrigin : u8 => { # [doc = " Local IP address was manually configured."] MANUAL = 0x00 , # [doc = " Local IP address assigned through IPv6 stateless"] # [doc = " auto-configuration."] STATELESS_AUTO_CONFIGURATION = 0x01 , # [doc = " Local IP address assigned through IPv6 stateful"] # [doc = " configuration."] STATEFUL_CONFIGURATION = 0x02 , }
2740
2741 }
2742
2743 bitflags! { # [doc = " Flags to identify/manage InfiniBand elements."] # [derive (Clone , Copy , Debug , Default , PartialEq , Eq , PartialOrd , Ord)] # [repr (transparent)] pub struct InfinibandResourceFlags : u32 { # [doc = " Set = service, unset = IOC."] const SERVICE = 0x0000_0001 ; # [doc = " Extended boot environment."] const EXTENDED_BOOT_ENVIRONMENT = 0x0000_0002 ; # [doc = " Console protocol."] const CONSOLE_PROTOCOL = 0x0000_0004 ; # [doc = " Storage protocol."] const STORAGE_PROTOCOL = 0x0000_0008 ; # [doc = " Network protocol."] const NETWORK_PROTOCOL = 0x0000_0010 ; }
2744
2745 }
2746
2747 newtype_enum! { # [doc = " UART parity setting."] pub enum Parity : u8 => { # [doc = " Default parity."] DEFAULT = 0x00 , # [doc = " No parity."] NO = 0x01 , # [doc = " Even parity."] EVEN = 0x02 , # [doc = " Odd parity."] ODD = 0x03 , # [doc = " Mark parity."] MARK = 0x04 , # [doc = " Space parity."] SPACE = 0x05 , }
2748
2749 }
2750
2751 newtype_enum! { # [doc = " UART number of stop bits."] pub enum StopBits : u8 => { # [doc = " Default number of stop bits."] DEFAULT = 0x00 , # [doc = " 1 stop bit."] ONE = 0x01 , # [doc = " 1.5 stop bits."] ONE_POINT_FIVE = 0x02 , # [doc = " 2 stop bits."] TWO = 0x03 , }
2752
2753 }
2754
2755 impl Vendor {
2756 /// PC-ANSI terminal GUID.
2757 pub const PC_ANSI: Guid = guid!("e0c14753-f9be-11d2-9a0c-0090273fc14d");
2758 /// VT-100 terminal GUID.
2759 pub const VT_100: Guid = guid!("dfa66065-b419-11d3-9a2d-0090273fc14d");
2760 /// VT-100+ terminal GUID.
2761 pub const VT_100_PLUS: Guid = guid!("7baec70b-57e0-4c76-8e87-2f9e28088343");
2762 /// VT-UTF8 terminal GUID.
2763 pub const VT_UTF8: Guid = guid!("ad15a0d6-8bec-4acf-a073-d01de77e2d88");
2764 }
2765
2766 newtype_enum! { # [doc = " iSCSI network protocol."] pub enum IscsiProtocol : u16 => { # [doc = " TCP."] TCP = 0x0000 , }
2767
2768 }
2769
2770 bitflags! { # [doc = " iSCSI login options."] # [derive (Clone , Copy , Debug , Default , PartialEq , Eq , PartialOrd , Ord)] # [repr (transparent)] pub struct IscsiLoginOptions : u16 { # [doc = " Header digest using CRC32. If not set, no header digest."] const HEADER_DIGEST_USING_CRC32 = 0x0002 ; # [doc = " Data digest using CRC32. If not set, no data digest."] const DATA_DIGEST_USING_CRC32 = 0x0008 ; # [doc = " Auth method none. If not set, auth method CHAP."] const AUTH_METHOD_NONE = 0x0800 ; # [doc = " CHAP UNI. If not set, CHAP BI."] const CHAP_UNI = 0x1000 ; }
2771
2772 }
2773
2774 newtype_enum! { # [doc = " BluetoothLE address type."] pub enum BluetoothLeAddressType : u8 => { # [doc = " Public device address."] PUBLIC = 0x00 , # [doc = " Random device address."] RANDOM = 0x01 , }
2775
2776 }
2777
2778 newtype_enum! { # [doc = " Whether the address is IPv4 or IPv6."] pub enum DnsAddressType : u8 => { # [doc = " DNS server address is IPv4."] IPV4 = 0x00 , # [doc = " DNS server address is IPv6."] IPV6 = 0x01 , }
2779
2780 }
2781
2782 impl RestService {
2783 /// Get the vendor GUID and vendor data. Only used if the
2784 /// service type is [`VENDOR`], otherwise returns None.
2785 ///
2786 /// [`VENDOR`]: uefi::proto::device_path::messaging::RestServiceType
2787 #[must_use]
2788 pub fn vendor_guid_and_data(&self) -> Option<(Guid, &[u8])> {
2789 if self.service_type == RestServiceType::VENDOR
2790 && self.vendor_guid_and_data.len() >= size_of::<Guid>()
2791 {
2792 let (guid, data) = self.vendor_guid_and_data.split_at(size_of::<Guid>());
2793 let guid: [u8; 16] = guid.try_into().unwrap();
2794 Some((Guid::from_bytes(guid), data))
2795 } else {
2796 None
2797 }
2798 }
2799 }
2800
2801 newtype_enum! { # [doc = " Type of REST service."] pub enum RestServiceType : u8 => { # [doc = " Redfish REST service."] REDFISH = 0x01 , # [doc = " OData REST service."] ODATA = 0x02 , # [doc = " Vendor-specific REST service."] VENDOR = 0xff , }
2802
2803 }
2804
2805 newtype_enum! { # [doc = " Whether the service is in-band or out-of-band."] pub enum RestServiceAccessMode : u8 => { # [doc = " In-band REST service."] IN_BAND = 0x01 , # [doc = " Out-of-band REST service."] OUT_OF_BAND = 0x02 , }
2806
2807 }
2808}
2809
2810/// Device path nodes for [`DeviceType::MEDIA`].
2811pub mod media {
2812 use super::*;
2813 /// Hard drive media device path node.
2814 #[repr(C, packed)]
2815 pub struct HardDrive {
2816 pub(super) header: DevicePathHeader,
2817 pub(super) partition_number: u32,
2818 pub(super) partition_start: u64,
2819 pub(super) partition_size: u64,
2820 pub(super) partition_signature: [u8; 16usize],
2821 pub(super) partition_format: device_path::media::PartitionFormat,
2822 pub(super) signature_type: u8,
2823 }
2824
2825 impl HardDrive {
2826 /// Index of the partition, starting from 1.
2827 #[must_use]
2828 pub fn partition_number(&self) -> u32 {
2829 self.partition_number
2830 }
2831
2832 /// Starting LBA (logical block address) of the partition.
2833 #[must_use]
2834 pub fn partition_start(&self) -> u64 {
2835 self.partition_start
2836 }
2837
2838 /// Size of the partition in blocks.
2839 #[must_use]
2840 pub fn partition_size(&self) -> u64 {
2841 self.partition_size
2842 }
2843
2844 /// Partition format.
2845 #[must_use]
2846 pub fn partition_format(&self) -> device_path::media::PartitionFormat {
2847 self.partition_format
2848 }
2849 }
2850
2851 impl fmt::Debug for HardDrive {
2852 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2853 f.debug_struct("HardDrive")
2854 .field("partition_number", &{ self.partition_number })
2855 .field("partition_start", &{ self.partition_start })
2856 .field("partition_size", &{ self.partition_size })
2857 .field("partition_signature", &{ self.partition_signature })
2858 .field("partition_format", &{ self.partition_format })
2859 .field("signature_type", &{ self.signature_type })
2860 .finish()
2861 }
2862 }
2863
2864 impl TryFrom<&DevicePathNode> for &HardDrive {
2865 type Error = NodeConversionError;
2866 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2867 if node.device_type() != DeviceType::MEDIA
2868 || node.sub_type() != DeviceSubType::MEDIA_HARD_DRIVE
2869 {
2870 return Err(NodeConversionError::DifferentType);
2871 }
2872
2873 if size_of_val(node) != size_of::<HardDrive>() {
2874 return Err(NodeConversionError::InvalidLength);
2875 }
2876
2877 let node: *const DevicePathNode = node;
2878 let node: *const HardDrive = node.cast();
2879 #[expect(clippy::undocumented_unsafe_blocks)]
2880 Ok(unsafe { &*node })
2881 }
2882 }
2883
2884 /// CD-ROM media device path node.
2885 #[repr(C, packed)]
2886 pub struct CdRom {
2887 pub(super) header: DevicePathHeader,
2888 pub(super) boot_entry: u32,
2889 pub(super) partition_start: u64,
2890 pub(super) partition_size: u64,
2891 }
2892
2893 impl CdRom {
2894 /// Boot entry number from the boot catalog, or 0 for the
2895 /// default entry.
2896 #[must_use]
2897 pub fn boot_entry(&self) -> u32 {
2898 self.boot_entry
2899 }
2900
2901 /// Starting RBA (Relative logical Block Address).
2902 #[must_use]
2903 pub fn partition_start(&self) -> u64 {
2904 self.partition_start
2905 }
2906
2907 /// Size of the partition in blocks.
2908 #[must_use]
2909 pub fn partition_size(&self) -> u64 {
2910 self.partition_size
2911 }
2912 }
2913
2914 impl fmt::Debug for CdRom {
2915 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2916 f.debug_struct("CdRom")
2917 .field("boot_entry", &{ self.boot_entry })
2918 .field("partition_start", &{ self.partition_start })
2919 .field("partition_size", &{ self.partition_size })
2920 .finish()
2921 }
2922 }
2923
2924 impl TryFrom<&DevicePathNode> for &CdRom {
2925 type Error = NodeConversionError;
2926 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2927 if node.device_type() != DeviceType::MEDIA
2928 || node.sub_type() != DeviceSubType::MEDIA_CD_ROM
2929 {
2930 return Err(NodeConversionError::DifferentType);
2931 }
2932
2933 if size_of_val(node) != size_of::<CdRom>() {
2934 return Err(NodeConversionError::InvalidLength);
2935 }
2936
2937 let node: *const DevicePathNode = node;
2938 let node: *const CdRom = node.cast();
2939 #[expect(clippy::undocumented_unsafe_blocks)]
2940 Ok(unsafe { &*node })
2941 }
2942 }
2943
2944 /// Vendor-defined media device path node.
2945 #[repr(C, packed)]
2946 #[derive(Pointee)]
2947 pub struct Vendor {
2948 pub(super) header: DevicePathHeader,
2949 pub(super) vendor_guid: Guid,
2950 pub(super) vendor_defined_data: [u8],
2951 }
2952
2953 impl Vendor {
2954 /// Vendor-assigned GUID that defines the data that follows.
2955 #[must_use]
2956 pub fn vendor_guid(&self) -> Guid {
2957 self.vendor_guid
2958 }
2959
2960 /// Vendor-defined data.
2961 #[must_use]
2962 pub fn vendor_defined_data(&self) -> &[u8] {
2963 &self.vendor_defined_data
2964 }
2965 }
2966
2967 impl fmt::Debug for Vendor {
2968 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2969 f.debug_struct("Vendor")
2970 .field("vendor_guid", &{ self.vendor_guid })
2971 .field("vendor_defined_data", &{
2972 let ptr = &raw const self.vendor_defined_data;
2973 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
2974 let byte_len = size_of::<u8>() * len;
2975 #[expect(clippy::undocumented_unsafe_blocks)]
2976 unsafe {
2977 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
2978 }
2979 })
2980 .finish()
2981 }
2982 }
2983
2984 impl TryFrom<&DevicePathNode> for &Vendor {
2985 type Error = NodeConversionError;
2986 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
2987 if node.device_type() != DeviceType::MEDIA
2988 || node.sub_type() != DeviceSubType::MEDIA_VENDOR
2989 {
2990 return Err(NodeConversionError::DifferentType);
2991 }
2992
2993 let static_size = 20usize;
2994 let dst_size = size_of_val(node)
2995 .checked_sub(static_size)
2996 .ok_or(NodeConversionError::InvalidLength)?;
2997 let elem_size = size_of::<u8>();
2998 if dst_size % elem_size != 0 {
2999 return Err(NodeConversionError::InvalidLength);
3000 }
3001
3002 let node: *const DevicePathNode = node;
3003 let node: *const Vendor = ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
3004 #[expect(clippy::undocumented_unsafe_blocks)]
3005 Ok(unsafe { &*node })
3006 }
3007 }
3008
3009 /// File path media device path node.
3010 #[repr(C, packed)]
3011 #[derive(Pointee)]
3012 pub struct FilePath {
3013 pub(super) header: DevicePathHeader,
3014 pub(super) path_name: [u16],
3015 }
3016
3017 impl FilePath {
3018 /// Null-terminated path.
3019 #[must_use]
3020 pub fn path_name(&self) -> UnalignedSlice<'_, u16> {
3021 let ptr: *const [u16] = &raw const self.path_name;
3022 let (ptr, len): (*const (), usize) = ptr_meta::to_raw_parts(ptr);
3023 #[expect(clippy::undocumented_unsafe_blocks)]
3024 unsafe {
3025 UnalignedSlice::new(ptr.cast::<u16>(), len)
3026 }
3027 }
3028 }
3029
3030 impl fmt::Debug for FilePath {
3031 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3032 f.debug_struct("FilePath")
3033 .field("path_name", &{
3034 let ptr = &raw const self.path_name;
3035 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
3036 let byte_len = size_of::<u16>() * len;
3037 #[expect(clippy::undocumented_unsafe_blocks)]
3038 unsafe {
3039 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
3040 }
3041 })
3042 .finish()
3043 }
3044 }
3045
3046 impl TryFrom<&DevicePathNode> for &FilePath {
3047 type Error = NodeConversionError;
3048 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
3049 if node.device_type() != DeviceType::MEDIA
3050 || node.sub_type() != DeviceSubType::MEDIA_FILE_PATH
3051 {
3052 return Err(NodeConversionError::DifferentType);
3053 }
3054
3055 let static_size = 4usize;
3056 let dst_size = size_of_val(node)
3057 .checked_sub(static_size)
3058 .ok_or(NodeConversionError::InvalidLength)?;
3059 let elem_size = size_of::<u16>();
3060 if dst_size % elem_size != 0 {
3061 return Err(NodeConversionError::InvalidLength);
3062 }
3063
3064 let node: *const DevicePathNode = node;
3065 let node: *const FilePath = ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
3066 #[expect(clippy::undocumented_unsafe_blocks)]
3067 Ok(unsafe { &*node })
3068 }
3069 }
3070
3071 /// Media protocol media device path node.
3072 #[repr(C, packed)]
3073 pub struct Protocol {
3074 pub(super) header: DevicePathHeader,
3075 pub(super) protocol_guid: Guid,
3076 }
3077
3078 impl Protocol {
3079 /// The ID of the protocol.
3080 #[must_use]
3081 pub fn protocol_guid(&self) -> Guid {
3082 self.protocol_guid
3083 }
3084 }
3085
3086 impl fmt::Debug for Protocol {
3087 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3088 f.debug_struct("Protocol")
3089 .field("protocol_guid", &{ self.protocol_guid })
3090 .finish()
3091 }
3092 }
3093
3094 impl TryFrom<&DevicePathNode> for &Protocol {
3095 type Error = NodeConversionError;
3096 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
3097 if node.device_type() != DeviceType::MEDIA
3098 || node.sub_type() != DeviceSubType::MEDIA_PROTOCOL
3099 {
3100 return Err(NodeConversionError::DifferentType);
3101 }
3102
3103 if size_of_val(node) != size_of::<Protocol>() {
3104 return Err(NodeConversionError::InvalidLength);
3105 }
3106
3107 let node: *const DevicePathNode = node;
3108 let node: *const Protocol = node.cast();
3109 #[expect(clippy::undocumented_unsafe_blocks)]
3110 Ok(unsafe { &*node })
3111 }
3112 }
3113
3114 /// PIWG firmware file media device path node.
3115 #[repr(C, packed)]
3116 #[derive(Pointee)]
3117 pub struct PiwgFirmwareFile {
3118 pub(super) header: DevicePathHeader,
3119 pub(super) data: [u8],
3120 }
3121
3122 impl PiwgFirmwareFile {
3123 /// Contents are defined in the UEFI PI Specification.
3124 #[must_use]
3125 pub fn data(&self) -> &[u8] {
3126 &self.data
3127 }
3128 }
3129
3130 impl fmt::Debug for PiwgFirmwareFile {
3131 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3132 f.debug_struct("PiwgFirmwareFile")
3133 .field("data", &{
3134 let ptr = &raw const self.data;
3135 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
3136 let byte_len = size_of::<u8>() * len;
3137 #[expect(clippy::undocumented_unsafe_blocks)]
3138 unsafe {
3139 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
3140 }
3141 })
3142 .finish()
3143 }
3144 }
3145
3146 impl TryFrom<&DevicePathNode> for &PiwgFirmwareFile {
3147 type Error = NodeConversionError;
3148 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
3149 if node.device_type() != DeviceType::MEDIA
3150 || node.sub_type() != DeviceSubType::MEDIA_PIWG_FIRMWARE_FILE
3151 {
3152 return Err(NodeConversionError::DifferentType);
3153 }
3154
3155 let static_size = 4usize;
3156 let dst_size = size_of_val(node)
3157 .checked_sub(static_size)
3158 .ok_or(NodeConversionError::InvalidLength)?;
3159 let elem_size = size_of::<u8>();
3160 if dst_size % elem_size != 0 {
3161 return Err(NodeConversionError::InvalidLength);
3162 }
3163
3164 let node: *const DevicePathNode = node;
3165 let node: *const PiwgFirmwareFile =
3166 ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
3167 #[expect(clippy::undocumented_unsafe_blocks)]
3168 Ok(unsafe { &*node })
3169 }
3170 }
3171
3172 /// PIWG firmware volume media device path node.
3173 #[repr(C, packed)]
3174 #[derive(Pointee)]
3175 pub struct PiwgFirmwareVolume {
3176 pub(super) header: DevicePathHeader,
3177 pub(super) data: [u8],
3178 }
3179
3180 impl PiwgFirmwareVolume {
3181 /// Contents are defined in the UEFI PI Specification.
3182 #[must_use]
3183 pub fn data(&self) -> &[u8] {
3184 &self.data
3185 }
3186 }
3187
3188 impl fmt::Debug for PiwgFirmwareVolume {
3189 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3190 f.debug_struct("PiwgFirmwareVolume")
3191 .field("data", &{
3192 let ptr = &raw const self.data;
3193 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
3194 let byte_len = size_of::<u8>() * len;
3195 #[expect(clippy::undocumented_unsafe_blocks)]
3196 unsafe {
3197 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
3198 }
3199 })
3200 .finish()
3201 }
3202 }
3203
3204 impl TryFrom<&DevicePathNode> for &PiwgFirmwareVolume {
3205 type Error = NodeConversionError;
3206 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
3207 if node.device_type() != DeviceType::MEDIA
3208 || node.sub_type() != DeviceSubType::MEDIA_PIWG_FIRMWARE_VOLUME
3209 {
3210 return Err(NodeConversionError::DifferentType);
3211 }
3212
3213 let static_size = 4usize;
3214 let dst_size = size_of_val(node)
3215 .checked_sub(static_size)
3216 .ok_or(NodeConversionError::InvalidLength)?;
3217 let elem_size = size_of::<u8>();
3218 if dst_size % elem_size != 0 {
3219 return Err(NodeConversionError::InvalidLength);
3220 }
3221
3222 let node: *const DevicePathNode = node;
3223 let node: *const PiwgFirmwareVolume =
3224 ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
3225 #[expect(clippy::undocumented_unsafe_blocks)]
3226 Ok(unsafe { &*node })
3227 }
3228 }
3229
3230 /// Relative offset range media device path node.
3231 #[repr(C, packed)]
3232 pub struct RelativeOffsetRange {
3233 pub(super) header: DevicePathHeader,
3234 pub(super) _reserved: u32,
3235 pub(super) starting_offset: u64,
3236 pub(super) ending_offset: u64,
3237 }
3238
3239 impl RelativeOffsetRange {
3240 /// Offset of the first byte, relative to the parent device node.
3241 #[must_use]
3242 pub fn starting_offset(&self) -> u64 {
3243 self.starting_offset
3244 }
3245
3246 /// Offset of the last byte, relative to the parent device node.
3247 #[must_use]
3248 pub fn ending_offset(&self) -> u64 {
3249 self.ending_offset
3250 }
3251 }
3252
3253 impl fmt::Debug for RelativeOffsetRange {
3254 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3255 f.debug_struct("RelativeOffsetRange")
3256 .field("_reserved", &{ self._reserved })
3257 .field("starting_offset", &{ self.starting_offset })
3258 .field("ending_offset", &{ self.ending_offset })
3259 .finish()
3260 }
3261 }
3262
3263 impl TryFrom<&DevicePathNode> for &RelativeOffsetRange {
3264 type Error = NodeConversionError;
3265 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
3266 if node.device_type() != DeviceType::MEDIA
3267 || node.sub_type() != DeviceSubType::MEDIA_RELATIVE_OFFSET_RANGE
3268 {
3269 return Err(NodeConversionError::DifferentType);
3270 }
3271
3272 if size_of_val(node) != size_of::<RelativeOffsetRange>() {
3273 return Err(NodeConversionError::InvalidLength);
3274 }
3275
3276 let node: *const DevicePathNode = node;
3277 let node: *const RelativeOffsetRange = node.cast();
3278 #[expect(clippy::undocumented_unsafe_blocks)]
3279 Ok(unsafe { &*node })
3280 }
3281 }
3282
3283 /// RAM disk media device path node.
3284 #[repr(C, packed)]
3285 pub struct RamDisk {
3286 pub(super) header: DevicePathHeader,
3287 pub(super) starting_address: u64,
3288 pub(super) ending_address: u64,
3289 pub(super) disk_type: device_path::media::RamDiskType,
3290 pub(super) disk_instance: u16,
3291 }
3292
3293 impl RamDisk {
3294 /// Starting memory address.
3295 #[must_use]
3296 pub fn starting_address(&self) -> u64 {
3297 self.starting_address
3298 }
3299
3300 /// Ending memory address.
3301 #[must_use]
3302 pub fn ending_address(&self) -> u64 {
3303 self.ending_address
3304 }
3305
3306 /// Type of RAM disk.
3307 #[must_use]
3308 pub fn disk_type(&self) -> device_path::media::RamDiskType {
3309 self.disk_type
3310 }
3311
3312 /// RAM disk instance number if supported, otherwise 0.
3313 #[must_use]
3314 pub fn disk_instance(&self) -> u16 {
3315 self.disk_instance
3316 }
3317 }
3318
3319 impl fmt::Debug for RamDisk {
3320 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3321 f.debug_struct("RamDisk")
3322 .field("starting_address", &{ self.starting_address })
3323 .field("ending_address", &{ self.ending_address })
3324 .field("disk_type", &{ self.disk_type })
3325 .field("disk_instance", &{ self.disk_instance })
3326 .finish()
3327 }
3328 }
3329
3330 impl TryFrom<&DevicePathNode> for &RamDisk {
3331 type Error = NodeConversionError;
3332 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
3333 if node.device_type() != DeviceType::MEDIA
3334 || node.sub_type() != DeviceSubType::MEDIA_RAM_DISK
3335 {
3336 return Err(NodeConversionError::DifferentType);
3337 }
3338
3339 if size_of_val(node) != size_of::<RamDisk>() {
3340 return Err(NodeConversionError::InvalidLength);
3341 }
3342
3343 let node: *const DevicePathNode = node;
3344 let node: *const RamDisk = node.cast();
3345 #[expect(clippy::undocumented_unsafe_blocks)]
3346 Ok(unsafe { &*node })
3347 }
3348 }
3349
3350 impl HardDrive {
3351 /// Signature unique to this partition.
3352 #[must_use]
3353 pub fn partition_signature(&self) -> PartitionSignature {
3354 match self.signature_type {
3355 0 => PartitionSignature::None,
3356 1 => PartitionSignature::Mbr([
3357 self.partition_signature[0],
3358 self.partition_signature[1],
3359 self.partition_signature[2],
3360 self.partition_signature[3],
3361 ]),
3362 2 => PartitionSignature::Guid(Guid::from_bytes(self.partition_signature)),
3363 unknown => PartitionSignature::Unknown {
3364 signature_type: unknown,
3365 signature: self.partition_signature,
3366 },
3367 }
3368 }
3369 }
3370
3371 /// Hard drive partition signature.
3372 #[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd)]
3373 pub enum PartitionSignature {
3374 /// No disk signature.
3375 None,
3376 /// 32-bit MBR partition signature.
3377 Mbr([u8; 4]),
3378 /// 128-bit GUID partition signature.
3379 Guid(Guid),
3380 /// Unknown signature type not listed in the UEFI Specification.
3381 Unknown {
3382 /// Signature type.
3383 signature_type: u8,
3384 /// Signature data.
3385 signature: [u8; 16],
3386 },
3387 }
3388
3389 newtype_enum! { # [doc = " Hard drive partition format."] pub enum PartitionFormat : u8 => { # [doc = " MBR (PC-AT compatible Master Boot Record) format."] MBR = 0x01 , # [doc = " GPT (GUID Partition Table) format."] GPT = 0x02 , }
3390
3391 }
3392
3393 newtype_enum! { # [doc = " RAM disk type."] pub enum RamDiskType : Guid => { # [doc = " RAM disk with a raw disk format in volatile memory."] VIRTUAL_DISK = guid ! ("77ab535a-45fc-624b-5560-f7b281d1f96e") , # [doc = " RAM disk of an ISO image in volatile memory."] VIRTUAL_CD = guid ! ("3d5abd30-4175-87ce-6d64-d2ade523c4bb") , # [doc = " RAM disk with a raw disk format in persistent memory."] PERSISTENT_VIRTUAL_DISK = guid ! ("5cea02c9-4d07-69d3-269f-4496fbe096f9") , # [doc = " RAM disk of an ISO image in persistent memory."] PERSISTENT_VIRTUAL_CD = guid ! ("08018188-42cd-bb48-100f-5387d53ded3d") , }
3394
3395 }
3396}
3397
3398/// Device path nodes for [`DeviceType::BIOS_BOOT_SPEC`].
3399pub mod bios_boot_spec {
3400 use super::*;
3401 /// BIOS Boot Specification device path node.
3402 #[repr(C, packed)]
3403 #[derive(Pointee)]
3404 pub struct BootSpecification {
3405 pub(super) header: DevicePathHeader,
3406 pub(super) device_type: u16,
3407 pub(super) status_flag: u16,
3408 pub(super) description_string: [u8],
3409 }
3410
3411 impl BootSpecification {
3412 /// Device type as defined by the BIOS Boot Specification.
3413 #[must_use]
3414 pub fn device_type(&self) -> u16 {
3415 self.device_type
3416 }
3417
3418 /// Status flags as defined by the BIOS Boot Specification.
3419 #[must_use]
3420 pub fn status_flag(&self) -> u16 {
3421 self.status_flag
3422 }
3423
3424 /// Description of the boot device encoded as a null-terminated
3425 /// ASCII string.
3426 #[must_use]
3427 pub fn description_string(&self) -> &[u8] {
3428 &self.description_string
3429 }
3430 }
3431
3432 impl fmt::Debug for BootSpecification {
3433 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
3434 f.debug_struct("BootSpecification")
3435 .field("device_type", &{ self.device_type })
3436 .field("status_flag", &{ self.status_flag })
3437 .field("description_string", &{
3438 let ptr = &raw const self.description_string;
3439 let (ptr, len) = ptr_meta::to_raw_parts(ptr);
3440 let byte_len = size_of::<u8>() * len;
3441 #[expect(clippy::undocumented_unsafe_blocks)]
3442 unsafe {
3443 slice::from_raw_parts(ptr.cast::<u8>(), byte_len)
3444 }
3445 })
3446 .finish()
3447 }
3448 }
3449
3450 impl TryFrom<&DevicePathNode> for &BootSpecification {
3451 type Error = NodeConversionError;
3452 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
3453 if node.device_type() != DeviceType::BIOS_BOOT_SPEC
3454 || node.sub_type() != DeviceSubType::BIOS_BOOT_SPECIFICATION
3455 {
3456 return Err(NodeConversionError::DifferentType);
3457 }
3458
3459 let static_size = 8usize;
3460 let dst_size = size_of_val(node)
3461 .checked_sub(static_size)
3462 .ok_or(NodeConversionError::InvalidLength)?;
3463 let elem_size = size_of::<u8>();
3464 if dst_size % elem_size != 0 {
3465 return Err(NodeConversionError::InvalidLength);
3466 }
3467
3468 let node: *const DevicePathNode = node;
3469 let node: *const BootSpecification =
3470 ptr_meta::from_raw_parts(node.cast(), dst_size / elem_size);
3471 #[expect(clippy::undocumented_unsafe_blocks)]
3472 Ok(unsafe { &*node })
3473 }
3474 }
3475}
3476
3477/// Enum of references to all the different device path node
3478/// types. Return type of [`DevicePathNode::as_enum`].
3479#[derive(Debug)]
3480pub enum DevicePathNodeEnum<'a> {
3481 /// Node that terminates a [`DevicePathInstance`].
3482 ///
3483 /// [`DevicePathInstance`]: device_path::DevicePathInstance
3484 EndInstance(&'a end::Instance),
3485 /// Node that terminates an entire [`DevicePath`].
3486 ///
3487 /// [`DevicePath`]: device_path::DevicePath
3488 EndEntire(&'a end::Entire),
3489 /// PCI hardware device path node.
3490 HardwarePci(&'a hardware::Pci),
3491 /// PCCARD hardware device path node.
3492 HardwarePccard(&'a hardware::Pccard),
3493 /// Memory mapped hardware device path node.
3494 HardwareMemoryMapped(&'a hardware::MemoryMapped),
3495 /// Vendor-defined hardware device path node.
3496 HardwareVendor(&'a hardware::Vendor),
3497 /// Controller hardware device path node.
3498 HardwareController(&'a hardware::Controller),
3499 /// Baseboard Management Controller (BMC) host interface hardware
3500 /// device path node.
3501 HardwareBmc(&'a hardware::Bmc),
3502 /// ACPI device path node.
3503 AcpiAcpi(&'a acpi::Acpi),
3504 /// Expanded ACPI device path node.
3505 AcpiExpanded(&'a acpi::Expanded),
3506 /// ADR ACPI device path node.
3507 AcpiAdr(&'a acpi::Adr),
3508 /// NVDIMM ACPI device path node.
3509 AcpiNvdimm(&'a acpi::Nvdimm),
3510 /// ATAPI messaging device path node.
3511 MessagingAtapi(&'a messaging::Atapi),
3512 /// SCSI messaging device path node.
3513 MessagingScsi(&'a messaging::Scsi),
3514 /// Fibre channel messaging device path node.
3515 MessagingFibreChannel(&'a messaging::FibreChannel),
3516 /// Fibre channel extended messaging device path node.
3517 MessagingFibreChannelEx(&'a messaging::FibreChannelEx),
3518 /// 1394 messaging device path node.
3519 MessagingIeee1394(&'a messaging::Ieee1394),
3520 /// USB messaging device path node.
3521 MessagingUsb(&'a messaging::Usb),
3522 /// SATA messaging device path node.
3523 MessagingSata(&'a messaging::Sata),
3524 /// USB World Wide ID (WWID) messaging device path node.
3525 MessagingUsbWwid(&'a messaging::UsbWwid),
3526 /// Device logical unit messaging device path node.
3527 MessagingDeviceLogicalUnit(&'a messaging::DeviceLogicalUnit),
3528 /// USB class messaging device path node.
3529 MessagingUsbClass(&'a messaging::UsbClass),
3530 /// I2O messaging device path node.
3531 MessagingI2o(&'a messaging::I2o),
3532 /// MAC address messaging device path node.
3533 MessagingMacAddress(&'a messaging::MacAddress),
3534 /// IPv4 messaging device path node.
3535 MessagingIpv4(&'a messaging::Ipv4),
3536 /// IPv6 messaging device path node.
3537 MessagingIpv6(&'a messaging::Ipv6),
3538 /// VLAN messaging device path node.
3539 MessagingVlan(&'a messaging::Vlan),
3540 /// InfiniBand messaging device path node.
3541 MessagingInfiniband(&'a messaging::Infiniband),
3542 /// UART messaging device path node.
3543 MessagingUart(&'a messaging::Uart),
3544 /// Vendor-defined messaging device path node.
3545 MessagingVendor(&'a messaging::Vendor),
3546 /// Serial Attached SCSI (SAS) extended messaging device path node.
3547 MessagingSasEx(&'a messaging::SasEx),
3548 /// iSCSI messaging device path node.
3549 MessagingIscsi(&'a messaging::Iscsi),
3550 /// NVM Express namespace messaging device path node.
3551 MessagingNvmeNamespace(&'a messaging::NvmeNamespace),
3552 /// Uniform Resource Identifier (URI) messaging device path node.
3553 MessagingUri(&'a messaging::Uri),
3554 /// Universal Flash Storage (UFS) messaging device path node.
3555 MessagingUfs(&'a messaging::Ufs),
3556 /// Secure Digital (SD) messaging device path node.
3557 MessagingSd(&'a messaging::Sd),
3558 /// Bluetooth messaging device path node.
3559 MessagingBluetooth(&'a messaging::Bluetooth),
3560 /// Wi-Fi messaging device path node.
3561 MessagingWifi(&'a messaging::Wifi),
3562 /// Embedded Multi-Media Card (eMMC) messaging device path node.
3563 MessagingEmmc(&'a messaging::Emmc),
3564 /// BluetoothLE messaging device path node.
3565 MessagingBluetoothLe(&'a messaging::BluetoothLe),
3566 /// DNS messaging device path node.
3567 MessagingDns(&'a messaging::Dns),
3568 /// NVDIMM namespace messaging device path node.
3569 MessagingNvdimmNamespace(&'a messaging::NvdimmNamespace),
3570 /// REST service messaging device path node.
3571 MessagingRestService(&'a messaging::RestService),
3572 /// NVME over Fabric (NVMe-oF) namespace messaging device path node.
3573 MessagingNvmeOfNamespace(&'a messaging::NvmeOfNamespace),
3574 /// Hard drive media device path node.
3575 MediaHardDrive(&'a media::HardDrive),
3576 /// CD-ROM media device path node.
3577 MediaCdRom(&'a media::CdRom),
3578 /// Vendor-defined media device path node.
3579 MediaVendor(&'a media::Vendor),
3580 /// File path media device path node.
3581 MediaFilePath(&'a media::FilePath),
3582 /// Media protocol media device path node.
3583 MediaProtocol(&'a media::Protocol),
3584 /// PIWG firmware file media device path node.
3585 MediaPiwgFirmwareFile(&'a media::PiwgFirmwareFile),
3586 /// PIWG firmware volume media device path node.
3587 MediaPiwgFirmwareVolume(&'a media::PiwgFirmwareVolume),
3588 /// Relative offset range media device path node.
3589 MediaRelativeOffsetRange(&'a media::RelativeOffsetRange),
3590 /// RAM disk media device path node.
3591 MediaRamDisk(&'a media::RamDisk),
3592 /// BIOS Boot Specification device path node.
3593 BiosBootSpecBootSpecification(&'a bios_boot_spec::BootSpecification),
3594}
3595
3596impl TryFrom<&DevicePathNode> for DevicePathNodeEnum<'_> {
3597 type Error = NodeConversionError;
3598 fn try_from(node: &DevicePathNode) -> Result<Self, Self::Error> {
3599 Ok(match node.full_type() {
3600 (DeviceType::END, DeviceSubType::END_INSTANCE) => Self::EndInstance(node.try_into()?),
3601 (DeviceType::END, DeviceSubType::END_ENTIRE) => Self::EndEntire(node.try_into()?),
3602 (DeviceType::HARDWARE, DeviceSubType::HARDWARE_PCI) => {
3603 Self::HardwarePci(node.try_into()?)
3604 }
3605 (DeviceType::HARDWARE, DeviceSubType::HARDWARE_PCCARD) => {
3606 Self::HardwarePccard(node.try_into()?)
3607 }
3608 (DeviceType::HARDWARE, DeviceSubType::HARDWARE_MEMORY_MAPPED) => {
3609 Self::HardwareMemoryMapped(node.try_into()?)
3610 }
3611 (DeviceType::HARDWARE, DeviceSubType::HARDWARE_VENDOR) => {
3612 Self::HardwareVendor(node.try_into()?)
3613 }
3614 (DeviceType::HARDWARE, DeviceSubType::HARDWARE_CONTROLLER) => {
3615 Self::HardwareController(node.try_into()?)
3616 }
3617 (DeviceType::HARDWARE, DeviceSubType::HARDWARE_BMC) => {
3618 Self::HardwareBmc(node.try_into()?)
3619 }
3620 (DeviceType::ACPI, DeviceSubType::ACPI) => Self::AcpiAcpi(node.try_into()?),
3621 (DeviceType::ACPI, DeviceSubType::ACPI_EXPANDED) => {
3622 Self::AcpiExpanded(node.try_into()?)
3623 }
3624 (DeviceType::ACPI, DeviceSubType::ACPI_ADR) => Self::AcpiAdr(node.try_into()?),
3625 (DeviceType::ACPI, DeviceSubType::ACPI_NVDIMM) => Self::AcpiNvdimm(node.try_into()?),
3626 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_ATAPI) => {
3627 Self::MessagingAtapi(node.try_into()?)
3628 }
3629 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_SCSI) => {
3630 Self::MessagingScsi(node.try_into()?)
3631 }
3632 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_FIBRE_CHANNEL) => {
3633 Self::MessagingFibreChannel(node.try_into()?)
3634 }
3635 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_FIBRE_CHANNEL_EX) => {
3636 Self::MessagingFibreChannelEx(node.try_into()?)
3637 }
3638 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_1394) => {
3639 Self::MessagingIeee1394(node.try_into()?)
3640 }
3641 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_USB) => {
3642 Self::MessagingUsb(node.try_into()?)
3643 }
3644 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_SATA) => {
3645 Self::MessagingSata(node.try_into()?)
3646 }
3647 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_USB_WWID) => {
3648 Self::MessagingUsbWwid(node.try_into()?)
3649 }
3650 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_DEVICE_LOGICAL_UNIT) => {
3651 Self::MessagingDeviceLogicalUnit(node.try_into()?)
3652 }
3653 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_USB_CLASS) => {
3654 Self::MessagingUsbClass(node.try_into()?)
3655 }
3656 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_I2O) => {
3657 Self::MessagingI2o(node.try_into()?)
3658 }
3659 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_MAC_ADDRESS) => {
3660 Self::MessagingMacAddress(node.try_into()?)
3661 }
3662 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_IPV4) => {
3663 Self::MessagingIpv4(node.try_into()?)
3664 }
3665 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_IPV6) => {
3666 Self::MessagingIpv6(node.try_into()?)
3667 }
3668 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_VLAN) => {
3669 Self::MessagingVlan(node.try_into()?)
3670 }
3671 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_INFINIBAND) => {
3672 Self::MessagingInfiniband(node.try_into()?)
3673 }
3674 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_UART) => {
3675 Self::MessagingUart(node.try_into()?)
3676 }
3677 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_VENDOR) => {
3678 Self::MessagingVendor(node.try_into()?)
3679 }
3680 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_SCSI_SAS_EX) => {
3681 Self::MessagingSasEx(node.try_into()?)
3682 }
3683 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_ISCSI) => {
3684 Self::MessagingIscsi(node.try_into()?)
3685 }
3686 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_NVME_NAMESPACE) => {
3687 Self::MessagingNvmeNamespace(node.try_into()?)
3688 }
3689 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_URI) => {
3690 Self::MessagingUri(node.try_into()?)
3691 }
3692 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_UFS) => {
3693 Self::MessagingUfs(node.try_into()?)
3694 }
3695 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_SD) => {
3696 Self::MessagingSd(node.try_into()?)
3697 }
3698 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_BLUETOOTH) => {
3699 Self::MessagingBluetooth(node.try_into()?)
3700 }
3701 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_WIFI) => {
3702 Self::MessagingWifi(node.try_into()?)
3703 }
3704 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_EMMC) => {
3705 Self::MessagingEmmc(node.try_into()?)
3706 }
3707 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_BLUETOOTH_LE) => {
3708 Self::MessagingBluetoothLe(node.try_into()?)
3709 }
3710 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_DNS) => {
3711 Self::MessagingDns(node.try_into()?)
3712 }
3713 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_NVDIMM_NAMESPACE) => {
3714 Self::MessagingNvdimmNamespace(node.try_into()?)
3715 }
3716 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_REST_SERVICE) => {
3717 Self::MessagingRestService(node.try_into()?)
3718 }
3719 (DeviceType::MESSAGING, DeviceSubType::MESSAGING_NVME_OF_NAMESPACE) => {
3720 Self::MessagingNvmeOfNamespace(node.try_into()?)
3721 }
3722 (DeviceType::MEDIA, DeviceSubType::MEDIA_HARD_DRIVE) => {
3723 Self::MediaHardDrive(node.try_into()?)
3724 }
3725 (DeviceType::MEDIA, DeviceSubType::MEDIA_CD_ROM) => Self::MediaCdRom(node.try_into()?),
3726 (DeviceType::MEDIA, DeviceSubType::MEDIA_VENDOR) => Self::MediaVendor(node.try_into()?),
3727 (DeviceType::MEDIA, DeviceSubType::MEDIA_FILE_PATH) => {
3728 Self::MediaFilePath(node.try_into()?)
3729 }
3730 (DeviceType::MEDIA, DeviceSubType::MEDIA_PROTOCOL) => {
3731 Self::MediaProtocol(node.try_into()?)
3732 }
3733 (DeviceType::MEDIA, DeviceSubType::MEDIA_PIWG_FIRMWARE_FILE) => {
3734 Self::MediaPiwgFirmwareFile(node.try_into()?)
3735 }
3736 (DeviceType::MEDIA, DeviceSubType::MEDIA_PIWG_FIRMWARE_VOLUME) => {
3737 Self::MediaPiwgFirmwareVolume(node.try_into()?)
3738 }
3739 (DeviceType::MEDIA, DeviceSubType::MEDIA_RELATIVE_OFFSET_RANGE) => {
3740 Self::MediaRelativeOffsetRange(node.try_into()?)
3741 }
3742 (DeviceType::MEDIA, DeviceSubType::MEDIA_RAM_DISK) => {
3743 Self::MediaRamDisk(node.try_into()?)
3744 }
3745 (DeviceType::BIOS_BOOT_SPEC, DeviceSubType::BIOS_BOOT_SPECIFICATION) => {
3746 Self::BiosBootSpecBootSpecification(node.try_into()?)
3747 }
3748 _ => return Err(NodeConversionError::UnsupportedType),
3749 })
3750 }
3751}
3752
3753/// Build device paths from their component nodes.
3754pub mod build {
3755 use super::*;
3756 use crate::CStr16;
3757 use crate::proto::device_path::build::{BuildError, BuildNode};
3758 use crate::proto::device_path::{DeviceSubType, DeviceType};
3759 use core::mem::MaybeUninit;
3760 /// Device path build nodes for [`DeviceType::END`].
3761 pub mod end {
3762 use super::*;
3763 /// Node that terminates a [`DevicePathInstance`].
3764 ///
3765 /// [`DevicePathInstance`]: device_path::DevicePathInstance
3766 #[derive(Debug)]
3767 pub struct Instance;
3768 #[expect(clippy::undocumented_unsafe_blocks)]
3769 unsafe impl BuildNode for Instance {
3770 fn size_in_bytes(&self) -> Result<u16, BuildError> {
3771 let size = 4usize;
3772 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
3773 }
3774
3775 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
3776 let size = usize::from(self.size_in_bytes().unwrap());
3777 assert_eq!(size, out.len());
3778 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
3779 let length = u16::try_from(size).unwrap();
3780 let header =
3781 DevicePathHeader::new(DeviceType::END, DeviceSubType::END_INSTANCE, length);
3782 #[expect(clippy::undocumented_unsafe_blocks)]
3783 unsafe {
3784 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
3785 }
3786 }
3787 }
3788
3789 /// Node that terminates an entire [`DevicePath`].
3790 ///
3791 /// [`DevicePath`]: device_path::DevicePath
3792 #[derive(Debug)]
3793 pub struct Entire;
3794 #[expect(clippy::undocumented_unsafe_blocks)]
3795 unsafe impl BuildNode for Entire {
3796 fn size_in_bytes(&self) -> Result<u16, BuildError> {
3797 let size = 4usize;
3798 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
3799 }
3800
3801 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
3802 let size = usize::from(self.size_in_bytes().unwrap());
3803 assert_eq!(size, out.len());
3804 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
3805 let length = u16::try_from(size).unwrap();
3806 let header =
3807 DevicePathHeader::new(DeviceType::END, DeviceSubType::END_ENTIRE, length);
3808 #[expect(clippy::undocumented_unsafe_blocks)]
3809 unsafe {
3810 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
3811 }
3812 }
3813 }
3814 }
3815
3816 /// Device path build nodes for [`DeviceType::HARDWARE`].
3817 pub mod hardware {
3818 use super::*;
3819 /// PCI hardware device path node.
3820 #[derive(Debug)]
3821 pub struct Pci {
3822 /// PCI function number.
3823 pub function: u8,
3824 /// PCI device number.
3825 pub device: u8,
3826 }
3827
3828 #[expect(clippy::undocumented_unsafe_blocks)]
3829 unsafe impl BuildNode for Pci {
3830 fn size_in_bytes(&self) -> Result<u16, BuildError> {
3831 let size = 6usize;
3832 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
3833 }
3834
3835 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
3836 let size = usize::from(self.size_in_bytes().unwrap());
3837 assert_eq!(size, out.len());
3838 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
3839 let length = u16::try_from(size).unwrap();
3840 let header = DevicePathHeader::new(
3841 DeviceType::HARDWARE,
3842 DeviceSubType::HARDWARE_PCI,
3843 length,
3844 );
3845 #[expect(clippy::undocumented_unsafe_blocks)]
3846 unsafe {
3847 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
3848 out_ptr
3849 .add(4usize)
3850 .cast::<u8>()
3851 .write_unaligned(self.function);
3852 out_ptr
3853 .add(5usize)
3854 .cast::<u8>()
3855 .write_unaligned(self.device);
3856 }
3857 }
3858 }
3859
3860 /// PCCARD hardware device path node.
3861 #[derive(Debug)]
3862 pub struct Pccard {
3863 /// Function number starting from 0.
3864 pub function: u8,
3865 }
3866
3867 #[expect(clippy::undocumented_unsafe_blocks)]
3868 unsafe impl BuildNode for Pccard {
3869 fn size_in_bytes(&self) -> Result<u16, BuildError> {
3870 let size = 5usize;
3871 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
3872 }
3873
3874 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
3875 let size = usize::from(self.size_in_bytes().unwrap());
3876 assert_eq!(size, out.len());
3877 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
3878 let length = u16::try_from(size).unwrap();
3879 let header = DevicePathHeader::new(
3880 DeviceType::HARDWARE,
3881 DeviceSubType::HARDWARE_PCCARD,
3882 length,
3883 );
3884 #[expect(clippy::undocumented_unsafe_blocks)]
3885 unsafe {
3886 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
3887 out_ptr
3888 .add(4usize)
3889 .cast::<u8>()
3890 .write_unaligned(self.function);
3891 }
3892 }
3893 }
3894
3895 /// Memory mapped hardware device path node.
3896 #[derive(Debug)]
3897 pub struct MemoryMapped {
3898 /// Memory type.
3899 pub memory_type: MemoryType,
3900 /// Starting memory address.
3901 pub start_address: u64,
3902 /// Ending memory address.
3903 pub end_address: u64,
3904 }
3905
3906 #[expect(clippy::undocumented_unsafe_blocks)]
3907 unsafe impl BuildNode for MemoryMapped {
3908 fn size_in_bytes(&self) -> Result<u16, BuildError> {
3909 let size = 24usize;
3910 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
3911 }
3912
3913 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
3914 let size = usize::from(self.size_in_bytes().unwrap());
3915 assert_eq!(size, out.len());
3916 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
3917 let length = u16::try_from(size).unwrap();
3918 let header = DevicePathHeader::new(
3919 DeviceType::HARDWARE,
3920 DeviceSubType::HARDWARE_MEMORY_MAPPED,
3921 length,
3922 );
3923 #[expect(clippy::undocumented_unsafe_blocks)]
3924 unsafe {
3925 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
3926 out_ptr
3927 .add(4usize)
3928 .cast::<MemoryType>()
3929 .write_unaligned(self.memory_type);
3930 out_ptr
3931 .add(8usize)
3932 .cast::<u64>()
3933 .write_unaligned(self.start_address);
3934 out_ptr
3935 .add(16usize)
3936 .cast::<u64>()
3937 .write_unaligned(self.end_address);
3938 }
3939 }
3940 }
3941
3942 /// Vendor-defined hardware device path node.
3943 #[derive(Debug)]
3944 pub struct Vendor<'a> {
3945 /// Vendor-assigned GUID that defines the data that follows.
3946 pub vendor_guid: Guid,
3947 /// Vendor-defined data.
3948 pub vendor_defined_data: &'a [u8],
3949 }
3950
3951 #[expect(clippy::undocumented_unsafe_blocks)]
3952 unsafe impl BuildNode for Vendor<'_> {
3953 fn size_in_bytes(&self) -> Result<u16, BuildError> {
3954 let size = 20usize + size_of_val(self.vendor_defined_data);
3955 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
3956 }
3957
3958 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
3959 let size = usize::from(self.size_in_bytes().unwrap());
3960 assert_eq!(size, out.len());
3961 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
3962 let length = u16::try_from(size).unwrap();
3963 let header = DevicePathHeader::new(
3964 DeviceType::HARDWARE,
3965 DeviceSubType::HARDWARE_VENDOR,
3966 length,
3967 );
3968 #[expect(clippy::undocumented_unsafe_blocks)]
3969 unsafe {
3970 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
3971 out_ptr
3972 .add(4usize)
3973 .cast::<Guid>()
3974 .write_unaligned(self.vendor_guid);
3975 self.vendor_defined_data
3976 .as_ptr()
3977 .cast::<u8>()
3978 .copy_to_nonoverlapping(
3979 out_ptr.add(20usize),
3980 size_of_val(self.vendor_defined_data),
3981 );
3982 }
3983 }
3984 }
3985
3986 /// Controller hardware device path node.
3987 #[derive(Debug)]
3988 pub struct Controller {
3989 /// Controller number.
3990 pub controller_number: u32,
3991 }
3992
3993 #[expect(clippy::undocumented_unsafe_blocks)]
3994 unsafe impl BuildNode for Controller {
3995 fn size_in_bytes(&self) -> Result<u16, BuildError> {
3996 let size = 8usize;
3997 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
3998 }
3999
4000 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4001 let size = usize::from(self.size_in_bytes().unwrap());
4002 assert_eq!(size, out.len());
4003 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4004 let length = u16::try_from(size).unwrap();
4005 let header = DevicePathHeader::new(
4006 DeviceType::HARDWARE,
4007 DeviceSubType::HARDWARE_CONTROLLER,
4008 length,
4009 );
4010 #[expect(clippy::undocumented_unsafe_blocks)]
4011 unsafe {
4012 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4013 out_ptr
4014 .add(4usize)
4015 .cast::<u32>()
4016 .write_unaligned(self.controller_number);
4017 }
4018 }
4019 }
4020
4021 /// Baseboard Management Controller (BMC) host interface hardware
4022 /// device path node.
4023 #[derive(Debug)]
4024 pub struct Bmc {
4025 /// Host interface type.
4026 pub interface_type: device_path::hardware::BmcInterfaceType,
4027 /// Base address of the BMC. If the least-significant bit of the
4028 /// field is a 1 then the address is in I/O space, otherwise the
4029 /// address is memory-mapped.
4030 pub base_address: u64,
4031 }
4032
4033 #[expect(clippy::undocumented_unsafe_blocks)]
4034 unsafe impl BuildNode for Bmc {
4035 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4036 let size = 13usize;
4037 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4038 }
4039
4040 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4041 let size = usize::from(self.size_in_bytes().unwrap());
4042 assert_eq!(size, out.len());
4043 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4044 let length = u16::try_from(size).unwrap();
4045 let header = DevicePathHeader::new(
4046 DeviceType::HARDWARE,
4047 DeviceSubType::HARDWARE_BMC,
4048 length,
4049 );
4050 #[expect(clippy::undocumented_unsafe_blocks)]
4051 unsafe {
4052 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4053 out_ptr
4054 .add(4usize)
4055 .cast::<device_path::hardware::BmcInterfaceType>()
4056 .write_unaligned(self.interface_type);
4057 out_ptr
4058 .add(5usize)
4059 .cast::<u64>()
4060 .write_unaligned(self.base_address);
4061 }
4062 }
4063 }
4064 }
4065
4066 /// Device path build nodes for [`DeviceType::ACPI`].
4067 pub mod acpi {
4068 use super::*;
4069 /// ACPI device path node.
4070 #[derive(Debug)]
4071 pub struct Acpi {
4072 /// Device's PnP hardware ID stored in a numeric 32-bit
4073 /// compressed EISA-type ID.
4074 pub hid: u32,
4075 /// Unique ID that is required by ACPI if two devices have the
4076 /// same HID.
4077 pub uid: u32,
4078 }
4079
4080 #[expect(clippy::undocumented_unsafe_blocks)]
4081 unsafe impl BuildNode for Acpi {
4082 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4083 let size = 12usize;
4084 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4085 }
4086
4087 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4088 let size = usize::from(self.size_in_bytes().unwrap());
4089 assert_eq!(size, out.len());
4090 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4091 let length = u16::try_from(size).unwrap();
4092 let header = DevicePathHeader::new(DeviceType::ACPI, DeviceSubType::ACPI, length);
4093 #[expect(clippy::undocumented_unsafe_blocks)]
4094 unsafe {
4095 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4096 out_ptr.add(4usize).cast::<u32>().write_unaligned(self.hid);
4097 out_ptr.add(8usize).cast::<u32>().write_unaligned(self.uid);
4098 }
4099 }
4100 }
4101
4102 /// Expanded ACPI device path node.
4103 #[derive(Debug)]
4104 pub struct Expanded<'a> {
4105 /// Device's PnP hardware ID stored in a numeric 32-bit compressed
4106 /// EISA-type ID.
4107 pub hid: u32,
4108 /// Unique ID that is required by ACPI if two devices have the
4109 /// same HID.
4110 pub uid: u32,
4111 /// Device's compatible PnP hardware ID stored in a numeric 32-bit
4112 /// compressed EISA-type ID.
4113 pub cid: u32,
4114 /// Device's PnP hardware ID stored as a null-terminated ASCII
4115 /// string. This value must match the corresponding HID in the
4116 /// ACPI name space. If the length of this string not including
4117 /// the null-terminator is 0, then the numeric HID is used.
4118 pub hid_str: &'a [u8],
4119 /// Unique ID that is required by ACPI if two devices have the
4120 /// same HID. This value is stored as a null-terminated ASCII
4121 /// string. If the length of this string not including the
4122 /// null-terminator is 0, then the numeric UID is used.
4123 pub uid_str: &'a [u8],
4124 /// Device's compatible PnP hardware ID stored as a
4125 /// null-terminated ASCII string. If the length of this string
4126 /// not including the null-terminator is 0, then the numeric CID
4127 /// is used.
4128 pub cid_str: &'a [u8],
4129 }
4130
4131 #[expect(clippy::undocumented_unsafe_blocks)]
4132 unsafe impl BuildNode for Expanded<'_> {
4133 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4134 let size = 16usize
4135 + size_of_val(self.hid_str)
4136 + size_of_val(self.uid_str)
4137 + size_of_val(self.cid_str);
4138 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4139 }
4140
4141 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4142 let size = usize::from(self.size_in_bytes().unwrap());
4143 assert_eq!(size, out.len());
4144 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4145 let length = u16::try_from(size).unwrap();
4146 let header =
4147 DevicePathHeader::new(DeviceType::ACPI, DeviceSubType::ACPI_EXPANDED, length);
4148 #[expect(clippy::undocumented_unsafe_blocks)]
4149 unsafe {
4150 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4151 let mut dst_group_offset = 0;
4152 out_ptr.add(4usize).cast::<u32>().write_unaligned(self.hid);
4153 out_ptr.add(8usize).cast::<u32>().write_unaligned(self.uid);
4154 out_ptr.add(12usize).cast::<u32>().write_unaligned(self.cid);
4155 self.hid_str.as_ptr().cast::<u8>().copy_to_nonoverlapping(
4156 out_ptr.add(16usize + dst_group_offset),
4157 size_of_val(self.hid_str),
4158 );
4159 dst_group_offset += size_of_val(self.hid_str);
4160 self.uid_str.as_ptr().cast::<u8>().copy_to_nonoverlapping(
4161 out_ptr.add(16usize + dst_group_offset),
4162 size_of_val(self.uid_str),
4163 );
4164 dst_group_offset += size_of_val(self.uid_str);
4165 self.cid_str.as_ptr().cast::<u8>().copy_to_nonoverlapping(
4166 out_ptr.add(16usize + dst_group_offset),
4167 size_of_val(self.cid_str),
4168 );
4169 }
4170 }
4171 }
4172
4173 /// ADR ACPI device path node.
4174 #[derive(Debug)]
4175 pub struct Adr<'a> {
4176 /// ADR values. For video output devices the value of this field
4177 /// comes from Table B-2 ACPI 3.0 specification. At least one
4178 /// ADR value is required.
4179 pub adr: &'a AdrSlice,
4180 }
4181
4182 #[expect(clippy::undocumented_unsafe_blocks)]
4183 unsafe impl BuildNode for Adr<'_> {
4184 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4185 let size = 4usize + size_of_val(self.adr);
4186 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4187 }
4188
4189 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4190 let size = usize::from(self.size_in_bytes().unwrap());
4191 assert_eq!(size, out.len());
4192 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4193 let length = u16::try_from(size).unwrap();
4194 let header =
4195 DevicePathHeader::new(DeviceType::ACPI, DeviceSubType::ACPI_ADR, length);
4196 #[expect(clippy::undocumented_unsafe_blocks)]
4197 unsafe {
4198 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4199 self.adr
4200 .as_ptr()
4201 .cast::<u8>()
4202 .copy_to_nonoverlapping(out_ptr.add(4usize), size_of_val(self.adr));
4203 }
4204 }
4205 }
4206
4207 /// NVDIMM ACPI device path node.
4208 #[derive(Debug)]
4209 pub struct Nvdimm {
4210 /// NFIT device handle.
4211 pub nfit_device_handle: u32,
4212 }
4213
4214 #[expect(clippy::undocumented_unsafe_blocks)]
4215 unsafe impl BuildNode for Nvdimm {
4216 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4217 let size = 8usize;
4218 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4219 }
4220
4221 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4222 let size = usize::from(self.size_in_bytes().unwrap());
4223 assert_eq!(size, out.len());
4224 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4225 let length = u16::try_from(size).unwrap();
4226 let header =
4227 DevicePathHeader::new(DeviceType::ACPI, DeviceSubType::ACPI_NVDIMM, length);
4228 #[expect(clippy::undocumented_unsafe_blocks)]
4229 unsafe {
4230 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4231 out_ptr
4232 .add(4usize)
4233 .cast::<u32>()
4234 .write_unaligned(self.nfit_device_handle);
4235 }
4236 }
4237 }
4238
4239 /// Wrapper for [`u32`] ADR values that enforces at least one
4240 /// element is present.
4241 #[repr(transparent)]
4242 #[derive(Debug)]
4243 pub struct AdrSlice([u32]);
4244 impl AdrSlice {
4245 /// Create a new `AdrSlice`. Returns `None` if the input slice
4246 /// is empty.
4247 #[must_use]
4248 pub fn new(slice: &[u32]) -> Option<&Self> {
4249 if slice.is_empty() {
4250 None
4251 } else {
4252 #[expect(clippy::undocumented_unsafe_blocks)]
4253 let adr_slice: &Self = unsafe { mem::transmute(slice) };
4254 Some(adr_slice)
4255 }
4256 }
4257
4258 fn as_ptr(&self) -> *const u32 {
4259 self.0.as_ptr()
4260 }
4261 }
4262 }
4263
4264 /// Device path build nodes for [`DeviceType::MESSAGING`].
4265 pub mod messaging {
4266 use super::*;
4267 /// ATAPI messaging device path node.
4268 #[derive(Debug)]
4269 pub struct Atapi {
4270 /// Whether the ATAPI device is primary or secondary.
4271 pub primary_secondary: device_path::messaging::PrimarySecondary,
4272 /// Whether the ATAPI device is master or slave.
4273 pub master_slave: device_path::messaging::MasterSlave,
4274 /// Logical Unit Number (LUN).
4275 pub logical_unit_number: u16,
4276 }
4277
4278 #[expect(clippy::undocumented_unsafe_blocks)]
4279 unsafe impl BuildNode for Atapi {
4280 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4281 let size = 8usize;
4282 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4283 }
4284
4285 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4286 let size = usize::from(self.size_in_bytes().unwrap());
4287 assert_eq!(size, out.len());
4288 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4289 let length = u16::try_from(size).unwrap();
4290 let header = DevicePathHeader::new(
4291 DeviceType::MESSAGING,
4292 DeviceSubType::MESSAGING_ATAPI,
4293 length,
4294 );
4295 #[expect(clippy::undocumented_unsafe_blocks)]
4296 unsafe {
4297 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4298 out_ptr
4299 .add(4usize)
4300 .cast::<device_path::messaging::PrimarySecondary>()
4301 .write_unaligned(self.primary_secondary);
4302 out_ptr
4303 .add(5usize)
4304 .cast::<device_path::messaging::MasterSlave>()
4305 .write_unaligned(self.master_slave);
4306 out_ptr
4307 .add(6usize)
4308 .cast::<u16>()
4309 .write_unaligned(self.logical_unit_number);
4310 }
4311 }
4312 }
4313
4314 /// SCSI messaging device path node.
4315 #[derive(Debug)]
4316 pub struct Scsi {
4317 /// Target ID on the SCSI bus.
4318 pub target_id: u16,
4319 /// Logical Unit Number.
4320 pub logical_unit_number: u16,
4321 }
4322
4323 #[expect(clippy::undocumented_unsafe_blocks)]
4324 unsafe impl BuildNode for Scsi {
4325 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4326 let size = 8usize;
4327 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4328 }
4329
4330 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4331 let size = usize::from(self.size_in_bytes().unwrap());
4332 assert_eq!(size, out.len());
4333 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4334 let length = u16::try_from(size).unwrap();
4335 let header = DevicePathHeader::new(
4336 DeviceType::MESSAGING,
4337 DeviceSubType::MESSAGING_SCSI,
4338 length,
4339 );
4340 #[expect(clippy::undocumented_unsafe_blocks)]
4341 unsafe {
4342 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4343 out_ptr
4344 .add(4usize)
4345 .cast::<u16>()
4346 .write_unaligned(self.target_id);
4347 out_ptr
4348 .add(6usize)
4349 .cast::<u16>()
4350 .write_unaligned(self.logical_unit_number);
4351 }
4352 }
4353 }
4354
4355 /// Fibre channel messaging device path node.
4356 #[derive(Debug)]
4357 pub struct FibreChannel {
4358 /// Fibre Channel World Wide Name.
4359 pub world_wide_name: u64,
4360 /// Fibre Channel Logical Unit Number.
4361 pub logical_unit_number: u64,
4362 }
4363
4364 #[expect(clippy::undocumented_unsafe_blocks)]
4365 unsafe impl BuildNode for FibreChannel {
4366 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4367 let size = 24usize;
4368 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4369 }
4370
4371 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4372 let size = usize::from(self.size_in_bytes().unwrap());
4373 assert_eq!(size, out.len());
4374 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4375 let length = u16::try_from(size).unwrap();
4376 let header = DevicePathHeader::new(
4377 DeviceType::MESSAGING,
4378 DeviceSubType::MESSAGING_FIBRE_CHANNEL,
4379 length,
4380 );
4381 #[expect(clippy::undocumented_unsafe_blocks)]
4382 unsafe {
4383 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4384 out_ptr.add(4usize).write_bytes(0, size_of::<u32>());
4385 out_ptr
4386 .add(8usize)
4387 .cast::<u64>()
4388 .write_unaligned(self.world_wide_name);
4389 out_ptr
4390 .add(16usize)
4391 .cast::<u64>()
4392 .write_unaligned(self.logical_unit_number);
4393 }
4394 }
4395 }
4396
4397 /// Fibre channel extended messaging device path node.
4398 #[derive(Debug)]
4399 pub struct FibreChannelEx {
4400 /// Fibre Channel end device port name (aka World Wide Name).
4401 pub world_wide_name: [u8; 8usize],
4402 /// Fibre Channel Logical Unit Number.
4403 pub logical_unit_number: [u8; 8usize],
4404 }
4405
4406 #[expect(clippy::undocumented_unsafe_blocks)]
4407 unsafe impl BuildNode for FibreChannelEx {
4408 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4409 let size = 24usize;
4410 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4411 }
4412
4413 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4414 let size = usize::from(self.size_in_bytes().unwrap());
4415 assert_eq!(size, out.len());
4416 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4417 let length = u16::try_from(size).unwrap();
4418 let header = DevicePathHeader::new(
4419 DeviceType::MESSAGING,
4420 DeviceSubType::MESSAGING_FIBRE_CHANNEL_EX,
4421 length,
4422 );
4423 #[expect(clippy::undocumented_unsafe_blocks)]
4424 unsafe {
4425 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4426 out_ptr.add(4usize).write_bytes(0, size_of::<u32>());
4427 out_ptr
4428 .add(8usize)
4429 .cast::<[u8; 8usize]>()
4430 .write_unaligned(self.world_wide_name);
4431 out_ptr
4432 .add(16usize)
4433 .cast::<[u8; 8usize]>()
4434 .write_unaligned(self.logical_unit_number);
4435 }
4436 }
4437 }
4438
4439 /// 1394 messaging device path node.
4440 #[derive(Debug)]
4441 pub struct Ieee1394 {
4442 /// 1394 Global Unique ID. Note that this is not the same as a
4443 /// UEFI GUID.
4444 pub guid: [u8; 8usize],
4445 }
4446
4447 #[expect(clippy::undocumented_unsafe_blocks)]
4448 unsafe impl BuildNode for Ieee1394 {
4449 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4450 let size = 16usize;
4451 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4452 }
4453
4454 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4455 let size = usize::from(self.size_in_bytes().unwrap());
4456 assert_eq!(size, out.len());
4457 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4458 let length = u16::try_from(size).unwrap();
4459 let header = DevicePathHeader::new(
4460 DeviceType::MESSAGING,
4461 DeviceSubType::MESSAGING_1394,
4462 length,
4463 );
4464 #[expect(clippy::undocumented_unsafe_blocks)]
4465 unsafe {
4466 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4467 out_ptr.add(4usize).write_bytes(0, size_of::<u32>());
4468 out_ptr
4469 .add(8usize)
4470 .cast::<[u8; 8usize]>()
4471 .write_unaligned(self.guid);
4472 }
4473 }
4474 }
4475
4476 /// USB messaging device path node.
4477 #[derive(Debug)]
4478 pub struct Usb {
4479 /// USB parent port number.
4480 pub parent_port_number: u8,
4481 /// USB interface number.
4482 pub interface: u8,
4483 }
4484
4485 #[expect(clippy::undocumented_unsafe_blocks)]
4486 unsafe impl BuildNode for Usb {
4487 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4488 let size = 6usize;
4489 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4490 }
4491
4492 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4493 let size = usize::from(self.size_in_bytes().unwrap());
4494 assert_eq!(size, out.len());
4495 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4496 let length = u16::try_from(size).unwrap();
4497 let header = DevicePathHeader::new(
4498 DeviceType::MESSAGING,
4499 DeviceSubType::MESSAGING_USB,
4500 length,
4501 );
4502 #[expect(clippy::undocumented_unsafe_blocks)]
4503 unsafe {
4504 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4505 out_ptr
4506 .add(4usize)
4507 .cast::<u8>()
4508 .write_unaligned(self.parent_port_number);
4509 out_ptr
4510 .add(5usize)
4511 .cast::<u8>()
4512 .write_unaligned(self.interface);
4513 }
4514 }
4515 }
4516
4517 /// SATA messaging device path node.
4518 #[derive(Debug)]
4519 pub struct Sata {
4520 /// The HBA port number that facilitates the connection to the
4521 /// device or a port multiplier. The value 0xffff is reserved.
4522 pub hba_port_number: u16,
4523 /// the port multiplier port number that facilitates the
4524 /// connection to the device. Must be set to 0xffff if the
4525 /// device is directly connected to the HBA.
4526 pub port_multiplier_port_number: u16,
4527 /// Logical unit number.
4528 pub logical_unit_number: u16,
4529 }
4530
4531 #[expect(clippy::undocumented_unsafe_blocks)]
4532 unsafe impl BuildNode for Sata {
4533 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4534 let size = 10usize;
4535 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4536 }
4537
4538 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4539 let size = usize::from(self.size_in_bytes().unwrap());
4540 assert_eq!(size, out.len());
4541 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4542 let length = u16::try_from(size).unwrap();
4543 let header = DevicePathHeader::new(
4544 DeviceType::MESSAGING,
4545 DeviceSubType::MESSAGING_SATA,
4546 length,
4547 );
4548 #[expect(clippy::undocumented_unsafe_blocks)]
4549 unsafe {
4550 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4551 out_ptr
4552 .add(4usize)
4553 .cast::<u16>()
4554 .write_unaligned(self.hba_port_number);
4555 out_ptr
4556 .add(6usize)
4557 .cast::<u16>()
4558 .write_unaligned(self.port_multiplier_port_number);
4559 out_ptr
4560 .add(8usize)
4561 .cast::<u16>()
4562 .write_unaligned(self.logical_unit_number);
4563 }
4564 }
4565 }
4566
4567 /// USB World Wide ID (WWID) messaging device path node.
4568 #[derive(Debug)]
4569 pub struct UsbWwid<'a> {
4570 /// USB interface number.
4571 pub interface_number: u16,
4572 /// USB vendor ID.
4573 pub device_vendor_id: u16,
4574 /// USB product ID.
4575 pub device_product_id: u16,
4576 /// Last 64 (or fewer) characters of the USB Serial number.
4577 pub serial_number: &'a [u16],
4578 }
4579
4580 #[expect(clippy::undocumented_unsafe_blocks)]
4581 unsafe impl BuildNode for UsbWwid<'_> {
4582 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4583 let size = 10usize + size_of_val(self.serial_number);
4584 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4585 }
4586
4587 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4588 let size = usize::from(self.size_in_bytes().unwrap());
4589 assert_eq!(size, out.len());
4590 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4591 let length = u16::try_from(size).unwrap();
4592 let header = DevicePathHeader::new(
4593 DeviceType::MESSAGING,
4594 DeviceSubType::MESSAGING_USB_WWID,
4595 length,
4596 );
4597 #[expect(clippy::undocumented_unsafe_blocks)]
4598 unsafe {
4599 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4600 out_ptr
4601 .add(4usize)
4602 .cast::<u16>()
4603 .write_unaligned(self.interface_number);
4604 out_ptr
4605 .add(6usize)
4606 .cast::<u16>()
4607 .write_unaligned(self.device_vendor_id);
4608 out_ptr
4609 .add(8usize)
4610 .cast::<u16>()
4611 .write_unaligned(self.device_product_id);
4612 self.serial_number
4613 .as_ptr()
4614 .cast::<u8>()
4615 .copy_to_nonoverlapping(
4616 out_ptr.add(10usize),
4617 size_of_val(self.serial_number),
4618 );
4619 }
4620 }
4621 }
4622
4623 /// Device logical unit messaging device path node.
4624 #[derive(Debug)]
4625 pub struct DeviceLogicalUnit {
4626 /// Logical Unit Number.
4627 pub logical_unit_number: u8,
4628 }
4629
4630 #[expect(clippy::undocumented_unsafe_blocks)]
4631 unsafe impl BuildNode for DeviceLogicalUnit {
4632 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4633 let size = 5usize;
4634 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4635 }
4636
4637 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4638 let size = usize::from(self.size_in_bytes().unwrap());
4639 assert_eq!(size, out.len());
4640 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4641 let length = u16::try_from(size).unwrap();
4642 let header = DevicePathHeader::new(
4643 DeviceType::MESSAGING,
4644 DeviceSubType::MESSAGING_DEVICE_LOGICAL_UNIT,
4645 length,
4646 );
4647 #[expect(clippy::undocumented_unsafe_blocks)]
4648 unsafe {
4649 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4650 out_ptr
4651 .add(4usize)
4652 .cast::<u8>()
4653 .write_unaligned(self.logical_unit_number);
4654 }
4655 }
4656 }
4657
4658 /// USB class messaging device path node.
4659 #[derive(Debug)]
4660 pub struct UsbClass {
4661 /// USB vendor ID.
4662 pub vendor_id: u16,
4663 /// USB product ID.
4664 pub product_id: u16,
4665 /// USB device class.
4666 pub device_class: u8,
4667 /// USB device subclass.
4668 pub device_subclass: u8,
4669 /// USB device protocol.
4670 pub device_protocol: u8,
4671 }
4672
4673 #[expect(clippy::undocumented_unsafe_blocks)]
4674 unsafe impl BuildNode for UsbClass {
4675 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4676 let size = 11usize;
4677 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4678 }
4679
4680 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4681 let size = usize::from(self.size_in_bytes().unwrap());
4682 assert_eq!(size, out.len());
4683 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4684 let length = u16::try_from(size).unwrap();
4685 let header = DevicePathHeader::new(
4686 DeviceType::MESSAGING,
4687 DeviceSubType::MESSAGING_USB_CLASS,
4688 length,
4689 );
4690 #[expect(clippy::undocumented_unsafe_blocks)]
4691 unsafe {
4692 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4693 out_ptr
4694 .add(4usize)
4695 .cast::<u16>()
4696 .write_unaligned(self.vendor_id);
4697 out_ptr
4698 .add(6usize)
4699 .cast::<u16>()
4700 .write_unaligned(self.product_id);
4701 out_ptr
4702 .add(8usize)
4703 .cast::<u8>()
4704 .write_unaligned(self.device_class);
4705 out_ptr
4706 .add(9usize)
4707 .cast::<u8>()
4708 .write_unaligned(self.device_subclass);
4709 out_ptr
4710 .add(10usize)
4711 .cast::<u8>()
4712 .write_unaligned(self.device_protocol);
4713 }
4714 }
4715 }
4716
4717 /// I2O messaging device path node.
4718 #[derive(Debug)]
4719 pub struct I2o {
4720 /// Target ID (TID).
4721 pub target_id: u32,
4722 }
4723
4724 #[expect(clippy::undocumented_unsafe_blocks)]
4725 unsafe impl BuildNode for I2o {
4726 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4727 let size = 8usize;
4728 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4729 }
4730
4731 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4732 let size = usize::from(self.size_in_bytes().unwrap());
4733 assert_eq!(size, out.len());
4734 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4735 let length = u16::try_from(size).unwrap();
4736 let header = DevicePathHeader::new(
4737 DeviceType::MESSAGING,
4738 DeviceSubType::MESSAGING_I2O,
4739 length,
4740 );
4741 #[expect(clippy::undocumented_unsafe_blocks)]
4742 unsafe {
4743 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4744 out_ptr
4745 .add(4usize)
4746 .cast::<u32>()
4747 .write_unaligned(self.target_id);
4748 }
4749 }
4750 }
4751
4752 /// MAC address messaging device path node.
4753 #[derive(Debug)]
4754 pub struct MacAddress {
4755 /// MAC address for a network interface, padded with zeros.
4756 pub mac_address: [u8; 32usize],
4757 /// Network interface type. See
4758 /// <https://www.iana.org/assignments/smi-numbers/smi-numbers.xhtml#smi-numbers-5>
4759 pub interface_type: u8,
4760 }
4761
4762 #[expect(clippy::undocumented_unsafe_blocks)]
4763 unsafe impl BuildNode for MacAddress {
4764 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4765 let size = 37usize;
4766 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4767 }
4768
4769 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4770 let size = usize::from(self.size_in_bytes().unwrap());
4771 assert_eq!(size, out.len());
4772 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4773 let length = u16::try_from(size).unwrap();
4774 let header = DevicePathHeader::new(
4775 DeviceType::MESSAGING,
4776 DeviceSubType::MESSAGING_MAC_ADDRESS,
4777 length,
4778 );
4779 #[expect(clippy::undocumented_unsafe_blocks)]
4780 unsafe {
4781 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4782 out_ptr
4783 .add(4usize)
4784 .cast::<[u8; 32usize]>()
4785 .write_unaligned(self.mac_address);
4786 out_ptr
4787 .add(36usize)
4788 .cast::<u8>()
4789 .write_unaligned(self.interface_type);
4790 }
4791 }
4792 }
4793
4794 /// IPv4 messaging device path node.
4795 #[derive(Debug)]
4796 pub struct Ipv4 {
4797 /// Local IPv4 address.
4798 pub local_ip_address: [u8; 4usize],
4799 /// Remote IPv4 address.
4800 pub remote_ip_address: [u8; 4usize],
4801 /// Local port number.
4802 pub local_port: u16,
4803 /// Remote port number.
4804 pub remote_port: u16,
4805 /// Network protocol. See
4806 /// <https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml>
4807 pub protocol: u16,
4808 /// Whether the source IP address is static or assigned via DHCP.
4809 pub ip_address_origin: device_path::messaging::Ipv4AddressOrigin,
4810 /// Gateway IP address.
4811 pub gateway_ip_address: [u8; 4usize],
4812 /// Subnet mask.
4813 pub subnet_mask: [u8; 4usize],
4814 }
4815
4816 #[expect(clippy::undocumented_unsafe_blocks)]
4817 unsafe impl BuildNode for Ipv4 {
4818 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4819 let size = 27usize;
4820 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4821 }
4822
4823 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4824 let size = usize::from(self.size_in_bytes().unwrap());
4825 assert_eq!(size, out.len());
4826 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4827 let length = u16::try_from(size).unwrap();
4828 let header = DevicePathHeader::new(
4829 DeviceType::MESSAGING,
4830 DeviceSubType::MESSAGING_IPV4,
4831 length,
4832 );
4833 #[expect(clippy::undocumented_unsafe_blocks)]
4834 unsafe {
4835 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4836 out_ptr
4837 .add(4usize)
4838 .cast::<[u8; 4usize]>()
4839 .write_unaligned(self.local_ip_address);
4840 out_ptr
4841 .add(8usize)
4842 .cast::<[u8; 4usize]>()
4843 .write_unaligned(self.remote_ip_address);
4844 out_ptr
4845 .add(12usize)
4846 .cast::<u16>()
4847 .write_unaligned(self.local_port);
4848 out_ptr
4849 .add(14usize)
4850 .cast::<u16>()
4851 .write_unaligned(self.remote_port);
4852 out_ptr
4853 .add(16usize)
4854 .cast::<u16>()
4855 .write_unaligned(self.protocol);
4856 out_ptr
4857 .add(18usize)
4858 .cast::<device_path::messaging::Ipv4AddressOrigin>()
4859 .write_unaligned(self.ip_address_origin);
4860 out_ptr
4861 .add(19usize)
4862 .cast::<[u8; 4usize]>()
4863 .write_unaligned(self.gateway_ip_address);
4864 out_ptr
4865 .add(23usize)
4866 .cast::<[u8; 4usize]>()
4867 .write_unaligned(self.subnet_mask);
4868 }
4869 }
4870 }
4871
4872 /// IPv6 messaging device path node.
4873 #[derive(Debug)]
4874 pub struct Ipv6 {
4875 /// Local Ipv6 address.
4876 pub local_ip_address: [u8; 16usize],
4877 /// Remote Ipv6 address.
4878 pub remote_ip_address: [u8; 16usize],
4879 /// Local port number.
4880 pub local_port: u16,
4881 /// Remote port number.
4882 pub remote_port: u16,
4883 /// Network protocol. See
4884 /// <https://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml>
4885 pub protocol: u16,
4886 /// Origin of the local IP address.
4887 pub ip_address_origin: device_path::messaging::Ipv6AddressOrigin,
4888 /// Prefix length.
4889 pub prefix_length: u8,
4890 /// Gateway IP address.
4891 pub gateway_ip_address: [u8; 16usize],
4892 }
4893
4894 #[expect(clippy::undocumented_unsafe_blocks)]
4895 unsafe impl BuildNode for Ipv6 {
4896 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4897 let size = 60usize;
4898 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4899 }
4900
4901 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4902 let size = usize::from(self.size_in_bytes().unwrap());
4903 assert_eq!(size, out.len());
4904 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4905 let length = u16::try_from(size).unwrap();
4906 let header = DevicePathHeader::new(
4907 DeviceType::MESSAGING,
4908 DeviceSubType::MESSAGING_IPV6,
4909 length,
4910 );
4911 #[expect(clippy::undocumented_unsafe_blocks)]
4912 unsafe {
4913 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4914 out_ptr
4915 .add(4usize)
4916 .cast::<[u8; 16usize]>()
4917 .write_unaligned(self.local_ip_address);
4918 out_ptr
4919 .add(20usize)
4920 .cast::<[u8; 16usize]>()
4921 .write_unaligned(self.remote_ip_address);
4922 out_ptr
4923 .add(36usize)
4924 .cast::<u16>()
4925 .write_unaligned(self.local_port);
4926 out_ptr
4927 .add(38usize)
4928 .cast::<u16>()
4929 .write_unaligned(self.remote_port);
4930 out_ptr
4931 .add(40usize)
4932 .cast::<u16>()
4933 .write_unaligned(self.protocol);
4934 out_ptr
4935 .add(42usize)
4936 .cast::<device_path::messaging::Ipv6AddressOrigin>()
4937 .write_unaligned(self.ip_address_origin);
4938 out_ptr
4939 .add(43usize)
4940 .cast::<u8>()
4941 .write_unaligned(self.prefix_length);
4942 out_ptr
4943 .add(44usize)
4944 .cast::<[u8; 16usize]>()
4945 .write_unaligned(self.gateway_ip_address);
4946 }
4947 }
4948 }
4949
4950 /// VLAN messaging device path node.
4951 #[derive(Debug)]
4952 pub struct Vlan {
4953 /// VLAN identifier (0-4094).
4954 pub vlan_id: u16,
4955 }
4956
4957 #[expect(clippy::undocumented_unsafe_blocks)]
4958 unsafe impl BuildNode for Vlan {
4959 fn size_in_bytes(&self) -> Result<u16, BuildError> {
4960 let size = 6usize;
4961 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
4962 }
4963
4964 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
4965 let size = usize::from(self.size_in_bytes().unwrap());
4966 assert_eq!(size, out.len());
4967 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
4968 let length = u16::try_from(size).unwrap();
4969 let header = DevicePathHeader::new(
4970 DeviceType::MESSAGING,
4971 DeviceSubType::MESSAGING_VLAN,
4972 length,
4973 );
4974 #[expect(clippy::undocumented_unsafe_blocks)]
4975 unsafe {
4976 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
4977 out_ptr
4978 .add(4usize)
4979 .cast::<u16>()
4980 .write_unaligned(self.vlan_id);
4981 }
4982 }
4983 }
4984
4985 /// InfiniBand messaging device path node.
4986 #[derive(Debug)]
4987 pub struct Infiniband {
4988 /// Flags to identify/manage InfiniBand elements.
4989 pub resource_flags: device_path::messaging::InfinibandResourceFlags,
4990 /// 128-bit Global Identifier for remote fabric port. Note that
4991 /// this is not the same as a UEFI GUID.
4992 pub port_gid: [u8; 16usize],
4993 /// IOC GUID if bit 0 of `resource_flags` is unset, or Service
4994 /// ID if bit 0 of `resource_flags` is set.
4995 pub ioc_guid_or_service_id: u64,
4996 /// 64-bit persistent ID of remote IOC port.
4997 pub target_port_id: u64,
4998 /// 64-bit persistent ID of remote device..
4999 pub device_id: u64,
5000 }
5001
5002 #[expect(clippy::undocumented_unsafe_blocks)]
5003 unsafe impl BuildNode for Infiniband {
5004 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5005 let size = 48usize;
5006 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5007 }
5008
5009 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5010 let size = usize::from(self.size_in_bytes().unwrap());
5011 assert_eq!(size, out.len());
5012 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5013 let length = u16::try_from(size).unwrap();
5014 let header = DevicePathHeader::new(
5015 DeviceType::MESSAGING,
5016 DeviceSubType::MESSAGING_INFINIBAND,
5017 length,
5018 );
5019 #[expect(clippy::undocumented_unsafe_blocks)]
5020 unsafe {
5021 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5022 out_ptr
5023 .add(4usize)
5024 .cast::<device_path::messaging::InfinibandResourceFlags>()
5025 .write_unaligned(self.resource_flags);
5026 out_ptr
5027 .add(8usize)
5028 .cast::<[u8; 16usize]>()
5029 .write_unaligned(self.port_gid);
5030 out_ptr
5031 .add(24usize)
5032 .cast::<u64>()
5033 .write_unaligned(self.ioc_guid_or_service_id);
5034 out_ptr
5035 .add(32usize)
5036 .cast::<u64>()
5037 .write_unaligned(self.target_port_id);
5038 out_ptr
5039 .add(40usize)
5040 .cast::<u64>()
5041 .write_unaligned(self.device_id);
5042 }
5043 }
5044 }
5045
5046 /// UART messaging device path node.
5047 #[derive(Debug)]
5048 pub struct Uart {
5049 /// Baud rate setting, or 0 to use the device's default.
5050 pub baud_rate: u64,
5051 /// Number of data bits, or 0 to use the device's default.
5052 pub data_bits: u8,
5053 /// Parity setting.
5054 pub parity: device_path::messaging::Parity,
5055 /// Number of stop bits.
5056 pub stop_bits: device_path::messaging::StopBits,
5057 }
5058
5059 #[expect(clippy::undocumented_unsafe_blocks)]
5060 unsafe impl BuildNode for Uart {
5061 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5062 let size = 19usize;
5063 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5064 }
5065
5066 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5067 let size = usize::from(self.size_in_bytes().unwrap());
5068 assert_eq!(size, out.len());
5069 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5070 let length = u16::try_from(size).unwrap();
5071 let header = DevicePathHeader::new(
5072 DeviceType::MESSAGING,
5073 DeviceSubType::MESSAGING_UART,
5074 length,
5075 );
5076 #[expect(clippy::undocumented_unsafe_blocks)]
5077 unsafe {
5078 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5079 out_ptr.add(4usize).write_bytes(0, size_of::<u32>());
5080 out_ptr
5081 .add(8usize)
5082 .cast::<u64>()
5083 .write_unaligned(self.baud_rate);
5084 out_ptr
5085 .add(16usize)
5086 .cast::<u8>()
5087 .write_unaligned(self.data_bits);
5088 out_ptr
5089 .add(17usize)
5090 .cast::<device_path::messaging::Parity>()
5091 .write_unaligned(self.parity);
5092 out_ptr
5093 .add(18usize)
5094 .cast::<device_path::messaging::StopBits>()
5095 .write_unaligned(self.stop_bits);
5096 }
5097 }
5098 }
5099
5100 /// Vendor-defined messaging device path node.
5101 #[derive(Debug)]
5102 pub struct Vendor<'a> {
5103 /// Vendor-assigned GUID that defines the data that follows.
5104 pub vendor_guid: Guid,
5105 /// Vendor-defined data.
5106 pub vendor_defined_data: &'a [u8],
5107 }
5108
5109 #[expect(clippy::undocumented_unsafe_blocks)]
5110 unsafe impl BuildNode for Vendor<'_> {
5111 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5112 let size = 20usize + size_of_val(self.vendor_defined_data);
5113 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5114 }
5115
5116 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5117 let size = usize::from(self.size_in_bytes().unwrap());
5118 assert_eq!(size, out.len());
5119 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5120 let length = u16::try_from(size).unwrap();
5121 let header = DevicePathHeader::new(
5122 DeviceType::MESSAGING,
5123 DeviceSubType::MESSAGING_VENDOR,
5124 length,
5125 );
5126 #[expect(clippy::undocumented_unsafe_blocks)]
5127 unsafe {
5128 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5129 out_ptr
5130 .add(4usize)
5131 .cast::<Guid>()
5132 .write_unaligned(self.vendor_guid);
5133 self.vendor_defined_data
5134 .as_ptr()
5135 .cast::<u8>()
5136 .copy_to_nonoverlapping(
5137 out_ptr.add(20usize),
5138 size_of_val(self.vendor_defined_data),
5139 );
5140 }
5141 }
5142 }
5143
5144 /// Serial Attached SCSI (SAS) extended messaging device path node.
5145 #[derive(Debug)]
5146 pub struct SasEx {
5147 /// SAS address.
5148 pub sas_address: [u8; 8usize],
5149 /// Logical Unit Number.
5150 pub logical_unit_number: [u8; 8usize],
5151 /// Information about the device and its interconnect.
5152 pub info: u16,
5153 /// Relative Target Port (RTP).
5154 pub relative_target_port: u16,
5155 }
5156
5157 #[expect(clippy::undocumented_unsafe_blocks)]
5158 unsafe impl BuildNode for SasEx {
5159 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5160 let size = 24usize;
5161 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5162 }
5163
5164 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5165 let size = usize::from(self.size_in_bytes().unwrap());
5166 assert_eq!(size, out.len());
5167 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5168 let length = u16::try_from(size).unwrap();
5169 let header = DevicePathHeader::new(
5170 DeviceType::MESSAGING,
5171 DeviceSubType::MESSAGING_SCSI_SAS_EX,
5172 length,
5173 );
5174 #[expect(clippy::undocumented_unsafe_blocks)]
5175 unsafe {
5176 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5177 out_ptr
5178 .add(4usize)
5179 .cast::<[u8; 8usize]>()
5180 .write_unaligned(self.sas_address);
5181 out_ptr
5182 .add(12usize)
5183 .cast::<[u8; 8usize]>()
5184 .write_unaligned(self.logical_unit_number);
5185 out_ptr
5186 .add(20usize)
5187 .cast::<u16>()
5188 .write_unaligned(self.info);
5189 out_ptr
5190 .add(22usize)
5191 .cast::<u16>()
5192 .write_unaligned(self.relative_target_port);
5193 }
5194 }
5195 }
5196
5197 /// iSCSI messaging device path node.
5198 #[derive(Debug)]
5199 pub struct Iscsi<'a> {
5200 /// Network protocol.
5201 pub protocol: device_path::messaging::IscsiProtocol,
5202 /// iSCSI login options (bitfield).
5203 pub options: device_path::messaging::IscsiLoginOptions,
5204 /// iSCSI Logical Unit Number.
5205 pub logical_unit_number: [u8; 8usize],
5206 /// iSCSI Target Portal group tag the initiator intends to
5207 /// establish a session with.
5208 pub target_portal_group_tag: u16,
5209 /// iSCSI Node Target name.
5210 ///
5211 /// The UEFI Specification does not specify how the string is
5212 /// encoded, but gives one example that appears to be
5213 /// null-terminated ASCII.
5214 pub iscsi_target_name: &'a [u8],
5215 }
5216
5217 #[expect(clippy::undocumented_unsafe_blocks)]
5218 unsafe impl BuildNode for Iscsi<'_> {
5219 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5220 let size = 18usize + size_of_val(self.iscsi_target_name);
5221 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5222 }
5223
5224 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5225 let size = usize::from(self.size_in_bytes().unwrap());
5226 assert_eq!(size, out.len());
5227 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5228 let length = u16::try_from(size).unwrap();
5229 let header = DevicePathHeader::new(
5230 DeviceType::MESSAGING,
5231 DeviceSubType::MESSAGING_ISCSI,
5232 length,
5233 );
5234 #[expect(clippy::undocumented_unsafe_blocks)]
5235 unsafe {
5236 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5237 out_ptr
5238 .add(4usize)
5239 .cast::<device_path::messaging::IscsiProtocol>()
5240 .write_unaligned(self.protocol);
5241 out_ptr
5242 .add(6usize)
5243 .cast::<device_path::messaging::IscsiLoginOptions>()
5244 .write_unaligned(self.options);
5245 out_ptr
5246 .add(8usize)
5247 .cast::<[u8; 8usize]>()
5248 .write_unaligned(self.logical_unit_number);
5249 out_ptr
5250 .add(16usize)
5251 .cast::<u16>()
5252 .write_unaligned(self.target_portal_group_tag);
5253 self.iscsi_target_name
5254 .as_ptr()
5255 .cast::<u8>()
5256 .copy_to_nonoverlapping(
5257 out_ptr.add(18usize),
5258 size_of_val(self.iscsi_target_name),
5259 );
5260 }
5261 }
5262 }
5263
5264 /// NVM Express namespace messaging device path node.
5265 #[derive(Debug)]
5266 pub struct NvmeNamespace {
5267 /// Namespace identifier (NSID). The values 0 and 0xffff_ffff
5268 /// are invalid.
5269 pub namespace_identifier: u32,
5270 /// IEEE Extended Unique Identifier (EUI-64), or 0 if the device
5271 /// does not have a EUI-64.
5272 pub ieee_extended_unique_identifier: u64,
5273 }
5274
5275 #[expect(clippy::undocumented_unsafe_blocks)]
5276 unsafe impl BuildNode for NvmeNamespace {
5277 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5278 let size = 16usize;
5279 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5280 }
5281
5282 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5283 let size = usize::from(self.size_in_bytes().unwrap());
5284 assert_eq!(size, out.len());
5285 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5286 let length = u16::try_from(size).unwrap();
5287 let header = DevicePathHeader::new(
5288 DeviceType::MESSAGING,
5289 DeviceSubType::MESSAGING_NVME_NAMESPACE,
5290 length,
5291 );
5292 #[expect(clippy::undocumented_unsafe_blocks)]
5293 unsafe {
5294 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5295 out_ptr
5296 .add(4usize)
5297 .cast::<u32>()
5298 .write_unaligned(self.namespace_identifier);
5299 out_ptr
5300 .add(8usize)
5301 .cast::<u64>()
5302 .write_unaligned(self.ieee_extended_unique_identifier);
5303 }
5304 }
5305 }
5306
5307 /// Uniform Resource Identifier (URI) messaging device path node.
5308 #[derive(Debug)]
5309 pub struct Uri<'a> {
5310 /// URI as defined by [RFC 3986](https://www.rfc-editor.org/rfc/rfc3986).
5311 pub value: &'a [u8],
5312 }
5313
5314 #[expect(clippy::undocumented_unsafe_blocks)]
5315 unsafe impl BuildNode for Uri<'_> {
5316 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5317 let size = 4usize + size_of_val(self.value);
5318 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5319 }
5320
5321 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5322 let size = usize::from(self.size_in_bytes().unwrap());
5323 assert_eq!(size, out.len());
5324 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5325 let length = u16::try_from(size).unwrap();
5326 let header = DevicePathHeader::new(
5327 DeviceType::MESSAGING,
5328 DeviceSubType::MESSAGING_URI,
5329 length,
5330 );
5331 #[expect(clippy::undocumented_unsafe_blocks)]
5332 unsafe {
5333 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5334 self.value
5335 .as_ptr()
5336 .cast::<u8>()
5337 .copy_to_nonoverlapping(out_ptr.add(4usize), size_of_val(self.value));
5338 }
5339 }
5340 }
5341
5342 /// Universal Flash Storage (UFS) messaging device path node.
5343 #[derive(Debug)]
5344 pub struct Ufs {
5345 /// Target ID on the UFS interface (PUN).
5346 pub target_id: u8,
5347 /// Logical Unit Number (LUN).
5348 pub logical_unit_number: u8,
5349 }
5350
5351 #[expect(clippy::undocumented_unsafe_blocks)]
5352 unsafe impl BuildNode for Ufs {
5353 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5354 let size = 6usize;
5355 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5356 }
5357
5358 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5359 let size = usize::from(self.size_in_bytes().unwrap());
5360 assert_eq!(size, out.len());
5361 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5362 let length = u16::try_from(size).unwrap();
5363 let header = DevicePathHeader::new(
5364 DeviceType::MESSAGING,
5365 DeviceSubType::MESSAGING_UFS,
5366 length,
5367 );
5368 #[expect(clippy::undocumented_unsafe_blocks)]
5369 unsafe {
5370 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5371 out_ptr
5372 .add(4usize)
5373 .cast::<u8>()
5374 .write_unaligned(self.target_id);
5375 out_ptr
5376 .add(5usize)
5377 .cast::<u8>()
5378 .write_unaligned(self.logical_unit_number);
5379 }
5380 }
5381 }
5382
5383 /// Secure Digital (SD) messaging device path node.
5384 #[derive(Debug)]
5385 pub struct Sd {
5386 /// Slot number.
5387 pub slot_number: u8,
5388 }
5389
5390 #[expect(clippy::undocumented_unsafe_blocks)]
5391 unsafe impl BuildNode for Sd {
5392 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5393 let size = 5usize;
5394 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5395 }
5396
5397 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5398 let size = usize::from(self.size_in_bytes().unwrap());
5399 assert_eq!(size, out.len());
5400 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5401 let length = u16::try_from(size).unwrap();
5402 let header = DevicePathHeader::new(
5403 DeviceType::MESSAGING,
5404 DeviceSubType::MESSAGING_SD,
5405 length,
5406 );
5407 #[expect(clippy::undocumented_unsafe_blocks)]
5408 unsafe {
5409 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5410 out_ptr
5411 .add(4usize)
5412 .cast::<u8>()
5413 .write_unaligned(self.slot_number);
5414 }
5415 }
5416 }
5417
5418 /// Bluetooth messaging device path node.
5419 #[derive(Debug)]
5420 pub struct Bluetooth {
5421 /// 48-bit bluetooth device address.
5422 pub device_address: [u8; 6usize],
5423 }
5424
5425 #[expect(clippy::undocumented_unsafe_blocks)]
5426 unsafe impl BuildNode for Bluetooth {
5427 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5428 let size = 10usize;
5429 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5430 }
5431
5432 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5433 let size = usize::from(self.size_in_bytes().unwrap());
5434 assert_eq!(size, out.len());
5435 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5436 let length = u16::try_from(size).unwrap();
5437 let header = DevicePathHeader::new(
5438 DeviceType::MESSAGING,
5439 DeviceSubType::MESSAGING_BLUETOOTH,
5440 length,
5441 );
5442 #[expect(clippy::undocumented_unsafe_blocks)]
5443 unsafe {
5444 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5445 out_ptr
5446 .add(4usize)
5447 .cast::<[u8; 6usize]>()
5448 .write_unaligned(self.device_address);
5449 }
5450 }
5451 }
5452
5453 /// Wi-Fi messaging device path node.
5454 #[derive(Debug)]
5455 pub struct Wifi {
5456 /// Service set identifier (SSID).
5457 pub ssid: [u8; 32usize],
5458 }
5459
5460 #[expect(clippy::undocumented_unsafe_blocks)]
5461 unsafe impl BuildNode for Wifi {
5462 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5463 let size = 36usize;
5464 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5465 }
5466
5467 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5468 let size = usize::from(self.size_in_bytes().unwrap());
5469 assert_eq!(size, out.len());
5470 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5471 let length = u16::try_from(size).unwrap();
5472 let header = DevicePathHeader::new(
5473 DeviceType::MESSAGING,
5474 DeviceSubType::MESSAGING_WIFI,
5475 length,
5476 );
5477 #[expect(clippy::undocumented_unsafe_blocks)]
5478 unsafe {
5479 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5480 out_ptr
5481 .add(4usize)
5482 .cast::<[u8; 32usize]>()
5483 .write_unaligned(self.ssid);
5484 }
5485 }
5486 }
5487
5488 /// Embedded Multi-Media Card (eMMC) messaging device path node.
5489 #[derive(Debug)]
5490 pub struct Emmc {
5491 /// Slot number.
5492 pub slot_number: u8,
5493 }
5494
5495 #[expect(clippy::undocumented_unsafe_blocks)]
5496 unsafe impl BuildNode for Emmc {
5497 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5498 let size = 5usize;
5499 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5500 }
5501
5502 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5503 let size = usize::from(self.size_in_bytes().unwrap());
5504 assert_eq!(size, out.len());
5505 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5506 let length = u16::try_from(size).unwrap();
5507 let header = DevicePathHeader::new(
5508 DeviceType::MESSAGING,
5509 DeviceSubType::MESSAGING_EMMC,
5510 length,
5511 );
5512 #[expect(clippy::undocumented_unsafe_blocks)]
5513 unsafe {
5514 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5515 out_ptr
5516 .add(4usize)
5517 .cast::<u8>()
5518 .write_unaligned(self.slot_number);
5519 }
5520 }
5521 }
5522
5523 /// BluetoothLE messaging device path node.
5524 #[derive(Debug)]
5525 pub struct BluetoothLe {
5526 /// 48-bit bluetooth device address.
5527 pub device_address: [u8; 6usize],
5528 /// Address type.
5529 pub address_type: device_path::messaging::BluetoothLeAddressType,
5530 }
5531
5532 #[expect(clippy::undocumented_unsafe_blocks)]
5533 unsafe impl BuildNode for BluetoothLe {
5534 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5535 let size = 11usize;
5536 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5537 }
5538
5539 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5540 let size = usize::from(self.size_in_bytes().unwrap());
5541 assert_eq!(size, out.len());
5542 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5543 let length = u16::try_from(size).unwrap();
5544 let header = DevicePathHeader::new(
5545 DeviceType::MESSAGING,
5546 DeviceSubType::MESSAGING_BLUETOOTH_LE,
5547 length,
5548 );
5549 #[expect(clippy::undocumented_unsafe_blocks)]
5550 unsafe {
5551 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5552 out_ptr
5553 .add(4usize)
5554 .cast::<[u8; 6usize]>()
5555 .write_unaligned(self.device_address);
5556 out_ptr
5557 .add(10usize)
5558 .cast::<device_path::messaging::BluetoothLeAddressType>()
5559 .write_unaligned(self.address_type);
5560 }
5561 }
5562 }
5563
5564 /// DNS messaging device path node.
5565 #[derive(Debug)]
5566 pub struct Dns<'a> {
5567 /// Whether the addresses are IPv4 or IPv6.
5568 pub address_type: device_path::messaging::DnsAddressType,
5569 /// One or more instances of the DNS server address.
5570 pub addresses: &'a [IpAddress],
5571 }
5572
5573 #[expect(clippy::undocumented_unsafe_blocks)]
5574 unsafe impl BuildNode for Dns<'_> {
5575 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5576 let size = 5usize + size_of_val(self.addresses);
5577 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5578 }
5579
5580 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5581 let size = usize::from(self.size_in_bytes().unwrap());
5582 assert_eq!(size, out.len());
5583 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5584 let length = u16::try_from(size).unwrap();
5585 let header = DevicePathHeader::new(
5586 DeviceType::MESSAGING,
5587 DeviceSubType::MESSAGING_DNS,
5588 length,
5589 );
5590 #[expect(clippy::undocumented_unsafe_blocks)]
5591 unsafe {
5592 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5593 out_ptr
5594 .add(4usize)
5595 .cast::<device_path::messaging::DnsAddressType>()
5596 .write_unaligned(self.address_type);
5597 self.addresses
5598 .as_ptr()
5599 .cast::<u8>()
5600 .copy_to_nonoverlapping(out_ptr.add(5usize), size_of_val(self.addresses));
5601 }
5602 }
5603 }
5604
5605 /// NVDIMM namespace messaging device path node.
5606 #[derive(Debug)]
5607 pub struct NvdimmNamespace {
5608 /// Namespace unique label identifier.
5609 pub uuid: [u8; 16usize],
5610 }
5611
5612 #[expect(clippy::undocumented_unsafe_blocks)]
5613 unsafe impl BuildNode for NvdimmNamespace {
5614 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5615 let size = 20usize;
5616 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5617 }
5618
5619 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5620 let size = usize::from(self.size_in_bytes().unwrap());
5621 assert_eq!(size, out.len());
5622 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5623 let length = u16::try_from(size).unwrap();
5624 let header = DevicePathHeader::new(
5625 DeviceType::MESSAGING,
5626 DeviceSubType::MESSAGING_NVDIMM_NAMESPACE,
5627 length,
5628 );
5629 #[expect(clippy::undocumented_unsafe_blocks)]
5630 unsafe {
5631 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5632 out_ptr
5633 .add(4usize)
5634 .cast::<[u8; 16usize]>()
5635 .write_unaligned(self.uuid);
5636 }
5637 }
5638 }
5639
5640 /// REST service messaging device path node.
5641 #[derive(Debug)]
5642 pub struct RestService<'a> {
5643 /// Type of REST service.
5644 pub service_type: device_path::messaging::RestServiceType,
5645 /// Whether the service is in-band or out-of-band.
5646 pub access_mode: device_path::messaging::RestServiceAccessMode,
5647 /// Vendor-specific data. Only used if the service type is [`VENDOR`].
5648 ///
5649 /// [`VENDOR`]: uefi::proto::device_path::messaging::RestServiceType
5650 pub vendor_guid_and_data: Option<RestServiceVendorData<'a>>,
5651 }
5652
5653 #[expect(clippy::undocumented_unsafe_blocks)]
5654 unsafe impl BuildNode for RestService<'_> {
5655 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5656 let size = 6usize + self.build_size_vendor_guid_and_data();
5657 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5658 }
5659
5660 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5661 let size = usize::from(self.size_in_bytes().unwrap());
5662 assert_eq!(size, out.len());
5663 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5664 let length = u16::try_from(size).unwrap();
5665 let header = DevicePathHeader::new(
5666 DeviceType::MESSAGING,
5667 DeviceSubType::MESSAGING_REST_SERVICE,
5668 length,
5669 );
5670 #[expect(clippy::undocumented_unsafe_blocks)]
5671 unsafe {
5672 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5673 out_ptr
5674 .add(4usize)
5675 .cast::<device_path::messaging::RestServiceType>()
5676 .write_unaligned(self.service_type);
5677 out_ptr
5678 .add(5usize)
5679 .cast::<device_path::messaging::RestServiceAccessMode>()
5680 .write_unaligned(self.access_mode);
5681 self.build_vendor_guid_and_data(&mut out[6usize..])
5682 }
5683 }
5684 }
5685
5686 /// NVME over Fabric (NVMe-oF) namespace messaging device path node.
5687 #[derive(Debug)]
5688 pub struct NvmeOfNamespace<'a> {
5689 /// Namespace Identifier Type (NIDT).
5690 pub nidt: u8,
5691 /// Namespace Identifier (NID).
5692 pub nid: [u8; 16usize],
5693 /// Unique identifier of an NVM subsystem stored as a
5694 /// null-terminated UTF-8 string. Maximum length of 224 bytes.
5695 pub subsystem_nqn: &'a [u8],
5696 }
5697
5698 #[expect(clippy::undocumented_unsafe_blocks)]
5699 unsafe impl BuildNode for NvmeOfNamespace<'_> {
5700 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5701 let size = 21usize + size_of_val(self.subsystem_nqn);
5702 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5703 }
5704
5705 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5706 let size = usize::from(self.size_in_bytes().unwrap());
5707 assert_eq!(size, out.len());
5708 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5709 let length = u16::try_from(size).unwrap();
5710 let header = DevicePathHeader::new(
5711 DeviceType::MESSAGING,
5712 DeviceSubType::MESSAGING_NVME_OF_NAMESPACE,
5713 length,
5714 );
5715 #[expect(clippy::undocumented_unsafe_blocks)]
5716 unsafe {
5717 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5718 out_ptr.add(4usize).cast::<u8>().write_unaligned(self.nidt);
5719 out_ptr
5720 .add(5usize)
5721 .cast::<[u8; 16usize]>()
5722 .write_unaligned(self.nid);
5723 self.subsystem_nqn
5724 .as_ptr()
5725 .cast::<u8>()
5726 .copy_to_nonoverlapping(
5727 out_ptr.add(21usize),
5728 size_of_val(self.subsystem_nqn),
5729 );
5730 }
5731 }
5732 }
5733
5734 /// Vendor-specific REST service data. Only used for service type [`VENDOR`].
5735 ///
5736 /// [`VENDOR`]: uefi::proto::device_path::messaging::RestServiceType
5737 #[derive(Debug)]
5738 pub struct RestServiceVendorData<'a> {
5739 /// Vendor GUID.
5740 pub vendor_guid: Guid,
5741 /// Vendor-defined data.
5742 pub vendor_defined_data: &'a [u8],
5743 }
5744
5745 impl RestService<'_> {
5746 fn build_size_vendor_guid_and_data(&self) -> usize {
5747 if let Some(src) = &self.vendor_guid_and_data {
5748 assert!(self.service_type == device_path::messaging::RestServiceType::VENDOR);
5749 size_of::<Guid>() + size_of_val(src.vendor_defined_data)
5750 } else {
5751 0
5752 }
5753 }
5754
5755 fn build_vendor_guid_and_data(&self, out: &mut [MaybeUninit<u8>]) {
5756 if let Some(src) = &self.vendor_guid_and_data {
5757 assert!(self.service_type == device_path::messaging::RestServiceType::VENDOR);
5758 let (guid_out, data_out) = out.split_at_mut(size_of::<Guid>());
5759 let guid_out_ptr: *mut Guid = maybe_uninit_slice_as_mut_ptr(guid_out).cast();
5760 #[expect(clippy::undocumented_unsafe_blocks)]
5761 unsafe {
5762 guid_out_ptr.write_unaligned(src.vendor_guid);
5763 }
5764
5765 let data_out_ptr = maybe_uninit_slice_as_mut_ptr(data_out);
5766 #[expect(clippy::undocumented_unsafe_blocks)]
5767 unsafe {
5768 src.vendor_defined_data
5769 .as_ptr()
5770 .copy_to_nonoverlapping(data_out_ptr, data_out.len());
5771 }
5772 }
5773 }
5774 }
5775 }
5776
5777 /// Device path build nodes for [`DeviceType::MEDIA`].
5778 pub mod media {
5779 use super::*;
5780 /// Hard drive media device path node.
5781 #[derive(Debug)]
5782 pub struct HardDrive {
5783 /// Index of the partition, starting from 1.
5784 pub partition_number: u32,
5785 /// Starting LBA (logical block address) of the partition.
5786 pub partition_start: u64,
5787 /// Size of the partition in blocks.
5788 pub partition_size: u64,
5789 /// Partition signature.
5790 pub partition_signature: device_path::media::PartitionSignature,
5791 /// Partition format.
5792 pub partition_format: device_path::media::PartitionFormat,
5793 }
5794
5795 #[expect(clippy::undocumented_unsafe_blocks)]
5796 unsafe impl BuildNode for HardDrive {
5797 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5798 let size = 42usize;
5799 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5800 }
5801
5802 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5803 let size = usize::from(self.size_in_bytes().unwrap());
5804 assert_eq!(size, out.len());
5805 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5806 let length = u16::try_from(size).unwrap();
5807 let header = DevicePathHeader::new(
5808 DeviceType::MEDIA,
5809 DeviceSubType::MEDIA_HARD_DRIVE,
5810 length,
5811 );
5812 #[expect(clippy::undocumented_unsafe_blocks)]
5813 unsafe {
5814 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5815 out_ptr
5816 .add(4usize)
5817 .cast::<u32>()
5818 .write_unaligned(self.partition_number);
5819 out_ptr
5820 .add(8usize)
5821 .cast::<u64>()
5822 .write_unaligned(self.partition_start);
5823 out_ptr
5824 .add(16usize)
5825 .cast::<u64>()
5826 .write_unaligned(self.partition_size);
5827 out_ptr
5828 .add(24usize)
5829 .cast::<[u8; 16usize]>()
5830 .write_unaligned(self.build_partition_signature());
5831 out_ptr
5832 .add(40usize)
5833 .cast::<device_path::media::PartitionFormat>()
5834 .write_unaligned(self.partition_format);
5835 out_ptr
5836 .add(41usize)
5837 .cast::<u8>()
5838 .write_unaligned(self.build_signature_type());
5839 }
5840 }
5841 }
5842
5843 /// CD-ROM media device path node.
5844 #[derive(Debug)]
5845 pub struct CdRom {
5846 /// Boot entry number from the boot catalog, or 0 for the
5847 /// default entry.
5848 pub boot_entry: u32,
5849 /// Starting RBA (Relative logical Block Address).
5850 pub partition_start: u64,
5851 /// Size of the partition in blocks.
5852 pub partition_size: u64,
5853 }
5854
5855 #[expect(clippy::undocumented_unsafe_blocks)]
5856 unsafe impl BuildNode for CdRom {
5857 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5858 let size = 24usize;
5859 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5860 }
5861
5862 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5863 let size = usize::from(self.size_in_bytes().unwrap());
5864 assert_eq!(size, out.len());
5865 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5866 let length = u16::try_from(size).unwrap();
5867 let header =
5868 DevicePathHeader::new(DeviceType::MEDIA, DeviceSubType::MEDIA_CD_ROM, length);
5869 #[expect(clippy::undocumented_unsafe_blocks)]
5870 unsafe {
5871 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5872 out_ptr
5873 .add(4usize)
5874 .cast::<u32>()
5875 .write_unaligned(self.boot_entry);
5876 out_ptr
5877 .add(8usize)
5878 .cast::<u64>()
5879 .write_unaligned(self.partition_start);
5880 out_ptr
5881 .add(16usize)
5882 .cast::<u64>()
5883 .write_unaligned(self.partition_size);
5884 }
5885 }
5886 }
5887
5888 /// Vendor-defined media device path node.
5889 #[derive(Debug)]
5890 pub struct Vendor<'a> {
5891 /// Vendor-assigned GUID that defines the data that follows.
5892 pub vendor_guid: Guid,
5893 /// Vendor-defined data.
5894 pub vendor_defined_data: &'a [u8],
5895 }
5896
5897 #[expect(clippy::undocumented_unsafe_blocks)]
5898 unsafe impl BuildNode for Vendor<'_> {
5899 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5900 let size = 20usize + size_of_val(self.vendor_defined_data);
5901 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5902 }
5903
5904 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5905 let size = usize::from(self.size_in_bytes().unwrap());
5906 assert_eq!(size, out.len());
5907 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5908 let length = u16::try_from(size).unwrap();
5909 let header =
5910 DevicePathHeader::new(DeviceType::MEDIA, DeviceSubType::MEDIA_VENDOR, length);
5911 #[expect(clippy::undocumented_unsafe_blocks)]
5912 unsafe {
5913 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5914 out_ptr
5915 .add(4usize)
5916 .cast::<Guid>()
5917 .write_unaligned(self.vendor_guid);
5918 self.vendor_defined_data
5919 .as_ptr()
5920 .cast::<u8>()
5921 .copy_to_nonoverlapping(
5922 out_ptr.add(20usize),
5923 size_of_val(self.vendor_defined_data),
5924 );
5925 }
5926 }
5927 }
5928
5929 /// File path media device path node.
5930 #[derive(Debug)]
5931 pub struct FilePath<'a> {
5932 /// Null-terminated path.
5933 pub path_name: &'a CStr16,
5934 }
5935
5936 #[expect(clippy::undocumented_unsafe_blocks)]
5937 unsafe impl BuildNode for FilePath<'_> {
5938 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5939 let size = 4usize + size_of_val(self.path_name);
5940 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5941 }
5942
5943 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5944 let size = usize::from(self.size_in_bytes().unwrap());
5945 assert_eq!(size, out.len());
5946 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5947 let length = u16::try_from(size).unwrap();
5948 let header = DevicePathHeader::new(
5949 DeviceType::MEDIA,
5950 DeviceSubType::MEDIA_FILE_PATH,
5951 length,
5952 );
5953 #[expect(clippy::undocumented_unsafe_blocks)]
5954 unsafe {
5955 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5956 self.path_name
5957 .as_ptr()
5958 .cast::<u8>()
5959 .copy_to_nonoverlapping(out_ptr.add(4usize), size_of_val(self.path_name));
5960 }
5961 }
5962 }
5963
5964 /// Media protocol media device path node.
5965 #[derive(Debug)]
5966 pub struct Protocol {
5967 /// The ID of the protocol.
5968 pub protocol_guid: Guid,
5969 }
5970
5971 #[expect(clippy::undocumented_unsafe_blocks)]
5972 unsafe impl BuildNode for Protocol {
5973 fn size_in_bytes(&self) -> Result<u16, BuildError> {
5974 let size = 20usize;
5975 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
5976 }
5977
5978 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
5979 let size = usize::from(self.size_in_bytes().unwrap());
5980 assert_eq!(size, out.len());
5981 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
5982 let length = u16::try_from(size).unwrap();
5983 let header =
5984 DevicePathHeader::new(DeviceType::MEDIA, DeviceSubType::MEDIA_PROTOCOL, length);
5985 #[expect(clippy::undocumented_unsafe_blocks)]
5986 unsafe {
5987 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
5988 out_ptr
5989 .add(4usize)
5990 .cast::<Guid>()
5991 .write_unaligned(self.protocol_guid);
5992 }
5993 }
5994 }
5995
5996 /// PIWG firmware file media device path node.
5997 #[derive(Debug)]
5998 pub struct PiwgFirmwareFile<'a> {
5999 /// Contents are defined in the UEFI PI Specification.
6000 pub data: &'a [u8],
6001 }
6002
6003 #[expect(clippy::undocumented_unsafe_blocks)]
6004 unsafe impl BuildNode for PiwgFirmwareFile<'_> {
6005 fn size_in_bytes(&self) -> Result<u16, BuildError> {
6006 let size = 4usize + size_of_val(self.data);
6007 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
6008 }
6009
6010 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
6011 let size = usize::from(self.size_in_bytes().unwrap());
6012 assert_eq!(size, out.len());
6013 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
6014 let length = u16::try_from(size).unwrap();
6015 let header = DevicePathHeader::new(
6016 DeviceType::MEDIA,
6017 DeviceSubType::MEDIA_PIWG_FIRMWARE_FILE,
6018 length,
6019 );
6020 #[expect(clippy::undocumented_unsafe_blocks)]
6021 unsafe {
6022 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
6023 self.data
6024 .as_ptr()
6025 .cast::<u8>()
6026 .copy_to_nonoverlapping(out_ptr.add(4usize), size_of_val(self.data));
6027 }
6028 }
6029 }
6030
6031 /// PIWG firmware volume media device path node.
6032 #[derive(Debug)]
6033 pub struct PiwgFirmwareVolume<'a> {
6034 /// Contents are defined in the UEFI PI Specification.
6035 pub data: &'a [u8],
6036 }
6037
6038 #[expect(clippy::undocumented_unsafe_blocks)]
6039 unsafe impl BuildNode for PiwgFirmwareVolume<'_> {
6040 fn size_in_bytes(&self) -> Result<u16, BuildError> {
6041 let size = 4usize + size_of_val(self.data);
6042 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
6043 }
6044
6045 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
6046 let size = usize::from(self.size_in_bytes().unwrap());
6047 assert_eq!(size, out.len());
6048 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
6049 let length = u16::try_from(size).unwrap();
6050 let header = DevicePathHeader::new(
6051 DeviceType::MEDIA,
6052 DeviceSubType::MEDIA_PIWG_FIRMWARE_VOLUME,
6053 length,
6054 );
6055 #[expect(clippy::undocumented_unsafe_blocks)]
6056 unsafe {
6057 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
6058 self.data
6059 .as_ptr()
6060 .cast::<u8>()
6061 .copy_to_nonoverlapping(out_ptr.add(4usize), size_of_val(self.data));
6062 }
6063 }
6064 }
6065
6066 /// Relative offset range media device path node.
6067 #[derive(Debug)]
6068 pub struct RelativeOffsetRange {
6069 /// Offset of the first byte, relative to the parent device node.
6070 pub starting_offset: u64,
6071 /// Offset of the last byte, relative to the parent device node.
6072 pub ending_offset: u64,
6073 }
6074
6075 #[expect(clippy::undocumented_unsafe_blocks)]
6076 unsafe impl BuildNode for RelativeOffsetRange {
6077 fn size_in_bytes(&self) -> Result<u16, BuildError> {
6078 let size = 24usize;
6079 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
6080 }
6081
6082 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
6083 let size = usize::from(self.size_in_bytes().unwrap());
6084 assert_eq!(size, out.len());
6085 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
6086 let length = u16::try_from(size).unwrap();
6087 let header = DevicePathHeader::new(
6088 DeviceType::MEDIA,
6089 DeviceSubType::MEDIA_RELATIVE_OFFSET_RANGE,
6090 length,
6091 );
6092 #[expect(clippy::undocumented_unsafe_blocks)]
6093 unsafe {
6094 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
6095 out_ptr.add(4usize).write_bytes(0, size_of::<u32>());
6096 out_ptr
6097 .add(8usize)
6098 .cast::<u64>()
6099 .write_unaligned(self.starting_offset);
6100 out_ptr
6101 .add(16usize)
6102 .cast::<u64>()
6103 .write_unaligned(self.ending_offset);
6104 }
6105 }
6106 }
6107
6108 /// RAM disk media device path node.
6109 #[derive(Debug)]
6110 pub struct RamDisk {
6111 /// Starting memory address.
6112 pub starting_address: u64,
6113 /// Ending memory address.
6114 pub ending_address: u64,
6115 /// Type of RAM disk.
6116 pub disk_type: device_path::media::RamDiskType,
6117 /// RAM disk instance number if supported, otherwise 0.
6118 pub disk_instance: u16,
6119 }
6120
6121 #[expect(clippy::undocumented_unsafe_blocks)]
6122 unsafe impl BuildNode for RamDisk {
6123 fn size_in_bytes(&self) -> Result<u16, BuildError> {
6124 let size = 38usize;
6125 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
6126 }
6127
6128 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
6129 let size = usize::from(self.size_in_bytes().unwrap());
6130 assert_eq!(size, out.len());
6131 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
6132 let length = u16::try_from(size).unwrap();
6133 let header =
6134 DevicePathHeader::new(DeviceType::MEDIA, DeviceSubType::MEDIA_RAM_DISK, length);
6135 #[expect(clippy::undocumented_unsafe_blocks)]
6136 unsafe {
6137 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
6138 out_ptr
6139 .add(4usize)
6140 .cast::<u64>()
6141 .write_unaligned(self.starting_address);
6142 out_ptr
6143 .add(12usize)
6144 .cast::<u64>()
6145 .write_unaligned(self.ending_address);
6146 out_ptr
6147 .add(20usize)
6148 .cast::<device_path::media::RamDiskType>()
6149 .write_unaligned(self.disk_type);
6150 out_ptr
6151 .add(36usize)
6152 .cast::<u16>()
6153 .write_unaligned(self.disk_instance);
6154 }
6155 }
6156 }
6157
6158 impl HardDrive {
6159 fn build_partition_signature(&self) -> [u8; 16] {
6160 use device_path::media::PartitionSignature::*;
6161 match self.partition_signature {
6162 None => [0u8; 16],
6163 Mbr(mbr) => {
6164 let mut sig = [0u8; 16];
6165 sig[0..4].copy_from_slice(&mbr);
6166 sig
6167 }
6168
6169 Guid(guid) => guid.to_bytes(),
6170 Unknown { signature, .. } => signature,
6171 }
6172 }
6173
6174 fn build_signature_type(&self) -> u8 {
6175 use device_path::media::PartitionSignature::*;
6176 match self.partition_signature {
6177 None => 0,
6178 Mbr(_) => 1,
6179 Guid(_) => 2,
6180 Unknown { signature_type, .. } => signature_type,
6181 }
6182 }
6183 }
6184 }
6185
6186 /// Device path build nodes for [`DeviceType::BIOS_BOOT_SPEC`].
6187 pub mod bios_boot_spec {
6188 use super::*;
6189 /// BIOS Boot Specification device path node.
6190 #[derive(Debug)]
6191 pub struct BootSpecification<'a> {
6192 /// Device type as defined by the BIOS Boot Specification.
6193 pub device_type: u16,
6194 /// Status flags as defined by the BIOS Boot Specification.
6195 pub status_flag: u16,
6196 /// Description of the boot device encoded as a null-terminated
6197 /// ASCII string.
6198 pub description_string: &'a [u8],
6199 }
6200
6201 #[expect(clippy::undocumented_unsafe_blocks)]
6202 unsafe impl BuildNode for BootSpecification<'_> {
6203 fn size_in_bytes(&self) -> Result<u16, BuildError> {
6204 let size = 8usize + size_of_val(self.description_string);
6205 u16::try_from(size).map_err(|_| BuildError::NodeTooBig)
6206 }
6207
6208 fn write_data(&self, out: &mut [MaybeUninit<u8>]) {
6209 let size = usize::from(self.size_in_bytes().unwrap());
6210 assert_eq!(size, out.len());
6211 let out_ptr: *mut u8 = maybe_uninit_slice_as_mut_ptr(out);
6212 let length = u16::try_from(size).unwrap();
6213 let header = DevicePathHeader::new(
6214 DeviceType::BIOS_BOOT_SPEC,
6215 DeviceSubType::BIOS_BOOT_SPECIFICATION,
6216 length,
6217 );
6218 #[expect(clippy::undocumented_unsafe_blocks)]
6219 unsafe {
6220 out_ptr.cast::<DevicePathHeader>().write_unaligned(header);
6221 out_ptr
6222 .add(4usize)
6223 .cast::<u16>()
6224 .write_unaligned(self.device_type);
6225 out_ptr
6226 .add(6usize)
6227 .cast::<u16>()
6228 .write_unaligned(self.status_flag);
6229 self.description_string
6230 .as_ptr()
6231 .cast::<u8>()
6232 .copy_to_nonoverlapping(
6233 out_ptr.add(8usize),
6234 size_of_val(self.description_string),
6235 );
6236 }
6237 }
6238 }
6239 }
6240}