TianoCore EDK2 master
Loading...
Searching...
No Matches
UefiFileHandleLib.c
Go to the documentation of this file.
1
9#include <Uefi.h>
10
13
14#include <Guid/FileInfo.h>
15
16#include <Library/DebugLib.h>
18#include <Library/BaseLib.h>
21#include <Library/PcdLib.h>
22#include <Library/PrintLib.h>
23
25
26#define MAX_FILE_NAME_LEN 522// (20 * (6+5+2))+1) unicode characters from EFI FAT spec (doubled for bytes)
27#define FIND_XXXXX_FILE_BUFFER_SIZE (SIZE_OF_EFI_FILE_INFO + MAX_FILE_NAME_LEN)
28
44EFIAPI
46 IN EFI_FILE_HANDLE FileHandle
47 )
48{
50 UINTN FileInfoSize;
51 EFI_STATUS Status;
52
53 if (FileHandle == NULL) {
54 return (NULL);
55 }
56
57 //
58 // Get the required size to allocate
59 //
60 FileInfoSize = 0;
61 FileInfo = NULL;
62 Status = FileHandle->GetInfo (
63 FileHandle,
64 &gEfiFileInfoGuid,
65 &FileInfoSize,
66 NULL
67 );
68 if (Status == EFI_BUFFER_TOO_SMALL) {
69 //
70 // error is expected. getting size to allocate
71 //
72 FileInfo = AllocateZeroPool (FileInfoSize);
73 if (FileInfo != NULL) {
74 //
75 // now get the information
76 //
77 Status = FileHandle->GetInfo (
78 FileHandle,
79 &gEfiFileInfoGuid,
80 &FileInfoSize,
82 );
83 //
84 // if we got an error free the memory and return NULL
85 //
86 if (EFI_ERROR (Status)) {
88 FileInfo = NULL;
89 }
90 }
91 }
92
93 return (FileInfo);
94}
95
116EFIAPI
118 IN EFI_FILE_HANDLE FileHandle,
120 )
121{
122 if ((FileHandle == NULL) || (FileInfo == NULL)) {
123 return (EFI_INVALID_PARAMETER);
124 }
125
126 //
127 // Set the info
128 //
129 return (FileHandle->SetInfo (
130 FileHandle,
131 &gEfiFileInfoGuid,
134 ));
135}
136
167EFIAPI
169 IN EFI_FILE_HANDLE FileHandle,
170 IN OUT UINTN *BufferSize,
171 OUT VOID *Buffer
172 )
173{
174 if (FileHandle == NULL) {
175 return (EFI_INVALID_PARAMETER);
176 }
177
178 //
179 // Perform the read based on EFI_FILE_PROTOCOL
180 //
181 return (FileHandle->Read (FileHandle, BufferSize, Buffer));
182}
183
209EFIAPI
211 IN EFI_FILE_HANDLE FileHandle,
212 IN OUT UINTN *BufferSize,
213 IN VOID *Buffer
214 )
215{
216 if (FileHandle == NULL) {
217 return (EFI_INVALID_PARAMETER);
218 }
219
220 //
221 // Perform the write based on EFI_FILE_PROTOCOL
222 //
223 return (FileHandle->Write (FileHandle, BufferSize, Buffer));
224}
225
238EFIAPI
240 IN EFI_FILE_HANDLE FileHandle
241 )
242{
243 EFI_STATUS Status;
244
245 if (FileHandle == NULL) {
246 return (EFI_INVALID_PARAMETER);
247 }
248
249 //
250 // Perform the Close based on EFI_FILE_PROTOCOL
251 //
252 Status = FileHandle->Close (FileHandle);
253 return Status;
254}
255
271EFIAPI
273 IN EFI_FILE_HANDLE FileHandle
274 )
275{
276 EFI_STATUS Status;
277
278 if (FileHandle == NULL) {
279 return (EFI_INVALID_PARAMETER);
280 }
281
282 //
283 // Perform the Delete based on EFI_FILE_PROTOCOL
284 //
285 Status = FileHandle->Delete (FileHandle);
286 return Status;
287}
288
309EFIAPI
311 IN EFI_FILE_HANDLE FileHandle,
312 IN UINT64 Position
313 )
314{
315 if (FileHandle == NULL) {
316 return (EFI_INVALID_PARAMETER);
317 }
318
319 //
320 // Perform the SetPosition based on EFI_FILE_PROTOCOL
321 //
322 return (FileHandle->SetPosition (FileHandle, Position));
323}
324
341EFIAPI
343 IN EFI_FILE_HANDLE FileHandle,
344 OUT UINT64 *Position
345 )
346{
347 if ((Position == NULL) || (FileHandle == NULL)) {
348 return (EFI_INVALID_PARAMETER);
349 }
350
351 //
352 // Perform the GetPosition based on EFI_FILE_PROTOCOL
353 //
354 return (FileHandle->GetPosition (FileHandle, Position));
355}
356
372EFIAPI
374 IN EFI_FILE_HANDLE FileHandle
375 )
376{
377 if (FileHandle == NULL) {
378 return (EFI_INVALID_PARAMETER);
379 }
380
381 //
382 // Perform the Flush based on EFI_FILE_PROTOCOL
383 //
384 return (FileHandle->Flush (FileHandle));
385}
386
401EFIAPI
403 IN EFI_FILE_HANDLE DirHandle
404 )
405{
406 EFI_FILE_INFO *DirInfo;
407
408 if (DirHandle == NULL) {
409 return (EFI_INVALID_PARAMETER);
410 }
411
412 //
413 // get the file information for DirHandle
414 //
415 DirInfo = FileHandleGetInfo (DirHandle);
416
417 //
418 // Parse DirInfo
419 //
420 if (DirInfo == NULL) {
421 //
422 // We got nothing...
423 //
424 return (EFI_INVALID_PARAMETER);
425 }
426
427 if ((DirInfo->Attribute & EFI_FILE_DIRECTORY) == 0) {
428 //
429 // Attributes say this is not a directory
430 //
431 FreePool (DirInfo);
432 return (EFI_NOT_FOUND);
433 }
434
435 //
436 // all good...
437 //
438 FreePool (DirInfo);
439 return (EFI_SUCCESS);
440}
441
465EFIAPI
467 IN EFI_FILE_HANDLE DirHandle,
468 OUT EFI_FILE_INFO **Buffer
469 )
470{
471 EFI_STATUS Status;
472 UINTN BufferSize;
473
474 if ((Buffer == NULL) || (DirHandle == NULL)) {
475 return (EFI_INVALID_PARAMETER);
476 }
477
478 //
479 // verify that DirHandle is a directory
480 //
481 Status = FileHandleIsDirectory (DirHandle);
482 if (EFI_ERROR (Status)) {
483 return (Status);
484 }
485
486 //
487 // Allocate a buffer sized to struct size + enough for the string at the end
488 //
489 BufferSize = FIND_XXXXX_FILE_BUFFER_SIZE;
490 *Buffer = AllocateZeroPool (BufferSize);
491 if (*Buffer == NULL) {
492 return (EFI_OUT_OF_RESOURCES);
493 }
494
495 //
496 // reset to the beginning of the directory
497 //
498 Status = FileHandleSetPosition (DirHandle, 0);
499 if (EFI_ERROR (Status)) {
500 FreePool (*Buffer);
501 *Buffer = NULL;
502 return (Status);
503 }
504
505 //
506 // read in the info about the first file
507 //
508 Status = FileHandleRead (DirHandle, &BufferSize, *Buffer);
509 ASSERT (Status != EFI_BUFFER_TOO_SMALL);
510 if (EFI_ERROR (Status) || (BufferSize == 0)) {
511 FreePool (*Buffer);
512 *Buffer = NULL;
513 if (BufferSize == 0) {
514 return (EFI_NOT_FOUND);
515 }
516
517 return (Status);
518 }
519
520 return (EFI_SUCCESS);
521}
522
542EFIAPI
544 IN EFI_FILE_HANDLE DirHandle,
545 OUT EFI_FILE_INFO *Buffer,
546 OUT BOOLEAN *NoFile
547 )
548{
549 EFI_STATUS Status;
550 UINTN BufferSize;
551
552 if ((DirHandle == NULL) || (Buffer == NULL) || (NoFile == NULL)) {
553 return (EFI_INVALID_PARAMETER);
554 }
555
556 //
557 // This BufferSize MUST stay equal to the originally allocated one in GetFirstFile
558 //
559 BufferSize = FIND_XXXXX_FILE_BUFFER_SIZE;
560
561 //
562 // read in the info about the next file
563 //
564 Status = FileHandleRead (DirHandle, &BufferSize, Buffer);
565 ASSERT (Status != EFI_BUFFER_TOO_SMALL);
566 if (EFI_ERROR (Status)) {
567 return (Status);
568 }
569
570 //
571 // If we read 0 bytes (but did not have erros) we already read in the last file.
572 //
573 if (BufferSize == 0) {
574 FreePool (Buffer);
575 *NoFile = TRUE;
576 }
577
578 return (EFI_SUCCESS);
579}
580
596EFIAPI
598 IN EFI_FILE_HANDLE FileHandle,
599 OUT UINT64 *Size
600 )
601{
603
604 if ((FileHandle == NULL) || (Size == NULL)) {
605 return (EFI_INVALID_PARAMETER);
606 }
607
608 //
609 // get the FileInfo structure
610 //
611 FileInfo = FileHandleGetInfo (FileHandle);
612 if (FileInfo == NULL) {
613 return (EFI_DEVICE_ERROR);
614 }
615
616 //
617 // Assign the Size pointer to the correct value
618 //
619 *Size = FileInfo->FileSize;
620
621 //
622 // free the FileInfo memory
623 //
625
626 return (EFI_SUCCESS);
627}
628
643EFIAPI
645 IN EFI_FILE_HANDLE FileHandle,
646 IN UINT64 Size
647 )
648{
650 EFI_STATUS Status;
651
652 if (FileHandle == NULL) {
653 return (EFI_INVALID_PARAMETER);
654 }
655
656 //
657 // get the FileInfo structure
658 //
659 FileInfo = FileHandleGetInfo (FileHandle);
660 if (FileInfo == NULL) {
661 return (EFI_DEVICE_ERROR);
662 }
663
664 //
665 // Assign the FileSize pointer to the new value
666 //
667 FileInfo->FileSize = Size;
668
669 Status = FileHandleSetInfo (FileHandle, FileInfo);
670 //
671 // free the FileInfo memory
672 //
674
675 return (Status);
676}
677
710CHAR16 *
711EFIAPI
713 IN OUT CHAR16 **Destination,
714 IN OUT UINTN *CurrentSize,
715 IN CONST CHAR16 *Source,
716 IN UINTN Count
717 )
718{
719 UINTN DestinationStartSize;
720 UINTN NewSize;
721 UINTN CopySize;
722
723 if (Destination == NULL) {
724 return (NULL);
725 }
726
727 //
728 // If there's nothing to do then just return Destination
729 //
730 if (Source == NULL) {
731 return (*Destination);
732 }
733
734 //
735 // allow for NULL pointers address as Destination
736 //
737 if (*Destination != NULL) {
738 ASSERT (CurrentSize != 0);
739 DestinationStartSize = StrSize (*Destination);
740 ASSERT (DestinationStartSize <= *CurrentSize);
741 } else {
742 DestinationStartSize = 0;
743 // ASSERT(*CurrentSize == 0);
744 }
745
746 //
747 // Append all of Source?
748 //
749 if (Count == 0) {
750 Count = StrSize (Source);
751 }
752
753 //
754 // Test and grow if required
755 //
756 if (CurrentSize != NULL) {
757 NewSize = *CurrentSize;
758 while (NewSize < (DestinationStartSize + Count)) {
759 NewSize += 2 * Count;
760 }
761
762 *Destination = ReallocatePool (*CurrentSize, NewSize, *Destination);
763 *CurrentSize = NewSize;
764 } else {
765 *Destination = AllocateZeroPool (Count+sizeof (CHAR16));
766 }
767
768 if (*Destination == NULL) {
769 return NULL;
770 }
771
772 CopySize = StrSize (*Destination);
773 CopyMem ((*Destination)+((Count-2)/sizeof (CHAR16)), *Destination, CopySize);
774 CopyMem (*Destination, Source, Count-2);
775 return (*Destination);
776}
777
796EFIAPI
798 IN CONST EFI_FILE_HANDLE Handle,
799 OUT CHAR16 **FullFileName
800 )
801{
802 EFI_STATUS Status;
803 UINTN Size;
804 EFI_FILE_HANDLE CurrentHandle;
805 EFI_FILE_HANDLE NextHigherHandle;
807
808 Size = 0;
809
810 //
811 // Check our parameters
812 //
813 if ((FullFileName == NULL) || (Handle == NULL)) {
814 return (EFI_INVALID_PARAMETER);
815 }
816
817 *FullFileName = NULL;
818 CurrentHandle = NULL;
819
820 Status = Handle->Open (Handle, &CurrentHandle, L".", EFI_FILE_MODE_READ, 0);
821 if (!EFI_ERROR (Status)) {
822 //
823 // Reverse out the current directory on the device
824 //
825 for ( ; ;) {
826 FileInfo = FileHandleGetInfo (CurrentHandle);
827 if (FileInfo == NULL) {
828 Status = EFI_OUT_OF_RESOURCES;
829 break;
830 } else {
831 //
832 // Prepare to move to the parent directory.
833 // Also determine whether CurrentHandle refers to the Root directory.
834 //
835 Status = CurrentHandle->Open (CurrentHandle, &NextHigherHandle, L"..", EFI_FILE_MODE_READ, 0);
836 //
837 // We got info... do we have a name? if yes precede the current path with it...
838 //
839 if ((StrLen (FileInfo->FileName) == 0) || EFI_ERROR (Status)) {
840 //
841 // Both FileInfo->FileName being '\0' and EFI_ERROR() suggest that
842 // CurrentHandle refers to the Root directory. As this loop ensures
843 // FullFileName is starting with '\\' at all times, signal success
844 // and exit the loop.
845 // While FileInfo->FileName could theoretically be a value other than
846 // '\0' or '\\', '\\' is guaranteed to be supported by the
847 // specification and hence its value can safely be ignored.
848 //
849 Status = EFI_SUCCESS;
850 if (*FullFileName == NULL) {
851 ASSERT ((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
852 *FullFileName = StrnCatGrowLeft (FullFileName, &Size, L"\\", 0);
853 }
854
856 break;
857 } else {
858 if (*FullFileName == NULL) {
859 ASSERT ((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
860 *FullFileName = StrnCatGrowLeft (FullFileName, &Size, L"\\", 0);
861 }
862
863 ASSERT ((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
864 *FullFileName = StrnCatGrowLeft (FullFileName, &Size, FileInfo->FileName, 0);
865 *FullFileName = StrnCatGrowLeft (FullFileName, &Size, L"\\", 0);
867 }
868 }
869
870 FileHandleClose (CurrentHandle);
871 //
872 // Move to the parent directory
873 //
874 CurrentHandle = NextHigherHandle;
875 }
876 } else if (Status == EFI_NOT_FOUND) {
877 Status = EFI_SUCCESS;
878 ASSERT ((*FullFileName == NULL && Size == 0) || (*FullFileName != NULL));
879 *FullFileName = StrnCatGrowLeft (FullFileName, &Size, L"\\", 0);
880 }
881
882 if ((*FullFileName != NULL) &&
883 ((*FullFileName)[StrLen (*FullFileName) - 1] == L'\\') &&
884 (StrLen (*FullFileName) > 1) &&
885 (FileHandleIsDirectory (Handle) == EFI_NOT_FOUND)
886 )
887 {
888 (*FullFileName)[StrLen (*FullFileName) - 1] = CHAR_NULL;
889 }
890
891 if (CurrentHandle != NULL) {
892 CurrentHandle->Close (CurrentHandle);
893 }
894
895 if (EFI_ERROR (Status) && (*FullFileName != NULL)) {
896 FreePool (*FullFileName);
897 }
898
899 return (Status);
900}
901
916CHAR16 *
917EFIAPI
919 IN EFI_FILE_HANDLE Handle,
920 IN OUT BOOLEAN *Ascii
921 )
922{
923 CHAR16 *RetVal;
924 UINTN Size;
925 EFI_STATUS Status;
926
927 Size = 0;
928 RetVal = NULL;
929
930 Status = FileHandleReadLine (Handle, RetVal, &Size, FALSE, Ascii);
931 if (Status == EFI_BUFFER_TOO_SMALL) {
932 RetVal = AllocateZeroPool (Size);
933
934 if (RetVal == NULL) {
935 return NULL;
936 }
937
938 Status = FileHandleReadLine (Handle, RetVal, &Size, FALSE, Ascii);
939 }
940
941 ASSERT_EFI_ERROR (Status);
942 if (EFI_ERROR (Status) && (RetVal != NULL)) {
943 FreePool (RetVal);
944 RetVal = NULL;
945 }
946
947 return (RetVal);
948}
949
979EFIAPI
981 IN EFI_FILE_HANDLE Handle,
982 IN OUT CHAR16 *Buffer,
983 IN OUT UINTN *Size,
984 IN BOOLEAN Truncate,
985 IN OUT BOOLEAN *Ascii
986 )
987{
988 EFI_STATUS Status;
989 CHAR16 CharBuffer;
990 UINT64 FileSize;
991 UINTN CharSize;
992 UINTN CountSoFar;
993 UINTN CrCount;
994 UINTN OldSize;
995 UINT64 OriginalFilePosition;
996
997 if ( (Handle == NULL)
998 || (Size == NULL)
999 || ((Buffer == NULL) && (*Size != 0))
1000 )
1001 {
1002 return (EFI_INVALID_PARAMETER);
1003 }
1004
1005 if ((Buffer != NULL) && (*Size != 0)) {
1006 *Buffer = CHAR_NULL;
1007 }
1008
1009 Status = FileHandleGetSize (Handle, &FileSize);
1010 if (EFI_ERROR (Status)) {
1011 return Status;
1012 } else if (FileSize == 0) {
1013 *Ascii = TRUE;
1014 return EFI_SUCCESS;
1015 }
1016
1017 FileHandleGetPosition (Handle, &OriginalFilePosition);
1018 if (OriginalFilePosition == 0) {
1019 CharSize = sizeof (CHAR16);
1020 Status = FileHandleRead (Handle, &CharSize, &CharBuffer);
1021 ASSERT_EFI_ERROR (Status);
1022 if (CharBuffer == gUnicodeFileTag) {
1023 *Ascii = FALSE;
1024 } else {
1025 *Ascii = TRUE;
1026 FileHandleSetPosition (Handle, OriginalFilePosition);
1027 }
1028 }
1029
1030 CrCount = 0;
1031 for (CountSoFar = 0; ; CountSoFar++) {
1032 CharBuffer = 0;
1033 if (*Ascii) {
1034 CharSize = sizeof (CHAR8);
1035 } else {
1036 CharSize = sizeof (CHAR16);
1037 }
1038
1039 Status = FileHandleRead (Handle, &CharSize, &CharBuffer);
1040 if ( EFI_ERROR (Status)
1041 || (CharSize == 0)
1042 || ((CharBuffer == L'\n') && !(*Ascii))
1043 || ((CharBuffer == '\n') && *Ascii)
1044 )
1045 {
1046 break;
1047 } else if (
1048 ((CharBuffer == L'\r') && !(*Ascii)) ||
1049 ((CharBuffer == '\r') && *Ascii)
1050 )
1051 {
1052 CrCount++;
1053 continue;
1054 }
1055
1056 //
1057 // if we have space save it...
1058 //
1059 if ((CountSoFar+1-CrCount)*sizeof (CHAR16) < *Size) {
1060 ASSERT (Buffer != NULL);
1061 ((CHAR16 *)Buffer)[CountSoFar-CrCount] = CharBuffer;
1062 ((CHAR16 *)Buffer)[CountSoFar+1-CrCount] = CHAR_NULL;
1063 }
1064 }
1065
1066 //
1067 // if we ran out of space tell when...
1068 //
1069 if ((CountSoFar+1-CrCount)*sizeof (CHAR16) > *Size) {
1070 OldSize = *Size;
1071 *Size = (CountSoFar+1-CrCount)*sizeof (CHAR16);
1072 if (!Truncate) {
1073 if ((Buffer != NULL) && (OldSize != 0)) {
1074 ZeroMem (Buffer, OldSize);
1075 }
1076
1077 FileHandleSetPosition (Handle, OriginalFilePosition);
1078 return (EFI_BUFFER_TOO_SMALL);
1079 } else {
1080 DEBUG ((DEBUG_WARN, "The line was truncated in FileHandleReadLine"));
1081 return (EFI_SUCCESS);
1082 }
1083 }
1084
1085 return (Status);
1086}
1087
1110EFIAPI
1112 IN EFI_FILE_HANDLE Handle,
1113 IN CHAR16 *Buffer
1114 )
1115{
1116 EFI_STATUS Status;
1117 CHAR16 CharBuffer;
1118 UINTN Size;
1119 UINTN Index;
1120 UINTN CharSize;
1121 UINT64 FileSize;
1122 UINT64 OriginalFilePosition;
1123 BOOLEAN Ascii;
1124 CHAR8 *AsciiBuffer;
1125
1126 if (Buffer == NULL) {
1127 return (EFI_SUCCESS);
1128 }
1129
1130 if (Handle == NULL) {
1131 return (EFI_INVALID_PARAMETER);
1132 }
1133
1134 Ascii = FALSE;
1135 AsciiBuffer = NULL;
1136
1137 Status = FileHandleGetPosition (Handle, &OriginalFilePosition);
1138 if (EFI_ERROR (Status)) {
1139 return Status;
1140 }
1141
1142 Status = FileHandleSetPosition (Handle, 0);
1143 if (EFI_ERROR (Status)) {
1144 return Status;
1145 }
1146
1147 Status = FileHandleGetSize (Handle, &FileSize);
1148 if (EFI_ERROR (Status)) {
1149 return Status;
1150 }
1151
1152 if (FileSize == 0) {
1153 Ascii = TRUE;
1154 } else {
1155 CharSize = sizeof (CHAR16);
1156 Status = FileHandleRead (Handle, &CharSize, &CharBuffer);
1157 ASSERT_EFI_ERROR (Status);
1158 if (CharBuffer == gUnicodeFileTag) {
1159 Ascii = FALSE;
1160 } else {
1161 Ascii = TRUE;
1162 }
1163 }
1164
1165 Status = FileHandleSetPosition (Handle, OriginalFilePosition);
1166 if (EFI_ERROR (Status)) {
1167 return Status;
1168 }
1169
1170 if (Ascii) {
1171 Size = (StrSize (Buffer) / sizeof (CHAR16)) * sizeof (CHAR8);
1172 AsciiBuffer = (CHAR8 *)AllocateZeroPool (Size);
1173 if (AsciiBuffer == NULL) {
1174 return EFI_OUT_OF_RESOURCES;
1175 }
1176
1177 UnicodeStrToAsciiStrS (Buffer, AsciiBuffer, Size);
1178 for (Index = 0; Index < Size; Index++) {
1179 if ((AsciiBuffer[Index] & BIT7) != 0) {
1180 FreePool (AsciiBuffer);
1181 return EFI_INVALID_PARAMETER;
1182 }
1183 }
1184
1185 Size = AsciiStrSize (AsciiBuffer) - sizeof (CHAR8);
1186 Status = FileHandleWrite (Handle, &Size, AsciiBuffer);
1187 if (EFI_ERROR (Status)) {
1188 FreePool (AsciiBuffer);
1189 return (Status);
1190 }
1191
1192 Size = AsciiStrSize ("\r\n") - sizeof (CHAR8);
1193 Status = FileHandleWrite (Handle, &Size, "\r\n");
1194 } else {
1195 if (OriginalFilePosition == 0) {
1196 Status = FileHandleSetPosition (Handle, sizeof (CHAR16));
1197 if (EFI_ERROR (Status)) {
1198 return Status;
1199 }
1200 }
1201
1202 Size = StrSize (Buffer) - sizeof (CHAR16);
1203 Status = FileHandleWrite (Handle, &Size, Buffer);
1204 if (EFI_ERROR (Status)) {
1205 return (Status);
1206 }
1207
1208 Size = StrSize (L"\r\n") - sizeof (CHAR16);
1209 Status = FileHandleWrite (Handle, &Size, L"\r\n");
1210 }
1211
1212 if (AsciiBuffer != NULL) {
1213 FreePool (AsciiBuffer);
1214 }
1215
1216 return Status;
1217}
1218
1232EFIAPI
1234 IN EFI_FILE_HANDLE Handle,
1235 IN CONST CHAR16 *Format,
1236 ...
1237 )
1238{
1239 VA_LIST Marker;
1240 CHAR16 *Buffer;
1241 EFI_STATUS Status;
1242
1243 //
1244 // Get a buffer to print into
1245 //
1246 Buffer = AllocateZeroPool (PcdGet16 (PcdUefiFileHandleLibPrintBufferSize));
1247 if (Buffer == NULL) {
1248 return (EFI_OUT_OF_RESOURCES);
1249 }
1250
1251 //
1252 // Print into our buffer
1253 //
1254 VA_START (Marker, Format);
1255 UnicodeVSPrint (Buffer, PcdGet16 (PcdUefiFileHandleLibPrintBufferSize), Format, Marker);
1256 VA_END (Marker);
1257
1258 //
1259 // Print buffer into file
1260 //
1261 Status = FileHandleWriteLine (Handle, Buffer);
1262
1263 //
1264 // Cleanup and return
1265 //
1266 FreePool (Buffer);
1267 return (Status);
1268}
1269
1282BOOLEAN
1283EFIAPI
1285 IN EFI_FILE_HANDLE Handle
1286 )
1287{
1288 EFI_FILE_INFO *Info;
1289 UINT64 Pos;
1290 BOOLEAN RetVal;
1291
1292 if (Handle == NULL) {
1293 return (FALSE);
1294 }
1295
1296 FileHandleGetPosition (Handle, &Pos);
1297 Info = FileHandleGetInfo (Handle);
1298
1299 if (Info == NULL) {
1300 return (FALSE);
1301 }
1302
1303 FileHandleSetPosition (Handle, Pos);
1304
1305 if (Pos == Info->FileSize) {
1306 RetVal = TRUE;
1307 } else {
1308 RetVal = FALSE;
1309 }
1310
1311 FreePool (Info);
1312
1313 return (RetVal);
1314}
UINT64 UINTN
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
RETURN_STATUS EFIAPI UnicodeStrToAsciiStrS(IN CONST CHAR16 *Source, OUT CHAR8 *Destination, IN UINTN DestMax)
Definition: SafeString.c:2650
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
Definition: String.c:681
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI ReallocatePool(IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI UnicodeVSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString, IN VA_LIST Marker)
Definition: PrintLib.c:287
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define VA_START(Marker, Parameter)
Definition: Base.h:661
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define VA_END(Marker)
Definition: Base.h:691
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PcdGet16(TokenName)
Definition: PcdLib.h:349
EFI_FILE_INFO * FileInfo(IN EFI_FILE_HANDLE FHand)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI FileHandleFlush(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI FileHandleGetFileName(IN CONST EFI_FILE_HANDLE Handle, OUT CHAR16 **FullFileName)
EFI_STATUS EFIAPI FileHandleWriteLine(IN EFI_FILE_HANDLE Handle, IN CHAR16 *Buffer)
EFI_STATUS EFIAPI FileHandlePrintLine(IN EFI_FILE_HANDLE Handle, IN CONST CHAR16 *Format,...)
EFI_STATUS EFIAPI FileHandleSetInfo(IN EFI_FILE_HANDLE FileHandle, IN CONST EFI_FILE_INFO *FileInfo)
CHAR16 *EFIAPI StrnCatGrowLeft(IN OUT CHAR16 **Destination, IN OUT UINTN *CurrentSize, IN CONST CHAR16 *Source, IN UINTN Count)
BOOLEAN EFIAPI FileHandleEof(IN EFI_FILE_HANDLE Handle)
EFI_STATUS EFIAPI FileHandleGetPosition(IN EFI_FILE_HANDLE FileHandle, OUT UINT64 *Position)
EFI_STATUS EFIAPI FileHandleReadLine(IN EFI_FILE_HANDLE Handle, IN OUT CHAR16 *Buffer, IN OUT UINTN *Size, IN BOOLEAN Truncate, IN OUT BOOLEAN *Ascii)
EFI_STATUS EFIAPI FileHandleSetPosition(IN EFI_FILE_HANDLE FileHandle, IN UINT64 Position)
EFI_FILE_INFO *EFIAPI FileHandleGetInfo(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI FileHandleIsDirectory(IN EFI_FILE_HANDLE DirHandle)
EFI_STATUS EFIAPI FileHandleSetSize(IN EFI_FILE_HANDLE FileHandle, IN UINT64 Size)
EFI_STATUS EFIAPI FileHandleFindNextFile(IN EFI_FILE_HANDLE DirHandle, OUT EFI_FILE_INFO *Buffer, OUT BOOLEAN *NoFile)
EFI_STATUS EFIAPI FileHandleClose(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI FileHandleGetSize(IN EFI_FILE_HANDLE FileHandle, OUT UINT64 *Size)
CHAR16 *EFIAPI FileHandleReturnLine(IN EFI_FILE_HANDLE Handle, IN OUT BOOLEAN *Ascii)
EFI_STATUS EFIAPI FileHandleDelete(IN EFI_FILE_HANDLE FileHandle)
EFI_STATUS EFIAPI FileHandleFindFirstFile(IN EFI_FILE_HANDLE DirHandle, OUT EFI_FILE_INFO **Buffer)
EFI_STATUS EFIAPI FileHandleWrite(IN EFI_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, IN VOID *Buffer)
EFI_STATUS EFIAPI FileHandleRead(IN EFI_FILE_HANDLE FileHandle, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
CONST UINT16 gUnicodeFileTag
#define EFI_UNICODE_BYTE_ORDER_MARK
UINT64 Size
Definition: FileInfo.h:23
UINT64 Attribute
Definition: FileInfo.h:47
CHAR16 FileName[1]
Definition: FileInfo.h:52
UINT64 FileSize
Definition: FileInfo.h:27