X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;ds=sidebyside;f=Nt32Pkg%2FWinNtSimpleFileSystemDxe%2FWinNtSimpleFileSystem.c;h=f13f82eee22be537d17d5007b64d3fe51fc492bd;hb=4d5d7812786db947e476b4d850698b465d0e2d99;hp=92fb38415fa1be91fc04284a48ffccb7a0d7f7c7;hpb=6c28f1182f51404e8e341740c3e548b0c63d0d1d;p=mirror_edk2.git diff --git a/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c b/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c index 92fb38415f..f13f82eee2 100644 --- a/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c +++ b/Nt32Pkg/WinNtSimpleFileSystemDxe/WinNtSimpleFileSystem.c @@ -1,13 +1,7 @@ -/*++ - -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 +/**@file -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 - 2017, Intel Corporation. All rights reserved.
+SPDX-License-Identifier: BSD-2-Clause-Patent Module Name: @@ -22,7 +16,7 @@ Abstract: * Other names and brands may be claimed as the property of others. ---*/ +**/ // // The package level header files this module uses @@ -255,7 +249,7 @@ Returns: Status = gBS->OpenProtocol ( ControllerHandle, &gEfiWinNtIoProtocolGuid, - &WinNtIo, + (VOID **) &WinNtIo, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER @@ -328,7 +322,7 @@ Returns: Status = gBS->OpenProtocol ( ControllerHandle, &gEfiWinNtIoProtocolGuid, - &WinNtIo, + (VOID **) &WinNtIo, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_BY_DRIVER @@ -459,7 +453,7 @@ Returns: Status = gBS->OpenProtocol ( ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, - &SimpleFileSystem, + (VOID **) &SimpleFileSystem, This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL @@ -504,7 +498,7 @@ EFI_STATUS EFIAPI WinNtSimpleFileSystemOpenVolume ( IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, - OUT EFI_FILE **Root + OUT EFI_FILE_PROTOCOL **Root ) /*++ @@ -543,6 +537,8 @@ Returns: WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE *Private; WIN_NT_EFI_FILE_PRIVATE *PrivateFile; EFI_TPL OldTpl; + CHAR16 *TempFileName; + UINTN Size; if (This == NULL || Root == NULL) { return EFI_INVALID_PARAMETER; @@ -589,10 +585,50 @@ Returns: PrivateFile->EfiFile.GetInfo = WinNtSimpleFileSystemGetInfo; PrivateFile->EfiFile.SetInfo = WinNtSimpleFileSystemSetInfo; PrivateFile->EfiFile.Flush = WinNtSimpleFileSystemFlush; - PrivateFile->LHandle = INVALID_HANDLE_VALUE; - PrivateFile->DirHandle = INVALID_HANDLE_VALUE; PrivateFile->IsValidFindBuf = FALSE; + // + // Set DirHandle + // + PrivateFile->DirHandle = PrivateFile->WinNtThunk->CreateFile ( + PrivateFile->FilePath, + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS, + NULL + ); + + if (PrivateFile->DirHandle == INVALID_HANDLE_VALUE) { + Status = EFI_NOT_FOUND; + goto Done; + } + + // + // Find the first file under it + // + Size = StrSize (PrivateFile->FilePath); + Size += StrSize (L"\\*"); + Status = gBS->AllocatePool ( + EfiBootServicesData, + Size, + (VOID **)&TempFileName + ); + if (EFI_ERROR (Status)) { + goto Done; + } + StrCpy (TempFileName, PrivateFile->FilePath); + StrCat (TempFileName, L"\\*"); + + PrivateFile->LHandle = PrivateFile->WinNtThunk->FindFirstFile (TempFileName, &PrivateFile->FindBuf); + FreePool (TempFileName); + + if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) { + PrivateFile->IsValidFindBuf = FALSE; + } else { + PrivateFile->IsValidFindBuf = TRUE; + } *Root = &PrivateFile->EfiFile; Status = EFI_SUCCESS; @@ -617,14 +653,170 @@ Done: return Status; } +/** + Count the number of Leading Dot in FileNameToken. + + @param FileNameToken A string representing a token in the path name. + + @return UINTN The number of leading dot in the name. + +**/ +UINTN +CountLeadingDots ( + IN CONST CHAR16 * FileNameToken + ) +{ + UINTN Num; + + Num = 0; + while (*FileNameToken == L'.') { + Num++; + FileNameToken++; + } + + return Num; +} + +BOOLEAN +IsFileNameTokenValid ( + IN CONST CHAR16 * FileNameToken + ) +{ + UINTN Num; + if (StrStr (FileNameToken, L"/") != NULL) { + // + // No L'/' in file name. + // + return FALSE; + } else { + // + // If Token has all dot, the number should not exceed 2 + // + Num = CountLeadingDots (FileNameToken); + + if (Num == StrLen (FileNameToken)) { + // + // If the FileNameToken only contains a number of L'.'. + // + if (Num > 2) { + return FALSE; + } + } + } + + return TRUE; +} + +/** + Return the first string token found in the indirect pointer a String named by FileName. + + On input, FileName is a indirect pointer pointing to a String. + On output, FileName is a updated to point to the next character after the first + found L"\" or NULL if there is no L"\" found. + + @param FileName A indirect pointer pointing to a FileName. + + @return Token The first string token found before a L"\". + +**/ +CHAR16 * +GetNextFileNameToken ( + IN OUT CONST CHAR16 ** FileName + ) +{ + CHAR16 *SlashPos; + CHAR16 *Token; + UINTN Offset; + ASSERT (**FileName != L'\\'); + ASSERT (**FileName != L'\0'); + + SlashPos = StrStr (*FileName, L"\\"); + if (SlashPos == NULL) { + Token = AllocateCopyPool (StrSize(*FileName), *FileName); + *FileName = NULL; + } else { + Offset = SlashPos - *FileName; + Token = AllocateZeroPool ((Offset + 1) * sizeof (CHAR16)); + StrnCpy (Token, *FileName, Offset); + // + // Point *FileName to the next character after L'\'. + // + *FileName = *FileName + Offset + 1; + // + // If *FileName is an empty string, then set *FileName to NULL + // + if (**FileName == L'\0') { + *FileName = NULL; + } + } + + return Token; +} + +/** + Check if a FileName contains only Valid Characters. + + If FileName contains only a single L'\', return TRUE. + If FileName contains two adjacent L'\', return FALSE. + If FileName conatins L'/' , return FALSE. + If FielName contains more than two dots seperated with other FileName characters + by L'\', return FALSE. For example, L'.\...\filename.txt' is invalid path name. But L'..TwoDots\filename.txt' is valid path name. + + @param FileName The File Name String to check. + + @return TRUE FileName only contains valid characters. + @return FALSE FileName contains at least one invalid character. + +**/ + +BOOLEAN +IsFileNameValid ( + IN CONST CHAR16 *FileName + ) +{ + CHAR16 *Token; + BOOLEAN Valid; + + // + // If FileName is just L'\', then it is a valid pathname. + // + if (StrCmp (FileName, L"\\") == 0) { + return TRUE; + } + // + // We don't support two or more adjacent L'\'. + // + if (StrStr (FileName, L"\\\\") != NULL) { + return FALSE; + } + + // + // Is FileName has a leading L"\", skip to next character. + // + if (FileName [0] == L'\\') { + FileName++; + } + + do { + Token = GetNextFileNameToken (&FileName); + Valid = IsFileNameTokenValid (Token); + FreePool (Token); + + if (!Valid) + return FALSE; + } while (FileName != NULL); + + return TRUE; +} + EFI_STATUS EFIAPI WinNtSimpleFileSystemOpen ( - IN EFI_FILE *This, - OUT EFI_FILE **NewHandle, - IN CHAR16 *FileName, - IN UINT64 OpenMode, - IN UINT64 Attributes + IN EFI_FILE_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **NewHandle, + IN CHAR16 *FileName, + IN UINT64 OpenMode, + IN UINT64 Attributes ) /*++ @@ -672,7 +864,6 @@ Returns: // TODO: EFI_INVALID_PARAMETER - add return value to function comment // TODO: EFI_INVALID_PARAMETER - add return value to function comment { - EFI_FILE *Root; WIN_NT_EFI_FILE_PRIVATE *PrivateFile; WIN_NT_EFI_FILE_PRIVATE *NewPrivateFile; WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot; @@ -687,6 +878,7 @@ Returns: BOOLEAN LoopFinish; UINTN InfoSize; EFI_FILE_INFO *Info; + UINTN Size; // // Check for obvious invalid parameters. @@ -733,29 +925,16 @@ Returns: StrCpy (TempFileName, FileName); FileName = TempFileName; - // - // BUGBUG: assume an open of root - // if current location, return current data - // - if (StrCmp (FileName, L"\\") == 0 || (StrCmp (FileName, L".") == 0 && PrivateFile->IsRootDirectory)) { - // - // BUGBUG: assume an open root - // -OpenRoot: - Status = WinNtSimpleFileSystemOpenVolume (PrivateFile->SimpleFileSystem, &Root); - NewPrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (Root); - goto Done; - } - if (FileName[StrLen (FileName) - 1] == L'\\') { FileName[StrLen (FileName) - 1] = 0; } // - // If file name does not equal to "." or "..", + // If file name does not equal to "." or ".." and not trailed with "\..", // then we trim the leading/trailing blanks and trailing dots // - if (StrCmp (FileName, L".") != 0 && StrCmp (FileName, L"..") != 0) { + if (StrCmp (FileName, L".") != 0 && StrCmp (FileName, L"..") != 0 && + ((StrLen (FileName) >= 3) ? (StrCmp (&FileName[StrLen (FileName) - 3], L"\\..") != 0) : TRUE)) { // // Trim leading blanks // @@ -767,10 +946,10 @@ OpenRoot: } CutPrefix (FileName, Count); // - // Trim trailing dots and blanks + // Trim trailing blanks // for (TempFileName = FileName + StrLen (FileName) - 1; - TempFileName >= FileName && (*TempFileName == L' ' || *TempFileName == L'.'); + TempFileName >= FileName && (*TempFileName == L' '); TempFileName--) { ; } @@ -800,7 +979,10 @@ OpenRoot: StrCpy (NewPrivateFile->FilePath, PrivateFile->FilePath); } - NewPrivateFile->FileName = AllocatePool (StrSize (NewPrivateFile->FilePath) + StrSize (L"\\") + StrSize (FileName)); + Size = StrSize (NewPrivateFile->FilePath); + Size += StrSize (L"\\"); + Size += StrSize (FileName); + NewPrivateFile->FileName = AllocatePool (Size); if (NewPrivateFile->FileName == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Done; @@ -821,6 +1003,11 @@ OpenRoot: } } + if (!IsFileNameValid (NewPrivateFile->FileName)) { + Status = EFI_NOT_FOUND; + goto Done; + } + // // Get rid of . and .., except leading . or .. // @@ -877,22 +1064,17 @@ OpenRoot: } } - if (StrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) { - NewPrivateFile->IsRootDirectory = TRUE; - FreePool (NewPrivateFile->FilePath); - FreePool (NewPrivateFile->FileName); - FreePool (NewPrivateFile); - goto OpenRoot; - } - RealFileName = NewPrivateFile->FileName; while (EfiStrChr (RealFileName, L'\\') != NULL) { RealFileName = EfiStrChr (RealFileName, L'\\') + 1; } - TempChar = *(RealFileName - 1); - *(RealFileName - 1) = 0; - + TempChar = 0; + if (RealFileName != NewPrivateFile->FileName) { + TempChar = *(RealFileName - 1); + *(RealFileName - 1) = 0; + } + FreePool (NewPrivateFile->FilePath); NewPrivateFile->FilePath = NULL; NewPrivateFile->FilePath = AllocatePool (StrSize (NewPrivateFile->FileName)); @@ -902,8 +1084,9 @@ OpenRoot: } StrCpy (NewPrivateFile->FilePath, NewPrivateFile->FileName); - - *(RealFileName - 1) = TempChar; + if (TempChar != 0) { + *(RealFileName - 1) = TempChar; + } NewPrivateFile->IsRootDirectory = FALSE; @@ -951,7 +1134,9 @@ OpenRoot: // if (NewPrivateFile->IsDirectoryPath) { - TempFileName = AllocatePool (StrSize (NewPrivateFile->FileName) + StrSize (L"\\*")); + Size = StrSize (NewPrivateFile->FileName); + Size += StrSize (L"\\*"); + TempFileName = AllocatePool (Size); if (TempFileName == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Done; @@ -1004,6 +1189,7 @@ OpenRoot: Status = EFI_NOT_FOUND; } + FreePool (TempFileName); goto Done; } @@ -1012,6 +1198,7 @@ OpenRoot: // StrCat (TempFileName, L"\\*"); NewPrivateFile->LHandle = NewPrivateFile->WinNtThunk->FindFirstFile (TempFileName, &NewPrivateFile->FindBuf); + FreePool (TempFileName); if (NewPrivateFile->LHandle == INVALID_HANDLE_VALUE) { NewPrivateFile->IsValidFindBuf = FALSE; @@ -1092,15 +1279,17 @@ OpenRoot: Status = WinNtSimpleFileSystemGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info); if (EFI_ERROR (Status)) { + FreePool (Info); goto Done; } Info->Attribute = Attributes; WinNtSimpleFileSystemSetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, InfoSize, Info); + FreePool (Info); } -Done: ; +Done: FreePool (FileName); if (EFI_ERROR (Status)) { @@ -1117,6 +1306,9 @@ Done: ; } } else { *NewHandle = &NewPrivateFile->EfiFile; + if (StrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) { + NewPrivateFile->IsRootDirectory = TRUE; + } } return Status; @@ -1125,7 +1317,7 @@ Done: ; EFI_STATUS EFIAPI WinNtSimpleFileSystemClose ( - IN EFI_FILE *This + IN EFI_FILE_PROTOCOL *This ) /*++ @@ -1174,6 +1366,10 @@ Returns: FreePool (PrivateFile->FileName); } + if (PrivateFile->FilePath) { + FreePool (PrivateFile->FilePath); + } + FreePool (PrivateFile); gBS->RestoreTPL (OldTpl); @@ -1184,7 +1380,7 @@ Returns: EFI_STATUS EFIAPI WinNtSimpleFileSystemDelete ( - IN EFI_FILE *This + IN EFI_FILE_PROTOCOL *This ) /*++ @@ -1244,6 +1440,7 @@ Returns: } FreePool (PrivateFile->FileName); + FreePool (PrivateFile->FilePath); FreePool (PrivateFile); gBS->RestoreTPL (OldTpl); @@ -1251,7 +1448,6 @@ Returns: return Status; } -STATIC VOID WinNtSystemTimeToEfiTime ( IN SYSTEMTIME *SystemTime, @@ -1290,12 +1486,36 @@ Returns: } } +/** + Convert the FileTime to EfiTime. + + @param PrivateFile Pointer to WIN_NT_EFI_FILE_PRIVATE. + @param TimeZone Pointer to the current time zone. + @param FileTime Pointer to file time. + @param EfiTime Pointer to EFI time. +**/ +VOID +WinNtFileTimeToEfiTime ( + IN CONST WIN_NT_EFI_FILE_PRIVATE *PrivateFile, + IN TIME_ZONE_INFORMATION *TimeZone, + IN CONST FILETIME *FileTime, + OUT EFI_TIME *EfiTime + ) +{ + FILETIME TempFileTime; + SYSTEMTIME SystemTime; + + PrivateFile->WinNtThunk->FileTimeToLocalFileTime (FileTime, &TempFileTime); + PrivateFile->WinNtThunk->FileTimeToSystemTime (&TempFileTime, &SystemTime); + WinNtSystemTimeToEfiTime (&SystemTime, TimeZone, EfiTime); +} + EFI_STATUS EFIAPI WinNtSimpleFileSystemRead ( - IN EFI_FILE *This, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ) /*++ @@ -1333,7 +1553,6 @@ Returns: UINTN NameSize; UINTN ResultSize; UINTN Index; - SYSTEMTIME SystemTime; EFI_FILE_INFO *Info; WCHAR *pw; TIME_ZONE_INFORMATION TimeZone; @@ -1405,12 +1624,12 @@ Returns: } Status = PrivateFile->WinNtThunk->ReadFile ( - PrivateFile->LHandle, - Buffer, - *BufferSize, - BufferSize, - NULL - ) ? EFI_SUCCESS : EFI_DEVICE_ERROR; + PrivateFile->LHandle, + Buffer, + (DWORD)*BufferSize, + (LPDWORD)BufferSize, + NULL + ) ? EFI_SUCCESS : EFI_DEVICE_ERROR; goto Done; } @@ -1440,24 +1659,9 @@ Returns: Info->Size = ResultSize; PrivateFile->WinNtThunk->GetTimeZoneInformation (&TimeZone); - - PrivateFile->WinNtThunk->FileTimeToLocalFileTime ( - &PrivateFile->FindBuf.ftCreationTime, - &PrivateFile->FindBuf.ftCreationTime - ); - - PrivateFile->WinNtThunk->FileTimeToSystemTime (&PrivateFile->FindBuf.ftCreationTime, &SystemTime); - - WinNtSystemTimeToEfiTime (&SystemTime, &TimeZone, &Info->CreateTime); - - PrivateFile->WinNtThunk->FileTimeToLocalFileTime ( - &PrivateFile->FindBuf.ftLastWriteTime, - &PrivateFile->FindBuf.ftLastWriteTime - ); - - PrivateFile->WinNtThunk->FileTimeToSystemTime (&PrivateFile->FindBuf.ftLastWriteTime, &SystemTime); - - WinNtSystemTimeToEfiTime (&SystemTime, &TimeZone, &Info->ModificationTime); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.ftCreationTime, &Info->CreateTime); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.ftLastAccessTime, &Info->LastAccessTime); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.ftLastWriteTime, &Info->ModificationTime); Info->FileSize = PrivateFile->FindBuf.nFileSizeLow; @@ -1508,9 +1712,9 @@ Done: EFI_STATUS EFIAPI WinNtSimpleFileSystemWrite ( - IN EFI_FILE *This, - IN OUT UINTN *BufferSize, - IN VOID *Buffer + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + IN VOID *Buffer ) /*++ @@ -1576,12 +1780,12 @@ Returns: } Status = PrivateFile->WinNtThunk->WriteFile ( - PrivateFile->LHandle, - Buffer, - *BufferSize, - BufferSize, - NULL - ) ? EFI_SUCCESS : EFI_DEVICE_ERROR; + PrivateFile->LHandle, + Buffer, + (DWORD)*BufferSize, + (LPDWORD)BufferSize, + NULL + ) ? EFI_SUCCESS : EFI_DEVICE_ERROR; Done: gBS->RestoreTPL (OldTpl); @@ -1595,8 +1799,8 @@ Done: EFI_STATUS EFIAPI WinNtSimpleFileSystemSetPosition ( - IN EFI_FILE *This, - IN UINT64 Position + IN EFI_FILE_PROTOCOL *This, + IN UINT64 Position ) /*++ @@ -1625,6 +1829,7 @@ Returns: UINT32 PosHigh; CHAR16 *FileName; EFI_TPL OldTpl; + UINTN Size; if (This == NULL) { return EFI_INVALID_PARAMETER; @@ -1640,7 +1845,9 @@ Returns: goto Done; } - FileName = AllocatePool (StrSize (PrivateFile->FileName) + StrSize (L"\\*")); + Size = StrSize (PrivateFile->FileName); + Size += StrSize (L"\\*"); + FileName = AllocatePool (Size); if (FileName == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Done; @@ -1670,7 +1877,7 @@ Returns: } else { PosHigh = (UINT32) RShiftU64 (Position, 32); - PosLow = PrivateFile->WinNtThunk->SetFilePointer (PrivateFile->LHandle, (ULONG) Position, &PosHigh, FILE_BEGIN); + PosLow = PrivateFile->WinNtThunk->SetFilePointer (PrivateFile->LHandle, (ULONG) Position, (PLONG)&PosHigh, FILE_BEGIN); } Status = (PosLow == 0xFFFFFFFF) ? EFI_DEVICE_ERROR : EFI_SUCCESS; @@ -1684,8 +1891,8 @@ Done: EFI_STATUS EFIAPI WinNtSimpleFileSystemGetPosition ( - IN EFI_FILE *This, - OUT UINT64 *Position + IN EFI_FILE_PROTOCOL *This, + OUT UINT64 *Position ) /*++ @@ -1733,11 +1940,11 @@ Returns: PositionHigh = 0; *Position = PrivateFile->WinNtThunk->SetFilePointer ( - PrivateFile->LHandle, - 0, - &PositionHigh, - FILE_CURRENT - ); + PrivateFile->LHandle, + 0, + (PLONG)&PositionHigh, + FILE_CURRENT + ); Status = *Position == 0xffffffff ? EFI_DEVICE_ERROR : EFI_SUCCESS; if (EFI_ERROR (Status)) { @@ -1753,7 +1960,6 @@ Done: return Status; } -STATIC EFI_STATUS WinNtSimpleFileSystemFileInfo ( IN WIN_NT_EFI_FILE_PRIVATE *PrivateFile, @@ -1784,18 +1990,24 @@ Returns: UINTN ResultSize; EFI_FILE_INFO *Info; BY_HANDLE_FILE_INFORMATION FileInfo; - SYSTEMTIME SystemTime; CHAR16 *RealFileName; CHAR16 *TempPointer; - EFI_FILE_INFO *DirInfo; - UINTN ReadSize; - UINT64 Location; - EFI_STATUS DirStatus; - + TIME_ZONE_INFORMATION TimeZone; Size = SIZE_OF_EFI_FILE_INFO; - NameSize = StrSize (PrivateFile->FileName); - ResultSize = Size + NameSize; + + RealFileName = PrivateFile->FileName; + TempPointer = RealFileName; + while (*TempPointer) { + if (*TempPointer == '\\') { + RealFileName = TempPointer + 1; + } + + TempPointer++; + } + NameSize = StrSize (RealFileName); + + ResultSize = Size + NameSize; Status = EFI_BUFFER_TOO_SMALL; if (*BufferSize >= ResultSize) { @@ -1812,29 +2024,10 @@ Returns: Info->FileSize = FileInfo.nFileSizeLow; Info->PhysicalSize = Info->FileSize; - PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftCreationTime, &SystemTime); - Info->CreateTime.Year = SystemTime.wYear; - Info->CreateTime.Month = (UINT8) SystemTime.wMonth; - Info->CreateTime.Day = (UINT8) SystemTime.wDay; - Info->CreateTime.Hour = (UINT8) SystemTime.wHour; - Info->CreateTime.Minute = (UINT8) SystemTime.wMinute; - Info->CreateTime.Second = (UINT8) SystemTime.wSecond; - - PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftLastAccessTime, &SystemTime); - Info->LastAccessTime.Year = SystemTime.wYear; - Info->LastAccessTime.Month = (UINT8) SystemTime.wMonth; - Info->LastAccessTime.Day = (UINT8) SystemTime.wDay; - Info->LastAccessTime.Hour = (UINT8) SystemTime.wHour; - Info->LastAccessTime.Minute = (UINT8) SystemTime.wMinute; - Info->LastAccessTime.Second = (UINT8) SystemTime.wSecond; - - PrivateFile->WinNtThunk->FileTimeToSystemTime (&FileInfo.ftLastWriteTime, &SystemTime); - Info->ModificationTime.Year = SystemTime.wYear; - Info->ModificationTime.Month = (UINT8) SystemTime.wMonth; - Info->ModificationTime.Day = (UINT8) SystemTime.wDay; - Info->ModificationTime.Hour = (UINT8) SystemTime.wHour; - Info->ModificationTime.Minute = (UINT8) SystemTime.wMinute; - Info->ModificationTime.Second = (UINT8) SystemTime.wSecond; + PrivateFile->WinNtThunk->GetTimeZoneInformation (&TimeZone); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &FileInfo.ftCreationTime, &Info->CreateTime); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &FileInfo.ftLastAccessTime, &Info->LastAccessTime); + WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &FileInfo.ftLastWriteTime, &Info->ModificationTime); if (FileInfo.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) { Info->Attribute |= EFI_FILE_ARCHIVE; @@ -1860,61 +2053,11 @@ Returns: Info->Attribute |= EFI_FILE_DIRECTORY; } - RealFileName = PrivateFile->FileName; - TempPointer = RealFileName; - - while (*TempPointer) { - if (*TempPointer == '\\') { - RealFileName = TempPointer + 1; - } - - TempPointer++; - } - if (PrivateFile->IsRootDirectory) { *((CHAR8 *) Buffer + Size) = 0; } 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; @@ -1924,10 +2067,10 @@ Returns: EFI_STATUS EFIAPI WinNtSimpleFileSystemGetInfo ( - IN EFI_FILE *This, - IN EFI_GUID *InformationType, - IN OUT UINTN *BufferSize, - OUT VOID *Buffer + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer ) /*++ @@ -2045,10 +2188,10 @@ Returns: // NtStatus = PrivateFile->WinNtThunk->GetDiskFreeSpace ( DriveNameFound ? DriveName : NULL, - &SectorsPerCluster, - &BytesPerSector, - &FreeClusters, - &TotalClusters + (LPDWORD)&SectorsPerCluster, + (LPDWORD)&BytesPerSector, + (LPDWORD)&FreeClusters, + (LPDWORD)&TotalClusters ); if (DriveName) { FreePool (DriveName); @@ -2105,7 +2248,7 @@ Done: EFI_STATUS EFIAPI WinNtSimpleFileSystemSetInfo ( - IN EFI_FILE *This, + IN EFI_FILE_PROTOCOL*This, IN EFI_GUID *InformationType, IN UINTN BufferSize, IN VOID *Buffer @@ -2177,6 +2320,7 @@ Returns: WIN32_FIND_DATA FindBuf; EFI_FILE_SYSTEM_INFO *NewFileSystemInfo; EFI_TPL OldTpl; + UINTN Size; // // Check for invalid parameters. @@ -2202,12 +2346,12 @@ Returns: // Set file system information. // if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) { - if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) { + NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer; + if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (NewFileSystemInfo->VolumeLabel)) { Status = EFI_BAD_BUFFER_SIZE; goto Done; } - NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer; FreePool (PrivateRoot->VolumeLabel); PrivateRoot->VolumeLabel = AllocatePool (StrSize (NewFileSystemInfo->VolumeLabel)); @@ -2256,7 +2400,7 @@ Returns: // NewFileInfo = (EFI_FILE_INFO *) Buffer; - if (NewFileInfo->Size <= sizeof (EFI_FILE_INFO) || + if ((NewFileInfo->Size <= SIZE_OF_EFI_FILE_INFO) || (NewFileInfo->Attribute &~(EFI_FILE_VALID_ATTR)) || (sizeof (UINTN) == 4 && NewFileInfo->Size > 0xFFFFFFFF) ) { @@ -2306,7 +2450,10 @@ Returns: // Make full pathname from new filename and rootpath. // if (NewFileInfo->FileName[0] == '\\') { - NewFileName = AllocatePool (StrSize (PrivateRoot->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName)); + Size = StrSize (PrivateRoot->FilePath); + Size += StrSize (L"\\"); + Size += StrSize (NewFileInfo->FileName); + NewFileName = AllocatePool (Size); if (NewFileName == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Done; @@ -2316,7 +2463,10 @@ Returns: StrCat (NewFileName, L"\\"); StrCat (NewFileName, NewFileInfo->FileName + 1); } else { - NewFileName = AllocatePool (StrSize (PrivateFile->FilePath) + StrSize (L"\\") + StrSize (NewFileInfo->FileName)); + Size = StrSize (PrivateFile->FilePath); + Size += StrSize (L"\\"); + Size += StrSize (NewFileInfo->FileName); + NewFileName = AllocatePool (Size); if (NewFileName == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Done; @@ -2434,7 +2584,9 @@ Returns: StrCpy (PrivateFile->FileName, NewFileName); - TempFileName = AllocatePool (StrSize (NewFileName) + StrSize (L"\\*")); + Size = StrSize (NewFileName); + Size += StrSize (L"\\*"); + TempFileName = AllocatePool (Size); StrCpy (TempFileName, NewFileName); @@ -2475,8 +2627,8 @@ Returns: FreePool (TempFileName); } } else { + Status = EFI_ACCESS_DENIED; Reopen: ; - Status = EFI_DEVICE_ERROR; NtStatus = PrivateFile->WinNtThunk->SetFileAttributes (OldFileName, OldAttr); @@ -2484,7 +2636,9 @@ Reopen: ; goto Done; } - TempFileName = AllocatePool (StrSize (OldFileName) + StrSize (L"\\*")); + Size = StrSize (OldFileName); + Size += StrSize (L"\\*"); + TempFileName = AllocatePool (Size); StrCpy (TempFileName, OldFileName); @@ -2575,6 +2729,13 @@ Reopen: ; goto Done; } + if (!PrivateFile->WinNtThunk->LocalFileTimeToFileTime ( + &NewCreationFileTime, + &NewCreationFileTime + )) { + goto Done; + } + NewLastAccessSystemTime.wYear = NewFileInfo->LastAccessTime.Year; NewLastAccessSystemTime.wMonth = NewFileInfo->LastAccessTime.Month; NewLastAccessSystemTime.wDay = NewFileInfo->LastAccessTime.Day; @@ -2590,6 +2751,13 @@ Reopen: ; goto Done; } + if (!PrivateFile->WinNtThunk->LocalFileTimeToFileTime ( + &NewLastAccessFileTime, + &NewLastAccessFileTime + )) { + goto Done; + } + NewLastWriteSystemTime.wYear = NewFileInfo->ModificationTime.Year; NewLastWriteSystemTime.wMonth = NewFileInfo->ModificationTime.Month; NewLastWriteSystemTime.wDay = NewFileInfo->ModificationTime.Day; @@ -2605,6 +2773,13 @@ Reopen: ; goto Done; } + if (!PrivateFile->WinNtThunk->LocalFileTimeToFileTime ( + &NewLastWriteFileTime, + &NewLastWriteFileTime + )) { + goto Done; + } + if (!PrivateFile->WinNtThunk->SetFileTime ( PrivateFile->IsDirectoryPath ? PrivateFile->DirHandle : PrivateFile->LHandle, &NewCreationFileTime, @@ -2650,6 +2825,7 @@ Reopen: ; NtStatus = PrivateFile->WinNtThunk->SetFileAttributes (NewFileName, NewAttr); if (!NtStatus) { + Status = EFI_DEVICE_ERROR; goto Reopen; } @@ -2673,7 +2849,7 @@ Done: EFI_STATUS EFIAPI WinNtSimpleFileSystemFlush ( - IN EFI_FILE *This + IN EFI_FILE_PROTOCOL *This ) /*++