4 * FILE: drivers/fs/vfat/fcb.c
5 * PURPOSE: Routines to manipulate FCBs.
6 * COPYRIGHT: See COPYING in the top level directory
7 * PROJECT: ReactOS kernel
8 * PROGRAMMER: Jason Filby (jasonfilby@yahoo.com)
9 * Rex Jolliff (rex@lvcablemodem.com)
11 * Herve Poussineau (reactos@poussine.freesurf.fr)
14 /* ------------------------------------------------------- INCLUDES */
16 #include <ddk/ntddk.h>
17 #include <ntos/kefuncs.h>
20 #include <rosrtl/string.h>
27 /* -------------------------------------------------------- DEFINES */
29 #define TAG(A, B, C, D) (ULONG)(((A)<<0) + ((B)<<8) + ((C)<<16) + ((D)<<24))
30 #define TAG_FCB TAG('V', 'F', 'C', 'B')
32 #define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
34 /* -------------------------------------------------------- PUBLICS */
36 ULONG
vfatNameHash(ULONG hash
, PUNICODE_STRING NameU
)
42 ASSERT(NameU
->Buffer
[0] != L
'.');
44 last
= NameU
->Buffer
+ NameU
->Length
/ sizeof(WCHAR
);
48 c
= towlower(*curr
++);
49 hash
= (hash
+ (c
<< 4) + (c
>> 4)) * 11;
55 vfatSplitPathName(PUNICODE_STRING PathNameU
, PUNICODE_STRING DirNameU
, 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
;
80 vfatInitFcb(PVFATFCB Fcb
, PUNICODE_STRING NameU
)
82 Fcb
->PathNameU
.Length
= 0;
83 Fcb
->PathNameU
.Buffer
= Fcb
->PathNameBuffer
;
84 Fcb
->PathNameU
.MaximumLength
= sizeof(Fcb
->PathNameBuffer
);
85 Fcb
->ShortNameU
.Length
= 0;
86 Fcb
->ShortNameU
.Buffer
= Fcb
->ShortNameBuffer
;
87 Fcb
->ShortNameU
.MaximumLength
= sizeof(Fcb
->ShortNameBuffer
);
88 Fcb
->DirNameU
.Buffer
= Fcb
->PathNameU
.Buffer
;
89 if (NameU
&& NameU
->Length
)
91 RtlCopyUnicodeString(&Fcb
->PathNameU
, NameU
);
92 vfatSplitPathName(&Fcb
->PathNameU
, &Fcb
->DirNameU
, &Fcb
->LongNameU
);
96 Fcb
->DirNameU
.Buffer
= Fcb
->LongNameU
.Buffer
= NULL
;
97 Fcb
->DirNameU
.MaximumLength
= Fcb
->DirNameU
.Length
= 0;
98 Fcb
->LongNameU
.MaximumLength
= Fcb
->LongNameU
.Length
= 0;
100 RtlZeroMemory(&Fcb
->FCBShareAccess
, sizeof(SHARE_ACCESS
));
101 Fcb
->OpenHandleCount
= 0;
105 vfatNewFCB(PDEVICE_EXTENSION pVCB
, PUNICODE_STRING pFileNameU
)
109 DPRINT("'%wZ'\n", pFileNameU
);
111 rcFCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
);
116 RtlZeroMemory(rcFCB
, sizeof(VFATFCB
));
117 vfatInitFcb(rcFCB
, pFileNameU
);
118 if (pVCB
->Flags
& VCB_IS_FATX
)
120 rcFCB
->Flags
|= FCB_IS_FATX_ENTRY
;
121 rcFCB
->Attributes
= &rcFCB
->entry
.FatX
.Attrib
;
124 rcFCB
->Attributes
= &rcFCB
->entry
.Fat
.Attrib
;
125 rcFCB
->Hash
.Hash
= vfatNameHash(0, &rcFCB
->PathNameU
);
126 rcFCB
->Hash
.self
= rcFCB
;
127 rcFCB
->ShortHash
.self
= rcFCB
;
128 ExInitializeResourceLite(&rcFCB
->PagingIoResource
);
129 ExInitializeResourceLite(&rcFCB
->MainResource
);
130 FsRtlInitializeFileLock(&rcFCB
->FileLock
, NULL
, NULL
);
131 ExInitializeFastMutex(&rcFCB
->LastMutex
);
136 vfatDestroyCCB(PVFATCCB pCcb
)
138 if (pCcb
->SearchPattern
.Buffer
)
140 ExFreePool(pCcb
->SearchPattern
.Buffer
);
142 ExFreeToNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
, pCcb
);
146 vfatDestroyFCB(PVFATFCB pFCB
)
148 FsRtlUninitializeFileLock(&pFCB
->FileLock
);
149 ExDeleteResourceLite(&pFCB
->PagingIoResource
);
150 ExDeleteResourceLite(&pFCB
->MainResource
);
151 ExFreeToNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
, pFCB
);
155 vfatFCBIsDirectory(PVFATFCB FCB
)
157 return *FCB
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
;
161 vfatFCBIsRoot(PVFATFCB FCB
)
163 return FCB
->PathNameU
.Length
== sizeof(WCHAR
) && FCB
->PathNameU
.Buffer
[0] == L
'\\' ? TRUE
: FALSE
;
167 vfatReleaseFCB(PDEVICE_EXTENSION pVCB
, PVFATFCB pFCB
)
174 DPRINT ("releasing FCB at %x: %wZ, refCount:%d\n",
181 Index
= pFCB
->Hash
.Hash
% FCB_HASH_TABLE_SIZE
;
182 ShortIndex
= pFCB
->ShortHash
.Hash
% FCB_HASH_TABLE_SIZE
;
184 if (pFCB
->RefCount
<= 0 && (!vfatFCBIsDirectory (pFCB
) || pFCB
->Flags
& FCB_DELETE_PENDING
))
186 tmpFcb
= pFCB
->parentFcb
;
187 RemoveEntryList (&pFCB
->FcbListEntry
);
188 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
190 entry
= pVCB
->FcbHashTable
[ShortIndex
];
191 if (entry
->self
== pFCB
)
193 pVCB
->FcbHashTable
[ShortIndex
] = entry
->next
;
197 while (entry
->next
->self
!= pFCB
)
201 entry
->next
= pFCB
->ShortHash
.next
;
204 entry
= pVCB
->FcbHashTable
[Index
];
205 if (entry
->self
== pFCB
)
207 pVCB
->FcbHashTable
[Index
] = entry
->next
;
211 while (entry
->next
->self
!= pFCB
)
215 entry
->next
= pFCB
->Hash
.next
;
217 if (vfatFCBIsDirectory(pFCB
))
219 /* Uninitialize file cache if initialized for this file object. */
220 if (pFCB
->FileObject
->SectionObjectPointer
->SharedCacheMap
)
222 CcRosReleaseFileCache(pFCB
->FileObject
);
224 vfatDestroyCCB(pFCB
->FileObject
->FsContext2
);
225 pFCB
->FileObject
->FsContext2
= NULL
;
226 pFCB
->FileObject
->FsContext
= NULL
;
227 ObDereferenceObject(pFCB
->FileObject
);
229 vfatDestroyFCB (pFCB
);
240 vfatAddFCBToTable(PDEVICE_EXTENSION pVCB
, PVFATFCB pFCB
)
245 Index
= pFCB
->Hash
.Hash
% FCB_HASH_TABLE_SIZE
;
246 ShortIndex
= pFCB
->ShortHash
.Hash
% FCB_HASH_TABLE_SIZE
;
248 InsertTailList (&pVCB
->FcbListHead
, &pFCB
->FcbListEntry
);
250 pFCB
->Hash
.next
= pVCB
->FcbHashTable
[Index
];
251 pVCB
->FcbHashTable
[Index
] = &pFCB
->Hash
;
252 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
254 pFCB
->ShortHash
.next
= pVCB
->FcbHashTable
[ShortIndex
];
255 pVCB
->FcbHashTable
[ShortIndex
] = &pFCB
->ShortHash
;
259 pFCB
->parentFcb
->RefCount
++;
264 vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB
, PUNICODE_STRING PathNameU
)
268 UNICODE_STRING DirNameU
;
269 UNICODE_STRING FileNameU
;
270 PUNICODE_STRING FcbNameU
;
274 DPRINT("'%wZ'\n", PathNameU
);
276 Hash
= vfatNameHash(0, PathNameU
);
278 entry
= pVCB
->FcbHashTable
[Hash
% FCB_HASH_TABLE_SIZE
];
281 vfatSplitPathName(PathNameU
, &DirNameU
, &FileNameU
);
286 if (entry
->Hash
== Hash
)
289 DPRINT("'%wZ' '%wZ'\n", &DirNameU
, &rcFCB
->DirNameU
);
290 if (RtlEqualUnicodeString(&DirNameU
, &rcFCB
->DirNameU
, TRUE
))
292 if (rcFCB
->Hash
.Hash
== Hash
)
294 FcbNameU
= &rcFCB
->LongNameU
;
298 FcbNameU
= &rcFCB
->ShortNameU
;
300 /* compare the file name */
301 DPRINT("'%wZ' '%wZ'\n", &FileNameU
, FcbNameU
);
302 if (RtlEqualUnicodeString(&FileNameU
, FcbNameU
, TRUE
))
317 vfatFCBInitializeCacheFromVolume (PVCB vcb
, PVFATFCB fcb
)
320 PFILE_OBJECT fileObject
;
321 ULONG fileCacheQuantum
;
324 fileObject
= IoCreateStreamFileObject (NULL
, vcb
->StorageDevice
);
326 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
329 return STATUS_INSUFFICIENT_RESOURCES
;
331 RtlZeroMemory(newCCB
, sizeof (VFATCCB
));
333 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
334 fileObject
->FsContext
= fcb
;
335 fileObject
->FsContext2
= newCCB
;
336 fcb
->FileObject
= fileObject
;
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 fcb
->Flags
|= FCB_CACHE_INITIALIZED
;
356 vfatMakeRootFCB(PDEVICE_EXTENSION pVCB
)
359 ULONG FirstCluster
, CurrentCluster
, Size
= 0;
360 NTSTATUS Status
= STATUS_SUCCESS
;
361 UNICODE_STRING NameU
;
363 RtlRosInitUnicodeStringFromLiteral(&NameU
, L
"\\");
365 FCB
= vfatNewFCB(pVCB
, &NameU
);
366 if (FCB
->Flags
& FCB_IS_FATX_ENTRY
)
368 memset(FCB
->entry
.FatX
.Filename
, ' ', 42);
369 FCB
->entry
.FatX
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
370 FCB
->entry
.FatX
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
371 FCB
->entry
.FatX
.FirstCluster
= 1;
372 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
376 memset(FCB
->entry
.Fat
.Filename
, ' ', 11);
377 FCB
->entry
.Fat
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
378 FCB
->entry
.Fat
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
379 if (pVCB
->FatInfo
.FatType
== FAT32
)
381 CurrentCluster
= FirstCluster
= pVCB
->FatInfo
.RootCluster
;
382 FCB
->entry
.Fat
.FirstCluster
= (unsigned short)(FirstCluster
& 0xffff);
383 FCB
->entry
.Fat
.FirstClusterHigh
= (unsigned short)(FirstCluster
>> 16);
385 while (CurrentCluster
!= 0xffffffff && NT_SUCCESS(Status
))
387 Size
+= pVCB
->FatInfo
.BytesPerCluster
;
388 Status
= NextCluster (pVCB
, FirstCluster
, &CurrentCluster
, FALSE
);
393 FCB
->entry
.Fat
.FirstCluster
= 1;
394 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
397 FCB
->ShortHash
.Hash
= FCB
->Hash
.Hash
;
400 FCB
->RFCB
.FileSize
.QuadPart
= Size
;
401 FCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
402 FCB
->RFCB
.AllocationSize
.QuadPart
= Size
;
404 vfatFCBInitializeCacheFromVolume(pVCB
, FCB
);
405 vfatAddFCBToTable(pVCB
, FCB
);
411 vfatOpenRootFCB(PDEVICE_EXTENSION pVCB
)
414 UNICODE_STRING NameU
;
416 RtlRosInitUnicodeStringFromLiteral(&NameU
, L
"\\");
418 FCB
= vfatGrabFCBFromTable (pVCB
, &NameU
);
421 FCB
= vfatMakeRootFCB (pVCB
);
428 vfatMakeFCBFromDirEntry(PVCB vcb
,
429 PVFATFCB directoryFCB
,
430 PVFAT_DIRENTRY_CONTEXT DirContext
,
434 WCHAR pathName
[MAX_PATH
];
438 UNICODE_STRING NameU
;
440 if (directoryFCB
->PathNameU
.Length
+ 2 * sizeof(WCHAR
) +
441 + DirContext
->LongNameU
.Length
> MAX_PATH
* sizeof(WCHAR
))
443 return STATUS_OBJECT_NAME_INVALID
;
445 NameU
.Buffer
= pathName
;
447 NameU
.MaximumLength
= sizeof(pathName
);
449 RtlCopyUnicodeString(&NameU
, &directoryFCB
->PathNameU
);
450 if (!vfatFCBIsRoot (directoryFCB
))
452 RtlAppendUnicodeToString(&NameU
, L
"\\");
454 hash
= vfatNameHash(0, &NameU
);
455 if (DirContext
->LongNameU
.Length
> 0)
457 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->LongNameU
);
461 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->ShortNameU
);
463 NameU
.Buffer
[NameU
.Length
/ sizeof(WCHAR
)] = 0;
465 rcFCB
= vfatNewFCB (vcb
, &NameU
);
466 RtlCopyMemory (&rcFCB
->entry
, &DirContext
->DirEntry
, sizeof (DIR_ENTRY
));
467 RtlCopyUnicodeString(&rcFCB
->ShortNameU
, &DirContext
->ShortNameU
);
468 if (vcb
->Flags
& VCB_IS_FATX
)
470 rcFCB
->ShortHash
.Hash
= rcFCB
->Hash
.Hash
;
474 rcFCB
->ShortHash
.Hash
= vfatNameHash(hash
, &rcFCB
->ShortNameU
);
477 if (vfatFCBIsDirectory(rcFCB
))
479 ULONG FirstCluster
, CurrentCluster
;
482 FirstCluster
= vfatDirEntryGetFirstCluster (vcb
, &rcFCB
->entry
);
483 if (FirstCluster
== 1)
485 Size
= vcb
->FatInfo
.rootDirectorySectors
* vcb
->FatInfo
.BytesPerSector
;
487 else if (FirstCluster
!= 0)
489 CurrentCluster
= FirstCluster
;
490 while (CurrentCluster
!= 0xffffffff)
492 Size
+= vcb
->FatInfo
.BytesPerCluster
;
493 Status
= NextCluster (vcb
, FirstCluster
, &CurrentCluster
, FALSE
);
497 else if (rcFCB
->Flags
& FCB_IS_FATX_ENTRY
)
499 Size
= rcFCB
->entry
.FatX
.FileSize
;
503 Size
= rcFCB
->entry
.Fat
.FileSize
;
505 rcFCB
->dirIndex
= DirContext
->DirIndex
;
506 rcFCB
->startIndex
= DirContext
->StartIndex
;
507 rcFCB
->RFCB
.FileSize
.QuadPart
= Size
;
508 rcFCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
509 rcFCB
->RFCB
.AllocationSize
.QuadPart
= ROUND_UP(Size
, vcb
->FatInfo
.BytesPerCluster
);
511 if (vfatFCBIsDirectory(rcFCB
))
513 vfatFCBInitializeCacheFromVolume(vcb
, rcFCB
);
515 rcFCB
->parentFcb
= directoryFCB
;
516 vfatAddFCBToTable (vcb
, rcFCB
);
519 return STATUS_SUCCESS
;
523 vfatAttachFCBToFileObject (PDEVICE_EXTENSION vcb
,
525 PFILE_OBJECT fileObject
)
529 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
533 return STATUS_INSUFFICIENT_RESOURCES
;
535 RtlZeroMemory (newCCB
, sizeof (VFATCCB
));
537 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
538 fileObject
->FsContext
= fcb
;
539 fileObject
->FsContext2
= newCCB
;
540 DPRINT ("file open: fcb:%x PathName:%wZ file size: %d\n", fcb
, &fcb
->PathNameU
, fcb
->entry
.FileSize
);
542 return STATUS_SUCCESS
;
546 vfatDirFindFile (PDEVICE_EXTENSION pDeviceExt
,
547 PVFATFCB pDirectoryFCB
,
548 PUNICODE_STRING FileToFindU
,
549 PVFATFCB
* pFoundFCB
)
552 PVOID Context
= NULL
;
554 BOOLEAN First
= TRUE
;
555 VFAT_DIRENTRY_CONTEXT DirContext
;
556 WCHAR LongNameBuffer
[MAX_PATH
];
557 WCHAR ShortNameBuffer
[13];
558 BOOLEAN FoundLong
= FALSE
;
559 BOOLEAN FoundShort
= FALSE
;
562 ASSERT(pDirectoryFCB
);
565 DPRINT ("vfatDirFindFile(VCB:%08x, dirFCB:%08x, File:%wZ)\n",
569 DPRINT ("Dir Path:%wZ\n", &pDirectoryFCB
->PathNameU
);
571 DirContext
.DirIndex
= 0;
572 DirContext
.LongNameU
.Buffer
= LongNameBuffer
;
573 DirContext
.LongNameU
.Length
= 0;
574 DirContext
.LongNameU
.MaximumLength
= sizeof(LongNameBuffer
);
575 DirContext
.ShortNameU
.Buffer
= ShortNameBuffer
;
576 DirContext
.ShortNameU
.Length
= 0;
577 DirContext
.ShortNameU
.MaximumLength
= sizeof(ShortNameBuffer
);
581 status
= pDeviceExt
->GetNextDirEntry(&Context
,
587 if (status
== STATUS_NO_MORE_ENTRIES
)
589 return STATUS_OBJECT_NAME_NOT_FOUND
;
591 if (!NT_SUCCESS(status
))
596 DPRINT (" Index:%d longName:%wZ\n",
598 &DirContext
.LongNameU
);
599 DirContext
.LongNameU
.Buffer
[DirContext
.LongNameU
.Length
/ sizeof(WCHAR
)] = 0;
600 DirContext
.ShortNameU
.Buffer
[DirContext
.ShortNameU
.Length
/ sizeof(WCHAR
)] = 0;
601 if (!ENTRY_VOLUME(pDeviceExt
, &DirContext
.DirEntry
))
603 FoundLong
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.LongNameU
, TRUE
);
604 if (FoundLong
== FALSE
)
606 FoundShort
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.ShortNameU
, TRUE
);
608 if (FoundLong
|| FoundShort
)
610 status
= vfatMakeFCBFromDirEntry (pDeviceExt
,
614 CcUnpinData(Context
);
618 DirContext
.DirIndex
++;
621 return STATUS_OBJECT_NAME_NOT_FOUND
;
625 vfatGetFCBForFile (PDEVICE_EXTENSION pVCB
,
626 PVFATFCB
*pParentFCB
,
628 PUNICODE_STRING pFileNameU
)
633 UNICODE_STRING NameU
;
634 UNICODE_STRING RootNameU
;
635 PWCHAR curr
, prev
, last
;
638 DPRINT ("vfatGetFCBForFile (%x,%x,%x,%wZ)\n",
644 parentFCB
= *pParentFCB
;
646 if (parentFCB
== NULL
)
648 RtlRosInitUnicodeStringFromLiteral(&RootNameU
, L
"\\");
650 // Trivial case, open of the root directory on volume
651 if (RtlEqualUnicodeString(pFileNameU
, &RootNameU
, FALSE
))
653 DPRINT ("returning root FCB\n");
655 FCB
= vfatOpenRootFCB (pVCB
);
659 return (FCB
!= NULL
) ? STATUS_SUCCESS
: STATUS_OBJECT_PATH_NOT_FOUND
;
662 /* Check for an existing FCB */
663 FCB
= vfatGrabFCBFromTable (pVCB
, pFileNameU
);
667 *pParentFCB
= FCB
->parentFcb
;
668 (*pParentFCB
)->RefCount
++;
669 return STATUS_SUCCESS
;
672 last
= curr
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
673 while (*curr
!= L
'\\' && curr
> pFileNameU
->Buffer
)
678 if (curr
> pFileNameU
->Buffer
)
680 NameU
.Buffer
= pFileNameU
->Buffer
;
681 NameU
.MaximumLength
= NameU
.Length
= (curr
- pFileNameU
->Buffer
) * sizeof(WCHAR
);
682 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
685 Length
= (curr
- pFileNameU
->Buffer
) * sizeof(WCHAR
);
686 if (Length
!= FCB
->PathNameU
.Length
)
688 if (pFileNameU
->Length
+ FCB
->PathNameU
.Length
- Length
> pFileNameU
->MaximumLength
)
690 vfatReleaseFCB (pVCB
, FCB
);
691 return STATUS_OBJECT_NAME_INVALID
;
693 memmove(pFileNameU
->Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
),
694 curr
, pFileNameU
->Length
- Length
);
695 pFileNameU
->Length
+= FCB
->PathNameU
.Length
- Length
;
696 curr
= pFileNameU
->Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
);
697 last
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
699 RtlCopyMemory(pFileNameU
->Buffer
, FCB
->PathNameU
.Buffer
, FCB
->PathNameU
.Length
);
709 FCB
= vfatOpenRootFCB(pVCB
);
710 curr
= pFileNameU
->Buffer
;
720 prev
= curr
= pFileNameU
->Buffer
- 1;
721 last
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
728 vfatReleaseFCB (pVCB
, parentFCB
);
731 // fail if element in FCB is not a directory
732 if (!vfatFCBIsDirectory (FCB
))
734 DPRINT ("Element in requested path is not a directory\n");
736 vfatReleaseFCB (pVCB
, FCB
);
741 return STATUS_OBJECT_PATH_NOT_FOUND
;
746 Length
= (curr
- prev
) * sizeof(WCHAR
);
747 if (Length
!= parentFCB
->LongNameU
.Length
)
749 if (pFileNameU
->Length
+ parentFCB
->LongNameU
.Length
- Length
> pFileNameU
->MaximumLength
)
751 vfatReleaseFCB (pVCB
, parentFCB
);
752 return STATUS_OBJECT_NAME_INVALID
;
754 memmove(prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
), curr
,
755 pFileNameU
->Length
- (curr
- pFileNameU
->Buffer
) * sizeof(WCHAR
));
756 pFileNameU
->Length
+= parentFCB
->LongNameU
.Length
- Length
;
757 curr
= prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
);
758 last
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
760 RtlCopyMemory(prev
, parentFCB
->LongNameU
.Buffer
, parentFCB
->LongNameU
.Length
);
764 while (*curr
!= L
'\\' && curr
<= last
)
768 NameU
.Buffer
= pFileNameU
->Buffer
;
769 NameU
.Length
= (curr
- NameU
.Buffer
) * sizeof(WCHAR
);
770 NameU
.MaximumLength
= pFileNameU
->MaximumLength
;
771 DPRINT("%wZ\n", &NameU
);
772 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
776 NameU
.MaximumLength
= NameU
.Length
= (curr
- prev
) * sizeof(WCHAR
);
777 status
= vfatDirFindFile(pVCB
, parentFCB
, &NameU
, &FCB
);
778 if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
783 *pParentFCB
= parentFCB
;
784 return STATUS_OBJECT_NAME_NOT_FOUND
;
788 vfatReleaseFCB (pVCB
, parentFCB
);
790 return STATUS_OBJECT_PATH_NOT_FOUND
;
793 else if (!NT_SUCCESS (status
))
795 vfatReleaseFCB (pVCB
, parentFCB
);
804 *pParentFCB
= parentFCB
;
807 return STATUS_SUCCESS
;