1 /* $Id: fcb.c,v 1.43 2004/12/05 16:31:51 gvg Exp $
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
)
58 DirNameU
->Buffer
= PathNameU
->Buffer
;
59 pName
= PathNameU
->Buffer
+ PathNameU
->Length
/ sizeof(WCHAR
) - 1;
60 while (*pName
!= L
'\\' && pName
> PathNameU
->Buffer
)
64 ASSERT(*pName
== L
'\\');
65 FileNameU
->Buffer
= pName
+ 1;
66 DirNameU
->Length
= (FileNameU
->Buffer
- PathNameU
->Buffer
) * sizeof(WCHAR
);
67 DirNameU
->MaximumLength
= DirNameU
->Length
;
68 FileNameU
->Length
= PathNameU
->Length
- DirNameU
->Length
;
69 FileNameU
->MaximumLength
= FileNameU
->Length
;
73 vfatInitFcb(PVFATFCB Fcb
, PUNICODE_STRING NameU
)
75 Fcb
->PathNameU
.Length
= 0;
76 Fcb
->PathNameU
.Buffer
= Fcb
->PathNameBuffer
;
77 Fcb
->PathNameU
.MaximumLength
= sizeof(Fcb
->PathNameBuffer
);
78 Fcb
->ShortNameU
.Length
= 0;
79 Fcb
->ShortNameU
.Buffer
= Fcb
->ShortNameBuffer
;
80 Fcb
->ShortNameU
.MaximumLength
= sizeof(Fcb
->ShortNameBuffer
);
81 Fcb
->DirNameU
.Buffer
= Fcb
->PathNameU
.Buffer
;
82 if (NameU
&& NameU
->Length
)
84 RtlCopyUnicodeString(&Fcb
->PathNameU
, NameU
);
85 vfatSplitPathName(&Fcb
->PathNameU
, &Fcb
->DirNameU
, &Fcb
->LongNameU
);
89 Fcb
->DirNameU
.Buffer
= Fcb
->LongNameU
.Buffer
= NULL
;
90 Fcb
->DirNameU
.MaximumLength
= Fcb
->DirNameU
.Length
= 0;
91 Fcb
->LongNameU
.MaximumLength
= Fcb
->LongNameU
.Length
= 0;
93 RtlZeroMemory(&Fcb
->FCBShareAccess
, sizeof(SHARE_ACCESS
));
94 Fcb
->OpenHandleCount
= 0;
98 vfatNewFCB(PDEVICE_EXTENSION pVCB
, PUNICODE_STRING pFileNameU
)
102 DPRINT("'%wZ'\n", pFileNameU
);
104 rcFCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
);
109 RtlZeroMemory(rcFCB
, sizeof(VFATFCB
));
110 vfatInitFcb(rcFCB
, pFileNameU
);
111 if (pVCB
->Flags
& VCB_IS_FATX
)
113 rcFCB
->Flags
|= FCB_IS_FATX_ENTRY
;
114 rcFCB
->Attributes
= &rcFCB
->entry
.FatX
.Attrib
;
117 rcFCB
->Attributes
= &rcFCB
->entry
.Fat
.Attrib
;
118 rcFCB
->Hash
.Hash
= vfatNameHash(0, &rcFCB
->PathNameU
);
119 rcFCB
->Hash
.self
= rcFCB
;
120 rcFCB
->ShortHash
.self
= rcFCB
;
121 ExInitializeResourceLite(&rcFCB
->PagingIoResource
);
122 ExInitializeResourceLite(&rcFCB
->MainResource
);
123 FsRtlInitializeFileLock(&rcFCB
->FileLock
, NULL
, NULL
);
124 ExInitializeFastMutex(&rcFCB
->LastMutex
);
129 vfatDestroyCCB(PVFATCCB pCcb
)
131 if (pCcb
->SearchPattern
.Buffer
)
133 ExFreePool(pCcb
->SearchPattern
.Buffer
);
135 ExFreeToNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
, pCcb
);
139 vfatDestroyFCB(PVFATFCB pFCB
)
141 FsRtlUninitializeFileLock(&pFCB
->FileLock
);
142 ExDeleteResourceLite(&pFCB
->PagingIoResource
);
143 ExDeleteResourceLite(&pFCB
->MainResource
);
144 ExFreeToNPagedLookasideList(&VfatGlobalData
->FcbLookasideList
, pFCB
);
148 vfatFCBIsDirectory(PVFATFCB FCB
)
150 return *FCB
->Attributes
& FILE_ATTRIBUTE_DIRECTORY
;
154 vfatFCBIsRoot(PVFATFCB FCB
)
156 return FCB
->PathNameU
.Length
== sizeof(WCHAR
) && FCB
->PathNameU
.Buffer
[0] == L
'\\' ? TRUE
: FALSE
;
160 vfatReleaseFCB(PDEVICE_EXTENSION pVCB
, PVFATFCB pFCB
)
167 DPRINT ("releasing FCB at %x: %wZ, refCount:%d\n",
174 Index
= pFCB
->Hash
.Hash
% FCB_HASH_TABLE_SIZE
;
175 ShortIndex
= pFCB
->ShortHash
.Hash
% FCB_HASH_TABLE_SIZE
;
177 if (pFCB
->RefCount
<= 0 && (!vfatFCBIsDirectory (pFCB
) || pFCB
->Flags
& FCB_DELETE_PENDING
))
179 tmpFcb
= pFCB
->parentFcb
;
180 RemoveEntryList (&pFCB
->FcbListEntry
);
181 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
183 entry
= pVCB
->FcbHashTable
[ShortIndex
];
184 if (entry
->self
== pFCB
)
186 pVCB
->FcbHashTable
[ShortIndex
] = entry
->next
;
190 while (entry
->next
->self
!= pFCB
)
194 entry
->next
= pFCB
->ShortHash
.next
;
197 entry
= pVCB
->FcbHashTable
[Index
];
198 if (entry
->self
== pFCB
)
200 pVCB
->FcbHashTable
[Index
] = entry
->next
;
204 while (entry
->next
->self
!= pFCB
)
208 entry
->next
= pFCB
->Hash
.next
;
210 if (vfatFCBIsDirectory(pFCB
))
212 /* Uninitialize file cache if initialized for this file object. */
213 if (pFCB
->FileObject
->SectionObjectPointer
->SharedCacheMap
)
215 CcRosReleaseFileCache(pFCB
->FileObject
);
217 vfatDestroyCCB(pFCB
->FileObject
->FsContext2
);
218 pFCB
->FileObject
->FsContext2
= NULL
;
219 pFCB
->FileObject
->FsContext
= NULL
;
220 ObDereferenceObject(pFCB
->FileObject
);
222 vfatDestroyFCB (pFCB
);
233 vfatAddFCBToTable(PDEVICE_EXTENSION pVCB
, PVFATFCB pFCB
)
238 Index
= pFCB
->Hash
.Hash
% FCB_HASH_TABLE_SIZE
;
239 ShortIndex
= pFCB
->ShortHash
.Hash
% FCB_HASH_TABLE_SIZE
;
241 InsertTailList (&pVCB
->FcbListHead
, &pFCB
->FcbListEntry
);
243 pFCB
->Hash
.next
= pVCB
->FcbHashTable
[Index
];
244 pVCB
->FcbHashTable
[Index
] = &pFCB
->Hash
;
245 if (pFCB
->Hash
.Hash
!= pFCB
->ShortHash
.Hash
)
247 pFCB
->ShortHash
.next
= pVCB
->FcbHashTable
[ShortIndex
];
248 pVCB
->FcbHashTable
[ShortIndex
] = &pFCB
->ShortHash
;
252 pFCB
->parentFcb
->RefCount
++;
257 vfatGrabFCBFromTable(PDEVICE_EXTENSION pVCB
, PUNICODE_STRING PathNameU
)
261 UNICODE_STRING DirNameU
;
262 UNICODE_STRING FileNameU
;
263 PUNICODE_STRING FcbNameU
;
267 DPRINT("'%wZ'\n", PathNameU
);
269 Hash
= vfatNameHash(0, PathNameU
);
271 entry
= pVCB
->FcbHashTable
[Hash
% FCB_HASH_TABLE_SIZE
];
274 vfatSplitPathName(PathNameU
, &DirNameU
, &FileNameU
);
279 if (entry
->Hash
== Hash
)
282 DPRINT("'%wZ' '%wZ'\n", &DirNameU
, &rcFCB
->DirNameU
);
283 if (RtlEqualUnicodeString(&DirNameU
, &rcFCB
->DirNameU
, TRUE
))
285 if (rcFCB
->Hash
.Hash
== Hash
)
287 FcbNameU
= &rcFCB
->LongNameU
;
291 FcbNameU
= &rcFCB
->ShortNameU
;
293 /* compare the file name */
294 DPRINT("'%wZ' '%wZ'\n", &FileNameU
, FcbNameU
);
295 if (RtlEqualUnicodeString(&FileNameU
, FcbNameU
, TRUE
))
310 vfatFCBInitializeCacheFromVolume (PVCB vcb
, PVFATFCB fcb
)
313 PFILE_OBJECT fileObject
;
314 ULONG fileCacheQuantum
;
317 fileObject
= IoCreateStreamFileObject (NULL
, vcb
->StorageDevice
);
319 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
322 return STATUS_INSUFFICIENT_RESOURCES
;
324 RtlZeroMemory(newCCB
, sizeof (VFATCCB
));
326 fileObject
->Flags
|= FO_FCB_IS_VALID
| FO_DIRECT_CACHE_PAGING_READ
;
327 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
328 fileObject
->FsContext
= fcb
;
329 fileObject
->FsContext2
= newCCB
;
330 fcb
->FileObject
= fileObject
;
333 fileCacheQuantum
= (vcb
->FatInfo
.BytesPerCluster
>= PAGE_SIZE
) ?
334 vcb
->FatInfo
.BytesPerCluster
: PAGE_SIZE
;
336 status
= CcRosInitializeFileCache (fileObject
,
338 if (!NT_SUCCESS (status
))
340 DbgPrint ("CcRosInitializeFileCache failed\n");
344 fcb
->Flags
|= FCB_CACHE_INITIALIZED
;
350 vfatMakeRootFCB(PDEVICE_EXTENSION pVCB
)
353 ULONG FirstCluster
, CurrentCluster
, Size
= 0;
354 NTSTATUS Status
= STATUS_SUCCESS
;
355 UNICODE_STRING NameU
;
357 RtlRosInitUnicodeStringFromLiteral(&NameU
, L
"\\");
359 FCB
= vfatNewFCB(pVCB
, &NameU
);
360 if (FCB
->Flags
& FCB_IS_FATX_ENTRY
)
362 memset(FCB
->entry
.FatX
.Filename
, ' ', 42);
363 FCB
->entry
.FatX
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
364 FCB
->entry
.FatX
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
365 FCB
->entry
.FatX
.FirstCluster
= 1;
366 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
370 memset(FCB
->entry
.Fat
.Filename
, ' ', 11);
371 FCB
->entry
.Fat
.FileSize
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
372 FCB
->entry
.Fat
.Attrib
= FILE_ATTRIBUTE_DIRECTORY
;
373 if (pVCB
->FatInfo
.FatType
== FAT32
)
375 CurrentCluster
= FirstCluster
= pVCB
->FatInfo
.RootCluster
;
376 FCB
->entry
.Fat
.FirstCluster
= (unsigned short)(FirstCluster
& 0xffff);
377 FCB
->entry
.Fat
.FirstClusterHigh
= (unsigned short)(FirstCluster
>> 16);
379 while (CurrentCluster
!= 0xffffffff && NT_SUCCESS(Status
))
381 Size
+= pVCB
->FatInfo
.BytesPerCluster
;
382 Status
= NextCluster (pVCB
, FirstCluster
, &CurrentCluster
, FALSE
);
387 FCB
->entry
.Fat
.FirstCluster
= 1;
388 Size
= pVCB
->FatInfo
.rootDirectorySectors
* pVCB
->FatInfo
.BytesPerSector
;
391 FCB
->ShortHash
.Hash
= FCB
->Hash
.Hash
;
394 FCB
->RFCB
.FileSize
.QuadPart
= Size
;
395 FCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
396 FCB
->RFCB
.AllocationSize
.QuadPart
= Size
;
398 vfatFCBInitializeCacheFromVolume(pVCB
, FCB
);
399 vfatAddFCBToTable(pVCB
, FCB
);
405 vfatOpenRootFCB(PDEVICE_EXTENSION pVCB
)
408 UNICODE_STRING NameU
;
410 RtlRosInitUnicodeStringFromLiteral(&NameU
, L
"\\");
412 FCB
= vfatGrabFCBFromTable (pVCB
, &NameU
);
415 FCB
= vfatMakeRootFCB (pVCB
);
422 vfatMakeFCBFromDirEntry(PVCB vcb
,
423 PVFATFCB directoryFCB
,
424 PVFAT_DIRENTRY_CONTEXT DirContext
,
428 WCHAR pathName
[MAX_PATH
];
432 UNICODE_STRING NameU
;
434 if (directoryFCB
->PathNameU
.Length
+ 2 * sizeof(WCHAR
) +
435 + DirContext
->LongNameU
.Length
> MAX_PATH
* sizeof(WCHAR
))
437 return STATUS_OBJECT_NAME_INVALID
;
439 NameU
.Buffer
= pathName
;
441 NameU
.MaximumLength
= sizeof(pathName
);
443 RtlCopyUnicodeString(&NameU
, &directoryFCB
->PathNameU
);
444 if (!vfatFCBIsRoot (directoryFCB
))
446 RtlAppendUnicodeToString(&NameU
, L
"\\");
448 hash
= vfatNameHash(0, &NameU
);
449 if (DirContext
->LongNameU
.Length
> 0)
451 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->LongNameU
);
455 RtlAppendUnicodeStringToString(&NameU
, &DirContext
->ShortNameU
);
457 NameU
.Buffer
[NameU
.Length
/ sizeof(WCHAR
)] = 0;
459 rcFCB
= vfatNewFCB (vcb
, &NameU
);
460 RtlCopyMemory (&rcFCB
->entry
, &DirContext
->DirEntry
, sizeof (DIR_ENTRY
));
461 RtlCopyUnicodeString(&rcFCB
->ShortNameU
, &DirContext
->ShortNameU
);
462 if (vcb
->Flags
& VCB_IS_FATX
)
464 rcFCB
->ShortHash
.Hash
= rcFCB
->Hash
.Hash
;
468 rcFCB
->ShortHash
.Hash
= vfatNameHash(hash
, &rcFCB
->ShortNameU
);
471 if (vfatFCBIsDirectory(rcFCB
))
473 ULONG FirstCluster
, CurrentCluster
;
476 FirstCluster
= vfatDirEntryGetFirstCluster (vcb
, &rcFCB
->entry
);
477 if (FirstCluster
== 1)
479 Size
= vcb
->FatInfo
.rootDirectorySectors
* vcb
->FatInfo
.BytesPerSector
;
481 else if (FirstCluster
!= 0)
483 CurrentCluster
= FirstCluster
;
484 while (CurrentCluster
!= 0xffffffff)
486 Size
+= vcb
->FatInfo
.BytesPerCluster
;
487 Status
= NextCluster (vcb
, FirstCluster
, &CurrentCluster
, FALSE
);
491 else if (rcFCB
->Flags
& FCB_IS_FATX_ENTRY
)
493 Size
= rcFCB
->entry
.FatX
.FileSize
;
497 Size
= rcFCB
->entry
.Fat
.FileSize
;
499 rcFCB
->dirIndex
= DirContext
->DirIndex
;
500 rcFCB
->startIndex
= DirContext
->StartIndex
;
501 rcFCB
->RFCB
.FileSize
.QuadPart
= Size
;
502 rcFCB
->RFCB
.ValidDataLength
.QuadPart
= Size
;
503 rcFCB
->RFCB
.AllocationSize
.QuadPart
= ROUND_UP(Size
, vcb
->FatInfo
.BytesPerCluster
);
505 if (vfatFCBIsDirectory(rcFCB
))
507 vfatFCBInitializeCacheFromVolume(vcb
, rcFCB
);
509 rcFCB
->parentFcb
= directoryFCB
;
510 vfatAddFCBToTable (vcb
, rcFCB
);
513 return STATUS_SUCCESS
;
517 vfatAttachFCBToFileObject (PDEVICE_EXTENSION vcb
,
519 PFILE_OBJECT fileObject
)
523 newCCB
= ExAllocateFromNPagedLookasideList(&VfatGlobalData
->CcbLookasideList
);
527 return STATUS_INSUFFICIENT_RESOURCES
;
529 RtlZeroMemory (newCCB
, sizeof (VFATCCB
));
531 fileObject
->Flags
= fileObject
->Flags
| FO_FCB_IS_VALID
|
532 FO_DIRECT_CACHE_PAGING_READ
;
533 fileObject
->SectionObjectPointer
= &fcb
->SectionObjectPointers
;
534 fileObject
->FsContext
= fcb
;
535 fileObject
->FsContext2
= newCCB
;
536 DPRINT ("file open: fcb:%x PathName:%wZ file size: %d\n", fcb
, &fcb
->PathNameU
, fcb
->entry
.FileSize
);
538 return STATUS_SUCCESS
;
542 vfatDirFindFile (PDEVICE_EXTENSION pDeviceExt
,
543 PVFATFCB pDirectoryFCB
,
544 PUNICODE_STRING FileToFindU
,
545 PVFATFCB
* pFoundFCB
)
548 PVOID Context
= NULL
;
550 BOOLEAN First
= TRUE
;
551 VFAT_DIRENTRY_CONTEXT DirContext
;
552 WCHAR LongNameBuffer
[MAX_PATH
];
553 WCHAR ShortNameBuffer
[13];
554 BOOLEAN FoundLong
= FALSE
;
555 BOOLEAN FoundShort
= FALSE
;
558 ASSERT(pDirectoryFCB
);
561 DPRINT ("vfatDirFindFile(VCB:%08x, dirFCB:%08x, File:%wZ)\n",
565 DPRINT ("Dir Path:%wZ\n", &pDirectoryFCB
->PathNameU
);
567 DirContext
.DirIndex
= 0;
568 DirContext
.LongNameU
.Buffer
= LongNameBuffer
;
569 DirContext
.LongNameU
.Length
= 0;
570 DirContext
.LongNameU
.MaximumLength
= sizeof(LongNameBuffer
);
571 DirContext
.ShortNameU
.Buffer
= ShortNameBuffer
;
572 DirContext
.ShortNameU
.Length
= 0;
573 DirContext
.ShortNameU
.MaximumLength
= sizeof(ShortNameBuffer
);
577 status
= pDeviceExt
->GetNextDirEntry(&Context
,
583 if (status
== STATUS_NO_MORE_ENTRIES
)
585 return STATUS_OBJECT_NAME_NOT_FOUND
;
587 if (!NT_SUCCESS(status
))
592 DPRINT (" Index:%d longName:%wZ\n",
594 &DirContext
.LongNameU
);
595 DirContext
.LongNameU
.Buffer
[DirContext
.LongNameU
.Length
/ sizeof(WCHAR
)] = 0;
596 DirContext
.ShortNameU
.Buffer
[DirContext
.ShortNameU
.Length
/ sizeof(WCHAR
)] = 0;
597 if (!ENTRY_VOLUME(pDeviceExt
, &DirContext
.DirEntry
))
599 FoundLong
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.LongNameU
, TRUE
);
600 if (FoundLong
== FALSE
)
602 FoundShort
= RtlEqualUnicodeString(FileToFindU
, &DirContext
.ShortNameU
, TRUE
);
604 if (FoundLong
|| FoundShort
)
606 status
= vfatMakeFCBFromDirEntry (pDeviceExt
,
610 CcUnpinData(Context
);
614 DirContext
.DirIndex
++;
617 return STATUS_OBJECT_NAME_NOT_FOUND
;
621 vfatGetFCBForFile (PDEVICE_EXTENSION pVCB
,
622 PVFATFCB
*pParentFCB
,
624 PUNICODE_STRING pFileNameU
)
629 UNICODE_STRING NameU
;
630 UNICODE_STRING RootNameU
;
631 PWCHAR curr
, prev
, last
;
634 DPRINT ("vfatGetFCBForFile (%x,%x,%x,%wZ)\n",
640 RtlRosInitUnicodeStringFromLiteral(&RootNameU
, L
"\\");
642 // Trivial case, open of the root directory on volume
643 if (RtlEqualUnicodeString(pFileNameU
, &RootNameU
, FALSE
))
645 DPRINT ("returning root FCB\n");
647 FCB
= vfatOpenRootFCB (pVCB
);
651 return (FCB
!= NULL
) ? STATUS_SUCCESS
: STATUS_OBJECT_PATH_NOT_FOUND
;
654 last
= curr
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
655 while (*curr
!= L
'\\' && curr
> pFileNameU
->Buffer
)
660 if (curr
> pFileNameU
->Buffer
)
662 NameU
.Buffer
= pFileNameU
->Buffer
;
663 NameU
.MaximumLength
= NameU
.Length
= (curr
- pFileNameU
->Buffer
) * sizeof(WCHAR
);
664 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
667 Length
= (curr
- pFileNameU
->Buffer
) * sizeof(WCHAR
);
668 if (Length
!= FCB
->PathNameU
.Length
)
670 if (pFileNameU
->Length
+ FCB
->PathNameU
.Length
- Length
> pFileNameU
->MaximumLength
)
672 vfatReleaseFCB (pVCB
, FCB
);
673 return STATUS_OBJECT_NAME_INVALID
;
675 memmove(pFileNameU
->Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
),
676 curr
, pFileNameU
->Length
- Length
);
677 pFileNameU
->Length
+= FCB
->PathNameU
.Length
- Length
;
678 curr
= pFileNameU
->Buffer
+ FCB
->PathNameU
.Length
/ sizeof(WCHAR
);
679 last
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
681 RtlCopyMemory(pFileNameU
->Buffer
, FCB
->PathNameU
.Buffer
, FCB
->PathNameU
.Length
);
691 FCB
= vfatOpenRootFCB(pVCB
);
692 curr
= pFileNameU
->Buffer
;
702 vfatReleaseFCB (pVCB
, parentFCB
);
705 // fail if element in FCB is not a directory
706 if (!vfatFCBIsDirectory (FCB
))
708 DPRINT ("Element in requested path is not a directory\n");
710 vfatReleaseFCB (pVCB
, FCB
);
715 return STATUS_OBJECT_PATH_NOT_FOUND
;
720 Length
= (curr
- prev
) * sizeof(WCHAR
);
721 if (Length
!= parentFCB
->LongNameU
.Length
)
723 if (pFileNameU
->Length
+ parentFCB
->LongNameU
.Length
- Length
> pFileNameU
->MaximumLength
)
725 vfatReleaseFCB (pVCB
, parentFCB
);
726 return STATUS_OBJECT_NAME_INVALID
;
728 memmove(prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
), curr
,
729 pFileNameU
->Length
- (curr
- pFileNameU
->Buffer
) * sizeof(WCHAR
));
730 pFileNameU
->Length
+= parentFCB
->LongNameU
.Length
- Length
;
731 curr
= prev
+ parentFCB
->LongNameU
.Length
/ sizeof(WCHAR
);
732 last
= pFileNameU
->Buffer
+ pFileNameU
->Length
/ sizeof(WCHAR
) - 1;
734 RtlCopyMemory(prev
, parentFCB
->LongNameU
.Buffer
, parentFCB
->LongNameU
.Length
);
738 while (*curr
!= L
'\\' && curr
<= last
)
742 NameU
.Buffer
= pFileNameU
->Buffer
;
743 NameU
.Length
= (curr
- NameU
.Buffer
) * sizeof(WCHAR
);
744 NameU
.MaximumLength
= pFileNameU
->MaximumLength
;
745 DPRINT("%wZ\n", &NameU
);
746 FCB
= vfatGrabFCBFromTable(pVCB
, &NameU
);
750 NameU
.MaximumLength
= NameU
.Length
= (curr
- prev
) * sizeof(WCHAR
);
751 status
= vfatDirFindFile(pVCB
, parentFCB
, &NameU
, &FCB
);
752 if (status
== STATUS_OBJECT_NAME_NOT_FOUND
)
754 *pParentFCB
= parentFCB
;
758 return STATUS_OBJECT_NAME_NOT_FOUND
;
762 return STATUS_OBJECT_PATH_NOT_FOUND
;
765 else if (!NT_SUCCESS (status
))
767 vfatReleaseFCB (pVCB
, parentFCB
);
776 *pParentFCB
= parentFCB
;
779 return STATUS_SUCCESS
;