]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/FileSystem/BootMonFs/BootMonFsEntryPoint.c
ArmPlatformPkg/BootMonFs: eliminate deprecated string functions
[mirror_edk2.git] / ArmPlatformPkg / FileSystem / BootMonFs / BootMonFsEntryPoint.c
index 00f7c077ea65d04b86a13297403901463ccb1e4b..a1150856f6ba5eee61b0cee76e0e672ae823d020 100644 (file)
@@ -24,7 +24,6 @@
 #include "BootMonFsInternal.h"\r
 \r
 EFI_DEVICE_PATH* mBootMonFsSupportedDevicePaths;\r
-EFI_HANDLE       mImageHandle;\r
 LIST_ENTRY       mInstances;\r
 \r
 EFI_FILE_PROTOCOL mBootMonFsRootTemplate = {\r
@@ -55,6 +54,30 @@ EFI_FILE_PROTOCOL mBootMonFsFileTemplate = {
   BootMonFsFlushFile\r
 };\r
 \r
+/**\r
+  Search for a file given its name coded in Ascii.\r
+\r
+  When searching through the files of the volume, if a file is currently not\r
+  open, its name was written on the media and is kept in RAM in the\r
+  "HwDescription.Footer.Filename[]" field of the file's description.\r
+\r
+  If a file is currently open, its name might not have been written on the\r
+  media yet, and as the "HwDescription" is a mirror in RAM of what is on the\r
+  media the "HwDescription.Footer.Filename[]" might be outdated. In that case,\r
+  the up to date name of the file is stored in the "Info" field of the file's\r
+  description.\r
+\r
+  @param[in]   Instance       Pointer to the description of the volume in which\r
+                              the file has to be search for.\r
+  @param[in]   AsciiFileName  Name of the file.\r
+\r
+  @param[out]  File           Pointer to the description of the file if the\r
+                              file was found.\r
+\r
+  @retval  EFI_SUCCESS    The file was found.\r
+  @retval  EFI_NOT_FOUND  The file was not found.\r
+\r
+**/\r
 EFI_STATUS\r
 BootMonGetFileFromAsciiFileName (\r
   IN  BOOTMON_FS_INSTANCE   *Instance,\r
@@ -62,22 +85,27 @@ BootMonGetFileFromAsciiFileName (
   OUT BOOTMON_FS_FILE       **File\r
   )\r
 {\r
-  LIST_ENTRY        *Entry;\r
-  BOOTMON_FS_FILE   *FileEntry;\r
-\r
-  // Remove the leading '\\'\r
-  if (*AsciiFileName == '\\') {\r
-    AsciiFileName++;\r
-  }\r
+  LIST_ENTRY       *Entry;\r
+  BOOTMON_FS_FILE  *FileEntry;\r
+  CHAR8            OpenFileAsciiFileName[MAX_NAME_LENGTH];\r
+  CHAR8            *AsciiFileNameToCompare;\r
 \r
   // Go through all the files in the list and return the file handle\r
   for (Entry = GetFirstNode (&Instance->RootFile->Link);\r
-         !IsNull (&Instance->RootFile->Link, Entry);\r
-         Entry = GetNextNode (&Instance->RootFile->Link, Entry)\r
-         )\r
+       !IsNull (&Instance->RootFile->Link, Entry);\r
+       Entry = GetNextNode (&Instance->RootFile->Link, Entry)\r
+       )\r
   {\r
     FileEntry = BOOTMON_FS_FILE_FROM_LINK_THIS (Entry);\r
-    if (AsciiStrCmp (FileEntry->HwDescription.Footer.Filename, AsciiFileName) == 0) {\r
+    if (FileEntry->Info != NULL) {\r
+      UnicodeStrToAsciiStrS (FileEntry->Info->FileName, OpenFileAsciiFileName,\r
+        MAX_NAME_LENGTH);\r
+      AsciiFileNameToCompare = OpenFileAsciiFileName;\r
+    } else {\r
+      AsciiFileNameToCompare = FileEntry->HwDescription.Footer.Filename;\r
+    }\r
+\r
+    if (AsciiStrCmp (AsciiFileNameToCompare, AsciiFileName) == 0) {\r
       *File = FileEntry;\r
       return EFI_SUCCESS;\r
     }\r
@@ -217,7 +245,7 @@ BootMonFsDriverSupported (
                   ControllerHandle,\r
                   &gEfiDiskIoProtocolGuid,\r
                   (VOID **) &DiskIo,\r
-                  mImageHandle,\r
+                  gImageHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
@@ -231,7 +259,7 @@ BootMonFsDriverSupported (
   gBS->CloseProtocol (\r
          ControllerHandle,\r
          &gEfiDiskIoProtocolGuid,\r
-         mImageHandle,\r
+         gImageHandle,\r
          ControllerHandle\r
          );\r
 \r
@@ -240,7 +268,7 @@ BootMonFsDriverSupported (
                   ControllerHandle,\r
                   &gEfiBlockIoProtocolGuid,\r
                   NULL,\r
-                  mImageHandle,\r
+                  gImageHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
                   );\r
@@ -253,7 +281,7 @@ BootMonFsDriverSupported (
                   ControllerHandle,\r
                   &gEfiDevicePathProtocolGuid,\r
                   (VOID **)&DevicePathProtocol,\r
-                  mImageHandle,\r
+                  gImageHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
@@ -277,7 +305,7 @@ BootMonFsDriverSupported (
     }\r
   }\r
 \r
-  gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, mImageHandle, ControllerHandle);\r
+  gBS->CloseProtocol (ControllerHandle, &gEfiDevicePathProtocolGuid, gImageHandle, ControllerHandle);\r
   return Status;\r
 }\r
 \r
@@ -292,6 +320,7 @@ BootMonFsDriverStart (
   BOOTMON_FS_INSTANCE *Instance;\r
   EFI_STATUS           Status;\r
   UINTN                VolumeNameSize;\r
+  EFI_FILE_INFO       *Info;\r
 \r
   Instance = AllocateZeroPool (sizeof (BOOTMON_FS_INSTANCE));\r
   if (Instance == NULL) {\r
@@ -303,26 +332,24 @@ BootMonFsDriverStart (
                   ControllerHandle,\r
                   &gEfiBlockIoProtocolGuid,\r
                   (VOID **)&(Instance->BlockIo),\r
-                  mImageHandle,\r
+                  gImageHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (Instance);\r
-    return Status;\r
+    goto Error;\r
   }\r
 \r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
                   &gEfiDiskIoProtocolGuid,\r
                   (VOID **)&(Instance->DiskIo),\r
-                  mImageHandle,\r
+                  gImageHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (Instance);\r
-    return Status;\r
+    goto Error;\r
   }\r
 \r
   //\r
@@ -351,22 +378,27 @@ BootMonFsDriverStart (
   // Initialize the root file\r
   Status = BootMonFsCreateFile (Instance, &Instance->RootFile);\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (Instance);\r
-    return Status;\r
+    goto Error;\r
   }\r
 \r
+  Info = AllocateZeroPool (sizeof (EFI_FILE_INFO));\r
+  if (Info == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Error;\r
+  }\r
+  Instance->RootFile->Info = Info;\r
+\r
   // Initialize the DevicePath of the Instance\r
   Status = gBS->OpenProtocol (\r
                   ControllerHandle,\r
                   &gEfiDevicePathProtocolGuid,\r
                   (VOID **)&(Instance->DevicePath),\r
-                  mImageHandle,\r
+                  gImageHandle,\r
                   ControllerHandle,\r
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (Instance);\r
-    return Status;\r
+    goto Error;\r
   }\r
 \r
   //\r
@@ -377,9 +409,24 @@ BootMonFsDriverStart (
                       &gEfiSimpleFileSystemProtocolGuid, &Instance->Fs,\r
                       NULL\r
                       );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
+  }\r
 \r
   InsertTailList (&mInstances, &Instance->Link);\r
 \r
+  return EFI_SUCCESS;\r
+\r
+Error:\r
+\r
+    if (Instance->RootFile != NULL) {\r
+      if (Instance->RootFile->Info != NULL) {\r
+        FreePool (Instance->RootFile->Info);\r
+      }\r
+      FreePool (Instance->RootFile);\r
+    }\r
+    FreePool (Instance);\r
+\r
   return Status;\r
 }\r
 \r
@@ -435,6 +482,10 @@ BootMonFsDriverStop (
       &gEfiSimpleFileSystemProtocolGuid, &Instance->Fs,\r
       NULL);\r
 \r
+  FreePool (Instance->RootFile->Info);\r
+  FreePool (Instance->RootFile);\r
+  FreePool (Instance);\r
+\r
   return Status;\r
 }\r
 \r
@@ -459,7 +510,6 @@ BootMonFsEntryPoint (
 {\r
   EFI_STATUS  Status;\r
 \r
-  mImageHandle = ImageHandle;\r
   InitializeListHead (&mInstances);\r
 \r
   // Initialize the list of Device Paths that could support BootMonFs\r