1
1
// SPDX-License-Identifier: MIT OR Apache-2.0
2
2
3
- //! Device Path protocol
3
+ //! The UEFI device path [`Protocol`], i.e., UEFI device paths.
4
4
//!
5
- //! A UEFI device path is a very flexible structure for encoding a
6
- //! programmatic path such as a hard drive or console.
5
+ //! This module provides high-level wrappers to work with UEFI device paths.
6
+ //! Please find additional low-level information in the
7
+ //! [device path section of `uefi-raw`].
7
8
//!
8
- //! A device path is made up of a packed list of variable-length nodes of
9
- //! various types. The entire device path is terminated with an
10
- //! [`END_ENTIRE`] node. A device path _may_ contain multiple device-path
11
- //! instances separated by [`END_INSTANCE`] nodes, but typical paths contain
12
- //! only a single instance (in which case no `END_INSTANCE` node is needed).
9
+ //! # Terminology: Device Paths, Device Path Instances, and Device Path Nodes
10
+ //! An open UEFI device path [`Protocol`], also called _device path_, is a
11
+ //! flexible and structured sequence of binary nodes that describe a route from
12
+ //! the UEFI root to a particular device, controller, or file.
13
+ //!
14
+ //! An entire device path can be made up of multiple device path instances,
15
+ //! and each instance is made up of multiple device path nodes. A device path
16
+ //! _may_ contain multiple device-path instances, but typical paths contain only
17
+ //! a single instance.
18
+ //!
19
+ //! Each node represents a step in the path: PCI device, partition, filesystem,
20
+ //! file path, etc. Each node represents a step in the path: PCI device,
21
+ //! partition, filesystem, file path, etc.
13
22
//!
14
23
//! Example of what a device path containing two instances (each comprised of
15
24
//! three nodes) might look like:
16
25
//!
17
26
//! ```text
18
- //! ┌──────┬─────┬──────────────╥───────┬──────────┬────────────┐
19
- //! │ ACPI │ PCI │ END_INSTANCE ║ CDROM │ FILEPATH │ END_ENTIRE │
20
- //! └──────┴─────┴──────────────╨───────┴──────────┴────────────┘
21
- //! ↑ ↑ ↑
22
- //! ├─── DevicePathInstance ────╨────── DevicePathInstance ─────┤
23
- //! │ │
24
- //! └─────────────────── Entire DevicePath ─────────────────────┘
27
+ //! ┌──────┬──────┬──────────────╥───────┬──────────┬────────────┐
28
+ //! │ ACPI │ PCI │ END_INSTANCE ║ CDROM │ FILEPATH │ END_ENTIRE │
29
+ //! └──────┴──────┴──────────────╨───────┴──────────┴────────────┘
30
+ //! ↑ ↑ ↑ ↑ ↑ ↑ ↑
31
+ //! ├─Node─╨─Node─╨─────Node─────╨─Node──╨───Node───╨────Node────┤
32
+ //! ↑ ↑ ↑
33
+ //! ├─── DevicePathInstance ─────╨────── DevicePathInstance ─────┤
34
+ //! │ │
35
+ //! └──────────────────── Entire DevicePath ─────────────────────┘
25
36
//! ```
26
37
//!
27
38
//! # Types
74
85
//! [`Protocol`]: crate::proto::Protocol
75
86
//! [`device_type`]: DevicePathNode::device_type
76
87
//! [`sub_type`]: DevicePathNode::sub_type
88
+ //! [device path section of `uefi-raw`]: uefi_raw::protocol::device_path
77
89
78
90
pub mod build;
79
91
pub mod text;
@@ -92,7 +104,6 @@ use core::ffi::c_void;
92
104
use core:: fmt:: { self , Debug , Display , Formatter } ;
93
105
use core:: ops:: Deref ;
94
106
use ptr_meta:: Pointee ;
95
-
96
107
use uefi_raw:: protocol:: device_path:: DevicePathProtocol ;
97
108
#[ cfg( feature = "alloc" ) ]
98
109
use {
@@ -400,21 +411,49 @@ impl ToOwned for DevicePathInstance {
400
411
}
401
412
}
402
413
403
- /// Device path protocol.
414
+ /// High-level representation of the UEFI [device path protocol] .
404
415
///
405
- /// Can be used on any device handle to obtain generic path/location information
406
- /// concerning the physical device or logical device. If the handle does not
407
- /// logically map to a physical device, the handle may not necessarily support
408
- /// the device path protocol. The device path describes the location of the
409
- /// device the handle is for. The size of the Device Path can be determined from
410
- /// the structures that make up the Device Path.
416
+ /// This type represents an entire device path, possibly consisting of multiple
417
+ /// [`DevicePathInstance`]s and [`DevicePathNode`]s.
411
418
///
412
419
/// See the [module-level documentation] for more details.
413
420
///
421
+ /// # Usage
422
+ /// This type implements [`Protocol`] and therefore can be used on any
423
+ /// device handle to obtain generic path/location information concerning the
424
+ /// physical device or logical device. If the handle does not logically map to a
425
+ /// physical device, the handle may not necessarily support the device path
426
+ /// protocol. The device path describes the location of the device the handle is
427
+ /// for. The size of the Device Path can be determined from the structures that
428
+ /// make up the Device Path.
429
+ ///
430
+ /// # Example
431
+ /// ```rust,no_run
432
+ /// use uefi::Handle;
433
+ /// use uefi::boot::{open_protocol_exclusive, ScopedProtocol};
434
+ /// use uefi::proto::device_path::DevicePath;
435
+ /// use uefi::proto::device_path::text::{AllowShortcuts, DisplayOnly};
436
+ /// use uefi::proto::loaded_image::LoadedImage;
437
+ ///
438
+ /// fn open_device_path(image_handle: Handle) {
439
+ /// let loaded_image = open_protocol_exclusive::<LoadedImage>(image_handle).unwrap();
440
+ /// let device_handle = loaded_image.device().unwrap();
441
+ /// let device_path: ScopedProtocol<DevicePath>
442
+ /// = open_protocol_exclusive::<DevicePath>(device_handle).unwrap();
443
+ /// log::debug!(
444
+ /// "Device path: {}",
445
+ /// device_path.to_string(DisplayOnly(true), AllowShortcuts(true)).unwrap()
446
+ /// );
447
+ /// }
448
+ /// ```
449
+ ///
414
450
/// [module-level documentation]: crate::proto::device_path
415
451
/// [`END_ENTIRE`]: DeviceSubType::END_ENTIRE
452
+ /// [`DevicePathProtocol`]: uefi_raw::protocol::device_path::DevicePathProtocol
453
+ /// [`Protocol`]: uefi::proto::Protocol
454
+ /// [device path protocol]: uefi_raw::protocol::device_path
416
455
#[ repr( C , packed) ]
417
- #[ unsafe_protocol( uefi_raw :: protocol :: device_path :: DevicePathProtocol :: GUID ) ]
456
+ #[ unsafe_protocol( DevicePathProtocol :: GUID ) ]
418
457
#[ derive( Eq , Pointee ) ]
419
458
pub struct DevicePath {
420
459
data : [ u8 ] ,
0 commit comments