1
- //! `DevicePathToText` and `DevicePathFromText` Protocol
1
+ //! Protocols for converting between UEFI strings and [`DevicePath`]/[`DevicePathNode`].
2
2
3
3
// Note on return types: the specification of the conversion functions
4
4
// is a little unusual in that they return a pointer rather than
@@ -16,32 +16,37 @@ use core::ops::Deref;
16
16
use core:: ptr:: NonNull ;
17
17
use uefi_raw:: protocol:: device_path:: { DevicePathFromTextProtocol , DevicePathToTextProtocol } ;
18
18
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.
21
20
///
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)`
28
29
#[ derive( Clone , Copy , Debug ) ]
29
30
pub struct DisplayOnly ( pub bool ) ;
30
31
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.
33
38
///
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()`
40
43
#[ derive( Clone , Copy , Debug ) ]
41
44
pub struct AllowShortcuts ( pub bool ) ;
42
45
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.
45
50
#[ derive( Debug ) ]
46
51
pub struct PoolString ( PoolAllocation ) ;
47
52
@@ -85,17 +90,14 @@ impl Deref for PoolDevicePathNode {
85
90
}
86
91
}
87
92
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.
93
+ /// Protocol for converting a [`DevicePath`] or `DevicePathNode`] to a string.
92
94
#[ derive( Debug ) ]
93
95
#[ repr( transparent) ]
94
96
#[ unsafe_protocol( DevicePathToTextProtocol :: GUID ) ]
95
97
pub struct DevicePathToText ( DevicePathToTextProtocol ) ;
96
98
97
99
impl DevicePathToText {
98
- /// Convert a device node to its text representation .
100
+ /// Convert a [`DevicePathNode`] to a [`PoolString`] .
99
101
///
100
102
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
101
103
/// memory for the conversion.
@@ -107,17 +109,17 @@ impl DevicePathToText {
107
109
display_only : DisplayOnly ,
108
110
allow_shortcuts : AllowShortcuts ,
109
111
) -> Result < PoolString > {
110
- let text_device_node = unsafe {
112
+ let text = unsafe {
111
113
( self . 0 . convert_device_node_to_text ) (
112
114
device_node. as_ffi_ptr ( ) . cast ( ) ,
113
115
display_only. 0 ,
114
116
allow_shortcuts. 0 ,
115
117
)
116
118
} ;
117
- PoolString :: new ( text_device_node . cast ( ) )
119
+ PoolString :: new ( text . cast ( ) )
118
120
}
119
121
120
- /// Convert a device path to its text representation .
122
+ /// Convert a [`DevicePath`] to a [`PoolString`] .
121
123
///
122
124
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
123
125
/// memory for the conversion.
@@ -129,32 +131,27 @@ impl DevicePathToText {
129
131
display_only : DisplayOnly ,
130
132
allow_shortcuts : AllowShortcuts ,
131
133
) -> Result < PoolString > {
132
- let text_device_path = unsafe {
134
+ let text = unsafe {
133
135
( self . 0 . convert_device_path_to_text ) (
134
136
device_path. as_ffi_ptr ( ) . cast ( ) ,
135
137
display_only. 0 ,
136
138
allow_shortcuts. 0 ,
137
139
)
138
140
} ;
139
- PoolString :: new ( text_device_path . cast ( ) )
141
+ PoolString :: new ( text . cast ( ) )
140
142
}
141
143
}
142
144
143
- /// Device Path from Text protocol.
144
- ///
145
- /// This protocol provides common utilities for converting text to
146
- /// device paths and device nodes.
145
+ /// Protocol for converting a string to a [`DevicePath`] or `DevicePathNode`].
147
146
#[ derive( Debug ) ]
148
147
#[ repr( transparent) ]
149
148
#[ unsafe_protocol( "05c99a21-c70f-4ad2-8a5f-35df3343f51e" ) ]
150
149
pub struct DevicePathFromText ( DevicePathFromTextProtocol ) ;
151
150
152
151
impl DevicePathFromText {
153
- /// Convert text to the binary representation of a device node .
152
+ /// Convert a [`CStr16`] to a [`DevicePathNode`] .
154
153
///
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.
154
+ /// If a non-device-node character is encountered, the rest of the string is ignored.
158
155
///
159
156
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
160
157
/// memory for the conversion.
@@ -172,11 +169,9 @@ impl DevicePathFromText {
172
169
}
173
170
}
174
171
175
- /// Convert a text to its binary device path representation .
172
+ /// Convert a [`CStr16`] to a [`DevicePath`] .
176
173
///
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.
174
+ /// If a non-device-node character is encountered, the rest of the string is ignored.
180
175
///
181
176
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
182
177
/// memory for the conversion.
0 commit comments