[NTFS]
[reactos.git] / reactos / drivers / filesystems / ntfs / mft.c
index cc8fa85..3e83fe8 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ReactOS kernel
- *  Copyright (C) 2002 ReactOS Team
+ *  Copyright (C) 2002, 2014 ReactOS Team
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  * PROJECT:          ReactOS kernel
  * FILE:             drivers/filesystem/ntfs/mft.c
  * PURPOSE:          NTFS filesystem driver
- * PROGRAMMER:       Eric Kohl
- *                   Updated by Valentin Verkhovsky  2003/09/12
+ * PROGRAMMERS:      Eric Kohl
+ *                   Valentin Verkhovsky
+ *                   Pierre Schweitzer (pierre@reactos.org)
+ *                   HervĂ© Poussineau (hpoussin@reactos.org)
  */
 
 /* INCLUDES *****************************************************************/
@@ -103,9 +105,6 @@ FindAttributeHelper(PDEVICE_EXTENSION Vcb,
             PNTFS_ATTR_RECORD ListAttrRecord;
             PNTFS_ATTR_RECORD ListAttrRecordEnd;
 
-            // Do not handle non-resident yet
-            ASSERT(!(AttrRecord->IsNonResident & 1));
-
             ListContext = PrepareAttributeContext(AttrRecord);
 
             ListSize = AttributeDataLength(&ListContext->Record);
@@ -133,7 +132,7 @@ FindAttributeHelper(PDEVICE_EXTENSION Vcb,
 
                 if (Context != NULL)
                 {
-                    DPRINT("Found context = %p\n", Context);
+                    if (AttrRecord->IsNonResident) DPRINT("Found context = %p\n", Context);
                     return Context;
                 }
             }
@@ -308,6 +307,7 @@ ReadAttribute(PDEVICE_EXTENSION Vcb,
     Status = NtfsReadDisk(Vcb->StorageDevice,
                           DataRunStartLCN * Vcb->NtfsInfo.BytesPerCluster + Offset - CurrentOffset,
                           ReadLength,
+                          Vcb->NtfsInfo.BytesPerSector,
                           (PVOID)Buffer,
                           FALSE);
     if (NT_SUCCESS(Status))
@@ -342,6 +342,7 @@ ReadAttribute(PDEVICE_EXTENSION Vcb,
                 Status = NtfsReadDisk(Vcb->StorageDevice,
                                       DataRunStartLCN * Vcb->NtfsInfo.BytesPerCluster,
                                       ReadLength,
+                                      Vcb->NtfsInfo.BytesPerSector,
                                       (PVOID)Buffer,
                                       FALSE);
                 if (!NT_SUCCESS(Status))
@@ -469,7 +470,7 @@ CompareFileName(PUNICODE_STRING FileName,
 
     EntryName.Buffer = IndexEntry->FileName.Name;
     EntryName.Length = 
-    EntryName.MaximumLength = IndexEntry->FileName.NameLength;
+    EntryName.MaximumLength = IndexEntry->FileName.NameLength * sizeof(WCHAR);
 
     if (DirSearch)
     {
@@ -477,7 +478,7 @@ CompareFileName(PUNICODE_STRING FileName,
     }
     else
     {
-        return (RtlCompareUnicodeString(FileName, &EntryName, (IndexEntry->FileName.NameType != NTFS_FILE_NAME_POSIX)) == TRUE);
+        return (RtlCompareUnicodeString(FileName, &EntryName, (IndexEntry->FileName.NameType != NTFS_FILE_NAME_POSIX)) == 0);
     }
 }
 
@@ -491,7 +492,6 @@ NtfsFindMftRecord(PDEVICE_EXTENSION Vcb,
                   ULONGLONG *OutMFTIndex)
 {
     PFILE_RECORD_HEADER MftRecord;
-    //ULONG Magic;
     PNTFS_ATTR_CONTEXT IndexRootCtx;
     PNTFS_ATTR_CONTEXT IndexBitmapCtx;
     PNTFS_ATTR_CONTEXT IndexAllocationCtx;
@@ -519,7 +519,7 @@ NtfsFindMftRecord(PDEVICE_EXTENSION Vcb,
 
     if (NT_SUCCESS(ReadFileRecord(Vcb, MFTIndex, MftRecord)))
     {
-        //Magic = MftRecord->Magic;
+        ASSERT(MftRecord->Ntfs.Type == NRH_FILE_TYPE);
 
         Status = FindAttribute(Vcb, MftRecord, AttributeIndexRoot, L"$I30", 4, &IndexRootCtx);
         if (!NT_SUCCESS(Status))
@@ -629,11 +629,11 @@ NtfsFindMftRecord(PDEVICE_EXTENSION Vcb,
                 }
 
                 IndexBuffer = (PINDEX_BUFFER)IndexRecord;
-                ASSERT(IndexBuffer->Ntfs.Type == 'XDNI');
+                ASSERT(IndexBuffer->Ntfs.Type == NRH_INDX_TYPE);
                 ASSERT(IndexBuffer->Header.AllocatedSize + 0x18 == IndexBlockSize);
-                IndexEntry = (PINDEX_ENTRY_ATTRIBUTE)(&IndexBuffer->Header + IndexBuffer->Header.FirstEntryOffset);
-                IndexEntryEnd = (PINDEX_ENTRY_ATTRIBUTE)(&IndexBuffer->Header + IndexBuffer->Header.TotalSizeOfEntries);
-                //ASSERT(IndexEntryEnd <= (PINDEX_ENTRY_ATTRIBUTE)((ULONG_PTR)IndexBuffer + IndexBlockSize)); FIXME: Why doesn't it work?
+                IndexEntry = (PINDEX_ENTRY_ATTRIBUTE)((ULONG_PTR)&IndexBuffer->Header + IndexBuffer->Header.FirstEntryOffset);
+                IndexEntryEnd = (PINDEX_ENTRY_ATTRIBUTE)((ULONG_PTR)&IndexBuffer->Header + IndexBuffer->Header.TotalSizeOfEntries);
+                ASSERT(IndexEntryEnd <= (PINDEX_ENTRY_ATTRIBUTE)((ULONG_PTR)IndexBuffer + IndexBlockSize));
 
                 while (IndexEntry < IndexEntryEnd &&
                        !(IndexEntry->Flags & NTFS_INDEX_ENTRY_END))
@@ -653,6 +653,7 @@ NtfsFindMftRecord(PDEVICE_EXTENSION Vcb,
                     }
 
                     ++CurrentEntry;
+                    ASSERT(IndexEntry->Length >= sizeof(INDEX_ENTRY_ATTRIBUTE));
                     IndexEntry = (PINDEX_ENTRY_ATTRIBUTE)((PCHAR)IndexEntry + IndexEntry->Length);
                 }
 
@@ -701,7 +702,7 @@ NtfsLookupFileAt(PDEVICE_EXTENSION Vcb,
         }
 
         if (Remaining.Length == 0)
-            return STATUS_OBJECT_PATH_NOT_FOUND;
+            break;
 
         FsRtlDissectName(Current, &Current, &Remaining);
     }