- PWCHAR PathNameBuffer;
- USHORT PathNameBufferLength;
- NTSTATUS Status;
- PVOID Context = NULL;
- PVOID Page;
- PVFATFCB rcFcb;
- BOOLEAN Found;
- UNICODE_STRING PathNameU;
- UNICODE_STRING FileToFindUpcase;
- BOOLEAN WildCard;
-
- DPRINT ("FindFile(Parent %p, FileToFind '%wZ', DirIndex: %u)\n",
- Parent, FileToFindU, DirContext->DirIndex);
- DPRINT ("FindFile: Path %wZ\n",&Parent->PathNameU);
-
- PathNameBufferLength = LONGNAME_MAX_LENGTH * sizeof(WCHAR);
- PathNameBuffer = ExAllocatePoolWithTag(NonPagedPool, PathNameBufferLength + sizeof(WCHAR), TAG_VFAT);
- if (!PathNameBuffer)
- {
- return STATUS_INSUFFICIENT_RESOURCES;
- }
-
- PathNameU.Buffer = PathNameBuffer;
- PathNameU.Length = 0;
- PathNameU.MaximumLength = PathNameBufferLength;
-
- DirContext->LongNameU.Length = 0;
- DirContext->ShortNameU.Length = 0;
-
- WildCard = FsRtlDoesNameContainWildCards(FileToFindU);
-
- if (WildCard == FALSE)
- {
- /* if there is no '*?' in the search name, than look first for an existing fcb */
- RtlCopyUnicodeString(&PathNameU, &Parent->PathNameU);
- if (!vfatFCBIsRoot(Parent))
- {
- PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = L'\\';
- PathNameU.Length += sizeof(WCHAR);
- }
- RtlAppendUnicodeStringToString(&PathNameU, FileToFindU);
- PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = 0;
- rcFcb = vfatGrabFCBFromTable(DeviceExt, &PathNameU);
- if (rcFcb)
- {
- ULONG startIndex = rcFcb->startIndex;
- if ((rcFcb->Flags & FCB_IS_FATX_ENTRY) && !vfatFCBIsRoot(Parent))
- {
- startIndex += 2;
- }
- if(startIndex >= DirContext->DirIndex)
- {
- RtlCopyUnicodeString(&DirContext->LongNameU, &rcFcb->LongNameU);
- RtlCopyUnicodeString(&DirContext->ShortNameU, &rcFcb->ShortNameU);
- RtlCopyMemory(&DirContext->DirEntry, &rcFcb->entry, sizeof(DIR_ENTRY));
- DirContext->StartIndex = rcFcb->startIndex;
- DirContext->DirIndex = rcFcb->dirIndex;
- DPRINT("FindFile: new Name %wZ, DirIndex %u (%u)\n",
- &DirContext->LongNameU, DirContext->DirIndex, DirContext->StartIndex);
- Status = STATUS_SUCCESS;
- }
- else
- {
- DPRINT("FCB not found for %wZ\n", &PathNameU);
- Status = STATUS_UNSUCCESSFUL;
- }
- vfatReleaseFCB(DeviceExt, rcFcb);
- ExFreePool(PathNameBuffer);
- return Status;
- }
- }
-
- /* FsRtlIsNameInExpression need the searched string to be upcase,
- * even if IgnoreCase is specified */
- Status = RtlUpcaseUnicodeString(&FileToFindUpcase, FileToFindU, TRUE);
- if (!NT_SUCCESS(Status))
- {
- ExFreePool(PathNameBuffer);
- return Status;
- }
-
- while(TRUE)
- {
- Status = DeviceExt->GetNextDirEntry(&Context, &Page, Parent, DirContext, First);
- First = FALSE;
- if (Status == STATUS_NO_MORE_ENTRIES)
- {
- break;
- }
- if (ENTRY_VOLUME(DeviceExt, &DirContext->DirEntry))
- {
- DirContext->DirIndex++;
- continue;
- }
- if (WildCard)
- {
- Found = FsRtlIsNameInExpression(&FileToFindUpcase, &DirContext->LongNameU, TRUE, NULL) ||
- FsRtlIsNameInExpression(&FileToFindUpcase, &DirContext->ShortNameU, TRUE, NULL);
- }
- else
- {
- Found = FsRtlAreNamesEqual(&DirContext->LongNameU, FileToFindU, TRUE, NULL) ||
- FsRtlAreNamesEqual(&DirContext->ShortNameU, FileToFindU, TRUE, NULL);
- }
-
- if (Found)
- {
- if (WildCard)
- {
- RtlCopyUnicodeString(&PathNameU, &Parent->PathNameU);
- if (!vfatFCBIsRoot(Parent))
- {
- PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = L'\\';
- PathNameU.Length += sizeof(WCHAR);
- }
- RtlAppendUnicodeStringToString(&PathNameU, &DirContext->LongNameU);
- PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = 0;
- rcFcb = vfatGrabFCBFromTable(DeviceExt, &PathNameU);
- if (rcFcb != NULL)
- {
- RtlCopyMemory(&DirContext->DirEntry, &rcFcb->entry, sizeof(DIR_ENTRY));
- vfatReleaseFCB(DeviceExt, rcFcb);
- }
- }
- DPRINT("%u\n", DirContext->LongNameU.Length);
- DPRINT("FindFile: new Name %wZ, DirIndex %u\n",
- &DirContext->LongNameU, DirContext->DirIndex);
-
- if (Context)
- {
- CcUnpinData(Context);
- }
- RtlFreeUnicodeString(&FileToFindUpcase);
- ExFreePool(PathNameBuffer);
- return STATUS_SUCCESS;
- }
- DirContext->DirIndex++;
- }
-
- if (Context)
- {
- CcUnpinData(Context);
- }
-
- RtlFreeUnicodeString(&FileToFindUpcase);
- ExFreePool(PathNameBuffer);
- return Status;
+ PWCHAR PathNameBuffer;
+ USHORT PathNameBufferLength;
+ NTSTATUS Status;
+ PVOID Context = NULL;
+ PVOID Page;
+ PVFATFCB rcFcb;
+ BOOLEAN Found;
+ UNICODE_STRING PathNameU;
+ UNICODE_STRING FileToFindUpcase;
+ BOOLEAN WildCard;
+
+ DPRINT("FindFile(Parent %p, FileToFind '%wZ', DirIndex: %u)\n",
+ Parent, FileToFindU, DirContext->DirIndex);
+ DPRINT("FindFile: Path %wZ\n",&Parent->PathNameU);
+
+ PathNameBufferLength = LONGNAME_MAX_LENGTH * sizeof(WCHAR);
+ PathNameBuffer = ExAllocatePoolWithTag(NonPagedPool, PathNameBufferLength + sizeof(WCHAR), TAG_VFAT);
+ if (!PathNameBuffer)
+ {
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+
+ PathNameU.Buffer = PathNameBuffer;
+ PathNameU.Length = 0;
+ PathNameU.MaximumLength = PathNameBufferLength;
+
+ DirContext->LongNameU.Length = 0;
+ DirContext->ShortNameU.Length = 0;
+
+ WildCard = FsRtlDoesNameContainWildCards(FileToFindU);
+
+ if (WildCard == FALSE)
+ {
+ /* if there is no '*?' in the search name, than look first for an existing fcb */
+ RtlCopyUnicodeString(&PathNameU, &Parent->PathNameU);
+ if (!vfatFCBIsRoot(Parent))
+ {
+ PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = L'\\';
+ PathNameU.Length += sizeof(WCHAR);
+ }
+ RtlAppendUnicodeStringToString(&PathNameU, FileToFindU);
+ PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = 0;
+ rcFcb = vfatGrabFCBFromTable(DeviceExt, &PathNameU);
+ if (rcFcb)
+ {
+ ULONG startIndex = rcFcb->startIndex;
+ if ((rcFcb->Flags & FCB_IS_FATX_ENTRY) && !vfatFCBIsRoot(Parent))
+ {
+ startIndex += 2;
+ }
+ if(startIndex >= DirContext->DirIndex)
+ {
+ RtlCopyUnicodeString(&DirContext->LongNameU, &rcFcb->LongNameU);
+ RtlCopyUnicodeString(&DirContext->ShortNameU, &rcFcb->ShortNameU);
+ RtlCopyMemory(&DirContext->DirEntry, &rcFcb->entry, sizeof(DIR_ENTRY));
+ DirContext->StartIndex = rcFcb->startIndex;
+ DirContext->DirIndex = rcFcb->dirIndex;
+ DPRINT("FindFile: new Name %wZ, DirIndex %u (%u)\n",
+ &DirContext->LongNameU, DirContext->DirIndex, DirContext->StartIndex);
+ Status = STATUS_SUCCESS;
+ }
+ else
+ {
+ DPRINT("FCB not found for %wZ\n", &PathNameU);
+ Status = STATUS_UNSUCCESSFUL;
+ }
+ vfatReleaseFCB(DeviceExt, rcFcb);
+ ExFreePool(PathNameBuffer);
+ return Status;
+ }
+ }
+
+ /* FsRtlIsNameInExpression need the searched string to be upcase,
+ * even if IgnoreCase is specified */
+ Status = RtlUpcaseUnicodeString(&FileToFindUpcase, FileToFindU, TRUE);
+ if (!NT_SUCCESS(Status))
+ {
+ ExFreePool(PathNameBuffer);
+ return Status;
+ }
+
+ while(TRUE)
+ {
+ Status = DeviceExt->GetNextDirEntry(&Context, &Page, Parent, DirContext, First);
+ First = FALSE;
+ if (Status == STATUS_NO_MORE_ENTRIES)
+ {
+ break;
+ }
+ if (ENTRY_VOLUME(DeviceExt, &DirContext->DirEntry))
+ {
+ DirContext->DirIndex++;
+ continue;
+ }
+ if (WildCard)
+ {
+ Found = FsRtlIsNameInExpression(&FileToFindUpcase, &DirContext->LongNameU, TRUE, NULL) ||
+ FsRtlIsNameInExpression(&FileToFindUpcase, &DirContext->ShortNameU, TRUE, NULL);
+ }
+ else
+ {
+ Found = FsRtlAreNamesEqual(&DirContext->LongNameU, FileToFindU, TRUE, NULL) ||
+ FsRtlAreNamesEqual(&DirContext->ShortNameU, FileToFindU, TRUE, NULL);
+ }
+
+ if (Found)
+ {
+ if (WildCard)
+ {
+ RtlCopyUnicodeString(&PathNameU, &Parent->PathNameU);
+ if (!vfatFCBIsRoot(Parent))
+ {
+ PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = L'\\';
+ PathNameU.Length += sizeof(WCHAR);
+ }
+ RtlAppendUnicodeStringToString(&PathNameU, &DirContext->LongNameU);
+ PathNameU.Buffer[PathNameU.Length / sizeof(WCHAR)] = 0;
+ rcFcb = vfatGrabFCBFromTable(DeviceExt, &PathNameU);
+ if (rcFcb != NULL)
+ {
+ RtlCopyMemory(&DirContext->DirEntry, &rcFcb->entry, sizeof(DIR_ENTRY));
+ vfatReleaseFCB(DeviceExt, rcFcb);
+ }
+ }
+ DPRINT("%u\n", DirContext->LongNameU.Length);
+ DPRINT("FindFile: new Name %wZ, DirIndex %u\n",
+ &DirContext->LongNameU, DirContext->DirIndex);
+
+ if (Context)
+ {
+ CcUnpinData(Context);
+ }
+ RtlFreeUnicodeString(&FileToFindUpcase);
+ ExFreePool(PathNameBuffer);
+ return STATUS_SUCCESS;
+ }
+ DirContext->DirIndex++;
+ }
+
+ if (Context)
+ {
+ CcUnpinData(Context);
+ }
+
+ RtlFreeUnicodeString(&FileToFindUpcase);
+ ExFreePool(PathNameBuffer);
+ return Status;