/*++\r
\r
-Copyright (c) 2006, 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
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
WinNtSimpleFileSystemDriverBindingSupported,\r
WinNtSimpleFileSystemDriverBindingStart,\r
WinNtSimpleFileSystemDriverBindingStop,\r
- 0x10,\r
+ 0xa,\r
NULL,\r
NULL\r
};\r
ASSERT (0);\r
}\r
\r
- for (Pointer = Str; *(Pointer + Count); Pointer++) {\r
+ if (Count != 0) {\r
+ for (Pointer = Str; *(Pointer + Count); Pointer++) {\r
+ *Pointer = *(Pointer + Count);\r
+ }\r
*Pointer = *(Pointer + Count);\r
}\r
-\r
- *Pointer = *(Pointer + Count);\r
}\r
\r
\r
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
\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
\r
FreeUnicodeStringTable (Private->ControllerNameTable);\r
\r
- gBS->FreePool (Private);\r
+ FreePool (Private);\r
}\r
\r
gBS->CloseProtocol (\r
//\r
FreeUnicodeStringTable (Private->ControllerNameTable);\r
\r
- gBS->FreePool (Private);\r
+ FreePool (Private);\r
}\r
\r
return Status;\r
EFI_STATUS Status;\r
WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
WIN_NT_EFI_FILE_PRIVATE *PrivateFile;\r
+ EFI_TPL OldTpl;\r
\r
if (This == NULL || Root == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
+\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
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
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
+ gBS->RestoreTPL (OldTpl);\r
+\r
return Status;\r
}\r
\r
CHAR16 TempChar;\r
DWORD LastError;\r
UINTN Count;\r
- BOOLEAN TrailingDash;\r
BOOLEAN LoopFinish;\r
UINTN InfoSize;\r
EFI_FILE_INFO *Info;\r
\r
- TrailingDash = FALSE;\r
-\r
//\r
// Check for obvious invalid parameters.\r
//\r
}\r
\r
//\r
- //\r
+ // Init local variables\r
//\r
PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
PrivateRoot = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);\r
NewPrivateFile = NULL;\r
\r
+ //\r
+ // Allocate buffer for FileName as the passed in FileName may be read only\r
+ //\r
+ TempFileName = AllocatePool (StrSize (FileName));\r
+ if (TempFileName == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+ StrCpy (TempFileName, FileName);\r
+ FileName = TempFileName;\r
+\r
//\r
// BUGBUG: assume an open of root\r
// if current location, return current data\r
}\r
\r
if (FileName[StrLen (FileName) - 1] == L'\\') {\r
- TrailingDash = TRUE;\r
FileName[StrLen (FileName) - 1] = 0;\r
}\r
\r
//\r
- // Attempt to open the file\r
+ // If file name does not equal to "." or "..",\r
+ // then we trim the leading/trailing blanks and trailing dots\r
//\r
- Status = gBS->AllocatePool (\r
- EfiBootServicesData,\r
- sizeof (WIN_NT_EFI_FILE_PRIVATE),\r
- &NewPrivateFile\r
- );\r
+ if (StrCmp (FileName, L".") != 0 && StrCmp (FileName, L"..") != 0) {\r
+ //\r
+ // Trim leading blanks\r
+ //\r
+ Count = 0;\r
+ for (TempFileName = FileName;\r
+ *TempFileName != 0 && *TempFileName == L' ';\r
+ TempFileName++) {\r
+ Count++;\r
+ }\r
+ CutPrefix (FileName, Count);\r
+ //\r
+ // Trim trailing dots and blanks\r
+ //\r
+ for (TempFileName = FileName + StrLen (FileName) - 1;\r
+ TempFileName >= FileName && (*TempFileName == L' ' || *TempFileName == L'.');\r
+ TempFileName--) {\r
+ ;\r
+ }\r
+ *(TempFileName + 1) = 0;\r
+ }\r
\r
- if (EFI_ERROR (Status)) {\r
+ //\r
+ // Attempt to open the file\r
+ //\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
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
StrCat (NewPrivateFile->FileName, FileName + 1);\r
} else {\r
StrCpy (NewPrivateFile->FileName, NewPrivateFile->FilePath);\r
- StrCat (NewPrivateFile->FileName, L"\\");\r
- StrCat (NewPrivateFile->FileName, FileName);\r
+ if (StrCmp (FileName, L"") != 0) {\r
+ //\r
+ // In case the filename becomes empty, especially after trimming dots and blanks\r
+ //\r
+ StrCat (NewPrivateFile->FileName, L"\\");\r
+ StrCat (NewPrivateFile->FileName, FileName);\r
+ }\r
}\r
\r
//\r
\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
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
//\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
\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
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
}\r
\r
Done: ;\r
- if (TrailingDash) {\r
- FileName[StrLen (FileName) + 1] = 0;\r
- FileName[StrLen (FileName)] = L'\\';\r
- }\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
// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
{\r
WIN_NT_EFI_FILE_PRIVATE *PrivateFile;\r
+ EFI_TPL OldTpl;\r
\r
if (This == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
+\r
PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
\r
if (PrivateFile->LHandle != INVALID_HANDLE_VALUE) {\r
}\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
return EFI_SUCCESS;\r
}\r
\r
{\r
EFI_STATUS Status;\r
WIN_NT_EFI_FILE_PRIVATE *PrivateFile;\r
+ EFI_TPL OldTpl;\r
\r
if (This == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
+\r
PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
\r
Status = EFI_WARN_DELETE_FAILURE;\r
}\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
return Status;\r
}\r
UINT64 Pos;\r
UINT64 FileSize;\r
UINTN FileInfoSize;\r
+ EFI_TPL OldTpl;\r
\r
- if (This == NULL || BufferSize == NULL || Buffer == NULL) {\r
+ if (This == NULL || BufferSize == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
+\r
PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
\r
if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {\r
- return EFI_DEVICE_ERROR;\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
}\r
\r
if (!PrivateFile->IsDirectoryPath) {\r
\r
if (This->GetPosition (This, &Pos) != EFI_SUCCESS) {\r
- return EFI_DEVICE_ERROR;\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
}\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
);\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
}\r
\r
if (EFI_ERROR (Status)) {\r
- return EFI_DEVICE_ERROR;\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
}\r
\r
FileSize = FileInfo->FileSize;\r
\r
- gBS->FreePool (FileInfo);\r
+ FreePool (FileInfo);\r
\r
if (Pos >= FileSize) {\r
*BufferSize = 0;\r
if (Pos == FileSize) {\r
- return EFI_SUCCESS;\r
+ Status = EFI_SUCCESS;\r
+ goto Done;\r
} else {\r
- return EFI_DEVICE_ERROR;\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
}\r
}\r
\r
- return PrivateFile->WinNtThunk->ReadFile (\r
+ Status = PrivateFile->WinNtThunk->ReadFile (\r
PrivateFile->LHandle,\r
Buffer,\r
*BufferSize,\r
BufferSize,\r
NULL\r
) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
+ goto Done;\r
}\r
\r
//\r
//\r
if (!PrivateFile->IsValidFindBuf) {\r
*BufferSize = 0;\r
- return EFI_SUCCESS;\r
+ Status = EFI_SUCCESS;\r
+ goto Done;\r
}\r
\r
Size = SIZE_OF_EFI_FILE_INFO;\r
\r
*BufferSize = ResultSize;\r
\r
+Done:\r
+ gBS->RestoreTPL (OldTpl);\r
return Status;\r
}\r
\r
// TODO: EFI_INVALID_PARAMETER - add return value to function comment\r
{\r
WIN_NT_EFI_FILE_PRIVATE *PrivateFile;\r
+ EFI_STATUS Status;\r
+ EFI_TPL OldTpl;\r
\r
if (This == NULL || BufferSize == NULL || Buffer == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
+\r
PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
\r
if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {\r
- return EFI_DEVICE_ERROR;\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
}\r
\r
if (PrivateFile->IsDirectoryPath) {\r
- return EFI_UNSUPPORTED;\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
}\r
\r
if (PrivateFile->IsOpenedByRead) {\r
- return EFI_ACCESS_DENIED;\r
+ Status = EFI_ACCESS_DENIED;\r
+ goto Done;\r
}\r
\r
- return PrivateFile->WinNtThunk->WriteFile (\r
+ Status = PrivateFile->WinNtThunk->WriteFile (\r
PrivateFile->LHandle,\r
Buffer,\r
*BufferSize,\r
NULL\r
) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
\r
+Done:\r
+ gBS->RestoreTPL (OldTpl);\r
+ return Status;\r
+\r
//\r
// bugbug: need to access windows error reporting\r
//\r
UINT32 PosLow;\r
UINT32 PosHigh;\r
CHAR16 *FileName;\r
+ EFI_TPL OldTpl;\r
\r
if (This == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
+\r
PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
\r
if (PrivateFile->IsDirectoryPath) {\r
if (Position != 0) {\r
- return EFI_UNSUPPORTED;\r
+ Status = EFI_UNSUPPORTED;\r
+ 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
- return 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
StrCpy (FileName, PrivateFile->FileName);\r
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
Status = (PosLow == 0xFFFFFFFF) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
}\r
\r
+Done:\r
+ gBS->RestoreTPL (OldTpl);\r
return Status;\r
}\r
\r
WIN_NT_EFI_FILE_PRIVATE *PrivateFile;\r
INT32 PositionHigh;\r
UINT64 PosHigh64;\r
+ EFI_TPL OldTpl;\r
\r
if (This == NULL || Position == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
\r
PositionHigh = 0;\r
\r
if (PrivateFile->IsDirectoryPath) {\r
\r
- return EFI_UNSUPPORTED;\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
\r
} else {\r
\r
}\r
\r
Done:\r
+ gBS->RestoreTPL (OldTpl);\r
return Status;\r
}\r
\r
SYSTEMTIME SystemTime;\r
CHAR16 *RealFileName;\r
CHAR16 *TempPointer;\r
+ EFI_FILE_INFO *DirInfo;\r
+ UINTN ReadSize;\r
+ UINT64 Location;\r
+ EFI_STATUS DirStatus;\r
+\r
\r
Size = SIZE_OF_EFI_FILE_INFO;\r
NameSize = StrSize (PrivateFile->FileName);\r
} else {\r
CopyMem ((CHAR8 *) Buffer + Size, RealFileName, NameSize);\r
}\r
+\r
+ if (Info->Attribute & EFI_FILE_DIRECTORY) {\r
+ //\r
+ // The GetFileInformationByHandle.nFileSizeLow is bogus for dir so we \r
+ // need to do the same thing the caller would do to get the right value\r
+ //\r
+ ASSERT (PrivateFile->EfiFile.Read != NULL);\r
+ DirStatus = PrivateFile->EfiFile.GetPosition (&PrivateFile->EfiFile, &Location);\r
+ if (EFI_ERROR (DirStatus)) {\r
+ Location = 0;\r
+ }\r
+\r
+ PrivateFile->EfiFile.SetPosition (&PrivateFile->EfiFile, 0);\r
+ Info->FileSize = 0; \r
+ do {\r
+ ReadSize = 0;\r
+ DirInfo = NULL;\r
+ DirStatus = PrivateFile->EfiFile.Read (&PrivateFile->EfiFile, &ReadSize, DirInfo);\r
+ if (DirStatus == EFI_BUFFER_TOO_SMALL) {\r
+ DirInfo = AllocatePool (ReadSize);\r
+ if (DirInfo != NULL) {\r
+ //\r
+ // Read each dir entry to figure out how big the directory is\r
+ //\r
+ DirStatus = PrivateFile->EfiFile.Read (&PrivateFile->EfiFile, &ReadSize, DirInfo);\r
+ if (!EFI_ERROR (DirStatus) && (ReadSize != 0)) {\r
+ Info->FileSize += ReadSize;\r
+ }\r
+ FreePool (DirInfo);\r
+ }\r
+ }\r
+ \r
+ } while (!EFI_ERROR (DirStatus) && (ReadSize != 0));\r
+\r
+ //\r
+ // reset the file possition back to the previous location\r
+ //\r
+ PrivateFile->EfiFile.SetPosition (&PrivateFile->EfiFile, Location);\r
+ }\r
}\r
\r
*BufferSize = ResultSize;\r
BOOL NtStatus;\r
UINTN Index;\r
WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;\r
+ EFI_TPL OldTpl;\r
\r
if (This == NULL || InformationType == NULL || BufferSize == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
+\r
PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
PrivateRoot = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);\r
\r
if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {\r
if (*BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) {\r
*BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);\r
- return EFI_BUFFER_TOO_SMALL;\r
+ Status = EFI_BUFFER_TOO_SMALL;\r
+ goto Done;\r
}\r
\r
FileSystemInfoBuffer = (EFI_FILE_SYSTEM_INFO *) Buffer;\r
//\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
- return Status;\r
+ DriveName = AllocatePool (StrSize (PrivateFile->FilePath) + 1);\r
+ if (DriveName == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
}\r
\r
StrCpy (DriveName, PrivateFile->FilePath);\r
&TotalClusters\r
);\r
if (DriveName) {\r
- gBS->FreePool (DriveName);\r
+ FreePool (DriveName);\r
}\r
\r
if (NtStatus) {\r
NULL\r
);\r
if (!NtStatus) {\r
- return EFI_DEVICE_ERROR;\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
}\r
}\r
\r
if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {\r
if (*BufferSize < StrSize (PrivateRoot->VolumeLabel)) {\r
*BufferSize = StrSize (PrivateRoot->VolumeLabel);\r
- return EFI_BUFFER_TOO_SMALL;\r
+ Status = EFI_BUFFER_TOO_SMALL;\r
+ goto Done;\r
}\r
\r
StrCpy ((CHAR16 *) Buffer, PrivateRoot->VolumeLabel);\r
Status = EFI_SUCCESS;\r
}\r
\r
+Done:\r
+ gBS->RestoreTPL (OldTpl);\r
return Status;\r
}\r
\r
FILETIME NewLastWriteFileTime;\r
WIN32_FIND_DATA FindBuf;\r
EFI_FILE_SYSTEM_INFO *NewFileSystemInfo;\r
+ EFI_TPL OldTpl;\r
\r
//\r
// Check for invalid parameters.\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
+\r
//\r
// Initialise locals.\r
//\r
//\r
if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {\r
if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) {\r
- return EFI_BAD_BUFFER_SIZE;\r
+ Status = EFI_BAD_BUFFER_SIZE;\r
+ goto Done;\r
}\r
\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
StrCpy (PrivateRoot->VolumeLabel, NewFileSystemInfo->VolumeLabel);\r
\r
- return EFI_SUCCESS;\r
+ Status = EFI_SUCCESS;\r
+ goto Done;\r
}\r
\r
//\r
//\r
if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {\r
if (BufferSize < StrSize (PrivateRoot->VolumeLabel)) {\r
- return EFI_BAD_BUFFER_SIZE;\r
+ Status = EFI_BAD_BUFFER_SIZE;\r
+ goto Done;\r
}\r
\r
StrCpy (PrivateRoot->VolumeLabel, (CHAR16 *) Buffer);\r
\r
- return EFI_SUCCESS;\r
+ Status = EFI_SUCCESS;\r
+ goto Done;\r
}\r
\r
if (!CompareGuid (InformationType, &gEfiFileInfoGuid)) {\r
- return EFI_UNSUPPORTED;\r
+ Status = EFI_UNSUPPORTED;\r
+ goto Done;\r
}\r
\r
if (BufferSize < SIZE_OF_EFI_FILE_INFO) {\r
- return EFI_BAD_BUFFER_SIZE;\r
+ Status = EFI_BAD_BUFFER_SIZE;\r
+ goto Done;\r
}\r
\r
//\r
(NewFileInfo->Attribute &~(EFI_FILE_VALID_ATTR)) ||\r
(sizeof (UINTN) == 4 && NewFileInfo->Size > 0xFFFFFFFF)\r
) {\r
- return EFI_INVALID_PARAMETER;\r
+ Status = EFI_INVALID_PARAMETER;\r
+ goto Done;\r
}\r
\r
//\r
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
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
// 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
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
//\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
NULL\r
);\r
\r
- gBS->FreePool (TempFileName);\r
+ FreePool (TempFileName);\r
\r
//\r
// Flush buffers just in case\r
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
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
PrivateFile->LHandle = PrivateFile->WinNtThunk->FindFirstFile (TempFileName, &FindBuf);\r
}\r
\r
- gBS->FreePool (TempFileName);\r
+ FreePool (TempFileName);\r
\r
goto Done;\r
\r
\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
return Status;\r
}\r
\r
{\r
BY_HANDLE_FILE_INFORMATION FileInfo;\r
WIN_NT_EFI_FILE_PRIVATE *PrivateFile;\r
+ EFI_STATUS Status;\r
+ EFI_TPL OldTpl;\r
\r
if (This == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
+ OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK);\r
+\r
PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
\r
if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {\r
- return EFI_DEVICE_ERROR;\r
+ Status = EFI_DEVICE_ERROR;\r
+ goto Done;\r
}\r
\r
if (PrivateFile->IsDirectoryPath) {\r
- return EFI_SUCCESS;\r
+ Status = EFI_SUCCESS;\r
+ goto Done;\r
}\r
\r
if (PrivateFile->IsOpenedByRead) {\r
- return EFI_ACCESS_DENIED;\r
+ Status = EFI_ACCESS_DENIED;\r
+ goto Done;\r
}\r
\r
PrivateFile->WinNtThunk->GetFileInformationByHandle (PrivateFile->LHandle, &FileInfo);\r
\r
if (FileInfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {\r
- return EFI_ACCESS_DENIED;\r
+ Status = EFI_ACCESS_DENIED;\r
+ goto Done;\r
}\r
\r
- return PrivateFile->WinNtThunk->FlushFileBuffers (PrivateFile->LHandle) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
+ Status = PrivateFile->WinNtThunk->FlushFileBuffers (PrivateFile->LHandle) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
\r
+Done:\r
+ gBS->RestoreTPL (OldTpl);\r
+ return Status;\r
//\r
// bugbug: - Use Windows error reporting.\r
//\r
}\r
\r
+\r