3 * Copyright (C) 2002, 2014 ReactOS Team
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.
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.
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.
19 * COPYRIGHT: See COPYING in the top level directory
20 * PROJECT: ReactOS kernel
21 * FILE: drivers/filesystem/ntfs/mft.c
22 * PURPOSE: NTFS filesystem driver
23 * PROGRAMMERS: Eric Kohl
25 * Pierre Schweitzer (pierre@reactos.org)
26 * Hervé Poussineau (hpoussin@reactos.org)
30 /* INCLUDES *****************************************************************/
38 /* FUNCTIONS ****************************************************************/
41 PrepareAttributeContext(PNTFS_ATTR_RECORD AttrRecord
)
43 PNTFS_ATTR_CONTEXT Context
;
45 Context
= ExAllocatePoolWithTag(NonPagedPool
,
46 FIELD_OFFSET(NTFS_ATTR_CONTEXT
, Record
) + AttrRecord
->Length
,
48 RtlCopyMemory(&Context
->Record
, AttrRecord
, AttrRecord
->Length
);
49 if (AttrRecord
->IsNonResident
)
51 LONGLONG DataRunOffset
;
52 ULONGLONG DataRunLength
;
54 Context
->CacheRun
= (PUCHAR
)&Context
->Record
+ Context
->Record
.NonResident
.MappingPairsOffset
;
55 Context
->CacheRunOffset
= 0;
56 Context
->CacheRun
= DecodeRun(Context
->CacheRun
, &DataRunOffset
, &DataRunLength
);
57 Context
->CacheRunLength
= DataRunLength
;
58 if (DataRunOffset
!= -1)
61 Context
->CacheRunStartLCN
=
62 Context
->CacheRunLastLCN
= DataRunOffset
;
67 Context
->CacheRunStartLCN
= -1;
68 Context
->CacheRunLastLCN
= 0;
70 Context
->CacheRunCurrentOffset
= 0;
78 ReleaseAttributeContext(PNTFS_ATTR_CONTEXT Context
)
80 ExFreePoolWithTag(Context
, TAG_NTFS
);
88 * Searches a file record for an attribute matching the given type and name.
91 * Optional pointer to a ULONG that will receive the offset of the found attribute
92 * from the beginning of the record. Can be set to NULL.
95 FindAttribute(PDEVICE_EXTENSION Vcb
,
96 PFILE_RECORD_HEADER MftRecord
,
100 PNTFS_ATTR_CONTEXT
* AttrCtx
,
105 FIND_ATTR_CONTXT Context
;
106 PNTFS_ATTR_RECORD Attribute
;
108 DPRINT("FindAttribute(%p, %p, 0x%x, %S, %u, %p)\n", Vcb
, MftRecord
, Type
, Name
, NameLength
, AttrCtx
);
111 Status
= FindFirstAttribute(&Context
, Vcb
, MftRecord
, FALSE
, &Attribute
);
112 while (NT_SUCCESS(Status
))
114 if (Attribute
->Type
== Type
&& Attribute
->NameLength
== NameLength
)
120 AttrName
= (PWCHAR
)((PCHAR
)Attribute
+ Attribute
->NameOffset
);
121 DPRINT("%.*S, %.*S\n", Attribute
->NameLength
, AttrName
, NameLength
, Name
);
122 if (RtlCompareMemory(AttrName
, Name
, NameLength
<< 1) == (NameLength
<< 1))
134 /* Found it, fill up the context and return. */
135 DPRINT("Found context\n");
136 *AttrCtx
= PrepareAttributeContext(Attribute
);
139 *Offset
= Context
.Offset
;
141 FindCloseAttribute(&Context
);
142 return STATUS_SUCCESS
;
146 Status
= FindNextAttribute(&Context
, &Attribute
);
149 FindCloseAttribute(&Context
);
150 return STATUS_OBJECT_NAME_NOT_FOUND
;
155 AttributeAllocatedLength(PNTFS_ATTR_RECORD AttrRecord
)
157 if (AttrRecord
->IsNonResident
)
158 return AttrRecord
->NonResident
.AllocatedSize
;
160 return AttrRecord
->Resident
.ValueLength
;
165 AttributeDataLength(PNTFS_ATTR_RECORD AttrRecord
)
167 if (AttrRecord
->IsNonResident
)
168 return AttrRecord
->NonResident
.DataSize
;
170 return AttrRecord
->Resident
.ValueLength
;
175 SetAttributeDataLength(PFILE_OBJECT FileObject
,
177 PNTFS_ATTR_CONTEXT AttrContext
,
179 PFILE_RECORD_HEADER FileRecord
,
180 PLARGE_INTEGER DataSize
)
182 if (AttrContext
->Record
.IsNonResident
)
184 // do we need to increase the allocation size?
185 if (AttrContext
->Record
.NonResident
.AllocatedSize
< DataSize
->QuadPart
)
187 DPRINT1("FixMe: Increasing allocation size is unimplemented!\n");
188 return STATUS_NOT_IMPLEMENTED
;
191 // TODO: is the file compressed, encrypted, or sparse?
193 // NOTE: we need to have acquired the main resource exclusively, as well as(?) the PagingIoResource
195 // TODO: update the allocated size on-disk
196 DPRINT("Allocated Size: %I64u\n", AttrContext
->Record
.NonResident
.AllocatedSize
);
198 AttrContext
->Record
.NonResident
.DataSize
= DataSize
->QuadPart
;
199 AttrContext
->Record
.NonResident
.InitializedSize
= DataSize
->QuadPart
;
201 Fcb
->RFCB
.FileSize
= *DataSize
;
202 Fcb
->RFCB
.ValidDataLength
= *DataSize
;
204 DPRINT("Data Size: %I64u\n", Fcb
->RFCB
.FileSize
.QuadPart
);
206 //NtfsDumpFileAttributes(Fcb->Vcb, FileRecord);
208 // copy the attribute back into the FileRecord
209 RtlCopyMemory((PCHAR
)FileRecord
+ AttrOffset
, &AttrContext
->Record
, AttrContext
->Record
.Length
);
211 //NtfsDumpFileAttributes(Fcb->Vcb, FileRecord);
213 // write the updated file record back to disk
214 UpdateFileRecord(Fcb
->Vcb
, Fcb
->MFTIndex
, FileRecord
);
216 CcSetFileSizes(FileObject
, (PCC_FILE_SIZES
)&Fcb
->RFCB
.AllocationSize
);
220 // we can't yet handle resident attributes
221 DPRINT1("FixMe: Can't handle increasing length of resident attribute\n");
222 return STATUS_NOT_IMPLEMENTED
;
225 return STATUS_SUCCESS
;
229 ReadAttribute(PDEVICE_EXTENSION Vcb
,
230 PNTFS_ATTR_CONTEXT Context
,
237 LONGLONG DataRunOffset
;
238 ULONGLONG DataRunLength
;
239 LONGLONG DataRunStartLCN
;
240 ULONGLONG CurrentOffset
;
245 if (!Context
->Record
.IsNonResident
)
247 if (Offset
> Context
->Record
.Resident
.ValueLength
)
249 if (Offset
+ Length
> Context
->Record
.Resident
.ValueLength
)
250 Length
= (ULONG
)(Context
->Record
.Resident
.ValueLength
- Offset
);
251 RtlCopyMemory(Buffer
, (PCHAR
)&Context
->Record
+ Context
->Record
.Resident
.ValueOffset
+ Offset
, Length
);
256 * Non-resident attribute
260 * I. Find the corresponding start data run.
265 // FIXME: Cache seems to be non-working. Disable it for now
266 //if(Context->CacheRunOffset <= Offset && Offset < Context->CacheRunOffset + Context->CacheRunLength * Volume->ClusterSize)
269 DataRun
= Context
->CacheRun
;
270 LastLCN
= Context
->CacheRunLastLCN
;
271 DataRunStartLCN
= Context
->CacheRunStartLCN
;
272 DataRunLength
= Context
->CacheRunLength
;
273 CurrentOffset
= Context
->CacheRunCurrentOffset
;
278 DataRun
= (PUCHAR
)&Context
->Record
+ Context
->Record
.NonResident
.MappingPairsOffset
;
283 DataRun
= DecodeRun(DataRun
, &DataRunOffset
, &DataRunLength
);
284 if (DataRunOffset
!= -1)
286 /* Normal data run. */
287 DataRunStartLCN
= LastLCN
+ DataRunOffset
;
288 LastLCN
= DataRunStartLCN
;
292 /* Sparse data run. */
293 DataRunStartLCN
= -1;
296 if (Offset
>= CurrentOffset
&&
297 Offset
< CurrentOffset
+ (DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
))
307 CurrentOffset
+= DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
;
312 * II. Go through the run list and read the data
315 ReadLength
= (ULONG
)min(DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
- (Offset
- CurrentOffset
), Length
);
316 if (DataRunStartLCN
== -1)
318 RtlZeroMemory(Buffer
, ReadLength
);
319 Status
= STATUS_SUCCESS
;
323 Status
= NtfsReadDisk(Vcb
->StorageDevice
,
324 DataRunStartLCN
* Vcb
->NtfsInfo
.BytesPerCluster
+ Offset
- CurrentOffset
,
326 Vcb
->NtfsInfo
.BytesPerSector
,
330 if (NT_SUCCESS(Status
))
332 Length
-= ReadLength
;
333 Buffer
+= ReadLength
;
334 AlreadyRead
+= ReadLength
;
336 if (ReadLength
== DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
- (Offset
- CurrentOffset
))
338 CurrentOffset
+= DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
;
339 DataRun
= DecodeRun(DataRun
, &DataRunOffset
, &DataRunLength
);
340 if (DataRunOffset
!= (ULONGLONG
)-1)
342 DataRunStartLCN
= LastLCN
+ DataRunOffset
;
343 LastLCN
= DataRunStartLCN
;
346 DataRunStartLCN
= -1;
351 ReadLength
= (ULONG
)min(DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
, Length
);
352 if (DataRunStartLCN
== -1)
353 RtlZeroMemory(Buffer
, ReadLength
);
356 Status
= NtfsReadDisk(Vcb
->StorageDevice
,
357 DataRunStartLCN
* Vcb
->NtfsInfo
.BytesPerCluster
,
359 Vcb
->NtfsInfo
.BytesPerSector
,
362 if (!NT_SUCCESS(Status
))
366 Length
-= ReadLength
;
367 Buffer
+= ReadLength
;
368 AlreadyRead
+= ReadLength
;
370 /* We finished this request, but there still data in this data run. */
371 if (Length
== 0 && ReadLength
!= DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
)
375 * Go to next run in the list.
380 CurrentOffset
+= DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
;
381 DataRun
= DecodeRun(DataRun
, &DataRunOffset
, &DataRunLength
);
382 if (DataRunOffset
!= -1)
384 /* Normal data run. */
385 DataRunStartLCN
= LastLCN
+ DataRunOffset
;
386 LastLCN
= DataRunStartLCN
;
390 /* Sparse data run. */
391 DataRunStartLCN
= -1;
397 Context
->CacheRun
= DataRun
;
398 Context
->CacheRunOffset
= Offset
+ AlreadyRead
;
399 Context
->CacheRunStartLCN
= DataRunStartLCN
;
400 Context
->CacheRunLength
= DataRunLength
;
401 Context
->CacheRunLastLCN
= LastLCN
;
402 Context
->CacheRunCurrentOffset
= CurrentOffset
;
409 * @name WriteAttribute
412 * Writes an NTFS attribute to the disk. It presently borrows a lot of code from ReadAttribute(),
413 * and it still needs more documentation / cleaning up.
416 * Volume Control Block indicating which volume to write the attribute to
419 * Pointer to an NTFS_ATTR_CONTEXT that has information about the attribute
422 * Offset, in bytes, from the beginning of the attribute indicating where to start
426 * The data that's being written to the device
429 * How much data will be written, in bytes
431 * @param RealLengthWritten
432 * Pointer to a ULONG which will receive how much data was written, in bytes
435 * STATUS_SUCCESS if successful, an error code otherwise. STATUS_NOT_IMPLEMENTED if
436 * writing to a sparse file.
438 * @remarks Note that in this context the word "attribute" isn't referring read-only, hidden,
439 * etc. - the file's data is actually stored in an attribute in NTFS parlance.
444 WriteAttribute(PDEVICE_EXTENSION Vcb
,
445 PNTFS_ATTR_CONTEXT Context
,
449 PULONG RealLengthWritten
)
453 LONGLONG DataRunOffset
;
454 ULONGLONG DataRunLength
;
455 LONGLONG DataRunStartLCN
;
456 ULONGLONG CurrentOffset
;
459 PUCHAR SourceBuffer
= Buffer
;
460 LONGLONG StartingOffset
;
462 DPRINT("WriteAttribute(%p, %p, %I64U, %p, %lu)\n", Vcb
, Context
, Offset
, Buffer
, Length
);
464 // is this a resident attribute?
465 if (!Context
->Record
.IsNonResident
)
467 DPRINT1("FIXME: Writing to resident NTFS records (small files) is not supported at this time.\n");
468 // (TODO: This should be really easy to implement)
470 /* LeftOver code from ReadAttribute(), may be helpful:
471 if (Offset > Context->Record.Resident.ValueLength)
473 if (Offset + Length > Context->Record.Resident.ValueLength)
474 Length = (ULONG)(Context->Record.Resident.ValueLength - Offset);
475 RtlCopyMemory(Buffer, (PCHAR)&Context->Record + Context->Record.Resident.ValueOffset + Offset, Length);
478 return STATUS_NOT_IMPLEMENTED
; // until we implement it
481 // This is a non-resident attribute.
483 // I. Find the corresponding start data run.
485 *RealLengthWritten
= 0;
487 // FIXME: Cache seems to be non-working. Disable it for now
488 //if(Context->CacheRunOffset <= Offset && Offset < Context->CacheRunOffset + Context->CacheRunLength * Volume->ClusterSize)
491 DataRun = Context->CacheRun;
492 LastLCN = Context->CacheRunLastLCN;
493 DataRunStartLCN = Context->CacheRunStartLCN;
494 DataRunLength = Context->CacheRunLength;
495 CurrentOffset = Context->CacheRunCurrentOffset;
500 DataRun
= (PUCHAR
)&Context
->Record
+ Context
->Record
.NonResident
.MappingPairsOffset
;
505 DataRun
= DecodeRun(DataRun
, &DataRunOffset
, &DataRunLength
);
506 if (DataRunOffset
!= -1)
509 // DPRINT1("Writing to normal data run, LastLCN %I64u DataRunOffset %I64d\n", LastLCN, DataRunOffset);
510 DataRunStartLCN
= LastLCN
+ DataRunOffset
;
511 LastLCN
= DataRunStartLCN
;
515 // Sparse data run. We can't support writing to sparse files yet
516 // (it may require increasing the allocation size).
517 DataRunStartLCN
= -1;
518 DPRINT1("FIXME: Writing to sparse files is not supported yet!\n");
519 return STATUS_NOT_IMPLEMENTED
;
522 // Have we reached the data run we're trying to write to?
523 if (Offset
>= CurrentOffset
&&
524 Offset
< CurrentOffset
+ (DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
))
531 // We reached the last assigned cluster
532 // TODO: assign new clusters to the end of the file.
533 // (Presently, this code will never be reached, the write should have already failed by now)
534 return STATUS_END_OF_FILE
;
537 CurrentOffset
+= DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
;
541 // II. Go through the run list and write the data
543 /* REVIEWME -- As adapted from NtfsReadAttribute():
544 We seem to be making a special case for the first applicable data run, but I'm not sure why.
545 Does it have something to do with (not) caching? Is this strategy equally applicable to writing? */
547 WriteLength
= (ULONG
)min(DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
- (Offset
- CurrentOffset
), Length
);
549 StartingOffset
= DataRunStartLCN
* Vcb
->NtfsInfo
.BytesPerCluster
+ Offset
- CurrentOffset
;
551 // Write the data to the disk
552 Status
= NtfsWriteDisk(Vcb
->StorageDevice
,
555 Vcb
->NtfsInfo
.BytesPerSector
,
556 (PVOID
)SourceBuffer
);
558 // Did the write fail?
559 if (!NT_SUCCESS(Status
))
561 Context
->CacheRun
= DataRun
;
562 Context
->CacheRunOffset
= Offset
;
563 Context
->CacheRunStartLCN
= DataRunStartLCN
;
564 Context
->CacheRunLength
= DataRunLength
;
565 Context
->CacheRunLastLCN
= LastLCN
;
566 Context
->CacheRunCurrentOffset
= CurrentOffset
;
571 Length
-= WriteLength
;
572 SourceBuffer
+= WriteLength
;
573 *RealLengthWritten
+= WriteLength
;
575 // Did we write to the end of the data run?
576 if (WriteLength
== DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
- (Offset
- CurrentOffset
))
578 // Advance to the next data run
579 CurrentOffset
+= DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
;
580 DataRun
= DecodeRun(DataRun
, &DataRunOffset
, &DataRunLength
);
582 if (DataRunOffset
!= (ULONGLONG
)-1)
584 DataRunStartLCN
= LastLCN
+ DataRunOffset
;
585 LastLCN
= DataRunStartLCN
;
588 DataRunStartLCN
= -1;
591 // Do we have more data to write?
594 // Make sure we don't write past the end of the current data run
595 WriteLength
= (ULONG
)min(DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
, Length
);
597 // Are we dealing with a sparse data run?
598 if (DataRunStartLCN
== -1)
600 DPRINT1("FIXME: Don't know how to write to sparse files yet! (DataRunStartLCN == -1)\n");
601 return STATUS_NOT_IMPLEMENTED
;
605 // write the data to the disk
606 Status
= NtfsWriteDisk(Vcb
->StorageDevice
,
607 DataRunStartLCN
* Vcb
->NtfsInfo
.BytesPerCluster
,
609 Vcb
->NtfsInfo
.BytesPerSector
,
610 (PVOID
)SourceBuffer
);
611 if (!NT_SUCCESS(Status
))
615 Length
-= WriteLength
;
616 SourceBuffer
+= WriteLength
;
617 *RealLengthWritten
+= WriteLength
;
619 // We finished this request, but there's still data in this data run.
620 if (Length
== 0 && WriteLength
!= DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
)
623 // Go to next run in the list.
627 // that was the last run
630 // Failed sanity check.
631 DPRINT1("Encountered EOF before expected!\n");
632 return STATUS_END_OF_FILE
;
638 // Advance to the next data run
639 CurrentOffset
+= DataRunLength
* Vcb
->NtfsInfo
.BytesPerCluster
;
640 DataRun
= DecodeRun(DataRun
, &DataRunOffset
, &DataRunLength
);
641 if (DataRunOffset
!= -1)
644 DataRunStartLCN
= LastLCN
+ DataRunOffset
;
645 LastLCN
= DataRunStartLCN
;
650 DataRunStartLCN
= -1;
652 } // end while (Length > 0) [more data to write]
654 Context
->CacheRun
= DataRun
;
655 Context
->CacheRunOffset
= Offset
+ *RealLengthWritten
;
656 Context
->CacheRunStartLCN
= DataRunStartLCN
;
657 Context
->CacheRunLength
= DataRunLength
;
658 Context
->CacheRunLastLCN
= LastLCN
;
659 Context
->CacheRunCurrentOffset
= CurrentOffset
;
665 ReadFileRecord(PDEVICE_EXTENSION Vcb
,
667 PFILE_RECORD_HEADER file
)
671 DPRINT("ReadFileRecord(%p, %I64x, %p)\n", Vcb
, index
, file
);
673 BytesRead
= ReadAttribute(Vcb
, Vcb
->MFTContext
, index
* Vcb
->NtfsInfo
.BytesPerFileRecord
, (PCHAR
)file
, Vcb
->NtfsInfo
.BytesPerFileRecord
);
674 if (BytesRead
!= Vcb
->NtfsInfo
.BytesPerFileRecord
)
676 DPRINT1("ReadFileRecord failed: %I64u read, %u expected\n", BytesRead
, Vcb
->NtfsInfo
.BytesPerFileRecord
);
677 return STATUS_PARTIAL_COPY
;
680 /* Apply update sequence array fixups. */
681 return FixupUpdateSequenceArray(Vcb
, &file
->Ntfs
);
686 * Searches a file's parent directory (given the parent's index in the mft)
687 * for the given file. Upon finding an index entry for that file, updates
688 * Data Size and Allocated Size values in the $FILE_NAME attribute of that entry.
690 * (Most of this code was copied from NtfsFindMftRecord)
693 UpdateFileNameRecord(PDEVICE_EXTENSION Vcb
,
694 ULONGLONG ParentMFTIndex
,
695 PUNICODE_STRING FileName
,
697 ULONGLONG NewDataSize
,
698 ULONGLONG NewAllocationSize
)
700 PFILE_RECORD_HEADER MftRecord
;
701 PNTFS_ATTR_CONTEXT IndexRootCtx
;
702 PINDEX_ROOT_ATTRIBUTE IndexRoot
;
704 PINDEX_ENTRY_ATTRIBUTE IndexEntry
, IndexEntryEnd
;
706 ULONG CurrentEntry
= 0;
708 DPRINT("UpdateFileNameRecord(%p, %I64d, %wZ, %u, %I64u, %I64u)\n", Vcb
, ParentMFTIndex
, FileName
, DirSearch
, NewDataSize
, NewAllocationSize
);
710 MftRecord
= ExAllocatePoolWithTag(NonPagedPool
,
711 Vcb
->NtfsInfo
.BytesPerFileRecord
,
713 if (MftRecord
== NULL
)
715 return STATUS_INSUFFICIENT_RESOURCES
;
718 Status
= ReadFileRecord(Vcb
, ParentMFTIndex
, MftRecord
);
719 if (!NT_SUCCESS(Status
))
721 ExFreePoolWithTag(MftRecord
, TAG_NTFS
);
725 ASSERT(MftRecord
->Ntfs
.Type
== NRH_FILE_TYPE
);
726 Status
= FindAttribute(Vcb
, MftRecord
, AttributeIndexRoot
, L
"$I30", 4, &IndexRootCtx
, NULL
);
727 if (!NT_SUCCESS(Status
))
729 ExFreePoolWithTag(MftRecord
, TAG_NTFS
);
733 IndexRecord
= ExAllocatePoolWithTag(NonPagedPool
, Vcb
->NtfsInfo
.BytesPerIndexRecord
, TAG_NTFS
);
734 if (IndexRecord
== NULL
)
736 ReleaseAttributeContext(IndexRootCtx
);
737 ExFreePoolWithTag(MftRecord
, TAG_NTFS
);
738 return STATUS_INSUFFICIENT_RESOURCES
;
741 ReadAttribute(Vcb
, IndexRootCtx
, 0, IndexRecord
, Vcb
->NtfsInfo
.BytesPerIndexRecord
);
742 IndexRoot
= (PINDEX_ROOT_ATTRIBUTE
)IndexRecord
;
743 IndexEntry
= (PINDEX_ENTRY_ATTRIBUTE
)((PCHAR
)&IndexRoot
->Header
+ IndexRoot
->Header
.FirstEntryOffset
);
744 // Index root is always resident.
745 IndexEntryEnd
= (PINDEX_ENTRY_ATTRIBUTE
)(IndexRecord
+ IndexRoot
->Header
.TotalSizeOfEntries
);
747 DPRINT("IndexRecordSize: %x IndexBlockSize: %x\n", Vcb
->NtfsInfo
.BytesPerIndexRecord
, IndexRoot
->SizeOfEntry
);
749 Status
= UpdateIndexEntryFileNameSize(Vcb
,
752 IndexRoot
->SizeOfEntry
,
762 ReleaseAttributeContext(IndexRootCtx
);
763 ExFreePoolWithTag(IndexRecord
, TAG_NTFS
);
764 ExFreePoolWithTag(MftRecord
, TAG_NTFS
);
770 * Recursively searches directory index and applies the size update to the $FILE_NAME attribute of the
771 * proper index entry.
772 * (Heavily based on BrowseIndexEntries)
775 UpdateIndexEntryFileNameSize(PDEVICE_EXTENSION Vcb
,
776 PFILE_RECORD_HEADER MftRecord
,
778 ULONG IndexBlockSize
,
779 PINDEX_ENTRY_ATTRIBUTE FirstEntry
,
780 PINDEX_ENTRY_ATTRIBUTE LastEntry
,
781 PUNICODE_STRING FileName
,
785 ULONGLONG NewDataSize
,
786 ULONGLONG NewAllocatedSize
)
790 PINDEX_ENTRY_ATTRIBUTE IndexEntry
;
791 PNTFS_ATTR_CONTEXT IndexAllocationCtx
;
792 ULONGLONG IndexAllocationSize
;
793 PINDEX_BUFFER IndexBuffer
;
795 DPRINT("UpdateIndexEntrySize(%p, %p, %p, %u, %p, %p, %wZ, %u, %u, %u, %I64u, %I64u)\n", Vcb
, MftRecord
, IndexRecord
, IndexBlockSize
, FirstEntry
, LastEntry
, FileName
, *StartEntry
, *CurrentEntry
, DirSearch
, NewDataSize
, NewAllocatedSize
);
797 // find the index entry responsible for the file we're trying to update
798 IndexEntry
= FirstEntry
;
799 while (IndexEntry
< LastEntry
&&
800 !(IndexEntry
->Flags
& NTFS_INDEX_ENTRY_END
))
802 if ((IndexEntry
->Data
.Directory
.IndexedFile
& NTFS_MFT_MASK
) > 0x10 &&
803 *CurrentEntry
>= *StartEntry
&&
804 IndexEntry
->FileName
.NameType
!= NTFS_FILE_NAME_DOS
&&
805 CompareFileName(FileName
, IndexEntry
, DirSearch
))
807 *StartEntry
= *CurrentEntry
;
808 IndexEntry
->FileName
.DataSize
= NewDataSize
;
809 IndexEntry
->FileName
.AllocatedSize
= NewAllocatedSize
;
810 // indicate that the caller will still need to write the structure to the disk
811 return STATUS_PENDING
;
814 (*CurrentEntry
) += 1;
815 ASSERT(IndexEntry
->Length
>= sizeof(INDEX_ENTRY_ATTRIBUTE
));
816 IndexEntry
= (PINDEX_ENTRY_ATTRIBUTE
)((PCHAR
)IndexEntry
+ IndexEntry
->Length
);
819 /* If we're already browsing a subnode */
820 if (IndexRecord
== NULL
)
822 return STATUS_OBJECT_PATH_NOT_FOUND
;
825 /* If there's no subnode */
826 if (!(IndexEntry
->Flags
& NTFS_INDEX_ENTRY_NODE
))
828 return STATUS_OBJECT_PATH_NOT_FOUND
;
831 Status
= FindAttribute(Vcb
, MftRecord
, AttributeIndexAllocation
, L
"$I30", 4, &IndexAllocationCtx
, NULL
);
832 if (!NT_SUCCESS(Status
))
834 DPRINT("Corrupted filesystem!\n");
838 IndexAllocationSize
= AttributeDataLength(&IndexAllocationCtx
->Record
);
839 Status
= STATUS_OBJECT_PATH_NOT_FOUND
;
840 for (RecordOffset
= 0; RecordOffset
< IndexAllocationSize
; RecordOffset
+= IndexBlockSize
)
842 ReadAttribute(Vcb
, IndexAllocationCtx
, RecordOffset
, IndexRecord
, IndexBlockSize
);
843 Status
= FixupUpdateSequenceArray(Vcb
, &((PFILE_RECORD_HEADER
)IndexRecord
)->Ntfs
);
844 if (!NT_SUCCESS(Status
))
849 IndexBuffer
= (PINDEX_BUFFER
)IndexRecord
;
850 ASSERT(IndexBuffer
->Ntfs
.Type
== NRH_INDX_TYPE
);
851 ASSERT(IndexBuffer
->Header
.AllocatedSize
+ FIELD_OFFSET(INDEX_BUFFER
, Header
) == IndexBlockSize
);
852 FirstEntry
= (PINDEX_ENTRY_ATTRIBUTE
)((ULONG_PTR
)&IndexBuffer
->Header
+ IndexBuffer
->Header
.FirstEntryOffset
);
853 LastEntry
= (PINDEX_ENTRY_ATTRIBUTE
)((ULONG_PTR
)&IndexBuffer
->Header
+ IndexBuffer
->Header
.TotalSizeOfEntries
);
854 ASSERT(LastEntry
<= (PINDEX_ENTRY_ATTRIBUTE
)((ULONG_PTR
)IndexBuffer
+ IndexBlockSize
));
856 Status
= UpdateIndexEntryFileNameSize(NULL
, NULL
, NULL
, 0, FirstEntry
, LastEntry
, FileName
, StartEntry
, CurrentEntry
, DirSearch
, NewDataSize
, NewAllocatedSize
);
857 if (Status
== STATUS_PENDING
)
859 // write the index record back to disk
862 // first we need to update the fixup values for the index block
863 Status
= AddFixupArray(Vcb
, &((PFILE_RECORD_HEADER
)IndexRecord
)->Ntfs
);
864 if (!NT_SUCCESS(Status
))
866 DPRINT1("Error: Failed to update fixup sequence array!\n");
870 Status
= WriteAttribute(Vcb
, IndexAllocationCtx
, RecordOffset
, (const PUCHAR
)IndexRecord
, IndexBlockSize
, &Written
);
871 if (!NT_SUCCESS(Status
))
873 DPRINT1("ERROR Performing write!\n");
877 Status
= STATUS_SUCCESS
;
880 if (NT_SUCCESS(Status
))
886 ReleaseAttributeContext(IndexAllocationCtx
);
893 * Writes a file record to the master file table, at a given index.
896 UpdateFileRecord(PDEVICE_EXTENSION Vcb
,
898 PFILE_RECORD_HEADER file
)
901 NTSTATUS Status
= STATUS_SUCCESS
;
903 DPRINT("UpdateFileRecord(%p, %I64x, %p)\n", Vcb
, index
, file
);
905 // Add the fixup array to prepare the data for writing to disk
906 AddFixupArray(Vcb
, &file
->Ntfs
);
908 // write the file record to the master file table
909 Status
= WriteAttribute(Vcb
, Vcb
->MFTContext
, index
* Vcb
->NtfsInfo
.BytesPerFileRecord
, (const PUCHAR
)file
, Vcb
->NtfsInfo
.BytesPerFileRecord
, &BytesWritten
);
911 // TODO: Update MFT mirror
913 if (!NT_SUCCESS(Status
))
915 DPRINT1("UpdateFileRecord failed: %I64u written, %u expected\n", BytesWritten
, Vcb
->NtfsInfo
.BytesPerFileRecord
);
923 FixupUpdateSequenceArray(PDEVICE_EXTENSION Vcb
,
924 PNTFS_RECORD_HEADER Record
)
931 USA
= (USHORT
*)((PCHAR
)Record
+ Record
->UsaOffset
);
932 USANumber
= *(USA
++);
933 USACount
= Record
->UsaCount
- 1; /* Exclude the USA Number. */
934 Block
= (USHORT
*)((PCHAR
)Record
+ Vcb
->NtfsInfo
.BytesPerSector
- 2);
936 DPRINT("FixupUpdateSequenceArray(%p, %p)\nUSANumber: %u\tUSACount: %u\n", Vcb
, Record
, USANumber
, USACount
);
940 if (*Block
!= USANumber
)
942 DPRINT1("Mismatch with USA: %u read, %u expected\n" , *Block
, USANumber
);
943 return STATUS_UNSUCCESSFUL
;
946 Block
= (USHORT
*)((PCHAR
)Block
+ Vcb
->NtfsInfo
.BytesPerSector
);
950 return STATUS_SUCCESS
;
954 AddFixupArray(PDEVICE_EXTENSION Vcb
,
955 PNTFS_RECORD_HEADER Record
)
957 USHORT
*pShortToFixUp
;
958 unsigned int ArrayEntryCount
= Record
->UsaCount
- 1;
959 unsigned int Offset
= Vcb
->NtfsInfo
.BytesPerSector
- 2;
962 PFIXUP_ARRAY fixupArray
= (PFIXUP_ARRAY
)((UCHAR
*)Record
+ Record
->UsaOffset
);
964 DPRINT("AddFixupArray(%p, %p)\n fixupArray->USN: %u, ArrayEntryCount: %u\n", Vcb
, Record
, fixupArray
->USN
, ArrayEntryCount
);
968 for (i
= 0; i
< ArrayEntryCount
; i
++)
970 DPRINT("USN: %u\tOffset: %u\n", fixupArray
->USN
, Offset
);
972 pShortToFixUp
= (USHORT
*)((PCHAR
)Record
+ Offset
);
973 fixupArray
->Array
[i
] = *pShortToFixUp
;
974 *pShortToFixUp
= fixupArray
->USN
;
975 Offset
+= Vcb
->NtfsInfo
.BytesPerSector
;
978 return STATUS_SUCCESS
;
982 ReadLCN(PDEVICE_EXTENSION Vcb
,
987 LARGE_INTEGER DiskSector
;
989 DiskSector
.QuadPart
= lcn
;
991 return NtfsReadSectors(Vcb
->StorageDevice
,
992 DiskSector
.u
.LowPart
* Vcb
->NtfsInfo
.SectorsPerCluster
,
993 count
* Vcb
->NtfsInfo
.SectorsPerCluster
,
994 Vcb
->NtfsInfo
.BytesPerSector
,
1001 CompareFileName(PUNICODE_STRING FileName
,
1002 PINDEX_ENTRY_ATTRIBUTE IndexEntry
,
1005 BOOLEAN Ret
, Alloc
= FALSE
;
1006 UNICODE_STRING EntryName
;
1008 EntryName
.Buffer
= IndexEntry
->FileName
.Name
;
1010 EntryName
.MaximumLength
= IndexEntry
->FileName
.NameLength
* sizeof(WCHAR
);
1014 UNICODE_STRING IntFileName
;
1015 if (IndexEntry
->FileName
.NameType
!= NTFS_FILE_NAME_POSIX
)
1017 NT_VERIFY(NT_SUCCESS(RtlUpcaseUnicodeString(&IntFileName
, FileName
, TRUE
)));
1022 IntFileName
= *FileName
;
1025 Ret
= FsRtlIsNameInExpression(&IntFileName
, &EntryName
, (IndexEntry
->FileName
.NameType
!= NTFS_FILE_NAME_POSIX
), NULL
);
1029 RtlFreeUnicodeString(&IntFileName
);
1036 return (RtlCompareUnicodeString(FileName
, &EntryName
, (IndexEntry
->FileName
.NameType
!= NTFS_FILE_NAME_POSIX
)) == 0);
1043 DumpIndexEntry(PINDEX_ENTRY_ATTRIBUTE IndexEntry
)
1045 DPRINT1("Entry: %p\n", IndexEntry
);
1046 DPRINT1("\tData.Directory.IndexedFile: %I64x\n", IndexEntry
->Data
.Directory
.IndexedFile
);
1047 DPRINT1("\tLength: %u\n", IndexEntry
->Length
);
1048 DPRINT1("\tKeyLength: %u\n", IndexEntry
->KeyLength
);
1049 DPRINT1("\tFlags: %x\n", IndexEntry
->Flags
);
1050 DPRINT1("\tReserved: %x\n", IndexEntry
->Reserved
);
1051 DPRINT1("\t\tDirectoryFileReferenceNumber: %I64x\n", IndexEntry
->FileName
.DirectoryFileReferenceNumber
);
1052 DPRINT1("\t\tCreationTime: %I64u\n", IndexEntry
->FileName
.CreationTime
);
1053 DPRINT1("\t\tChangeTime: %I64u\n", IndexEntry
->FileName
.ChangeTime
);
1054 DPRINT1("\t\tLastWriteTime: %I64u\n", IndexEntry
->FileName
.LastWriteTime
);
1055 DPRINT1("\t\tLastAccessTime: %I64u\n", IndexEntry
->FileName
.LastAccessTime
);
1056 DPRINT1("\t\tAllocatedSize: %I64u\n", IndexEntry
->FileName
.AllocatedSize
);
1057 DPRINT1("\t\tDataSize: %I64u\n", IndexEntry
->FileName
.DataSize
);
1058 DPRINT1("\t\tFileAttributes: %x\n", IndexEntry
->FileName
.FileAttributes
);
1059 DPRINT1("\t\tNameLength: %u\n", IndexEntry
->FileName
.NameLength
);
1060 DPRINT1("\t\tNameType: %x\n", IndexEntry
->FileName
.NameType
);
1061 DPRINT1("\t\tName: %.*S\n", IndexEntry
->FileName
.NameLength
, IndexEntry
->FileName
.Name
);
1066 BrowseIndexEntries(PDEVICE_EXTENSION Vcb
,
1067 PFILE_RECORD_HEADER MftRecord
,
1069 ULONG IndexBlockSize
,
1070 PINDEX_ENTRY_ATTRIBUTE FirstEntry
,
1071 PINDEX_ENTRY_ATTRIBUTE LastEntry
,
1072 PUNICODE_STRING FileName
,
1074 PULONG CurrentEntry
,
1076 ULONGLONG
*OutMFTIndex
)
1080 PINDEX_ENTRY_ATTRIBUTE IndexEntry
;
1081 PNTFS_ATTR_CONTEXT IndexAllocationCtx
;
1082 ULONGLONG IndexAllocationSize
;
1083 PINDEX_BUFFER IndexBuffer
;
1085 DPRINT("BrowseIndexEntries(%p, %p, %p, %u, %p, %p, %wZ, %u, %u, %u, %p)\n", Vcb
, MftRecord
, IndexRecord
, IndexBlockSize
, FirstEntry
, LastEntry
, FileName
, *StartEntry
, *CurrentEntry
, DirSearch
, OutMFTIndex
);
1087 IndexEntry
= FirstEntry
;
1088 while (IndexEntry
< LastEntry
&&
1089 !(IndexEntry
->Flags
& NTFS_INDEX_ENTRY_END
))
1091 if ((IndexEntry
->Data
.Directory
.IndexedFile
& NTFS_MFT_MASK
) > 0x10 &&
1092 *CurrentEntry
>= *StartEntry
&&
1093 IndexEntry
->FileName
.NameType
!= NTFS_FILE_NAME_DOS
&&
1094 CompareFileName(FileName
, IndexEntry
, DirSearch
))
1096 *StartEntry
= *CurrentEntry
;
1097 *OutMFTIndex
= (IndexEntry
->Data
.Directory
.IndexedFile
& NTFS_MFT_MASK
);
1098 return STATUS_SUCCESS
;
1101 (*CurrentEntry
) += 1;
1102 ASSERT(IndexEntry
->Length
>= sizeof(INDEX_ENTRY_ATTRIBUTE
));
1103 IndexEntry
= (PINDEX_ENTRY_ATTRIBUTE
)((PCHAR
)IndexEntry
+ IndexEntry
->Length
);
1106 /* If we're already browsing a subnode */
1107 if (IndexRecord
== NULL
)
1109 return STATUS_OBJECT_PATH_NOT_FOUND
;
1112 /* If there's no subnode */
1113 if (!(IndexEntry
->Flags
& NTFS_INDEX_ENTRY_NODE
))
1115 return STATUS_OBJECT_PATH_NOT_FOUND
;
1118 Status
= FindAttribute(Vcb
, MftRecord
, AttributeIndexAllocation
, L
"$I30", 4, &IndexAllocationCtx
, NULL
);
1119 if (!NT_SUCCESS(Status
))
1121 DPRINT("Corrupted filesystem!\n");
1125 IndexAllocationSize
= AttributeDataLength(&IndexAllocationCtx
->Record
);
1126 Status
= STATUS_OBJECT_PATH_NOT_FOUND
;
1127 for (RecordOffset
= 0; RecordOffset
< IndexAllocationSize
; RecordOffset
+= IndexBlockSize
)
1129 ReadAttribute(Vcb
, IndexAllocationCtx
, RecordOffset
, IndexRecord
, IndexBlockSize
);
1130 Status
= FixupUpdateSequenceArray(Vcb
, &((PFILE_RECORD_HEADER
)IndexRecord
)->Ntfs
);
1131 if (!NT_SUCCESS(Status
))
1136 IndexBuffer
= (PINDEX_BUFFER
)IndexRecord
;
1137 ASSERT(IndexBuffer
->Ntfs
.Type
== NRH_INDX_TYPE
);
1138 ASSERT(IndexBuffer
->Header
.AllocatedSize
+ FIELD_OFFSET(INDEX_BUFFER
, Header
) == IndexBlockSize
);
1139 FirstEntry
= (PINDEX_ENTRY_ATTRIBUTE
)((ULONG_PTR
)&IndexBuffer
->Header
+ IndexBuffer
->Header
.FirstEntryOffset
);
1140 LastEntry
= (PINDEX_ENTRY_ATTRIBUTE
)((ULONG_PTR
)&IndexBuffer
->Header
+ IndexBuffer
->Header
.TotalSizeOfEntries
);
1141 ASSERT(LastEntry
<= (PINDEX_ENTRY_ATTRIBUTE
)((ULONG_PTR
)IndexBuffer
+ IndexBlockSize
));
1143 Status
= BrowseIndexEntries(NULL
, NULL
, NULL
, 0, FirstEntry
, LastEntry
, FileName
, StartEntry
, CurrentEntry
, DirSearch
, OutMFTIndex
);
1144 if (NT_SUCCESS(Status
))
1150 ReleaseAttributeContext(IndexAllocationCtx
);
1155 NtfsFindMftRecord(PDEVICE_EXTENSION Vcb
,
1157 PUNICODE_STRING FileName
,
1160 ULONGLONG
*OutMFTIndex
)
1162 PFILE_RECORD_HEADER MftRecord
;
1163 PNTFS_ATTR_CONTEXT IndexRootCtx
;
1164 PINDEX_ROOT_ATTRIBUTE IndexRoot
;
1166 PINDEX_ENTRY_ATTRIBUTE IndexEntry
, IndexEntryEnd
;
1168 ULONG CurrentEntry
= 0;
1170 DPRINT("NtfsFindMftRecord(%p, %I64d, %wZ, %u, %u, %p)\n", Vcb
, MFTIndex
, FileName
, *FirstEntry
, DirSearch
, OutMFTIndex
);
1172 MftRecord
= ExAllocatePoolWithTag(NonPagedPool
,
1173 Vcb
->NtfsInfo
.BytesPerFileRecord
,
1175 if (MftRecord
== NULL
)
1177 return STATUS_INSUFFICIENT_RESOURCES
;
1180 Status
= ReadFileRecord(Vcb
, MFTIndex
, MftRecord
);
1181 if (!NT_SUCCESS(Status
))
1183 ExFreePoolWithTag(MftRecord
, TAG_NTFS
);
1187 ASSERT(MftRecord
->Ntfs
.Type
== NRH_FILE_TYPE
);
1188 Status
= FindAttribute(Vcb
, MftRecord
, AttributeIndexRoot
, L
"$I30", 4, &IndexRootCtx
, NULL
);
1189 if (!NT_SUCCESS(Status
))
1191 ExFreePoolWithTag(MftRecord
, TAG_NTFS
);
1195 IndexRecord
= ExAllocatePoolWithTag(NonPagedPool
, Vcb
->NtfsInfo
.BytesPerIndexRecord
, TAG_NTFS
);
1196 if (IndexRecord
== NULL
)
1198 ReleaseAttributeContext(IndexRootCtx
);
1199 ExFreePoolWithTag(MftRecord
, TAG_NTFS
);
1200 return STATUS_INSUFFICIENT_RESOURCES
;
1203 ReadAttribute(Vcb
, IndexRootCtx
, 0, IndexRecord
, Vcb
->NtfsInfo
.BytesPerIndexRecord
);
1204 IndexRoot
= (PINDEX_ROOT_ATTRIBUTE
)IndexRecord
;
1205 IndexEntry
= (PINDEX_ENTRY_ATTRIBUTE
)((PCHAR
)&IndexRoot
->Header
+ IndexRoot
->Header
.FirstEntryOffset
);
1206 /* Index root is always resident. */
1207 IndexEntryEnd
= (PINDEX_ENTRY_ATTRIBUTE
)(IndexRecord
+ IndexRoot
->Header
.TotalSizeOfEntries
);
1208 ReleaseAttributeContext(IndexRootCtx
);
1210 DPRINT("IndexRecordSize: %x IndexBlockSize: %x\n", Vcb
->NtfsInfo
.BytesPerIndexRecord
, IndexRoot
->SizeOfEntry
);
1212 Status
= BrowseIndexEntries(Vcb
, MftRecord
, IndexRecord
, IndexRoot
->SizeOfEntry
, IndexEntry
, IndexEntryEnd
, FileName
, FirstEntry
, &CurrentEntry
, DirSearch
, OutMFTIndex
);
1214 ExFreePoolWithTag(IndexRecord
, TAG_NTFS
);
1215 ExFreePoolWithTag(MftRecord
, TAG_NTFS
);
1221 NtfsLookupFileAt(PDEVICE_EXTENSION Vcb
,
1222 PUNICODE_STRING PathName
,
1223 PFILE_RECORD_HEADER
*FileRecord
,
1224 PULONGLONG MFTIndex
,
1225 ULONGLONG CurrentMFTIndex
)
1227 UNICODE_STRING Current
, Remaining
;
1229 ULONG FirstEntry
= 0;
1231 DPRINT("NtfsLookupFileAt(%p, %wZ, %p, %I64x)\n", Vcb
, PathName
, FileRecord
, CurrentMFTIndex
);
1233 FsRtlDissectName(*PathName
, &Current
, &Remaining
);
1235 while (Current
.Length
!= 0)
1237 DPRINT("Current: %wZ\n", &Current
);
1239 Status
= NtfsFindMftRecord(Vcb
, CurrentMFTIndex
, &Current
, &FirstEntry
, FALSE
, &CurrentMFTIndex
);
1240 if (!NT_SUCCESS(Status
))
1245 if (Remaining
.Length
== 0)
1248 FsRtlDissectName(Current
, &Current
, &Remaining
);
1251 *FileRecord
= ExAllocatePoolWithTag(NonPagedPool
, Vcb
->NtfsInfo
.BytesPerFileRecord
, TAG_NTFS
);
1252 if (*FileRecord
== NULL
)
1254 DPRINT("NtfsLookupFileAt: Can't allocate MFT record\n");
1255 return STATUS_INSUFFICIENT_RESOURCES
;
1258 Status
= ReadFileRecord(Vcb
, CurrentMFTIndex
, *FileRecord
);
1259 if (!NT_SUCCESS(Status
))
1261 DPRINT("NtfsLookupFileAt: Can't read MFT record\n");
1262 ExFreePoolWithTag(*FileRecord
, TAG_NTFS
);
1266 *MFTIndex
= CurrentMFTIndex
;
1268 return STATUS_SUCCESS
;
1272 NtfsLookupFile(PDEVICE_EXTENSION Vcb
,
1273 PUNICODE_STRING PathName
,
1274 PFILE_RECORD_HEADER
*FileRecord
,
1275 PULONGLONG MFTIndex
)
1277 return NtfsLookupFileAt(Vcb
, PathName
, FileRecord
, MFTIndex
, NTFS_FILE_ROOT
);
1281 NtfsFindFileAt(PDEVICE_EXTENSION Vcb
,
1282 PUNICODE_STRING SearchPattern
,
1284 PFILE_RECORD_HEADER
*FileRecord
,
1285 PULONGLONG MFTIndex
,
1286 ULONGLONG CurrentMFTIndex
)
1290 DPRINT("NtfsFindFileAt(%p, %wZ, %u, %p, %p, %I64x)\n", Vcb
, SearchPattern
, *FirstEntry
, FileRecord
, MFTIndex
, CurrentMFTIndex
);
1292 Status
= NtfsFindMftRecord(Vcb
, CurrentMFTIndex
, SearchPattern
, FirstEntry
, TRUE
, &CurrentMFTIndex
);
1293 if (!NT_SUCCESS(Status
))
1295 DPRINT("NtfsFindFileAt: NtfsFindMftRecord() failed with status 0x%08lx\n", Status
);
1299 *FileRecord
= ExAllocatePoolWithTag(NonPagedPool
, Vcb
->NtfsInfo
.BytesPerFileRecord
, TAG_NTFS
);
1300 if (*FileRecord
== NULL
)
1302 DPRINT("NtfsFindFileAt: Can't allocate MFT record\n");
1303 return STATUS_INSUFFICIENT_RESOURCES
;
1306 Status
= ReadFileRecord(Vcb
, CurrentMFTIndex
, *FileRecord
);
1307 if (!NT_SUCCESS(Status
))
1309 DPRINT("NtfsFindFileAt: Can't read MFT record\n");
1310 ExFreePoolWithTag(*FileRecord
, TAG_NTFS
);
1314 *MFTIndex
= CurrentMFTIndex
;
1316 return STATUS_SUCCESS
;