-/*++\r
+/**@file\r
\r
-Copyright (c) 2006 - 2007, Intel Corporation\r
+Copyright (c) 2006 - 2008, 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
\r
* Other names and brands may be claimed as the property of others.\r
\r
---*/\r
+**/\r
\r
//\r
// The package level header files this module uses\r
//\r
// Install driver model protocol(s).\r
//\r
- Status = EfiLibInstallAllDriverProtocols (\r
+ Status = EfiLibInstallDriverBindingComponentName2 (\r
ImageHandle,\r
SystemTable,\r
&gWinNtSimpleFileSystemDriverBinding,\r
ImageHandle,\r
&gWinNtSimpleFileSystemComponentName,\r
- NULL,\r
- NULL\r
+ &gWinNtSimpleFileSystemComponentName2\r
);\r
ASSERT_EFI_ERROR (Status);\r
\r
Status = gBS->OpenProtocol (\r
ControllerHandle,\r
&gEfiWinNtIoProtocolGuid,\r
- &WinNtIo,\r
+ (VOID **) &WinNtIo,\r
This->DriverBindingHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_BY_DRIVER\r
Status = gBS->OpenProtocol (\r
ControllerHandle,\r
&gEfiWinNtIoProtocolGuid,\r
- &WinNtIo,\r
+ (VOID **) &WinNtIo,\r
This->DriverBindingHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_BY_DRIVER\r
\r
Private->ControllerNameTable = NULL;\r
\r
- AddUnicodeString (\r
+ AddUnicodeString2 (\r
"eng",\r
gWinNtSimpleFileSystemComponentName.SupportedLanguages,\r
&Private->ControllerNameTable,\r
- WinNtIo->EnvString\r
+ WinNtIo->EnvString,\r
+ TRUE\r
);\r
+ AddUnicodeString2 (\r
+ "en",\r
+ gWinNtSimpleFileSystemComponentName2.SupportedLanguages,\r
+ &Private->ControllerNameTable,\r
+ WinNtIo->EnvString,\r
+ FALSE\r
+ );\r
+\r
\r
Status = gBS->InstallMultipleProtocolInterfaces (\r
&ControllerHandle,\r
Status = gBS->OpenProtocol (\r
ControllerHandle,\r
&gEfiSimpleFileSystemProtocolGuid,\r
- &SimpleFileSystem,\r
+ (VOID **) &SimpleFileSystem,\r
This->DriverBindingHandle,\r
ControllerHandle,\r
EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
return Status;\r
}\r
\r
+/**\r
+ Count the number of Leading Dot in FileNameToken.\r
+\r
+ @param FileNameToken A string representing a token in the path name.\r
+\r
+ @return UINTN The number of leading dot in the name.\r
+\r
+**/\r
+UINTN\r
+CountLeadingDots (\r
+ IN CONST CHAR16 * FileNameToken\r
+ )\r
+{\r
+ UINTN Num;\r
+\r
+ Num = 0;\r
+ while (*FileNameToken == L'.') {\r
+ Num++;\r
+ FileNameToken++;\r
+ }\r
+ \r
+ return Num;\r
+}\r
+\r
+BOOLEAN \r
+IsFileNameTokenValid (\r
+ IN CONST CHAR16 * FileNameToken\r
+ )\r
+{\r
+ UINTN Num;\r
+ if (StrStr (FileNameToken, L"/") != NULL) {\r
+ //\r
+ // No L'/' in file name.\r
+ //\r
+ return FALSE;\r
+ } else {\r
+ //\r
+ // If Token has all dot, the number should not exceed 2\r
+ //\r
+ Num = CountLeadingDots (FileNameToken);\r
+\r
+ if (Num == StrLen (FileNameToken)) {\r
+ //\r
+ // If the FileNameToken only contains a number of L'.'.\r
+ //\r
+ if (Num > 2) {\r
+ return FALSE;\r
+ }\r
+ }\r
+ }\r
+\r
+ return TRUE;\r
+}\r
+\r
+/**\r
+ Return the first string token found in the indirect pointer a String named by FileName.\r
+\r
+ On input, FileName is a indirect pointer pointing to a String.\r
+ On output, FileName is a updated to point to the next character after the first\r
+ found L"\" or NULL if there is no L"\" found.\r
+\r
+ @param FileName A indirect pointer pointing to a FileName.\r
+\r
+ @return Token The first string token found before a L"\".\r
+\r
+**/\r
+CHAR16 *\r
+GetNextFileNameToken (\r
+ IN OUT CONST CHAR16 ** FileName \r
+ )\r
+{\r
+ CHAR16 *SlashPos;\r
+ CHAR16 *Token;\r
+ UINTN Offset;\r
+ ASSERT (**FileName != L'\\');\r
+ ASSERT (**FileName != L'\0');\r
+\r
+ SlashPos = StrStr (*FileName, L"\\");\r
+ if (SlashPos == NULL) {\r
+ Token = AllocateCopyPool (StrSize(*FileName), *FileName);\r
+ *FileName = NULL;\r
+ } else {\r
+ Offset = SlashPos - *FileName;\r
+ Token = AllocateZeroPool ((Offset + 1) * sizeof (CHAR16));\r
+ StrnCpy (Token, *FileName, Offset);\r
+ //\r
+ // Point *FileName to the next character after L'\'.\r
+ //\r
+ *FileName = *FileName + Offset + 1;\r
+ }\r
+\r
+ return Token;\r
+}\r
+\r
+/**\r
+ Check if a FileName contains only Valid Characters.\r
+\r
+ If FileName contains only a single L'\', return TRUE.\r
+ If FileName contains two adjacent L'\', return FALSE.\r
+ If FileName conatins L'/' , return FALSE.\r
+ If FielName contains more than two dots seperated with other FileName characters\r
+ by L'\', return FALSE. For example, L'.\...\filename.txt' is invalid path name. But L'..TwoDots\filename.txt' is valid path name.\r
+\r
+ @param FileName The File Name String to check.\r
+\r
+ @return TRUE FileName only contains valid characters.\r
+ @return FALSE FileName contains at least one invalid character.\r
+\r
+**/\r
+\r
+BOOLEAN\r
+IsFileNameValid (\r
+ IN CONST CHAR16 *FileName \r
+ )\r
+{\r
+ CHAR16 *Token;\r
+ BOOLEAN Valid;\r
+\r
+ //\r
+ // If FileName is just L'\', then it is a valid pathname. \r
+ //\r
+ if (StrCmp (FileName, L"\\") == 0) {\r
+ return TRUE;\r
+ }\r
+ //\r
+ // We don't support two or more adjacent L'\'.\r
+ //\r
+ if (StrStr (FileName, L"\\\\") != NULL) {\r
+ return FALSE;\r
+ }\r
+\r
+ //\r
+ // Is FileName has a leading L"\", skip to next character.\r
+ //\r
+ if (FileName [0] == L'\\') {\r
+ FileName++;\r
+ }\r
+\r
+ do {\r
+ Token = GetNextFileNameToken (&FileName);\r
+ Valid = IsFileNameTokenValid (Token);\r
+ FreePool (Token);\r
+ \r
+ if (!Valid)\r
+ return FALSE;\r
+ } while (FileName != NULL);\r
+\r
+ return TRUE;\r
+}\r
+\r
EFI_STATUS\r
EFIAPI\r
WinNtSimpleFileSystemOpen (\r
\r
Arguments:\r
\r
- This - A pointer to the source file location.\r
+ This - A pointer to the seource file location.\r
\r
NewHandle - Pointer to storage for the new file handle.\r
\r
BOOLEAN LoopFinish;\r
UINTN InfoSize;\r
EFI_FILE_INFO *Info;\r
+ UINTN Size;\r
\r
//\r
// Check for obvious invalid parameters.\r
}\r
\r
//\r
- // If file name does not equal to "." or "..",\r
+ // If file name does not equal to "." or ".." and not trailed with "\..",\r
// then we trim the leading/trailing blanks and trailing dots\r
//\r
- if (StrCmp (FileName, L".") != 0 && StrCmp (FileName, L"..") != 0) {\r
+ if (StrCmp (FileName, L".") != 0 && StrCmp (FileName, L"..") != 0 && \r
+ ((StrLen (FileName) >= 3) ? (StrCmp (&FileName[StrLen (FileName) - 3], L"\\..") != 0) : TRUE)) {\r
//\r
// Trim leading blanks\r
//\r
}\r
CutPrefix (FileName, Count);\r
//\r
- // Trim trailing dots and blanks\r
+ // Trim trailing blanks\r
//\r
for (TempFileName = FileName + StrLen (FileName) - 1;\r
- TempFileName >= FileName && (*TempFileName == L' ' || *TempFileName == L'.');\r
+ TempFileName >= FileName && (*TempFileName == L' ');\r
TempFileName--) {\r
;\r
}\r
StrCpy (NewPrivateFile->FilePath, PrivateFile->FilePath);\r
}\r
\r
- NewPrivateFile->FileName = AllocatePool (StrSize (NewPrivateFile->FilePath) + StrSize (L"\\") + StrSize (FileName));\r
+ Size = StrSize (NewPrivateFile->FilePath);\r
+ Size += StrSize (L"\\");\r
+ Size += StrSize (FileName);\r
+ NewPrivateFile->FileName = AllocatePool (Size);\r
if (NewPrivateFile->FileName == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
goto Done;\r
}\r
}\r
\r
+ if (!IsFileNameValid (NewPrivateFile->FileName)) {\r
+ Status = EFI_NOT_FOUND;\r
+ goto Done;\r
+ }\r
+\r
//\r
// Get rid of . and .., except leading . or ..\r
//\r
//\r
if (NewPrivateFile->IsDirectoryPath) {\r
\r
- TempFileName = AllocatePool (StrSize (NewPrivateFile->FileName) + StrSize (L"\\*"));\r
+ Size = StrSize (NewPrivateFile->FileName);\r
+ Size += StrSize (L"\\*");\r
+ TempFileName = AllocatePool (Size);\r
if (TempFileName == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
goto Done;\r
WinNtSimpleFileSystemSetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, InfoSize, Info);\r
}\r
\r
-Done: ;\r
+Done:\r
FreePool (FileName);\r
\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
\r
-STATIC\r
VOID\r
WinNtSystemTimeToEfiTime (\r
IN SYSTEMTIME *SystemTime,\r
}\r
\r
Status = PrivateFile->WinNtThunk->ReadFile (\r
- PrivateFile->LHandle,\r
- Buffer,\r
- *BufferSize,\r
- BufferSize,\r
- NULL\r
- ) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
+ PrivateFile->LHandle,\r
+ Buffer,\r
+ *BufferSize,\r
+ (LPDWORD)BufferSize,\r
+ NULL\r
+ ) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
goto Done;\r
}\r
\r
}\r
\r
Status = PrivateFile->WinNtThunk->WriteFile (\r
- PrivateFile->LHandle,\r
- Buffer,\r
- *BufferSize,\r
- BufferSize,\r
- NULL\r
- ) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
+ PrivateFile->LHandle,\r
+ Buffer,\r
+ *BufferSize,\r
+ (LPDWORD)BufferSize,\r
+ NULL\r
+ ) ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
\r
Done:\r
gBS->RestoreTPL (OldTpl);\r
UINT32 PosHigh;\r
CHAR16 *FileName;\r
EFI_TPL OldTpl;\r
+ UINTN Size;\r
\r
if (This == NULL) {\r
return EFI_INVALID_PARAMETER;\r
goto Done;\r
}\r
\r
- FileName = AllocatePool (StrSize (PrivateFile->FileName) + StrSize (L"\\*"));\r
+ Size = StrSize (PrivateFile->FileName);\r
+ Size += StrSize (L"\\*");\r
+ FileName = AllocatePool (Size);\r
if (FileName == NULL) {\r
Status = EFI_OUT_OF_RESOURCES;\r
goto Done;\r
} else {\r
PosHigh = (UINT32) RShiftU64 (Position, 32);\r
\r
- PosLow = PrivateFile->WinNtThunk->SetFilePointer (PrivateFile->LHandle, (ULONG) Position, &PosHigh, FILE_BEGIN);\r
+ PosLow = PrivateFile->WinNtThunk->SetFilePointer (PrivateFile->LHandle, (ULONG) Position, (PLONG)&PosHigh, FILE_BEGIN);\r
}\r
\r
Status = (PosLow == 0xFFFFFFFF) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
\r
PositionHigh = 0;\r
*Position = PrivateFile->WinNtThunk->SetFilePointer (\r
- PrivateFile->LHandle,\r
- 0,\r
- &PositionHigh,\r
- FILE_CURRENT\r
- );\r
+ PrivateFile->LHandle,\r
+ 0,\r
+ (PLONG)&PositionHigh,\r
+ FILE_CURRENT\r
+ );\r
\r
Status = *Position == 0xffffffff ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
\r
-STATIC\r
EFI_STATUS\r
WinNtSimpleFileSystemFileInfo (\r
IN WIN_NT_EFI_FILE_PRIVATE *PrivateFile,\r
//\r
NtStatus = PrivateFile->WinNtThunk->GetDiskFreeSpace (\r
DriveNameFound ? DriveName : NULL,\r
- &SectorsPerCluster,\r
- &BytesPerSector,\r
- &FreeClusters,\r
- &TotalClusters\r
+ (LPDWORD)&SectorsPerCluster,\r
+ (LPDWORD)&BytesPerSector,\r
+ (LPDWORD)&FreeClusters,\r
+ (LPDWORD)&TotalClusters\r
);\r
if (DriveName) {\r
FreePool (DriveName);\r
WIN32_FIND_DATA FindBuf;\r
EFI_FILE_SYSTEM_INFO *NewFileSystemInfo;\r
EFI_TPL OldTpl;\r
+ UINTN Size;\r
\r
//\r
// Check for invalid parameters.\r
//\r
// Make full pathname from new filename and rootpath.\r
//\r
- if (NewFileInfo->FileName[0] == '\\') {\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
+ Size = StrSize (PrivateRoot->FilePath);\r
+ Size += StrSize (L"\\");\r
+ Size += StrSize (NewFileInfo->FileName);\r
+ NewFileName = AllocatePool (Size);\r
+ if (NewFileName == NULL) {\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Done;\r
+ }\r
\r
- StrCpy (NewFileName, PrivateRoot->FilePath);\r
- StrCat (NewFileName, L"\\");\r
+ StrCpy (NewFileName, PrivateRoot->FilePath);\r
+ StrCat (NewFileName, L"\\");\r
+ if (NewFileInfo->FileName[0] == '\\') {\r
StrCat (NewFileName, NewFileInfo->FileName + 1);\r
} else {\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
- StrCpy (NewFileName, PrivateFile->FilePath);\r
- StrCat (NewFileName, L"\\");\r
StrCat (NewFileName, NewFileInfo->FileName);\r
}\r
\r
\r
StrCpy (PrivateFile->FileName, NewFileName);\r
\r
- TempFileName = AllocatePool (StrSize (NewFileName) + StrSize (L"\\*"));\r
+ Size = StrSize (NewFileName);\r
+ Size += StrSize (L"\\*");\r
+ TempFileName = AllocatePool (Size);\r
\r
StrCpy (TempFileName, NewFileName);\r
\r
goto Done;\r
}\r
\r
- TempFileName = AllocatePool (StrSize (OldFileName) + StrSize (L"\\*"));\r
+ Size = StrSize (OldFileName);\r
+ Size += StrSize (L"\\*");\r
+ TempFileName = AllocatePool (Size);\r
\r
StrCpy (TempFileName, OldFileName);\r
\r