2 Provides library functions to construct and parse UEFI Device Paths.
4 This library provides defines, macros, and functions to help create and parse
5 EFI_DEVICE_PATH_PROTOCOL structures.
7 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
8 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #ifndef __DEVICE_PATH_LIB_H__
13 #define __DEVICE_PATH_LIB_H__
15 #define END_DEVICE_PATH_LENGTH (sizeof (EFI_DEVICE_PATH_PROTOCOL))
18 Determine whether a given device path is valid.
20 @param DevicePath A pointer to a device path data structure.
21 @param MaxSize The maximum size of the device path data structure.
23 @retval TRUE DevicePath is valid.
24 @retval FALSE DevicePath is NULL.
25 @retval FALSE Maxsize is less than sizeof(EFI_DEVICE_PATH_PROTOCOL).
26 @retval FALSE The length of any node node in the DevicePath is less
27 than sizeof (EFI_DEVICE_PATH_PROTOCOL).
28 @retval FALSE If MaxSize is not zero, the size of the DevicePath
30 @retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node
31 count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.
36 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
41 Returns the Type field of a device path node.
43 Returns the Type field of the device path node specified by Node.
45 If Node is NULL, then ASSERT().
47 @param Node A pointer to a device path node data structure.
49 @return The Type field of the device path node specified by Node.
59 Returns the SubType field of a device path node.
61 Returns the SubType field of the device path node specified by Node.
63 If Node is NULL, then ASSERT().
65 @param Node A pointer to a device path node data structure.
67 @return The SubType field of the device path node specified by Node.
77 Returns the 16-bit Length field of a device path node.
79 Returns the 16-bit Length field of the device path node specified by Node.
80 Node is not required to be aligned on a 16-bit boundary, so it is recommended
81 that a function such as ReadUnaligned16() be used to extract the contents of
84 If Node is NULL, then ASSERT().
86 @param Node A pointer to a device path node data structure.
88 @return The 16-bit Length field of the device path node specified by Node.
93 DevicePathNodeLength (
98 Returns a pointer to the next node in a device path.
100 Returns a pointer to the device path node that follows the device path node specified by Node.
102 If Node is NULL, then ASSERT().
104 @param Node A pointer to a device path node data structure.
106 @return a pointer to the device path node that follows the device path node specified by Node.
109 EFI_DEVICE_PATH_PROTOCOL
*
116 Determines if a device path node is an end node of a device path.
117 This includes nodes that are the end of a device path instance and nodes that
118 are the end of an entire device path.
120 Determines if the device path node specified by Node is an end node of a device path.
121 This includes nodes that are the end of a device path instance and nodes that are the
122 end of an entire device path. If Node represents an end node of a device path,
123 then TRUE is returned. Otherwise, FALSE is returned.
125 If Node is NULL, then ASSERT().
127 @param Node A pointer to a device path node data structure.
129 @retval TRUE The device path node specified by Node is an end node of a device path.
130 @retval FALSE The device path node specified by Node is not an end node of a device path.
135 IsDevicePathEndType (
140 Determines if a device path node is an end node of an entire device path.
142 Determines if a device path node specified by Node is an end node of an entire device path.
143 If Node represents the end of an entire device path, then TRUE is returned.
144 Otherwise, FALSE is returned.
146 If Node is NULL, then ASSERT().
148 @param Node A pointer to a device path node data structure.
150 @retval TRUE The device path node specified by Node is the end of an entire device path.
151 @retval FALSE The device path node specified by Node is not the end of an entire device path.
161 Determines if a device path node is an end node of a device path instance.
163 Determines if a device path node specified by Node is an end node of a device path instance.
164 If Node represents the end of a device path instance, then TRUE is returned.
165 Otherwise, FALSE is returned.
167 If Node is NULL, then ASSERT().
169 @param Node A pointer to a device path node data structure.
171 @retval TRUE The device path node specified by Node is the end of a device path instance.
172 @retval FALSE The device path node specified by Node is not the end of a device path instance.
177 IsDevicePathEndInstance (
182 Sets the length, in bytes, of a device path node.
184 Sets the length of the device path node specified by Node to the value specified
185 by NodeLength. NodeLength is returned. Node is not required to be aligned on
186 a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()
187 be used to set the contents of the Length field.
189 If Node is NULL, then ASSERT().
190 If NodeLength >= 0x10000, then ASSERT().
191 If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().
193 @param Node A pointer to a device path node data structure.
194 @param Length The length, in bytes, of the device path node.
201 SetDevicePathNodeLength (
207 Fills in all the fields of a device path node that is the end of an entire device path.
209 Fills in all the fields of a device path node specified by Node so Node represents
210 the end of an entire device path. The Type field of Node is set to
211 END_DEVICE_PATH_TYPE, the SubType field of Node is set to
212 END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to
213 END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary,
214 so it is recommended that a function such as WriteUnaligned16() be used to set
215 the contents of the Length field.
217 If Node is NULL, then ASSERT().
219 @param Node A pointer to a device path node data structure.
224 SetDevicePathEndNode (
229 Returns the size of a device path in bytes.
231 This function returns the size, in bytes, of the device path data structure
232 specified by DevicePath including the end of device path node.
233 If DevicePath is NULL or invalid, then 0 is returned.
235 @param DevicePath A pointer to a device path data structure.
237 @retval 0 If DevicePath is NULL or invalid.
238 @retval Others The size of a device path in bytes.
244 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
248 Creates a new copy of an existing device path.
250 This function allocates space for a new copy of the device path specified by DevicePath. If
251 DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the
252 contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer
253 is returned. Otherwise, NULL is returned.
254 The memory for the new device path is allocated from EFI boot services memory.
255 It is the responsibility of the caller to free the memory allocated.
257 @param DevicePath A pointer to a device path data structure.
259 @retval NULL DevicePath is NULL or invalid.
260 @retval Others A pointer to the duplicated device path.
263 EFI_DEVICE_PATH_PROTOCOL
*
265 DuplicateDevicePath (
266 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
270 Creates a new device path by appending a second device path to a first device path.
272 This function creates a new device path by appending a copy of SecondDevicePath to a copy of
273 FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from
274 SecondDevicePath is retained. The newly created device path is returned.
275 If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned.
276 If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned.
277 If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is
279 If there is not enough memory for the newly allocated buffer, then NULL is returned.
280 The memory for the new device path is allocated from EFI boot services memory. It is the
281 responsibility of the caller to free the memory allocated.
283 @param FirstDevicePath A pointer to a device path data structure.
284 @param SecondDevicePath A pointer to a device path data structure.
286 @retval NULL If there is not enough memory for the newly allocated buffer.
287 @retval NULL If FirstDevicePath or SecondDevicePath is invalid.
288 @retval Others A pointer to the new device path if success.
289 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
292 EFI_DEVICE_PATH_PROTOCOL
*
295 IN CONST EFI_DEVICE_PATH_PROTOCOL
*FirstDevicePath
, OPTIONAL
296 IN CONST EFI_DEVICE_PATH_PROTOCOL
*SecondDevicePath OPTIONAL
300 Creates a new path by appending the device node to the device path.
302 This function creates a new device path by appending a copy of the device node specified by
303 DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.
304 The end-of-device-path device node is moved after the end of the appended device node.
305 If DevicePathNode is NULL then a copy of DevicePath is returned.
306 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device
308 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node
310 If there is not enough memory to allocate space for the new device path, then NULL is returned.
311 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
312 free the memory allocated.
314 @param DevicePath A pointer to a device path data structure.
315 @param DevicePathNode A pointer to a single device path node.
317 @retval NULL There is not enough memory for the new device path.
318 @retval Others A pointer to the new device path if success.
319 A copy of DevicePathNode followed by an end-of-device-path node
320 if both FirstDevicePath and SecondDevicePath are NULL.
321 A copy of an end-of-device-path node if both FirstDevicePath and SecondDevicePath are NULL.
324 EFI_DEVICE_PATH_PROTOCOL
*
326 AppendDevicePathNode (
327 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, OPTIONAL
328 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode OPTIONAL
332 Creates a new device path by appending the specified device path instance to the specified device
335 This function creates a new device path by appending a copy of the device path instance specified
336 by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.
337 The end-of-device-path device node is moved after the end of the appended device path instance
338 and a new end-of-device-path-instance node is inserted between.
339 If DevicePath is NULL, then a copy if DevicePathInstance is returned.
340 If DevicePathInstance is NULL, then NULL is returned.
341 If DevicePath or DevicePathInstance is invalid, then NULL is returned.
342 If there is not enough memory to allocate space for the new device path, then NULL is returned.
343 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
344 free the memory allocated.
346 @param DevicePath A pointer to a device path data structure.
347 @param DevicePathInstance A pointer to a device path instance.
349 @return A pointer to the new device path.
352 EFI_DEVICE_PATH_PROTOCOL
*
354 AppendDevicePathInstance (
355 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
, OPTIONAL
356 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathInstance OPTIONAL
360 Creates a copy of the current device path instance and returns a pointer to the next device path
363 This function creates a copy of the current device path instance. It also updates DevicePath to
364 point to the next device path instance in the device path (or NULL if no more) and updates Size
365 to hold the size of the device path instance copy.
366 If DevicePath is NULL, then NULL is returned.
367 If DevicePath points to a invalid device path, then NULL is returned.
368 If there is not enough memory to allocate space for the new device path, then NULL is returned.
369 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
370 free the memory allocated.
371 If Size is NULL, then ASSERT().
373 @param DevicePath On input, this holds the pointer to the current device path
374 instance. On output, this holds the pointer to the next device
375 path instance or NULL if there are no more device path
376 instances in the device path pointer to a device path data
378 @param Size On output, this holds the size of the device path instance, in
379 bytes or zero, if DevicePath is NULL.
381 @return A pointer to the current device path instance.
384 EFI_DEVICE_PATH_PROTOCOL
*
386 GetNextDevicePathInstance (
387 IN OUT EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
392 Creates a device node.
394 This function creates a new device node in a newly allocated buffer of size NodeLength and
395 initializes the device path node header with NodeType and NodeSubType. The new device path node
397 If NodeLength is smaller than a device path header, then NULL is returned.
398 If there is not enough memory to allocate space for the new device path, then NULL is returned.
399 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to
400 free the memory allocated.
402 @param NodeType The device node type for the new device node.
403 @param NodeSubType The device node sub-type for the new device node.
404 @param NodeLength The length of the new device node.
406 @return The new device path.
409 EFI_DEVICE_PATH_PROTOCOL
*
413 IN UINT8 NodeSubType
,
418 Determines if a device path is single or multi-instance.
420 This function returns TRUE if the device path specified by DevicePath is multi-instance.
421 Otherwise, FALSE is returned.
422 If DevicePath is NULL or invalid, then FALSE is returned.
424 @param DevicePath A pointer to a device path data structure.
426 @retval TRUE DevicePath is multi-instance.
427 @retval FALSE DevicePath is not multi-instance, or DevicePath is NULL or invalid.
432 IsDevicePathMultiInstance (
433 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
437 Retrieves the device path protocol from a handle.
439 This function returns the device path protocol from the handle specified by Handle. If Handle is
440 NULL or Handle does not contain a device path protocol, then NULL is returned.
442 @param Handle The handle from which to retrieve the device path protocol.
444 @return The device path protocol from the handle specified by Handle.
447 EFI_DEVICE_PATH_PROTOCOL
*
449 DevicePathFromHandle (
454 Allocates a device path for a file and appends it to an existing device path.
456 If Device is a valid device handle that contains a device path protocol, then a device path for
457 the file specified by FileName is allocated and appended to the device path associated with the
458 handle Device. The allocated device path is returned. If Device is NULL or Device is a handle
459 that does not support the device path protocol, then a device path containing a single device
460 path node for the file specified by FileName is allocated and returned.
461 The memory for the new device path is allocated from EFI boot services memory. It is the responsibility
462 of the caller to free the memory allocated.
464 If FileName is NULL, then ASSERT().
465 If FileName is not aligned on a 16-bit boundary, then ASSERT().
467 @param Device A pointer to a device handle. This parameter is optional and
469 @param FileName A pointer to a Null-terminated Unicode string.
471 @return The allocated device path.
474 EFI_DEVICE_PATH_PROTOCOL
*
477 IN EFI_HANDLE Device
, OPTIONAL
478 IN CONST CHAR16
*FileName
482 Converts a device path to its text representation.
484 @param DevicePath A Pointer to the device to be converted.
485 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
486 of the display node is used, where applicable. If DisplayOnly
487 is FALSE, then the longer text representation of the display node
489 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
490 representation for a device node can be used, where applicable.
492 @return A pointer to the allocated text representation of the device path or
493 NULL if DeviceNode is NULL or there was insufficient memory.
498 ConvertDevicePathToText (
499 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
500 IN BOOLEAN DisplayOnly
,
501 IN BOOLEAN AllowShortcuts
505 Converts a device node to its string representation.
507 @param DeviceNode A Pointer to the device node to be converted.
508 @param DisplayOnly If DisplayOnly is TRUE, then the shorter text representation
509 of the display node is used, where applicable. If DisplayOnly
510 is FALSE, then the longer text representation of the display node
512 @param AllowShortcuts If AllowShortcuts is TRUE, then the shortcut forms of text
513 representation for a device node can be used, where applicable.
515 @return A pointer to the allocated text representation of the device node or NULL if DeviceNode
516 is NULL or there was insufficient memory.
521 ConvertDeviceNodeToText (
522 IN CONST EFI_DEVICE_PATH_PROTOCOL
*DeviceNode
,
523 IN BOOLEAN DisplayOnly
,
524 IN BOOLEAN AllowShortcuts
528 Convert text to the binary representation of a device node.
530 @param TextDeviceNode TextDeviceNode points to the text representation of a device
531 node. Conversion starts with the first character and continues
532 until the first non-device node character.
534 @return A pointer to the EFI device node or NULL if TextDeviceNode is NULL or there was
535 insufficient memory or text unsupported.
538 EFI_DEVICE_PATH_PROTOCOL
*
540 ConvertTextToDeviceNode (
541 IN CONST CHAR16
*TextDeviceNode
545 Convert text to the binary representation of a device path.
547 @param TextDevicePath TextDevicePath points to the text representation of a device
548 path. Conversion starts with the first character and continues
549 until the first non-device node character.
551 @return A pointer to the allocated device path or NULL if TextDeviceNode is NULL or
552 there was insufficient memory.
555 EFI_DEVICE_PATH_PROTOCOL
*
557 ConvertTextToDevicePath (
558 IN CONST CHAR16
*TextDevicePath