39 EFI_FILE_PROTOCOL_REVISION,
77 EFI_SECTION_TYPE SectionType;
78 UINT32 AuthenticationStatus;
81 for (SectionType =
EFI_SECTION_PE32; SectionType <= EFI_SECTION_TE; SectionType++) {
82 Status = FvProtocol->ReadSection (
84 &FvFileInfo->NameGuid,
91 if (Status != EFI_NOT_FOUND) {
116 UINT32 AuthenticationStatus;
117 EFI_FV_FILETYPE FoundType;
129 IgnoredPtr = &IgnoredByte;
130 FvFileInfo->FileInfo.FileSize = 0;
132 if (FV_FILETYPE_IS_EXECUTABLE (FvFileInfo->Type)) {
137 if (Status == EFI_WARN_BUFFER_TOO_SMALL) {
140 }
else if (FvFileInfo->Type == EFI_FV_FILETYPE_FREEFORM) {
144 Status = FvProtocol->ReadSection (
146 &FvFileInfo->NameGuid,
150 (
UINTN *)&FvFileInfo->FileInfo.FileSize,
151 &AuthenticationStatus
153 if (Status == EFI_WARN_BUFFER_TOO_SMALL) {
157 if (EFI_ERROR (Status)) {
161 return FvProtocol->ReadFile (
163 &FvFileInfo->NameGuid,
165 (
UINTN *)&FvFileInfo->FileInfo.FileSize,
168 &AuthenticationStatus
175 return FvProtocol->ReadFile (
177 &FvFileInfo->NameGuid,
179 (
UINTN *)&FvFileInfo->FileInfo.FileSize,
182 &AuthenticationStatus
221 UINT32 AuthenticationStatus;
222 EFI_FV_FILETYPE FoundType;
226 if (FV_FILETYPE_IS_EXECUTABLE (FvFileInfo->Type)) {
231 }
else if (FvFileInfo->Type == EFI_FV_FILETYPE_FREEFORM) {
235 Status = FvProtocol->ReadSection (
237 &FvFileInfo->NameGuid,
242 &AuthenticationStatus
244 if (EFI_ERROR (Status)) {
248 Status = FvProtocol->ReadFile (
250 &FvFileInfo->NameGuid,
255 &AuthenticationStatus
262 Status = FvProtocol->ReadFile (
264 &FvFileInfo->NameGuid,
269 &AuthenticationStatus
301 InfoSize = (
UINTN)FvFileInfo->FileInfo.Size;
302 if (*BufferSize < InfoSize) {
303 *BufferSize = InfoSize;
304 return EFI_BUFFER_TOO_SMALL;
312 *BufferSize = InfoSize;
338 for ( Walker = Path, LastSlash =
NULL
339 ; Walker !=
NULL && *Walker != CHAR_NULL
343 if ((*Walker == L
'\\') && (*(Walker + 1) != CHAR_NULL)) {
344 LastSlash = Walker + 1;
348 if (LastSlash !=
NULL) {
349 *LastSlash = CHAR_NULL;
388 for (TempString = Path; (TempString !=
NULL) && (*TempString != CHAR_NULL); TempString++) {
389 if (*TempString == L
'/') {
397 while ((TempString =
StrStr (Path, L
"\\..\\")) !=
NULL) {
398 *TempString = CHAR_NULL;
401 TempSize =
StrSize (TempString);
405 if (((TempString =
StrStr (Path, L
"\\..")) !=
NULL) && (*(TempString + 3) == CHAR_NULL)) {
406 *TempString = CHAR_NULL;
413 while ((TempString =
StrStr (Path, L
"\\.\\")) !=
NULL) {
414 *TempString = CHAR_NULL;
416 TempSize =
StrSize (TempString);
420 if (((TempString =
StrStr (Path, L
"\\.")) !=
NULL) && (*(TempString + 2) == CHAR_NULL)) {
421 *(TempString + 1) = CHAR_NULL;
424 while ((TempString =
StrStr (Path, L
"\\\\")) !=
NULL) {
425 *TempString = CHAR_NULL;
427 TempSize =
StrSize (TempString);
431 if (((TempString =
StrStr (Path, L
"\\\\")) !=
NULL) && (*(TempString + 1) == CHAR_NULL)) {
432 *(TempString) = CHAR_NULL;
484 UINTN FileNameLength;
485 UINTN NewFileNameLength;
486 CHAR16 *FileNameWithExtension;
492 case EFI_FILE_MODE_READ:
496 return EFI_WRITE_PROTECTED;
499 File = FVFS_FILE_FROM_FILE_THIS (This);
500 Instance = File->Instance;
503 if (FileName ==
NULL) {
504 return EFI_INVALID_PARAMETER;
507 if (FileName[0] == L
'\\') {
514 if ((
StrCmp (FileName, L
".") == 0) || (
StrCmp (FileName, L
"") == 0)) {
516 if (NewFile ==
NULL) {
517 return EFI_OUT_OF_RESOURCES;
520 NewFile->Signature = FVFS_FILE_SIGNATURE;
521 NewFile->Instance = Instance;
522 NewFile->FvFileInfo = File->FvFileInfo;
523 CopyMem (&NewFile->FileProtocol, &mFileSystemTemplate, sizeof (mFileSystemTemplate));
527 NewFile->DirReadNext =
NULL;
529 NewFile->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance);
532 *NewHandle = &NewFile->FileProtocol;
539 Status = EFI_NOT_FOUND;
541 for (FvFileInfoLink =
GetFirstNode (&Instance->FileInfoHead);
542 !
IsNull (&Instance->FileInfoHead, FvFileInfoLink);
543 FvFileInfoLink =
GetNextNode (&Instance->FileInfoHead, FvFileInfoLink))
545 FvFileInfo = FVFS_FILE_INFO_FROM_LINK (FvFileInfoLink);
546 if (mUnicodeCollation->StriColl (mUnicodeCollation, &FvFileInfo->FileInfo.
FileName[0], FileName) == 0) {
556 if (Status == EFI_NOT_FOUND) {
557 FileNameLength =
StrLen (FileName);
560 if (mUnicodeCollation->StriColl (mUnicodeCollation, FileName + FileNameLength - 4, L
".efi") != 0) {
563 NewFileNameLength = FileNameLength + 1 + 4;
564 FileNameWithExtension =
AllocatePool (NewFileNameLength * 2);
565 StrCpyS (FileNameWithExtension, NewFileNameLength, FileName);
566 StrCatS (FileNameWithExtension, NewFileNameLength, L
".EFI");
568 for (FvFileInfoLink =
GetFirstNode (&Instance->FileInfoHead);
569 !
IsNull (&Instance->FileInfoHead, FvFileInfoLink);
570 FvFileInfoLink =
GetNextNode (&Instance->FileInfoHead, FvFileInfoLink))
572 FvFileInfo = FVFS_FILE_INFO_FROM_LINK (FvFileInfoLink);
573 if (mUnicodeCollation->StriColl (mUnicodeCollation, &FvFileInfo->FileInfo.
FileName[0], FileNameWithExtension) == 0) {
581 if (!EFI_ERROR (Status)) {
583 if (NewFile ==
NULL) {
584 return EFI_OUT_OF_RESOURCES;
587 NewFile->Signature = FVFS_FILE_SIGNATURE;
588 NewFile->Instance = Instance;
589 NewFile->FvFileInfo = FvFileInfo;
590 CopyMem (&NewFile->FileProtocol, &mFileSystemTemplate, sizeof (mFileSystemTemplate));
594 *NewHandle = &NewFile->FileProtocol;
598 return EFI_NOT_FOUND;
619 File = FVFS_FILE_FROM_FILE_THIS (This);
620 Instance = File->Instance;
622 if (File != Instance->Root) {
665 File = FVFS_FILE_FROM_FILE_THIS (This);
666 Instance = File->Instance;
668 if (File->FvFileInfo == Instance->Root->FvFileInfo) {
669 if (File->DirReadNext) {
674 if (!EFI_ERROR (Status)) {
679 FvFileInfoLink =
GetNextNode (&Instance->FileInfoHead, &File->DirReadNext->Link);
680 if (
IsNull (&Instance->FileInfoHead, FvFileInfoLink)) {
684 File->DirReadNext =
NULL;
686 File->DirReadNext = FVFS_FILE_INFO_FROM_LINK (FvFileInfoLink);
703 if (FileBuffer ==
NULL) {
704 return EFI_DEVICE_ERROR;
707 Status =
FvFsReadFile (File->Instance->FvProtocol, File->FvFileInfo, &FileSize, &FileBuffer);
708 if (EFI_ERROR (Status)) {
710 return EFI_DEVICE_ERROR;
713 if (*BufferSize + File->Position > FileSize) {
714 *BufferSize = (
UINTN)(FileSize - File->Position);
717 CopyMem (Buffer, (UINT8 *)FileBuffer + File->Position, *BufferSize);
718 File->Position += *BufferSize;
757 File = FVFS_FILE_FROM_FILE_THIS (This);
758 Instance = File->Instance;
760 if (File->FvFileInfo == Instance->Root->FvFileInfo) {
761 return EFI_UNSUPPORTED;
763 return EFI_WRITE_PROTECTED;
789 File = FVFS_FILE_FROM_FILE_THIS (This);
790 Instance = File->Instance;
792 if (File->FvFileInfo == Instance->Root->FvFileInfo) {
793 return EFI_UNSUPPORTED;
795 *Position = File->Position;
823 File = FVFS_FILE_FROM_FILE_THIS (This);
824 Instance = File->Instance;
826 if (File->FvFileInfo == Instance->Root->FvFileInfo) {
828 return EFI_UNSUPPORTED;
834 if (File->DirReadNext) {
835 File->DirReadNext = FVFS_GET_FIRST_FILE_INFO (Instance);
837 }
else if (Position == 0xFFFFFFFFFFFFFFFFull) {
838 File->Position = File->FvFileInfo->FileInfo.
FileSize;
840 File->Position = Position;
867 return EFI_WRITE_PROTECTED;
891 return EFI_WARN_DELETE_FAILURE;
930 File = FVFS_FILE_FROM_FILE_THIS (This);
932 if (
CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
936 Instance = File->Instance;
940 if (*BufferSize < Size) {
942 return EFI_BUFFER_TOO_SMALL;
954 Instance->VolumeLabel,
955 StrLen (Instance->VolumeLabel)
958 FsInfoOut->
Size = Size;
960 }
else if (
CompareGuid (InformationType, &gEfiFileInfoGuid)) {
965 }
else if (
CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
969 Instance = File->Instance;
971 if (*BufferSize < Size) {
973 return EFI_BUFFER_TOO_SMALL;
980 Instance->VolumeLabel,
981 StrLen (Instance->VolumeLabel)
986 return EFI_UNSUPPORTED;
1033 if (
CompareGuid (InformationType, &gEfiFileSystemInfoGuid) ||
1034 CompareGuid (InformationType, &gEfiFileInfoGuid) ||
1035 CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid))
1037 return EFI_WRITE_PROTECTED;
1040 return EFI_UNSUPPORTED;
BOOLEAN EFIAPI IsNull(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
LIST_ENTRY *EFIAPI GetNextNode(IN CONST LIST_ENTRY *List, IN CONST LIST_ENTRY *Node)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
LIST_ENTRY *EFIAPI InsertHeadList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI GetFirstNode(IN CONST LIST_ENTRY *List)
RETURN_STATUS EFIAPI StrCatS(IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
RETURN_STATUS EFIAPI StrnCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS FvFsGetFileInfo(IN FV_FILESYSTEM_FILE_INFO *FvFileInfo, IN OUT UINTN *BufferSize, OUT EFI_FILE_INFO *FileInfo)
EFI_STATUS FvFsReadFile(IN EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol, IN FV_FILESYSTEM_FILE_INFO *FvFileInfo, IN OUT UINTN *BufferSize, IN OUT VOID **Buffer)
EFI_STATUS EFIAPI FvSimpleFileSystemSetPosition(IN EFI_FILE_PROTOCOL *This, IN UINT64 Position)
EFI_STATUS FvFsFindExecutableSection(IN EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol, IN FV_FILESYSTEM_FILE_INFO *FvFileInfo, IN OUT UINTN *BufferSize, IN OUT VOID **Buffer)
EFI_STATUS EFIAPI FvSimpleFileSystemGetInfo(IN EFI_FILE_PROTOCOL *This, IN EFI_GUID *InformationType, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
CHAR16 *EFIAPI TrimFilePathToAbsolutePath(IN CHAR16 *Path)
EFI_STATUS EFIAPI FvSimpleFileSystemDelete(IN EFI_FILE_PROTOCOL *This)
EFI_STATUS EFIAPI FvSimpleFileSystemOpen(IN EFI_FILE_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **NewHandle, IN CHAR16 *FileName, IN UINT64 OpenMode, IN UINT64 Attributes)
EFI_STATUS EFIAPI FvSimpleFileSystemRead(IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
BOOLEAN EFIAPI RemoveLastItemFromPath(IN OUT CHAR16 *Path)
EFI_STATUS EFIAPI FvSimpleFileSystemSetInfo(IN EFI_FILE_PROTOCOL *This, IN EFI_GUID *InformationType, IN UINTN BufferSize, IN VOID *Buffer)
EFI_STATUS EFIAPI FvSimpleFileSystemGetPosition(IN EFI_FILE_PROTOCOL *This, OUT UINT64 *Position)
EFI_STATUS EFIAPI FvSimpleFileSystemWrite(IN EFI_FILE_PROTOCOL *This, IN OUT UINTN *BufferSize, IN VOID *Buffer)
EFI_STATUS EFIAPI FvSimpleFileSystemFlush(IN EFI_FILE_PROTOCOL *This)
EFI_STATUS FvFsGetFileSize(IN EFI_FIRMWARE_VOLUME2_PROTOCOL *FvProtocol, IN OUT FV_FILESYSTEM_FILE_INFO *FvFileInfo)
EFI_STATUS EFIAPI FvSimpleFileSystemClose(IN EFI_FILE_PROTOCOL *This)
#define OFFSET_OF(TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
UINT32 EFI_FV_FILE_ATTRIBUTES
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_FILE_INFO * FileInfo(IN EFI_FILE_HANDLE FHand)