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,37 @@ use core::ops::Deref;
1616use core:: ptr:: NonNull ;
1717use 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 ) ]
2930pub 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 ) ]
4144pub 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.
4550#[ derive( Debug ) ]
4651pub struct PoolString ( PoolAllocation ) ;
4752
@@ -85,17 +90,14 @@ impl Deref for PoolDevicePathNode {
8590 }
8691}
8792
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.
9294#[ derive( Debug ) ]
9395#[ repr( transparent) ]
9496#[ unsafe_protocol( DevicePathToTextProtocol :: GUID ) ]
9597pub struct DevicePathToText ( DevicePathToTextProtocol ) ;
9698
9799impl DevicePathToText {
98- /// Convert a device node to its text representation .
100+ /// Convert a [`DevicePathNode`] to a [`PoolString`] .
99101 ///
100102 /// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
101103 /// memory for the conversion.
@@ -107,17 +109,17 @@ impl DevicePathToText {
107109 display_only : DisplayOnly ,
108110 allow_shortcuts : AllowShortcuts ,
109111 ) -> Result < PoolString > {
110- let text_device_node = unsafe {
112+ let text = unsafe {
111113 ( self . 0 . convert_device_node_to_text ) (
112114 device_node. as_ffi_ptr ( ) . cast ( ) ,
113115 display_only. 0 ,
114116 allow_shortcuts. 0 ,
115117 )
116118 } ;
117- PoolString :: new ( text_device_node . cast ( ) )
119+ PoolString :: new ( text . cast ( ) )
118120 }
119121
120- /// Convert a device path to its text representation .
122+ /// Convert a [`DevicePath`] to a [`PoolString`] .
121123 ///
122124 /// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
123125 /// memory for the conversion.
@@ -129,32 +131,27 @@ impl DevicePathToText {
129131 display_only : DisplayOnly ,
130132 allow_shortcuts : AllowShortcuts ,
131133 ) -> Result < PoolString > {
132- let text_device_path = unsafe {
134+ let text = unsafe {
133135 ( self . 0 . convert_device_path_to_text ) (
134136 device_path. as_ffi_ptr ( ) . cast ( ) ,
135137 display_only. 0 ,
136138 allow_shortcuts. 0 ,
137139 )
138140 } ;
139- PoolString :: new ( text_device_path . cast ( ) )
141+ PoolString :: new ( text . cast ( ) )
140142 }
141143}
142144
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`].
147146#[ derive( Debug ) ]
148147#[ repr( transparent) ]
149148#[ unsafe_protocol( "05c99a21-c70f-4ad2-8a5f-35df3343f51e" ) ]
150149pub struct DevicePathFromText ( DevicePathFromTextProtocol ) ;
151150
152151impl DevicePathFromText {
153- /// Convert text to the binary representation of a device node .
152+ /// Convert a [`CStr16`] to a [`DevicePathNode`] .
154153 ///
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.
158155 ///
159156 /// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
160157 /// memory for the conversion.
@@ -172,11 +169,9 @@ impl DevicePathFromText {
172169 }
173170 }
174171
175- /// Convert a text to its binary device path representation .
172+ /// Convert a [`CStr16`] to a [`DevicePath`] .
176173 ///
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.
180175 ///
181176 /// Returns an [`OUT_OF_RESOURCES`] error if there is insufficient
182177 /// memory for the conversion.
0 commit comments