88 USHORT PathNameBufferLength;
91 PathNameBufferLength = NameU->
Length +
sizeof(
WCHAR);
93 PathNameBufferLength = 0;
96 if (!
Fcb->PathNameBuffer)
99 DPRINT1(
"Unable to initialize FCB for filename '%wZ'\n", NameU);
106 Fcb->PathNameU.Length = 0;
107 Fcb->PathNameU.Buffer =
Fcb->PathNameBuffer;
108 Fcb->PathNameU.MaximumLength = PathNameBufferLength;
109 Fcb->ShortNameU.Length = 0;
110 Fcb->ShortNameU.Buffer =
Fcb->ShortNameBuffer;
111 Fcb->ShortNameU.MaximumLength =
sizeof(
Fcb->ShortNameBuffer);
112 Fcb->DirNameU.Buffer =
Fcb->PathNameU.Buffer;
113 if (NameU && NameU->
Length)
120 Fcb->DirNameU.Buffer =
Fcb->LongNameU.Buffer =
NULL;
121 Fcb->DirNameU.MaximumLength =
Fcb->DirNameU.Length = 0;
122 Fcb->LongNameU.MaximumLength =
Fcb->LongNameU.Length = 0;
135 DPRINT(
"'%wZ'\n", pFileNameU);
178 entry = pVCB->FcbHashTable[ShortIndex];
179 if (
entry->self == pFCB)
181 pVCB->FcbHashTable[ShortIndex] =
entry->next;
185 while (
entry->next->self != pFCB)
193 if (
entry->self == pFCB)
199 while (
entry->next->self != pFCB)
223 PathNameLength +=
sizeof(
WCHAR);
235 NameU->
Buffer = PathNameBuffer;
244 if (LongNameU->
Length > 0)
319 DPRINT1(
"Inc ref count (%d, oc: %d) for: %p (%wZ) at: %s(%d) %s\n", pFCB->RefCount, pFCB->OpenHandleCount, pFCB, &pFCB->PathNameU, File, Line, Func);
322 DPRINT(
"Grabbing FCB at %p: %wZ, refCount:%d\n",
323 pFCB, &pFCB->PathNameU, pFCB->RefCount);
330 ASSERT(pFCB->RefCount > 0);
355 DPRINT1(
"Dec ref count (%d, oc: %d) for: %p (%wZ) at: %s(%d) %s\n", pFCB->RefCount, pFCB->OpenHandleCount, pFCB, &pFCB->PathNameU, File, Line, Func);
358 DPRINT(
"Releasing FCB at %p: %wZ, refCount:%d\n",
359 pFCB, &pFCB->PathNameU, pFCB->RefCount);
370 ASSERT(pFCB->RefCount > 0);
371 RefCount = --pFCB->RefCount;
376 tmpFileObject = pFCB->FileObject;
378 pFCB->FileObject =
NULL;
386 ASSERT(pFCB->OpenHandleCount == 0);
419 pVCB->FcbHashTable[ShortIndex] = &pFCB->
ShortHash;
441 Fcb->ShortHash.Hash =
Fcb->Hash.Hash;
451 ULONG FirstCluster, CurrentCluster;
455 if (FirstCluster == 1)
457 Size =
Vcb->FatInfo.rootDirectorySectors *
Vcb->FatInfo.BytesPerSector;
459 else if (FirstCluster != 0)
461 CurrentCluster = FirstCluster;
464 Size +=
Vcb->FatInfo.BytesPerCluster;
471 Size =
Fcb->entry.FatX.FileSize;
475 Size =
Fcb->entry.Fat.FileSize;
507 if (
Fcb->PathNameBuffer)
511 Fcb->PathNameU = NewNameU;
517 Fcb->PathNameBuffer =
Fcb->PathNameU.Buffer;
518 Fcb->DirNameU.Buffer =
Fcb->PathNameU.Buffer;
523 Fcb->ShortHash.Hash =
Fcb->Hash.Hash;
557 if (
Fcb->PathNameBuffer)
566 Fcb->PathNameBuffer =
Fcb->PathNameU.Buffer;
567 Fcb->DirNameU.Buffer =
Fcb->PathNameU.Buffer;
571 OldParent =
Fcb->parentFcb;
606 DPRINT(
"'%wZ'\n", PathNameU);
611 entry = pVCB->FcbHashTable[
Hash % pVCB->HashTableSize];
634 DPRINT(
"'%wZ' '%wZ'\n", &FileNameU, FcbNameU);
652 ULONG FirstCluster, CurrentCluster,
Size = 0;
661 memset(
FCB->entry.FatX.Filename,
' ', 42);
662 FCB->entry.FatX.FileSize = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
664 FCB->entry.FatX.FirstCluster = 1;
665 Size = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
670 FCB->entry.Fat.FileSize = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
672 if (pVCB->FatInfo.FatType ==
FAT32)
674 CurrentCluster = FirstCluster = pVCB->FatInfo.RootCluster;
675 FCB->entry.Fat.FirstCluster = (
unsigned short)(FirstCluster & 0xffff);
676 FCB->entry.Fat.FirstClusterHigh = (
unsigned short)(FirstCluster >> 16);
680 Size += pVCB->FatInfo.BytesPerCluster;
686 FCB->entry.Fat.FirstCluster = 1;
687 Size = pVCB->FatInfo.rootDirectorySectors * pVCB->FatInfo.BytesPerSector;
690 FCB->ShortHash.Hash =
FCB->Hash.Hash;
765 DPRINT1(
"Attaching %p to %p (%d)\n",
fcb, fileObject,
fcb->RefCount);
776 fileObject->SectionObjectPointer = &
fcb->SectionObjectPointers;
777 fileObject->FsContext =
fcb;
778 fileObject->FsContext2 = newCCB;
779 fileObject->Vpb = vcb->IoVPB;
780 DPRINT(
"file open: fcb:%p PathName:%wZ\n",
fcb, &
fcb->PathNameU);
783 fcb->Flags &= ~FCB_CLEANED_UP;
784 fcb->Flags &= ~FCB_CLOSED;
804 WCHAR LongNameBuffer[260];
805 WCHAR ShortNameBuffer[13];
814 DPRINT(
"vfatDirFindFile(VCB:%p, dirFCB:%p, File:%wZ)\n",
815 pDeviceExt, pDirectoryFCB, FileToFindU);
821 DirContext.LongNameU.MaximumLength =
sizeof(LongNameBuffer);
822 DirContext.ShortNameU.Buffer = ShortNameBuffer;
824 DirContext.ShortNameU.MaximumLength =
sizeof(ShortNameBuffer);
845 DPRINT(
" Index:%u longName:%wZ\n",
853 DPRINT1(
"WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
863 if (FoundLong ==
FALSE)
867 if (FoundLong || FoundShort)
896 WCHAR NameBuffer[260];
900 DPRINT(
"vfatGetFCBForFile (%p,%p,%p,%wZ)\n",
901 pVCB, pParentFCB, pFCB, pFileNameU);
903 RtlInitEmptyUnicodeString(&FileNameU, NameBuffer,
sizeof(NameBuffer));
905 parentFCB = *pParentFCB;
907 if (parentFCB ==
NULL)
915 DPRINT(
"returning root FCB\n");
929 *pParentFCB =
FCB->parentFcb;
935 while (*curr !=
L'\\' && curr > FileNameU.
Buffer)
940 if (curr > FileNameU.
Buffer)
1007 DPRINT (
"Element in requested path is not a directory\n");
1039 while (*curr !=
L'\\' && curr <=
last)
1058 *pParentFCB = parentFCB;
1079 *pParentFCB = parentFCB;
static int Hash(const char *)
NTSTATUS vfatUpdateFCB(PDEVICE_EXTENSION pVCB, PVFATFCB Fcb, PVFAT_DIRENTRY_CONTEXT DirContext, PVFATFCB ParentFcb)
static VOID vfatInitFcb(PVFATFCB Fcb, PUNICODE_STRING NameU)
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
#define STATUS_INSUFFICIENT_RESOURCES
_In_ ULONG _In_ ULONG _In_ ULONG Length
#define STATUS_NO_MORE_ENTRIES
UNICODE_STRING ShortNameU
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
VOID NTAPI FsRtlInitializeFileLock(IN PFILE_LOCK FileLock, IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL, IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL)
NPAGED_LOOKASIDE_LIST FcbLookasideList
ULONG vfatDirEntryGetFirstCluster(PDEVICE_EXTENSION pDeviceExt, PDIR_ENTRY pFatDirEntry)
#define BooleanFlagOn(F, SF)
static VOID vfatAddFCBToTable(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
PVFATFCB vfatOpenRootFCB(PDEVICE_EXTENSION pVCB)
VOID NTAPI FsRtlUninitializeFileLock(IN PFILE_LOCK FileLock)
NTSTATUS vfatAttachFCBToFileObject(PDEVICE_EXTENSION vcb, PVFATFCB fcb, PFILE_OBJECT fileObject)
VOID NTAPI CcUnpinData(IN PVOID Bcb)
NTSTATUS ExInitializeResourceLite(PULONG res)
NTSTATUS NTAPI ExDeleteResourceLite(IN PERESOURCE Resource)
FORCEINLINE BOOLEAN vfatFCBIsDirectory(PVFATFCB FCB)
IN PVOID IN PVOID IN USHORT IN USHORT Size
BOOLEAN vfatFCBIsRoot(PVFATFCB FCB)
UNICODE_STRING SearchPattern
#define InsertTailList(ListHead, Entry)
NTSTATUS vfatMakeFCBFromDirEntry(PVCB vcb, PVFATFCB directoryFCB, PVFAT_DIRENTRY_CONTEXT DirContext, PVFATFCB *fileFCB)
NTSTATUS vfatSetFCBNewDirName(PDEVICE_EXTENSION pVCB, PVFATFCB Fcb, PVFATFCB ParentFcb)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
BOOLEAN NTAPI FsRtlIsNameInExpression(IN PUNICODE_STRING Expression, IN PUNICODE_STRING Name, IN BOOLEAN IgnoreCase, IN PWCHAR UpcaseTable OPTIONAL)
#define ENTRY_VOLUME(IsFatX, DirEntry)
#define RtlMoveMemory(Destination, Source, Length)
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
#define ROUND_UP_64(n, align)
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
PVFATFCB vfatMakeRootFCB(PDEVICE_EXTENSION pVCB)
FSRTL_COMMON_FCB_HEADER RFCB
NPAGED_LOOKASIDE_LIST CcbLookasideList
#define FILE_ATTRIBUTE_DIRECTORY
FORCEINLINE BOOLEAN vfatVolumeIsFatX(PDEVICE_EXTENSION DeviceExt)
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
NTSTATUS vfatFCBInitializeCacheFromVolume(PVCB vcb, PVFATFCB fcb)
struct _VFATFCB * parentFcb
#define NT_SUCCESS(StatCode)
_In_ WDFCOLLECTION _In_ ULONG Index
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
static ULONG vfatNameHash(ULONG hash, PUNICODE_STRING NameU)
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT DirContext
#define ObDereferenceObject
#define STATUS_OBJECT_PATH_NOT_FOUND
VOID vfatDestroyFCB(PVFATFCB pFCB)
FSRTL_COMMON_FCB_HEADER RFCB
PVFATFCB vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB, PUNICODE_STRING PathNameU)
#define ExAllocatePoolWithTag(hernya, size, tag)
VOID vfatDestroyCCB(PVFATCCB pCcb)
static VOID vfatInitFCBFromDirEntry(PDEVICE_EXTENSION Vcb, PVFATFCB Fcb, PVFAT_DIRENTRY_CONTEXT DirContext)
FORCEINLINE NTSTATUS VfatGetNextDirEntry(PDEVICE_EXTENSION DeviceExt, PVOID *pContext, PVOID *pPage, struct _VFATFCB *pDirFcb, struct _VFAT_DIRENTRY_CONTEXT *DirContext, BOOLEAN First)
ClearFlag(Dirent->Flags, DIRENT_FLAG_NOT_PERSISTENT)
#define FCB_CACHE_INITIALIZED
#define VFAT_BREAK_ON_CORRUPTION
PVFAT_GLOBAL_DATA VfatGlobalData
ERESOURCE PagingIoResource
#define STATUS_OBJECT_NAME_NOT_FOUND
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
#define InitializeListHead(ListHead)
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
#define STATUS_OBJECT_NAME_INVALID
PVFATFCB vfatNewFCB(PDEVICE_EXTENSION pVCB, PUNICODE_STRING pFileNameU)
static NTSTATUS vfatMakeFullName(PVFATFCB directoryFCB, PUNICODE_STRING LongNameU, PUNICODE_STRING ShortNameU, PUNICODE_STRING NameU)
#define LONGNAME_MAX_LENGTH
VOID vfatGrabFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
#define RtlZeroMemory(Destination, Length)
#define RtlCopyMemory(Destination, Source, Length)
VOID vfatReleaseFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
NTSTATUS vfatDirFindFile(PDEVICE_EXTENSION pDeviceExt, PVFATFCB pDirectoryFCB, PUNICODE_STRING FileToFindU, PVFATFCB *pFoundFCB)
NTSTATUS vfatGetFCBForFile(PDEVICE_EXTENSION pVCB, PVFATFCB *pParentFCB, PVFATFCB *pFCB, PUNICODE_STRING pFileNameU)
#define ExFreePoolWithTag(_P, _T)
#define ExIsResourceAcquiredExclusive
static VOID vfatDelFCBFromTable(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
LIST_ENTRY ParentListHead
static SERVICE_STATUS status
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
VOID vfatSplitPathName(PUNICODE_STRING PathNameU, PUNICODE_STRING DirNameU, PUNICODE_STRING FileNameU)
SECTION_OBJECT_POINTERS SectionObjectPointers
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
LIST_ENTRY ParentListEntry
#define RTL_CONSTANT_STRING(s)