]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c
MdePkg/UefiFileHandleLib: Tolerate more Root handle FileNames
[mirror_edk2.git] / MdePkg / Library / UefiFileHandleLib / UefiFileHandleLib.c
... / ...
CommitLineData
1/** @file\r
2 Provides interface to EFI_FILE_HANDLE functionality.\r
3\r
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved. <BR>\r
5 SPDX-License-Identifier: BSD-2-Clause-Patent\r
6\r
7**/\r
8\r
9#include <Uefi.h>\r
10\r
11#include <Protocol/SimpleFileSystem.h>\r
12#include <Protocol/UnicodeCollation.h>\r
13\r
14#include <Guid/FileInfo.h>\r
15\r
16#include <Library/DebugLib.h>\r
17#include <Library/MemoryAllocationLib.h>\r
18#include <Library/BaseLib.h>\r
19#include <Library/BaseMemoryLib.h>\r
20#include <Library/FileHandleLib.h>\r
21#include <Library/PcdLib.h>\r
22#include <Library/PrintLib.h>\r
23\r
24CONST UINT16 gUnicodeFileTag = EFI_UNICODE_BYTE_ORDER_MARK;\r
25\r
26#define MAX_FILE_NAME_LEN 522 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)\r
27#define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)\r
28\r
29/**\r
30 This function will retrieve the information about the file for the handle\r
31 specified and store it in allocated pool memory.\r
32\r
33 This function allocates a buffer to store the file's information. It is the\r
34 caller's responsibility to free the buffer\r
35\r
36 @param FileHandle The file handle of the file for which information is\r
37 being requested.\r
38\r
39 @retval NULL information could not be retrieved.\r
40\r
41 @return the information about the file\r
42**/\r
43EFI_FILE_INFO*\r
44EFIAPI\r
45FileHandleGetInfo (\r
46 IN EFI_FILE_HANDLE FileHandle\r
47 )\r
48{\r
49 EFI_FILE_INFO *FileInfo;\r
50 UINTN FileInfoSize;\r
51 EFI_STATUS Status;\r
52\r
53 if (FileHandle == NULL) {\r
54 return (NULL);\r
55 }\r
56\r
57 //\r
58 // Get the required size to allocate\r
59 //\r
60 FileInfoSize = 0;\r
61 FileInfo = NULL;\r
62 Status = FileHandle->GetInfo(FileHandle,\r
63 &gEfiFileInfoGuid,\r
64 &FileInfoSize,\r
65 NULL);\r
66 if (Status == EFI_BUFFER_TOO_SMALL){\r
67 //\r
68 // error is expected. getting size to allocate\r
69 //\r
70 FileInfo = AllocateZeroPool(FileInfoSize);\r
71 if (FileInfo != NULL) {\r
72 //\r
73 // now get the information\r
74 //\r
75 Status = FileHandle->GetInfo(FileHandle,\r
76 &gEfiFileInfoGuid,\r
77 &FileInfoSize,\r
78 FileInfo);\r
79 //\r
80 // if we got an error free the memory and return NULL\r
81 //\r
82 if (EFI_ERROR(Status)) {\r
83 FreePool(FileInfo);\r
84 FileInfo = NULL;\r
85 }\r
86 }\r
87 }\r
88 return (FileInfo);\r
89}\r
90\r
91/**\r
92 This function sets the information about the file for the opened handle\r
93 specified.\r
94\r
95 @param[in] FileHandle The file handle of the file for which information\r
96 is being set.\r
97\r
98 @param[in] FileInfo The information to set.\r
99\r
100 @retval EFI_SUCCESS The information was set.\r
101 @retval EFI_INVALID_PARAMETER A parameter was out of range or invalid.\r
102 @retval EFI_UNSUPPORTED The FileHandle does not support FileInfo.\r
103 @retval EFI_NO_MEDIA The device has no medium.\r
104 @retval EFI_DEVICE_ERROR The device reported an error.\r
105 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
106 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
107 @retval EFI_ACCESS_DENIED The file was opened read only.\r
108 @retval EFI_VOLUME_FULL The volume is full.\r
109**/\r
110EFI_STATUS\r
111EFIAPI\r
112FileHandleSetInfo (\r
113 IN EFI_FILE_HANDLE FileHandle,\r
114 IN CONST EFI_FILE_INFO *FileInfo\r
115 )\r
116{\r
117\r
118 if (FileHandle == NULL || FileInfo == NULL) {\r
119 return (EFI_INVALID_PARAMETER);\r
120 }\r
121\r
122 //\r
123 // Set the info\r
124 //\r
125 return (FileHandle->SetInfo(FileHandle,\r
126 &gEfiFileInfoGuid,\r
127 (UINTN)FileInfo->Size,\r
128 (EFI_FILE_INFO*)FileInfo));\r
129}\r
130\r
131/**\r
132 This function reads information from an opened file.\r
133\r
134 If FileHandle is not a directory, the function reads the requested number of\r
135 bytes from the file at the file's current position and returns them in Buffer.\r
136 If the read goes beyond the end of the file, the read length is truncated to the\r
137 end of the file. The file's current position is increased by the number of bytes\r
138 returned. If FileHandle is a directory, the function reads the directory entry\r
139 at the file's current position and returns the entry in Buffer. If the Buffer\r
140 is not large enough to hold the current directory entry, then\r
141 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.\r
142 BufferSize is set to be the size of the buffer needed to read the entry. On\r
143 success, the current position is updated to the next directory entry. If there\r
144 are no more directory entries, the read returns a zero-length buffer.\r
145 EFI_FILE_INFO is the structure returned as the directory entry.\r
146\r
147 @param FileHandle the opened file handle\r
148 @param BufferSize on input the size of buffer in bytes. on return\r
149 the number of bytes written.\r
150 @param Buffer the buffer to put read data into.\r
151\r
152 @retval EFI_SUCCESS Data was read.\r
153 @retval EFI_NO_MEDIA The device has no media.\r
154 @retval EFI_DEVICE_ERROR The device reported an error.\r
155 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
156 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required\r
157 size.\r
158\r
159**/\r
160EFI_STATUS\r
161EFIAPI\r
162FileHandleRead(\r
163 IN EFI_FILE_HANDLE FileHandle,\r
164 IN OUT UINTN *BufferSize,\r
165 OUT VOID *Buffer\r
166 )\r
167{\r
168 if (FileHandle == NULL) {\r
169 return (EFI_INVALID_PARAMETER);\r
170 }\r
171\r
172 //\r
173 // Perform the read based on EFI_FILE_PROTOCOL\r
174 //\r
175 return (FileHandle->Read(FileHandle, BufferSize, Buffer));\r
176}\r
177\r
178\r
179/**\r
180 Write data to a file.\r
181\r
182 This function writes the specified number of bytes to the file at the current\r
183 file position. The current file position is advanced the actual number of bytes\r
184 written, which is returned in BufferSize. Partial writes only occur when there\r
185 has been a data error during the write attempt (such as "volume space full").\r
186 The file is automatically grown to hold the data if required. Direct writes to\r
187 opened directories are not supported.\r
188\r
189 @param FileHandle The opened file for writing\r
190 @param BufferSize on input the number of bytes in Buffer. On output\r
191 the number of bytes written.\r
192 @param Buffer the buffer containing data to write is stored.\r
193\r
194 @retval EFI_SUCCESS Data was written.\r
195 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.\r
196 @retval EFI_NO_MEDIA The device has no media.\r
197 @retval EFI_DEVICE_ERROR The device reported an error.\r
198 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
199 @retval EFI_WRITE_PROTECTED The device is write-protected.\r
200 @retval EFI_ACCESS_DENIED The file was open for read only.\r
201 @retval EFI_VOLUME_FULL The volume is full.\r
202**/\r
203EFI_STATUS\r
204EFIAPI\r
205FileHandleWrite(\r
206 IN EFI_FILE_HANDLE FileHandle,\r
207 IN OUT UINTN *BufferSize,\r
208 IN VOID *Buffer\r
209 )\r
210{\r
211 if (FileHandle == NULL) {\r
212 return (EFI_INVALID_PARAMETER);\r
213 }\r
214\r
215 //\r
216 // Perform the write based on EFI_FILE_PROTOCOL\r
217 //\r
218 return (FileHandle->Write(FileHandle, BufferSize, Buffer));\r
219}\r
220\r
221/**\r
222 Close an open file handle.\r
223\r
224 This function closes a specified file handle. All "dirty" cached file data is\r
225 flushed to the device, and the file is closed. In all cases the handle is\r
226 closed.\r
227\r
228@param FileHandle the file handle to close.\r
229\r
230@retval EFI_SUCCESS the file handle was closed successfully.\r
231**/\r
232EFI_STATUS\r
233EFIAPI\r
234FileHandleClose (\r
235 IN EFI_FILE_HANDLE FileHandle\r
236 )\r
237{\r
238 EFI_STATUS Status;\r
239\r
240 if (FileHandle == NULL) {\r
241 return (EFI_INVALID_PARAMETER);\r
242 }\r
243\r
244 //\r
245 // Perform the Close based on EFI_FILE_PROTOCOL\r
246 //\r
247 Status = FileHandle->Close(FileHandle);\r
248 return Status;\r
249}\r
250\r
251/**\r
252 Delete a file and close the handle\r
253\r
254 This function closes and deletes a file. In all cases the file handle is closed.\r
255 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is\r
256 returned, but the handle is still closed.\r
257\r
258 @param FileHandle the file handle to delete\r
259\r
260 @retval EFI_SUCCESS the file was closed successfully\r
261 @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not\r
262 deleted\r
263 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
264**/\r
265EFI_STATUS\r
266EFIAPI\r
267FileHandleDelete (\r
268 IN EFI_FILE_HANDLE FileHandle\r
269 )\r
270{\r
271 EFI_STATUS Status;\r
272\r
273 if (FileHandle == NULL) {\r
274 return (EFI_INVALID_PARAMETER);\r
275 }\r
276\r
277 //\r
278 // Perform the Delete based on EFI_FILE_PROTOCOL\r
279 //\r
280 Status = FileHandle->Delete(FileHandle);\r
281 return Status;\r
282}\r
283\r
284/**\r
285 Set the current position in a file.\r
286\r
287 This function sets the current file position for the handle to the position\r
288 supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only\r
289 absolute positioning is supported, and seeking past the end of the file is\r
290 allowed (a subsequent write would grow the file). Seeking to position\r
291 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.\r
292 If FileHandle is a directory, the only position that may be set is zero. This\r
293 has the effect of starting the read process of the directory entries over.\r
294\r
295 @param FileHandle The file handle on which the position is being set\r
296 @param Position Byte position from beginning of file\r
297\r
298 @retval EFI_SUCCESS Operation completed successfully.\r
299 @retval EFI_UNSUPPORTED the seek request for non-zero is not valid on\r
300 directories.\r
301 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
302**/\r
303EFI_STATUS\r
304EFIAPI\r
305FileHandleSetPosition (\r
306 IN EFI_FILE_HANDLE FileHandle,\r
307 IN UINT64 Position\r
308 )\r
309{\r
310 if (FileHandle == NULL) {\r
311 return (EFI_INVALID_PARAMETER);\r
312 }\r
313\r
314 //\r
315 // Perform the SetPosition based on EFI_FILE_PROTOCOL\r
316 //\r
317 return (FileHandle->SetPosition(FileHandle, Position));\r
318}\r
319\r
320/**\r
321 Gets a file's current position\r
322\r
323 This function retrieves the current file position for the file handle. For\r
324 directories, the current file position has no meaning outside of the file\r
325 system driver and as such the operation is not supported. An error is returned\r
326 if FileHandle is a directory.\r
327\r
328 @param FileHandle The open file handle on which to get the position.\r
329 @param Position Byte position from beginning of file.\r
330\r
331 @retval EFI_SUCCESS the operation completed successfully.\r
332 @retval INVALID_PARAMETER One of the parameters has an invalid value.\r
333 @retval EFI_UNSUPPORTED the request is not valid on directories.\r
334**/\r
335EFI_STATUS\r
336EFIAPI\r
337FileHandleGetPosition (\r
338 IN EFI_FILE_HANDLE FileHandle,\r
339 OUT UINT64 *Position\r
340 )\r
341{\r
342 if (Position == NULL || FileHandle == NULL) {\r
343 return (EFI_INVALID_PARAMETER);\r
344 }\r
345\r
346 //\r
347 // Perform the GetPosition based on EFI_FILE_PROTOCOL\r
348 //\r
349 return (FileHandle->GetPosition(FileHandle, Position));\r
350}\r
351/**\r
352 Flushes data on a file\r
353\r
354 This function flushes all modified data associated with a file to a device.\r
355\r
356 @param FileHandle The file handle on which to flush data\r
357\r
358 @retval EFI_SUCCESS The data was flushed.\r
359 @retval EFI_NO_MEDIA The device has no media.\r
360 @retval EFI_DEVICE_ERROR The device reported an error.\r
361 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
362 @retval EFI_WRITE_PROTECTED The file or medium is write protected.\r
363 @retval EFI_ACCESS_DENIED The file was opened for read only.\r
364**/\r
365EFI_STATUS\r
366EFIAPI\r
367FileHandleFlush (\r
368 IN EFI_FILE_HANDLE FileHandle\r
369 )\r
370{\r
371 if (FileHandle == NULL) {\r
372 return (EFI_INVALID_PARAMETER);\r
373 }\r
374\r
375 //\r
376 // Perform the Flush based on EFI_FILE_PROTOCOL\r
377 //\r
378 return (FileHandle->Flush(FileHandle));\r
379}\r
380\r
381/**\r
382 Function to determine if a given handle is a directory handle.\r
383\r
384 Open the file information on the DirHandle and verify that the Attribute\r
385 includes EFI_FILE_DIRECTORY bit set.\r
386\r
387 @param[in] DirHandle Handle to open file.\r
388\r
389 @retval EFI_SUCCESS DirHandle is a directory.\r
390 @retval EFI_INVALID_PARAMETER DirHandle is NULL.\r
391 The file information returns from FileHandleGetInfo is NULL.\r
392 @retval EFI_NOT_FOUND DirHandle is not a directory.\r
393**/\r
394EFI_STATUS\r
395EFIAPI\r
396FileHandleIsDirectory (\r
397 IN EFI_FILE_HANDLE DirHandle\r
398 )\r
399{\r
400 EFI_FILE_INFO *DirInfo;\r
401\r
402 if (DirHandle == NULL) {\r
403 return (EFI_INVALID_PARAMETER);\r
404 }\r
405\r
406 //\r
407 // get the file information for DirHandle\r
408 //\r
409 DirInfo = FileHandleGetInfo (DirHandle);\r
410\r
411 //\r
412 // Parse DirInfo\r
413 //\r
414 if (DirInfo == NULL) {\r
415 //\r
416 // We got nothing...\r
417 //\r
418 return (EFI_INVALID_PARAMETER);\r
419 }\r
420 if ((DirInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {\r
421 //\r
422 // Attributes say this is not a directory\r
423 //\r
424 FreePool (DirInfo);\r
425 return (EFI_NOT_FOUND);\r
426 }\r
427 //\r
428 // all good...\r
429 //\r
430 FreePool (DirInfo);\r
431 return (EFI_SUCCESS);\r
432}\r
433\r
434/** Retrieve first entry from a directory.\r
435\r
436 This function takes an open directory handle and gets information from the\r
437 first entry in the directory. A buffer is allocated to contain\r
438 the information and a pointer to the buffer is returned in *Buffer. The\r
439 caller can use FileHandleFindNextFile() to get subsequent directory entries.\r
440\r
441 The buffer will be freed by FileHandleFindNextFile() when the last directory\r
442 entry is read. Otherwise, the caller must free the buffer, using FreePool,\r
443 when finished with it.\r
444\r
445 @param[in] DirHandle The file handle of the directory to search.\r
446 @param[out] Buffer The pointer to pointer to buffer for file's information.\r
447\r
448 @retval EFI_SUCCESS Found the first file.\r
449 @retval EFI_NOT_FOUND Cannot find the directory.\r
450 @retval EFI_NO_MEDIA The device has no media.\r
451 @retval EFI_DEVICE_ERROR The device reported an error.\r
452 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
453 @return Others status of FileHandleGetInfo, FileHandleSetPosition,\r
454 or FileHandleRead\r
455**/\r
456EFI_STATUS\r
457EFIAPI\r
458FileHandleFindFirstFile (\r
459 IN EFI_FILE_HANDLE DirHandle,\r
460 OUT EFI_FILE_INFO **Buffer\r
461 )\r
462{\r
463 EFI_STATUS Status;\r
464 UINTN BufferSize;\r
465\r
466 if (Buffer == NULL || DirHandle == NULL) {\r
467 return (EFI_INVALID_PARAMETER);\r
468 }\r
469\r
470 //\r
471 // verify that DirHandle is a directory\r
472 //\r
473 Status = FileHandleIsDirectory(DirHandle);\r
474 if (EFI_ERROR(Status)) {\r
475 return (Status);\r
476 }\r
477\r
478 //\r
479 // Allocate a buffer sized to struct size + enough for the string at the end\r
480 //\r
481 BufferSize = FIND_XXXXX_FILE_BUFFER_SIZE;\r
482 *Buffer = AllocateZeroPool(BufferSize);\r
483 if (*Buffer == NULL){\r
484 return (EFI_OUT_OF_RESOURCES);\r
485 }\r
486\r
487 //\r
488 // reset to the beginning of the directory\r
489 //\r
490 Status = FileHandleSetPosition(DirHandle, 0);\r
491 if (EFI_ERROR(Status)) {\r
492 FreePool(*Buffer);\r
493 *Buffer = NULL;\r
494 return (Status);\r
495 }\r
496\r
497 //\r
498 // read in the info about the first file\r
499 //\r
500 Status = FileHandleRead (DirHandle, &BufferSize, *Buffer);\r
501 ASSERT(Status != EFI_BUFFER_TOO_SMALL);\r
502 if (EFI_ERROR(Status) || BufferSize == 0) {\r
503 FreePool(*Buffer);\r
504 *Buffer = NULL;\r
505 if (BufferSize == 0) {\r
506 return (EFI_NOT_FOUND);\r
507 }\r
508 return (Status);\r
509 }\r
510 return (EFI_SUCCESS);\r
511}\r
512\r
513/** Retrieve next entries from a directory.\r
514\r
515 To use this function, the caller must first call the FileHandleFindFirstFile()\r
516 function to get the first directory entry. Subsequent directory entries are\r
517 retrieved by using the FileHandleFindNextFile() function. This function can\r
518 be called several times to get each entry from the directory. If the call of\r
519 FileHandleFindNextFile() retrieved the last directory entry, the next call of\r
520 this function will set *NoFile to TRUE and free the buffer.\r
521\r
522 @param[in] DirHandle The file handle of the directory.\r
523 @param[out] Buffer The pointer to buffer for file's information.\r
524 @param[out] NoFile The pointer to boolean when last file is found.\r
525\r
526 @retval EFI_SUCCESS Found the next file, or reached last file\r
527 @retval EFI_NO_MEDIA The device has no media.\r
528 @retval EFI_DEVICE_ERROR The device reported an error.\r
529 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
530**/\r
531EFI_STATUS\r
532EFIAPI\r
533FileHandleFindNextFile(\r
534 IN EFI_FILE_HANDLE DirHandle,\r
535 OUT EFI_FILE_INFO *Buffer,\r
536 OUT BOOLEAN *NoFile\r
537 )\r
538{\r
539 EFI_STATUS Status;\r
540 UINTN BufferSize;\r
541\r
542 if (DirHandle == NULL || Buffer == NULL || NoFile == NULL) {\r
543 return (EFI_INVALID_PARAMETER);\r
544 }\r
545\r
546 //\r
547 // This BufferSize MUST stay equal to the originally allocated one in GetFirstFile\r
548 //\r
549 BufferSize = FIND_XXXXX_FILE_BUFFER_SIZE;\r
550\r
551 //\r
552 // read in the info about the next file\r
553 //\r
554 Status = FileHandleRead (DirHandle, &BufferSize, Buffer);\r
555 ASSERT(Status != EFI_BUFFER_TOO_SMALL);\r
556 if (EFI_ERROR(Status)) {\r
557 return (Status);\r
558 }\r
559\r
560 //\r
561 // If we read 0 bytes (but did not have erros) we already read in the last file.\r
562 //\r
563 if (BufferSize == 0) {\r
564 FreePool(Buffer);\r
565 *NoFile = TRUE;\r
566 }\r
567\r
568 return (EFI_SUCCESS);\r
569}\r
570\r
571/**\r
572 Retrieve the size of a file.\r
573\r
574 This function extracts the file size info from the FileHandle's EFI_FILE_INFO\r
575 data.\r
576\r
577 @param[in] FileHandle The file handle from which size is retrieved.\r
578 @param[out] Size The pointer to size.\r
579\r
580 @retval EFI_SUCCESS Operation was completed successfully.\r
581 @retval EFI_DEVICE_ERROR Cannot access the file.\r
582 @retval EFI_INVALID_PARAMETER FileHandle is NULL.\r
583 Size is NULL.\r
584**/\r
585EFI_STATUS\r
586EFIAPI\r
587FileHandleGetSize (\r
588 IN EFI_FILE_HANDLE FileHandle,\r
589 OUT UINT64 *Size\r
590 )\r
591{\r
592 EFI_FILE_INFO *FileInfo;\r
593\r
594 if (FileHandle == NULL || Size == NULL) {\r
595 return (EFI_INVALID_PARAMETER);\r
596 }\r
597\r
598 //\r
599 // get the FileInfo structure\r
600 //\r
601 FileInfo = FileHandleGetInfo(FileHandle);\r
602 if (FileInfo == NULL) {\r
603 return (EFI_DEVICE_ERROR);\r
604 }\r
605\r
606 //\r
607 // Assign the Size pointer to the correct value\r
608 //\r
609 *Size = FileInfo->FileSize;\r
610\r
611 //\r
612 // free the FileInfo memory\r
613 //\r
614 FreePool(FileInfo);\r
615\r
616 return (EFI_SUCCESS);\r
617}\r
618\r
619/**\r
620 Set the size of a file.\r
621\r
622 This function changes the file size info from the FileHandle's EFI_FILE_INFO\r
623 data.\r
624\r
625 @param[in] FileHandle The file handle whose size is to be changed.\r
626 @param[in] Size The new size.\r
627\r
628 @retval EFI_SUCCESS The operation completed successfully.\r
629 @retval EFI_DEVICE_ERROR Cannot access the file.\r
630 @retval EFI_INVALID_PARAMETER FileHandle is NULL.\r
631**/\r
632EFI_STATUS\r
633EFIAPI\r
634FileHandleSetSize (\r
635 IN EFI_FILE_HANDLE FileHandle,\r
636 IN UINT64 Size\r
637 )\r
638{\r
639 EFI_FILE_INFO *FileInfo;\r
640 EFI_STATUS Status;\r
641\r
642 if (FileHandle == NULL) {\r
643 return (EFI_INVALID_PARAMETER);\r
644 }\r
645\r
646 //\r
647 // get the FileInfo structure\r
648 //\r
649 FileInfo = FileHandleGetInfo(FileHandle);\r
650 if (FileInfo == NULL) {\r
651 return (EFI_DEVICE_ERROR);\r
652 }\r
653\r
654 //\r
655 // Assign the FileSize pointer to the new value\r
656 //\r
657 FileInfo->FileSize = Size;\r
658\r
659 Status = FileHandleSetInfo(FileHandle, FileInfo);\r
660 //\r
661 // free the FileInfo memory\r
662 //\r
663 FreePool(FileInfo);\r
664\r
665 return (Status);\r
666}\r
667\r
668/**\r
669 Safely append (on the left) with automatic string resizing given length of Destination and\r
670 desired length of copy from Source.\r
671\r
672 append the first D characters of Source to the end of Destination, where D is\r
673 the lesser of Count and the StrLen() of Source. If appending those D characters\r
674 will fit within Destination (whose Size is given as CurrentSize) and\r
675 still leave room for a NULL terminator, then those characters are appended,\r
676 starting at the original terminating NULL of Destination, and a new terminating\r
677 NULL is appended.\r
678\r
679 If appending D characters onto Destination will result in a overflow of the size\r
680 given in CurrentSize the string will be grown such that the copy can be performed\r
681 and CurrentSize will be updated to the new size.\r
682\r
683 If Source is NULL, there is nothing to append, just return the current buffer in\r
684 Destination.\r
685\r
686 if Destination is NULL, then return error\r
687 if Destination's current length (including NULL terminator) is already more then\r
688 CurrentSize, then ASSERT()\r
689\r
690 @param[in, out] Destination The String to append onto\r
691 @param[in, out] CurrentSize on call the number of bytes in Destination. On\r
692 return possibly the new size (still in bytes). if NULL\r
693 then allocate whatever is needed.\r
694 @param[in] Source The String to append from\r
695 @param[in] Count Maximum number of characters to append. if 0 then\r
696 all are appended.\r
697\r
698 @return Destination return the resultant string.\r
699**/\r
700CHAR16*\r
701EFIAPI\r
702StrnCatGrowLeft (\r
703 IN OUT CHAR16 **Destination,\r
704 IN OUT UINTN *CurrentSize,\r
705 IN CONST CHAR16 *Source,\r
706 IN UINTN Count\r
707 )\r
708{\r
709 UINTN DestinationStartSize;\r
710 UINTN NewSize;\r
711 UINTN CopySize;\r
712\r
713 if (Destination == NULL) {\r
714 return (NULL);\r
715 }\r
716\r
717 //\r
718 // If there's nothing to do then just return Destination\r
719 //\r
720 if (Source == NULL) {\r
721 return (*Destination);\r
722 }\r
723\r
724 //\r
725 // allow for NULL pointers address as Destination\r
726 //\r
727 if (*Destination != NULL) {\r
728 ASSERT(CurrentSize != 0);\r
729 DestinationStartSize = StrSize(*Destination);\r
730 ASSERT(DestinationStartSize <= *CurrentSize);\r
731 } else {\r
732 DestinationStartSize = 0;\r
733// ASSERT(*CurrentSize == 0);\r
734 }\r
735\r
736 //\r
737 // Append all of Source?\r
738 //\r
739 if (Count == 0) {\r
740 Count = StrSize(Source);\r
741 }\r
742\r
743 //\r
744 // Test and grow if required\r
745 //\r
746 if (CurrentSize != NULL) {\r
747 NewSize = *CurrentSize;\r
748 while (NewSize < (DestinationStartSize + Count)) {\r
749 NewSize += 2 * Count;\r
750 }\r
751 *Destination = ReallocatePool(*CurrentSize, NewSize, *Destination);\r
752 *CurrentSize = NewSize;\r
753 } else {\r
754 *Destination = AllocateZeroPool(Count+sizeof(CHAR16));\r
755 }\r
756 if (*Destination == NULL) {\r
757 return NULL;\r
758 }\r
759\r
760 CopySize = StrSize(*Destination);\r
761 CopyMem((*Destination)+((Count-2)/sizeof(CHAR16)), *Destination, CopySize);\r
762 CopyMem(*Destination, Source, Count-2);\r
763 return (*Destination);\r
764}\r
765\r
766/**\r
767 Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the\r
768 directory 'stack'. If the file is a directory, then append the '\' char at the\r
769 end of name string. If it's not a directory, then the last '\' should not be\r
770 added.\r
771\r
772 if Handle is NULL, return EFI_INVALID_PARAMETER\r
773\r
774 @param[in] Handle Handle to the Directory or File to create path to.\r
775 @param[out] FullFileName pointer to pointer to generated full file name. It\r
776 is the responsibility of the caller to free this memory\r
777 with a call to FreePool().\r
778 @retval EFI_SUCCESS the operation was sucessful and the FullFileName is valid.\r
779 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
780 @retval EFI_INVALID_PARAMETER FullFileName was NULL.\r
781 @retval EFI_OUT_OF_RESOURCES a memory allocation failed.\r
782**/\r
783EFI_STATUS\r
784EFIAPI\r
785FileHandleGetFileName (\r
786 IN CONST EFI_FILE_HANDLE Handle,\r
787 OUT CHAR16 **FullFileName\r
788 )\r
789{\r
790 EFI_STATUS Status;\r
791 UINTN Size;\r
792 EFI_FILE_HANDLE CurrentHandle;\r
793 EFI_FILE_HANDLE NextHigherHandle;\r
794 EFI_FILE_INFO *FileInfo;\r
795\r
796 Size = 0;\r
797\r
798 //\r
799 // Check our parameters\r
800 //\r
801 if (FullFileName == NULL || Handle == NULL) {\r
802 return (EFI_INVALID_PARAMETER);\r
803 }\r
804\r
805 *FullFileName = NULL;\r
806 CurrentHandle = NULL;\r
807\r
808 Status = Handle->Open(Handle, &CurrentHandle, L".", EFI_FILE_MODE_READ, 0);\r
809 if (!EFI_ERROR(Status)) {\r
810 //\r
811 // Reverse out the current directory on the device\r
812 //\r
813 for (;;) {\r
814 FileInfo = FileHandleGetInfo(CurrentHandle);\r
815 if (FileInfo == NULL) {\r
816 Status = EFI_OUT_OF_RESOURCES;\r
817 break;\r
818 } else {\r
819 //\r
820 // Prepare to move to the parent directory.\r
821 // Also determine whether CurrentHandle refers to the Root directory.\r
822 //\r
823 Status = CurrentHandle->Open (CurrentHandle, &NextHigherHandle, L"..", EFI_FILE_MODE_READ, 0);\r
824 //\r
825 // We got info... do we have a name? if yes precede the current path with it...\r
826 //\r
827 if ((StrLen (FileInfo->FileName) == 0) || EFI_ERROR (Status)) {\r
828 //\r
829 // Both FileInfo->FileName being '\0' and EFI_ERROR() suggest that\r
830 // CurrentHandle refers to the Root directory. As this loop ensures\r
831 // FullFileName is starting with '\\' at all times, signal success\r
832 // and exit the loop.\r
833 // While FileInfo->FileName could theoretically be a value other than\r
834 // '\0' or '\\', '\\' is guaranteed to be supported by the\r
835 // specification and hence its value can safely be ignored.\r
836 //\r
837 Status = EFI_SUCCESS;\r
838 if (*FullFileName == NULL) {\r
839 ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));\r
840 *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);\r
841 }\r
842 FreePool(FileInfo);\r
843 break;\r
844 } else {\r
845 if (*FullFileName == NULL) {\r
846 ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));\r
847 *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);\r
848 }\r
849 ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));\r
850 *FullFileName = StrnCatGrowLeft(FullFileName, &Size, FileInfo->FileName, 0);\r
851 *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);\r
852 FreePool(FileInfo);\r
853 }\r
854 }\r
855\r
856 FileHandleClose(CurrentHandle);\r
857 //\r
858 // Move to the parent directory\r
859 //\r
860 CurrentHandle = NextHigherHandle;\r
861 }\r
862 } else if (Status == EFI_NOT_FOUND) {\r
863 Status = EFI_SUCCESS;\r
864 ASSERT((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));\r
865 *FullFileName = StrnCatGrowLeft(FullFileName, &Size, L"\\", 0);\r
866 }\r
867\r
868 if (*FullFileName != NULL &&\r
869 (*FullFileName)[StrLen(*FullFileName) - 1] == L'\\' &&\r
870 StrLen(*FullFileName) > 1 &&\r
871 FileHandleIsDirectory(Handle) == EFI_NOT_FOUND\r
872 ) {\r
873 (*FullFileName)[StrLen(*FullFileName) - 1] = CHAR_NULL;\r
874 }\r
875\r
876 if (CurrentHandle != NULL) {\r
877 CurrentHandle->Close (CurrentHandle);\r
878 }\r
879\r
880 if (EFI_ERROR(Status) && *FullFileName != NULL) {\r
881 FreePool(*FullFileName);\r
882 }\r
883\r
884 return (Status);\r
885}\r
886\r
887/**\r
888 Function to read a single line from a file. The \n is not included in the returned\r
889 buffer. The returned buffer must be callee freed.\r
890\r
891 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
892 maintained and not changed for all operations with the same file.\r
893\r
894 @param[in] Handle FileHandle to read from.\r
895 @param[in, out] Ascii Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);\r
896\r
897 @return The line of text from the file.\r
898\r
899 @sa FileHandleReadLine\r
900**/\r
901CHAR16*\r
902EFIAPI\r
903FileHandleReturnLine(\r
904 IN EFI_FILE_HANDLE Handle,\r
905 IN OUT BOOLEAN *Ascii\r
906 )\r
907{\r
908 CHAR16 *RetVal;\r
909 UINTN Size;\r
910 EFI_STATUS Status;\r
911\r
912 Size = 0;\r
913 RetVal = NULL;\r
914\r
915 Status = FileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
916 if (Status == EFI_BUFFER_TOO_SMALL) {\r
917 RetVal = AllocateZeroPool(Size);\r
918 Status = FileHandleReadLine(Handle, RetVal, &Size, FALSE, Ascii);\r
919 }\r
920 ASSERT_EFI_ERROR(Status);\r
921 if (EFI_ERROR(Status) && (RetVal != NULL)) {\r
922 FreePool(RetVal);\r
923 RetVal = NULL;\r
924 }\r
925 return (RetVal);\r
926}\r
927\r
928/**\r
929 Function to read a single line (up to but not including the \n) from a file.\r
930\r
931 If the position upon start is 0, then the Ascii Boolean will be set. This should be\r
932 maintained and not changed for all operations with the same file.\r
933 The function will not return the \r and \n character in buffer. When an empty line is\r
934 read a CHAR_NULL character will be returned in buffer.\r
935\r
936 @param[in] Handle FileHandle to read from.\r
937 @param[in, out] Buffer The pointer to buffer to read into.\r
938 @param[in, out] Size The pointer to number of bytes in Buffer.\r
939 @param[in] Truncate If the buffer is large enough, this has no effect.\r
940 If the buffer is is too small and Truncate is TRUE,\r
941 the line will be truncated.\r
942 If the buffer is is too small and Truncate is FALSE,\r
943 then no read will occur.\r
944\r
945 @param[in, out] Ascii Boolean value for indicating whether the file is\r
946 Ascii (TRUE) or UCS2 (FALSE).\r
947\r
948 @retval EFI_SUCCESS The operation was successful. The line is stored in\r
949 Buffer.\r
950 @retval EFI_INVALID_PARAMETER Handle was NULL.\r
951 @retval EFI_INVALID_PARAMETER Size was NULL.\r
952 @retval EFI_BUFFER_TOO_SMALL Size was not large enough to store the line.\r
953 Size was updated to the minimum space required.\r
954 @sa FileHandleRead\r
955**/\r
956EFI_STATUS\r
957EFIAPI\r
958FileHandleReadLine(\r
959 IN EFI_FILE_HANDLE Handle,\r
960 IN OUT CHAR16 *Buffer,\r
961 IN OUT UINTN *Size,\r
962 IN BOOLEAN Truncate,\r
963 IN OUT BOOLEAN *Ascii\r
964 )\r
965{\r
966 EFI_STATUS Status;\r
967 CHAR16 CharBuffer;\r
968 UINT64 FileSize;\r
969 UINTN CharSize;\r
970 UINTN CountSoFar;\r
971 UINTN CrCount;\r
972 UINT64 OriginalFilePosition;\r
973\r
974 if (Handle == NULL\r
975 ||Size == NULL\r
976 ||(Buffer==NULL&&*Size!=0)\r
977 ){\r
978 return (EFI_INVALID_PARAMETER);\r
979 }\r
980\r
981 if (Buffer != NULL && *Size != 0) {\r
982 *Buffer = CHAR_NULL;\r
983 }\r
984\r
985 Status = FileHandleGetSize (Handle, &FileSize);\r
986 if (EFI_ERROR (Status)) {\r
987 return Status;\r
988 } else if (FileSize == 0) {\r
989 *Ascii = TRUE;\r
990 return EFI_SUCCESS;\r
991 }\r
992\r
993 FileHandleGetPosition(Handle, &OriginalFilePosition);\r
994 if (OriginalFilePosition == 0) {\r
995 CharSize = sizeof(CHAR16);\r
996 Status = FileHandleRead(Handle, &CharSize, &CharBuffer);\r
997 ASSERT_EFI_ERROR(Status);\r
998 if (CharBuffer == gUnicodeFileTag) {\r
999 *Ascii = FALSE;\r
1000 } else {\r
1001 *Ascii = TRUE;\r
1002 FileHandleSetPosition(Handle, OriginalFilePosition);\r
1003 }\r
1004 }\r
1005\r
1006 CrCount = 0;\r
1007 for (CountSoFar = 0;;CountSoFar++){\r
1008 CharBuffer = 0;\r
1009 if (*Ascii) {\r
1010 CharSize = sizeof(CHAR8);\r
1011 } else {\r
1012 CharSize = sizeof(CHAR16);\r
1013 }\r
1014 Status = FileHandleRead(Handle, &CharSize, &CharBuffer);\r
1015 if ( EFI_ERROR(Status)\r
1016 || CharSize == 0\r
1017 || (CharBuffer == L'\n' && !(*Ascii))\r
1018 || (CharBuffer == '\n' && *Ascii)\r
1019 ){\r
1020 break;\r
1021 } else if (\r
1022 (CharBuffer == L'\r' && !(*Ascii)) ||\r
1023 (CharBuffer == '\r' && *Ascii)\r
1024 ) {\r
1025 CrCount++;\r
1026 continue;\r
1027 }\r
1028 //\r
1029 // if we have space save it...\r
1030 //\r
1031 if ((CountSoFar+1-CrCount)*sizeof(CHAR16) < *Size){\r
1032 ASSERT(Buffer != NULL);\r
1033 ((CHAR16*)Buffer)[CountSoFar-CrCount] = CharBuffer;\r
1034 ((CHAR16*)Buffer)[CountSoFar+1-CrCount] = CHAR_NULL;\r
1035 }\r
1036 }\r
1037\r
1038 //\r
1039 // if we ran out of space tell when...\r
1040 //\r
1041 if ((CountSoFar+1-CrCount)*sizeof(CHAR16) > *Size){\r
1042 *Size = (CountSoFar+1-CrCount)*sizeof(CHAR16);\r
1043 if (!Truncate) {\r
1044 if (Buffer != NULL && *Size != 0) {\r
1045 ZeroMem(Buffer, *Size);\r
1046 }\r
1047 FileHandleSetPosition(Handle, OriginalFilePosition);\r
1048 return (EFI_BUFFER_TOO_SMALL);\r
1049 } else {\r
1050 DEBUG((DEBUG_WARN, "The line was truncated in FileHandleReadLine"));\r
1051 return (EFI_SUCCESS);\r
1052 }\r
1053 }\r
1054\r
1055 return (Status);\r
1056}\r
1057\r
1058/**\r
1059 Function to write a line of text to a file.\r
1060\r
1061 If the file is a Unicode file (with UNICODE file tag) then write the unicode\r
1062 text.\r
1063 If the file is an ASCII file then write the ASCII text.\r
1064 If the size of file is zero (without file tag at the beginning) then write\r
1065 ASCII text as default.\r
1066\r
1067 @param[in] Handle FileHandle to write to.\r
1068 @param[in] Buffer Buffer to write, if NULL the function will\r
1069 take no action and return EFI_SUCCESS.\r
1070\r
1071 @retval EFI_SUCCESS The data was written.\r
1072 Buffer is NULL.\r
1073 @retval EFI_INVALID_PARAMETER Handle is NULL.\r
1074 @retval EFI_OUT_OF_RESOURCES Unable to allocate temporary space for ASCII\r
1075 string due to out of resources.\r
1076\r
1077 @sa FileHandleWrite\r
1078**/\r
1079EFI_STATUS\r
1080EFIAPI\r
1081FileHandleWriteLine(\r
1082 IN EFI_FILE_HANDLE Handle,\r
1083 IN CHAR16 *Buffer\r
1084 )\r
1085{\r
1086 EFI_STATUS Status;\r
1087 CHAR16 CharBuffer;\r
1088 UINTN Size;\r
1089 UINTN Index;\r
1090 UINTN CharSize;\r
1091 UINT64 FileSize;\r
1092 UINT64 OriginalFilePosition;\r
1093 BOOLEAN Ascii;\r
1094 CHAR8 *AsciiBuffer;\r
1095\r
1096 if (Buffer == NULL) {\r
1097 return (EFI_SUCCESS);\r
1098 }\r
1099\r
1100 if (Handle == NULL) {\r
1101 return (EFI_INVALID_PARAMETER);\r
1102 }\r
1103\r
1104 Ascii = FALSE;\r
1105 AsciiBuffer = NULL;\r
1106\r
1107 Status = FileHandleGetPosition(Handle, &OriginalFilePosition);\r
1108 if (EFI_ERROR(Status)) {\r
1109 return Status;\r
1110 }\r
1111\r
1112 Status = FileHandleSetPosition(Handle, 0);\r
1113 if (EFI_ERROR(Status)) {\r
1114 return Status;\r
1115 }\r
1116\r
1117 Status = FileHandleGetSize(Handle, &FileSize);\r
1118 if (EFI_ERROR(Status)) {\r
1119 return Status;\r
1120 }\r
1121\r
1122 if (FileSize == 0) {\r
1123 Ascii = TRUE;\r
1124 } else {\r
1125 CharSize = sizeof (CHAR16);\r
1126 Status = FileHandleRead (Handle, &CharSize, &CharBuffer);\r
1127 ASSERT_EFI_ERROR (Status);\r
1128 if (CharBuffer == gUnicodeFileTag) {\r
1129 Ascii = FALSE;\r
1130 } else {\r
1131 Ascii = TRUE;\r
1132 }\r
1133 }\r
1134\r
1135 Status = FileHandleSetPosition(Handle, OriginalFilePosition);\r
1136 if (EFI_ERROR(Status)) {\r
1137 return Status;\r
1138 }\r
1139\r
1140 if (Ascii) {\r
1141 Size = ( StrSize(Buffer) / sizeof(CHAR16) ) * sizeof(CHAR8);\r
1142 AsciiBuffer = (CHAR8 *)AllocateZeroPool(Size);\r
1143 if (AsciiBuffer == NULL) {\r
1144 return EFI_OUT_OF_RESOURCES;\r
1145 }\r
1146 UnicodeStrToAsciiStrS (Buffer, AsciiBuffer, Size);\r
1147 for (Index = 0; Index < Size; Index++) {\r
1148 if ((AsciiBuffer[Index] & BIT7) != 0) {\r
1149 FreePool(AsciiBuffer);\r
1150 return EFI_INVALID_PARAMETER;\r
1151 }\r
1152 }\r
1153\r
1154 Size = AsciiStrSize(AsciiBuffer) - sizeof(CHAR8);\r
1155 Status = FileHandleWrite(Handle, &Size, AsciiBuffer);\r
1156 if (EFI_ERROR(Status)) {\r
1157 FreePool (AsciiBuffer);\r
1158 return (Status);\r
1159 }\r
1160 Size = AsciiStrSize("\r\n") - sizeof(CHAR8);\r
1161 Status = FileHandleWrite(Handle, &Size, "\r\n");\r
1162 } else {\r
1163 if (OriginalFilePosition == 0) {\r
1164 Status = FileHandleSetPosition (Handle, sizeof(CHAR16));\r
1165 if (EFI_ERROR(Status)) {\r
1166 return Status;\r
1167 }\r
1168 }\r
1169 Size = StrSize(Buffer) - sizeof(CHAR16);\r
1170 Status = FileHandleWrite(Handle, &Size, Buffer);\r
1171 if (EFI_ERROR(Status)) {\r
1172 return (Status);\r
1173 }\r
1174 Size = StrSize(L"\r\n") - sizeof(CHAR16);\r
1175 Status = FileHandleWrite(Handle, &Size, L"\r\n");\r
1176 }\r
1177\r
1178 if (AsciiBuffer != NULL) {\r
1179 FreePool (AsciiBuffer);\r
1180 }\r
1181 return Status;\r
1182}\r
1183\r
1184/**\r
1185 function to take a formatted argument and print it to a file.\r
1186\r
1187 @param[in] Handle the file handle for the file to write to\r
1188 @param[in] Format the format argument (see printlib for format specifier)\r
1189 @param[in] ... the variable arguments for the format\r
1190\r
1191 @retval EFI_SUCCESS the operation was successful\r
1192 @return other a return value from FileHandleWriteLine\r
1193\r
1194 @sa FileHandleWriteLine\r
1195**/\r
1196EFI_STATUS\r
1197EFIAPI\r
1198FileHandlePrintLine(\r
1199 IN EFI_FILE_HANDLE Handle,\r
1200 IN CONST CHAR16 *Format,\r
1201 ...\r
1202 )\r
1203{\r
1204 VA_LIST Marker;\r
1205 CHAR16 *Buffer;\r
1206 EFI_STATUS Status;\r
1207\r
1208 //\r
1209 // Get a buffer to print into\r
1210 //\r
1211 Buffer = AllocateZeroPool (PcdGet16 (PcdUefiFileHandleLibPrintBufferSize));\r
1212 if (Buffer == NULL) {\r
1213 return (EFI_OUT_OF_RESOURCES);\r
1214 }\r
1215\r
1216 //\r
1217 // Print into our buffer\r
1218 //\r
1219 VA_START (Marker, Format);\r
1220 UnicodeVSPrint (Buffer, PcdGet16 (PcdUefiFileHandleLibPrintBufferSize), Format, Marker);\r
1221 VA_END (Marker);\r
1222\r
1223 //\r
1224 // Print buffer into file\r
1225 //\r
1226 Status = FileHandleWriteLine(Handle, Buffer);\r
1227\r
1228 //\r
1229 // Cleanup and return\r
1230 //\r
1231 FreePool(Buffer);\r
1232 return (Status);\r
1233}\r
1234\r
1235/**\r
1236 Function to determine if a FILE_HANDLE is at the end of the file.\r
1237\r
1238 This will NOT work on directories.\r
1239\r
1240 If Handle is NULL, then return False.\r
1241\r
1242 @param[in] Handle the file handle\r
1243\r
1244 @retval TRUE the position is at the end of the file\r
1245 @retval FALSE the position is not at the end of the file\r
1246**/\r
1247BOOLEAN\r
1248EFIAPI\r
1249FileHandleEof(\r
1250 IN EFI_FILE_HANDLE Handle\r
1251 )\r
1252{\r
1253 EFI_FILE_INFO *Info;\r
1254 UINT64 Pos;\r
1255 BOOLEAN RetVal;\r
1256\r
1257 if (Handle == NULL) {\r
1258 return (FALSE);\r
1259 }\r
1260\r
1261 FileHandleGetPosition(Handle, &Pos);\r
1262 Info = FileHandleGetInfo (Handle);\r
1263\r
1264 if (Info == NULL) {\r
1265 return (FALSE);\r
1266 }\r
1267\r
1268 FileHandleSetPosition(Handle, Pos);\r
1269\r
1270 if (Pos == Info->FileSize) {\r
1271 RetVal = TRUE;\r
1272 } else {\r
1273 RetVal = FALSE;\r
1274 }\r
1275\r
1276 FreePool (Info);\r
1277\r
1278 return (RetVal);\r
1279}\r