2 Provides interface to EFI_FILE_HANDLE functionality.
4 Copyright (c) 2006 - 2009, Intel Corporation<BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <Protocol/SimpleFileSystem.h>
19 #include <Guid/FileInfo.h>
21 #include <Library/DebugLib.h>
22 #include <Library/MemoryAllocationLib.h>
23 #include <Library/BaseLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/FileHandleLib.h>
26 #include <Library/PcdLib.h>
27 #include <Library/PrintLib.h>
29 #define MAX_FILE_NAME_LEN 522 // (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)
30 #define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)
33 This function will retrieve the information about the file for the handle
34 specified and store it in allocated pool memory.
36 This function allocates a buffer to store the file's information. It is the
37 caller's responsibility to free the buffer
39 @param FileHandle The file handle of the file for which information is
42 @retval NULL information could not be retrieved.
44 @return the information about the file
49 IN EFI_FILE_HANDLE FileHandle
52 EFI_FILE_INFO
*pFileInfo
;
57 // ASSERT if FileHandle is NULL
59 ASSERT (FileHandle
!= NULL
);
62 // Get the required size to allocate
66 Status
= FileHandle
->GetInfo(FileHandle
,
71 // error is expected. getting size to allocate
73 ASSERT (Status
== EFI_BUFFER_TOO_SMALL
);
74 pFileInfo
= AllocateZeroPool(FileInfoSize
);
75 ASSERT (pFileInfo
!= NULL
);
77 // now get the information
79 Status
= FileHandle
->GetInfo(FileHandle
,
84 // if we got an error free the memory and return NULL
86 if (EFI_ERROR(Status
)) {
94 This function will set the information about the file for the opened handle
97 @param FileHandle The file handle of the file for which information
100 @param FileInfo The infotmation to set.
102 @retval EFI_SUCCESS The information was set.
103 @retval EFI_UNSUPPORTED The InformationType is not known.
104 @retval EFI_NO_MEDIA The device has no medium.
105 @retval EFI_DEVICE_ERROR The device reported an error.
106 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
107 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
108 @retval EFI_ACCESS_DENIED The file was opened read only.
109 @retval EFI_VOLUME_FULL The volume is full.
114 IN EFI_FILE_HANDLE FileHandle
,
115 IN CONST EFI_FILE_INFO
*FileInfo
120 // ASSERT if the FileHandle or FileInfo is NULL
122 ASSERT (FileHandle
!= NULL
);
123 ASSERT (FileInfo
!= NULL
);
128 return (FileHandle
->SetInfo(FileHandle
,
130 (UINTN
)FileInfo
->Size
,
131 (EFI_FILE_INFO
*)FileInfo
));
135 This function reads information from an opened file.
137 If FileHandle is not a directory, the function reads the requested number of
138 bytes from the file at the file's current position and returns them in Buffer.
139 If the read goes beyond the end of the file, the read length is truncated to the
140 end of the file. The file's current position is increased by the number of bytes
141 returned. If FileHandle is a directory, the function reads the directory entry
142 at the file's current position and returns the entry in Buffer. If the Buffer
143 is not large enough to hold the current directory entry, then
144 EFI_BUFFER_TOO_SMALL is returned and the current file position is not updated.
145 BufferSize is set to be the size of the buffer needed to read the entry. On
146 success, the current position is updated to the next directory entry. If there
147 are no more directory entries, the read returns a zero-length buffer.
148 EFI_FILE_INFO is the structure returned as the directory entry.
150 @param FileHandle the opened file handle
151 @param BufferSize on input the size of buffer in bytes. on return
152 the number of bytes written.
153 @param Buffer the buffer to put read data into.
155 @retval EFI_SUCCESS Data was read.
156 @retval EFI_NO_MEDIA The device has no media.
157 @retval EFI_DEVICE_ERROR The device reported an error.
158 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
159 @retval EFI_BUFFER_TO_SMALL Buffer is too small. ReadSize contains required
166 IN EFI_FILE_HANDLE FileHandle
,
167 IN OUT UINTN
*BufferSize
,
172 // ASSERT if FileHandle is NULL
174 ASSERT (FileHandle
!= NULL
);
177 // Perform the read based on EFI_FILE_PROTOCOL
179 return (FileHandle
->Read(FileHandle
, BufferSize
, Buffer
));
184 Write data to a file.
186 This function writes the specified number of bytes to the file at the current
187 file position. The current file position is advanced the actual number of bytes
188 written, which is returned in BufferSize. Partial writes only occur when there
189 has been a data error during the write attempt (such as "volume space full").
190 The file is automatically grown to hold the data if required. Direct writes to
191 opened directories are not supported.
193 @param FileHandle The opened file for writing
194 @param BufferSize on input the number of bytes in Buffer. On output
195 the number of bytes written.
196 @param Buffer the buffer containing data to write is stored.
198 @retval EFI_SUCCESS Data was written.
199 @retval EFI_UNSUPPORTED Writes to an open directory are not supported.
200 @retval EFI_NO_MEDIA The device has no media.
201 @retval EFI_DEVICE_ERROR The device reported an error.
202 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
203 @retval EFI_WRITE_PROTECTED The device is write-protected.
204 @retval EFI_ACCESS_DENIED The file was open for read only.
205 @retval EFI_VOLUME_FULL The volume is full.
210 IN EFI_FILE_HANDLE FileHandle
,
211 IN OUT UINTN
*BufferSize
,
216 // ASSERT if FileHandle is NULL
218 ASSERT (FileHandle
!= NULL
);
220 // Perform the write based on EFI_FILE_PROTOCOL
222 return (FileHandle
->Write(FileHandle
, BufferSize
, Buffer
));
226 Close an open file handle.
228 This function closes a specified file handle. All "dirty" cached file data is
229 flushed to the device, and the file is closed. In all cases the handle is
232 @param FileHandle the file handle to close.
234 @retval EFI_SUCCESS the file handle was closed sucessfully.
239 IN EFI_FILE_HANDLE FileHandle
244 // ASSERT if FileHandle is NULL
246 ASSERT (FileHandle
!= NULL
);
248 // Perform the Close based on EFI_FILE_PROTOCOL
250 Status
= FileHandle
->Close(FileHandle
);
255 Delete a file and close the handle
257 This function closes and deletes a file. In all cases the file handle is closed.
258 If the file cannot be deleted, the warning code EFI_WARN_DELETE_FAILURE is
259 returned, but the handle is still closed.
261 @param FileHandle the file handle to delete
263 @retval EFI_SUCCESS the file was closed sucessfully
264 @retval EFI_WARN_DELETE_FAILURE the handle was closed, but the file was not
266 @retval INVALID_PARAMETER One of the parameters has an invalid value.
271 IN EFI_FILE_HANDLE FileHandle
276 // ASSERT if FileHandle is NULL
278 ASSERT (FileHandle
!= NULL
);
280 // Perform the Delete based on EFI_FILE_PROTOCOL
282 Status
= FileHandle
->Delete(FileHandle
);
287 Set the current position in a file.
289 This function sets the current file position for the handle to the position
290 supplied. With the exception of seeking to position 0xFFFFFFFFFFFFFFFF, only
291 absolute positioning is supported, and seeking past the end of the file is
292 allowed (a subsequent write would grow the file). Seeking to position
293 0xFFFFFFFFFFFFFFFF causes the current position to be set to the end of the file.
294 If FileHandle is a directory, the only position that may be set is zero. This
295 has the effect of starting the read process of the directory entries over.
297 @param FileHandle The file handle on which the position is being set
298 @param Position Byte position from begining of file
300 @retval EFI_SUCCESS Operation completed sucessfully.
301 @retval EFI_UNSUPPORTED the seek request for non-zero is not valid on
303 @retval INVALID_PARAMETER One of the parameters has an invalid value.
307 FileHandleSetPosition (
308 IN EFI_FILE_HANDLE FileHandle
,
313 // ASSERT if FileHandle is NULL
315 ASSERT (FileHandle
!= NULL
);
317 // Perform the SetPosition based on EFI_FILE_PROTOCOL
319 return (FileHandle
->SetPosition(FileHandle
, Position
));
323 Gets a file's current position
325 This function retrieves the current file position for the file handle. For
326 directories, the current file position has no meaning outside of the file
327 system driver and as such the operation is not supported. An error is returned
328 if FileHandle is a directory.
330 @param FileHandle The open file handle on which to get the position.
331 @param Position Byte position from begining of file.
333 @retval EFI_SUCCESS the operation completed sucessfully.
334 @retval INVALID_PARAMETER One of the parameters has an invalid value.
335 @retval EFI_UNSUPPORTED the request is not valid on directories.
339 FileHandleGetPosition (
340 IN EFI_FILE_HANDLE FileHandle
,
345 // ASSERT if FileHandle is NULL
347 ASSERT (FileHandle
!= NULL
);
349 // Perform the GetPosition based on EFI_FILE_PROTOCOL
351 return (FileHandle
->GetPosition(FileHandle
, Position
));
354 Flushes data on a file
356 This function flushes all modified data associated with a file to a device.
358 @param FileHandle The file handle on which to flush data
360 @retval EFI_SUCCESS The data was flushed.
361 @retval EFI_NO_MEDIA The device has no media.
362 @retval EFI_DEVICE_ERROR The device reported an error.
363 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
364 @retval EFI_WRITE_PROTECTED The file or medium is write protected.
365 @retval EFI_ACCESS_DENIED The file was opened for read only.
370 IN EFI_FILE_HANDLE FileHandle
374 // ASSERT if FileHandle is NULL
376 ASSERT (FileHandle
!= NULL
);
378 // Perform the Flush based on EFI_FILE_PROTOCOL
380 return (FileHandle
->Flush(FileHandle
));
384 function to determine if a given handle is a directory handle
386 if DirHandle is NULL then ASSERT()
388 open the file information on the DirHandle and verify that the Attribute
389 includes EFI_FILE_DIRECTORY bit set.
391 @param DirHandle Handle to open file
393 @retval EFI_SUCCESS DirHandle is a directory
394 @retval EFI_INVALID_PARAMETER DirHandle did not have EFI_FILE_INFO available
395 @retval EFI_NOT_FOUND DirHandle is not a directory
399 FileHandleIsDirectory (
400 IN EFI_FILE_HANDLE DirHandle
403 EFI_FILE_INFO
*DirInfo
;
406 // ASSERT if DirHandle is NULL
408 ASSERT(DirHandle
!= NULL
);
411 // get the file information for DirHandle
413 DirInfo
= FileHandleGetInfo (DirHandle
);
418 if (DirInfo
== NULL
) {
422 return (EFI_INVALID_PARAMETER
);
424 if ((DirInfo
->Attribute
& EFI_FILE_DIRECTORY
) == 0) {
426 // Attributes say this is not a directory
429 return (EFI_NOT_FOUND
);
435 return (EFI_SUCCESS
);
439 Retrieves the first file from a directory
441 This function opens a directory and gets the first file's info in the
442 directory. Caller can use FileHandleFindNextFile() to get other files. When
443 complete the caller is responsible for calling FreePool() on Buffer.
445 @param DirHandle The file handle of the directory to search
446 @param Buffer Pointer to buffer for file's information
448 @retval EFI_SUCCESS Found the first file.
449 @retval EFI_NOT_FOUND Cannot find the directory.
450 @retval EFI_NO_MEDIA The device has no media.
451 @retval EFI_DEVICE_ERROR The device reported an error.
452 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
453 @return Others status of FileHandleGetInfo, FileHandleSetPosition,
458 FileHandleFindFirstFile (
459 IN EFI_FILE_HANDLE DirHandle
,
460 OUT EFI_FILE_INFO
**Buffer
469 ASSERT (DirHandle
!= NULL
);
470 ASSERT (Buffer
!= NULL
);
473 // verify that DirHandle is a directory
475 Status
= FileHandleIsDirectory(DirHandle
);
476 if (EFI_ERROR(Status
)) {
481 // reset to the begining of the directory
483 Status
= FileHandleSetPosition(DirHandle
, 0);
484 if (EFI_ERROR(Status
)) {
489 // Allocate a buffer sized to struct size + enough for the string at the end
491 BufferSize
= FIND_XXXXX_FILE_BUFFER_SIZE
;
492 *Buffer
= AllocateZeroPool(BufferSize
);
493 ASSERT (*Buffer
!= NULL
);
496 // read in the info about the first file
498 Status
= FileHandleRead (DirHandle
, &BufferSize
, *Buffer
);
499 ASSERT(Status
!= EFI_BUFFER_TOO_SMALL
);
500 if (EFI_ERROR(Status
)) {
505 return (EFI_SUCCESS
);
508 Retrieves the next file in a directory.
510 To use this function, caller must call the FileHandleFindFirstFile() to get the
511 first file, and then use this function get other files. This function can be
512 called for several times to get each file's information in the directory. If
513 the call of FileHandleFindNextFile() got the last file in the directory, the next
514 call of this function has no file to get. *NoFile will be set to TRUE and the
515 Buffer memory will be automatically freed.
517 @param DirHandle the file handle of the directory
518 @param Buffer pointer to buffer for file's information
519 @param NoFile pointer to boolean when last file is found
521 @retval EFI_SUCCESS Found the next file, or reached last file
522 @retval EFI_NO_MEDIA The device has no media.
523 @retval EFI_DEVICE_ERROR The device reported an error.
524 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
528 FileHandleFindNextFile(
529 IN EFI_FILE_HANDLE DirHandle
,
530 OUT EFI_FILE_INFO
*Buffer
,
538 // ASSERTs for DirHandle or Buffer or NoFile poitners being NULL
540 ASSERT (DirHandle
!= NULL
);
541 ASSERT (Buffer
!= NULL
);
542 ASSERT (NoFile
!= NULL
);
545 // This BufferSize MUST stay equal to the originally allocated one in GetFirstFile
547 BufferSize
= FIND_XXXXX_FILE_BUFFER_SIZE
;
550 // read in the info about the next file
552 Status
= FileHandleRead (DirHandle
, &BufferSize
, Buffer
);
553 ASSERT(Status
!= EFI_BUFFER_TOO_SMALL
);
554 if (EFI_ERROR(Status
)) {
559 // If we read 0 bytes (but did not have erros) we already read in the last file.
561 if (BufferSize
== 0) {
566 return (EFI_SUCCESS
);
569 Retrieve the size of a file.
571 if FileHandle is NULL then ASSERT()
572 if Size is NULL then ASSERT()
574 This function extracts the file size info from the FileHandle's EFI_FILE_INFO
577 @param FileHandle file handle from which size is retrieved
578 @param Size pointer to size
580 @retval EFI_SUCCESS operation was completed sucessfully
581 @retval EFI_DEVICE_ERROR cannot access the file
586 IN EFI_FILE_HANDLE FileHandle
,
590 EFI_FILE_INFO
*FileInfo
;
593 // ASSERT for FileHandle or Size being NULL
595 ASSERT (FileHandle
!= NULL
);
596 ASSERT (Size
!= NULL
);
599 // get the FileInfo structure
601 FileInfo
= FileHandleGetInfo(FileHandle
);
602 if (FileInfo
== NULL
) {
603 return (EFI_DEVICE_ERROR
);
607 // Assign the Size pointer to the correct value
609 *Size
= FileInfo
->FileSize
;
612 // free the FileInfo memory
616 return (EFI_SUCCESS
);
621 Safely append (on the left) with automatic string resizing given length of Destination and
622 desired length of copy from Source.
624 append the first D characters of Source to the end of Destination, where D is
625 the lesser of Count and the StrLen() of Source. If appending those D characters
626 will fit within Destination (whose Size is given as CurrentSize) and
627 still leave room for a null terminator, then those characters are appended,
628 starting at the original terminating null of Destination, and a new terminating
631 If appending D characters onto Destination will result in a overflow of the size
632 given in CurrentSize the string will be grown such that the copy can be performed
633 and CurrentSize will be updated to the new size.
635 If Source is NULL, there is nothing to append, just return the current buffer in
638 if Destination is NULL, then ASSERT()
639 if Destination's current length (including NULL terminator) is already more then
640 CurrentSize, then ASSERT()
642 @param[in,out] Destination The String to append onto
643 @param[in,out] CurrentSize on call the number of bytes in Destination. On
644 return possibly the new size (still in bytes). if NULL
645 then allocate whatever is needed.
646 @param[in] Source The String to append from
647 @param[in] Count Maximum number of characters to append. if 0 then
650 @return Destination return the resultant string.
655 IN OUT CHAR16
**Destination
,
656 IN OUT UINTN
*CurrentSize
,
657 IN CONST CHAR16
*Source
,
660 UINTN DestinationStartSize
;
667 ASSERT(Destination
!= NULL
);
670 // If there's nothing to do then just return Destination
672 if (Source
== NULL
) {
673 return (*Destination
);
677 // allow for NULL pointers address as Destination
679 if (*Destination
!= NULL
) {
680 ASSERT(CurrentSize
!= 0);
681 DestinationStartSize
= StrSize(*Destination
);
682 ASSERT(DestinationStartSize
<= *CurrentSize
);
684 DestinationStartSize
= 0;
685 // ASSERT(*CurrentSize == 0);
689 // Append all of Source?
692 Count
= StrSize(Source
);
696 // Test and grow if required
698 if (CurrentSize
!= NULL
) {
699 NewSize
= *CurrentSize
;
700 while (NewSize
< (DestinationStartSize
+ Count
)) {
701 NewSize
+= 2 * Count
;
703 *Destination
= ReallocatePool(*CurrentSize
, NewSize
, *Destination
);
704 *CurrentSize
= NewSize
;
706 *Destination
= AllocateZeroPool(Count
+sizeof(CHAR16
));
709 CopySize
= StrSize(*Destination
);
710 CopyMem((*Destination
)+((Count
-2)/sizeof(CHAR16
)), *Destination
, CopySize
);
711 CopyMem(*Destination
, Source
, Count
-2);
712 return (*Destination
);
716 Function to get a full filename given a EFI_FILE_HANDLE somewhere lower on the
719 if Handle is NULL, return EFI_INVALID_PARAMETER
721 @param[in] Handle Handle to the Directory or File to create path to.
722 @param[out] FullFileName pointer to pointer to generated full file name. It
723 is the responsibility of the caller to free this memory
724 with a call to FreePool().
725 @retval EFI_SUCCESS the operation was sucessful and the FullFileName is valid.
726 @retval EFI_INVALID_PARAMETER Handle was NULL.
727 @retval EFI_INVALID_PARAMETER FullFileName was NULL.
728 @retval EFI_OUT_OF_RESOURCES a memory allocation failed.
732 FileHandleGetFileName (
733 IN CONST EFI_FILE_HANDLE Handle
,
734 OUT CHAR16
**FullFileName
738 EFI_FILE_HANDLE CurrentHandle
;
739 EFI_FILE_HANDLE NextHigherHandle
;
740 EFI_FILE_INFO
*FileInfo
;
745 // Check our parameters
747 if (FullFileName
== NULL
|| Handle
== NULL
) {
748 return (EFI_INVALID_PARAMETER
);
751 *FullFileName
= NULL
;
753 Status
= Handle
->Open(Handle
, &CurrentHandle
, L
".", EFI_FILE_MODE_READ
, 0);
754 if (!EFI_ERROR(Status
)) {
756 // Reverse out the current directory on the device
759 FileInfo
= FileHandleGetInfo(CurrentHandle
);
760 if (FileInfo
== NULL
) {
761 Status
= EFI_OUT_OF_RESOURCES
;
765 // We got info... do we have a name? if yes preceed the current path with it...
767 if (StrLen (FileInfo
->FileName
) == 0) {
768 if (*FullFileName
== NULL
) {
769 *FullFileName
= StrnCatGrowLeft(FullFileName
, &Size
, L
"\\", 0);
774 if (*FullFileName
== NULL
) {
775 *FullFileName
= StrnCatGrowLeft(FullFileName
, &Size
, L
"\\", 0);
777 *FullFileName
= StrnCatGrowLeft(FullFileName
, &Size
, FileInfo
->FileName
, 0);
778 *FullFileName
= StrnCatGrowLeft(FullFileName
, &Size
, L
"\\", 0);
783 // Move to the parent directory
785 Status
= CurrentHandle
->Open (CurrentHandle
, &NextHigherHandle
, L
"..", EFI_FILE_MODE_READ
, 0);
786 if (EFI_ERROR (Status
)) {
790 FileHandleClose(CurrentHandle
);
791 CurrentHandle
= NextHigherHandle
;
795 if (CurrentHandle
!= NULL
) {
796 CurrentHandle
->Close (CurrentHandle
);
799 if (EFI_ERROR(Status
) && *FullFileName
!= NULL
) {
800 FreePool(*FullFileName
);
807 Function to read a single line from a file. The \n is not included in the returned
808 buffer. The returned buffer must be callee freed.
810 If the position upon start is 0, then the Ascii Boolean will be set. This should be
811 maintained and not changed for all operations with the same file.
813 @param[in] Handle FileHandle to read from.
814 @param[in,out] Ascii Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);
816 @return The line of text from the file.
818 @sa FileHandleReadLine
822 FileHandleReturnLine(
823 IN EFI_FILE_HANDLE Handle
,
824 IN OUT BOOLEAN
*Ascii
834 Status
= FileHandleReadLine(Handle
, RetVal
, &Size
, FALSE
, Ascii
);
835 if (Status
== EFI_BUFFER_TOO_SMALL
) {
836 RetVal
= AllocatePool(Size
);
837 Status
= FileHandleReadLine(Handle
, RetVal
, &Size
, FALSE
, Ascii
);
839 ASSERT_EFI_ERROR(Status
);
840 if (EFI_ERROR(Status
) && (RetVal
!= NULL
)) {
848 Function to read a single line (up to but not including the \n) from a file.
850 If the position upon start is 0, then the Ascii Boolean will be set. This should be
851 maintained and not changed for all operations with the same file.
853 @param[in] Handle FileHandle to read from
854 @param[in,out] Buffer pointer to buffer to read into
855 @param[in,out] Size pointer to number of bytes in buffer
856 @param[in] Truncate if TRUE then allows for truncation of the line to fit.
857 if FALSE will reset the position to the begining of the
858 line if the buffer is not large enough.
859 @param[in,out] Ascii Boolean value for indicating whether the file is Ascii (TRUE) or UCS2 (FALSE);
861 @retval EFI_SUCCESS the operation was sucessful. the line is stored in
863 @retval EFI_INVALID_PARAMETER Handle was NULL.
864 @retval EFI_INVALID_PARAMETER Size was NULL.
865 @retval EFI_BUFFER_TOO_SMALL Size was not enough space to store the line.
866 Size was updated to minimum space required.
872 IN EFI_FILE_HANDLE Handle
,
873 IN OUT CHAR16
*Buffer
,
876 IN OUT BOOLEAN
*Ascii
882 UINT64 OriginalFilePosition
;
888 return (EFI_INVALID_PARAMETER
);
890 FileHandleGetPosition(Handle
, &OriginalFilePosition
);
891 if (OriginalFilePosition
== 0) {
892 CharSize
= sizeof(CHAR16
);
893 Status
= FileHandleRead(Handle
, &CharSize
, &CharBuffer
);
894 ASSERT_EFI_ERROR(Status
);
895 if (CharBuffer
== UnicodeFileTag
) {
899 FileHandleSetPosition(Handle
, OriginalFilePosition
);
903 for (CountSoFar
= 0;;CountSoFar
++){
906 CharSize
= sizeof(CHAR8
);
908 CharSize
= sizeof(CHAR16
);
910 Status
= FileHandleRead(Handle
, &CharSize
, &CharBuffer
);
911 if (OriginalFilePosition
== 0 && *Ascii
== FALSE
&& CountSoFar
== 0) {
913 // we need to skip the unicode tag
917 if ( EFI_ERROR(Status
)
919 || (CharBuffer
== L
'\n' && *Ascii
== FALSE
)
920 || (CharBuffer
== '\n' && *Ascii
!= FALSE
)
925 // if we have space save it...
927 if ((CountSoFar
+1)*sizeof(CHAR16
) < *Size
){
928 ASSERT(Buffer
!= NULL
);
929 ((CHAR16
*)Buffer
)[CountSoFar
] = CharBuffer
;
930 ((CHAR16
*)Buffer
)[CountSoFar
+1] = CHAR_NULL
;
935 // if we ran out of space tell when...
937 if ((CountSoFar
+1)*sizeof(CHAR16
) > *Size
){
938 *Size
= (CountSoFar
+1)*sizeof(CHAR16
);
939 if (Truncate
== FALSE
) {
940 FileHandleSetPosition(Handle
, OriginalFilePosition
);
942 DEBUG((DEBUG_WARN
, "The line was truncated in FileHandleReadLine"));
944 return (EFI_BUFFER_TOO_SMALL
);
946 while(Buffer
[StrLen(Buffer
)-1] == L
'\r') {
947 Buffer
[StrLen(Buffer
)-1] = CHAR_NULL
;
954 function to write a line of unicode text to a file.
956 if Handle is NULL, ASSERT.
957 if Buffer is NULL, do nothing. (return SUCCESS)
959 @param[in] Handle FileHandle to write to
960 @param[in] Buffer Buffer to write
962 @retval EFI_SUCCESS the data was written.
963 @retval other failure.
970 IN EFI_FILE_HANDLE Handle
,
976 ASSERT(Handle
!= NULL
);
978 if (Buffer
== NULL
) {
979 return (EFI_SUCCESS
);
982 Size
= StrLen(Buffer
);
983 Status
= FileHandleWrite(Handle
, &Size
, Buffer
);
984 if (EFI_ERROR(Status
)) {
987 Size
= StrLen(L
"\r\n");
988 return FileHandleWrite(Handle
, &Size
, L
"\r\n");
992 function to take a formatted argument and print it to a file.
994 @param[in] Handle the file handle for the file to write to
995 @param[in] Format the format argument (see printlib for format specifier)
996 @param[in] ... the variable arguments for the format
998 @retval EFI_SUCCESS the operation was sucessful
999 @return other a return value from FileHandleWriteLine
1001 @sa FileHandleWriteLine
1005 FileHandlePrintLine(
1006 IN EFI_FILE_HANDLE Handle
,
1007 IN CONST CHAR16
*Format
,
1015 VA_START (Marker
, Format
);
1018 // Get a buffer to print into
1020 Buffer
= AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize
));
1021 ASSERT (Buffer
!= NULL
);
1024 // Print into our buffer
1026 UnicodeVSPrint (Buffer
, PcdGet16 (PcdShellPrintBufferSize
), Format
, Marker
);
1029 // Print buffer into file
1031 Status
= FileHandleWriteLine(Handle
, Buffer
);
1034 // Cleanup and return
1041 Function to determine if a FILE_HANDLE is at the end of the file.
1043 This will NOT work on directories.
1045 If Handle is NULL, then ASSERT.
1047 @param[in] Handle the file handle
1049 @retval TRUE the position is at the end of the file
1050 @retval FALSE the position is not at the end of the file
1055 IN EFI_FILE_HANDLE Handle
1058 EFI_FILE_INFO
*Info
;
1063 // ASSERT if Handle is NULL
1065 ASSERT(Handle
!= NULL
);
1067 FileHandleGetPosition(Handle
, &Pos
);
1068 Info
= FileHandleGetInfo (Handle
);
1069 ASSERT(Info
!= NULL
);
1070 FileHandleSetPosition(Handle
, Pos
);
1076 if (Pos
== Info
->FileSize
) {