]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/UefiDevicePathLibDevicePathProtocol/UefiDevicePathLib.c
Correct EFI_IFR_RESET_BUTTON from question to statement.
[mirror_edk2.git] / MdePkg / Library / UefiDevicePathLibDevicePathProtocol / UefiDevicePathLib.c
CommitLineData
e386b444 1/** @file\r
f008fc32 2 Library instance that implement UEFI Device Path Library class based on protocol\r
3 gEfiDevicePathUtilitiesProtocolGuid.\r
e386b444 4\r
373ade0e 5 Copyright (c) 2006 - 2008, Intel Corporation<BR>\r
e386b444 6 All rights reserved. This program and the accompanying materials\r
7 are licensed and made available under the terms and conditions of the BSD License\r
8 which accompanies this distribution. The full text of the license may be found at\r
9 http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
e386b444 14**/\r
15\r
c892d846 16\r
c7d265a9 17#include <Uefi.h>\r
c892d846 18\r
c7d265a9 19#include <Protocol/DevicePathUtilities.h>\r
c892d846 20\r
c7d265a9 21#include <Library/DevicePathLib.h>\r
22#include <Library/DebugLib.h>\r
23#include <Library/BaseLib.h>\r
24#include <Library/MemoryAllocationLib.h>\r
25#include <Library/BaseMemoryLib.h>\r
26#include <Library/UefiBootServicesTableLib.h>\r
e386b444 27\r
fe467413 28EFI_DEVICE_PATH_UTILITIES_PROTOCOL *mDevicePathUtilities = NULL;\r
e386b444 29\r
3dc728fb 30//\r
31// Template for an end-of-device path node.\r
32//\r
33GLOBAL_REMOVE_IF_UNREFERENCED CONST EFI_DEVICE_PATH_PROTOCOL mUefiDevicePathLibEndDevicePath = {\r
34 END_DEVICE_PATH_TYPE,\r
35 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
36 {\r
37 END_DEVICE_PATH_LENGTH,\r
38 0\r
39 }\r
40};\r
41\r
e386b444 42/**\r
43 The constructor function caches the pointer to DevicePathUtilites protocol.\r
44 \r
45 The constructor function locates DevicePathUtilities protocol from protocol database.\r
46 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS. \r
47\r
48 @param ImageHandle The firmware allocated handle for the EFI image.\r
49 @param SystemTable A pointer to the EFI System Table.\r
50 \r
51 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.\r
52\r
53**/\r
54EFI_STATUS\r
55EFIAPI\r
56DevicePathLibConstructor (\r
57 IN EFI_HANDLE ImageHandle,\r
58 IN EFI_SYSTEM_TABLE *SystemTable\r
59 )\r
60{\r
61 EFI_STATUS Status;\r
62\r
63 Status = gBS->LocateProtocol (\r
64 &gEfiDevicePathUtilitiesProtocolGuid,\r
65 NULL,\r
66 (VOID**) &mDevicePathUtilities\r
67 );\r
68 ASSERT_EFI_ERROR (Status);\r
69 ASSERT (mDevicePathUtilities != NULL);\r
70\r
71 return Status;\r
72}\r
73\r
3dc728fb 74/**\r
75 Returns the Type field of a device path node.\r
76\r
77 Returns the Type field of the device path node specified by Node.\r
78\r
79 If Node is NULL, then ASSERT().\r
80\r
81 @param Node A pointer to a device path node data structure.\r
82\r
83 @return The Type field of the device path node specified by Node.\r
84\r
85**/\r
86UINT8\r
87DevicePathType (\r
88 IN CONST VOID *Node\r
89 )\r
90{\r
91 ASSERT (Node != NULL);\r
92 return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Type;\r
93}\r
94\r
95/**\r
96 Returns the SubType field of a device path node.\r
97\r
98 Returns the SubType field of the device path node specified by Node.\r
99\r
100 If Node is NULL, then ASSERT().\r
101\r
102 @param Node A pointer to a device path node data structure.\r
103\r
104 @return The SubType field of the device path node specified by Node.\r
105\r
106**/\r
107UINT8\r
108DevicePathSubType (\r
109 IN CONST VOID *Node\r
110 )\r
111{\r
112 ASSERT (Node != NULL);\r
113 return ((EFI_DEVICE_PATH_PROTOCOL *)(Node))->SubType;\r
114}\r
115\r
116/**\r
117 Returns the 16-bit Length field of a device path node.\r
118\r
119 Returns the 16-bit Length field of the device path node specified by Node. \r
120 Node is not required to be aligned on a 16-bit boundary, so it is recommended\r
121 that a function such as ReadUnaligned16() be used to extract the contents of \r
122 the Length field.\r
123\r
124 If Node is NULL, then ASSERT().\r
125\r
126 @param Node A pointer to a device path node data structure.\r
127\r
128 @return The 16-bit Length field of the device path node specified by Node.\r
129\r
130**/\r
131UINTN\r
132DevicePathNodeLength (\r
133 IN CONST VOID *Node\r
134 )\r
135{\r
136 ASSERT (Node != NULL);\r
137 return ReadUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0]);\r
138}\r
139\r
140/**\r
141 Returns a pointer to the next node in a device path.\r
142\r
143 Returns a pointer to the device path node that follows the device path node specified by Node.\r
144\r
145 If Node is NULL, then ASSERT().\r
146\r
147 @param Node A pointer to a device path node data structure.\r
148\r
149 @return a pointer to the device path node that follows the device path node specified by Node.\r
150\r
151**/\r
152EFI_DEVICE_PATH_PROTOCOL *\r
153NextDevicePathNode (\r
154 IN CONST VOID *Node\r
155 )\r
156{\r
157 ASSERT (Node != NULL);\r
158 return (EFI_DEVICE_PATH_PROTOCOL *)((UINT8 *)(Node) + DevicePathNodeLength(Node));\r
159}\r
160\r
161/**\r
162 Determines if a device path node is an end node of a device path.\r
163 This includes nodes that are the end of a device path instance and nodes that are the end of an entire device path.\r
164\r
165 Determines if the device path node specified by Node is an end node of a device path. \r
166 This includes nodes that are the end of a device path instance and nodes that are the \r
167 end of an entire device path. If Node represents an end node of a device path, \r
168 then TRUE is returned. Otherwise, FALSE is returned.\r
169\r
170 If Node is NULL, then ASSERT().\r
171\r
172 @param Node A pointer to a device path node data structure.\r
173\r
174 @retval TRUE The device path node specified by Node is an end node of a device path.\r
175 @retval FALSE The device path node specified by Node is not an end node of a device path.\r
176 \r
177**/\r
178BOOLEAN\r
179IsDevicePathEndType (\r
180 IN CONST VOID *Node\r
181 )\r
182{\r
183 ASSERT (Node != NULL);\r
a357faa3 184 return (BOOLEAN) (DevicePathType (Node) == END_DEVICE_PATH_TYPE);\r
3dc728fb 185}\r
186\r
187/**\r
188 Determines if a device path node is an end node of an entire device path.\r
189\r
190 Determines if a device path node specified by Node is an end node of an entire device path.\r
191 If Node represents the end of an entire device path, then TRUE is returned. Otherwise, FALSE is returned.\r
192\r
193 If Node is NULL, then ASSERT().\r
194\r
195 @param Node A pointer to a device path node data structure.\r
196\r
197 @retval TRUE The device path node specified by Node is the end of an entire device path.\r
198 @retval FALSE The device path node specified by Node is not the end of an entire device path.\r
199\r
200**/\r
201BOOLEAN\r
202IsDevicePathEnd (\r
203 IN CONST VOID *Node\r
204 )\r
205{\r
206 ASSERT (Node != NULL);\r
1bfc7438 207 return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_ENTIRE_DEVICE_PATH_SUBTYPE);\r
3dc728fb 208}\r
209\r
210/**\r
211 Determines if a device path node is an end node of a device path instance.\r
212\r
213 Determines if a device path node specified by Node is an end node of a device path instance.\r
214 If Node represents the end of a device path instance, then TRUE is returned. Otherwise, FALSE is returned.\r
215\r
216 If Node is NULL, then ASSERT().\r
217\r
218 @param Node A pointer to a device path node data structure.\r
219\r
220 @retval TRUE The device path node specified by Node is the end of a device path instance.\r
221 @retval FALSE The device path node specified by Node is not the end of a device path instance.\r
222\r
223**/\r
224BOOLEAN\r
225IsDevicePathEndInstance (\r
226 IN CONST VOID *Node\r
227 )\r
228{\r
229 ASSERT (Node != NULL);\r
1bfc7438 230 return (BOOLEAN) (IsDevicePathEndType (Node) && DevicePathSubType(Node) == END_INSTANCE_DEVICE_PATH_SUBTYPE);\r
3dc728fb 231}\r
232\r
233/**\r
234 Sets the length, in bytes, of a device path node.\r
235\r
236 Sets the length of the device path node specified by Node to the value specified \r
237 by NodeLength. NodeLength is returned. Node is not required to be aligned on \r
238 a 16-bit boundary, so it is recommended that a function such as WriteUnaligned16()\r
239 be used to set the contents of the Length field.\r
240\r
241 If Node is NULL, then ASSERT().\r
242 If NodeLength >= 0x10000, then ASSERT().\r
243\r
244 @param Node A pointer to a device path node data structure.\r
245 @param Length The length, in bytes, of the device path node.\r
246\r
247 @return Length\r
248\r
249**/\r
250UINT16\r
251SetDevicePathNodeLength (\r
9bb407c6 252 IN OUT VOID *Node,\r
8f0dd97e 253 IN UINTN Length\r
3dc728fb 254 )\r
255{\r
256 ASSERT (Node != NULL);\r
8f0dd97e 257 ASSERT (Length < 0x10000);\r
258 return WriteUnaligned16 ((UINT16 *)&((EFI_DEVICE_PATH_PROTOCOL *)(Node))->Length[0], (UINT16)(Length));\r
3dc728fb 259}\r
260\r
261/**\r
262 Fills in all the fields of a device path node that is the end of an entire device path.\r
263\r
264 Fills in all the fields of a device path node specified by Node so Node represents \r
265 the end of an entire device path. The Type field of Node is set to \r
266 END_DEVICE_PATH_TYPE, the SubType field of Node is set to \r
267 END_ENTIRE_DEVICE_PATH_SUBTYPE, and the Length field of Node is set to \r
268 END_DEVICE_PATH_LENGTH. Node is not required to be aligned on a 16-bit boundary, \r
269 so it is recommended that a function such as WriteUnaligned16() be used to set \r
270 the contents of the Length field. \r
271\r
272 If Node is NULL, then ASSERT(). \r
273\r
274 @param Node A pointer to a device path node data structure.\r
275\r
276**/\r
277VOID\r
278SetDevicePathEndNode (\r
9bb407c6 279 OUT VOID *Node\r
3dc728fb 280 )\r
281{\r
282 ASSERT (Node != NULL);\r
283 CopyMem (Node, &mUefiDevicePathLibEndDevicePath, sizeof (mUefiDevicePathLibEndDevicePath));\r
284}\r
285\r
e386b444 286/**\r
287 Returns the size of a device path in bytes.\r
288\r
289 This function returns the size, in bytes, of the device path data structure specified by\r
290 DevicePath including the end of device path node. If DevicePath is NULL, then 0 is returned.\r
291\r
292 @param DevicePath A pointer to a device path data structure.\r
3e5c3238 293 \r
294 @retval 0 If DevicePath is NULL.\r
295 @retval Others The size of a device path in bytes.\r
e386b444 296\r
297**/\r
298UINTN\r
299EFIAPI\r
300GetDevicePathSize (\r
301 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
302 )\r
303{\r
304 return mDevicePathUtilities->GetDevicePathSize (DevicePath);\r
305}\r
306\r
307/**\r
6a3f4ef9 308 Creates a new copy of an existing device path.\r
e386b444 309\r
310 This function allocates space for a new copy of the device path specified by DevicePath. If\r
311 DevicePath is NULL, then NULL is returned. If the memory is successfully allocated, then the\r
312 contents of DevicePath are copied to the newly allocated buffer, and a pointer to that buffer\r
313 is returned. Otherwise, NULL is returned. \r
3e5c3238 314 The memory for the new device path is allocated from EFI boot services memory. \r
315 It is the responsibility of the caller to free the memory allocated. \r
e386b444 316 \r
317 @param DevicePath A pointer to a device path data structure.\r
318\r
3e5c3238 319 @retval NULL If DevicePath is NULL.\r
320 @retval Others A pointer to the duplicated device path.\r
321 \r
e386b444 322**/\r
323EFI_DEVICE_PATH_PROTOCOL *\r
324EFIAPI\r
325DuplicateDevicePath (\r
326 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
327 )\r
328{\r
329 return mDevicePathUtilities->DuplicateDevicePath (DevicePath);\r
330}\r
331\r
332/**\r
333 Creates a new device path by appending a second device path to a first device path.\r
334\r
335 This function creates a new device path by appending a copy of SecondDevicePath to a copy of\r
336 FirstDevicePath in a newly allocated buffer. Only the end-of-device-path device node from\r
337 SecondDevicePath is retained. The newly created device path is returned. \r
338 If FirstDevicePath is NULL, then it is ignored, and a duplicate of SecondDevicePath is returned. \r
339 If SecondDevicePath is NULL, then it is ignored, and a duplicate of FirstDevicePath is returned. \r
98a14db6 340 If both FirstDevicePath and SecondDevicePath are NULL, then a copy of an end-of-device-path is\r
341 returned. \r
e386b444 342 If there is not enough memory for the newly allocated buffer, then NULL is returned.\r
343 The memory for the new device path is allocated from EFI boot services memory. It is the\r
344 responsibility of the caller to free the memory allocated.\r
345\r
346 @param FirstDevicePath A pointer to a device path data structure.\r
347 @param SecondDevicePath A pointer to a device path data structure.\r
3e5c3238 348 \r
349 @retval NULL If there is not enough memory for the newly allocated buffer.\r
350 @retval Others A pointer to the new device path if success.\r
351 Or a copy an end-of-device-path if both FirstDevicePath and SecondDevicePath are NULL.\r
e386b444 352\r
353**/\r
354EFI_DEVICE_PATH_PROTOCOL *\r
355EFIAPI\r
356AppendDevicePath (\r
357 IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath, OPTIONAL\r
358 IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL\r
359 )\r
360{\r
361 return mDevicePathUtilities->AppendDevicePath (FirstDevicePath, SecondDevicePath);\r
362}\r
363\r
364/**\r
365 Creates a new path by appending the device node to the device path.\r
366\r
367 This function creates a new device path by appending a copy of the device node specified by\r
368 DevicePathNode to a copy of the device path specified by DevicePath in an allocated buffer.\r
369 The end-of-device-path device node is moved after the end of the appended device node.\r
98a14db6 370 If DevicePathNode is NULL then a copy of DevicePath is returned.\r
6336a895 371 If DevicePath is NULL then a copy of DevicePathNode, followed by an end-of-device path device\r
372 node is returned.\r
98a14db6 373 If both DevicePathNode and DevicePath are NULL then a copy of an end-of-device-path device node\r
374 is returned.\r
e386b444 375 If there is not enough memory to allocate space for the new device path, then NULL is returned. \r
376 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
377 free the memory allocated.\r
378\r
379 @param DevicePath A pointer to a device path data structure.\r
380 @param DevicePathNode A pointer to a single device path node.\r
381\r
3e5c3238 382 @retval NULL If there is not enough memory for the new device path.\r
383 @retval Others A pointer to the new device path if success.\r
384 A copy of DevicePathNode followed by an end-of-device-path node \r
385 if both FirstDevicePath and SecondDevicePath are NULL.\r
386 A copy of an end-of-device-path node if both FirstDevicePath and SecondDevicePath are NULL.\r
e386b444 387\r
388**/\r
389EFI_DEVICE_PATH_PROTOCOL *\r
390EFIAPI\r
391AppendDevicePathNode (\r
392 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r
393 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL\r
394 )\r
395{\r
396 return mDevicePathUtilities->AppendDeviceNode (DevicePath, DevicePathNode);\r
397}\r
398\r
399/**\r
400 Creates a new device path by appending the specified device path instance to the specified device\r
401 path.\r
402 \r
403 This function creates a new device path by appending a copy of the device path instance specified\r
404 by DevicePathInstance to a copy of the device path secified by DevicePath in a allocated buffer.\r
405 The end-of-device-path device node is moved after the end of the appended device path instance\r
406 and a new end-of-device-path-instance node is inserted between. \r
407 If DevicePath is NULL, then a copy if DevicePathInstance is returned.\r
408 If DevicePathInstance is NULL, then NULL is returned.\r
409 If there is not enough memory to allocate space for the new device path, then NULL is returned. \r
410 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
411 free the memory allocated.\r
412 \r
413 @param DevicePath A pointer to a device path data structure.\r
414 @param DevicePathInstance A pointer to a device path instance.\r
415\r
416 @return A pointer to the new device path.\r
417\r
418**/\r
419EFI_DEVICE_PATH_PROTOCOL *\r
420EFIAPI\r
421AppendDevicePathInstance (\r
422 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, OPTIONAL\r
423 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL\r
424 )\r
425{\r
426 return mDevicePathUtilities->AppendDevicePathInstance (DevicePath, DevicePathInstance);\r
427}\r
428\r
429/**\r
430 Creates a copy of the current device path instance and returns a pointer to the next device path\r
431 instance.\r
432\r
433 This function creates a copy of the current device path instance. It also updates DevicePath to\r
434 point to the next device path instance in the device path (or NULL if no more) and updates Size\r
435 to hold the size of the device path instance copy.\r
436 If DevicePath is NULL, then NULL is returned.\r
437 If there is not enough memory to allocate space for the new device path, then NULL is returned. \r
438 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
439 free the memory allocated.\r
440 If Size is NULL, then ASSERT().\r
441 \r
442 @param DevicePath On input, this holds the pointer to the current device path\r
443 instance. On output, this holds the pointer to the next device\r
444 path instance or NULL if there are no more device path\r
445 instances in the device path pointer to a device path data\r
446 structure.\r
447 @param Size On output, this holds the size of the device path instance, in\r
448 bytes or zero, if DevicePath is NULL.\r
449\r
450 @return A pointer to the current device path instance.\r
451\r
452**/\r
453EFI_DEVICE_PATH_PROTOCOL *\r
454EFIAPI\r
455GetNextDevicePathInstance (\r
456 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,\r
457 OUT UINTN *Size\r
458 )\r
459{\r
460 ASSERT (Size != NULL);\r
461 return mDevicePathUtilities->GetNextDevicePathInstance (DevicePath, Size);\r
462}\r
463\r
464/**\r
3e5c3238 465 Creates a device node.\r
e386b444 466\r
467 This function creates a new device node in a newly allocated buffer of size NodeLength and\r
468 initializes the device path node header with NodeType and NodeSubType. The new device path node\r
469 is returned.\r
470 If NodeLength is smaller than a device path header, then NULL is returned. \r
471 If there is not enough memory to allocate space for the new device path, then NULL is returned. \r
472 The memory is allocated from EFI boot services memory. It is the responsibility of the caller to\r
473 free the memory allocated.\r
474\r
475 @param NodeType The device node type for the new device node.\r
476 @param NodeSubType The device node sub-type for the new device node.\r
477 @param NodeLength The length of the new device node.\r
478\r
3e5c3238 479 @return The new device path.\r
e386b444 480\r
481**/\r
482EFI_DEVICE_PATH_PROTOCOL *\r
483EFIAPI\r
484CreateDeviceNode (\r
485 IN UINT8 NodeType,\r
486 IN UINT8 NodeSubType,\r
487 IN UINT16 NodeLength\r
488 )\r
489{\r
490 return mDevicePathUtilities->CreateDeviceNode (NodeType, NodeSubType, NodeLength);\r
491}\r
492\r
493/**\r
494 Determines if a device path is single or multi-instance.\r
495\r
496 This function returns TRUE if the device path specified by DevicePath is multi-instance.\r
497 Otherwise, FALSE is returned. If DevicePath is NULL, then FALSE is returned.\r
498\r
499 @param DevicePath A pointer to a device path data structure.\r
500\r
501 @retval TRUE DevicePath is multi-instance.\r
502 @retval FALSE DevicePath is not multi-instance or DevicePath is NULL.\r
503\r
504**/\r
505BOOLEAN\r
506EFIAPI\r
507IsDevicePathMultiInstance (\r
508 IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath\r
509 )\r
510{\r
511 return mDevicePathUtilities->IsDevicePathMultiInstance (DevicePath);\r
512}\r
513\r
514/**\r
515 Retrieves the device path protocol from a handle.\r
516\r
517 This function returns the device path protocol from the handle specified by Handle. If Handle is\r
518 NULL or Handle does not contain a device path protocol, then NULL is returned.\r
519 \r
520 @param Handle The handle from which to retrieve the device path protocol.\r
521\r
522 @return The device path protocol from the handle specified by Handle.\r
523\r
524**/\r
525EFI_DEVICE_PATH_PROTOCOL *\r
526EFIAPI\r
527DevicePathFromHandle (\r
528 IN EFI_HANDLE Handle\r
529 )\r
530{\r
531 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
532 EFI_STATUS Status;\r
533\r
534 Status = gBS->HandleProtocol (\r
535 Handle,\r
536 &gEfiDevicePathProtocolGuid,\r
537 (VOID *) &DevicePath\r
538 );\r
539 if (EFI_ERROR (Status)) {\r
540 DevicePath = NULL;\r
541 }\r
542 return DevicePath;\r
543}\r
544\r
545/**\r
546 Allocates a device path for a file and appends it to an existing device path.\r
547\r
548 If Device is a valid device handle that contains a device path protocol, then a device path for\r
549 the file specified by FileName is allocated and appended to the device path associated with the\r
550 handle Device. The allocated device path is returned. If Device is NULL or Device is a handle\r
551 that does not support the device path protocol, then a device path containing a single device\r
552 path node for the file specified by FileName is allocated and returned.\r
3e5c3238 553 The memory for the new device path is allocated from EFI boot services memory. It is the responsibility\r
554 of the caller to free the memory allocated.\r
555 \r
e386b444 556 If FileName is NULL, then ASSERT().\r
3e5c3238 557 If FileName is not aligned on a 16-bit boundary, then ASSERT().\r
e386b444 558\r
559 @param Device A pointer to a device handle. This parameter is optional and\r
560 may be NULL.\r
561 @param FileName A pointer to a Null-terminated Unicode string.\r
562\r
3e5c3238 563 @return The allocated device path.\r
e386b444 564\r
565**/\r
566EFI_DEVICE_PATH_PROTOCOL *\r
567EFIAPI\r
568FileDevicePath (\r
569 IN EFI_HANDLE Device, OPTIONAL\r
570 IN CONST CHAR16 *FileName\r
571 )\r
572{\r
573 UINTN Size;\r
574 FILEPATH_DEVICE_PATH *FilePath;\r
575 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
576 EFI_DEVICE_PATH_PROTOCOL *FileDevicePath;\r
577\r
578 DevicePath = NULL;\r
579\r
580 Size = StrSize (FileName);\r
e5dab016 581 FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);\r
e386b444 582 if (FileDevicePath != NULL) {\r
583 FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;\r
584 FilePath->Header.Type = MEDIA_DEVICE_PATH;\r
585 FilePath->Header.SubType = MEDIA_FILEPATH_DP;\r
586 CopyMem (&FilePath->PathName, FileName, Size);\r
587 SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);\r
588 SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));\r
589\r
590 if (Device != NULL) {\r
591 DevicePath = DevicePathFromHandle (Device);\r
592 }\r
593\r
594 DevicePath = AppendDevicePath (DevicePath, FileDevicePath);\r
595 FreePool (FileDevicePath);\r
596 }\r
597\r
598 return DevicePath;\r
599}\r