]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Device Path services. The thing to remember is device paths are built out of\r | |
3 | nodes. The device path is terminated by an end node that is length\r | |
4 | sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)\r | |
5 | all over this file.\r | |
6 | \r | |
7 | The only place where multi-instance device paths are supported is in\r | |
8 | environment varibles. Multi-instance device paths should never be placed\r | |
9 | on a Handle.\r | |
10 | \r | |
11 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r | |
12 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #include "UefiDevicePathLib.h"\r | |
17 | \r | |
18 | /**\r | |
19 | Returns the size of a device path in bytes.\r | |
20 | \r | |
21 | This function returns the size, in bytes, of the device path data structure\r | |
22 | specified by DevicePath including the end of device path node.\r | |
23 | If DevicePath is NULL or invalid, then 0 is returned.\r | |
24 | \r | |
25 | @param DevicePath A pointer to a device path data structure.\r | |
26 | \r | |
27 | @retval 0 If DevicePath is NULL or invalid.\r | |
28 | @retval Others The size of a device path in bytes.\r | |
29 | \r | |
30 | **/\r | |
31 | UINTN\r | |
32 | EFIAPI\r | |
33 | GetDevicePathSize (\r | |
34 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
35 | )\r | |
36 | {\r | |
37 | return UefiDevicePathLibGetDevicePathSize (DevicePath);\r | |
38 | }\r | |
39 | \r | |
40 | /**\r | |
41 | Creates a new copy of an existing device path.\r | |
42 | \r | |
43 | This function allocates space for a new copy of the device path specified by DevicePath.\r | |
44 | If DevicePath is NULL, then NULL is returned. If the memory is successfully\r | |
45 | allocated, then the contents of DevicePath are copied to the newly allocated\r | |
46 | buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.\r | |
47 | The memory for the new device path is allocated from EFI boot services memory.\r | |
48 | It is the responsibility of the caller to free the memory allocated.\r | |
49 | \r | |
50 | @param DevicePath A pointer to a device path data structure.\r | |
51 | \r | |
52 | @retval NULL DevicePath is NULL or invalid.\r | |
53 | @retval Others A pointer to the duplicated device path.\r | |
54 | \r | |
55 | **/\r | |
56 | EFI_DEVICE_PATH_PROTOCOL *\r | |
57 | EFIAPI\r | |
58 | DuplicateDevicePath (\r | |
59 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
60 | )\r | |
61 | {\r | |
62 | return UefiDevicePathLibDuplicateDevicePath (DevicePath);\r | |
63 | }\r | |
64 | \r | |
65 | /**\r | |
66 | Creates a new device path by appending a second device path to a first device path.\r | |
67 | \r | |
68 | This function creates a new device path by appending a copy of SecondDevicePath\r | |
69 | to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path\r | |
70 | device node from SecondDevicePath is retained. The newly created device path is\r | |
71 | returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of\r | |
72 | SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,\r | |
73 | and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and\r | |
74 | SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.\r | |
75 | \r | |
76 | If there is not enough memory for the newly allocated buffer, then NULL is returned.\r | |
77 | The memory for the new device path is allocated from EFI boot services memory.\r | |
78 | It is the responsibility of the caller to free the memory allocated.\r | |
79 | \r | |
80 | @param FirstDevicePath A pointer to a device path data structure.\r | |
81 | @param SecondDevicePath A pointer to a device path data structure.\r | |
82 | \r | |
83 | @retval NULL If there is not enough memory for the newly allocated buffer.\r | |
84 | @retval NULL If FirstDevicePath or SecondDevicePath is invalid.\r | |
85 | @retval Others A pointer to the new device path if success.\r | |
86 | Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r | |
87 | \r | |
88 | **/\r | |
89 | EFI_DEVICE_PATH_PROTOCOL *\r | |
90 | EFIAPI\r | |
91 | AppendDevicePath (\r | |
92 | IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL,\r | |
93 | IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r | |
94 | )\r | |
95 | {\r | |
96 | return UefiDevicePathLibAppendDevicePath (FirstDevicePath, SecondDevicePath);\r | |
97 | }\r | |
98 | \r | |
99 | /**\r | |
100 | Creates a new path by appending the device node to the device path.\r | |
101 | \r | |
102 | This function creates a new device path by appending a copy of the device node\r | |
103 | specified by DevicePathNode to a copy of the device path specified by DevicePath\r | |
104 | in an allocated buffer. The end-of-device-path device node is moved after the\r | |
105 | end of the appended device node.\r | |
106 | If DevicePathNode is NULL then a copy of DevicePath is returned.\r | |
107 | If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device\r | |
108 | path device node is returned.\r | |
109 | If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path\r | |
110 | device node is returned.\r | |
111 | If there is not enough memory to allocate space for the new device path, then\r | |
112 | NULL is returned.\r | |
113 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
114 | of the caller to free the memory allocated.\r | |
115 | \r | |
116 | @param DevicePath A pointer to a device path data structure.\r | |
117 | @param DevicePathNode A pointer to a single device path node.\r | |
118 | \r | |
119 | @retval NULL If there is not enough memory for the new device path.\r | |
120 | @retval Others A pointer to the new device path if success.\r | |
121 | A copy of DevicePathNode followed by an end-of-device-path node\r | |
122 | if both FirstDevicePath and SecondDevicePath are NULL.\r | |
123 | A copy of an end-of-device-path node if both FirstDevicePath\r | |
124 | and SecondDevicePath are NULL.\r | |
125 | \r | |
126 | **/\r | |
127 | EFI_DEVICE_PATH_PROTOCOL *\r | |
128 | EFIAPI\r | |
129 | AppendDevicePathNode (\r | |
130 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r | |
131 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r | |
132 | )\r | |
133 | {\r | |
134 | return UefiDevicePathLibAppendDevicePathNode (DevicePath, DevicePathNode);\r | |
135 | }\r | |
136 | \r | |
137 | /**\r | |
138 | Creates a new device path by appending the specified device path instance to the specified device\r | |
139 | path.\r | |
140 | \r | |
141 | This function creates a new device path by appending a copy of the device path\r | |
142 | instance specified by DevicePathInstance to a copy of the device path specified\r | |
143 | by DevicePath in a allocated buffer.\r | |
144 | The end-of-device-path device node is moved after the end of the appended device\r | |
145 | path instance and a new end-of-device-path-instance node is inserted between.\r | |
146 | If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r | |
147 | If DevicePathInstance is NULL, then NULL is returned.\r | |
148 | If DevicePath or DevicePathInstance is invalid, then NULL is returned.\r | |
149 | If there is not enough memory to allocate space for the new device path, then\r | |
150 | NULL is returned.\r | |
151 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
152 | of the caller to free the memory allocated.\r | |
153 | \r | |
154 | @param DevicePath A pointer to a device path data structure.\r | |
155 | @param DevicePathInstance A pointer to a device path instance.\r | |
156 | \r | |
157 | @return A pointer to the new device path.\r | |
158 | \r | |
159 | **/\r | |
160 | EFI_DEVICE_PATH_PROTOCOL *\r | |
161 | EFIAPI\r | |
162 | AppendDevicePathInstance (\r | |
163 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,\r | |
164 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r | |
165 | )\r | |
166 | {\r | |
167 | return UefiDevicePathLibAppendDevicePathInstance (DevicePath, DevicePathInstance);\r | |
168 | }\r | |
169 | \r | |
170 | /**\r | |
171 | Creates a copy of the current device path instance and returns a pointer to the next device path\r | |
172 | instance.\r | |
173 | \r | |
174 | This function creates a copy of the current device path instance. It also updates\r | |
175 | DevicePath to point to the next device path instance in the device path (or NULL\r | |
176 | if no more) and updates Size to hold the size of the device path instance copy.\r | |
177 | If DevicePath is NULL, then NULL is returned.\r | |
178 | If DevicePath points to a invalid device path, then NULL is returned.\r | |
179 | If there is not enough memory to allocate space for the new device path, then\r | |
180 | NULL is returned.\r | |
181 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
182 | of the caller to free the memory allocated.\r | |
183 | If Size is NULL, then ASSERT().\r | |
184 | \r | |
185 | @param DevicePath On input, this holds the pointer to the current\r | |
186 | device path instance. On output, this holds\r | |
187 | the pointer to the next device path instance\r | |
188 | or NULL if there are no more device path\r | |
189 | instances in the device path pointer to a\r | |
190 | device path data structure.\r | |
191 | @param Size On output, this holds the size of the device\r | |
192 | path instance, in bytes or zero, if DevicePath\r | |
193 | is NULL.\r | |
194 | \r | |
195 | @return A pointer to the current device path instance.\r | |
196 | \r | |
197 | **/\r | |
198 | EFI_DEVICE_PATH_PROTOCOL *\r | |
199 | EFIAPI\r | |
200 | GetNextDevicePathInstance (\r | |
201 | IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r | |
202 | OUT UINTN *Size\r | |
203 | )\r | |
204 | {\r | |
205 | return UefiDevicePathLibGetNextDevicePathInstance (DevicePath, Size);\r | |
206 | }\r | |
207 | \r | |
208 | /**\r | |
209 | Creates a device node.\r | |
210 | \r | |
211 | This function creates a new device node in a newly allocated buffer of size\r | |
212 | NodeLength and initializes the device path node header with NodeType and NodeSubType.\r | |
213 | The new device path node is returned.\r | |
214 | If NodeLength is smaller than a device path header, then NULL is returned.\r | |
215 | If there is not enough memory to allocate space for the new device path, then\r | |
216 | NULL is returned.\r | |
217 | The memory is allocated from EFI boot services memory. It is the responsibility\r | |
218 | of the caller to free the memory allocated.\r | |
219 | \r | |
220 | @param NodeType The device node type for the new device node.\r | |
221 | @param NodeSubType The device node sub-type for the new device node.\r | |
222 | @param NodeLength The length of the new device node.\r | |
223 | \r | |
224 | @return The new device path.\r | |
225 | \r | |
226 | **/\r | |
227 | EFI_DEVICE_PATH_PROTOCOL *\r | |
228 | EFIAPI\r | |
229 | CreateDeviceNode (\r | |
230 | IN UINT8 NodeType,\r | |
231 | IN UINT8 NodeSubType,\r | |
232 | IN UINT16 NodeLength\r | |
233 | )\r | |
234 | {\r | |
235 | return UefiDevicePathLibCreateDeviceNode (NodeType, NodeSubType, NodeLength);\r | |
236 | }\r | |
237 | \r | |
238 | /**\r | |
239 | Determines if a device path is single or multi-instance.\r | |
240 | \r | |
241 | This function returns TRUE if the device path specified by DevicePath is\r | |
242 | multi-instance.\r | |
243 | Otherwise, FALSE is returned.\r | |
244 | If DevicePath is NULL or invalid, then FALSE is returned.\r | |
245 | \r | |
246 | @param DevicePath A pointer to a device path data structure.\r | |
247 | \r | |
248 | @retval TRUE DevicePath is multi-instance.\r | |
249 | @retval FALSE DevicePath is not multi-instance, or DevicePath\r | |
250 | is NULL or invalid.\r | |
251 | \r | |
252 | **/\r | |
253 | BOOLEAN\r | |
254 | EFIAPI\r | |
255 | IsDevicePathMultiInstance (\r | |
256 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r | |
257 | )\r | |
258 | {\r | |
259 | return UefiDevicePathLibIsDevicePathMultiInstance (DevicePath);\r | |
260 | }\r | |
261 | \r | |
262 | /**\r | |
263 | Converts a device node to its string representation.\r | |
264 | \r | |
265 | @param DeviceNode A Pointer to the device node to be converted.\r | |
266 | @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r | |
267 | of the display node is used, where applicable. If DisplayOnly\r | |
268 | is FALSE, then the longer text representation of the display node\r | |
269 | is used.\r | |
270 | @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r | |
271 | representation for a device node can be used, where applicable.\r | |
272 | \r | |
273 | @return A pointer to the allocated text representation of the device node or NULL if DeviceNode\r | |
274 | is NULL or there was insufficient memory.\r | |
275 | \r | |
276 | **/\r | |
277 | CHAR16 *\r | |
278 | EFIAPI\r | |
279 | ConvertDeviceNodeToText (\r | |
280 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,\r | |
281 | IN BOOLEAN DisplayOnly,\r | |
282 | IN BOOLEAN AllowShortcuts\r | |
283 | )\r | |
284 | {\r | |
285 | return UefiDevicePathLibConvertDeviceNodeToText (DeviceNode, DisplayOnly, AllowShortcuts);\r | |
286 | }\r | |
287 | \r | |
288 | /**\r | |
289 | Converts a device path to its text representation.\r | |
290 | \r | |
291 | @param DevicePath A Pointer to the device to be converted.\r | |
292 | @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation\r | |
293 | of the display node is used, where applicable. If DisplayOnly\r | |
294 | is FALSE, then the longer text representation of the display node\r | |
295 | is used.\r | |
296 | @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text\r | |
297 | representation for a device node can be used, where applicable.\r | |
298 | \r | |
299 | @return A pointer to the allocated text representation of the device path or\r | |
300 | NULL if DeviceNode is NULL or there was insufficient memory.\r | |
301 | \r | |
302 | **/\r | |
303 | CHAR16 *\r | |
304 | EFIAPI\r | |
305 | ConvertDevicePathToText (\r | |
306 | IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r | |
307 | IN BOOLEAN DisplayOnly,\r | |
308 | IN BOOLEAN AllowShortcuts\r | |
309 | )\r | |
310 | {\r | |
311 | return UefiDevicePathLibConvertDevicePathToText (DevicePath, DisplayOnly, AllowShortcuts);\r | |
312 | }\r | |
313 | \r | |
314 | /**\r | |
315 | Convert text to the binary representation of a device node.\r | |
316 | \r | |
317 | @param TextDeviceNode TextDeviceNode points to the text representation of a device\r | |
318 | node. Conversion starts with the first character and continues\r | |
319 | until the first non-device node character.\r | |
320 | \r | |
321 | @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was\r | |
322 | insufficient memory or text unsupported.\r | |
323 | \r | |
324 | **/\r | |
325 | EFI_DEVICE_PATH_PROTOCOL *\r | |
326 | EFIAPI\r | |
327 | ConvertTextToDeviceNode (\r | |
328 | IN CONST CHAR16 *TextDeviceNode\r | |
329 | )\r | |
330 | {\r | |
331 | return UefiDevicePathLibConvertTextToDeviceNode (TextDeviceNode);\r | |
332 | }\r | |
333 | \r | |
334 | /**\r | |
335 | Convert text to the binary representation of a device path.\r | |
336 | \r | |
337 | \r | |
338 | @param TextDevicePath TextDevicePath points to the text representation of a device\r | |
339 | path. Conversion starts with the first character and continues\r | |
340 | until the first non-device node character.\r | |
341 | \r | |
342 | @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or\r | |
343 | there was insufficient memory.\r | |
344 | \r | |
345 | **/\r | |
346 | EFI_DEVICE_PATH_PROTOCOL *\r | |
347 | EFIAPI\r | |
348 | ConvertTextToDevicePath (\r | |
349 | IN CONST CHAR16 *TextDevicePath\r | |
350 | )\r | |
351 | {\r | |
352 | return UefiDevicePathLibConvertTextToDevicePath (TextDevicePath);\r | |
353 | }\r |