From 1ca40fa9d979e3fe3b6c38a667456eff6c9d7efa Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Thu, 9 Jul 2015 10:34:27 +0000 Subject: [PATCH] MdeModulePkg/FvSimpleFileSystemDxe: Support file opening with no '.efi' FvSimpleFileSystem adds '.efi' to the EFI application and drivers filenames even through this extension is not present in the real filename of the EFI module. In the current behaviour, it would not be possible to open an EFI application using FvSimpleFileSystem if the extension has been omitted in the given filename. It can be create some confusion if someone wants to try to open a file with the real application name (eg: 'Shell'). This patch adds support to try again to look for the file with the extension if it had failed to find it without the extension. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Olivier Martin Reviewed-by: Feng Tian git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17903 6f19259b-4bc3-4df7-8a09-765794883524 --- .../FvSimpleFileSystem.c | 66 +++++++++++++++---- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c index b0e7dc302e..c6137aca1f 100644 --- a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c +++ b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c @@ -483,6 +483,10 @@ FvSimpleFileSystemOpen ( FV_FILESYSTEM_FILE *NewFile; FV_FILESYSTEM_FILE_INFO *FvFileInfo; LIST_ENTRY *FvFileInfoLink; + EFI_STATUS Status; + UINTN FileNameLength; + UINTN NewFileNameLength; + CHAR16 *FileNameWithExtension; // // Check for a valid mode @@ -531,28 +535,62 @@ FvSimpleFileSystemOpen ( // // Do a linear search for a file in the FV with a matching filename // + Status = EFI_NOT_FOUND; + FvFileInfo = NULL; for (FvFileInfoLink = GetFirstNode (&Instance->FileInfoHead); !IsNull (&Instance->FileInfoHead, FvFileInfoLink); FvFileInfoLink = GetNextNode (&Instance->FileInfoHead, FvFileInfoLink)) { FvFileInfo = FVFS_FILE_INFO_FROM_LINK (FvFileInfoLink); if (mUnicodeCollation->StriColl (mUnicodeCollation, &FvFileInfo->FileInfo.FileName[0], FileName) == 0) { - NewFile = AllocateZeroPool (sizeof (FV_FILESYSTEM_FILE)); - if (NewFile == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - NewFile->Signature = FVFS_FILE_SIGNATURE; - NewFile->Instance = Instance; - NewFile->FvFileInfo = FvFileInfo; - CopyMem (&NewFile->FileProtocol, &mFileSystemTemplate, sizeof (mFileSystemTemplate)); - InitializeListHead (&NewFile->Link); - InsertHeadList (&Instance->FileHead, &NewFile->Link); - - *NewHandle = &NewFile->FileProtocol; - return EFI_SUCCESS; + Status = EFI_SUCCESS; + break; } } + // If the file has not been found check if the filename exists with an extension + // in case there was no extension present. + // FvFileSystem adds a 'virtual' extension '.EFI' to EFI applications and drivers + // present in the Firmware Volume + if (Status == EFI_NOT_FOUND) { + FileNameLength = StrLen (FileName); + + // Does the filename already contain the '.EFI' extension? + if (mUnicodeCollation->StriColl (mUnicodeCollation, FileName + FileNameLength - 4, L".efi") != 0) { + // No, there was no extension. So add one and search again for the file + // NewFileNameLength = FileNameLength + 1 + 4 = (Number of non-null character) + (file extension) + (a null character) + NewFileNameLength = FileNameLength + 1 + 4; + FileNameWithExtension = AllocateCopyPool (NewFileNameLength * 2, FileName); + StrCatS (FileNameWithExtension, NewFileNameLength, L".EFI"); + + for (FvFileInfoLink = GetFirstNode (&Instance->FileInfoHead); + !IsNull (&Instance->FileInfoHead, FvFileInfoLink); + FvFileInfoLink = GetNextNode (&Instance->FileInfoHead, FvFileInfoLink)) { + FvFileInfo = FVFS_FILE_INFO_FROM_LINK (FvFileInfoLink); + if (mUnicodeCollation->StriColl (mUnicodeCollation, &FvFileInfo->FileInfo.FileName[0], FileNameWithExtension) == 0) { + Status = EFI_SUCCESS; + break; + } + } + } + } + + if (!EFI_ERROR (Status)) { + NewFile = AllocateZeroPool (sizeof (FV_FILESYSTEM_FILE)); + if (NewFile == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + NewFile->Signature = FVFS_FILE_SIGNATURE; + NewFile->Instance = Instance; + NewFile->FvFileInfo = FvFileInfo; + CopyMem (&NewFile->FileProtocol, &mFileSystemTemplate, sizeof (mFileSystemTemplate)); + InitializeListHead (&NewFile->Link); + InsertHeadList (&Instance->FileHead, &NewFile->Link); + + *NewHandle = &NewFile->FileProtocol; + return EFI_SUCCESS; + } + return EFI_NOT_FOUND; }