87 USHORT PathNameBufferLength;
90 PathNameBufferLength = NameU->
Length +
sizeof(
WCHAR);
92 PathNameBufferLength = 0;
95 if (!
Fcb->PathNameBuffer)
98 DPRINT1(
"Unable to initialize FCB for filename '%wZ'\n", NameU);
105 Fcb->PathNameU.Length = 0;
106 Fcb->PathNameU.Buffer =
Fcb->PathNameBuffer;
107 Fcb->PathNameU.MaximumLength = PathNameBufferLength;
108 Fcb->ShortNameU.Length = 0;
109 Fcb->ShortNameU.Buffer =
Fcb->ShortNameBuffer;
110 Fcb->ShortNameU.MaximumLength =
sizeof(
Fcb->ShortNameBuffer);
111 Fcb->DirNameU.Buffer =
Fcb->PathNameU.Buffer;
112 if (NameU && NameU->
Length)
119 Fcb->DirNameU.Buffer =
Fcb->LongNameU.Buffer =
NULL;
120 Fcb->DirNameU.MaximumLength =
Fcb->DirNameU.Length = 0;
121 Fcb->LongNameU.MaximumLength =
Fcb->LongNameU.Length = 0;
134 DPRINT(
"'%wZ'\n", pFileNameU);
177 entry = pVCB->FcbHashTable[ShortIndex];
178 if (
entry->self == pFCB)
180 pVCB->FcbHashTable[ShortIndex] =
entry->next;
184 while (
entry->next->self != pFCB)
192 if (
entry->self == pFCB)
198 while (
entry->next->self != pFCB)
222 PathNameLength +=
sizeof(
WCHAR);
234 NameU->
Buffer = PathNameBuffer;
243 if (LongNameU->
Length > 0)
318 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);
321 DPRINT(
"Grabbing FCB at %p: %wZ, refCount:%d\n",
322 pFCB, &pFCB->PathNameU, pFCB->RefCount);
329 ASSERT(pFCB->RefCount > 0);
354 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);
357 DPRINT(
"Releasing FCB at %p: %wZ, refCount:%d\n",
358 pFCB, &pFCB->PathNameU, pFCB->RefCount);
369 ASSERT(pFCB->RefCount > 0);
370 RefCount = --pFCB->RefCount;
375 tmpFileObject = pFCB->FileObject;
377 pFCB->FileObject =
NULL;
385 ASSERT(pFCB->OpenHandleCount == 0);
418 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;
508 if (
Fcb->PathNameBuffer)
512 Fcb->PathNameU = NewNameU;
518 Fcb->PathNameBuffer =
Fcb->PathNameU.Buffer;
519 Fcb->DirNameU.Buffer =
Fcb->PathNameU.Buffer;
524 Fcb->ShortHash.Hash =
Fcb->Hash.Hash;
558 if (
Fcb->PathNameBuffer)
567 Fcb->PathNameBuffer =
Fcb->PathNameU.Buffer;
568 Fcb->DirNameU.Buffer =
Fcb->PathNameU.Buffer;
572 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;
764 DPRINT1(
"Attaching %p to %p (%d)\n",
fcb, fileObject,
fcb->RefCount);
775 fileObject->SectionObjectPointer = &
fcb->SectionObjectPointers;
776 fileObject->FsContext =
fcb;
777 fileObject->FsContext2 = newCCB;
778 fileObject->Vpb = vcb->IoVPB;
779 DPRINT(
"file open: fcb:%p PathName:%wZ\n",
fcb, &
fcb->PathNameU);
782 fcb->Flags &= ~FCB_CLEANED_UP;
783 fcb->Flags &= ~FCB_CLOSED;
803 WCHAR LongNameBuffer[260];
804 WCHAR ShortNameBuffer[13];
813 DPRINT(
"vfatDirFindFile(VCB:%p, dirFCB:%p, File:%wZ)\n",
814 pDeviceExt, pDirectoryFCB, FileToFindU);
820 DirContext.LongNameU.MaximumLength =
sizeof(LongNameBuffer);
821 DirContext.ShortNameU.Buffer = ShortNameBuffer;
823 DirContext.ShortNameU.MaximumLength =
sizeof(ShortNameBuffer);
844 DPRINT(
" Index:%u longName:%wZ\n",
852 DPRINT1(
"WARNING: File system corruption detected. You may need to run a disk repair utility.\n");
862 if (FoundLong ==
FALSE)
866 if (FoundLong || FoundShort)
895 WCHAR NameBuffer[260];
899 DPRINT(
"vfatGetFCBForFile (%p,%p,%p,%wZ)\n",
900 pVCB, pParentFCB, pFCB, pFileNameU);
902 RtlInitEmptyUnicodeString(&FileNameU, NameBuffer,
sizeof(NameBuffer));
904 parentFCB = *pParentFCB;
906 if (parentFCB ==
NULL)
914 DPRINT(
"returning root FCB\n");
928 *pParentFCB =
FCB->parentFcb;
934 while (*curr !=
L'\\' && curr > FileNameU.
Buffer)
939 if (curr > FileNameU.
Buffer)
1006 DPRINT (
"Element in requested path is not a directory\n");
1038 while (*curr !=
L'\\' && curr <=
last)
1057 *pParentFCB = parentFCB;
1078 *pParentFCB = parentFCB;
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
_In_ PFCB _In_ PDIRENT_ENUM_CONTEXT DirContext
ULONG vfatDirEntryGetFirstCluster(PDEVICE_EXTENSION pDeviceExt, PDIR_ENTRY pFatDirEntry)
NTSTATUS vfatFCBInitializeCacheFromVolume(PVCB vcb, PVFATFCB fcb)
#define NT_SUCCESS(StatCode)
static int Hash(const char *)
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
#define FCB_CACHE_INITIALIZED
NTSTATUS NextCluster(PDEVICE_EXTENSION DeviceExt, ULONG FirstCluster, PULONG CurrentCluster, BOOLEAN Extend)
#define RemoveEntryList(Entry)
#define InsertTailList(ListHead, Entry)
#define ExAllocatePoolWithTag(hernya, size, tag)
#define IsListEmpty(ListHead)
NTSTATUS ExInitializeResourceLite(PULONG res)
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
#define ExDeleteResourceLite(res)
#define InitializeListHead(ListHead)
#define ClearFlag(_F, _SF)
#define BooleanFlagOn(F, SF)
VOID NTAPI FsRtlInitializeFileLock(IN PFILE_LOCK FileLock, IN PCOMPLETE_LOCK_IRP_ROUTINE CompleteLockIrpRoutine OPTIONAL, IN PUNLOCK_ROUTINE UnlockRoutine OPTIONAL)
VOID NTAPI FsRtlUninitializeFileLock(IN PFILE_LOCK FileLock)
PVFAT_GLOBAL_DATA VfatGlobalData
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
#define ExFreePoolWithTag(_P, _T)
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
NTSYSAPI NTSTATUS NTAPI RtlAppendUnicodeStringToString(PUNICODE_STRING Destination, PUNICODE_STRING Source)
NTSYSAPI BOOLEAN NTAPI RtlEqualUnicodeString(PUNICODE_STRING String1, PUNICODE_STRING String2, BOOLEAN CaseInSensitive)
#define FILE_ATTRIBUTE_DIRECTORY
_In_ ULONG _In_ ULONG _In_ ULONG Length
BOOLEAN NTAPI FsRtlIsNameInExpression(IN PUNICODE_STRING Expression, IN PUNICODE_STRING Name, IN BOOLEAN IgnoreCase, IN PWCHAR UpcaseTable OPTIONAL)
_In_ PVOID _Out_opt_ BOOLEAN _Out_opt_ PPFN_NUMBER Page
#define STATUS_NO_MORE_ENTRIES
VOID NTAPI CcUnpinData(IN PVOID Bcb)
VOID NTAPI KeBugCheckEx(_In_ ULONG BugCheckCode, _In_ ULONG_PTR BugCheckParameter1, _In_ ULONG_PTR BugCheckParameter2, _In_ ULONG_PTR BugCheckParameter3, _In_ ULONG_PTR BugCheckParameter4)
NPAGED_LOOKASIDE_LIST CcbLookasideList
NPAGED_LOOKASIDE_LIST FcbLookasideList
FSRTL_COMMON_FCB_HEADER RFCB
SECTION_OBJECT_POINTERS SectionObjectPointers
UNICODE_STRING SearchPattern
LIST_ENTRY ParentListEntry
ERESOURCE PagingIoResource
UNICODE_STRING ShortNameU
FSRTL_COMMON_FCB_HEADER RFCB
struct _VFATFCB * parentFcb
LIST_ENTRY ParentListHead
#define RTL_CONSTANT_STRING(s)
#define RtlCopyMemory(Destination, Source, Length)
#define RtlZeroMemory(Destination, Length)
#define RtlMoveMemory(Destination, Source, Length)
#define STATUS_OBJECT_PATH_NOT_FOUND
#define STATUS_OBJECT_NAME_INVALID
#define STATUS_INSUFFICIENT_RESOURCES
#define STATUS_OBJECT_NAME_NOT_FOUND
#define ENTRY_VOLUME(IsFatX, DirEntry)
#define ROUND_UP_64(n, align)
FORCEINLINE BOOLEAN vfatFCBIsDirectory(PVFATFCB FCB)
#define VFAT_BREAK_ON_CORRUPTION
FORCEINLINE NTSTATUS VfatGetNextDirEntry(PDEVICE_EXTENSION DeviceExt, PVOID *pContext, PVOID *pPage, struct _VFATFCB *pDirFcb, struct _VFAT_DIRENTRY_CONTEXT *DirContext, BOOLEAN First)
#define LONGNAME_MAX_LENGTH
FORCEINLINE BOOLEAN vfatVolumeIsFatX(PDEVICE_EXTENSION DeviceExt)
static VOID vfatDelFCBFromTable(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
static NTSTATUS vfatMakeFullName(PVFATFCB directoryFCB, PUNICODE_STRING LongNameU, PUNICODE_STRING ShortNameU, PUNICODE_STRING NameU)
static ULONG vfatNameHash(ULONG hash, PUNICODE_STRING NameU)
NTSTATUS vfatUpdateFCB(PDEVICE_EXTENSION pVCB, PVFATFCB Fcb, PVFAT_DIRENTRY_CONTEXT DirContext, PVFATFCB ParentFcb)
VOID vfatSplitPathName(PUNICODE_STRING PathNameU, PUNICODE_STRING DirNameU, PUNICODE_STRING FileNameU)
PVFATFCB vfatOpenRootFCB(PDEVICE_EXTENSION pVCB)
BOOLEAN vfatFCBIsRoot(PVFATFCB FCB)
PVFATFCB vfatMakeRootFCB(PDEVICE_EXTENSION pVCB)
static VOID vfatInitFCBFromDirEntry(PDEVICE_EXTENSION Vcb, PVFATFCB ParentFcb, PVFATFCB Fcb, PVFAT_DIRENTRY_CONTEXT DirContext)
VOID vfatDestroyFCB(PVFATFCB pFCB)
NTSTATUS vfatAttachFCBToFileObject(PDEVICE_EXTENSION vcb, PVFATFCB fcb, PFILE_OBJECT fileObject)
VOID vfatDestroyCCB(PVFATCCB pCcb)
NTSTATUS vfatMakeFCBFromDirEntry(PVCB vcb, PVFATFCB directoryFCB, PVFAT_DIRENTRY_CONTEXT DirContext, PVFATFCB *fileFCB)
NTSTATUS vfatSetFCBNewDirName(PDEVICE_EXTENSION pVCB, PVFATFCB Fcb, PVFATFCB ParentFcb)
NTSTATUS vfatDirFindFile(PDEVICE_EXTENSION pDeviceExt, PVFATFCB pDirectoryFCB, PUNICODE_STRING FileToFindU, PVFATFCB *pFoundFCB)
NTSTATUS vfatGetFCBForFile(PDEVICE_EXTENSION pVCB, PVFATFCB *pParentFCB, PVFATFCB *pFCB, PUNICODE_STRING pFileNameU)
PVFATFCB vfatNewFCB(PDEVICE_EXTENSION pVCB, PUNICODE_STRING pFileNameU)
VOID vfatReleaseFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
PVFATFCB vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB, PUNICODE_STRING PathNameU)
static VOID vfatInitFcb(PVFATFCB Fcb, PUNICODE_STRING NameU)
static VOID vfatAddFCBToTable(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
VOID vfatGrabFCB(PDEVICE_EXTENSION pVCB, PVFATFCB pFCB)
_In_ WDFCOLLECTION _In_ ULONG Index
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
#define ExIsResourceAcquiredExclusive
FORCEINLINE VOID ExInitializeFastMutex(_Out_ PFAST_MUTEX FastMutex)
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
#define ObDereferenceObject