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 */
19 #include <wctype.h> /* towlower prototype */
22 /* -------------------------------------------------------- DEFINES */
24 #define TAG_FCB 'BCFV'
26 /* -------------------------------------------------------- PUBLICS */
32 PUNICODE_STRING NameU
)
38 // LFN could start from "."
39 //ASSERT(NameU->Buffer[0] != L'.');
41 last
= NameU
->Buffer
+ NameU
->Length
/ sizeof(WCHAR
);
45 c
= towlower(*curr
++);
46 hash
= (hash
+ (c
<< 4) + (c
>> 4)) * 11;
53 PUNICODE_STRING PathNameU
,
54 PUNICODE_STRING DirNameU
,
55 PUNICODE_STRING FileNameU
)
59 pName
= PathNameU
->Buffer
+ PathNameU
->Length
/ sizeof(WCHAR
) - 1;
60 while (*pName
!= L
'\\' && pName
>= PathNameU
->Buffer
)
65 ASSERT(*pName
== L
'\\' || pName
< PathNameU
->Buffer
);
68 FileNameU
->Buffer
= pName
+ 1;
69 FileNameU
->Length
= FileNameU
->MaximumLength
= Length
* sizeof(WCHAR
);
73 DirNameU
->Buffer
= PathNameU
->Buffer
;
74 DirNameU
->Length
= (pName
+ 1 - PathNameU
->Buffer
) * sizeof(WCHAR
);
75 DirNameU
->MaximumLength
= DirNameU
->Length
;
83 PUNICODE_STRING NameU
)
85 USHORT PathNameBufferLength
;
88 PathNameBufferLength
= NameU
->Length
+ sizeof(WCHAR
);
90 PathNameBufferLength
= 0;
92 Fcb
->PathNameBuffer
= ExAllocatePoolWithTag(NonPagedPool
, PathNameBufferLength
, TAG_FCB
);
93 if (!Fcb
->PathNameBuffer
)
95 /* FIXME: what to do if no more memory? */
96 DPRINT1("Unable to initialize FCB for filename '%wZ'\n", NameU
);
97 KeBugCheckEx(FAT_FILE_SYSTEM
, (ULONG_PTR
)Fcb
, (ULONG_PTR
)NameU
, 0, 0);
100 Fcb
->PathNameU
.Length
= 0;
101 Fcb
->PathNameU
.Buffer
= Fcb
->PathNameBuffer
;
102 Fcb
->PathNameU
.MaximumLength
= PathNameBufferLength
;
103 Fcb
->ShortNameU
.Length
= 0;
104 Fcb
->ShortNameU
.Buffer
= Fcb
->ShortNameBuffer
;
105 Fcb
->ShortNameU
.MaximumLength
= sizeof(Fcb
->ShortNameBuffer
);
106 Fcb
->DirNameU
.Buffer
= Fcb
->PathNameU
.Buffer
;
107 if (NameU
&& NameU
->Length
)
109 RtlCopyUnicodeString(&Fcb
->PathNameU
, NameU
);
110 vfatSplitPathName(&Fcb
->PathNameU
, &Fcb
->DirNameU
, &Fcb
->LongNameU
);
114 Fcb
->DirNameU
.Buffer
= Fcb
->LongNameU
.Buffer
= NULL
;
115 Fcb
->DirNameU
.MaximumLength
= Fcb
->DirNameU
.Length
= 0;
116 Fcb
->LongNameU
.MaximumLength
= Fcb
->LongNameU
.Length
= 0;
118 RtlZeroMemory(&Fcb
->FCBShareAccess
, sizeof(SHARE_ACCESS
));
119 Fcb
->OpenHandleCount
= 0;
124 PDEVICE_EXTENSION pVCB
,
125 PUNICODE_STRING pFileNameU
)
129 DPRINT("'%wZ'\n", pFileNameU
);
131 rcFCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
);
136 RtlZeroMemory(rcFCB
, sizeof(VFATFCB
));
137 vfatInitFcb(rcFCB
, pFileNameU
);
138 if (pVCB
->Flags
& VCB_IS_FATX
)
140 rcFCB
->Flags
|= FCB_IS_FATX_ENTRY
;
141 rcFCB
->Attributes
= &rcFCB
->entry
.FatX
.Attrib
;
144 rcFCB
->Attributes
= &rcFCB
->entry
.Fat
.Attrib
;
145 rcFCB
->Hash
.Hash
= vfatNameHash(0, &rcFCB
->PathNameU
);
146 rcFCB
->Hash
.self
= rcFCB
;
147 rcFCB
->ShortHash
.self
= rcFCB
;
148 ExInitializeResourceLite(&rcFCB
->PagingIoResource
);
149 ExInitializeResourceLite(&rcFCB
->MainResource
);
150 FsRtlInitializeFileLock(&rcFCB
->FileLock
, NULL
, NULL
);
151 ExInitializeFastMutex(&rcFCB
->LastMutex
);
152 rcFCB
->RFCB
.PagingIoResource
= &rcFCB
->PagingIoResource
;
153 rcFCB
->RFCB
.Resource
= &rcFCB
->MainResource
;
154 rcFCB
->RFCB
.IsFastIoPossible
= FastIoIsNotPossible
;
163 if (pCcb
->SearchPattern
.Buffer
)
165 ExFreePoolWithTag(pCcb
->SearchPattern
.Buffer
, TAG_VFAT
);
167 ExFreeToNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
, pCcb
);
174 FsRtlUninitializeFileLock(&pFCB
->FileLock
);
175 ExFreePool(pFCB
->PathNameBuffer
);
176 ExDeleteResourceLite(&pFCB
->PagingIoResource
);
177 ExDeleteResourceLite(&pFCB
->MainResource
);
178 ExFreeToNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
, pFCB
);
185 return *FCB
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
;
192 return FCB
->PathNameU
.Length
== sizeof(WCHAR
) && FCB
->PathNameU
.Buffer
[0] == L
'\\' ? TRUE
: FALSE
;
197 PDEVICE_EXTENSION pVCB
,
205 DPRINT("releasing FCB at %p: %wZ, refCount:%d\n",
206 pFCB
, &pFCB
->PathNameU
, pFCB
->RefCount
);
210 Index
= pFCB
->Hash
.Hash
% pVCB
->HashTableSize
;
211 ShortIndex
= pFCB
->ShortHash
.Hash
% pVCB
->HashTableSize
;
213 if (pFCB
->RefCount
== 0)
215 tmpFcb
= pFCB
->parentFcb
;
216 RemoveEntryList (&pFCB
->FcbListEntry
);
217 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
219 entry
= pVCB
->FcbHashTable
[ShortIndex
];
220 if (entry
->self
== pFCB
)
222 pVCB
->FcbHashTable
[ShortIndex
] = entry
->next
;
226 while (entry
->next
->self
!= pFCB
)
230 entry
->next
= pFCB
->ShortHash
.next
;
233 entry
= pVCB
->FcbHashTable
[Index
];
234 if (entry
->self
== pFCB
)
236 pVCB
->FcbHashTable
[Index
] = entry
->next
;
240 while (entry
->next
->self
!= pFCB
)
244 entry
->next
= pFCB
->Hash
.next
;
246 vfatDestroyFCB(pFCB
);
258 PDEVICE_EXTENSION pVCB
,
264 Index
= pFCB
->Hash
.Hash
% pVCB
->HashTableSize
;
265 ShortIndex
= pFCB
->ShortHash
.Hash
% pVCB
->HashTableSize
;
267 InsertTailList(&pVCB
->FcbListHead
, &pFCB
->FcbListEntry
);
269 pFCB
->Hash
.next
= pVCB
->FcbHashTable
[Index
];
270 pVCB
->FcbHashTable
[Index
] = &pFCB
->Hash
;
271 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
273 pFCB
->ShortHash
.next
= pVCB
->FcbHashTable
[ShortIndex
];
274 pVCB
->FcbHashTable
[ShortIndex
] = &pFCB
->ShortHash
;
278 pFCB
->parentFcb
->RefCount
++;
283 vfatGrabFCBFromTable(
284 PDEVICE_EXTENSION pVCB
,
285 PUNICODE_STRING PathNameU
)
289 UNICODE_STRING DirNameU
;
290 UNICODE_STRING FileNameU
;
291 PUNICODE_STRING FcbNameU
;
295 DPRINT("'%wZ'\n", PathNameU
);
297 Hash
= vfatNameHash(0, PathNameU
);
299 entry
= pVCB
->FcbHashTable
[Hash
% pVCB
->HashTableSize
];
302 vfatSplitPathName(PathNameU
, &DirNameU
, &FileNameU
);
307 if (entry
->Hash
== Hash
)
310 DPRINT("'%wZ' '%wZ'\n", &DirNameU
, &rcFCB
->DirNameU
);
311 if (RtlEqualUnicodeString(&DirNameU
, &rcFCB
->DirNameU
, TRUE
))
313 if (rcFCB
->Hash
.Hash
== Hash
)
315 FcbNameU
= &rcFCB
->LongNameU
;
319 FcbNameU
= &rcFCB
->ShortNameU
;
321 /* compare the file name */
322 DPRINT("'%wZ' '%wZ'\n", &FileNameU
, FcbNameU
);
323 if (RtlEqualUnicodeString(&FileNameU
, FcbNameU
, TRUE
))
337 vfatFCBInitializeCacheFromVolume(
341 PFILE_OBJECT fileObject
;
344 fileObject
= IoCreateStreamFileObject (NULL
, vcb
->StorageDevice
);
346 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
349 return STATUS_INSUFFICIENT_RESOURCES
;
351 RtlZeroMemory(newCCB
, sizeof (VFATCCB
));
353 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
354 fileObject
->FsContext
= fcb
;
355 fileObject
->FsContext2
= newCCB
;
356 fcb
->FileObject
= fileObject
;
359 CcInitializeCacheMap(fileObject
,
360 (PCC_FILE_SIZES
)(&fcb
->RFCB
.AllocationSize
),
362 &VfatGlobalData
->CacheMgrCallbacks
,
365 fcb
->Flags
|= FCB_CACHE_INITIALIZED
;
366 return STATUS_SUCCESS
;
371 PDEVICE_EXTENSION pVCB
)
374 ULONG FirstCluster
, CurrentCluster
, Size
= 0;
375 NTSTATUS Status
= STATUS_SUCCESS
;
376 UNICODE_STRING NameU
= RTL_CONSTANT_STRING(L
"\\");
378 FCB
= vfatNewFCB(pVCB
, &NameU
);
379 if (FCB
->Flags
& FCB_IS_FATX_ENTRY
)
381 memset(FCB
->entry
.FatX
.Filename
, ' ', 42);
382 FCB
->entry
.FatX
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
383 FCB
->entry
.FatX
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
384 FCB
->entry
.FatX
.FirstCluster
= 1;
385 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
389 memset(FCB
->entry
.Fat
.ShortName
, ' ', 11);
390 FCB
->entry
.Fat
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
391 FCB
->entry
.Fat
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
392 if (pVCB
->FatInfo
.FatType
== FAT32
)
394 CurrentCluster
= FirstCluster
= pVCB
->FatInfo
.RootCluster
;
395 FCB
->entry
.Fat
.FirstCluster
= (unsigned short)(FirstCluster
& 0xffff);
396 FCB
->entry
.Fat
.FirstClusterHigh
= (unsigned short)(FirstCluster
>> 16);
398 while (CurrentCluster
!= 0xffffffff && NT_SUCCESS(Status
))
400 Size
+= pVCB
->FatInfo
.BytesPerCluster
;
401 Status
= NextCluster (pVCB
, FirstCluster
, &CurrentCluster
, FALSE
);
406 FCB
->entry
.Fat
.FirstCluster
= 1;
407 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
410 FCB
->ShortHash
.Hash
= FCB
->Hash
.Hash
;
413 FCB
->RFCB
.FileSize
.QuadPart
= Size
;
414 FCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
415 FCB
->RFCB
.AllocationSize
.QuadPart
= Size
;
416 FCB
->RFCB
.IsFastIoPossible
= FastIoIsNotPossible
;
418 vfatFCBInitializeCacheFromVolume(pVCB
, FCB
);
419 vfatAddFCBToTable(pVCB
, FCB
);
426 PDEVICE_EXTENSION pVCB
)
429 UNICODE_STRING NameU
= RTL_CONSTANT_STRING(L
"\\");
431 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
434 FCB
= vfatMakeRootFCB(pVCB
);
441 vfatMakeFCBFromDirEntry(
443 PVFATFCB directoryFCB
,
444 PVFAT_DIRENTRY_CONTEXT DirContext
,
448 PWCHAR PathNameBuffer
;
449 USHORT PathNameLength
;
453 UNICODE_STRING NameU
;
455 PathNameLength
= directoryFCB
->PathNameU
.Length
+ max(DirContext
->LongNameU
.Length
, DirContext
->ShortNameU
.Length
);
456 if (!vfatFCBIsRoot (directoryFCB
))
458 PathNameLength
+= sizeof(WCHAR
);
461 if (PathNameLength
> LONGNAME_MAX_LENGTH
* sizeof(WCHAR
))
463 return STATUS_OBJECT_NAME_INVALID
;
465 PathNameBuffer
= ExAllocatePoolWithTag(NonPagedPool
, PathNameLength
+ sizeof(WCHAR
), TAG_FCB
);
468 return STATUS_INSUFFICIENT_RESOURCES
;
470 NameU
.Buffer
= PathNameBuffer
;
472 NameU
.MaximumLength
= PathNameLength
;
474 RtlCopyUnicodeString(&NameU
, &directoryFCB
->PathNameU
);
475 if (!vfatFCBIsRoot(directoryFCB
))
477 RtlAppendUnicodeToString(&NameU
, L
"\\");
479 hash
= vfatNameHash(0, &NameU
);
480 if (DirContext
->LongNameU
.Length
> 0)
482 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->LongNameU
);
486 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->ShortNameU
);
488 NameU
.Buffer
[NameU
.Length
/ sizeof(WCHAR
)] = 0;
490 rcFCB
= vfatNewFCB(vcb
, &NameU
);
491 RtlCopyMemory(&rcFCB
->entry
, &DirContext
->DirEntry
, sizeof (DIR_ENTRY
));
492 RtlCopyUnicodeString(&rcFCB
->ShortNameU
, &DirContext
->ShortNameU
);
493 if (vcb
->Flags
& VCB_IS_FATX
)
495 rcFCB
->ShortHash
.Hash
= rcFCB
->Hash
.Hash
;
499 rcFCB
->ShortHash
.Hash
= vfatNameHash(hash
, &rcFCB
->ShortNameU
);
502 if (vfatFCBIsDirectory(rcFCB
))
504 ULONG FirstCluster
, CurrentCluster
;
505 NTSTATUS Status
= STATUS_SUCCESS
;
507 FirstCluster
= vfatDirEntryGetFirstCluster(vcb
, &rcFCB
->entry
);
508 if (FirstCluster
== 1)
510 Size
= vcb
->FatInfo
.rootDirectorySectors
* vcb
->FatInfo
.BytesPerSector
;
512 else if (FirstCluster
!= 0)
514 CurrentCluster
= FirstCluster
;
515 while (CurrentCluster
!= 0xffffffff && NT_SUCCESS(Status
))
517 Size
+= vcb
->FatInfo
.BytesPerCluster
;
518 Status
= NextCluster(vcb
, FirstCluster
, &CurrentCluster
, FALSE
);
522 else if (rcFCB
->Flags
& FCB_IS_FATX_ENTRY
)
524 Size
= rcFCB
->entry
.FatX
.FileSize
;
528 Size
= rcFCB
->entry
.Fat
.FileSize
;
530 rcFCB
->dirIndex
= DirContext
->DirIndex
;
531 rcFCB
->startIndex
= DirContext
->StartIndex
;
532 if ((rcFCB
->Flags
& FCB_IS_FATX_ENTRY
) && !vfatFCBIsRoot(directoryFCB
))
534 ASSERT(DirContext
->DirIndex
>= 2 && DirContext
->StartIndex
>= 2);
535 rcFCB
->dirIndex
= DirContext
->DirIndex
-2;
536 rcFCB
->startIndex
= DirContext
->StartIndex
-2;
538 rcFCB
->RFCB
.FileSize
.QuadPart
= Size
;
539 rcFCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
540 rcFCB
->RFCB
.AllocationSize
.QuadPart
= ROUND_UP(Size
, vcb
->FatInfo
.BytesPerCluster
);
542 if (vfatFCBIsDirectory(rcFCB
))
544 vfatFCBInitializeCacheFromVolume(vcb
, rcFCB
);
546 rcFCB
->parentFcb
= directoryFCB
;
547 vfatAddFCBToTable(vcb
, rcFCB
);
550 ExFreePool(PathNameBuffer
);
551 return STATUS_SUCCESS
;
555 vfatAttachFCBToFileObject(
556 PDEVICE_EXTENSION vcb
,
558 PFILE_OBJECT fileObject
)
562 UNREFERENCED_PARAMETER(vcb
);
564 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
567 return STATUS_INSUFFICIENT_RESOURCES
;
569 RtlZeroMemory(newCCB
, sizeof (VFATCCB
));
571 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
572 fileObject
->FsContext
= fcb
;
573 fileObject
->FsContext2
= newCCB
;
574 DPRINT("file open: fcb:%p PathName:%wZ\n", fcb
, &fcb
->PathNameU
);
576 return STATUS_SUCCESS
;
581 PDEVICE_EXTENSION pDeviceExt
,
582 PVFATFCB pDirectoryFCB
,
583 PUNICODE_STRING FileToFindU
,
587 PVOID Context
= NULL
;
589 BOOLEAN First
= TRUE
;
590 VFAT_DIRENTRY_CONTEXT DirContext
;
591 /* This buffer must have a size of 260 characters, because
592 vfatMakeFCBFromDirEntry can copy 20 name entries with 13 characters. */
593 WCHAR LongNameBuffer
[260];
594 WCHAR ShortNameBuffer
[13];
595 BOOLEAN FoundLong
= FALSE
;
596 BOOLEAN FoundShort
= FALSE
;
599 ASSERT(pDirectoryFCB
);
602 DPRINT("vfatDirFindFile(VCB:%p, dirFCB:%p, File:%wZ)\n",
603 pDeviceExt
, pDirectoryFCB
, FileToFindU
);
604 DPRINT("Dir Path:%wZ\n", &pDirectoryFCB
->PathNameU
);
606 DirContext
.DirIndex
= 0;
607 DirContext
.LongNameU
.Buffer
= LongNameBuffer
;
608 DirContext
.LongNameU
.Length
= 0;
609 DirContext
.LongNameU
.MaximumLength
= sizeof(LongNameBuffer
);
610 DirContext
.ShortNameU
.Buffer
= ShortNameBuffer
;
611 DirContext
.ShortNameU
.Length
= 0;
612 DirContext
.ShortNameU
.MaximumLength
= sizeof(ShortNameBuffer
);
616 status
= pDeviceExt
->GetNextDirEntry(&Context
,
622 if (status
== STATUS_NO_MORE_ENTRIES
)
624 return STATUS_OBJECT_NAME_NOT_FOUND
;
626 if (!NT_SUCCESS(status
))
631 DPRINT(" Index:%u longName:%wZ\n",
632 DirContext
.DirIndex
, &DirContext
.LongNameU
);
634 if (!ENTRY_VOLUME(pDeviceExt
, &DirContext
.DirEntry
))
636 FoundLong
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.LongNameU
, TRUE
);
637 if (FoundLong
== FALSE
)
639 FoundShort
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.ShortNameU
, TRUE
);
641 if (FoundLong
|| FoundShort
)
643 status
= vfatMakeFCBFromDirEntry(pDeviceExt
,
647 CcUnpinData(Context
);
651 DirContext
.DirIndex
++;
654 return STATUS_OBJECT_NAME_NOT_FOUND
;
659 PDEVICE_EXTENSION pVCB
,
660 PVFATFCB
*pParentFCB
,
662 PUNICODE_STRING pFileNameU
)
667 UNICODE_STRING NameU
;
668 UNICODE_STRING RootNameU
= RTL_CONSTANT_STRING(L
"\\");
669 UNICODE_STRING FileNameU
;
670 WCHAR NameBuffer
[260];
671 PWCHAR curr
, prev
, last
;
674 DPRINT("vfatGetFCBForFile (%p,%p,%p,%wZ)\n",
675 pVCB
, pParentFCB
, pFCB
, pFileNameU
);
677 FileNameU
.Buffer
= NameBuffer
;
678 FileNameU
.MaximumLength
= sizeof(NameBuffer
);
679 RtlCopyUnicodeString(&FileNameU
, pFileNameU
);
681 parentFCB
= *pParentFCB
;
683 if (parentFCB
== NULL
)
685 // Trivial case, open of the root directory on volume
686 if (RtlEqualUnicodeString(&FileNameU
, &RootNameU
, FALSE
))
688 DPRINT("returning root FCB\n");
690 FCB
= vfatOpenRootFCB(pVCB
);
694 return (FCB
!= NULL
) ? STATUS_SUCCESS
: STATUS_OBJECT_PATH_NOT_FOUND
;
697 /* Check for an existing FCB */
698 FCB
= vfatGrabFCBFromTable(pVCB
, &FileNameU
);
702 *pParentFCB
= FCB
->parentFcb
;
703 (*pParentFCB
)->RefCount
++;
704 return STATUS_SUCCESS
;
707 last
= curr
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
708 while (*curr
!= L
'\\' && curr
> FileNameU
.Buffer
)
713 if (curr
> FileNameU
.Buffer
)
715 NameU
.Buffer
= FileNameU
.Buffer
;
716 NameU
.MaximumLength
= NameU
.Length
= (curr
- FileNameU
.Buffer
) * sizeof(WCHAR
);
717 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
720 Length
= (curr
- FileNameU
.Buffer
) * sizeof(WCHAR
);
721 if (Length
!= FCB
->PathNameU
.Length
)
723 if (FileNameU
.Length
+ FCB
->PathNameU
.Length
- Length
> FileNameU
.MaximumLength
)
725 vfatReleaseFCB(pVCB
, FCB
);
726 return STATUS_OBJECT_NAME_INVALID
;
728 RtlMoveMemory(FileNameU
.Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
),
729 curr
, FileNameU
.Length
- Length
);
730 FileNameU
.Length
+= (USHORT
)(FCB
->PathNameU
.Length
- Length
);
731 curr
= FileNameU
.Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
);
732 last
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
734 RtlCopyMemory(FileNameU
.Buffer
, FCB
->PathNameU
.Buffer
, FCB
->PathNameU
.Length
);
744 FCB
= vfatOpenRootFCB(pVCB
);
745 curr
= FileNameU
.Buffer
;
755 prev
= curr
= FileNameU
.Buffer
- 1;
756 last
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
763 vfatReleaseFCB(pVCB
, parentFCB
);
766 // fail if element in FCB is not a directory
767 if (!vfatFCBIsDirectory(FCB
))
769 DPRINT ("Element in requested path is not a directory\n");
771 vfatReleaseFCB(pVCB
, FCB
);
776 return STATUS_OBJECT_PATH_NOT_FOUND
;
781 Length
= (curr
- prev
) * sizeof(WCHAR
);
782 if (Length
!= parentFCB
->LongNameU
.Length
)
784 if (FileNameU
.Length
+ parentFCB
->LongNameU
.Length
- Length
> FileNameU
.MaximumLength
)
786 vfatReleaseFCB(pVCB
, parentFCB
);
787 return STATUS_OBJECT_NAME_INVALID
;
789 RtlMoveMemory(prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
), curr
,
790 FileNameU
.Length
- (curr
- FileNameU
.Buffer
) * sizeof(WCHAR
));
791 FileNameU
.Length
+= (USHORT
)(parentFCB
->LongNameU
.Length
- Length
);
792 curr
= prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
);
793 last
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
795 RtlCopyMemory(prev
, parentFCB
->LongNameU
.Buffer
, parentFCB
->LongNameU
.Length
);
799 while (*curr
!= L
'\\' && curr
<= last
)
803 NameU
.Buffer
= FileNameU
.Buffer
;
804 NameU
.Length
= (curr
- NameU
.Buffer
) * sizeof(WCHAR
);
805 NameU
.MaximumLength
= FileNameU
.MaximumLength
;
806 DPRINT("%wZ\n", &NameU
);
807 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
811 NameU
.MaximumLength
= NameU
.Length
= (curr
- prev
) * sizeof(WCHAR
);
812 status
= vfatDirFindFile(pVCB
, parentFCB
, &NameU
, &FCB
);
813 if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
818 *pParentFCB
= parentFCB
;
819 return STATUS_OBJECT_NAME_NOT_FOUND
;
823 vfatReleaseFCB(pVCB
, parentFCB
);
825 return STATUS_OBJECT_PATH_NOT_FOUND
;
828 else if (!NT_SUCCESS(status
))
830 vfatReleaseFCB(pVCB
, parentFCB
);
839 *pParentFCB
= parentFCB
;
842 return STATUS_SUCCESS
;