2 Device Path services. The thing to remember is device paths are built out of
3 nodes. The device path is terminated by an end node that is length
4 sizeof(EFI_DEVICE_PATH_PROTOCOL). That would be why there is sizeof(EFI_DEVICE_PATH_PROTOCOL)
7 The only place where multi-instance device paths are supported is in
8 environment varibles. Multi-instance device paths should never be placed
11 Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
12 This program and the accompanying materials
13 are licensed and made available under the terms and conditions of the BSD License
14 which accompanies this distribution. The full text of the license may be found at
15 http://opensource.org/licenses/bsd-license.php.
17 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
18 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #include "UefiDevicePathLib.h"
23 #include <Protocol/DevicePathUtilities.h>
26 // Template for an end-of-device path node.
28 CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLibEndDevicePath
= {
30 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
32 END_DEVICE_PATH_LENGTH
,
38 Determine whether a given device path is valid.
39 If DevicePath is NULL, then ASSERT().
41 @param DevicePath A pointer to a device path data structure.
42 @param MaxSize The maximum size of the device path data structure.
44 @retval TRUE DevicePath is valid.
45 @retval FALSE The length of any node node in the DevicePath is less
46 than sizeof (EFI_DEVICE_PATH_PROTOCOL).
47 @retval FALSE If MaxSize is not zero, the size of the DevicePath
49 @retval FALSE If PcdMaximumDevicePathNodeCount is not zero, the node
50 count of the DevicePath exceeds PcdMaximumDevicePathNodeCount.
54 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
62 ASSERT (DevicePath
!= NULL
);
69 // Validate the input size big enough to touch the first node.
71 if (MaxSize
< sizeof (EFI_DEVICE_PATH_PROTOCOL
)) {
75 for (Count
= 0, Size
= 0; !IsDevicePathEnd (DevicePath
); DevicePath
= NextDevicePathNode (DevicePath
)) {
76 NodeLength
= DevicePathNodeLength (DevicePath
);
77 if (NodeLength
< sizeof (EFI_DEVICE_PATH_PROTOCOL
)) {
81 if (NodeLength
> MAX_UINT32
- Size
) {
87 // Validate next node before touch it.
89 if (Size
> MaxSize
- END_DEVICE_PATH_LENGTH
) {
94 if (Count
>= MAX_DEVICE_PATH_NODE_COUNT
) {
101 // Only return TRUE when the End Device Path node is valid.
103 return (BOOLEAN
) (DevicePathNodeLength (DevicePath
) == END_DEVICE_PATH_LENGTH
);
108 Returns the Type field of a device path node.
110 Returns the Type field of the device path node specified by Node.
112 If Node is NULL, then ASSERT().
114 @param Node A pointer to a device path node data structure.
116 @return The Type field of the device path node specified by Node.
124 ASSERT (Node
!= NULL
);
125 return ((EFI_DEVICE_PATH_PROTOCOL
*)(Node
))->Type
;
129 Returns the SubType field of a device path node.
131 Returns the SubType field of the device path node specified by Node.
133 If Node is NULL, then ASSERT().
135 @param Node A pointer to a device path node data structure.
137 @return The SubType field of the device path node specified by Node.
145 ASSERT (Node
!= NULL
);
146 return ((EFI_DEVICE_PATH_PROTOCOL
*)(Node
))->SubType
;
150 Returns the 16-bit Length field of a device path node.
152 Returns the 16-bit Length field of the device path node specified by Node.
153 Node is not required to be aligned on a 16-bit boundary, so it is recommended
154 that a function such as ReadUnaligned16() be used to extract the contents of
157 If Node is NULL, then ASSERT().
159 @param Node A pointer to a device path node data structure.
161 @return The 16-bit Length field of the device path node specified by Node.
165 DevicePathNodeLength (
169 ASSERT (Node
!= NULL
);
170 return ReadUnaligned16 ((UINT16
*)&((EFI_DEVICE_PATH_PROTOCOL
*)(Node
))->Length
[0]);
174 Returns a pointer to the next node in a device path.
176 Returns a pointer to the device path node that follows the device path node
179 If Node is NULL, then ASSERT().
181 @param Node A pointer to a device path node data structure.
183 @return a pointer to the device path node that follows the device path node
187 EFI_DEVICE_PATH_PROTOCOL
*
192 ASSERT (Node
!= NULL
);
193 return (EFI_DEVICE_PATH_PROTOCOL
*)((UINT8
*)(Node
) + DevicePathNodeLength(Node
));
197 Determines if a device path node is an end node of a device path.
198 This includes nodes that are the end of a device path instance and nodes that
199 are the end of an entire device path.
201 Determines if the device path node specified by Node is an end node of a device path.
202 This includes nodes that are the end of a device path instance and nodes that are the
203 end of an entire device path. If Node represents an end node of a device path,
204 then TRUE is returned. Otherwise, FALSE is returned.
206 If Node is NULL, then ASSERT().
208 @param Node A pointer to a device path node data structure.
210 @retval TRUE The device path node specified by Node is an end node of a
212 @retval FALSE The device path node specified by Node is not an end node of
217 IsDevicePathEndType (
221 ASSERT (Node
!= NULL
);
222 return (BOOLEAN
) (DevicePathType (Node
) == END_DEVICE_PATH_TYPE
);
226 Determines if a device path node is an end node of an entire device path.
228 Determines if a device path node specified by Node is an end node of an entire
229 device path. If Node represents the end of an entire device path, then TRUE is
230 returned. Otherwise, FALSE is returned.
232 If Node is NULL, then ASSERT().
234 @param Node A pointer to a device path node data structure.
236 @retval TRUE The device path node specified by Node is the end of an entire
238 @retval FALSE The device path node specified by Node is not the end of an
247 ASSERT (Node
!= NULL
);
248 return (BOOLEAN
) (IsDevicePathEndType (Node
) && DevicePathSubType(Node
) == END_ENTIRE_DEVICE_PATH_SUBTYPE
);
252 Determines if a device path node is an end node of a device path instance.
254 Determines if a device path node specified by Node is an end node of a device
255 path instance. If Node represents the end of a device path instance, then TRUE
256 is returned. Otherwise, FALSE is returned.
258 If Node is NULL, then ASSERT().
260 @param Node A pointer to a device path node data structure.
262 @retval TRUE The device path node specified by Node is the end of a device
264 @retval FALSE The device path node specified by Node is not the end of a
265 device path instance.
269 IsDevicePathEndInstance (
273 ASSERT (Node
!= NULL
);
274 return (BOOLEAN
) (IsDevicePathEndType (Node
) && DevicePathSubType(Node
) == END_INSTANCE_DEVICE_PATH_SUBTYPE
);
278 Sets the length, in bytes, of a device path node.
280 Sets the length of the device path node specified by Node to the value specified
281 by NodeLength. NodeLength is returned. Node is not required to be aligned on
282 a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()
283 be used to set the contents of the Length field.
285 If Node is NULL, then ASSERT().
286 If NodeLength >= SIZE_64KB, then ASSERT().
287 If NodeLength < sizeof (EFI_DEVICE_PATH_PROTOCOL), then ASSERT().
289 @param Node A pointer to a device path node data structure.
290 @param Length The length, in bytes, of the device path node.
296 SetDevicePathNodeLength (
301 ASSERT (Node
!= NULL
);
302 ASSERT ((Length
>= sizeof (EFI_DEVICE_PATH_PROTOCOL
)) && (Length
< SIZE_64KB
));
303 return WriteUnaligned16 ((UINT16
*)&((EFI_DEVICE_PATH_PROTOCOL
*)(Node
))->Length
[0], (UINT16
)(Length
));
307 Fills in all the fields of a device path node that is the end of an entire device path.
309 Fills in all the fields of a device path node specified by Node so Node represents
310 the end of an entire device path. The Type field of Node is set to
311 END_DEVICE_PATH_TYPE, the SubType field of Node is set to
312 END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to
313 END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary,
314 so it is recommended that a function such as WriteUnaligned16() be used to set
315 the contents of the Length field.
317 If Node is NULL, then ASSERT().
319 @param Node A pointer to a device path node data structure.
323 SetDevicePathEndNode (
327 ASSERT (Node
!= NULL
);
328 memcpy (Node
, &mUefiDevicePathLibEndDevicePath
, sizeof (mUefiDevicePathLibEndDevicePath
));
332 Returns the size of a device path in bytes.
334 This function returns the size, in bytes, of the device path data structure
335 specified by DevicePath including the end of device path node.
336 If DevicePath is NULL or invalid, then 0 is returned.
338 @param DevicePath A pointer to a device path data structure.
340 @retval 0 If DevicePath is NULL or invalid.
341 @retval Others The size of a device path in bytes.
345 UefiDevicePathLibGetDevicePathSize (
346 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
349 CONST EFI_DEVICE_PATH_PROTOCOL
*Start
;
351 if (DevicePath
== NULL
) {
355 if (!IsDevicePathValid (DevicePath
, 0)) {
360 // Search for the end of the device path structure
363 while (!IsDevicePathEnd (DevicePath
)) {
364 DevicePath
= NextDevicePathNode (DevicePath
);
368 // Compute the size and add back in the size of the end device path structure
370 return ((UINTN
) DevicePath
- (UINTN
) Start
) + DevicePathNodeLength (DevicePath
);
374 Creates a new copy of an existing device path.
376 This function allocates space for a new copy of the device path specified by DevicePath.
377 If DevicePath is NULL, then NULL is returned. If the memory is successfully
378 allocated, then the contents of DevicePath are copied to the newly allocated
379 buffer, and a pointer to that buffer is returned. Otherwise, NULL is returned.
380 The memory for the new device path is allocated from EFI boot services memory.
381 It is the responsibility of the caller to free the memory allocated.
383 @param DevicePath A pointer to a device path data structure.
385 @retval NULL DevicePath is NULL or invalid.
386 @retval Others A pointer to the duplicated device path.
389 EFI_DEVICE_PATH_PROTOCOL
*
390 UefiDevicePathLibDuplicateDevicePath (
391 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
399 Size
= GetDevicePathSize (DevicePath
);
405 // Allocate space for duplicate device path
408 return AllocateCopyPool (Size
, DevicePath
);
412 Creates a new device path by appending a second device path to a first device path.
414 This function creates a new device path by appending a copy of SecondDevicePath
415 to a copy of FirstDevicePath in a newly allocated buffer. Only the end-of-device-path
416 device node from SecondDevicePath is retained. The newly created device path is
417 returned. If FirstDevicePath is NULL, then it is ignored, and a duplicate of
418 SecondDevicePath is returned. If SecondDevicePath is NULL, then it is ignored,
419 and a duplicate of FirstDevicePath is returned. If both FirstDevicePath and
420 SecondDevicePath are NULL, then a copy of an end-of-device-path is returned.
422 If there is not enough memory for the newly allocated buffer, then NULL is returned.
423 The memory for the new device path is allocated from EFI boot services memory.
424 It is the responsibility of the caller to free the memory allocated.
426 @param FirstDevicePath A pointer to a device path data structure.
427 @param SecondDevicePath A pointer to a device path data structure.
429 @retval NULL If there is not enough memory for the newly allocated buffer.
430 @retval NULL If FirstDevicePath or SecondDevicePath is invalid.
431 @retval Others A pointer to the new device path if success.
432 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.
435 EFI_DEVICE_PATH_PROTOCOL
*
436 UefiDevicePathLibAppendDevicePath (
437 CONST EFI_DEVICE_PATH_PROTOCOL
*FirstDevicePath
,
438 CONST EFI_DEVICE_PATH_PROTOCOL
*SecondDevicePath
444 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
445 EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
;
448 // If there's only 1 path, just duplicate it.
450 if (FirstDevicePath
== NULL
) {
451 return DuplicateDevicePath ((SecondDevicePath
!= NULL
) ? SecondDevicePath
: &mUefiDevicePathLibEndDevicePath
);
454 if (SecondDevicePath
== NULL
) {
455 return DuplicateDevicePath (FirstDevicePath
);
458 if (!IsDevicePathValid (FirstDevicePath
, 0) || !IsDevicePathValid (SecondDevicePath
, 0)) {
463 // Allocate space for the combined device path. It only has one end node of
464 // length EFI_DEVICE_PATH_PROTOCOL.
466 Size1
= GetDevicePathSize (FirstDevicePath
);
467 Size2
= GetDevicePathSize (SecondDevicePath
);
468 Size
= Size1
+ Size2
- END_DEVICE_PATH_LENGTH
;
470 NewDevicePath
= AllocatePool (Size
);
472 if (NewDevicePath
!= NULL
) {
473 NewDevicePath
= memcpy (NewDevicePath
, FirstDevicePath
, Size1
);
475 // Over write FirstDevicePath EndNode and do the copy
477 DevicePath2
= (EFI_DEVICE_PATH_PROTOCOL
*) ((CHAR8
*) NewDevicePath
+
478 (Size1
- END_DEVICE_PATH_LENGTH
));
479 memcpy (DevicePath2
, SecondDevicePath
, Size2
);
482 return NewDevicePath
;
486 Creates a new path by appending the device node to the device path.
488 This function creates a new device path by appending a copy of the device node
489 specified by DevicePathNode to a copy of the device path specified by DevicePath
490 in an allocated buffer. The end-of-device-path device node is moved after the
491 end of the appended device node.
492 If DevicePathNode is NULL then a copy of DevicePath is returned.
493 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device
494 path device node is returned.
495 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path
496 device node is returned.
497 If there is not enough memory to allocate space for the new device path, then
499 The memory is allocated from EFI boot services memory. It is the responsibility
500 of the caller to free the memory allocated.
502 @param DevicePath A pointer to a device path data structure.
503 @param DevicePathNode A pointer to a single device path node.
505 @retval NULL If there is not enough memory for the new device path.
506 @retval Others A pointer to the new device path if success.
507 A copy of DevicePathNode followed by an end-of-device-path node
508 if both FirstDevicePath and SecondDevicePath are NULL.
509 A copy of an end-of-device-path node if both FirstDevicePath
510 and SecondDevicePath are NULL.
513 EFI_DEVICE_PATH_PROTOCOL
*
514 UefiDevicePathLibAppendDevicePathNode (
515 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
516 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
519 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
520 EFI_DEVICE_PATH_PROTOCOL
*NextNode
;
521 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
524 if (DevicePathNode
== NULL
) {
525 return DuplicateDevicePath ((DevicePath
!= NULL
) ? DevicePath
: &mUefiDevicePathLibEndDevicePath
);
528 // Build a Node that has a terminator on it
530 NodeLength
= DevicePathNodeLength (DevicePathNode
);
532 TempDevicePath
= AllocatePool (NodeLength
+ END_DEVICE_PATH_LENGTH
);
533 if (TempDevicePath
== NULL
) {
536 TempDevicePath
= memcpy (TempDevicePath
, DevicePathNode
, NodeLength
);
538 // Add and end device path node to convert Node to device path
540 NextNode
= NextDevicePathNode (TempDevicePath
);
541 SetDevicePathEndNode (NextNode
);
543 // Append device paths
545 NewDevicePath
= AppendDevicePath (DevicePath
, TempDevicePath
);
547 free (TempDevicePath
);
549 return NewDevicePath
;
553 Creates a new device path by appending the specified device path instance to the specified device
556 This function creates a new device path by appending a copy of the device path
557 instance specified by DevicePathInstance to a copy of the device path specified
558 by DevicePath in a allocated buffer.
559 The end-of-device-path device node is moved after the end of the appended device
560 path instance and a new end-of-device-path-instance node is inserted between.
561 If DevicePath is NULL, then a copy if DevicePathInstance is returned.
562 If DevicePathInstance is NULL, then NULL is returned.
563 If DevicePath or DevicePathInstance is invalid, then NULL is returned.
564 If there is not enough memory to allocate space for the new device path, then
566 The memory is allocated from EFI boot services memory. It is the responsibility
567 of the caller to free the memory allocated.
569 @param DevicePath A pointer to a device path data structure.
570 @param DevicePathInstance A pointer to a device path instance.
572 @return A pointer to the new device path.
575 EFI_DEVICE_PATH_PROTOCOL
*
576 UefiDevicePathLibAppendDevicePathInstance (
577 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
578 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePathInstance
581 EFI_DEVICE_PATH_PROTOCOL
*NewDevicePath
;
582 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
586 if (DevicePath
== NULL
) {
587 return DuplicateDevicePath (DevicePathInstance
);
590 if (DevicePathInstance
== NULL
) {
594 if (!IsDevicePathValid (DevicePath
, 0) || !IsDevicePathValid (DevicePathInstance
, 0)) {
598 SrcSize
= GetDevicePathSize (DevicePath
);
599 InstanceSize
= GetDevicePathSize (DevicePathInstance
);
601 NewDevicePath
= AllocatePool (SrcSize
+ InstanceSize
);
602 if (NewDevicePath
!= NULL
) {
604 TempDevicePath
= memcpy (NewDevicePath
, DevicePath
, SrcSize
);;
606 while (!IsDevicePathEnd (TempDevicePath
)) {
607 TempDevicePath
= NextDevicePathNode (TempDevicePath
);
610 TempDevicePath
->SubType
= END_INSTANCE_DEVICE_PATH_SUBTYPE
;
611 TempDevicePath
= NextDevicePathNode (TempDevicePath
);
612 memcpy (TempDevicePath
, DevicePathInstance
, InstanceSize
);
615 return NewDevicePath
;
619 Creates a copy of the current device path instance and returns a pointer to the next device path
622 This function creates a copy of the current device path instance. It also updates
623 DevicePath to point to the next device path instance in the device path (or NULL
624 if no more) and updates Size to hold the size of the device path instance copy.
625 If DevicePath is NULL, then NULL is returned.
626 If DevicePath points to a invalid device path, then NULL is returned.
627 If there is not enough memory to allocate space for the new device path, then
629 The memory is allocated from EFI boot services memory. It is the responsibility
630 of the caller to free the memory allocated.
631 If Size is NULL, then ASSERT().
633 @param DevicePath On input, this holds the pointer to the current
634 device path instance. On output, this holds
635 the pointer to the next device path instance
636 or NULL if there are no more device path
637 instances in the device path pointer to a
638 device path data structure.
639 @param Size On output, this holds the size of the device
640 path instance, in bytes or zero, if DevicePath
643 @return A pointer to the current device path instance.
646 EFI_DEVICE_PATH_PROTOCOL
*
647 UefiDevicePathLibGetNextDevicePathInstance (
648 EFI_DEVICE_PATH_PROTOCOL
**DevicePath
,
652 EFI_DEVICE_PATH_PROTOCOL
*DevPath
;
653 EFI_DEVICE_PATH_PROTOCOL
*ReturnValue
;
656 ASSERT (Size
!= NULL
);
658 if (DevicePath
== NULL
|| *DevicePath
== NULL
) {
663 if (!IsDevicePathValid (*DevicePath
, 0)) {
668 // Find the end of the device path instance
670 DevPath
= *DevicePath
;
671 while (!IsDevicePathEndType (DevPath
)) {
672 DevPath
= NextDevicePathNode (DevPath
);
676 // Compute the size of the device path instance
678 *Size
= ((UINTN
) DevPath
- (UINTN
) (*DevicePath
)) + sizeof (EFI_DEVICE_PATH_PROTOCOL
);
681 // Make a copy and return the device path instance
683 Temp
= DevPath
->SubType
;
684 DevPath
->SubType
= END_ENTIRE_DEVICE_PATH_SUBTYPE
;
685 ReturnValue
= DuplicateDevicePath (*DevicePath
);
686 DevPath
->SubType
= Temp
;
689 // If DevPath is the end of an entire device path, then another instance
690 // does not follow, so *DevicePath is set to NULL.
692 if (DevicePathSubType (DevPath
) == END_ENTIRE_DEVICE_PATH_SUBTYPE
) {
695 *DevicePath
= NextDevicePathNode (DevPath
);
702 Creates a device node.
704 This function creates a new device node in a newly allocated buffer of size
705 NodeLength and initializes the device path node header with NodeType and NodeSubType.
706 The new device path node is returned.
707 If NodeLength is smaller than a device path header, then NULL is returned.
708 If there is not enough memory to allocate space for the new device path, then
710 The memory is allocated from EFI boot services memory. It is the responsibility
711 of the caller to free the memory allocated.
713 @param NodeType The device node type for the new device node.
714 @param NodeSubType The device node sub-type for the new device node.
715 @param NodeLength The length of the new device node.
717 @return The new device path.
720 EFI_DEVICE_PATH_PROTOCOL
*
721 UefiDevicePathLibCreateDeviceNode (
727 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
729 if (NodeLength
< sizeof (EFI_DEVICE_PATH_PROTOCOL
)) {
731 // NodeLength is less than the size of the header.
736 DevicePath
= AllocateZeroPool (NodeLength
);
737 if (DevicePath
!= NULL
) {
738 DevicePath
->Type
= NodeType
;
739 DevicePath
->SubType
= NodeSubType
;
740 SetDevicePathNodeLength (DevicePath
, NodeLength
);
747 Determines if a device path is single or multi-instance.
749 This function returns TRUE if the device path specified by DevicePath is
751 Otherwise, FALSE is returned.
752 If DevicePath is NULL or invalid, then FALSE is returned.
754 @param DevicePath A pointer to a device path data structure.
756 @retval TRUE DevicePath is multi-instance.
757 @retval FALSE DevicePath is not multi-instance, or DevicePath
762 UefiDevicePathLibIsDevicePathMultiInstance (
763 CONST EFI_DEVICE_PATH_PROTOCOL
*DevicePath
766 CONST EFI_DEVICE_PATH_PROTOCOL
*Node
;
768 if (DevicePath
== NULL
) {
772 if (!IsDevicePathValid (DevicePath
, 0)) {
777 while (!IsDevicePathEnd (Node
)) {
778 if (IsDevicePathEndInstance (Node
)) {
782 Node
= NextDevicePathNode (Node
);
790 Retrieves the device path protocol from a handle.
792 This function returns the device path protocol from the handle specified by Handle.
793 If Handle is NULL or Handle does not contain a device path protocol, then NULL
796 @param Handle The handle from which to retrieve the device
799 @return The device path protocol from the handle specified by Handle.
803 EFI_DEVICE_PATH_PROTOCOL *
804 DevicePathFromHandle (
808 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
811 Status = gBS->HandleProtocol (
813 &gEfiDevicePathProtocolGuid,
816 if (EFI_ERROR (Status)) {
823 Allocates a device path for a file and appends it to an existing device path.
825 If Device is a valid device handle that contains a device path protocol, then a device path for
826 the file specified by FileName is allocated and appended to the device path associated with the
827 handle Device. The allocated device path is returned. If Device is NULL or Device is a handle
828 that does not support the device path protocol, then a device path containing a single device
829 path node for the file specified by FileName is allocated and returned.
830 The memory for the new device path is allocated from EFI boot services memory. It is the responsibility
831 of the caller to free the memory allocated.
833 If FileName is NULL, then ASSERT().
834 If FileName is not aligned on a 16-bit boundary, then ASSERT().
836 @param Device A pointer to a device handle. This parameter
837 is optional and may be NULL.
838 @param FileName A pointer to a Null-terminated Unicode string.
840 @return The allocated device path.
843 EFI_DEVICE_PATH_PROTOCOL
*
845 EFI_HANDLE Device
, OPTIONAL
846 CONST CHAR16
*FileName
850 FILEPATH_DEVICE_PATH
*FilePath
;
851 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
852 EFI_DEVICE_PATH_PROTOCOL
*FileDevicePath
;
856 Size
= StrSize (FileName
);
857 FileDevicePath
= AllocatePool (Size
+ SIZE_OF_FILEPATH_DEVICE_PATH
+ END_DEVICE_PATH_LENGTH
);
858 if (FileDevicePath
!= NULL
) {
859 FilePath
= (FILEPATH_DEVICE_PATH
*) FileDevicePath
;
860 FilePath
->Header
.Type
= MEDIA_DEVICE_PATH
;
861 FilePath
->Header
.SubType
= MEDIA_FILEPATH_DP
;
862 memcpy (&FilePath
->PathName
, FileName
, Size
);
863 SetDevicePathNodeLength (&FilePath
->Header
, Size
+ SIZE_OF_FILEPATH_DEVICE_PATH
);
864 SetDevicePathEndNode (NextDevicePathNode (&FilePath
->Header
));
866 //if (Device != NULL) {
867 // DevicePath = DevicePathFromHandle (Device);
870 DevicePath
= AppendDevicePath (DevicePath
, FileDevicePath
);
871 free (FileDevicePath
);