12#define WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE SIGNATURE_32 ('N', 'T', 'f', 's')
22#define WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS(a) \
24 WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE, \
26 WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE \
29#define WIN_NT_EFI_FILE_PRIVATE_SIGNATURE SIGNATURE_32 ('l', 'o', 'f', 's')
38 BOOLEAN IsRootDirectory;
39 BOOLEAN IsDirectoryPath;
40 BOOLEAN IsOpenedByRead;
43 BOOLEAN IsValidFindBuf;
44 WIN32_FIND_DATA FindBuf;
47#define WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS(a) \
49 WIN_NT_EFI_FILE_PRIVATE, \
51 WIN_NT_EFI_FILE_PRIVATE_SIGNATURE \
102 while (*Str !=
'\0' && *Str != Chr) {
106 return (*Str == Chr) ? Str :
NULL;
115 if ((Buffer ==
NULL) || (Length == 0)) {
119 if (*(UINT8 *)Buffer != 0) {
124 if (!
CompareMem (Buffer, (UINT8 *)Buffer + 1, Length - 1)) {
140 if (
StrLen (Str) < Count) {
145 for (Pointer = Str; *(Pointer + Count); Pointer++) {
146 *Pointer = *(Pointer + Count);
149 *Pointer = *(Pointer + Count);
177 CHAR16 *TempFileName;
180 if ((This ==
NULL) || (Root ==
NULL)) {
181 return EFI_INVALID_PARAMETER;
184 Private = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);
187 if (PrivateFile ==
NULL) {
188 Status = EFI_OUT_OF_RESOURCES;
193 if (PrivateFile->FileName ==
NULL) {
194 Status = EFI_OUT_OF_RESOURCES;
199 if (PrivateFile->FilePath ==
NULL) {
200 Status = EFI_OUT_OF_RESOURCES;
205 PrivateFile->FilePath,
206 StrSize (Private->FilePath) / sizeof (CHAR16),
210 PrivateFile->FileName,
211 StrSize (Private->FilePath) / sizeof (CHAR16),
212 PrivateFile->FilePath
214 PrivateFile->Signature = WIN_NT_EFI_FILE_PRIVATE_SIGNATURE;
215 PrivateFile->Thunk = Private->Thunk;
216 PrivateFile->SimpleFileSystem = This;
217 PrivateFile->IsRootDirectory =
TRUE;
218 PrivateFile->IsDirectoryPath =
TRUE;
219 PrivateFile->IsOpenedByRead =
TRUE;
220 CopyMem (&PrivateFile->EfiFile, &gWinNtFileProtocol, sizeof (gWinNtFileProtocol));
221 PrivateFile->IsValidFindBuf =
FALSE;
226 PrivateFile->DirHandle = CreateFile (
227 PrivateFile->FilePath,
229 FILE_SHARE_READ | FILE_SHARE_WRITE,
232 FILE_FLAG_BACKUP_SEMANTICS,
236 if (PrivateFile->DirHandle == INVALID_HANDLE_VALUE) {
237 Status = EFI_NOT_FOUND;
244 Size =
StrSize (PrivateFile->FilePath);
247 if (TempFileName ==
NULL) {
251 StrCpyS (TempFileName, Size /
sizeof (CHAR16), PrivateFile->FilePath);
252 StrCatS (TempFileName, Size /
sizeof (CHAR16), L
"\\*");
254 PrivateFile->LHandle = FindFirstFile (TempFileName, &PrivateFile->FindBuf);
257 if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {
258 PrivateFile->IsValidFindBuf =
FALSE;
260 PrivateFile->IsValidFindBuf =
TRUE;
263 *Root = &PrivateFile->EfiFile;
268 if (EFI_ERROR (Status)) {
270 if (PrivateFile->FileName) {
274 if (PrivateFile->FilePath) {
301 while (*FileNameToken == L
'.') {
310IsFileNameTokenValid (
325 Num = CountLeadingDots (FileNameToken);
327 if (Num ==
StrLen (FileNameToken)) {
353GetNextFileNameToken (
361 ASSERT (**FileName != L
'\\');
362 ASSERT (**FileName != L
'\0');
364 SlashPos =
StrStr (*FileName, L
"\\");
365 if (SlashPos ==
NULL) {
369 Offset = SlashPos - *FileName;
371 StrnCpyS (Token, Offset + 1, *FileName, Offset);
375 *FileName = *FileName + Offset + 1;
379 if (**FileName == L
'\0') {
413 if (
StrCmp (FileName, L
"\\") == 0) {
427 if (FileName[0] == L
'\\') {
432 Token = GetNextFileNameToken (&FileName);
433 Valid = IsFileNameTokenValid (Token);
439 }
while (FileName !=
NULL);
477 CHAR16 *RealFileName;
478 CHAR16 *TempFileName;
479 CHAR16 *ParseFileName;
480 CHAR16 *GuardPointer;
492 PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
493 PrivateRoot = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
494 NewPrivateFile =
NULL;
500 if (TempFileName ==
NULL) {
501 return EFI_OUT_OF_RESOURCES;
504 StrCpyS (TempFileName,
StrSize (FileName) /
sizeof (CHAR16), FileName);
505 FileName = TempFileName;
507 if (FileName[
StrLen (FileName) - 1] == L
'\\') {
508 FileName[
StrLen (FileName) - 1] = 0;
515 if ((
StrCmp (FileName, L
".") != 0) && (
StrCmp (FileName, L
"..") != 0) &&
522 for (TempFileName = FileName;
523 *TempFileName != 0 && *TempFileName == L
' ';
529 CutPrefix (FileName, Count);
533 for (TempFileName = FileName +
StrLen (FileName) - 1;
534 TempFileName >= FileName && (*TempFileName == L
' ');
539 *(TempFileName + 1) = 0;
546 if (NewPrivateFile ==
NULL) {
547 Status = EFI_OUT_OF_RESOURCES;
554 if (NewPrivateFile->FilePath ==
NULL) {
555 Status = EFI_OUT_OF_RESOURCES;
559 if (PrivateFile->IsDirectoryPath) {
561 NewPrivateFile->FilePath,
562 StrSize (PrivateFile->FileName) / sizeof (CHAR16),
563 PrivateFile->FileName
567 NewPrivateFile->FilePath,
568 StrSize (PrivateFile->FileName) / sizeof (CHAR16),
569 PrivateFile->FilePath
573 Size =
StrSize (NewPrivateFile->FilePath);
577 if (NewPrivateFile->FileName ==
NULL) {
578 Status = EFI_OUT_OF_RESOURCES;
582 if (*FileName == L
'\\') {
583 StrCpyS (NewPrivateFile->FileName, Size / sizeof (CHAR16), PrivateRoot->FilePath);
584 StrCatS (NewPrivateFile->FileName, Size / sizeof (CHAR16), L
"\\");
585 StrCatS (NewPrivateFile->FileName, Size / sizeof (CHAR16), FileName + 1);
587 StrCpyS (NewPrivateFile->FileName, Size / sizeof (CHAR16), NewPrivateFile->FilePath);
588 if (
StrCmp (FileName, L
"") != 0) {
592 StrCatS (NewPrivateFile->FileName, Size / sizeof (CHAR16), L
"\\");
593 StrCatS (NewPrivateFile->FileName, Size / sizeof (CHAR16), FileName);
597 if (!IsFileNameValid (NewPrivateFile->FileName)) {
598 Status = EFI_NOT_FOUND;
609 GuardPointer = NewPrivateFile->FileName +
StrLen (PrivateRoot->FilePath);
613 while (!LoopFinish) {
616 for (ParseFileName = GuardPointer; *ParseFileName; ParseFileName++) {
617 if ((*ParseFileName == L
'.') &&
618 ((*(ParseFileName + 1) == 0) || (*(ParseFileName + 1) == L
'\\')) &&
619 (*(ParseFileName - 1) == L
'\\')
625 CutPrefix (ParseFileName - 1, 2);
630 if ((*ParseFileName == L
'.') &&
631 (*(ParseFileName + 1) == L
'.') &&
632 ((*(ParseFileName + 2) == 0) || (*(ParseFileName + 2) == L
'\\')) &&
633 (*(ParseFileName - 1) == L
'\\')
639 while (ParseFileName != GuardPointer) {
642 if (*ParseFileName == L
'\\') {
650 CutPrefix (ParseFileName, Count);
657 RealFileName = NewPrivateFile->FileName;
658 while (EfiStrChr (RealFileName, L
'\\') !=
NULL) {
659 RealFileName = EfiStrChr (RealFileName, L
'\\') + 1;
663 if (RealFileName != NewPrivateFile->FileName) {
664 TempChar = *(RealFileName - 1);
665 *(RealFileName - 1) = 0;
668 FreePool (NewPrivateFile->FilePath);
669 NewPrivateFile->FilePath =
NULL;
671 if (NewPrivateFile->FilePath ==
NULL) {
672 Status = EFI_OUT_OF_RESOURCES;
677 NewPrivateFile->FilePath,
678 StrSize (NewPrivateFile->FileName) / sizeof (CHAR16),
679 NewPrivateFile->FileName
682 *(RealFileName - 1) = TempChar;
685 NewPrivateFile->IsRootDirectory =
FALSE;
690 if (OpenMode & EFI_FILE_MODE_CREATE) {
691 if (Attributes & EFI_FILE_DIRECTORY) {
692 NewPrivateFile->IsDirectoryPath =
TRUE;
694 NewPrivateFile->IsDirectoryPath =
FALSE;
697 NewPrivateFile->LHandle = CreateFile (
698 NewPrivateFile->FileName,
700 FILE_SHARE_READ | FILE_SHARE_WRITE,
707 if (NewPrivateFile->LHandle != INVALID_HANDLE_VALUE) {
708 NewPrivateFile->IsDirectoryPath =
FALSE;
709 CloseHandle (NewPrivateFile->LHandle);
711 NewPrivateFile->IsDirectoryPath =
TRUE;
714 NewPrivateFile->LHandle = INVALID_HANDLE_VALUE;
717 if (OpenMode & EFI_FILE_MODE_WRITE) {
718 NewPrivateFile->IsOpenedByRead =
FALSE;
720 NewPrivateFile->IsOpenedByRead =
TRUE;
728 if (NewPrivateFile->IsDirectoryPath) {
729 Size =
StrSize (NewPrivateFile->FileName);
732 if (TempFileName ==
NULL) {
733 Status = EFI_OUT_OF_RESOURCES;
737 StrCpyS (TempFileName, Size /
sizeof (CHAR16), NewPrivateFile->FileName);
739 if ((OpenMode & EFI_FILE_MODE_CREATE)) {
744 LastError = GetLastError ();
745 if (LastError != ERROR_ALREADY_EXISTS) {
747 Status = EFI_ACCESS_DENIED;
753 NewPrivateFile->DirHandle = CreateFile (
755 NewPrivateFile->IsOpenedByRead ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE),
756 FILE_SHARE_READ | FILE_SHARE_WRITE,
759 FILE_FLAG_BACKUP_SEMANTICS,
763 if (NewPrivateFile->DirHandle == INVALID_HANDLE_VALUE) {
764 NewPrivateFile->DirHandle = CreateFile (
767 FILE_SHARE_READ | FILE_SHARE_WRITE,
770 FILE_FLAG_BACKUP_SEMANTICS,
774 if (NewPrivateFile->DirHandle != INVALID_HANDLE_VALUE) {
775 CloseHandle (NewPrivateFile->DirHandle);
776 NewPrivateFile->DirHandle = INVALID_HANDLE_VALUE;
777 Status = EFI_ACCESS_DENIED;
779 Status = EFI_NOT_FOUND;
789 StrCatS (TempFileName, Size /
sizeof (CHAR16), L
"\\*");
790 NewPrivateFile->LHandle = FindFirstFile (TempFileName, &NewPrivateFile->FindBuf);
793 if (NewPrivateFile->LHandle == INVALID_HANDLE_VALUE) {
794 NewPrivateFile->IsValidFindBuf =
FALSE;
796 NewPrivateFile->IsValidFindBuf =
TRUE;
802 if (!NewPrivateFile->IsOpenedByRead) {
803 NewPrivateFile->LHandle = CreateFile (
804 NewPrivateFile->FileName,
805 GENERIC_READ | GENERIC_WRITE,
806 FILE_SHARE_READ | FILE_SHARE_WRITE,
808 (OpenMode & EFI_FILE_MODE_CREATE) ? OPEN_ALWAYS : OPEN_EXISTING,
813 if (NewPrivateFile->LHandle == INVALID_HANDLE_VALUE) {
814 NewPrivateFile->LHandle = CreateFile (
815 NewPrivateFile->FileName,
817 FILE_SHARE_READ | FILE_SHARE_WRITE,
824 if (NewPrivateFile->LHandle == INVALID_HANDLE_VALUE) {
825 Status = EFI_NOT_FOUND;
827 Status = EFI_ACCESS_DENIED;
828 CloseHandle (NewPrivateFile->LHandle);
829 NewPrivateFile->LHandle = INVALID_HANDLE_VALUE;
833 NewPrivateFile->LHandle = CreateFile (
834 NewPrivateFile->FileName,
836 FILE_SHARE_READ | FILE_SHARE_WRITE,
843 if (NewPrivateFile->LHandle == INVALID_HANDLE_VALUE) {
844 Status = EFI_NOT_FOUND;
849 if ((OpenMode & EFI_FILE_MODE_CREATE) && (Status ==
EFI_SUCCESS)) {
856 Status = WinNtFileGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);
858 if (Status != EFI_BUFFER_TOO_SMALL) {
859 Status = EFI_DEVICE_ERROR;
865 Status = EFI_OUT_OF_RESOURCES;
869 Status = WinNtFileGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);
871 if (EFI_ERROR (Status)) {
878 WinNtFileSetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, InfoSize, Info);
885 if (EFI_ERROR (Status)) {
886 if (NewPrivateFile) {
887 if (NewPrivateFile->FileName) {
888 FreePool (NewPrivateFile->FileName);
891 if (NewPrivateFile->FilePath) {
892 FreePool (NewPrivateFile->FilePath);
898 *NewHandle = &NewPrivateFile->EfiFile;
899 if (
StrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) {
900 NewPrivateFile->IsRootDirectory =
TRUE;
922 PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
924 if (PrivateFile->LHandle != INVALID_HANDLE_VALUE) {
925 if (PrivateFile->IsDirectoryPath) {
926 FindClose (PrivateFile->LHandle);
928 CloseHandle (PrivateFile->LHandle);
931 PrivateFile->LHandle = INVALID_HANDLE_VALUE;
934 if (PrivateFile->IsDirectoryPath && (PrivateFile->DirHandle != INVALID_HANDLE_VALUE)) {
935 CloseHandle (PrivateFile->DirHandle);
936 PrivateFile->DirHandle = INVALID_HANDLE_VALUE;
939 if (PrivateFile->FileName) {
943 if (PrivateFile->FilePath) {
969 PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
971 Status = EFI_WARN_DELETE_FAILURE;
973 if (PrivateFile->IsDirectoryPath) {
974 if (PrivateFile->LHandle != INVALID_HANDLE_VALUE) {
975 FindClose (PrivateFile->LHandle);
978 if (PrivateFile->DirHandle != INVALID_HANDLE_VALUE) {
979 CloseHandle (PrivateFile->DirHandle);
980 PrivateFile->DirHandle = INVALID_HANDLE_VALUE;
983 if (RemoveDirectory (PrivateFile->FileName)) {
987 CloseHandle (PrivateFile->LHandle);
988 PrivateFile->LHandle = INVALID_HANDLE_VALUE;
990 if (!PrivateFile->IsOpenedByRead) {
991 if (DeleteFile (PrivateFile->FileName)) {
1005WinNtSystemTimeToEfiTime (
1006 IN SYSTEMTIME *SystemTime,
1007 IN TIME_ZONE_INFORMATION *TimeZone,
1029 Time->Year = (UINT16)SystemTime->wYear;
1030 Time->Month = (UINT8)SystemTime->wMonth;
1031 Time->Day = (UINT8)SystemTime->wDay;
1032 Time->Hour = (UINT8)SystemTime->wHour;
1033 Time->Minute = (UINT8)SystemTime->wMinute;
1034 Time->Second = (UINT8)SystemTime->wSecond;
1035 Time->Nanosecond = (UINT32)SystemTime->wMilliseconds * 1000000;
1036 Time->TimeZone = (INT16)TimeZone->Bias;
1038 if (TimeZone->StandardDate.wMonth) {
1039 Time->Daylight = EFI_TIME_ADJUST_DAYLIGHT;
1052WinNtFileTimeToEfiTime (
1054 IN TIME_ZONE_INFORMATION *TimeZone,
1059 FILETIME TempFileTime;
1060 SYSTEMTIME SystemTime;
1062 FileTimeToLocalFileTime (FileTime, &TempFileTime);
1063 FileTimeToSystemTime (&TempFileTime, &SystemTime);
1064 WinNtSystemTimeToEfiTime (&SystemTime, TimeZone, EfiTime);
1096 TIME_ZONE_INFORMATION TimeZone;
1102 PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1104 if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {
1105 Status = EFI_DEVICE_ERROR;
1109 if (!PrivateFile->IsDirectoryPath) {
1110 if (This->GetPosition (This, &Pos) !=
EFI_SUCCESS) {
1111 Status = EFI_DEVICE_ERROR;
1118 Status = This->GetInfo (
1125 if (Status == EFI_BUFFER_TOO_SMALL) {
1128 Status = This->GetInfo (
1136 if (EFI_ERROR (Status)) {
1137 Status = EFI_DEVICE_ERROR;
1145 if (Pos >= FileSize) {
1147 if (Pos == FileSize) {
1151 Status = EFI_DEVICE_ERROR;
1157 PrivateFile->LHandle,
1160 (LPDWORD)BufferSize,
1169 if (!PrivateFile->IsValidFindBuf) {
1177 NameSize =
StrSize (PrivateFile->FindBuf.cFileName);
1179 ResultSize = Size + NameSize;
1181 Status = EFI_BUFFER_TOO_SMALL;
1183 if (*BufferSize >= ResultSize) {
1189 Info->
Size = ResultSize;
1191 GetTimeZoneInformation (&TimeZone);
1192 WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.ftCreationTime, &Info->
CreateTime);
1193 WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.ftLastAccessTime, &Info->
LastAccessTime);
1194 WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &PrivateFile->FindBuf.ftLastWriteTime, &Info->
ModificationTime);
1196 Info->
FileSize = PrivateFile->FindBuf.nFileSizeLow;
1198 Info->
PhysicalSize = PrivateFile->FindBuf.nFileSizeLow;
1200 if (PrivateFile->FindBuf.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) {
1204 if (PrivateFile->FindBuf.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
1208 if (PrivateFile->FindBuf.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {
1212 if (PrivateFile->FindBuf.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
1216 if (PrivateFile->FindBuf.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1220 NameSize = NameSize /
sizeof (WCHAR);
1222 pw = (WCHAR *)(((CHAR8 *)Buffer) + Size);
1224 for (Index = 0; Index < NameSize; Index++) {
1225 pw[Index] = PrivateFile->FindBuf.cFileName[Index];
1228 if (FindNextFile (PrivateFile->LHandle, &PrivateFile->FindBuf)) {
1229 PrivateFile->IsValidFindBuf =
TRUE;
1231 PrivateFile->IsValidFindBuf =
FALSE;
1235 *BufferSize = ResultSize;
1269 PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1271 if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {
1272 Status = EFI_DEVICE_ERROR;
1276 if (PrivateFile->IsDirectoryPath) {
1277 Status = EFI_UNSUPPORTED;
1281 if (PrivateFile->IsOpenedByRead) {
1282 Status = EFI_ACCESS_DENIED;
1286 Status = WriteFile (
1287 PrivateFile->LHandle,
1290 (LPDWORD)BufferSize,
1313WinNtFileSetPossition (
1325 PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1327 if (PrivateFile->IsDirectoryPath) {
1328 if (Position != 0) {
1329 Status = EFI_UNSUPPORTED;
1333 Size =
StrSize (PrivateFile->FileName);
1336 if (FileName ==
NULL) {
1337 Status = EFI_OUT_OF_RESOURCES;
1341 StrCpyS (FileName, Size /
sizeof (CHAR16), PrivateFile->FileName);
1342 StrCatS (FileName, Size /
sizeof (CHAR16), L
"\\*");
1344 if (PrivateFile->LHandle != INVALID_HANDLE_VALUE) {
1345 FindClose (PrivateFile->LHandle);
1348 PrivateFile->LHandle = FindFirstFile (FileName, &PrivateFile->FindBuf);
1350 if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {
1351 PrivateFile->IsValidFindBuf =
FALSE;
1353 PrivateFile->IsValidFindBuf =
TRUE;
1358 Status = (PrivateFile->LHandle == INVALID_HANDLE_VALUE) ? EFI_DEVICE_ERROR :
EFI_SUCCESS;
1360 if (Position == (UINT64)-1) {
1361 PosLow = SetFilePointer (PrivateFile->LHandle, (ULONG)0,
NULL, FILE_END);
1363 PosHigh = (UINT32)
RShiftU64 (Position, 32);
1365 PosLow = SetFilePointer (PrivateFile->LHandle, (ULONG)Position, (PLONG)&PosHigh, FILE_BEGIN);
1368 Status = (PosLow == 0xFFFFFFFF) ? EFI_DEVICE_ERROR :
EFI_SUCCESS;
1386WinNtFileGetPossition (
1388 OUT UINT64 *Position
1396 PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1401 if (PrivateFile->IsDirectoryPath) {
1402 Status = EFI_UNSUPPORTED;
1406 *Position = SetFilePointer (
1407 PrivateFile->LHandle,
1409 (PLONG)&PositionHigh,
1413 Status = *Position == 0xffffffff ? EFI_DEVICE_ERROR :
EFI_SUCCESS;
1414 if (EFI_ERROR (Status)) {
1418 PosHigh64 = PositionHigh;
1427WinNtSimpleFileSystemFileInfo (
1456 BY_HANDLE_FILE_INFORMATION
FileInfo;
1457 CHAR16 *RealFileName;
1458 CHAR16 *TempPointer;
1459 TIME_ZONE_INFORMATION TimeZone;
1463 RealFileName = PrivateFile->FileName;
1464 TempPointer = RealFileName;
1465 while (*TempPointer) {
1466 if (*TempPointer ==
'\\') {
1467 RealFileName = TempPointer + 1;
1473 NameSize =
StrSize (RealFileName);
1475 ResultSize = Size + NameSize;
1477 Status = EFI_BUFFER_TOO_SMALL;
1478 if (*BufferSize >= ResultSize) {
1484 Info->
Size = ResultSize;
1485 GetFileInformationByHandle (
1486 PrivateFile->IsDirectoryPath ? PrivateFile->DirHandle : PrivateFile->LHandle,
1492 GetTimeZoneInformation (&TimeZone);
1493 WinNtFileTimeToEfiTime (PrivateFile, &TimeZone, &
FileInfo.ftCreationTime, &Info->
CreateTime);
1497 if (
FileInfo.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE) {
1501 if (
FileInfo.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
1505 if (
FileInfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
1509 if (
FileInfo.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {
1513 if (
FileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
1517 if (PrivateFile->IsDirectoryPath) {
1521 if (PrivateFile->IsRootDirectory) {
1522 *((CHAR8 *)Buffer + Size) = 0;
1524 CopyMem ((CHAR8 *)Buffer + Size, RealFileName, NameSize);
1528 *BufferSize = ResultSize;
1561 UINT32 SectorsPerCluster;
1562 UINT32 BytesPerSector;
1563 UINT32 FreeClusters;
1564 UINT32 TotalClusters;
1565 UINT32 BytesPerCluster;
1567 BOOLEAN DriveNameFound;
1572 if ((This ==
NULL) || (InformationType ==
NULL) || (BufferSize ==
NULL)) {
1573 return EFI_INVALID_PARAMETER;
1576 PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1577 PrivateRoot = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
1579 Status = EFI_UNSUPPORTED;
1581 if (
CompareGuid (InformationType, &gEfiFileInfoGuid)) {
1582 Status = WinNtSimpleFileSystemFileInfo (PrivateFile, BufferSize, Buffer);
1585 if (
CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
1588 Status = EFI_BUFFER_TOO_SMALL;
1599 DriveNameFound =
FALSE;
1601 if (DriveName ==
NULL) {
1602 Status = EFI_OUT_OF_RESOURCES;
1608 (
StrSize (PrivateFile->FilePath) + 1) / sizeof (CHAR16),
1609 PrivateFile->FilePath
1611 for (Index = 0; DriveName[Index] != 0 && DriveName[Index] !=
':'; Index++) {
1614 if (DriveName[Index] ==
':') {
1615 DriveName[Index + 1] =
'\\';
1616 DriveName[Index + 2] = 0;
1617 DriveNameFound =
TRUE;
1618 }
else if ((DriveName[0] ==
'\\') && (DriveName[1] ==
'\\')) {
1619 for (Index = 2; DriveName[Index] != 0 && DriveName[Index] !=
'\\'; Index++) {
1622 if (DriveName[Index] ==
'\\') {
1623 DriveNameFound =
TRUE;
1624 for (Index++; DriveName[Index] != 0 && DriveName[Index] !=
'\\'; Index++) {
1627 DriveName[Index] =
'\\';
1628 DriveName[Index + 1] = 0;
1635 NtStatus = GetDiskFreeSpace (
1636 DriveNameFound ? DriveName :
NULL,
1637 (LPDWORD)&SectorsPerCluster,
1638 (LPDWORD)&BytesPerSector,
1639 (LPDWORD)&FreeClusters,
1640 (LPDWORD)&TotalClusters
1650 BytesPerCluster = BytesPerSector * SectorsPerCluster;
1653 FileSystemInfoBuffer->
BlockSize = BytesPerCluster;
1659 NtStatus = GetDiskFreeSpaceEx (
1660 PrivateFile->FilePath,
1661 (PULARGE_INTEGER)(&FileSystemInfoBuffer->
FreeSpace),
1662 (PULARGE_INTEGER)(&FileSystemInfoBuffer->
VolumeSize),
1666 Status = EFI_DEVICE_ERROR;
1674 PrivateRoot->VolumeLabel
1680 if (
CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
1681 if (*BufferSize <
StrSize (PrivateRoot->VolumeLabel)) {
1682 *BufferSize =
StrSize (PrivateRoot->VolumeLabel);
1683 Status = EFI_BUFFER_TOO_SMALL;
1689 *BufferSize /
sizeof (CHAR16),
1690 PrivateRoot->VolumeLabel
1692 *BufferSize =
StrSize (PrivateRoot->VolumeLabel);
1734 CHAR16 *OldFileName;
1735 CHAR16 *NewFileName;
1736 CHAR16 *TempFileName;
1737 CHAR16 *CharPointer;
1738 BOOLEAN AttrChangeFlag;
1739 BOOLEAN NameChangeFlag;
1740 BOOLEAN SizeChangeFlag;
1741 BOOLEAN TimeChangeFlag;
1743 SYSTEMTIME NewCreationSystemTime;
1744 SYSTEMTIME NewLastAccessSystemTime;
1745 SYSTEMTIME NewLastWriteSystemTime;
1746 FILETIME NewCreationFileTime;
1747 FILETIME NewLastAccessFileTime;
1748 FILETIME NewLastWriteFileTime;
1749 WIN32_FIND_DATA FindBuf;
1756 PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
1757 PrivateRoot = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
1759 Status = EFI_UNSUPPORTED;
1760 OldFileInfo = NewFileInfo =
NULL;
1761 OldFileName = NewFileName =
NULL;
1762 AttrChangeFlag = NameChangeFlag = SizeChangeFlag = TimeChangeFlag =
FALSE;
1767 if (
CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
1770 Status = EFI_BAD_BUFFER_SIZE;
1774 FreePool (PrivateRoot->VolumeLabel);
1776 if (PrivateRoot->VolumeLabel ==
NULL) {
1777 Status = EFI_OUT_OF_RESOURCES;
1782 PrivateRoot->VolumeLabel,
1794 if (
CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
1795 if (BufferSize <
StrSize (PrivateRoot->VolumeLabel)) {
1796 Status = EFI_BAD_BUFFER_SIZE;
1801 PrivateRoot->VolumeLabel,
1802 StrSize (PrivateRoot->VolumeLabel) / sizeof (CHAR16),
1810 if (!
CompareGuid (InformationType, &gEfiFileInfoGuid)) {
1811 Status = EFI_UNSUPPORTED;
1816 Status = EFI_BAD_BUFFER_SIZE;
1830 (NewFileInfo->
Attribute &~(EFI_FILE_VALID_ATTR)) ||
1831 ((
sizeof (
UINTN) == 4) && (NewFileInfo->
Size > 0xFFFFFFFF))
1834 Status = EFI_INVALID_PARAMETER;
1849 Status = WinNtSimpleFileSystemFileInfo (PrivateFile, &OldInfoSize,
NULL);
1851 if (Status != EFI_BUFFER_TOO_SMALL) {
1852 Status = EFI_DEVICE_ERROR;
1857 if (OldFileInfo ==
NULL) {
1858 Status = EFI_OUT_OF_RESOURCES;
1862 Status = WinNtSimpleFileSystemFileInfo (PrivateFile, &OldInfoSize, OldFileInfo);
1864 if (EFI_ERROR (Status)) {
1869 if (OldFileName ==
NULL) {
1870 Status = EFI_OUT_OF_RESOURCES;
1876 StrSize (PrivateFile->FileName) / sizeof (CHAR16),
1877 PrivateFile->FileName
1883 if (NewFileInfo->
FileName[0] ==
'\\') {
1884 Size =
StrSize (PrivateRoot->FilePath);
1888 if (NewFileName ==
NULL) {
1889 Status = EFI_OUT_OF_RESOURCES;
1893 StrCpyS (NewFileName, Size /
sizeof (CHAR16), PrivateRoot->FilePath);
1894 StrCatS (NewFileName, Size /
sizeof (CHAR16), L
"\\");
1895 StrCatS (NewFileName, Size /
sizeof (CHAR16), NewFileInfo->
FileName + 1);
1897 Size =
StrSize (PrivateFile->FilePath);
1901 if (NewFileName ==
NULL) {
1902 Status = EFI_OUT_OF_RESOURCES;
1906 StrCpyS (NewFileName, Size /
sizeof (CHAR16), PrivateFile->FilePath);
1907 StrCatS (NewFileName, Size /
sizeof (CHAR16), L
"\\");
1915 if ((NewFileInfo->
Attribute & EFI_FILE_DIRECTORY) != (OldFileInfo->
Attribute & EFI_FILE_DIRECTORY)) {
1916 Status = EFI_INVALID_PARAMETER;
1920 AttrChangeFlag =
TRUE;
1928 NameChangeFlag =
TRUE;
1935 SizeChangeFlag =
TRUE;
1945 TimeChangeFlag =
TRUE;
1950 TimeChangeFlag =
TRUE;
1955 TimeChangeFlag =
TRUE;
1961 if (!(AttrChangeFlag || NameChangeFlag || SizeChangeFlag || TimeChangeFlag)) {
1969 OldAttr = GetFileAttributes (OldFileName);
1974 if (NameChangeFlag) {
1978 if (PrivateFile->IsOpenedByRead) {
1979 Status = EFI_ACCESS_DENIED;
1983 for (CharPointer = NewFileName; *CharPointer != 0 && *CharPointer != L
'/'; CharPointer++) {
1986 if (*CharPointer != 0) {
1987 Status = EFI_ACCESS_DENIED;
1991 if (PrivateFile->LHandle != INVALID_HANDLE_VALUE) {
1992 if (PrivateFile->IsDirectoryPath) {
1993 FindClose (PrivateFile->LHandle);
1995 CloseHandle (PrivateFile->LHandle);
1996 PrivateFile->LHandle = INVALID_HANDLE_VALUE;
2000 if (PrivateFile->IsDirectoryPath && (PrivateFile->DirHandle != INVALID_HANDLE_VALUE)) {
2001 CloseHandle (PrivateFile->DirHandle);
2002 PrivateFile->DirHandle = INVALID_HANDLE_VALUE;
2005 NtStatus = MoveFile (OldFileName, NewFileName);
2014 if (PrivateFile->FileName ==
NULL) {
2015 Status = EFI_OUT_OF_RESOURCES;
2019 StrCpyS (PrivateFile->FileName,
StrSize (NewFileName) /
sizeof (CHAR16), NewFileName);
2025 StrCpyS (TempFileName, Size /
sizeof (CHAR16), NewFileName);
2027 if (!PrivateFile->IsDirectoryPath) {
2028 PrivateFile->LHandle = CreateFile (
2030 PrivateFile->IsOpenedByRead ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,
2031 FILE_SHARE_READ | FILE_SHARE_WRITE,
2043 if (FlushFileBuffers (PrivateFile->LHandle) == 0) {
2044 Status = EFI_DEVICE_ERROR;
2048 PrivateFile->DirHandle = CreateFile (
2050 PrivateFile->IsOpenedByRead ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,
2051 FILE_SHARE_READ | FILE_SHARE_WRITE,
2054 FILE_FLAG_BACKUP_SEMANTICS,
2058 StrCatS (TempFileName, Size /
sizeof (CHAR16), L
"\\*");
2059 PrivateFile->LHandle = FindFirstFile (TempFileName, &FindBuf);
2064 Status = EFI_ACCESS_DENIED;
2067 NtStatus = SetFileAttributes (OldFileName, OldAttr);
2077 StrCpyS (TempFileName, Size /
sizeof (CHAR16), OldFileName);
2079 if (!PrivateFile->IsDirectoryPath) {
2080 PrivateFile->LHandle = CreateFile (
2082 PrivateFile->IsOpenedByRead ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,
2083 FILE_SHARE_READ | FILE_SHARE_WRITE,
2090 PrivateFile->DirHandle = CreateFile (
2092 PrivateFile->IsOpenedByRead ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE,
2093 FILE_SHARE_READ | FILE_SHARE_WRITE,
2096 FILE_FLAG_BACKUP_SEMANTICS,
2100 StrCatS (TempFileName, Size /
sizeof (CHAR16), L
"\\*");
2101 PrivateFile->LHandle = FindFirstFile (TempFileName, &FindBuf);
2113 if (SizeChangeFlag) {
2114 if (PrivateFile->IsDirectoryPath) {
2115 Status = EFI_UNSUPPORTED;
2119 if (PrivateFile->IsOpenedByRead || OldFileInfo->
Attribute & EFI_FILE_READ_ONLY) {
2120 Status = EFI_ACCESS_DENIED;
2124 Status = This->GetPosition (This, &CurPos);
2125 if (EFI_ERROR (Status)) {
2129 Status = This->SetPosition (This, NewFileInfo->
FileSize);
2130 if (EFI_ERROR (Status)) {
2134 if (SetEndOfFile (PrivateFile->LHandle) == 0) {
2135 Status = EFI_DEVICE_ERROR;
2139 Status = This->SetPosition (This, CurPos);
2140 if (EFI_ERROR (Status)) {
2148 if (TimeChangeFlag) {
2149 NewCreationSystemTime.wYear = NewFileInfo->
CreateTime.Year;
2150 NewCreationSystemTime.wMonth = NewFileInfo->
CreateTime.Month;
2151 NewCreationSystemTime.wDay = NewFileInfo->
CreateTime.Day;
2152 NewCreationSystemTime.wHour = NewFileInfo->
CreateTime.Hour;
2153 NewCreationSystemTime.wMinute = NewFileInfo->
CreateTime.Minute;
2154 NewCreationSystemTime.wSecond = NewFileInfo->
CreateTime.Second;
2155 NewCreationSystemTime.wMilliseconds = 0;
2157 if (!SystemTimeToFileTime (
2158 &NewCreationSystemTime,
2159 &NewCreationFileTime
2165 if (!LocalFileTimeToFileTime (
2166 &NewCreationFileTime,
2167 &NewCreationFileTime
2173 NewLastAccessSystemTime.wYear = NewFileInfo->
LastAccessTime.Year;
2174 NewLastAccessSystemTime.wMonth = NewFileInfo->
LastAccessTime.Month;
2176 NewLastAccessSystemTime.wHour = NewFileInfo->
LastAccessTime.Hour;
2177 NewLastAccessSystemTime.wMinute = NewFileInfo->
LastAccessTime.Minute;
2178 NewLastAccessSystemTime.wSecond = NewFileInfo->
LastAccessTime.Second;
2179 NewLastAccessSystemTime.wMilliseconds = 0;
2181 if (!SystemTimeToFileTime (
2182 &NewLastAccessSystemTime,
2183 &NewLastAccessFileTime
2189 if (!LocalFileTimeToFileTime (
2190 &NewLastAccessFileTime,
2191 &NewLastAccessFileTime
2203 NewLastWriteSystemTime.wMilliseconds = 0;
2205 if (!SystemTimeToFileTime (
2206 &NewLastWriteSystemTime,
2207 &NewLastWriteFileTime
2213 if (!LocalFileTimeToFileTime (
2214 &NewLastWriteFileTime,
2215 &NewLastWriteFileTime
2222 PrivateFile->IsDirectoryPath ? PrivateFile->DirHandle : PrivateFile->LHandle,
2223 &NewCreationFileTime,
2224 &NewLastAccessFileTime,
2225 &NewLastWriteFileTime
2228 Status = EFI_DEVICE_ERROR;
2239 if (NewFileInfo->
Attribute & EFI_FILE_ARCHIVE) {
2240 NewAttr |= FILE_ATTRIBUTE_ARCHIVE;
2242 NewAttr &= ~FILE_ATTRIBUTE_ARCHIVE;
2245 if (NewFileInfo->
Attribute & EFI_FILE_HIDDEN) {
2246 NewAttr |= FILE_ATTRIBUTE_HIDDEN;
2248 NewAttr &= ~FILE_ATTRIBUTE_HIDDEN;
2251 if (NewFileInfo->
Attribute & EFI_FILE_SYSTEM) {
2252 NewAttr |= FILE_ATTRIBUTE_SYSTEM;
2254 NewAttr &= ~FILE_ATTRIBUTE_SYSTEM;
2257 if (NewFileInfo->
Attribute & EFI_FILE_READ_ONLY) {
2258 NewAttr |= FILE_ATTRIBUTE_READONLY;
2260 NewAttr &= ~FILE_ATTRIBUTE_READONLY;
2263 NtStatus = SetFileAttributes (NewFileName, NewAttr);
2266 Status = EFI_DEVICE_ERROR;
2271 if (OldFileInfo !=
NULL) {
2275 if (OldFileName !=
NULL) {
2279 if (NewFileName !=
NULL) {
2306 BY_HANDLE_FILE_INFORMATION
FileInfo;
2310 PrivateFile = WIN_NT_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
2312 if (PrivateFile->LHandle == INVALID_HANDLE_VALUE) {
2313 Status = EFI_DEVICE_ERROR;
2317 if (PrivateFile->IsDirectoryPath) {
2322 if (PrivateFile->IsOpenedByRead) {
2323 Status = EFI_ACCESS_DENIED;
2327 GetFileInformationByHandle (PrivateFile->LHandle, &
FileInfo);
2329 if (
FileInfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
2330 Status = EFI_ACCESS_DENIED;
2334 Status = FlushFileBuffers (PrivateFile->LHandle) ?
EFI_SUCCESS : EFI_DEVICE_ERROR;
2344WinNtFileSystmeThunkOpen (
2351 if (Private ==
NULL) {
2352 return EFI_OUT_OF_RESOURCES;
2356 if (Private->FilePath ==
NULL) {
2358 return EFI_OUT_OF_RESOURCES;
2362 if (Private->VolumeLabel ==
NULL) {
2365 return EFI_OUT_OF_RESOURCES;
2368 Private->Signature = WIN_NT_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;
2369 Private->Thunk = This;
2370 CopyMem (&Private->SimpleFileSystem, &gWinNtFileSystemProtocol, sizeof (Private->SimpleFileSystem));
2372 This->Interface = &Private->SimpleFileSystem;
2373 This->Private = Private;
2378WinNtFileSystmeThunkClose (
2384 Private = This->Private;
2385 ASSERT (Private !=
NULL);
2387 if (Private->VolumeLabel !=
NULL) {
2391 if (Private->FilePath !=
NULL) {
2406 WinNtFileGetPossition,
2407 WinNtFileSetPossition,
2414 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION,
2419 &gEfiSimpleFileSystemProtocolGuid,
2423 WinNtFileSystmeThunkOpen,
2424 WinNtFileSystmeThunkClose,
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
RETURN_STATUS EFIAPI StrCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
RETURN_STATUS EFIAPI StrCatS(IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
UINT64 EFIAPI RShiftU64(IN UINT64 Operand, IN UINTN Count)
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
RETURN_STATUS EFIAPI StrnCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
CHAR16 *EFIAPI StrStr(IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
#define SIZE_OF_EFI_FILE_INFO
#define SIZE_OF_EFI_FILE_SYSTEM_INFO
EFI_STATUS ReadFile(IN EFI_BLOCK_IO_PROTOCOL *BlockIo, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN UDF_VOLUME_INFO *Volume, IN UDF_LONG_ALLOCATION_DESCRIPTOR *ParentIcb, IN VOID *FileEntryData, IN OUT UDF_READ_FILE_INFO *ReadFileInfo)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_FILE_INFO * FileInfo(IN EFI_FILE_HANDLE FHand)
STATIC EFI_STATUS CreateDirectory(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 DirNodeId, IN CHAR8 *Name, OUT UINT64 *NodeId, OUT UINT64 *FuseHandle)
EFI_TIME ModificationTime