X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=EdkNt32Pkg%2FDxe%2FWinNtThunk%2FBus%2FSimpleFileSystem%2FWinNtSimpleFileSystem.c;h=eb7b4346f71d3ef2a563e7d46f0feb4a9f54d942;hp=30f5476d5a2f179293a0c9fd76012d767ec06bf4;hb=f4c3fab9b839a86c7f8ad8981d030666272d7539;hpb=c7916981cc01e37d189e1802463fa68d10a17bf2 diff --git a/EdkNt32Pkg/Dxe/WinNtThunk/Bus/SimpleFileSystem/WinNtSimpleFileSystem.c b/EdkNt32Pkg/Dxe/WinNtThunk/Bus/SimpleFileSystem/WinNtSimpleFileSystem.c index 30f5476d5a..eb7b4346f7 100644 --- a/EdkNt32Pkg/Dxe/WinNtThunk/Bus/SimpleFileSystem/WinNtSimpleFileSystem.c +++ b/EdkNt32Pkg/Dxe/WinNtThunk/Bus/SimpleFileSystem/WinNtSimpleFileSystem.c @@ -1,13 +1,13 @@ /*++ -Copyright (c) 2006, Intel Corporation -All rights reserved. This program and the accompanying materials -are licensed and made available under the terms and conditions of the BSD License -which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php - -THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, -WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +Copyright (c) 2006 - 2007, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. Module Name: @@ -16,8 +16,8 @@ Module Name: Abstract: Produce Simple File System abstractions for directories on your PC using Win32 APIs. - The configuration of what devices to mount or emulate comes from NT - environment variables. The variables must be visible to the Microsoft* + The configuration of what devices to mount or emulate comes from NT + environment variables. The variables must be visible to the Microsoft* Developer Studio for them to work. * Other names and brands may be claimed as the property of others. @@ -138,11 +138,12 @@ Returns: ASSERT (0); } - for (Pointer = Str; *(Pointer + Count); Pointer++) { + if (Count != 0) { + for (Pointer = Str; *(Pointer + Count); Pointer++) { + *Pointer = *(Pointer + Count); + } *Pointer = *(Pointer + Count); } - - *Pointer = *(Pointer + Count); } @@ -283,12 +284,10 @@ Returns: goto Done; } - Status = gBS->AllocatePool ( - EfiBootServicesData, - sizeof (WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE), - &Private - ); - if (EFI_ERROR (Status)) { + Private = AllocatePool (sizeof (WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE)); + if (Private == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; } @@ -297,14 +296,9 @@ Returns: Private->FilePath = WinNtIo->EnvString; - Private->VolumeLabel = NULL; - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (L"EFI_EMULATED"), - &Private->VolumeLabel - ); - - if (EFI_ERROR (Status)) { + Private->VolumeLabel = AllocatePool (StrSize (L"EFI_EMULATED")); + if (Private->VolumeLabel == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -338,7 +332,7 @@ Done: FreeUnicodeStringTable (Private->ControllerNameTable); - gBS->FreePool (Private); + FreePool (Private); } gBS->CloseProtocol ( @@ -430,7 +424,7 @@ Returns: // FreeUnicodeStringTable (Private->ControllerNameTable); - gBS->FreePool (Private); + FreePool (Private); } return Status; @@ -478,40 +472,31 @@ Returns: EFI_STATUS Status; WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE *Private; WIN_NT_EFI_FILE_PRIVATE *PrivateFile; + EFI_TPL OldTpl; if (This == NULL || Root == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + Private = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This); - PrivateFile = NULL; - Status = gBS->AllocatePool ( - EfiBootServicesData, - sizeof (WIN_NT_EFI_FILE_PRIVATE), - &PrivateFile - ); - if (EFI_ERROR (Status)) { + PrivateFile = AllocatePool (sizeof (WIN_NT_EFI_FILE_PRIVATE)); + if (PrivateFile == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } - PrivateFile->FileName = NULL; - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (Private->FilePath), - &PrivateFile->FileName - ); - if (EFI_ERROR (Status)) { + PrivateFile->FileName = AllocatePool (StrSize (Private->FilePath)); + if (PrivateFile->FileName == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } - PrivateFile->FilePath = NULL; - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (Private->FilePath), - &PrivateFile->FilePath - ); - if (EFI_ERROR (Status)) { + PrivateFile->FilePath = AllocatePool (StrSize (Private->FilePath)); + if (PrivateFile->FilePath == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -537,7 +522,7 @@ Returns: PrivateFile->LHandle = INVALID_HANDLE_VALUE; PrivateFile->DirHandle = INVALID_HANDLE_VALUE; PrivateFile->IsValidFindBuf = FALSE; - + *Root = &PrivateFile->EfiFile; Status = EFI_SUCCESS; @@ -546,17 +531,19 @@ Done: if (EFI_ERROR (Status)) { if (PrivateFile) { if (PrivateFile->FileName) { - gBS->FreePool (PrivateFile->FileName); + FreePool (PrivateFile->FileName); } if (PrivateFile->FilePath) { - gBS->FreePool (PrivateFile->FilePath); + FreePool (PrivateFile->FilePath); } - gBS->FreePool (PrivateFile); + FreePool (PrivateFile); } } + gBS->RestoreTPL (OldTpl); + return Status; } @@ -627,13 +614,10 @@ Returns: CHAR16 TempChar; DWORD LastError; UINTN Count; - BOOLEAN TrailingDash; BOOLEAN LoopFinish; UINTN InfoSize; EFI_FILE_INFO *Info; - TrailingDash = FALSE; - // // Check for obvious invalid parameters. // @@ -663,12 +647,22 @@ Returns: } // - // + // Init local variables // PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); PrivateRoot = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem); NewPrivateFile = NULL; + // + // Allocate buffer for FileName as the passed in FileName may be read only + // + TempFileName = AllocatePool (StrSize (FileName)); + if (TempFileName == NULL) { + return EFI_OUT_OF_RESOURCES; + } + StrCpy (TempFileName, FileName); + FileName = TempFileName; + // // BUGBUG: assume an open of root // if current location, return current data @@ -684,12 +678,11 @@ OpenRoot: } if (FileName[StrLen (FileName) - 1] == L'\\') { - TrailingDash = TRUE; FileName[StrLen (FileName) - 1] = 0; } // - // If file name does not equal to "." or "..", + // If file name does not equal to "." or "..", // then we trim the leading/trailing blanks and trailing dots // if (StrCmp (FileName, L".") != 0 && StrCmp (FileName, L"..") != 0) { @@ -706,7 +699,7 @@ OpenRoot: // // Trim trailing dots and blanks // - for (TempFileName = FileName + StrLen (FileName) - 1; + for (TempFileName = FileName + StrLen (FileName) - 1; TempFileName >= FileName && (*TempFileName == L' ' || *TempFileName == L'.'); TempFileName--) { ; @@ -717,27 +710,17 @@ OpenRoot: // // Attempt to open the file // - Status = gBS->AllocatePool ( - EfiBootServicesData, - sizeof (WIN_NT_EFI_FILE_PRIVATE), - &NewPrivateFile - ); - - if (EFI_ERROR (Status)) { + NewPrivateFile = AllocatePool (sizeof (WIN_NT_EFI_FILE_PRIVATE)); + if (NewPrivateFile == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } CopyMem (NewPrivateFile, PrivateFile, sizeof (WIN_NT_EFI_FILE_PRIVATE)); - NewPrivateFile->FilePath = NULL; - - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (PrivateFile->FileName), - &NewPrivateFile->FilePath - ); - - if (EFI_ERROR (Status)) { + NewPrivateFile->FilePath = AllocatePool (StrSize (PrivateFile->FileName)); + if (NewPrivateFile->FilePath == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -747,14 +730,9 @@ OpenRoot: StrCpy (NewPrivateFile->FilePath, PrivateFile->FilePath); } - NewPrivateFile->FileName = NULL; - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (NewPrivateFile->FilePath) + StrSize (L"\\") + StrSize (FileName), - &NewPrivateFile->FileName - ); - - if (EFI_ERROR (Status)) { + NewPrivateFile->FileName = AllocatePool (StrSize (NewPrivateFile->FilePath) + StrSize (L"\\") + StrSize (FileName)); + if (NewPrivateFile->FileName == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -767,7 +745,7 @@ OpenRoot: if (StrCmp (FileName, L"") != 0) { // // In case the filename becomes empty, especially after trimming dots and blanks - // + // StrCat (NewPrivateFile->FileName, L"\\"); StrCat (NewPrivateFile->FileName, FileName); } @@ -831,9 +809,9 @@ OpenRoot: if (StrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) { NewPrivateFile->IsRootDirectory = TRUE; - gBS->FreePool (NewPrivateFile->FilePath); - gBS->FreePool (NewPrivateFile->FileName); - gBS->FreePool (NewPrivateFile); + FreePool (NewPrivateFile->FilePath); + FreePool (NewPrivateFile->FileName); + FreePool (NewPrivateFile); goto OpenRoot; } @@ -845,15 +823,11 @@ OpenRoot: TempChar = *(RealFileName - 1); *(RealFileName - 1) = 0; - gBS->FreePool (NewPrivateFile->FilePath); + FreePool (NewPrivateFile->FilePath); NewPrivateFile->FilePath = NULL; - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (NewPrivateFile->FileName), - &NewPrivateFile->FilePath - ); - - if (EFI_ERROR (Status)) { + NewPrivateFile->FilePath = AllocatePool (StrSize (NewPrivateFile->FileName)); + if (NewPrivateFile->FilePath == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -907,13 +881,9 @@ OpenRoot: // if (NewPrivateFile->IsDirectoryPath) { - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (NewPrivateFile->FileName) + StrSize (L"\\*"), - &TempFileName - ); - - if (EFI_ERROR (Status)) { + TempFileName = AllocatePool (StrSize (NewPrivateFile->FileName) + StrSize (L"\\*")); + if (TempFileName == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -927,7 +897,7 @@ OpenRoot: LastError = PrivateFile->WinNtThunk->GetLastError (); if (LastError != ERROR_ALREADY_EXISTS) { - gBS->FreePool (TempFileName); + FreePool (TempFileName); Status = EFI_ACCESS_DENIED; goto Done; } @@ -1043,13 +1013,9 @@ OpenRoot: goto Done; } - Status = gBS->AllocatePool ( - EfiBootServicesData, - InfoSize, - &Info - ); - - if (EFI_ERROR (Status)) { + Info = AllocatePool (InfoSize); + if (Info == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -1065,22 +1031,19 @@ OpenRoot: } Done: ; - if (TrailingDash) { - FileName[StrLen (FileName) + 1] = 0; - FileName[StrLen (FileName)] = L'\\'; - } + FreePool (FileName); if (EFI_ERROR (Status)) { if (NewPrivateFile) { if (NewPrivateFile->FileName) { - gBS->FreePool (NewPrivateFile->FileName); + FreePool (NewPrivateFile->FileName); } if (NewPrivateFile->FilePath) { - gBS->FreePool (NewPrivateFile->FilePath); + FreePool (NewPrivateFile->FilePath); } - gBS->FreePool (NewPrivateFile); + FreePool (NewPrivateFile); } } else { *NewHandle = &NewPrivateFile->EfiFile; @@ -1112,11 +1075,14 @@ Returns: // TODO: EFI_INVALID_PARAMETER - add return value to function comment { WIN_NT_EFI_FILE_PRIVATE *PrivateFile; + EFI_TPL OldTpl; if (This == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); if (PrivateFile->LHandle != INVALID_HANDLE_VALUE) { @@ -1135,10 +1101,13 @@ Returns: } if (PrivateFile->FileName) { - gBS->FreePool (PrivateFile->FileName); + FreePool (PrivateFile->FileName); } - gBS->FreePool (PrivateFile); + FreePool (PrivateFile); + + gBS->RestoreTPL (OldTpl); + return EFI_SUCCESS; } @@ -1168,11 +1137,14 @@ Returns: { EFI_STATUS Status; WIN_NT_EFI_FILE_PRIVATE *PrivateFile; + EFI_TPL OldTpl; if (This == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); Status = EFI_WARN_DELETE_FAILURE; @@ -1201,8 +1173,10 @@ Returns: } } - gBS->FreePool (PrivateFile->FileName); - gBS->FreePool (PrivateFile); + FreePool (PrivateFile->FileName); + FreePool (PrivateFile); + + gBS->RestoreTPL (OldTpl); return Status; } @@ -1297,29 +1271,30 @@ Returns: UINT64 Pos; UINT64 FileSize; UINTN FileInfoSize; + EFI_TPL OldTpl; - if (This == NULL || BufferSize == NULL || Buffer == NULL) { + if (This == NULL || BufferSize == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) { - return EFI_DEVICE_ERROR; + Status = EFI_DEVICE_ERROR; + goto Done; } if (!PrivateFile->IsDirectoryPath) { if (This->GetPosition (This, &Pos) != EFI_SUCCESS) { - return EFI_DEVICE_ERROR; + Status = EFI_DEVICE_ERROR; + goto Done; } FileInfoSize = SIZE_OF_EFI_FILE_SYSTEM_INFO; - gBS->AllocatePool ( - EfiBootServicesData, - FileInfoSize, - &FileInfo - ); + FileInfo = AllocatePool (FileInfoSize); Status = This->GetInfo ( This, @@ -1329,12 +1304,8 @@ Returns: ); if (Status == EFI_BUFFER_TOO_SMALL) { - gBS->FreePool (FileInfo); - gBS->AllocatePool ( - EfiBootServicesData, - FileInfoSize, - &FileInfo - ); + FreePool (FileInfo); + FileInfo = AllocatePool (FileInfoSize); Status = This->GetInfo ( This, &gEfiFileInfoGuid, @@ -1344,29 +1315,33 @@ Returns: } if (EFI_ERROR (Status)) { - return EFI_DEVICE_ERROR; + Status = EFI_DEVICE_ERROR; + goto Done; } FileSize = FileInfo->FileSize; - gBS->FreePool (FileInfo); + FreePool (FileInfo); if (Pos >= FileSize) { *BufferSize = 0; if (Pos == FileSize) { - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto Done; } else { - return EFI_DEVICE_ERROR; + Status = EFI_DEVICE_ERROR; + goto Done; } } - return PrivateFile->WinNtThunk->ReadFile ( + Status = PrivateFile->WinNtThunk->ReadFile ( PrivateFile->LHandle, Buffer, *BufferSize, BufferSize, NULL ) ? EFI_SUCCESS : EFI_DEVICE_ERROR; + goto Done; } // @@ -1374,7 +1349,8 @@ Returns: // if (!PrivateFile->IsValidFindBuf) { *BufferSize = 0; - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto Done; } Size = SIZE_OF_EFI_FILE_INFO; @@ -1454,6 +1430,8 @@ Returns: *BufferSize = ResultSize; +Done: + gBS->RestoreTPL (OldTpl); return Status; } @@ -1501,26 +1479,33 @@ Returns: // TODO: EFI_INVALID_PARAMETER - add return value to function comment { WIN_NT_EFI_FILE_PRIVATE *PrivateFile; + EFI_STATUS Status; + EFI_TPL OldTpl; if (This == NULL || BufferSize == NULL || Buffer == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) { - return EFI_DEVICE_ERROR; + Status = EFI_DEVICE_ERROR; + goto Done; } if (PrivateFile->IsDirectoryPath) { - return EFI_UNSUPPORTED; + Status = EFI_UNSUPPORTED; + goto Done; } if (PrivateFile->IsOpenedByRead) { - return EFI_ACCESS_DENIED; + Status = EFI_ACCESS_DENIED; + goto Done; } - return PrivateFile->WinNtThunk->WriteFile ( + Status = PrivateFile->WinNtThunk->WriteFile ( PrivateFile->LHandle, Buffer, *BufferSize, @@ -1528,6 +1513,10 @@ Returns: NULL ) ? EFI_SUCCESS : EFI_DEVICE_ERROR; +Done: + gBS->RestoreTPL (OldTpl); + return Status; + // // bugbug: need to access windows error reporting // @@ -1565,26 +1554,26 @@ Returns: UINT32 PosLow; UINT32 PosHigh; CHAR16 *FileName; + EFI_TPL OldTpl; if (This == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); if (PrivateFile->IsDirectoryPath) { if (Position != 0) { - return EFI_UNSUPPORTED; + Status = EFI_UNSUPPORTED; + goto Done; } - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (PrivateFile->FileName) + StrSize (L"\\*"), - &FileName - ); - - if (EFI_ERROR (Status)) { - return Status; + FileName = AllocatePool (StrSize (PrivateFile->FileName) + StrSize (L"\\*")); + if (FileName == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; } StrCpy (FileName, PrivateFile->FileName); @@ -1602,7 +1591,7 @@ Returns: PrivateFile->IsValidFindBuf = TRUE; } - gBS->FreePool (FileName); + FreePool (FileName); Status = (PrivateFile->LHandle == INVALID_HANDLE_VALUE) ? EFI_DEVICE_ERROR : EFI_SUCCESS; } else { @@ -1617,6 +1606,8 @@ Returns: Status = (PosLow == 0xFFFFFFFF) ? EFI_DEVICE_ERROR : EFI_SUCCESS; } +Done: + gBS->RestoreTPL (OldTpl); return Status; } @@ -1651,11 +1642,13 @@ Returns: WIN_NT_EFI_FILE_PRIVATE *PrivateFile; INT32 PositionHigh; UINT64 PosHigh64; + EFI_TPL OldTpl; if (This == NULL || Position == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); PositionHigh = 0; @@ -1663,7 +1656,8 @@ Returns: if (PrivateFile->IsDirectoryPath) { - return EFI_UNSUPPORTED; + Status = EFI_UNSUPPORTED; + goto Done; } else { @@ -1685,6 +1679,7 @@ Returns: } Done: + gBS->RestoreTPL (OldTpl); return Status; } @@ -1722,6 +1717,11 @@ Returns: SYSTEMTIME SystemTime; CHAR16 *RealFileName; CHAR16 *TempPointer; + EFI_FILE_INFO *DirInfo; + UINTN ReadSize; + UINT64 Location; + EFI_STATUS DirStatus; + Size = SIZE_OF_EFI_FILE_INFO; NameSize = StrSize (PrivateFile->FileName); @@ -1806,6 +1806,45 @@ Returns: } else { CopyMem ((CHAR8 *) Buffer + Size, RealFileName, NameSize); } + + if (Info->Attribute & EFI_FILE_DIRECTORY) { + // + // The GetFileInformationByHandle.nFileSizeLow is bogus for dir so we + // need to do the same thing the caller would do to get the right value + // + ASSERT (PrivateFile->EfiFile.Read != NULL); + DirStatus = PrivateFile->EfiFile.GetPosition (&PrivateFile->EfiFile, &Location); + if (EFI_ERROR (DirStatus)) { + Location = 0; + } + + PrivateFile->EfiFile.SetPosition (&PrivateFile->EfiFile, 0); + Info->FileSize = 0; + do { + ReadSize = 0; + DirInfo = NULL; + DirStatus = PrivateFile->EfiFile.Read (&PrivateFile->EfiFile, &ReadSize, DirInfo); + if (DirStatus == EFI_BUFFER_TOO_SMALL) { + DirInfo = AllocatePool (ReadSize); + if (DirInfo != NULL) { + // + // Read each dir entry to figure out how big the directory is + // + DirStatus = PrivateFile->EfiFile.Read (&PrivateFile->EfiFile, &ReadSize, DirInfo); + if (!EFI_ERROR (DirStatus) && (ReadSize != 0)) { + Info->FileSize += ReadSize; + } + FreePool (DirInfo); + } + } + + } while (!EFI_ERROR (DirStatus) && (ReadSize != 0)); + + // + // reset the file possition back to the previous location + // + PrivateFile->EfiFile.SetPosition (&PrivateFile->EfiFile, Location); + } } *BufferSize = ResultSize; @@ -1868,11 +1907,14 @@ Returns: BOOL NtStatus; UINTN Index; WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot; + EFI_TPL OldTpl; if (This == NULL || InformationType == NULL || BufferSize == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); PrivateRoot = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem); @@ -1885,7 +1927,8 @@ Returns: if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { if (*BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) { *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel); - return EFI_BUFFER_TOO_SMALL; + Status = EFI_BUFFER_TOO_SMALL; + goto Done; } FileSystemInfoBuffer = (EFI_FILE_SYSTEM_INFO *) Buffer; @@ -1895,15 +1938,11 @@ Returns: // // Try to get the drive name // - DriveName = NULL; DriveNameFound = FALSE; - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (PrivateFile->FilePath) + 1, - &DriveName - ); - if (EFI_ERROR (Status)) { - return Status; + DriveName = AllocatePool (StrSize (PrivateFile->FilePath) + 1); + if (DriveName == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Done; } StrCpy (DriveName, PrivateFile->FilePath); @@ -1942,7 +1981,7 @@ Returns: &TotalClusters ); if (DriveName) { - gBS->FreePool (DriveName); + FreePool (DriveName); } if (NtStatus) { @@ -1966,7 +2005,8 @@ Returns: NULL ); if (!NtStatus) { - return EFI_DEVICE_ERROR; + Status = EFI_DEVICE_ERROR; + goto Done; } } @@ -1978,7 +2018,8 @@ Returns: if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) { if (*BufferSize < StrSize (PrivateRoot->VolumeLabel)) { *BufferSize = StrSize (PrivateRoot->VolumeLabel); - return EFI_BUFFER_TOO_SMALL; + Status = EFI_BUFFER_TOO_SMALL; + goto Done; } StrCpy ((CHAR16 *) Buffer, PrivateRoot->VolumeLabel); @@ -1986,6 +2027,8 @@ Returns: Status = EFI_SUCCESS; } +Done: + gBS->RestoreTPL (OldTpl); return Status; } @@ -2063,6 +2106,7 @@ Returns: FILETIME NewLastWriteFileTime; WIN32_FIND_DATA FindBuf; EFI_FILE_SYSTEM_INFO *NewFileSystemInfo; + EFI_TPL OldTpl; // // Check for invalid parameters. @@ -2071,6 +2115,8 @@ Returns: return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + // // Initialise locals. // @@ -2087,27 +2133,23 @@ Returns: // if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) { - return EFI_BAD_BUFFER_SIZE; + Status = EFI_BAD_BUFFER_SIZE; + goto Done; } NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer; - gBS->FreePool (PrivateRoot->VolumeLabel); - - PrivateRoot->VolumeLabel = NULL; - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (NewFileSystemInfo->VolumeLabel), - &PrivateRoot->VolumeLabel - ); - - if (EFI_ERROR (Status)) { + FreePool (PrivateRoot->VolumeLabel); + PrivateRoot->VolumeLabel = AllocatePool (StrSize (NewFileSystemInfo->VolumeLabel)); + if (PrivateRoot->VolumeLabel == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } StrCpy (PrivateRoot->VolumeLabel, NewFileSystemInfo->VolumeLabel); - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto Done; } // @@ -2115,20 +2157,24 @@ Returns: // if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) { if (BufferSize < StrSize (PrivateRoot->VolumeLabel)) { - return EFI_BAD_BUFFER_SIZE; + Status = EFI_BAD_BUFFER_SIZE; + goto Done; } StrCpy (PrivateRoot->VolumeLabel, (CHAR16 *) Buffer); - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto Done; } if (!CompareGuid (InformationType, &gEfiFileInfoGuid)) { - return EFI_UNSUPPORTED; + Status = EFI_UNSUPPORTED; + goto Done; } if (BufferSize < SIZE_OF_EFI_FILE_INFO) { - return EFI_BAD_BUFFER_SIZE; + Status = EFI_BAD_BUFFER_SIZE; + goto Done; } // @@ -2144,7 +2190,8 @@ Returns: (NewFileInfo->Attribute &~(EFI_FILE_VALID_ATTR)) || (sizeof (UINTN) == 4 && NewFileInfo->Size > 0xFFFFFFFF) ) { - return EFI_INVALID_PARAMETER; + Status = EFI_INVALID_PARAMETER; + goto Done; } // @@ -2165,9 +2212,9 @@ Returns: goto Done; } - Status = gBS->AllocatePool (EfiBootServicesData, OldInfoSize, &OldFileInfo); - - if (EFI_ERROR (Status)) { + OldFileInfo = AllocatePool (OldInfoSize); + if (OldFileInfo == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -2177,13 +2224,9 @@ Returns: goto Done; } - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (PrivateFile->FileName), - &OldFileName - ); - - if (EFI_ERROR (Status)) { + OldFileName = AllocatePool (StrSize (PrivateFile->FileName)); + if (OldFileName == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -2193,13 +2236,9 @@ Returns: // Make full pathname from new filename and rootpath. // if (NewFileInfo->FileName[0] == '\\') { - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (PrivateRoot->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName), - &NewFileName - ); - - if (EFI_ERROR (Status)) { + NewFileName = AllocatePool (StrSize (PrivateRoot->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName)); + if (NewFileName == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -2207,13 +2246,9 @@ Returns: StrCat (NewFileName, L"\\"); StrCat (NewFileName, NewFileInfo->FileName + 1); } else { - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (PrivateFile->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName), - &NewFileName - ); - - if (EFI_ERROR (Status)) { + NewFileName = AllocatePool (StrSize (PrivateFile->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName)); + if (NewFileName == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } @@ -2319,30 +2354,22 @@ Returns: // // modify file name // - gBS->FreePool (PrivateFile->FileName); - - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (NewFileName), - &PrivateFile->FileName - ); + FreePool (PrivateFile->FileName); - if (EFI_ERROR (Status)) { + PrivateFile->FileName = AllocatePool (StrSize (NewFileName)); + if (PrivateFile->FileName == NULL) { + Status = EFI_OUT_OF_RESOURCES; goto Done; } StrCpy (PrivateFile->FileName, NewFileName); - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (NewFileName) + StrSize (L"\\*"), - &TempFileName - ); + TempFileName = AllocatePool (StrSize (NewFileName) + StrSize (L"\\*")); StrCpy (TempFileName, NewFileName); if (!PrivateFile->IsDirectoryPath) { - PrivateFile->LHandle = PrivateFile->WinNtThunk->CreateFile ( + PrivateFile->LHandle = PrivateFile->WinNtThunk->CreateFile ( TempFileName, PrivateFile->IsOpenedByRead ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, @@ -2352,7 +2379,7 @@ Returns: NULL ); - gBS->FreePool (TempFileName); + FreePool (TempFileName); // // Flush buffers just in case @@ -2375,7 +2402,7 @@ Returns: StrCat (TempFileName, L"\\*"); PrivateFile->LHandle = PrivateFile->WinNtThunk->FindFirstFile (TempFileName, &FindBuf); - gBS->FreePool (TempFileName); + FreePool (TempFileName); } } else { Reopen: ; @@ -2387,11 +2414,7 @@ Reopen: ; goto Done; } - Status = gBS->AllocatePool ( - EfiBootServicesData, - StrSize (OldFileName) + StrSize (L"\\*"), - &TempFileName - ); + TempFileName = AllocatePool (StrSize (OldFileName) + StrSize (L"\\*")); StrCpy (TempFileName, OldFileName); @@ -2420,7 +2443,7 @@ Reopen: ; PrivateFile->LHandle = PrivateFile->WinNtThunk->FindFirstFile (TempFileName, &FindBuf); } - gBS->FreePool (TempFileName); + FreePool (TempFileName); goto Done; @@ -2562,17 +2585,18 @@ Reopen: ; Done: if (OldFileInfo != NULL) { - gBS->FreePool (OldFileInfo); + FreePool (OldFileInfo); } if (OldFileName != NULL) { - gBS->FreePool (OldFileName); + FreePool (OldFileName); } if (NewFileName != NULL) { - gBS->FreePool (NewFileName); + FreePool (NewFileName); } + gBS->RestoreTPL (OldTpl); return Status; } @@ -2612,35 +2636,47 @@ Returns: { BY_HANDLE_FILE_INFORMATION FileInfo; WIN_NT_EFI_FILE_PRIVATE *PrivateFile; + EFI_STATUS Status; + EFI_TPL OldTpl; if (This == NULL) { return EFI_INVALID_PARAMETER; } + OldTpl = gBS->RaiseTPL (EFI_TPL_CALLBACK); + PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This); if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) { - return EFI_DEVICE_ERROR; + Status = EFI_DEVICE_ERROR; + goto Done; } if (PrivateFile->IsDirectoryPath) { - return EFI_SUCCESS; + Status = EFI_SUCCESS; + goto Done; } if (PrivateFile->IsOpenedByRead) { - return EFI_ACCESS_DENIED; + Status = EFI_ACCESS_DENIED; + goto Done; } PrivateFile->WinNtThunk->GetFileInformationByHandle (PrivateFile->LHandle, &FileInfo); if (FileInfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY) { - return EFI_ACCESS_DENIED; + Status = EFI_ACCESS_DENIED; + goto Done; } - return PrivateFile->WinNtThunk->FlushFileBuffers (PrivateFile->LHandle) ? EFI_SUCCESS : EFI_DEVICE_ERROR; + Status = PrivateFile->WinNtThunk->FlushFileBuffers (PrivateFile->LHandle) ? EFI_SUCCESS : EFI_DEVICE_ERROR; +Done: + gBS->RestoreTPL (OldTpl); + return Status; // // bugbug: - Use Windows error reporting. // } +