]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EdkNt32Pkg/Dxe/WinNtThunk/Bus/SimpleFileSystem/WinNtSimpleFileSystem.c
1. Perfect libraries MSA files
[mirror_edk2.git] / EdkNt32Pkg / Dxe / WinNtThunk / Bus / SimpleFileSystem / WinNtSimpleFileSystem.c
index d55a153f9b9900c5656fed7b9cde0214305c9953..28fd819b1d38bff77f4c40c4f57a10ffa2555be4 100644 (file)
@@ -1,13 +1,13 @@
 /*++\r
 \r
-Copyright (c) 2006 - 2007, Intel Corporation                                                         \r
-All rights reserved. This program and the accompanying materials                          \r
-are licensed and made available under the terms and conditions of the BSD License         \r
-which accompanies this distribution.  The full text of the license may be found at        \r
-http://opensource.org/licenses/bsd-license.php                                            \r
-                                                                                          \r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+Copyright (c) 2006 - 2007, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 Module Name:\r
 \r
@@ -16,8 +16,8 @@ Module Name:
 Abstract:\r
 \r
   Produce Simple File System abstractions for directories on your PC using Win32 APIs.\r
-  The configuration of what devices to mount or emulate comes from NT \r
-  environment variables. The variables must be visible to the Microsoft* \r
+  The configuration of what devices to mount or emulate comes from NT\r
+  environment variables. The variables must be visible to the Microsoft*\r
   Developer Studio for them to work.\r
 \r
   * Other names and brands may be claimed as the property of others.\r
@@ -142,7 +142,7 @@ Returns:
     for (Pointer = Str; *(Pointer + Count); Pointer++) {\r
       *Pointer = *(Pointer + Count);\r
     }\r
-    *Pointer = *(Pointer + Count);    \r
+    *Pointer = *(Pointer + Count);\r
   }\r
 }\r
 \r
@@ -284,12 +284,10 @@ Returns:
     goto Done;\r
   }\r
 \r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  sizeof (WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE),\r
-                  &Private\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
+  Private = AllocatePool (sizeof (WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE));\r
+  if (Private == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+\r
     goto Done;\r
   }\r
 \r
@@ -298,14 +296,9 @@ Returns:
 \r
   Private->FilePath = WinNtIo->EnvString;\r
 \r
-  Private->VolumeLabel      = NULL;\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  StrSize (L"EFI_EMULATED"),\r
-                  &Private->VolumeLabel\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
+  Private->VolumeLabel = AllocatePool (StrSize (L"EFI_EMULATED"));\r
+  if (Private->VolumeLabel == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
@@ -339,7 +332,7 @@ Done:
 \r
       FreeUnicodeStringTable (Private->ControllerNameTable);\r
 \r
-      gBS->FreePool (Private);\r
+      FreePool (Private);\r
     }\r
 \r
     gBS->CloseProtocol (\r
@@ -431,7 +424,7 @@ Returns:
     //\r
     FreeUnicodeStringTable (Private->ControllerNameTable);\r
 \r
-    gBS->FreePool (Private);\r
+    FreePool (Private);\r
   }\r
 \r
   return Status;\r
@@ -489,33 +482,21 @@ Returns:
 \r
   Private     = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);\r
 \r
-  PrivateFile = NULL;\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  sizeof (WIN_NT_EFI_FILE_PRIVATE),\r
-                  &PrivateFile\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
+  PrivateFile = AllocatePool (sizeof (WIN_NT_EFI_FILE_PRIVATE));\r
+  if (PrivateFile == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
-  PrivateFile->FileName = NULL;\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  StrSize (Private->FilePath),\r
-                  &PrivateFile->FileName\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
+  PrivateFile->FileName = AllocatePool (StrSize (Private->FilePath));\r
+  if (PrivateFile->FileName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
-  PrivateFile->FilePath = NULL;\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  StrSize (Private->FilePath),\r
-                  &PrivateFile->FilePath\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
+  PrivateFile->FilePath = AllocatePool (StrSize (Private->FilePath));\r
+  if (PrivateFile->FilePath == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
@@ -541,7 +522,7 @@ Returns:
   PrivateFile->LHandle              = INVALID_HANDLE_VALUE;\r
   PrivateFile->DirHandle            = INVALID_HANDLE_VALUE;\r
   PrivateFile->IsValidFindBuf       = FALSE;\r
-  \r
+\r
   *Root = &PrivateFile->EfiFile;\r
 \r
   Status = EFI_SUCCESS;\r
@@ -550,14 +531,14 @@ Done:
   if (EFI_ERROR (Status)) {\r
     if (PrivateFile) {\r
       if (PrivateFile->FileName) {\r
-        gBS->FreePool (PrivateFile->FileName);\r
+        FreePool (PrivateFile->FileName);\r
       }\r
 \r
       if (PrivateFile->FilePath) {\r
-        gBS->FreePool (PrivateFile->FilePath);\r
+        FreePool (PrivateFile->FilePath);\r
       }\r
 \r
-      gBS->FreePool (PrivateFile);\r
+      FreePool (PrivateFile);\r
     }\r
   }\r
 \r
@@ -675,13 +656,9 @@ Returns:
   //\r
   // Allocate buffer for FileName as the passed in FileName may be read only\r
   //\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  StrSize (FileName),\r
-                  &TempFileName\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return  Status;\r
+  TempFileName = AllocatePool (StrSize (FileName));\r
+  if (TempFileName == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
   }\r
   StrCpy (TempFileName, FileName);\r
   FileName = TempFileName;\r
@@ -705,7 +682,7 @@ OpenRoot:
   }\r
 \r
   //\r
-  // If file name does not equal to "." or "..", \r
+  // If file name does not equal to "." or "..",\r
   // then we trim the leading/trailing blanks and trailing dots\r
   //\r
   if (StrCmp (FileName, L".") != 0 && StrCmp (FileName, L"..") != 0) {\r
@@ -722,7 +699,7 @@ OpenRoot:
     //\r
     // Trim trailing dots and blanks\r
     //\r
-    for (TempFileName = FileName + StrLen (FileName) - 1; \r
+    for (TempFileName = FileName + StrLen (FileName) - 1;\r
       TempFileName >= FileName && (*TempFileName == L' ' || *TempFileName == L'.');\r
       TempFileName--) {\r
       ;\r
@@ -733,27 +710,17 @@ OpenRoot:
   //\r
   // Attempt to open the file\r
   //\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  sizeof (WIN_NT_EFI_FILE_PRIVATE),\r
-                  &NewPrivateFile\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
+  NewPrivateFile = AllocatePool (sizeof (WIN_NT_EFI_FILE_PRIVATE));\r
+  if (NewPrivateFile == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
   CopyMem (NewPrivateFile, PrivateFile, sizeof (WIN_NT_EFI_FILE_PRIVATE));\r
 \r
-  NewPrivateFile->FilePath = NULL;\r
-\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  StrSize (PrivateFile->FileName),\r
-                  &NewPrivateFile->FilePath\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
+  NewPrivateFile->FilePath = AllocatePool (StrSize (PrivateFile->FileName));\r
+  if (NewPrivateFile->FilePath == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
@@ -763,14 +730,9 @@ OpenRoot:
     StrCpy (NewPrivateFile->FilePath, PrivateFile->FilePath);\r
   }\r
 \r
-  NewPrivateFile->FileName = NULL;\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  StrSize (NewPrivateFile->FilePath) + StrSize (L"\\") + StrSize (FileName),\r
-                  &NewPrivateFile->FileName\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
+  NewPrivateFile->FileName = AllocatePool (StrSize (NewPrivateFile->FilePath) + StrSize (L"\\") + StrSize (FileName));\r
+  if (NewPrivateFile->FileName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
@@ -783,7 +745,7 @@ OpenRoot:
     if (StrCmp (FileName, L"") != 0) {\r
       //\r
       // In case the filename becomes empty, especially after trimming dots and blanks\r
-      //    \r
+      //\r
       StrCat (NewPrivateFile->FileName, L"\\");\r
       StrCat (NewPrivateFile->FileName, FileName);\r
     }\r
@@ -847,9 +809,9 @@ OpenRoot:
 \r
   if (StrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) {\r
     NewPrivateFile->IsRootDirectory = TRUE;\r
-    gBS->FreePool (NewPrivateFile->FilePath);\r
-    gBS->FreePool (NewPrivateFile->FileName);\r
-    gBS->FreePool (NewPrivateFile);\r
+    FreePool (NewPrivateFile->FilePath);\r
+    FreePool (NewPrivateFile->FileName);\r
+    FreePool (NewPrivateFile);\r
     goto OpenRoot;\r
   }\r
 \r
@@ -861,15 +823,11 @@ OpenRoot:
   TempChar            = *(RealFileName - 1);\r
   *(RealFileName - 1) = 0;\r
 \r
-  gBS->FreePool (NewPrivateFile->FilePath);\r
+  FreePool (NewPrivateFile->FilePath);\r
   NewPrivateFile->FilePath = NULL;\r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  StrSize (NewPrivateFile->FileName),\r
-                  &NewPrivateFile->FilePath\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
+  NewPrivateFile->FilePath = AllocatePool (StrSize (NewPrivateFile->FileName));\r
+  if (NewPrivateFile->FilePath == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
@@ -923,13 +881,9 @@ OpenRoot:
   //\r
   if (NewPrivateFile->IsDirectoryPath) {\r
 \r
-    Status = gBS->AllocatePool (\r
-                    EfiBootServicesData,\r
-                    StrSize (NewPrivateFile->FileName) + StrSize (L"\\*"),\r
-                    &TempFileName\r
-                    );\r
-\r
-    if (EFI_ERROR (Status)) {\r
+    TempFileName = AllocatePool (StrSize (NewPrivateFile->FileName) + StrSize (L"\\*"));\r
+    if (TempFileName == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
     }\r
 \r
@@ -943,7 +897,7 @@ OpenRoot:
 \r
         LastError = PrivateFile->WinNtThunk->GetLastError ();\r
         if (LastError != ERROR_ALREADY_EXISTS) {\r
-          gBS->FreePool (TempFileName);\r
+          FreePool (TempFileName);\r
           Status = EFI_ACCESS_DENIED;\r
           goto Done;\r
         }\r
@@ -1059,13 +1013,9 @@ OpenRoot:
       goto Done;\r
     }\r
 \r
-    Status = gBS->AllocatePool (\r
-                    EfiBootServicesData,\r
-                    InfoSize,\r
-                    &Info\r
-                    );\r
-\r
-    if (EFI_ERROR (Status)) {\r
+    Info = AllocatePool (InfoSize);\r
+    if (Info == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
     }\r
 \r
@@ -1081,19 +1031,19 @@ OpenRoot:
   }\r
 \r
 Done: ;\r
-  gBS->FreePool (FileName);\r
+  FreePool (FileName);\r
 \r
   if (EFI_ERROR (Status)) {\r
     if (NewPrivateFile) {\r
       if (NewPrivateFile->FileName) {\r
-        gBS->FreePool (NewPrivateFile->FileName);\r
+        FreePool (NewPrivateFile->FileName);\r
       }\r
 \r
       if (NewPrivateFile->FilePath) {\r
-        gBS->FreePool (NewPrivateFile->FilePath);\r
+        FreePool (NewPrivateFile->FilePath);\r
       }\r
 \r
-      gBS->FreePool (NewPrivateFile);\r
+      FreePool (NewPrivateFile);\r
     }\r
   } else {\r
     *NewHandle = &NewPrivateFile->EfiFile;\r
@@ -1132,7 +1082,7 @@ Returns:
   }\r
 \r
   OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
-  \r
+\r
   PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   if (PrivateFile->LHandle != INVALID_HANDLE_VALUE) {\r
@@ -1151,13 +1101,13 @@ Returns:
   }\r
 \r
   if (PrivateFile->FileName) {\r
-    gBS->FreePool (PrivateFile->FileName);\r
+    FreePool (PrivateFile->FileName);\r
   }\r
 \r
-  gBS->FreePool (PrivateFile);\r
+  FreePool (PrivateFile);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
-  \r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -1194,7 +1144,7 @@ Returns:
   }\r
 \r
   OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
-  \r
+\r
   PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   Status      = EFI_WARN_DELETE_FAILURE;\r
@@ -1223,8 +1173,8 @@ Returns:
     }\r
   }\r
 \r
-  gBS->FreePool (PrivateFile->FileName);\r
-  gBS->FreePool (PrivateFile);\r
+  FreePool (PrivateFile->FileName);\r
+  FreePool (PrivateFile);\r
 \r
   gBS->RestoreTPL (OldTpl);\r
 \r
@@ -1328,7 +1278,7 @@ Returns:
   }\r
 \r
   OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
-  \r
+\r
   PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {\r
@@ -1344,11 +1294,7 @@ Returns:
     }\r
 \r
     FileInfoSize = SIZE_OF_EFI_FILE_SYSTEM_INFO;\r
-    gBS->AllocatePool (\r
-          EfiBootServicesData,\r
-          FileInfoSize,\r
-          &FileInfo\r
-          );\r
+    FileInfo = AllocatePool (FileInfoSize);\r
 \r
     Status = This->GetInfo (\r
                     This,\r
@@ -1358,12 +1304,8 @@ Returns:
                     );\r
 \r
     if (Status == EFI_BUFFER_TOO_SMALL) {\r
-      gBS->FreePool (FileInfo);\r
-      gBS->AllocatePool (\r
-            EfiBootServicesData,\r
-            FileInfoSize,\r
-            &FileInfo\r
-            );\r
+      FreePool (FileInfo);\r
+      FileInfo = AllocatePool (FileInfoSize);\r
       Status = This->GetInfo (\r
                       This,\r
                       &gEfiFileInfoGuid,\r
@@ -1379,7 +1321,7 @@ Returns:
 \r
     FileSize = FileInfo->FileSize;\r
 \r
-    gBS->FreePool (FileInfo);\r
+    FreePool (FileInfo);\r
 \r
     if (Pos >= FileSize) {\r
       *BufferSize = 0;\r
@@ -1545,7 +1487,7 @@ Returns:
   }\r
 \r
   OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
-  \r
+\r
   PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {\r
@@ -1619,7 +1561,7 @@ Returns:
   }\r
 \r
   OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
-  \r
+\r
   PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   if (PrivateFile->IsDirectoryPath) {\r
@@ -1628,13 +1570,9 @@ Returns:
       goto Done;\r
     }\r
 \r
-    Status = gBS->AllocatePool (\r
-                    EfiBootServicesData,\r
-                    StrSize (PrivateFile->FileName) + StrSize (L"\\*"),\r
-                    &FileName\r
-                    );\r
-\r
-    if (EFI_ERROR (Status)) {\r
+    FileName = AllocatePool (StrSize (PrivateFile->FileName) + StrSize (L"\\*"));\r
+    if (FileName == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
     }\r
 \r
@@ -1653,7 +1591,7 @@ Returns:
       PrivateFile->IsValidFindBuf = TRUE;\r
     }\r
 \r
-    gBS->FreePool (FileName);\r
+    FreePool (FileName);\r
 \r
     Status = (PrivateFile->LHandle == INVALID_HANDLE_VALUE) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
   } else {\r
@@ -1956,14 +1894,10 @@ Returns:
     //\r
     // Try to get the drive name\r
     //\r
-    DriveName       = NULL;\r
     DriveNameFound  = FALSE;\r
-    Status = gBS->AllocatePool (\r
-                    EfiBootServicesData,\r
-                    StrSize (PrivateFile->FilePath) + 1,\r
-                    &DriveName\r
-                    );\r
-    if (EFI_ERROR (Status)) {\r
+    DriveName = AllocatePool (StrSize (PrivateFile->FilePath) + 1);\r
+    if (DriveName == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
     }\r
 \r
@@ -2003,7 +1937,7 @@ Returns:
                                           &TotalClusters\r
                                           );\r
     if (DriveName) {\r
-      gBS->FreePool (DriveName);\r
+      FreePool (DriveName);\r
     }\r
 \r
     if (NtStatus) {\r
@@ -2161,16 +2095,10 @@ Returns:
 \r
     NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer;\r
 \r
-    gBS->FreePool (PrivateRoot->VolumeLabel);\r
-\r
-    PrivateRoot->VolumeLabel = NULL;\r
-    Status = gBS->AllocatePool (\r
-                    EfiBootServicesData,\r
-                    StrSize (NewFileSystemInfo->VolumeLabel),\r
-                    &PrivateRoot->VolumeLabel\r
-                    );\r
-\r
-    if (EFI_ERROR (Status)) {\r
+    FreePool (PrivateRoot->VolumeLabel);\r
+    PrivateRoot->VolumeLabel = AllocatePool (StrSize (NewFileSystemInfo->VolumeLabel));\r
+    if (PrivateRoot->VolumeLabel == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
     }\r
 \r
@@ -2240,9 +2168,9 @@ Returns:
     goto Done;\r
   }\r
 \r
-  Status = gBS->AllocatePool (EfiBootServicesData, OldInfoSize, &OldFileInfo);\r
-\r
-  if (EFI_ERROR (Status)) {\r
+  OldFileInfo = AllocatePool (OldInfoSize);\r
+  if (OldFileInfo == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
@@ -2252,13 +2180,9 @@ Returns:
     goto Done;\r
   }\r
 \r
-  Status = gBS->AllocatePool (\r
-                  EfiBootServicesData,\r
-                  StrSize (PrivateFile->FileName),\r
-                  &OldFileName\r
-                  );\r
-\r
-  if (EFI_ERROR (Status)) {\r
+  OldFileName = AllocatePool (StrSize (PrivateFile->FileName));\r
+  if (OldFileName == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
     goto Done;\r
   }\r
 \r
@@ -2268,13 +2192,9 @@ Returns:
   // Make full pathname from new filename and rootpath.\r
   //\r
   if (NewFileInfo->FileName[0] == '\\') {\r
-    Status = gBS->AllocatePool (\r
-                    EfiBootServicesData,\r
-                    StrSize (PrivateRoot->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName),\r
-                    &NewFileName\r
-                    );\r
-\r
-    if (EFI_ERROR (Status)) {\r
+    NewFileName = AllocatePool (StrSize (PrivateRoot->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName));\r
+    if (NewFileName == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
     }\r
 \r
@@ -2282,13 +2202,9 @@ Returns:
     StrCat (NewFileName, L"\\");\r
     StrCat (NewFileName, NewFileInfo->FileName + 1);\r
   } else {\r
-    Status = gBS->AllocatePool (\r
-                    EfiBootServicesData,\r
-                    StrSize (PrivateFile->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName),\r
-                    &NewFileName\r
-                    );\r
-\r
-    if (EFI_ERROR (Status)) {\r
+    NewFileName = AllocatePool (StrSize (PrivateFile->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName));\r
+    if (NewFileName == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
       goto Done;\r
     }\r
 \r
@@ -2394,30 +2310,22 @@ Returns:
       //\r
       // modify file name\r
       //\r
-      gBS->FreePool (PrivateFile->FileName);\r
-\r
-      Status = gBS->AllocatePool (\r
-                      EfiBootServicesData,\r
-                      StrSize (NewFileName),\r
-                      &PrivateFile->FileName\r
-                      );\r
+      FreePool (PrivateFile->FileName);\r
 \r
-      if (EFI_ERROR (Status)) {\r
+      PrivateFile->FileName = AllocatePool (StrSize (NewFileName));\r
+      if (PrivateFile->FileName == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
         goto Done;\r
       }\r
 \r
       StrCpy (PrivateFile->FileName, NewFileName);\r
 \r
-      Status = gBS->AllocatePool (\r
-                      EfiBootServicesData,\r
-                      StrSize (NewFileName) + StrSize (L"\\*"),\r
-                      &TempFileName\r
-                      );\r
+      TempFileName = AllocatePool (StrSize (NewFileName) + StrSize (L"\\*"));\r
 \r
       StrCpy (TempFileName, NewFileName);\r
 \r
       if (!PrivateFile->IsDirectoryPath) {\r
-        PrivateFile->LHandle = PrivateFile->WinNtThunk->CreateFile (\r
+       PrivateFile->LHandle = PrivateFile->WinNtThunk->CreateFile (\r
                                                           TempFileName,\r
                                                           PrivateFile->IsOpenedByRead ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,\r
                                                           FILE_SHARE_READ | FILE_SHARE_WRITE,\r
@@ -2427,7 +2335,7 @@ Returns:
                                                           NULL\r
                                                           );\r
 \r
-        gBS->FreePool (TempFileName);\r
+        FreePool (TempFileName);\r
 \r
         //\r
         //  Flush buffers just in case\r
@@ -2450,7 +2358,7 @@ Returns:
         StrCat (TempFileName, L"\\*");\r
         PrivateFile->LHandle = PrivateFile->WinNtThunk->FindFirstFile (TempFileName, &FindBuf);\r
 \r
-        gBS->FreePool (TempFileName);\r
+        FreePool (TempFileName);\r
       }\r
     } else {\r
 Reopen: ;\r
@@ -2462,11 +2370,7 @@ Reopen: ;
         goto Done;\r
       }\r
 \r
-      Status = gBS->AllocatePool (\r
-                      EfiBootServicesData,\r
-                      StrSize (OldFileName) + StrSize (L"\\*"),\r
-                      &TempFileName\r
-                      );\r
+      TempFileName = AllocatePool (StrSize (OldFileName) + StrSize (L"\\*"));\r
 \r
       StrCpy (TempFileName, OldFileName);\r
 \r
@@ -2495,7 +2399,7 @@ Reopen: ;
         PrivateFile->LHandle = PrivateFile->WinNtThunk->FindFirstFile (TempFileName, &FindBuf);\r
       }\r
 \r
-      gBS->FreePool (TempFileName);\r
+      FreePool (TempFileName);\r
 \r
       goto Done;\r
 \r
@@ -2637,15 +2541,15 @@ Reopen: ;
 \r
 Done:\r
   if (OldFileInfo != NULL) {\r
-    gBS->FreePool (OldFileInfo);\r
+    FreePool (OldFileInfo);\r
   }\r
 \r
   if (OldFileName != NULL) {\r
-    gBS->FreePool (OldFileName);\r
+    FreePool (OldFileName);\r
   }\r
 \r
   if (NewFileName != NULL) {\r
-    gBS->FreePool (NewFileName);\r
+    FreePool (NewFileName);\r
   }\r
 \r
   gBS->RestoreTPL (OldTpl);\r
@@ -2696,7 +2600,7 @@ Returns:
   }\r
 \r
   OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
-  \r
+\r
   PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
 \r
   if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {\r