2 * FILE: drivers/fs/vfat/fcb.c
3 * PURPOSE: Routines to manipulate FCBs.
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS kernel
6 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
7 * Rex Jolliff (rex@lvcablemodem.com)
8 * Herve Poussineau (reactos@poussine.freesurf.fr)
11 /* ------------------------------------------------------- INCLUDES */
14 #include <wctype.h> /* towlower prototype */
20 /* -------------------------------------------------------- DEFINES */
22 #define TAG_FCB 'BCFV'
24 /* -------------------------------------------------------- PUBLICS */
30 PUNICODE_STRING NameU
)
36 // LFN could start from "."
37 //ASSERT(NameU->Buffer[0] != L'.');
39 last
= NameU
->Buffer
+ NameU
->Length
/ sizeof(WCHAR
);
43 c
= towlower(*curr
++);
44 hash
= (hash
+ (c
<< 4) + (c
>> 4)) * 11;
51 PUNICODE_STRING PathNameU
,
52 PUNICODE_STRING DirNameU
,
53 PUNICODE_STRING FileNameU
)
57 pName
= PathNameU
->Buffer
+ PathNameU
->Length
/ sizeof(WCHAR
) - 1;
58 while (*pName
!= L
'\\' && pName
>= PathNameU
->Buffer
)
63 ASSERT(*pName
== L
'\\' || pName
< PathNameU
->Buffer
);
66 FileNameU
->Buffer
= pName
+ 1;
67 FileNameU
->Length
= FileNameU
->MaximumLength
= Length
* sizeof(WCHAR
);
71 DirNameU
->Buffer
= PathNameU
->Buffer
;
72 DirNameU
->Length
= (pName
+ 1 - PathNameU
->Buffer
) * sizeof(WCHAR
);
73 DirNameU
->MaximumLength
= DirNameU
->Length
;
81 PUNICODE_STRING NameU
)
83 USHORT PathNameBufferLength
;
86 PathNameBufferLength
= NameU
->Length
+ sizeof(WCHAR
);
88 PathNameBufferLength
= 0;
90 Fcb
->PathNameBuffer
= ExAllocatePoolWithTag(NonPagedPool
, PathNameBufferLength
, TAG_FCB
);
91 if (!Fcb
->PathNameBuffer
)
93 /* FIXME: what to do if no more memory? */
94 DPRINT1("Unable to initialize FCB for filename '%wZ'\n", NameU
);
95 KeBugCheckEx(FAT_FILE_SYSTEM
, (ULONG_PTR
)Fcb
, (ULONG_PTR
)NameU
, 0, 0);
98 Fcb
->PathNameU
.Length
= 0;
99 Fcb
->PathNameU
.Buffer
= Fcb
->PathNameBuffer
;
100 Fcb
->PathNameU
.MaximumLength
= PathNameBufferLength
;
101 Fcb
->ShortNameU
.Length
= 0;
102 Fcb
->ShortNameU
.Buffer
= Fcb
->ShortNameBuffer
;
103 Fcb
->ShortNameU
.MaximumLength
= sizeof(Fcb
->ShortNameBuffer
);
104 Fcb
->DirNameU
.Buffer
= Fcb
->PathNameU
.Buffer
;
105 if (NameU
&& NameU
->Length
)
107 RtlCopyUnicodeString(&Fcb
->PathNameU
, NameU
);
108 vfatSplitPathName(&Fcb
->PathNameU
, &Fcb
->DirNameU
, &Fcb
->LongNameU
);
112 Fcb
->DirNameU
.Buffer
= Fcb
->LongNameU
.Buffer
= NULL
;
113 Fcb
->DirNameU
.MaximumLength
= Fcb
->DirNameU
.Length
= 0;
114 Fcb
->LongNameU
.MaximumLength
= Fcb
->LongNameU
.Length
= 0;
116 RtlZeroMemory(&Fcb
->FCBShareAccess
, sizeof(SHARE_ACCESS
));
117 Fcb
->OpenHandleCount
= 0;
122 PDEVICE_EXTENSION pVCB
,
123 PUNICODE_STRING pFileNameU
)
127 DPRINT("'%wZ'\n", pFileNameU
);
129 rcFCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
);
134 RtlZeroMemory(rcFCB
, sizeof(VFATFCB
));
135 vfatInitFcb(rcFCB
, pFileNameU
);
136 if (pVCB
->Flags
& VCB_IS_FATX
)
138 rcFCB
->Flags
|= FCB_IS_FATX_ENTRY
;
139 rcFCB
->Attributes
= &rcFCB
->entry
.FatX
.Attrib
;
142 rcFCB
->Attributes
= &rcFCB
->entry
.Fat
.Attrib
;
143 rcFCB
->Hash
.Hash
= vfatNameHash(0, &rcFCB
->PathNameU
);
144 rcFCB
->Hash
.self
= rcFCB
;
145 rcFCB
->ShortHash
.self
= rcFCB
;
146 ExInitializeResourceLite(&rcFCB
->PagingIoResource
);
147 ExInitializeResourceLite(&rcFCB
->MainResource
);
148 FsRtlInitializeFileLock(&rcFCB
->FileLock
, NULL
, NULL
);
149 ExInitializeFastMutex(&rcFCB
->LastMutex
);
150 rcFCB
->RFCB
.PagingIoResource
= &rcFCB
->PagingIoResource
;
151 rcFCB
->RFCB
.Resource
= &rcFCB
->MainResource
;
152 rcFCB
->RFCB
.IsFastIoPossible
= FastIoIsNotPossible
;
161 if (pCcb
->SearchPattern
.Buffer
)
163 ExFreePoolWithTag(pCcb
->SearchPattern
.Buffer
, TAG_VFAT
);
165 ExFreeToNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
, pCcb
);
172 FsRtlUninitializeFileLock(&pFCB
->FileLock
);
173 ExFreePool(pFCB
->PathNameBuffer
);
174 ExDeleteResourceLite(&pFCB
->PagingIoResource
);
175 ExDeleteResourceLite(&pFCB
->MainResource
);
176 ExFreeToNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
, pFCB
);
183 return *FCB
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
;
190 return FCB
->PathNameU
.Length
== sizeof(WCHAR
) && FCB
->PathNameU
.Buffer
[0] == L
'\\' ? TRUE
: FALSE
;
195 PDEVICE_EXTENSION pVCB
,
203 DPRINT("releasing FCB at %p: %wZ, refCount:%d\n",
204 pFCB
, &pFCB
->PathNameU
, pFCB
->RefCount
);
208 Index
= pFCB
->Hash
.Hash
% pVCB
->HashTableSize
;
209 ShortIndex
= pFCB
->ShortHash
.Hash
% pVCB
->HashTableSize
;
211 if (pFCB
->RefCount
== 0)
213 tmpFcb
= pFCB
->parentFcb
;
214 RemoveEntryList (&pFCB
->FcbListEntry
);
215 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
217 entry
= pVCB
->FcbHashTable
[ShortIndex
];
218 if (entry
->self
== pFCB
)
220 pVCB
->FcbHashTable
[ShortIndex
] = entry
->next
;
224 while (entry
->next
->self
!= pFCB
)
228 entry
->next
= pFCB
->ShortHash
.next
;
231 entry
= pVCB
->FcbHashTable
[Index
];
232 if (entry
->self
== pFCB
)
234 pVCB
->FcbHashTable
[Index
] = entry
->next
;
238 while (entry
->next
->self
!= pFCB
)
242 entry
->next
= pFCB
->Hash
.next
;
244 vfatDestroyFCB(pFCB
);
256 PDEVICE_EXTENSION pVCB
,
262 Index
= pFCB
->Hash
.Hash
% pVCB
->HashTableSize
;
263 ShortIndex
= pFCB
->ShortHash
.Hash
% pVCB
->HashTableSize
;
265 InsertTailList(&pVCB
->FcbListHead
, &pFCB
->FcbListEntry
);
267 pFCB
->Hash
.next
= pVCB
->FcbHashTable
[Index
];
268 pVCB
->FcbHashTable
[Index
] = &pFCB
->Hash
;
269 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
271 pFCB
->ShortHash
.next
= pVCB
->FcbHashTable
[ShortIndex
];
272 pVCB
->FcbHashTable
[ShortIndex
] = &pFCB
->ShortHash
;
276 pFCB
->parentFcb
->RefCount
++;
281 vfatGrabFCBFromTable(
282 PDEVICE_EXTENSION pVCB
,
283 PUNICODE_STRING PathNameU
)
287 UNICODE_STRING DirNameU
;
288 UNICODE_STRING FileNameU
;
289 PUNICODE_STRING FcbNameU
;
293 DPRINT("'%wZ'\n", PathNameU
);
295 Hash
= vfatNameHash(0, PathNameU
);
297 entry
= pVCB
->FcbHashTable
[Hash
% pVCB
->HashTableSize
];
300 vfatSplitPathName(PathNameU
, &DirNameU
, &FileNameU
);
305 if (entry
->Hash
== Hash
)
308 DPRINT("'%wZ' '%wZ'\n", &DirNameU
, &rcFCB
->DirNameU
);
309 if (RtlEqualUnicodeString(&DirNameU
, &rcFCB
->DirNameU
, TRUE
))
311 if (rcFCB
->Hash
.Hash
== Hash
)
313 FcbNameU
= &rcFCB
->LongNameU
;
317 FcbNameU
= &rcFCB
->ShortNameU
;
319 /* compare the file name */
320 DPRINT("'%wZ' '%wZ'\n", &FileNameU
, FcbNameU
);
321 if (RtlEqualUnicodeString(&FileNameU
, FcbNameU
, TRUE
))
335 vfatFCBInitializeCacheFromVolume(
339 PFILE_OBJECT fileObject
;
342 fileObject
= IoCreateStreamFileObject (NULL
, vcb
->StorageDevice
);
344 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
347 return STATUS_INSUFFICIENT_RESOURCES
;
349 RtlZeroMemory(newCCB
, sizeof (VFATCCB
));
351 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
352 fileObject
->FsContext
= fcb
;
353 fileObject
->FsContext2
= newCCB
;
354 fcb
->FileObject
= fileObject
;
357 CcInitializeCacheMap(fileObject
,
358 (PCC_FILE_SIZES
)(&fcb
->RFCB
.AllocationSize
),
360 &VfatGlobalData
->CacheMgrCallbacks
,
363 fcb
->Flags
|= FCB_CACHE_INITIALIZED
;
364 return STATUS_SUCCESS
;
369 PDEVICE_EXTENSION pVCB
)
372 ULONG FirstCluster
, CurrentCluster
, Size
= 0;
373 NTSTATUS Status
= STATUS_SUCCESS
;
374 UNICODE_STRING NameU
= RTL_CONSTANT_STRING(L
"\\");
376 FCB
= vfatNewFCB(pVCB
, &NameU
);
377 if (FCB
->Flags
& FCB_IS_FATX_ENTRY
)
379 memset(FCB
->entry
.FatX
.Filename
, ' ', 42);
380 FCB
->entry
.FatX
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
381 FCB
->entry
.FatX
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
382 FCB
->entry
.FatX
.FirstCluster
= 1;
383 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
387 memset(FCB
->entry
.Fat
.ShortName
, ' ', 11);
388 FCB
->entry
.Fat
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
389 FCB
->entry
.Fat
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
390 if (pVCB
->FatInfo
.FatType
== FAT32
)
392 CurrentCluster
= FirstCluster
= pVCB
->FatInfo
.RootCluster
;
393 FCB
->entry
.Fat
.FirstCluster
= (unsigned short)(FirstCluster
& 0xffff);
394 FCB
->entry
.Fat
.FirstClusterHigh
= (unsigned short)(FirstCluster
>> 16);
396 while (CurrentCluster
!= 0xffffffff && NT_SUCCESS(Status
))
398 Size
+= pVCB
->FatInfo
.BytesPerCluster
;
399 Status
= NextCluster (pVCB
, FirstCluster
, &CurrentCluster
, FALSE
);
404 FCB
->entry
.Fat
.FirstCluster
= 1;
405 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
408 FCB
->ShortHash
.Hash
= FCB
->Hash
.Hash
;
411 FCB
->RFCB
.FileSize
.QuadPart
= Size
;
412 FCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
413 FCB
->RFCB
.AllocationSize
.QuadPart
= Size
;
414 FCB
->RFCB
.IsFastIoPossible
= FastIoIsNotPossible
;
416 vfatFCBInitializeCacheFromVolume(pVCB
, FCB
);
417 vfatAddFCBToTable(pVCB
, FCB
);
424 PDEVICE_EXTENSION pVCB
)
427 UNICODE_STRING NameU
= RTL_CONSTANT_STRING(L
"\\");
429 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
432 FCB
= vfatMakeRootFCB(pVCB
);
439 vfatMakeFCBFromDirEntry(
441 PVFATFCB directoryFCB
,
442 PVFAT_DIRENTRY_CONTEXT DirContext
,
446 PWCHAR PathNameBuffer
;
447 USHORT PathNameLength
;
451 UNICODE_STRING NameU
;
453 PathNameLength
= directoryFCB
->PathNameU
.Length
+ max(DirContext
->LongNameU
.Length
, DirContext
->ShortNameU
.Length
);
454 if (!vfatFCBIsRoot (directoryFCB
))
456 PathNameLength
+= sizeof(WCHAR
);
459 if (PathNameLength
> LONGNAME_MAX_LENGTH
* sizeof(WCHAR
))
461 return STATUS_OBJECT_NAME_INVALID
;
463 PathNameBuffer
= ExAllocatePoolWithTag(NonPagedPool
, PathNameLength
+ sizeof(WCHAR
), TAG_FCB
);
466 return STATUS_INSUFFICIENT_RESOURCES
;
468 NameU
.Buffer
= PathNameBuffer
;
470 NameU
.MaximumLength
= PathNameLength
;
472 RtlCopyUnicodeString(&NameU
, &directoryFCB
->PathNameU
);
473 if (!vfatFCBIsRoot(directoryFCB
))
475 RtlAppendUnicodeToString(&NameU
, L
"\\");
477 hash
= vfatNameHash(0, &NameU
);
478 if (DirContext
->LongNameU
.Length
> 0)
480 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->LongNameU
);
484 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->ShortNameU
);
486 NameU
.Buffer
[NameU
.Length
/ sizeof(WCHAR
)] = 0;
488 rcFCB
= vfatNewFCB(vcb
, &NameU
);
489 RtlCopyMemory(&rcFCB
->entry
, &DirContext
->DirEntry
, sizeof (DIR_ENTRY
));
490 RtlCopyUnicodeString(&rcFCB
->ShortNameU
, &DirContext
->ShortNameU
);
491 if (vcb
->Flags
& VCB_IS_FATX
)
493 rcFCB
->ShortHash
.Hash
= rcFCB
->Hash
.Hash
;
497 rcFCB
->ShortHash
.Hash
= vfatNameHash(hash
, &rcFCB
->ShortNameU
);
500 if (vfatFCBIsDirectory(rcFCB
))
502 ULONG FirstCluster
, CurrentCluster
;
503 NTSTATUS Status
= STATUS_SUCCESS
;
505 FirstCluster
= vfatDirEntryGetFirstCluster(vcb
, &rcFCB
->entry
);
506 if (FirstCluster
== 1)
508 Size
= vcb
->FatInfo
.rootDirectorySectors
* vcb
->FatInfo
.BytesPerSector
;
510 else if (FirstCluster
!= 0)
512 CurrentCluster
= FirstCluster
;
513 while (CurrentCluster
!= 0xffffffff && NT_SUCCESS(Status
))
515 Size
+= vcb
->FatInfo
.BytesPerCluster
;
516 Status
= NextCluster(vcb
, FirstCluster
, &CurrentCluster
, FALSE
);
520 else if (rcFCB
->Flags
& FCB_IS_FATX_ENTRY
)
522 Size
= rcFCB
->entry
.FatX
.FileSize
;
526 Size
= rcFCB
->entry
.Fat
.FileSize
;
528 rcFCB
->dirIndex
= DirContext
->DirIndex
;
529 rcFCB
->startIndex
= DirContext
->StartIndex
;
530 if ((rcFCB
->Flags
& FCB_IS_FATX_ENTRY
) && !vfatFCBIsRoot(directoryFCB
))
532 ASSERT(DirContext
->DirIndex
>= 2 && DirContext
->StartIndex
>= 2);
533 rcFCB
->dirIndex
= DirContext
->DirIndex
-2;
534 rcFCB
->startIndex
= DirContext
->StartIndex
-2;
536 rcFCB
->RFCB
.FileSize
.QuadPart
= Size
;
537 rcFCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
538 rcFCB
->RFCB
.AllocationSize
.QuadPart
= ROUND_UP(Size
, vcb
->FatInfo
.BytesPerCluster
);
540 if (vfatFCBIsDirectory(rcFCB
))
542 vfatFCBInitializeCacheFromVolume(vcb
, rcFCB
);
544 rcFCB
->parentFcb
= directoryFCB
;
545 vfatAddFCBToTable(vcb
, rcFCB
);
548 ExFreePool(PathNameBuffer
);
549 return STATUS_SUCCESS
;
553 vfatAttachFCBToFileObject(
554 PDEVICE_EXTENSION vcb
,
556 PFILE_OBJECT fileObject
)
560 UNREFERENCED_PARAMETER(vcb
);
562 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
565 return STATUS_INSUFFICIENT_RESOURCES
;
567 RtlZeroMemory(newCCB
, sizeof (VFATCCB
));
569 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
570 fileObject
->FsContext
= fcb
;
571 fileObject
->FsContext2
= newCCB
;
572 DPRINT("file open: fcb:%p PathName:%wZ\n", fcb
, &fcb
->PathNameU
);
574 return STATUS_SUCCESS
;
579 PDEVICE_EXTENSION pDeviceExt
,
580 PVFATFCB pDirectoryFCB
,
581 PUNICODE_STRING FileToFindU
,
585 PVOID Context
= NULL
;
587 BOOLEAN First
= TRUE
;
588 VFAT_DIRENTRY_CONTEXT DirContext
;
589 /* This buffer must have a size of 260 characters, because
590 vfatMakeFCBFromDirEntry can copy 20 name entries with 13 characters. */
591 WCHAR LongNameBuffer
[260];
592 WCHAR ShortNameBuffer
[13];
593 BOOLEAN FoundLong
= FALSE
;
594 BOOLEAN FoundShort
= FALSE
;
597 ASSERT(pDirectoryFCB
);
600 DPRINT("vfatDirFindFile(VCB:%p, dirFCB:%p, File:%wZ)\n",
601 pDeviceExt
, pDirectoryFCB
, FileToFindU
);
602 DPRINT("Dir Path:%wZ\n", &pDirectoryFCB
->PathNameU
);
604 DirContext
.DirIndex
= 0;
605 DirContext
.LongNameU
.Buffer
= LongNameBuffer
;
606 DirContext
.LongNameU
.Length
= 0;
607 DirContext
.LongNameU
.MaximumLength
= sizeof(LongNameBuffer
);
608 DirContext
.ShortNameU
.Buffer
= ShortNameBuffer
;
609 DirContext
.ShortNameU
.Length
= 0;
610 DirContext
.ShortNameU
.MaximumLength
= sizeof(ShortNameBuffer
);
614 status
= pDeviceExt
->GetNextDirEntry(&Context
,
620 if (status
== STATUS_NO_MORE_ENTRIES
)
622 return STATUS_OBJECT_NAME_NOT_FOUND
;
624 if (!NT_SUCCESS(status
))
629 DPRINT(" Index:%u longName:%wZ\n",
630 DirContext
.DirIndex
, &DirContext
.LongNameU
);
632 if (!ENTRY_VOLUME(pDeviceExt
, &DirContext
.DirEntry
))
634 FoundLong
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.LongNameU
, TRUE
);
635 if (FoundLong
== FALSE
)
637 FoundShort
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.ShortNameU
, TRUE
);
639 if (FoundLong
|| FoundShort
)
641 status
= vfatMakeFCBFromDirEntry(pDeviceExt
,
645 CcUnpinData(Context
);
649 DirContext
.DirIndex
++;
652 return STATUS_OBJECT_NAME_NOT_FOUND
;
657 PDEVICE_EXTENSION pVCB
,
658 PVFATFCB
*pParentFCB
,
660 PUNICODE_STRING pFileNameU
)
665 UNICODE_STRING NameU
;
666 UNICODE_STRING RootNameU
= RTL_CONSTANT_STRING(L
"\\");
667 UNICODE_STRING FileNameU
;
668 WCHAR NameBuffer
[260];
669 PWCHAR curr
, prev
, last
;
672 DPRINT("vfatGetFCBForFile (%p,%p,%p,%wZ)\n",
673 pVCB
, pParentFCB
, pFCB
, pFileNameU
);
675 FileNameU
.Buffer
= NameBuffer
;
676 FileNameU
.MaximumLength
= sizeof(NameBuffer
);
677 RtlCopyUnicodeString(&FileNameU
, pFileNameU
);
679 parentFCB
= *pParentFCB
;
681 if (parentFCB
== NULL
)
683 // Trivial case, open of the root directory on volume
684 if (RtlEqualUnicodeString(&FileNameU
, &RootNameU
, FALSE
))
686 DPRINT("returning root FCB\n");
688 FCB
= vfatOpenRootFCB(pVCB
);
692 return (FCB
!= NULL
) ? STATUS_SUCCESS
: STATUS_OBJECT_PATH_NOT_FOUND
;
695 /* Check for an existing FCB */
696 FCB
= vfatGrabFCBFromTable(pVCB
, &FileNameU
);
700 *pParentFCB
= FCB
->parentFcb
;
701 (*pParentFCB
)->RefCount
++;
702 return STATUS_SUCCESS
;
705 last
= curr
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
706 while (*curr
!= L
'\\' && curr
> FileNameU
.Buffer
)
711 if (curr
> FileNameU
.Buffer
)
713 NameU
.Buffer
= FileNameU
.Buffer
;
714 NameU
.MaximumLength
= NameU
.Length
= (curr
- FileNameU
.Buffer
) * sizeof(WCHAR
);
715 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
718 Length
= (curr
- FileNameU
.Buffer
) * sizeof(WCHAR
);
719 if (Length
!= FCB
->PathNameU
.Length
)
721 if (FileNameU
.Length
+ FCB
->PathNameU
.Length
- Length
> FileNameU
.MaximumLength
)
723 vfatReleaseFCB(pVCB
, FCB
);
724 return STATUS_OBJECT_NAME_INVALID
;
726 RtlMoveMemory(FileNameU
.Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
),
727 curr
, FileNameU
.Length
- Length
);
728 FileNameU
.Length
+= (USHORT
)(FCB
->PathNameU
.Length
- Length
);
729 curr
= FileNameU
.Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
);
730 last
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
732 RtlCopyMemory(FileNameU
.Buffer
, FCB
->PathNameU
.Buffer
, FCB
->PathNameU
.Length
);
742 FCB
= vfatOpenRootFCB(pVCB
);
743 curr
= FileNameU
.Buffer
;
753 prev
= curr
= FileNameU
.Buffer
- 1;
754 last
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
761 vfatReleaseFCB(pVCB
, parentFCB
);
764 // fail if element in FCB is not a directory
765 if (!vfatFCBIsDirectory(FCB
))
767 DPRINT ("Element in requested path is not a directory\n");
769 vfatReleaseFCB(pVCB
, FCB
);
774 return STATUS_OBJECT_PATH_NOT_FOUND
;
779 Length
= (curr
- prev
) * sizeof(WCHAR
);
780 if (Length
!= parentFCB
->LongNameU
.Length
)
782 if (FileNameU
.Length
+ parentFCB
->LongNameU
.Length
- Length
> FileNameU
.MaximumLength
)
784 vfatReleaseFCB(pVCB
, parentFCB
);
785 return STATUS_OBJECT_NAME_INVALID
;
787 RtlMoveMemory(prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
), curr
,
788 FileNameU
.Length
- (curr
- FileNameU
.Buffer
) * sizeof(WCHAR
));
789 FileNameU
.Length
+= (USHORT
)(parentFCB
->LongNameU
.Length
- Length
);
790 curr
= prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
);
791 last
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
793 RtlCopyMemory(prev
, parentFCB
->LongNameU
.Buffer
, parentFCB
->LongNameU
.Length
);
797 while (*curr
!= L
'\\' && curr
<= last
)
801 NameU
.Buffer
= FileNameU
.Buffer
;
802 NameU
.Length
= (curr
- NameU
.Buffer
) * sizeof(WCHAR
);
803 NameU
.MaximumLength
= FileNameU
.MaximumLength
;
804 DPRINT("%wZ\n", &NameU
);
805 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
809 NameU
.MaximumLength
= NameU
.Length
= (curr
- prev
) * sizeof(WCHAR
);
810 status
= vfatDirFindFile(pVCB
, parentFCB
, &NameU
, &FCB
);
811 if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
816 *pParentFCB
= parentFCB
;
817 return STATUS_OBJECT_NAME_NOT_FOUND
;
821 vfatReleaseFCB(pVCB
, parentFCB
);
823 return STATUS_OBJECT_PATH_NOT_FOUND
;
826 else if (!NT_SUCCESS(status
))
828 vfatReleaseFCB(pVCB
, parentFCB
);
837 *pParentFCB
= parentFCB
;
840 return STATUS_SUCCESS
;