Skip to content

Commit eb0849f

Browse files
relicensing: Rewrite PR "DevicePathToText and DevicePathFromText Protocol"
This covers these commits: fa91d55 1c95dd5 704e98b
1 parent f10465a commit eb0849f

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

Diff for: uefi/src/proto/device_path/text.rs

+38-41
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! `DevicePathToText` and `DevicePathFromText` Protocol
1+
//! Protocols for converting between UEFI strings and [`DevicePath`]/[`DevicePathNode`].
22
33
// Note on return types: the specification of the conversion functions
44
// is a little unusual in that they return a pointer rather than
@@ -16,32 +16,39 @@ use core::ops::Deref;
1616
use core::ptr::NonNull;
1717
use uefi_raw::protocol::device_path::{DevicePathFromTextProtocol, DevicePathToTextProtocol};
1818

19-
/// This struct is a wrapper of `display_only` parameter
20-
/// used by Device Path to Text protocol.
19+
/// Parameter for [`DevicePathToText`] that alters the output format.
2120
///
22-
/// The `display_only` parameter controls whether the longer
23-
/// (parseable) or shorter (display-only) form of the conversion
24-
/// is used. If `display_only` is TRUE, then the shorter text
25-
/// representation of the display node is used, where applicable.
26-
/// If `display_only` is FALSE, then the longer text representation
27-
/// of the display node is used.
21+
/// * `DisplayOnly(false)` produces parseable output.
22+
/// * `DisplayOnly(true)` produces output that _may_ be shorter and not
23+
/// parseable.
24+
///
25+
/// Example of how a node's text representation may be altered by this
26+
/// parameter:
27+
/// * `DisplayOnly(false)`: `Ata(Primary,Master,0x1)`
28+
/// * `DisplayOnly(true)`: `Ata(0x1)`
2829
#[derive(Clone, Copy, Debug)]
2930
pub struct DisplayOnly(pub bool);
3031

31-
/// This struct is a wrapper of `allow_shortcuts` parameter
32-
/// used by Device Path to Text protocol.
32+
/// Parameter for [`DevicePathToText`] that alters the output format.
33+
///
34+
/// * `AllowShortcuts(false)`: node names are based only on the node's type and
35+
/// subtype.
36+
/// * `AllowShortcuts(true)` _may_ alter the node name based on other fields
37+
/// within the node.
3338
///
34-
/// The `allow_shortcuts` is FALSE, then the shortcut forms of
35-
/// text representation for a device node cannot be used. A
36-
/// shortcut form is one which uses information other than the
37-
/// type or subtype. If `allow_shortcuts is TRUE, then the
38-
/// shortcut forms of text representation for a device node
39-
/// can be used, where applicable.
39+
/// Example of how a node's text representation may be altered by this
40+
/// parameter:
41+
/// * `AllowShortcuts(false)`: `VenMsg(E0C14753-F9BE-11D2-9A0C-0090273FC14D)`
42+
/// * `AllowShortcuts(true)`: `VenPcAnsi()`
4043
#[derive(Clone, Copy, Debug)]
4144
pub struct AllowShortcuts(pub bool);
4245

43-
/// Wrapper for a string internally allocated from
44-
/// UEFI boot services memory.
46+
/// UCS-2 string allocated from UEFI pool memory.
47+
///
48+
/// This is similar to a [`CString16`], but used for memory that was allocated
49+
/// internally by UEFI rather than the Rust allocator.
50+
///
51+
/// [`CString16`]: crate::CString16
4552
#[derive(Debug)]
4653
pub struct PoolString(PoolAllocation);
4754

@@ -85,17 +92,14 @@ impl Deref for PoolDevicePathNode {
8592
}
8693
}
8794

88-
/// Device Path to Text protocol.
89-
///
90-
/// This protocol provides common utility functions for converting device
91-
/// nodes and device paths to a text representation.
95+
/// Protocol for converting a [`DevicePath`] or `DevicePathNode`] to a string.
9296
#[derive(Debug)]
9397
#[repr(transparent)]
9498
#[unsafe_protocol(DevicePathToTextProtocol::GUID)]
9599
pub struct DevicePathToText(DevicePathToTextProtocol);
96100

97101
impl DevicePathToText {
98-
/// Convert a device node to its text representation.
102+
/// Convert a [`DevicePathNode`] to a [`PoolString`].
99103
///
100104
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
101105
/// memory for the conversion.
@@ -107,17 +111,17 @@ impl DevicePathToText {
107111
display_only: DisplayOnly,
108112
allow_shortcuts: AllowShortcuts,
109113
) -> Result<PoolString> {
110-
let text_device_node = unsafe {
114+
let text = unsafe {
111115
(self.0.convert_device_node_to_text)(
112116
device_node.as_ffi_ptr().cast(),
113117
display_only.0,
114118
allow_shortcuts.0,
115119
)
116120
};
117-
PoolString::new(text_device_node.cast())
121+
PoolString::new(text.cast())
118122
}
119123

120-
/// Convert a device path to its text representation.
124+
/// Convert a [`DevicePath`] to a [`PoolString`].
121125
///
122126
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
123127
/// memory for the conversion.
@@ -129,32 +133,27 @@ impl DevicePathToText {
129133
display_only: DisplayOnly,
130134
allow_shortcuts: AllowShortcuts,
131135
) -> Result<PoolString> {
132-
let text_device_path = unsafe {
136+
let text = unsafe {
133137
(self.0.convert_device_path_to_text)(
134138
device_path.as_ffi_ptr().cast(),
135139
display_only.0,
136140
allow_shortcuts.0,
137141
)
138142
};
139-
PoolString::new(text_device_path.cast())
143+
PoolString::new(text.cast())
140144
}
141145
}
142146

143-
/// Device Path from Text protocol.
144-
///
145-
/// This protocol provides common utilities for converting text to
146-
/// device paths and device nodes.
147+
/// Protocol for converting a string to a [`DevicePath`] or `DevicePathNode`].
147148
#[derive(Debug)]
148149
#[repr(transparent)]
149150
#[unsafe_protocol("05c99a21-c70f-4ad2-8a5f-35df3343f51e")]
150151
pub struct DevicePathFromText(DevicePathFromTextProtocol);
151152

152153
impl DevicePathFromText {
153-
/// Convert text to the binary representation of a device node.
154+
/// Convert a [`CStr16`] to a [`DevicePathNode`].
154155
///
155-
/// `text_device_node` is the text representation of a device node.
156-
/// Conversion starts with the first character and continues until
157-
/// the first non-device node character.
156+
/// If a non-device-node character is encountered, the rest of the string is ignored.
158157
///
159158
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
160159
/// memory for the conversion.
@@ -172,11 +171,9 @@ impl DevicePathFromText {
172171
}
173172
}
174173

175-
/// Convert a text to its binary device path representation.
174+
/// Convert a [`CStr16`] to a [`DevicePath`].
176175
///
177-
/// `text_device_path` is the text representation of a device path.
178-
/// Conversion starts with the first character and continues until
179-
/// the first non-device path character.
176+
/// If a non-device-node character is encountered, the rest of the string is ignored.
180177
///
181178
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
182179
/// memory for the conversion.

0 commit comments

Comments
 (0)