[NTFS]
[reactos.git] / reactos / drivers / filesystems / ntfs / mft.c
index 2b94e22..acecf2d 100644 (file)
@@ -105,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);
@@ -135,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;
                 }
             }
@@ -310,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))
@@ -344,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))
@@ -467,6 +466,7 @@ CompareFileName(PUNICODE_STRING FileName,
                 PINDEX_ENTRY_ATTRIBUTE IndexEntry,
                 BOOLEAN DirSearch)
 {
+    BOOLEAN Ret, Alloc = FALSE;
     UNICODE_STRING EntryName;
 
     EntryName.Buffer = IndexEntry->FileName.Name;
@@ -475,7 +475,25 @@ CompareFileName(PUNICODE_STRING FileName,
 
     if (DirSearch)
     {
-        return FsRtlIsNameInExpression(FileName, &EntryName, (IndexEntry->FileName.NameType != NTFS_FILE_NAME_POSIX), NULL);
+        UNICODE_STRING IntFileName;
+        if (IndexEntry->FileName.NameType != NTFS_FILE_NAME_POSIX)
+        {
+            NT_VERIFY(NT_SUCCESS(RtlUpcaseUnicodeString(&IntFileName, FileName, TRUE)));
+            Alloc = TRUE;
+        }
+        else
+        {
+            IntFileName = *FileName;
+        }
+
+        Ret = FsRtlIsNameInExpression(&IntFileName, &EntryName, (IndexEntry->FileName.NameType != NTFS_FILE_NAME_POSIX), NULL);
+
+        if (Alloc)
+        {
+            RtlFreeUnicodeString(&IntFileName);
+        }
+
+        return Ret;
     }
     else
     {
@@ -493,7 +511,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;
@@ -521,7 +538,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))
@@ -549,6 +566,14 @@ NtfsFindMftRecord(PDEVICE_EXTENSION Vcb,
         while (IndexEntry < IndexEntryEnd &&
                !(IndexEntry->Flags & NTFS_INDEX_ENTRY_END))
         {
+            UNICODE_STRING EntryName;
+            EntryName.Buffer = IndexEntry->FileName.Name;
+            EntryName.Length = 
+            EntryName.MaximumLength = IndexEntry->FileName.NameLength * sizeof(WCHAR);
+
+            if (IndexEntry->Flags & NTFS_INDEX_ENTRY_NODE)
+                DPRINT1("Warning: sub-node browsing unimplemented! (%wZ)\n", &EntryName);
+
             if ((IndexEntry->Data.Directory.IndexedFile & NTFS_MFT_MASK) > 0x10 &&
                 CurrentEntry >= *FirstEntry &&
                 CompareFileName(FileName, IndexEntry, DirSearch))
@@ -631,7 +656,7 @@ 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)((ULONG_PTR)&IndexBuffer->Header + IndexBuffer->Header.FirstEntryOffset);
                 IndexEntryEnd = (PINDEX_ENTRY_ATTRIBUTE)((ULONG_PTR)&IndexBuffer->Header + IndexBuffer->Header.TotalSizeOfEntries);
@@ -640,6 +665,14 @@ NtfsFindMftRecord(PDEVICE_EXTENSION Vcb,
                 while (IndexEntry < IndexEntryEnd &&
                        !(IndexEntry->Flags & NTFS_INDEX_ENTRY_END))
                 {
+                    UNICODE_STRING EntryName;
+                    EntryName.Buffer = IndexEntry->FileName.Name;
+                    EntryName.Length = 
+                    EntryName.MaximumLength = IndexEntry->FileName.NameLength * sizeof(WCHAR);
+
+                    if (IndexEntry->Flags & NTFS_INDEX_ENTRY_NODE)
+                        DPRINT1("Warning: sub-node browsing unimplemented! (%wZ)\n", &EntryName);
+
                     if ((IndexEntry->Data.Directory.IndexedFile & NTFS_MFT_MASK) > 0x10 &&
                         CurrentEntry >= *FirstEntry &&
                         CompareFileName(FileName, IndexEntry, DirSearch))