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)
9 * Herve Poussineau (reactos@poussine.freesurf.fr)
12 /* ------------------------------------------------------- INCLUDES */
14 #include <wctype.h> /* towlower prototype */
19 /* -------------------------------------------------------- DEFINES */
21 #define TAG_FCB TAG('V', 'F', 'C', 'B')
23 /* -------------------------------------------------------- PUBLICS */
25 ULONG
vfatNameHash(ULONG hash
, PUNICODE_STRING NameU
)
31 ASSERT(NameU
->Buffer
[0] != L
'.');
33 last
= NameU
->Buffer
+ NameU
->Length
/ sizeof(WCHAR
);
37 c
= towlower(*curr
++);
38 hash
= (hash
+ (c
<< 4) + (c
>> 4)) * 11;
44 vfatSplitPathName(PUNICODE_STRING PathNameU
, PUNICODE_STRING DirNameU
, PUNICODE_STRING FileNameU
)
48 pName
= PathNameU
->Buffer
+ PathNameU
->Length
/ sizeof(WCHAR
) - 1;
49 while (*pName
!= L
'\\' && pName
>= PathNameU
->Buffer
)
54 ASSERT(*pName
== L
'\\' || pName
< PathNameU
->Buffer
);
57 FileNameU
->Buffer
= pName
+ 1;
58 FileNameU
->Length
= FileNameU
->MaximumLength
= Length
* sizeof(WCHAR
);
62 DirNameU
->Buffer
= PathNameU
->Buffer
;
63 DirNameU
->Length
= (pName
+ 1 - PathNameU
->Buffer
) * sizeof(WCHAR
);
64 DirNameU
->MaximumLength
= DirNameU
->Length
;
69 vfatInitFcb(PVFATFCB Fcb
, PUNICODE_STRING NameU
)
71 USHORT PathNameBufferLength
;
74 PathNameBufferLength
= NameU
->Length
+ sizeof(WCHAR
);
76 PathNameBufferLength
= 0;
78 Fcb
->PathNameBuffer
= ExAllocatePool(NonPagedPool
, PathNameBufferLength
);
79 if (!Fcb
->PathNameBuffer
)
81 /* FIXME: what to do if no more memory? */
82 DPRINT1("Unable to initialize FCB for filename '%wZ'\n", NameU
);
83 KEBUGCHECKEX(0, (ULONG_PTR
)Fcb
, (ULONG_PTR
)NameU
, 0, 0);
86 Fcb
->PathNameU
.Length
= 0;
87 Fcb
->PathNameU
.Buffer
= Fcb
->PathNameBuffer
;
88 Fcb
->PathNameU
.MaximumLength
= PathNameBufferLength
;
89 Fcb
->ShortNameU
.Length
= 0;
90 Fcb
->ShortNameU
.Buffer
= Fcb
->ShortNameBuffer
;
91 Fcb
->ShortNameU
.MaximumLength
= sizeof(Fcb
->ShortNameBuffer
);
92 Fcb
->DirNameU
.Buffer
= Fcb
->PathNameU
.Buffer
;
93 if (NameU
&& NameU
->Length
)
95 RtlCopyUnicodeString(&Fcb
->PathNameU
, NameU
);
96 vfatSplitPathName(&Fcb
->PathNameU
, &Fcb
->DirNameU
, &Fcb
->LongNameU
);
100 Fcb
->DirNameU
.Buffer
= Fcb
->LongNameU
.Buffer
= NULL
;
101 Fcb
->DirNameU
.MaximumLength
= Fcb
->DirNameU
.Length
= 0;
102 Fcb
->LongNameU
.MaximumLength
= Fcb
->LongNameU
.Length
= 0;
104 RtlZeroMemory(&Fcb
->FCBShareAccess
, sizeof(SHARE_ACCESS
));
105 Fcb
->OpenHandleCount
= 0;
109 vfatNewFCB(PDEVICE_EXTENSION pVCB
, PUNICODE_STRING pFileNameU
)
113 DPRINT("'%wZ'\n", pFileNameU
);
115 rcFCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
);
120 RtlZeroMemory(rcFCB
, sizeof(VFATFCB
));
121 vfatInitFcb(rcFCB
, pFileNameU
);
122 if (pVCB
->Flags
& VCB_IS_FATX
)
124 rcFCB
->Flags
|= FCB_IS_FATX_ENTRY
;
125 rcFCB
->Attributes
= &rcFCB
->entry
.FatX
.Attrib
;
128 rcFCB
->Attributes
= &rcFCB
->entry
.Fat
.Attrib
;
129 rcFCB
->Hash
.Hash
= vfatNameHash(0, &rcFCB
->PathNameU
);
130 rcFCB
->Hash
.self
= rcFCB
;
131 rcFCB
->ShortHash
.self
= rcFCB
;
132 ExInitializeResourceLite(&rcFCB
->PagingIoResource
);
133 ExInitializeResourceLite(&rcFCB
->MainResource
);
134 FsRtlInitializeFileLock(&rcFCB
->FileLock
, NULL
, NULL
);
135 ExInitializeFastMutex(&rcFCB
->LastMutex
);
136 rcFCB
->RFCB
.PagingIoResource
= &rcFCB
->PagingIoResource
;
137 rcFCB
->RFCB
.Resource
= &rcFCB
->MainResource
;
138 rcFCB
->RFCB
.IsFastIoPossible
= FastIoIsNotPossible
;
144 vfatDestroyCCB(PVFATCCB pCcb
)
146 if (pCcb
->SearchPattern
.Buffer
)
148 ExFreePool(pCcb
->SearchPattern
.Buffer
);
150 ExFreeToNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
, pCcb
);
154 vfatDestroyFCB(PVFATFCB pFCB
)
156 FsRtlUninitializeFileLock(&pFCB
->FileLock
);
157 ExFreePool(pFCB
->PathNameBuffer
);
158 ExDeleteResourceLite(&pFCB
->PagingIoResource
);
159 ExDeleteResourceLite(&pFCB
->MainResource
);
160 ExFreeToNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
, pFCB
);
164 vfatFCBIsDirectory(PVFATFCB FCB
)
166 return *FCB
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
;
170 vfatFCBIsRoot(PVFATFCB FCB
)
172 return FCB
->PathNameU
.Length
== sizeof(WCHAR
) && FCB
->PathNameU
.Buffer
[0] == L
'\\' ? TRUE
: FALSE
;
176 vfatReleaseFCB(PDEVICE_EXTENSION pVCB
, PVFATFCB pFCB
)
183 DPRINT ("releasing FCB at %x: %wZ, refCount:%d\n",
190 Index
= pFCB
->Hash
.Hash
% pVCB
->HashTableSize
;
191 ShortIndex
= pFCB
->ShortHash
.Hash
% pVCB
->HashTableSize
;
193 if (pFCB
->RefCount
== 0)
195 tmpFcb
= pFCB
->parentFcb
;
196 RemoveEntryList (&pFCB
->FcbListEntry
);
197 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
199 entry
= pVCB
->FcbHashTable
[ShortIndex
];
200 if (entry
->self
== pFCB
)
202 pVCB
->FcbHashTable
[ShortIndex
] = entry
->next
;
206 while (entry
->next
->self
!= pFCB
)
210 entry
->next
= pFCB
->ShortHash
.next
;
213 entry
= pVCB
->FcbHashTable
[Index
];
214 if (entry
->self
== pFCB
)
216 pVCB
->FcbHashTable
[Index
] = entry
->next
;
220 while (entry
->next
->self
!= pFCB
)
224 entry
->next
= pFCB
->Hash
.next
;
226 vfatDestroyFCB (pFCB
);
237 vfatAddFCBToTable(PDEVICE_EXTENSION pVCB
, PVFATFCB pFCB
)
242 Index
= pFCB
->Hash
.Hash
% pVCB
->HashTableSize
;
243 ShortIndex
= pFCB
->ShortHash
.Hash
% pVCB
->HashTableSize
;
245 InsertTailList (&pVCB
->FcbListHead
, &pFCB
->FcbListEntry
);
247 pFCB
->Hash
.next
= pVCB
->FcbHashTable
[Index
];
248 pVCB
->FcbHashTable
[Index
] = &pFCB
->Hash
;
249 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
251 pFCB
->ShortHash
.next
= pVCB
->FcbHashTable
[ShortIndex
];
252 pVCB
->FcbHashTable
[ShortIndex
] = &pFCB
->ShortHash
;
256 pFCB
->parentFcb
->RefCount
++;
261 vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB
, PUNICODE_STRING PathNameU
)
265 UNICODE_STRING DirNameU
;
266 UNICODE_STRING FileNameU
;
267 PUNICODE_STRING FcbNameU
;
271 DPRINT("'%wZ'\n", PathNameU
);
273 Hash
= vfatNameHash(0, PathNameU
);
275 entry
= pVCB
->FcbHashTable
[Hash
% pVCB
->HashTableSize
];
278 vfatSplitPathName(PathNameU
, &DirNameU
, &FileNameU
);
283 if (entry
->Hash
== Hash
)
286 DPRINT("'%wZ' '%wZ'\n", &DirNameU
, &rcFCB
->DirNameU
);
287 if (RtlEqualUnicodeString(&DirNameU
, &rcFCB
->DirNameU
, TRUE
))
289 if (rcFCB
->Hash
.Hash
== Hash
)
291 FcbNameU
= &rcFCB
->LongNameU
;
295 FcbNameU
= &rcFCB
->ShortNameU
;
297 /* compare the file name */
298 DPRINT("'%wZ' '%wZ'\n", &FileNameU
, FcbNameU
);
299 if (RtlEqualUnicodeString(&FileNameU
, FcbNameU
, TRUE
))
314 vfatFCBInitializeCacheFromVolume (PVCB vcb
, PVFATFCB fcb
)
316 #ifdef USE_ROS_CC_AND_FS
318 ULONG fileCacheQuantum
;
320 PFILE_OBJECT fileObject
;
323 fileObject
= IoCreateStreamFileObject (NULL
, vcb
->StorageDevice
);
325 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
328 return STATUS_INSUFFICIENT_RESOURCES
;
330 RtlZeroMemory(newCCB
, sizeof (VFATCCB
));
332 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
333 fileObject
->FsContext
= fcb
;
334 fileObject
->FsContext2
= newCCB
;
335 fcb
->FileObject
= fileObject
;
338 #ifdef USE_ROS_CC_AND_FS
339 fileCacheQuantum
= (vcb
->FatInfo
.BytesPerCluster
>= PAGE_SIZE
) ?
340 vcb
->FatInfo
.BytesPerCluster
: PAGE_SIZE
;
342 status
= CcRosInitializeFileCache (fileObject
,
344 if (!NT_SUCCESS (status
))
346 DbgPrint ("CcRosInitializeFileCache failed\n");
350 /* FIXME: Guard by SEH. */
351 CcInitializeCacheMap(fileObject
,
352 (PCC_FILE_SIZES
)(&fcb
->RFCB
.AllocationSize
),
354 &VfatGlobalData
->CacheMgrCallbacks
,
358 fcb
->Flags
|= FCB_CACHE_INITIALIZED
;
359 return STATUS_SUCCESS
;
363 vfatMakeRootFCB(PDEVICE_EXTENSION pVCB
)
366 ULONG FirstCluster
, CurrentCluster
, Size
= 0;
367 NTSTATUS Status
= STATUS_SUCCESS
;
368 UNICODE_STRING NameU
= RTL_CONSTANT_STRING(L
"\\");
370 FCB
= vfatNewFCB(pVCB
, &NameU
);
371 if (FCB
->Flags
& FCB_IS_FATX_ENTRY
)
373 memset(FCB
->entry
.FatX
.Filename
, ' ', 42);
374 FCB
->entry
.FatX
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
375 FCB
->entry
.FatX
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
376 FCB
->entry
.FatX
.FirstCluster
= 1;
377 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
381 memset(FCB
->entry
.Fat
.ShortName
, ' ', 11);
382 FCB
->entry
.Fat
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
383 FCB
->entry
.Fat
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
384 if (pVCB
->FatInfo
.FatType
== FAT32
)
386 CurrentCluster
= FirstCluster
= pVCB
->FatInfo
.RootCluster
;
387 FCB
->entry
.Fat
.FirstCluster
= (unsigned short)(FirstCluster
& 0xffff);
388 FCB
->entry
.Fat
.FirstClusterHigh
= (unsigned short)(FirstCluster
>> 16);
390 while (CurrentCluster
!= 0xffffffff && NT_SUCCESS(Status
))
392 Size
+= pVCB
->FatInfo
.BytesPerCluster
;
393 Status
= NextCluster (pVCB
, FirstCluster
, &CurrentCluster
, FALSE
);
398 FCB
->entry
.Fat
.FirstCluster
= 1;
399 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
402 FCB
->ShortHash
.Hash
= FCB
->Hash
.Hash
;
405 FCB
->RFCB
.FileSize
.QuadPart
= Size
;
406 FCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
407 FCB
->RFCB
.AllocationSize
.QuadPart
= Size
;
408 FCB
->RFCB
.IsFastIoPossible
= FastIoIsNotPossible
;
410 vfatFCBInitializeCacheFromVolume(pVCB
, FCB
);
411 vfatAddFCBToTable(pVCB
, FCB
);
417 vfatOpenRootFCB(PDEVICE_EXTENSION pVCB
)
420 UNICODE_STRING NameU
= RTL_CONSTANT_STRING(L
"\\");
422 FCB
= vfatGrabFCBFromTable (pVCB
, &NameU
);
425 FCB
= vfatMakeRootFCB (pVCB
);
432 vfatMakeFCBFromDirEntry(PVCB vcb
,
433 PVFATFCB directoryFCB
,
434 PVFAT_DIRENTRY_CONTEXT DirContext
,
438 PWCHAR PathNameBuffer
;
439 USHORT PathNameLength
;
443 UNICODE_STRING NameU
;
445 PathNameLength
= directoryFCB
->PathNameU
.Length
+ max(DirContext
->LongNameU
.Length
, DirContext
->ShortNameU
.Length
);
446 if (!vfatFCBIsRoot (directoryFCB
))
448 PathNameLength
+= sizeof(WCHAR
);
451 if (PathNameLength
> LONGNAME_MAX_LENGTH
* sizeof(WCHAR
))
453 return STATUS_OBJECT_NAME_INVALID
;
455 PathNameBuffer
= ExAllocatePool(NonPagedPool
, PathNameLength
+ sizeof(WCHAR
));
458 return STATUS_INSUFFICIENT_RESOURCES
;
460 NameU
.Buffer
= PathNameBuffer
;
462 NameU
.MaximumLength
= PathNameLength
;
464 RtlCopyUnicodeString(&NameU
, &directoryFCB
->PathNameU
);
465 if (!vfatFCBIsRoot (directoryFCB
))
467 RtlAppendUnicodeToString(&NameU
, L
"\\");
469 hash
= vfatNameHash(0, &NameU
);
470 if (DirContext
->LongNameU
.Length
> 0)
472 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->LongNameU
);
476 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->ShortNameU
);
478 NameU
.Buffer
[NameU
.Length
/ sizeof(WCHAR
)] = 0;
480 rcFCB
= vfatNewFCB (vcb
, &NameU
);
481 RtlCopyMemory (&rcFCB
->entry
, &DirContext
->DirEntry
, sizeof (DIR_ENTRY
));
482 RtlCopyUnicodeString(&rcFCB
->ShortNameU
, &DirContext
->ShortNameU
);
483 if (vcb
->Flags
& VCB_IS_FATX
)
485 rcFCB
->ShortHash
.Hash
= rcFCB
->Hash
.Hash
;
489 rcFCB
->ShortHash
.Hash
= vfatNameHash(hash
, &rcFCB
->ShortNameU
);
492 if (vfatFCBIsDirectory(rcFCB
))
494 ULONG FirstCluster
, CurrentCluster
;
497 FirstCluster
= vfatDirEntryGetFirstCluster (vcb
, &rcFCB
->entry
);
498 if (FirstCluster
== 1)
500 Size
= vcb
->FatInfo
.rootDirectorySectors
* vcb
->FatInfo
.BytesPerSector
;
502 else if (FirstCluster
!= 0)
504 CurrentCluster
= FirstCluster
;
505 while (CurrentCluster
!= 0xffffffff)
507 Size
+= vcb
->FatInfo
.BytesPerCluster
;
508 Status
= NextCluster (vcb
, FirstCluster
, &CurrentCluster
, FALSE
);
512 else if (rcFCB
->Flags
& FCB_IS_FATX_ENTRY
)
514 Size
= rcFCB
->entry
.FatX
.FileSize
;
518 Size
= rcFCB
->entry
.Fat
.FileSize
;
520 rcFCB
->dirIndex
= DirContext
->DirIndex
;
521 rcFCB
->startIndex
= DirContext
->StartIndex
;
522 if ((rcFCB
->Flags
& FCB_IS_FATX_ENTRY
) && !vfatFCBIsRoot (directoryFCB
))
524 ASSERT(DirContext
->DirIndex
>= 2 && DirContext
->StartIndex
>= 2);
525 rcFCB
->dirIndex
= DirContext
->DirIndex
-2;
526 rcFCB
->startIndex
= DirContext
->StartIndex
-2;
528 rcFCB
->RFCB
.FileSize
.QuadPart
= Size
;
529 rcFCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
530 rcFCB
->RFCB
.AllocationSize
.QuadPart
= ROUND_UP(Size
, vcb
->FatInfo
.BytesPerCluster
);
532 if (vfatFCBIsDirectory(rcFCB
))
534 vfatFCBInitializeCacheFromVolume(vcb
, rcFCB
);
536 rcFCB
->parentFcb
= directoryFCB
;
537 vfatAddFCBToTable (vcb
, rcFCB
);
540 ExFreePool(PathNameBuffer
);
541 return STATUS_SUCCESS
;
545 vfatAttachFCBToFileObject (PDEVICE_EXTENSION vcb
,
547 PFILE_OBJECT fileObject
)
551 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
555 return STATUS_INSUFFICIENT_RESOURCES
;
557 RtlZeroMemory (newCCB
, sizeof (VFATCCB
));
559 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
560 fileObject
->FsContext
= fcb
;
561 fileObject
->FsContext2
= newCCB
;
562 DPRINT ("file open: fcb:%x PathName:%wZ\n", fcb
, &fcb
->PathNameU
);
564 return STATUS_SUCCESS
;
568 vfatDirFindFile (PDEVICE_EXTENSION pDeviceExt
,
569 PVFATFCB pDirectoryFCB
,
570 PUNICODE_STRING FileToFindU
,
571 PVFATFCB
* pFoundFCB
)
574 PVOID Context
= NULL
;
576 BOOLEAN First
= TRUE
;
577 VFAT_DIRENTRY_CONTEXT DirContext
;
578 /* This buffer must have a size of 260 characters, because
579 vfatMakeFCBFromDirEntry can copy 20 name entries with 13 characters. */
580 WCHAR LongNameBuffer
[260];
581 WCHAR ShortNameBuffer
[13];
582 BOOLEAN FoundLong
= FALSE
;
583 BOOLEAN FoundShort
= FALSE
;
586 ASSERT(pDirectoryFCB
);
589 DPRINT ("vfatDirFindFile(VCB:%08x, dirFCB:%08x, File:%wZ)\n",
593 DPRINT ("Dir Path:%wZ\n", &pDirectoryFCB
->PathNameU
);
595 DirContext
.DirIndex
= 0;
596 DirContext
.LongNameU
.Buffer
= LongNameBuffer
;
597 DirContext
.LongNameU
.Length
= 0;
598 DirContext
.LongNameU
.MaximumLength
= sizeof(LongNameBuffer
);
599 DirContext
.ShortNameU
.Buffer
= ShortNameBuffer
;
600 DirContext
.ShortNameU
.Length
= 0;
601 DirContext
.ShortNameU
.MaximumLength
= sizeof(ShortNameBuffer
);
605 status
= pDeviceExt
->GetNextDirEntry(&Context
,
611 if (status
== STATUS_NO_MORE_ENTRIES
)
613 return STATUS_OBJECT_NAME_NOT_FOUND
;
615 if (!NT_SUCCESS(status
))
620 DPRINT (" Index:%d longName:%wZ\n",
622 &DirContext
.LongNameU
);
623 DirContext
.LongNameU
.Buffer
[DirContext
.LongNameU
.Length
/ sizeof(WCHAR
)] = 0;
624 DirContext
.ShortNameU
.Buffer
[DirContext
.ShortNameU
.Length
/ sizeof(WCHAR
)] = 0;
625 if (!ENTRY_VOLUME(pDeviceExt
, &DirContext
.DirEntry
))
627 FoundLong
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.LongNameU
, TRUE
);
628 if (FoundLong
== FALSE
)
630 FoundShort
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.ShortNameU
, TRUE
);
632 if (FoundLong
|| FoundShort
)
634 status
= vfatMakeFCBFromDirEntry (pDeviceExt
,
638 CcUnpinData(Context
);
642 DirContext
.DirIndex
++;
645 return STATUS_OBJECT_NAME_NOT_FOUND
;
649 vfatGetFCBForFile (PDEVICE_EXTENSION pVCB
,
650 PVFATFCB
*pParentFCB
,
652 PUNICODE_STRING pFileNameU
)
657 UNICODE_STRING NameU
;
658 UNICODE_STRING RootNameU
= RTL_CONSTANT_STRING(L
"\\");
659 PWCHAR curr
, prev
, last
;
662 DPRINT ("vfatGetFCBForFile (%x,%x,%x,%wZ)\n",
668 parentFCB
= *pParentFCB
;
670 if (parentFCB
== NULL
)
672 // Trivial case, open of the root directory on volume
673 if (RtlEqualUnicodeString(pFileNameU
, &RootNameU
, FALSE
))
675 DPRINT ("returning root FCB\n");
677 FCB
= vfatOpenRootFCB (pVCB
);
681 return (FCB
!= NULL
) ? STATUS_SUCCESS
: STATUS_OBJECT_PATH_NOT_FOUND
;
684 /* Check for an existing FCB */
685 FCB
= vfatGrabFCBFromTable (pVCB
, pFileNameU
);
689 *pParentFCB
= FCB
->parentFcb
;
690 (*pParentFCB
)->RefCount
++;
691 return STATUS_SUCCESS
;
694 last
= curr
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
695 while (*curr
!= L
'\\' && curr
> pFileNameU
->Buffer
)
700 if (curr
> pFileNameU
->Buffer
)
702 NameU
.Buffer
= pFileNameU
->Buffer
;
703 NameU
.MaximumLength
= NameU
.Length
= (curr
- pFileNameU
->Buffer
) * sizeof(WCHAR
);
704 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
707 Length
= (curr
- pFileNameU
->Buffer
) * sizeof(WCHAR
);
708 if (Length
!= FCB
->PathNameU
.Length
)
710 if (pFileNameU
->Length
+ FCB
->PathNameU
.Length
- Length
> pFileNameU
->MaximumLength
)
712 vfatReleaseFCB (pVCB
, FCB
);
713 return STATUS_OBJECT_NAME_INVALID
;
715 RtlMoveMemory(pFileNameU
->Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
),
716 curr
, pFileNameU
->Length
- Length
);
717 pFileNameU
->Length
+= (USHORT
)(FCB
->PathNameU
.Length
- Length
);
718 curr
= pFileNameU
->Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
);
719 last
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
721 RtlCopyMemory(pFileNameU
->Buffer
, FCB
->PathNameU
.Buffer
, FCB
->PathNameU
.Length
);
731 FCB
= vfatOpenRootFCB(pVCB
);
732 curr
= pFileNameU
->Buffer
;
742 prev
= curr
= pFileNameU
->Buffer
- 1;
743 last
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
750 vfatReleaseFCB (pVCB
, parentFCB
);
753 // fail if element in FCB is not a directory
754 if (!vfatFCBIsDirectory (FCB
))
756 DPRINT ("Element in requested path is not a directory\n");
758 vfatReleaseFCB (pVCB
, FCB
);
763 return STATUS_OBJECT_PATH_NOT_FOUND
;
768 Length
= (curr
- prev
) * sizeof(WCHAR
);
769 if (Length
!= parentFCB
->LongNameU
.Length
)
771 if (pFileNameU
->Length
+ parentFCB
->LongNameU
.Length
- Length
> pFileNameU
->MaximumLength
)
773 vfatReleaseFCB (pVCB
, parentFCB
);
774 return STATUS_OBJECT_NAME_INVALID
;
776 RtlMoveMemory(prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
), curr
,
777 pFileNameU
->Length
- (curr
- pFileNameU
->Buffer
) * sizeof(WCHAR
));
778 pFileNameU
->Length
+= (USHORT
)(parentFCB
->LongNameU
.Length
- Length
);
779 curr
= prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
);
780 last
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
782 RtlCopyMemory(prev
, parentFCB
->LongNameU
.Buffer
, parentFCB
->LongNameU
.Length
);
786 while (*curr
!= L
'\\' && curr
<= last
)
790 NameU
.Buffer
= pFileNameU
->Buffer
;
791 NameU
.Length
= (curr
- NameU
.Buffer
) * sizeof(WCHAR
);
792 NameU
.MaximumLength
= pFileNameU
->MaximumLength
;
793 DPRINT("%wZ\n", &NameU
);
794 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
798 NameU
.MaximumLength
= NameU
.Length
= (curr
- prev
) * sizeof(WCHAR
);
799 status
= vfatDirFindFile(pVCB
, parentFCB
, &NameU
, &FCB
);
800 if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
805 *pParentFCB
= parentFCB
;
806 return STATUS_OBJECT_NAME_NOT_FOUND
;
810 vfatReleaseFCB (pVCB
, parentFCB
);
812 return STATUS_OBJECT_PATH_NOT_FOUND
;
815 else if (!NT_SUCCESS (status
))
817 vfatReleaseFCB (pVCB
, parentFCB
);
826 *pParentFCB
= parentFCB
;
829 return STATUS_SUCCESS
;