]> 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 5eb7afca7c5119a26dfa6ca03b2c24f64107c3a2..a1150856f6ba5eee61b0cee76e0e672ae823d020 100644 (file)
@@ -54,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
@@ -61,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
@@ -291,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
@@ -307,8 +337,7 @@ BootMonFsDriverStart (
                   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
@@ -320,8 +349,7 @@ BootMonFsDriverStart (
                   EFI_OPEN_PROTOCOL_BY_DRIVER\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (Instance);\r
-    return Status;\r
+    goto Error;\r
   }\r
 \r
   //\r
@@ -350,10 +378,16 @@ 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
@@ -364,8 +398,7 @@ BootMonFsDriverStart (
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    FreePool (Instance);\r
-    return Status;\r
+    goto Error;\r
   }\r
 \r
   //\r
@@ -376,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
@@ -434,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