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 */
26 static ULONG
vfatNameHash(ULONG hash
, PUNICODE_STRING NameU
)
32 // LFN could start from "."
33 //ASSERT(NameU->Buffer[0] != L'.');
35 last
= NameU
->Buffer
+ NameU
->Length
/ sizeof(WCHAR
);
39 c
= towlower(*curr
++);
40 hash
= (hash
+ (c
<< 4) + (c
>> 4)) * 11;
46 vfatSplitPathName(PUNICODE_STRING PathNameU
, PUNICODE_STRING DirNameU
, PUNICODE_STRING FileNameU
)
50 pName
= PathNameU
->Buffer
+ PathNameU
->Length
/ sizeof(WCHAR
) - 1;
51 while (*pName
!= L
'\\' && pName
>= PathNameU
->Buffer
)
56 ASSERT(*pName
== L
'\\' || pName
< PathNameU
->Buffer
);
59 FileNameU
->Buffer
= pName
+ 1;
60 FileNameU
->Length
= FileNameU
->MaximumLength
= Length
* sizeof(WCHAR
);
64 DirNameU
->Buffer
= PathNameU
->Buffer
;
65 DirNameU
->Length
= (pName
+ 1 - PathNameU
->Buffer
) * sizeof(WCHAR
);
66 DirNameU
->MaximumLength
= DirNameU
->Length
;
71 vfatInitFcb(PVFATFCB Fcb
, PUNICODE_STRING NameU
)
73 USHORT PathNameBufferLength
;
76 PathNameBufferLength
= NameU
->Length
+ sizeof(WCHAR
);
78 PathNameBufferLength
= 0;
80 Fcb
->PathNameBuffer
= ExAllocatePoolWithTag(NonPagedPool
, PathNameBufferLength
, TAG_FCB
);
81 if (!Fcb
->PathNameBuffer
)
83 /* FIXME: what to do if no more memory? */
84 DPRINT1("Unable to initialize FCB for filename '%wZ'\n", NameU
);
85 KeBugCheckEx(FAT_FILE_SYSTEM
, (ULONG_PTR
)Fcb
, (ULONG_PTR
)NameU
, 0, 0);
88 Fcb
->PathNameU
.Length
= 0;
89 Fcb
->PathNameU
.Buffer
= Fcb
->PathNameBuffer
;
90 Fcb
->PathNameU
.MaximumLength
= PathNameBufferLength
;
91 Fcb
->ShortNameU
.Length
= 0;
92 Fcb
->ShortNameU
.Buffer
= Fcb
->ShortNameBuffer
;
93 Fcb
->ShortNameU
.MaximumLength
= sizeof(Fcb
->ShortNameBuffer
);
94 Fcb
->DirNameU
.Buffer
= Fcb
->PathNameU
.Buffer
;
95 if (NameU
&& NameU
->Length
)
97 RtlCopyUnicodeString(&Fcb
->PathNameU
, NameU
);
98 vfatSplitPathName(&Fcb
->PathNameU
, &Fcb
->DirNameU
, &Fcb
->LongNameU
);
102 Fcb
->DirNameU
.Buffer
= Fcb
->LongNameU
.Buffer
= NULL
;
103 Fcb
->DirNameU
.MaximumLength
= Fcb
->DirNameU
.Length
= 0;
104 Fcb
->LongNameU
.MaximumLength
= Fcb
->LongNameU
.Length
= 0;
106 RtlZeroMemory(&Fcb
->FCBShareAccess
, sizeof(SHARE_ACCESS
));
107 Fcb
->OpenHandleCount
= 0;
111 vfatNewFCB(PDEVICE_EXTENSION pVCB
, PUNICODE_STRING pFileNameU
)
115 DPRINT("'%wZ'\n", pFileNameU
);
117 rcFCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
);
122 RtlZeroMemory(rcFCB
, sizeof(VFATFCB
));
123 vfatInitFcb(rcFCB
, pFileNameU
);
124 if (pVCB
->Flags
& VCB_IS_FATX
)
126 rcFCB
->Flags
|= FCB_IS_FATX_ENTRY
;
127 rcFCB
->Attributes
= &rcFCB
->entry
.FatX
.Attrib
;
130 rcFCB
->Attributes
= &rcFCB
->entry
.Fat
.Attrib
;
131 rcFCB
->Hash
.Hash
= vfatNameHash(0, &rcFCB
->PathNameU
);
132 rcFCB
->Hash
.self
= rcFCB
;
133 rcFCB
->ShortHash
.self
= rcFCB
;
134 ExInitializeResourceLite(&rcFCB
->PagingIoResource
);
135 ExInitializeResourceLite(&rcFCB
->MainResource
);
136 FsRtlInitializeFileLock(&rcFCB
->FileLock
, NULL
, NULL
);
137 ExInitializeFastMutex(&rcFCB
->LastMutex
);
138 rcFCB
->RFCB
.PagingIoResource
= &rcFCB
->PagingIoResource
;
139 rcFCB
->RFCB
.Resource
= &rcFCB
->MainResource
;
140 rcFCB
->RFCB
.IsFastIoPossible
= FastIoIsNotPossible
;
146 vfatDestroyCCB(PVFATCCB pCcb
)
148 if (pCcb
->SearchPattern
.Buffer
)
150 ExFreePoolWithTag(pCcb
->SearchPattern
.Buffer
, TAG_VFAT
);
152 ExFreeToNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
, pCcb
);
156 vfatDestroyFCB(PVFATFCB pFCB
)
158 FsRtlUninitializeFileLock(&pFCB
->FileLock
);
159 ExFreePool(pFCB
->PathNameBuffer
);
160 ExDeleteResourceLite(&pFCB
->PagingIoResource
);
161 ExDeleteResourceLite(&pFCB
->MainResource
);
162 ExFreeToNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
, pFCB
);
166 vfatFCBIsDirectory(PVFATFCB FCB
)
168 return *FCB
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
;
172 vfatFCBIsRoot(PVFATFCB FCB
)
174 return FCB
->PathNameU
.Length
== sizeof(WCHAR
) && FCB
->PathNameU
.Buffer
[0] == L
'\\' ? TRUE
: FALSE
;
178 vfatReleaseFCB(PDEVICE_EXTENSION pVCB
, PVFATFCB pFCB
)
185 DPRINT ("releasing FCB at %p: %wZ, refCount:%d\n",
192 Index
= pFCB
->Hash
.Hash
% pVCB
->HashTableSize
;
193 ShortIndex
= pFCB
->ShortHash
.Hash
% pVCB
->HashTableSize
;
195 if (pFCB
->RefCount
== 0)
197 tmpFcb
= pFCB
->parentFcb
;
198 RemoveEntryList (&pFCB
->FcbListEntry
);
199 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
201 entry
= pVCB
->FcbHashTable
[ShortIndex
];
202 if (entry
->self
== pFCB
)
204 pVCB
->FcbHashTable
[ShortIndex
] = entry
->next
;
208 while (entry
->next
->self
!= pFCB
)
212 entry
->next
= pFCB
->ShortHash
.next
;
215 entry
= pVCB
->FcbHashTable
[Index
];
216 if (entry
->self
== pFCB
)
218 pVCB
->FcbHashTable
[Index
] = entry
->next
;
222 while (entry
->next
->self
!= pFCB
)
226 entry
->next
= pFCB
->Hash
.next
;
228 vfatDestroyFCB (pFCB
);
239 vfatAddFCBToTable(PDEVICE_EXTENSION pVCB
, PVFATFCB pFCB
)
244 Index
= pFCB
->Hash
.Hash
% pVCB
->HashTableSize
;
245 ShortIndex
= pFCB
->ShortHash
.Hash
% pVCB
->HashTableSize
;
247 InsertTailList (&pVCB
->FcbListHead
, &pFCB
->FcbListEntry
);
249 pFCB
->Hash
.next
= pVCB
->FcbHashTable
[Index
];
250 pVCB
->FcbHashTable
[Index
] = &pFCB
->Hash
;
251 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
253 pFCB
->ShortHash
.next
= pVCB
->FcbHashTable
[ShortIndex
];
254 pVCB
->FcbHashTable
[ShortIndex
] = &pFCB
->ShortHash
;
258 pFCB
->parentFcb
->RefCount
++;
263 vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB
, PUNICODE_STRING PathNameU
)
267 UNICODE_STRING DirNameU
;
268 UNICODE_STRING FileNameU
;
269 PUNICODE_STRING FcbNameU
;
273 DPRINT("'%wZ'\n", PathNameU
);
275 Hash
= vfatNameHash(0, PathNameU
);
277 entry
= pVCB
->FcbHashTable
[Hash
% pVCB
->HashTableSize
];
280 vfatSplitPathName(PathNameU
, &DirNameU
, &FileNameU
);
285 if (entry
->Hash
== Hash
)
288 DPRINT("'%wZ' '%wZ'\n", &DirNameU
, &rcFCB
->DirNameU
);
289 if (RtlEqualUnicodeString(&DirNameU
, &rcFCB
->DirNameU
, TRUE
))
291 if (rcFCB
->Hash
.Hash
== Hash
)
293 FcbNameU
= &rcFCB
->LongNameU
;
297 FcbNameU
= &rcFCB
->ShortNameU
;
299 /* compare the file name */
300 DPRINT("'%wZ' '%wZ'\n", &FileNameU
, FcbNameU
);
301 if (RtlEqualUnicodeString(&FileNameU
, FcbNameU
, TRUE
))
314 vfatFCBInitializeCacheFromVolume (PVCB vcb
, PVFATFCB fcb
)
316 PFILE_OBJECT fileObject
;
319 fileObject
= IoCreateStreamFileObject (NULL
, vcb
->StorageDevice
);
321 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
324 return STATUS_INSUFFICIENT_RESOURCES
;
326 RtlZeroMemory(newCCB
, sizeof (VFATCCB
));
328 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
329 fileObject
->FsContext
= fcb
;
330 fileObject
->FsContext2
= newCCB
;
331 fcb
->FileObject
= fileObject
;
334 CcInitializeCacheMap(fileObject
,
335 (PCC_FILE_SIZES
)(&fcb
->RFCB
.AllocationSize
),
337 &VfatGlobalData
->CacheMgrCallbacks
,
340 fcb
->Flags
|= FCB_CACHE_INITIALIZED
;
341 return STATUS_SUCCESS
;
345 vfatMakeRootFCB(PDEVICE_EXTENSION pVCB
)
348 ULONG FirstCluster
, CurrentCluster
, Size
= 0;
349 NTSTATUS Status
= STATUS_SUCCESS
;
350 UNICODE_STRING NameU
= RTL_CONSTANT_STRING(L
"\\");
352 FCB
= vfatNewFCB(pVCB
, &NameU
);
353 if (FCB
->Flags
& FCB_IS_FATX_ENTRY
)
355 memset(FCB
->entry
.FatX
.Filename
, ' ', 42);
356 FCB
->entry
.FatX
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
357 FCB
->entry
.FatX
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
358 FCB
->entry
.FatX
.FirstCluster
= 1;
359 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
363 memset(FCB
->entry
.Fat
.ShortName
, ' ', 11);
364 FCB
->entry
.Fat
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
365 FCB
->entry
.Fat
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
366 if (pVCB
->FatInfo
.FatType
== FAT32
)
368 CurrentCluster
= FirstCluster
= pVCB
->FatInfo
.RootCluster
;
369 FCB
->entry
.Fat
.FirstCluster
= (unsigned short)(FirstCluster
& 0xffff);
370 FCB
->entry
.Fat
.FirstClusterHigh
= (unsigned short)(FirstCluster
>> 16);
372 while (CurrentCluster
!= 0xffffffff && NT_SUCCESS(Status
))
374 Size
+= pVCB
->FatInfo
.BytesPerCluster
;
375 Status
= NextCluster (pVCB
, FirstCluster
, &CurrentCluster
, FALSE
);
380 FCB
->entry
.Fat
.FirstCluster
= 1;
381 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
384 FCB
->ShortHash
.Hash
= FCB
->Hash
.Hash
;
387 FCB
->RFCB
.FileSize
.QuadPart
= Size
;
388 FCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
389 FCB
->RFCB
.AllocationSize
.QuadPart
= Size
;
390 FCB
->RFCB
.IsFastIoPossible
= FastIoIsNotPossible
;
392 vfatFCBInitializeCacheFromVolume(pVCB
, FCB
);
393 vfatAddFCBToTable(pVCB
, FCB
);
399 vfatOpenRootFCB(PDEVICE_EXTENSION pVCB
)
402 UNICODE_STRING NameU
= RTL_CONSTANT_STRING(L
"\\");
404 FCB
= vfatGrabFCBFromTable (pVCB
, &NameU
);
407 FCB
= vfatMakeRootFCB (pVCB
);
414 vfatMakeFCBFromDirEntry(
416 PVFATFCB directoryFCB
,
417 PVFAT_DIRENTRY_CONTEXT DirContext
,
421 PWCHAR PathNameBuffer
;
422 USHORT PathNameLength
;
426 UNICODE_STRING NameU
;
428 PathNameLength
= directoryFCB
->PathNameU
.Length
+ max(DirContext
->LongNameU
.Length
, DirContext
->ShortNameU
.Length
);
429 if (!vfatFCBIsRoot (directoryFCB
))
431 PathNameLength
+= sizeof(WCHAR
);
434 if (PathNameLength
> LONGNAME_MAX_LENGTH
* sizeof(WCHAR
))
436 return STATUS_OBJECT_NAME_INVALID
;
438 PathNameBuffer
= ExAllocatePoolWithTag(NonPagedPool
, PathNameLength
+ sizeof(WCHAR
), TAG_FCB
);
441 return STATUS_INSUFFICIENT_RESOURCES
;
443 NameU
.Buffer
= PathNameBuffer
;
445 NameU
.MaximumLength
= PathNameLength
;
447 RtlCopyUnicodeString(&NameU
, &directoryFCB
->PathNameU
);
448 if (!vfatFCBIsRoot (directoryFCB
))
450 RtlAppendUnicodeToString(&NameU
, L
"\\");
452 hash
= vfatNameHash(0, &NameU
);
453 if (DirContext
->LongNameU
.Length
> 0)
455 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->LongNameU
);
459 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->ShortNameU
);
461 NameU
.Buffer
[NameU
.Length
/ sizeof(WCHAR
)] = 0;
463 rcFCB
= vfatNewFCB (vcb
, &NameU
);
464 RtlCopyMemory (&rcFCB
->entry
, &DirContext
->DirEntry
, sizeof (DIR_ENTRY
));
465 RtlCopyUnicodeString(&rcFCB
->ShortNameU
, &DirContext
->ShortNameU
);
466 if (vcb
->Flags
& VCB_IS_FATX
)
468 rcFCB
->ShortHash
.Hash
= rcFCB
->Hash
.Hash
;
472 rcFCB
->ShortHash
.Hash
= vfatNameHash(hash
, &rcFCB
->ShortNameU
);
475 if (vfatFCBIsDirectory(rcFCB
))
477 ULONG FirstCluster
, CurrentCluster
;
478 NTSTATUS Status
= STATUS_SUCCESS
;
480 FirstCluster
= vfatDirEntryGetFirstCluster (vcb
, &rcFCB
->entry
);
481 if (FirstCluster
== 1)
483 Size
= vcb
->FatInfo
.rootDirectorySectors
* vcb
->FatInfo
.BytesPerSector
;
485 else if (FirstCluster
!= 0)
487 CurrentCluster
= FirstCluster
;
488 while (CurrentCluster
!= 0xffffffff && NT_SUCCESS(Status
))
490 Size
+= vcb
->FatInfo
.BytesPerCluster
;
491 Status
= NextCluster (vcb
, FirstCluster
, &CurrentCluster
, FALSE
);
495 else if (rcFCB
->Flags
& FCB_IS_FATX_ENTRY
)
497 Size
= rcFCB
->entry
.FatX
.FileSize
;
501 Size
= rcFCB
->entry
.Fat
.FileSize
;
503 rcFCB
->dirIndex
= DirContext
->DirIndex
;
504 rcFCB
->startIndex
= DirContext
->StartIndex
;
505 if ((rcFCB
->Flags
& FCB_IS_FATX_ENTRY
) && !vfatFCBIsRoot (directoryFCB
))
507 ASSERT(DirContext
->DirIndex
>= 2 && DirContext
->StartIndex
>= 2);
508 rcFCB
->dirIndex
= DirContext
->DirIndex
-2;
509 rcFCB
->startIndex
= DirContext
->StartIndex
-2;
511 rcFCB
->RFCB
.FileSize
.QuadPart
= Size
;
512 rcFCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
513 rcFCB
->RFCB
.AllocationSize
.QuadPart
= ROUND_UP(Size
, vcb
->FatInfo
.BytesPerCluster
);
515 if (vfatFCBIsDirectory(rcFCB
))
517 vfatFCBInitializeCacheFromVolume(vcb
, rcFCB
);
519 rcFCB
->parentFcb
= directoryFCB
;
520 vfatAddFCBToTable (vcb
, rcFCB
);
523 ExFreePool(PathNameBuffer
);
524 return STATUS_SUCCESS
;
528 vfatAttachFCBToFileObject (
529 PDEVICE_EXTENSION vcb
,
531 PFILE_OBJECT fileObject
)
535 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
538 return STATUS_INSUFFICIENT_RESOURCES
;
540 RtlZeroMemory (newCCB
, sizeof (VFATCCB
));
542 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
543 fileObject
->FsContext
= fcb
;
544 fileObject
->FsContext2
= newCCB
;
545 DPRINT ("file open: fcb:%p PathName:%wZ\n", fcb
, &fcb
->PathNameU
);
547 return STATUS_SUCCESS
;
552 PDEVICE_EXTENSION pDeviceExt
,
553 PVFATFCB pDirectoryFCB
,
554 PUNICODE_STRING FileToFindU
,
555 PVFATFCB
* pFoundFCB
)
558 PVOID Context
= NULL
;
560 BOOLEAN First
= TRUE
;
561 VFAT_DIRENTRY_CONTEXT DirContext
;
562 /* This buffer must have a size of 260 characters, because
563 vfatMakeFCBFromDirEntry can copy 20 name entries with 13 characters. */
564 WCHAR LongNameBuffer
[260];
565 WCHAR ShortNameBuffer
[13];
566 BOOLEAN FoundLong
= FALSE
;
567 BOOLEAN FoundShort
= FALSE
;
570 ASSERT(pDirectoryFCB
);
573 DPRINT ("vfatDirFindFile(VCB:%p, dirFCB:%p, File:%wZ)\n",
577 DPRINT ("Dir Path:%wZ\n", &pDirectoryFCB
->PathNameU
);
579 DirContext
.DirIndex
= 0;
580 DirContext
.LongNameU
.Buffer
= LongNameBuffer
;
581 DirContext
.LongNameU
.Length
= 0;
582 DirContext
.LongNameU
.MaximumLength
= sizeof(LongNameBuffer
);
583 DirContext
.ShortNameU
.Buffer
= ShortNameBuffer
;
584 DirContext
.ShortNameU
.Length
= 0;
585 DirContext
.ShortNameU
.MaximumLength
= sizeof(ShortNameBuffer
);
589 status
= pDeviceExt
->GetNextDirEntry(&Context
,
595 if (status
== STATUS_NO_MORE_ENTRIES
)
597 return STATUS_OBJECT_NAME_NOT_FOUND
;
599 if (!NT_SUCCESS(status
))
604 DPRINT (" Index:%d longName:%wZ\n",
606 &DirContext
.LongNameU
);
608 if (!ENTRY_VOLUME(pDeviceExt
, &DirContext
.DirEntry
))
610 FoundLong
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.LongNameU
, TRUE
);
611 if (FoundLong
== FALSE
)
613 FoundShort
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.ShortNameU
, TRUE
);
615 if (FoundLong
|| FoundShort
)
617 status
= vfatMakeFCBFromDirEntry (pDeviceExt
,
621 CcUnpinData(Context
);
625 DirContext
.DirIndex
++;
628 return STATUS_OBJECT_NAME_NOT_FOUND
;
633 PDEVICE_EXTENSION pVCB
,
634 PVFATFCB
*pParentFCB
,
636 PUNICODE_STRING pFileNameU
)
641 UNICODE_STRING NameU
;
642 UNICODE_STRING RootNameU
= RTL_CONSTANT_STRING(L
"\\");
643 UNICODE_STRING FileNameU
;
644 WCHAR NameBuffer
[260];
645 PWCHAR curr
, prev
, last
;
648 DPRINT ("vfatGetFCBForFile (%p,%p,%p,%wZ)\n",
654 FileNameU
.Buffer
= NameBuffer
;
655 FileNameU
.MaximumLength
= sizeof(NameBuffer
);
656 RtlCopyUnicodeString(&FileNameU
, pFileNameU
);
658 parentFCB
= *pParentFCB
;
660 if (parentFCB
== NULL
)
662 // Trivial case, open of the root directory on volume
663 if (RtlEqualUnicodeString(&FileNameU
, &RootNameU
, FALSE
))
665 DPRINT ("returning root FCB\n");
667 FCB
= vfatOpenRootFCB (pVCB
);
671 return (FCB
!= NULL
) ? STATUS_SUCCESS
: STATUS_OBJECT_PATH_NOT_FOUND
;
674 /* Check for an existing FCB */
675 FCB
= vfatGrabFCBFromTable (pVCB
, &FileNameU
);
679 *pParentFCB
= FCB
->parentFcb
;
680 (*pParentFCB
)->RefCount
++;
681 return STATUS_SUCCESS
;
684 last
= curr
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
685 while (*curr
!= L
'\\' && curr
> FileNameU
.Buffer
)
690 if (curr
> FileNameU
.Buffer
)
692 NameU
.Buffer
= FileNameU
.Buffer
;
693 NameU
.MaximumLength
= NameU
.Length
= (curr
- FileNameU
.Buffer
) * sizeof(WCHAR
);
694 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
697 Length
= (curr
- FileNameU
.Buffer
) * sizeof(WCHAR
);
698 if (Length
!= FCB
->PathNameU
.Length
)
700 if (FileNameU
.Length
+ FCB
->PathNameU
.Length
- Length
> FileNameU
.MaximumLength
)
702 vfatReleaseFCB (pVCB
, FCB
);
703 return STATUS_OBJECT_NAME_INVALID
;
705 RtlMoveMemory(FileNameU
.Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
),
706 curr
, FileNameU
.Length
- Length
);
707 FileNameU
.Length
+= (USHORT
)(FCB
->PathNameU
.Length
- Length
);
708 curr
= FileNameU
.Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
);
709 last
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
711 RtlCopyMemory(FileNameU
.Buffer
, FCB
->PathNameU
.Buffer
, FCB
->PathNameU
.Length
);
721 FCB
= vfatOpenRootFCB(pVCB
);
722 curr
= FileNameU
.Buffer
;
732 prev
= curr
= FileNameU
.Buffer
- 1;
733 last
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
740 vfatReleaseFCB (pVCB
, parentFCB
);
743 // fail if element in FCB is not a directory
744 if (!vfatFCBIsDirectory (FCB
))
746 DPRINT ("Element in requested path is not a directory\n");
748 vfatReleaseFCB (pVCB
, FCB
);
753 return STATUS_OBJECT_PATH_NOT_FOUND
;
758 Length
= (curr
- prev
) * sizeof(WCHAR
);
759 if (Length
!= parentFCB
->LongNameU
.Length
)
761 if (FileNameU
.Length
+ parentFCB
->LongNameU
.Length
- Length
> FileNameU
.MaximumLength
)
763 vfatReleaseFCB (pVCB
, parentFCB
);
764 return STATUS_OBJECT_NAME_INVALID
;
766 RtlMoveMemory(prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
), curr
,
767 FileNameU
.Length
- (curr
- FileNameU
.Buffer
) * sizeof(WCHAR
));
768 FileNameU
.Length
+= (USHORT
)(parentFCB
->LongNameU
.Length
- Length
);
769 curr
= prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
);
770 last
= FileNameU
.Buffer
+ FileNameU
.Length
/ sizeof(WCHAR
) - 1;
772 RtlCopyMemory(prev
, parentFCB
->LongNameU
.Buffer
, parentFCB
->LongNameU
.Length
);
776 while (*curr
!= L
'\\' && curr
<= last
)
780 NameU
.Buffer
= FileNameU
.Buffer
;
781 NameU
.Length
= (curr
- NameU
.Buffer
) * sizeof(WCHAR
);
782 NameU
.MaximumLength
= FileNameU
.MaximumLength
;
783 DPRINT("%wZ\n", &NameU
);
784 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
788 NameU
.MaximumLength
= NameU
.Length
= (curr
- prev
) * sizeof(WCHAR
);
789 status
= vfatDirFindFile(pVCB
, parentFCB
, &NameU
, &FCB
);
790 if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
795 *pParentFCB
= parentFCB
;
796 return STATUS_OBJECT_NAME_NOT_FOUND
;
800 vfatReleaseFCB (pVCB
, parentFCB
);
802 return STATUS_OBJECT_PATH_NOT_FOUND
;
805 else if (!NT_SUCCESS (status
))
807 vfatReleaseFCB (pVCB
, parentFCB
);
816 *pParentFCB
= parentFCB
;
819 return STATUS_SUCCESS
;