278ea3ee9dfbd7687a3a29f06c520557e7000d62
[reactos.git] / reactos / drivers / filesystems / ntfs / fcb.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002, 2014 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/fcb.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMERS: Eric Kohl
24 * Pierre Schweitzer (pierre@reactos.org)
25 * Hervé Poussineau (hpoussin@reactos.org)
26 */
27
28 /* INCLUDES *****************************************************************/
29
30 #include "ntfs.h"
31
32 #define NDEBUG
33 #include <debug.h>
34
35 /* FUNCTIONS ****************************************************************/
36
37 static
38 PWCHAR
39 NtfsGetNextPathElement(PWCHAR FileName)
40 {
41 if (*FileName == L'\0')
42 {
43 return NULL;
44 }
45
46 while (*FileName != L'\0' && *FileName != L'\\')
47 {
48 FileName++;
49 }
50
51 return FileName;
52 }
53
54
55 static
56 VOID
57 NtfsWSubString(PWCHAR pTarget,
58 const PWCHAR pSource,
59 size_t pLength)
60 {
61 wcsncpy(pTarget, pSource, pLength);
62 pTarget[pLength] = L'\0';
63 }
64
65
66 PNTFS_FCB
67 NtfsCreateFCB(PCWSTR FileName,
68 PCWSTR Stream,
69 PNTFS_VCB Vcb)
70 {
71 PNTFS_FCB Fcb;
72
73 ASSERT(Vcb);
74 ASSERT(Vcb->Identifier.Type == NTFS_TYPE_VCB);
75
76 Fcb = ExAllocateFromNPagedLookasideList(&NtfsGlobalData->FcbLookasideList);
77 RtlZeroMemory(Fcb, sizeof(NTFS_FCB));
78
79 Fcb->Identifier.Type = NTFS_TYPE_FCB;
80 Fcb->Identifier.Size = sizeof(NTFS_TYPE_FCB);
81
82 Fcb->Vcb = Vcb;
83
84 if (FileName)
85 {
86 wcscpy(Fcb->PathName, FileName);
87 if (wcsrchr(Fcb->PathName, '\\') != 0)
88 {
89 Fcb->ObjectName = wcsrchr(Fcb->PathName, '\\');
90 }
91 else
92 {
93 Fcb->ObjectName = Fcb->PathName;
94 }
95 }
96
97 if (Stream)
98 {
99 wcscpy(Fcb->Stream, Stream);
100 }
101 else
102 {
103 Fcb->Stream[0] = UNICODE_NULL;
104 }
105
106 ExInitializeResourceLite(&Fcb->MainResource);
107
108 Fcb->RFCB.Resource = &(Fcb->MainResource);
109
110 return Fcb;
111 }
112
113
114 VOID
115 NtfsDestroyFCB(PNTFS_FCB Fcb)
116 {
117 ASSERT(Fcb);
118 ASSERT(Fcb->Identifier.Type == NTFS_TYPE_FCB);
119
120 ExDeleteResourceLite(&Fcb->MainResource);
121
122 ExFreeToNPagedLookasideList(&NtfsGlobalData->FcbLookasideList, Fcb);
123 }
124
125
126 BOOLEAN
127 NtfsFCBIsDirectory(PNTFS_FCB Fcb)
128 {
129 return ((Fcb->Entry.FileAttributes & NTFS_FILE_TYPE_DIRECTORY) == NTFS_FILE_TYPE_DIRECTORY);
130 }
131
132
133 BOOLEAN
134 NtfsFCBIsReparsePoint(PNTFS_FCB Fcb)
135 {
136 return ((Fcb->Entry.FileAttributes & NTFS_FILE_TYPE_REPARSE) == NTFS_FILE_TYPE_REPARSE);
137 }
138
139
140 BOOLEAN
141 NtfsFCBIsRoot(PNTFS_FCB Fcb)
142 {
143 return (wcscmp(Fcb->PathName, L"\\") == 0);
144 }
145
146
147 VOID
148 NtfsGrabFCB(PNTFS_VCB Vcb,
149 PNTFS_FCB Fcb)
150 {
151 KIRQL oldIrql;
152
153 DPRINT("grabbing FCB at %p: %S, refCount:%d\n",
154 Fcb,
155 Fcb->PathName,
156 Fcb->RefCount);
157
158 KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
159 Fcb->RefCount++;
160 KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
161 }
162
163
164 VOID
165 NtfsReleaseFCB(PNTFS_VCB Vcb,
166 PNTFS_FCB Fcb)
167 {
168 KIRQL oldIrql;
169
170 DPRINT("releasing FCB at %p: %S, refCount:%d\n",
171 Fcb,
172 Fcb->PathName,
173 Fcb->RefCount);
174
175 KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
176 Fcb->RefCount--;
177 if (Fcb->RefCount <= 0 && !NtfsFCBIsDirectory(Fcb))
178 {
179 RemoveEntryList(&Fcb->FcbListEntry);
180 KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
181 CcUninitializeCacheMap(Fcb->FileObject, NULL, NULL);
182 NtfsDestroyFCB(Fcb);
183 }
184 else
185 {
186 KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
187 }
188 }
189
190
191 VOID
192 NtfsAddFCBToTable(PNTFS_VCB Vcb,
193 PNTFS_FCB Fcb)
194 {
195 KIRQL oldIrql;
196
197 KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
198 Fcb->Vcb = Vcb;
199 InsertTailList(&Vcb->FcbListHead, &Fcb->FcbListEntry);
200 KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
201 }
202
203
204 PNTFS_FCB
205 NtfsGrabFCBFromTable(PNTFS_VCB Vcb,
206 PCWSTR FileName)
207 {
208 KIRQL oldIrql;
209 PNTFS_FCB Fcb;
210 PLIST_ENTRY current_entry;
211
212 KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
213
214 if (FileName == NULL || *FileName == 0)
215 {
216 DPRINT("Return FCB for stream file object\n");
217 Fcb = Vcb->StreamFileObject->FsContext;
218 Fcb->RefCount++;
219 KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
220 return Fcb;
221 }
222
223 current_entry = Vcb->FcbListHead.Flink;
224 while (current_entry != &Vcb->FcbListHead)
225 {
226 Fcb = CONTAINING_RECORD(current_entry, NTFS_FCB, FcbListEntry);
227
228 DPRINT("Comparing '%S' and '%S'\n", FileName, Fcb->PathName);
229 if (_wcsicmp(FileName, Fcb->PathName) == 0)
230 {
231 Fcb->RefCount++;
232 KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
233 return Fcb;
234 }
235
236 //FIXME: need to compare against short name in FCB here
237
238 current_entry = current_entry->Flink;
239 }
240
241 KeReleaseSpinLock(&Vcb->FcbListLock, oldIrql);
242
243 return NULL;
244 }
245
246
247 NTSTATUS
248 NtfsFCBInitializeCache(PNTFS_VCB Vcb,
249 PNTFS_FCB Fcb)
250 {
251 PFILE_OBJECT FileObject;
252 NTSTATUS Status;
253 PNTFS_CCB newCCB;
254
255 FileObject = IoCreateStreamFileObject(NULL, Vcb->StorageDevice);
256
257 newCCB = ExAllocatePoolWithTag(NonPagedPool, sizeof(NTFS_CCB), TAG_CCB);
258 if (newCCB == NULL)
259 {
260 return STATUS_INSUFFICIENT_RESOURCES;
261 }
262
263 RtlZeroMemory(newCCB, sizeof(NTFS_CCB));
264
265 newCCB->Identifier.Type = NTFS_TYPE_CCB;
266 newCCB->Identifier.Size = sizeof(NTFS_TYPE_CCB);
267
268 FileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
269 FileObject->FsContext = Fcb;
270 FileObject->FsContext2 = newCCB;
271 newCCB->PtrFileObject = FileObject;
272 Fcb->FileObject = FileObject;
273 Fcb->Vcb = Vcb;
274
275 Status = STATUS_SUCCESS;
276 _SEH2_TRY
277 {
278 CcInitializeCacheMap(FileObject,
279 (PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize),
280 FALSE,
281 &(NtfsGlobalData->CacheMgrCallbacks),
282 Fcb);
283 }
284 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
285 {
286 FileObject->FsContext2 = NULL;
287 ExFreePoolWithTag(newCCB, TAG_CCB);
288 ObDereferenceObject(FileObject);
289 Fcb->FileObject = NULL;
290 return _SEH2_GetExceptionCode();
291 }
292 _SEH2_END;
293
294 ObDereferenceObject(FileObject);
295 Fcb->Flags |= FCB_CACHE_INITIALIZED;
296
297 return Status;
298 }
299
300
301 PNTFS_FCB
302 NtfsMakeRootFCB(PNTFS_VCB Vcb)
303 {
304 PNTFS_FCB Fcb;
305 PFILE_RECORD_HEADER MftRecord;
306 PFILENAME_ATTRIBUTE FileName;
307
308 MftRecord = ExAllocatePoolWithTag(NonPagedPool,
309 Vcb->NtfsInfo.BytesPerFileRecord,
310 TAG_NTFS);
311 if (MftRecord == NULL)
312 {
313 return NULL;
314 }
315
316 if (!NT_SUCCESS(ReadFileRecord(Vcb, NTFS_FILE_ROOT, MftRecord)))
317 {
318 ExFreePoolWithTag(MftRecord, TAG_NTFS);
319 return NULL;
320 }
321
322 FileName = GetFileNameFromRecord(Vcb, MftRecord, NTFS_FILE_NAME_WIN32);
323 if (!FileName)
324 {
325 ExFreePoolWithTag(MftRecord, TAG_NTFS);
326 return NULL;
327 }
328
329 Fcb = NtfsCreateFCB(L"\\", NULL, Vcb);
330 if (!Fcb)
331 {
332 ExFreePoolWithTag(MftRecord, TAG_NTFS);
333 return NULL;
334 }
335
336 memcpy(&Fcb->Entry, FileName, FIELD_OFFSET(FILENAME_ATTRIBUTE, NameLength));
337 Fcb->Entry.NameType = FileName->NameType;
338 Fcb->Entry.NameLength = 0;
339 Fcb->Entry.Name[0] = UNICODE_NULL;
340 Fcb->RefCount = 1;
341 Fcb->DirIndex = 0;
342 Fcb->RFCB.FileSize.QuadPart = FileName->DataSize;
343 Fcb->RFCB.ValidDataLength.QuadPart = FileName->DataSize;
344 Fcb->RFCB.AllocationSize.QuadPart = FileName->AllocatedSize;
345 Fcb->MFTIndex = NTFS_FILE_ROOT;
346 Fcb->LinkCount = MftRecord->LinkCount;
347
348 NtfsFCBInitializeCache(Vcb, Fcb);
349 NtfsAddFCBToTable(Vcb, Fcb);
350 NtfsGrabFCB(Vcb, Fcb);
351
352 ExFreePoolWithTag(MftRecord, TAG_NTFS);
353
354 return Fcb;
355 }
356
357
358 PNTFS_FCB
359 NtfsOpenRootFCB(PNTFS_VCB Vcb)
360 {
361 PNTFS_FCB Fcb;
362
363 Fcb = NtfsGrabFCBFromTable(Vcb, L"\\");
364 if (Fcb == NULL)
365 {
366 Fcb = NtfsMakeRootFCB(Vcb);
367 }
368
369 return Fcb;
370 }
371
372
373 NTSTATUS
374 NtfsMakeFCBFromDirEntry(PNTFS_VCB Vcb,
375 PNTFS_FCB DirectoryFCB,
376 PUNICODE_STRING Name,
377 PCWSTR Stream,
378 PFILE_RECORD_HEADER Record,
379 ULONGLONG MFTIndex,
380 PNTFS_FCB * fileFCB)
381 {
382 WCHAR pathName[MAX_PATH];
383 PFILENAME_ATTRIBUTE FileName;
384 PSTANDARD_INFORMATION StdInfo;
385 PNTFS_FCB rcFCB;
386 ULONGLONG Size, AllocatedSize;
387
388 DPRINT1("NtfsMakeFCBFromDirEntry(%p, %p, %wZ, %p, %p, %p)\n", Vcb, DirectoryFCB, Name, Stream, Record, fileFCB);
389
390 FileName = GetBestFileNameFromRecord(Vcb, Record);
391 if (!FileName)
392 {
393 return STATUS_OBJECT_NAME_NOT_FOUND; // Not sure that's the best here
394 }
395
396 if (DirectoryFCB && Name)
397 {
398 if (Name->Buffer[0] != 0 && wcslen(DirectoryFCB->PathName) +
399 sizeof(WCHAR) + Name->Length / sizeof(WCHAR) > MAX_PATH)
400 {
401 return STATUS_OBJECT_NAME_INVALID;
402 }
403
404 wcscpy(pathName, DirectoryFCB->PathName);
405 if (!NtfsFCBIsRoot(DirectoryFCB))
406 {
407 wcscat(pathName, L"\\");
408 }
409 wcscat(pathName, Name->Buffer);
410 }
411 else
412 {
413 RtlCopyMemory(pathName, FileName->Name, FileName->NameLength * sizeof (WCHAR));
414 pathName[FileName->NameLength] = UNICODE_NULL;
415 }
416
417 Size = NtfsGetFileSize(Vcb, Record, (Stream ? Stream : L""), (Stream ? wcslen(Stream) : 0), &AllocatedSize);
418
419 rcFCB = NtfsCreateFCB(pathName, Stream, Vcb);
420 if (!rcFCB)
421 {
422 return STATUS_INSUFFICIENT_RESOURCES;
423 }
424
425 memcpy(&rcFCB->Entry, FileName, FIELD_OFFSET(FILENAME_ATTRIBUTE, NameLength));
426 rcFCB->Entry.NameType = FileName->NameType;
427 rcFCB->RFCB.FileSize.QuadPart = Size;
428 rcFCB->RFCB.ValidDataLength.QuadPart = Size;
429 rcFCB->RFCB.AllocationSize.QuadPart = AllocatedSize;
430
431 StdInfo = GetStandardInformationFromRecord(Vcb, Record);
432 if (StdInfo != NULL)
433 {
434 rcFCB->Entry.FileAttributes |= StdInfo->FileAttribute;
435 }
436
437 NtfsFCBInitializeCache(Vcb, rcFCB);
438 rcFCB->RefCount = 1;
439 rcFCB->MFTIndex = MFTIndex;
440 rcFCB->LinkCount = Record->LinkCount;
441 NtfsAddFCBToTable(Vcb, rcFCB);
442 *fileFCB = rcFCB;
443
444 return STATUS_SUCCESS;
445 }
446
447
448 NTSTATUS
449 NtfsAttachFCBToFileObject(PNTFS_VCB Vcb,
450 PNTFS_FCB Fcb,
451 PFILE_OBJECT FileObject)
452 {
453 PNTFS_CCB newCCB;
454
455 newCCB = ExAllocatePoolWithTag(NonPagedPool, sizeof(NTFS_CCB), TAG_CCB);
456 if (newCCB == NULL)
457 {
458 return STATUS_INSUFFICIENT_RESOURCES;
459 }
460
461 RtlZeroMemory(newCCB, sizeof(NTFS_CCB));
462
463 newCCB->Identifier.Type = NTFS_TYPE_CCB;
464 newCCB->Identifier.Size = sizeof(NTFS_TYPE_CCB);
465
466 FileObject->SectionObjectPointer = &Fcb->SectionObjectPointers;
467 FileObject->FsContext = Fcb;
468 FileObject->FsContext2 = newCCB;
469 newCCB->PtrFileObject = FileObject;
470 Fcb->Vcb = Vcb;
471
472 if (!(Fcb->Flags & FCB_CACHE_INITIALIZED))
473 {
474 _SEH2_TRY
475 {
476 CcInitializeCacheMap(FileObject,
477 (PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize),
478 FALSE,
479 &(NtfsGlobalData->CacheMgrCallbacks),
480 Fcb);
481 }
482 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
483 {
484 FileObject->FsContext2 = NULL;
485 ExFreePoolWithTag(newCCB, TAG_CCB);
486 return _SEH2_GetExceptionCode();
487 }
488 _SEH2_END;
489
490 Fcb->Flags |= FCB_CACHE_INITIALIZED;
491 }
492
493 //DPRINT("file open: fcb:%x file size: %d\n", Fcb, Fcb->Entry.DataLengthL);
494
495 return STATUS_SUCCESS;
496 }
497
498
499 static NTSTATUS
500 NtfsDirFindFile(PNTFS_VCB Vcb,
501 PNTFS_FCB DirectoryFcb,
502 PWSTR FileToFind,
503 PNTFS_FCB *FoundFCB)
504 {
505 NTSTATUS Status;
506 ULONGLONG CurrentDir;
507 UNICODE_STRING File;
508 PFILE_RECORD_HEADER FileRecord;
509 ULONGLONG MFTIndex;
510 PWSTR Colon, OldColon;
511 PNTFS_ATTR_CONTEXT DataContext;
512 USHORT Length = 0;
513
514 DPRINT1("NtfsDirFindFile(%p, %p, %S, %p)\n", Vcb, DirectoryFcb, FileToFind, FoundFCB);
515
516 *FoundFCB = NULL;
517 RtlInitUnicodeString(&File, FileToFind);
518 CurrentDir = DirectoryFcb->MFTIndex;
519
520 Colon = wcsrchr(FileToFind, L':');
521 if (Colon != NULL)
522 {
523 Length = File.Length;
524 File.Length = (Colon - FileToFind) * sizeof(WCHAR);
525
526 if (_wcsicmp(Colon + 1, L"$DATA") == 0)
527 {
528 OldColon = Colon;
529 Colon[0] = UNICODE_NULL;
530 Colon = wcsrchr(FileToFind, L':');
531 if (Colon != NULL)
532 {
533 Length = File.Length;
534 File.Length = (Colon - FileToFind) * sizeof(WCHAR);
535 }
536 else
537 {
538 Colon = OldColon;
539 Colon[0] = L':';
540 }
541 }
542
543 /* Skip colon */
544 ++Colon;
545 DPRINT1("Will now look for file '%wZ' with stream '%S'\n", &File, Colon);
546 }
547
548 Status = NtfsLookupFileAt(Vcb, &File, &FileRecord, &MFTIndex, CurrentDir);
549 if (!NT_SUCCESS(Status))
550 {
551 return Status;
552 }
553
554 if (Length != 0)
555 {
556 File.Length = Length;
557 }
558
559 if ((FileRecord->Flags & FRH_DIRECTORY) && Colon != 0)
560 {
561 return STATUS_INVALID_PARAMETER;
562 }
563 else if (Colon != 0)
564 {
565 Status = FindAttribute(Vcb, FileRecord, AttributeData, Colon, wcslen(Colon), &DataContext);
566 if (!NT_SUCCESS(Status))
567 {
568 return STATUS_OBJECT_NAME_NOT_FOUND;
569 }
570 ReleaseAttributeContext(DataContext);
571 }
572
573 Status = NtfsMakeFCBFromDirEntry(Vcb, DirectoryFcb, &File, Colon, FileRecord, MFTIndex, FoundFCB);
574 ExFreePoolWithTag(FileRecord, TAG_NTFS);
575
576 return Status;
577 }
578
579
580 NTSTATUS
581 NtfsGetFCBForFile(PNTFS_VCB Vcb,
582 PNTFS_FCB *pParentFCB,
583 PNTFS_FCB *pFCB,
584 const PWSTR pFileName)
585 {
586 NTSTATUS Status;
587 WCHAR pathName [MAX_PATH];
588 WCHAR elementName [MAX_PATH];
589 PWCHAR currentElement;
590 PNTFS_FCB FCB;
591 PNTFS_FCB parentFCB;
592
593 DPRINT("NtfsGetFCBForFile(%p, %p, %p, '%S')\n",
594 Vcb,
595 pParentFCB,
596 pFCB,
597 pFileName);
598
599 /* Dummy code */
600 // FCB = NtfsOpenRootFCB(Vcb);
601 // *pFCB = FCB;
602 // *pParentFCB = NULL;
603
604 #if 1
605 /* Trivial case, open of the root directory on volume */
606 if (pFileName [0] == L'\0' || wcscmp(pFileName, L"\\") == 0)
607 {
608 DPRINT("returning root FCB\n");
609
610 FCB = NtfsOpenRootFCB(Vcb);
611 *pFCB = FCB;
612 *pParentFCB = NULL;
613
614 return (FCB != NULL) ? STATUS_SUCCESS : STATUS_OBJECT_PATH_NOT_FOUND;
615 }
616 else
617 {
618 currentElement = pFileName + 1;
619 wcscpy (pathName, L"\\");
620 FCB = NtfsOpenRootFCB (Vcb);
621 }
622
623 parentFCB = NULL;
624
625 /* Parse filename and check each path element for existance and access */
626 while (NtfsGetNextPathElement(currentElement) != 0)
627 {
628 /* Skip blank directory levels */
629 if ((NtfsGetNextPathElement(currentElement) - currentElement) == 0)
630 {
631 currentElement++;
632 continue;
633 }
634
635 DPRINT("Parsing, currentElement:%S\n", currentElement);
636 DPRINT(" parentFCB:%p FCB:%p\n", parentFCB, FCB);
637
638 /* Descend to next directory level */
639 if (parentFCB)
640 {
641 NtfsReleaseFCB(Vcb, parentFCB);
642 parentFCB = NULL;
643 }
644
645 /* fail if element in FCB is not a directory */
646 if (!NtfsFCBIsDirectory(FCB))
647 {
648 DPRINT("Element in requested path is not a directory\n");
649
650 NtfsReleaseFCB(Vcb, FCB);
651 FCB = 0;
652 *pParentFCB = NULL;
653 *pFCB = NULL;
654
655 return STATUS_OBJECT_PATH_NOT_FOUND;
656 }
657
658 parentFCB = FCB;
659
660 /* Extract next directory level into dirName */
661 NtfsWSubString(pathName,
662 pFileName,
663 NtfsGetNextPathElement(currentElement) - pFileName);
664 DPRINT(" pathName:%S\n", pathName);
665
666 FCB = NtfsGrabFCBFromTable(Vcb, pathName);
667 if (FCB == NULL)
668 {
669 NtfsWSubString(elementName,
670 currentElement,
671 NtfsGetNextPathElement(currentElement) - currentElement);
672 DPRINT(" elementName:%S\n", elementName);
673
674 Status = NtfsDirFindFile(Vcb, parentFCB, elementName, &FCB);
675 if (Status == STATUS_OBJECT_NAME_NOT_FOUND)
676 {
677 *pParentFCB = parentFCB;
678 *pFCB = NULL;
679 currentElement = NtfsGetNextPathElement(currentElement);
680 if (*currentElement == L'\0' || NtfsGetNextPathElement(currentElement + 1) == 0)
681 {
682 return STATUS_OBJECT_NAME_NOT_FOUND;
683 }
684 else
685 {
686 return STATUS_OBJECT_PATH_NOT_FOUND;
687 }
688 }
689 else if (!NT_SUCCESS(Status))
690 {
691 NtfsReleaseFCB(Vcb, parentFCB);
692 *pParentFCB = NULL;
693 *pFCB = NULL;
694
695 return Status;
696 }
697 }
698
699 currentElement = NtfsGetNextPathElement(currentElement);
700 }
701
702 *pParentFCB = parentFCB;
703 *pFCB = FCB;
704 #endif
705
706 return STATUS_SUCCESS;
707 }
708
709
710 NTSTATUS
711 NtfsReadFCBAttribute(PNTFS_VCB Vcb,
712 PNTFS_FCB pFCB,
713 ULONG Type,
714 PCWSTR Name,
715 ULONG NameLength,
716 PVOID * Data)
717 {
718 NTSTATUS Status;
719 PFILE_RECORD_HEADER FileRecord;
720 PNTFS_ATTR_CONTEXT AttrCtxt;
721 ULONGLONG AttrLength;
722
723 FileRecord = ExAllocatePoolWithTag(NonPagedPool,
724 Vcb->NtfsInfo.BytesPerFileRecord,
725 TAG_NTFS);
726 if (FileRecord == NULL)
727 {
728 return STATUS_INSUFFICIENT_RESOURCES;
729 }
730
731 Status = ReadFileRecord(Vcb, pFCB->MFTIndex, FileRecord);
732 if (!NT_SUCCESS(Status))
733 {
734 ExFreePoolWithTag(FileRecord, TAG_NTFS);
735 return Status;
736 }
737
738 Status = FindAttribute(Vcb, FileRecord, Type, Name, NameLength, &AttrCtxt);
739 if (!NT_SUCCESS(Status))
740 {
741 ExFreePoolWithTag(FileRecord, TAG_NTFS);
742 return Status;
743 }
744
745 AttrLength = AttributeDataLength(&AttrCtxt->Record);
746 *Data = ExAllocatePoolWithTag(NonPagedPool, AttrLength, TAG_NTFS);
747 if (*Data == NULL)
748 {
749 ReleaseAttributeContext(AttrCtxt);
750 ExFreePoolWithTag(FileRecord, TAG_NTFS);
751 return STATUS_INSUFFICIENT_RESOURCES;
752 }
753
754 ReadAttribute(Vcb, AttrCtxt, 0, *Data, AttrLength);
755
756 ReleaseAttributeContext(AttrCtxt);
757 ExFreePoolWithTag(FileRecord, TAG_NTFS);
758
759 return STATUS_SUCCESS;
760 }
761
762 /* EOF */