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 <olivier.mar...@arm.com>
---
 .../FvSimpleFileSystemDxe/FvSimpleFileSystem.c     | 62 +++++++++++++++++-----
 1 file changed, 50 insertions(+), 12 deletions(-)

diff --git a/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c 
b/MdeModulePkg/Universal/FvSimpleFileSystemDxe/FvSimpleFileSystem.c
index b0e7dc3..c6137ac 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,26 +535,60 @@ 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;
-      }
+      Status = EFI_SUCCESS;
+      break;
+    }
+  }
 
-      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);
+  // 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;
+        }
+      }
+    }
+  }
 
-      *NewHandle = &NewFile->FileProtocol;
-      return EFI_SUCCESS;
+  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;
-- 
2.1.1


------------------------------------------------------------------------------
Don't Limit Your Business. Reach for the Cloud.
GigeNET's Cloud Solutions provide you with the tools and support that
you need to offload your IT needs and focus on growing your business.
Configured For All Businesses. Start Your Cloud Today.
https://www.gigenetcloud.com/
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to