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,39 @@ 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.
50
+ ///
51
+ /// [`CString16`]: crate::CString16
45
52
#[ derive( Debug ) ]
46
53
pub struct PoolString ( PoolAllocation ) ;
47
54
@@ -85,17 +92,14 @@ impl Deref for PoolDevicePathNode {
85
92
}
86
93
}
87
94
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.
92
96
#[ derive( Debug ) ]
93
97
#[ repr( transparent) ]
94
98
#[ unsafe_protocol( DevicePathToTextProtocol :: GUID ) ]
95
99
pub struct DevicePathToText ( DevicePathToTextProtocol ) ;
96
100
97
101
impl DevicePathToText {
98
- /// Convert a device node to its text representation .
102
+ /// Convert a [`DevicePathNode`] to a [`PoolString`] .
99
103
///
100
104
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
101
105
/// memory for the conversion.
@@ -107,17 +111,17 @@ impl DevicePathToText {
107
111
display_only : DisplayOnly ,
108
112
allow_shortcuts : AllowShortcuts ,
109
113
) -> Result < PoolString > {
110
- let text_device_node = unsafe {
114
+ let text = unsafe {
111
115
( self . 0 . convert_device_node_to_text ) (
112
116
device_node. as_ffi_ptr ( ) . cast ( ) ,
113
117
display_only. 0 ,
114
118
allow_shortcuts. 0 ,
115
119
)
116
120
} ;
117
- PoolString :: new ( text_device_node . cast ( ) )
121
+ PoolString :: new ( text . cast ( ) )
118
122
}
119
123
120
- /// Convert a device path to its text representation .
124
+ /// Convert a [`DevicePath`] to a [`PoolString`] .
121
125
///
122
126
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
123
127
/// memory for the conversion.
@@ -129,32 +133,27 @@ impl DevicePathToText {
129
133
display_only : DisplayOnly ,
130
134
allow_shortcuts : AllowShortcuts ,
131
135
) -> Result < PoolString > {
132
- let text_device_path = unsafe {
136
+ let text = unsafe {
133
137
( self . 0 . convert_device_path_to_text ) (
134
138
device_path. as_ffi_ptr ( ) . cast ( ) ,
135
139
display_only. 0 ,
136
140
allow_shortcuts. 0 ,
137
141
)
138
142
} ;
139
- PoolString :: new ( text_device_path . cast ( ) )
143
+ PoolString :: new ( text . cast ( ) )
140
144
}
141
145
}
142
146
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`].
147
148
#[ derive( Debug ) ]
148
149
#[ repr( transparent) ]
149
150
#[ unsafe_protocol( "05c99a21-c70f-4ad2-8a5f-35df3343f51e" ) ]
150
151
pub struct DevicePathFromText ( DevicePathFromTextProtocol ) ;
151
152
152
153
impl DevicePathFromText {
153
- /// Convert text to the binary representation of a device node .
154
+ /// Convert a [`CStr16`] to a [`DevicePathNode`] .
154
155
///
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.
158
157
///
159
158
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
160
159
/// memory for the conversion.
@@ -172,11 +171,9 @@ impl DevicePathFromText {
172
171
}
173
172
}
174
173
175
- /// Convert a text to its binary device path representation .
174
+ /// Convert a [`CStr16`] to a [`DevicePath`] .
176
175
///
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.
180
177
///
181
178
/// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
182
179
/// memory for the conversion.
0 commit comments