Author: pschweitzer
Date: Thu Oct 16 20:05:36 2014
New Revision: 64765
URL:
http://svn.reactos.org/svn/reactos?rev=64765&view=rev
Log:
[NTFS]
Bugfixing... Part 1/X:
- FixupUpdateSequenceArray() returns a NTSTATUS, so properly handle it.
- Actually... Attributes name can be unicode in case of a file name, but it can also be
ansi, for streams name... So, don't force UNICODE_STRING, it causes more troubles than
it solves.
So, now, we really progress in reading directory. Instead of finding no files because we
improperly read attributes, we now corrupt memory somewhere and crash ReactOS.
Modified:
trunk/reactos/drivers/filesystems/ntfs/fsctl.c
trunk/reactos/drivers/filesystems/ntfs/mft.c
trunk/reactos/drivers/filesystems/ntfs/ntfs.h
Modified: trunk/reactos/drivers/filesystems/ntfs/fsctl.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/f…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/fsctl.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/fsctl.c [iso-8859-1] Thu Oct 16 20:05:36 2014
@@ -34,8 +34,6 @@
#define NDEBUG
#include <debug.h>
-UNICODE_STRING EmptyName = RTL_CONSTANT_STRING(L"");
-
/* FUNCTIONS ****************************************************************/
/*
@@ -274,7 +272,7 @@
return Status;
}
- Status = FindAttribute(DeviceExt, DeviceExt->MasterFileTable, AttributeData,
&EmptyName, &DeviceExt->MFTContext);
+ Status = FindAttribute(DeviceExt, DeviceExt->MasterFileTable, AttributeData,
L"", 0, &DeviceExt->MFTContext);
if (!NT_SUCCESS(Status))
{
DPRINT1("Can't find data attribute for Master File Table.\n");
@@ -312,7 +310,7 @@
NtfsDumpFileAttributes(VolumeRecord);
/* Get volume name */
- Status = FindAttribute(DeviceExt, VolumeRecord, AttributeVolumeName, &EmptyName,
&AttrCtxt);
+ Status = FindAttribute(DeviceExt, VolumeRecord, AttributeVolumeName, L"",
0, &AttrCtxt);
if (NT_SUCCESS(Status) && AttrCtxt->Record.Resident.ValueLength != 0)
{
@@ -348,7 +346,7 @@
DeviceExt->VolumeFcb = VolumeFcb;
/* Get volume information */
- Status = FindAttribute(DeviceExt, VolumeRecord, AttributeVolumeInformation,
&EmptyName, &AttrCtxt);
+ Status = FindAttribute(DeviceExt, VolumeRecord, AttributeVolumeInformation,
L"", 0, &AttrCtxt);
if (NT_SUCCESS(Status) && AttrCtxt->Record.Resident.ValueLength != 0)
{
Modified: trunk/reactos/drivers/filesystems/ntfs/mft.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/m…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/mft.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/mft.c [iso-8859-1] Thu Oct 16 20:05:36 2014
@@ -31,8 +31,6 @@
#define NDEBUG
#include <debug.h>
-UNICODE_STRING IndexOfFileNames = RTL_CONSTANT_STRING(L"$I30");
-
/* FUNCTIONS ****************************************************************/
PNTFS_ATTR_CONTEXT
@@ -84,10 +82,10 @@
PNTFS_ATTR_RECORD AttrRecord,
PNTFS_ATTR_RECORD AttrRecordEnd,
ULONG Type,
- const WCHAR *Name,
+ PCWSTR Name,
ULONG NameLength)
{
- DPRINT("FindAttributeHelper(%p, %p, %p, 0x%x, %s, %u)\n", Vcb, AttrRecord,
AttrRecordEnd, Type, Name, NameLength);
+ DPRINT1("FindAttributeHelper(%p, %p, %p, 0x%x, %S, %u)\n", Vcb, AttrRecord,
AttrRecordEnd, Type, Name, NameLength);
while (AttrRecord < AttrRecordEnd)
{
@@ -143,7 +141,6 @@
if (AttrRecord->Type == Type)
{
- DPRINT("%d, %d\n", AttrRecord->NameLength, NameLength);
if (AttrRecord->NameLength == NameLength)
{
PWCHAR AttrName;
@@ -176,18 +173,19 @@
FindAttribute(PDEVICE_EXTENSION Vcb,
PFILE_RECORD_HEADER MftRecord,
ULONG Type,
- PUNICODE_STRING Name,
+ PCWSTR Name,
+ ULONG NameLength,
PNTFS_ATTR_CONTEXT * AttrCtx)
{
PNTFS_ATTR_RECORD AttrRecord;
PNTFS_ATTR_RECORD AttrRecordEnd;
- DPRINT("NtfsFindAttribute(%p, %p, %u, %s)\n", Vcb, MftRecord, Type, Name);
+ DPRINT1("NtfsFindAttribute(%p, %p, %u, %S, %u, %p)\n", Vcb, MftRecord,
Type, Name, NameLength, AttrCtx);
AttrRecord = (PNTFS_ATTR_RECORD)((PCHAR)MftRecord + MftRecord->AttributeOffset);
AttrRecordEnd = (PNTFS_ATTR_RECORD)((PCHAR)MftRecord +
Vcb->NtfsInfo.BytesPerFileRecord);
- *AttrCtx = FindAttributeHelper(Vcb, AttrRecord, AttrRecordEnd, Type, Name->Buffer,
Name->Length);
+ *AttrCtx = FindAttributeHelper(Vcb, AttrRecord, AttrRecordEnd, Type, Name,
NameLength);
if (*AttrCtx == NULL)
{
return STATUS_OBJECT_NAME_NOT_FOUND;
@@ -507,6 +505,8 @@
NTSTATUS Status;
ULONG CurrentEntry = 0;
+ DPRINT1("NtfsFindMftRecord(%p, %I64d, %wZ, %p, %u, %p, %p)\n", Vcb,
MFTIndex, FileName, FirstEntry, DirSearch, OutMFTIndex, OutName);
+
MftRecord = ExAllocatePoolWithTag(NonPagedPool,
Vcb->NtfsInfo.BytesPerFileRecord,
TAG_NTFS);
@@ -519,7 +519,7 @@
{
//Magic = MftRecord->Magic;
- Status = FindAttribute(Vcb, MftRecord, AttributeIndexRoot, &IndexOfFileNames,
&IndexRootCtx);
+ Status = FindAttribute(Vcb, MftRecord, AttributeIndexRoot, L"$I30", 4,
&IndexRootCtx);
if (!NT_SUCCESS(Status))
{
ExFreePoolWithTag(MftRecord, TAG_NTFS);
@@ -566,10 +566,10 @@
IndexBlockSize = IndexRoot->SizeOfEntry;
- Status = FindAttribute(Vcb, MftRecord, AttributeBitmap,
&IndexOfFileNames, &IndexBitmapCtx);
+ Status = FindAttribute(Vcb, MftRecord, AttributeBitmap, L"$I30", 4,
&IndexBitmapCtx);
if (!NT_SUCCESS(Status))
{
- DPRINT("Corrupted filesystem!\n");
+ DPRINT1("Corrupted filesystem!\n");
ExFreePoolWithTag(MftRecord, TAG_NTFS);
return Status;
}
@@ -589,7 +589,7 @@
ReadAttribute(Vcb, IndexBitmapCtx, 0, BitmapData, (ULONG)BitmapDataSize);
ReleaseAttributeContext(IndexBitmapCtx);
- Status = FindAttribute(Vcb, MftRecord, AttributeIndexAllocation,
&IndexOfFileNames, &IndexAllocationCtx);
+ Status = FindAttribute(Vcb, MftRecord, AttributeIndexAllocation,
L"$I30", 4, &IndexAllocationCtx);
if (!NT_SUCCESS(Status))
{
DPRINT("Corrupted filesystem!\n");
@@ -621,7 +621,7 @@
ReadAttribute(Vcb, IndexAllocationCtx, RecordOffset, IndexRecord,
IndexBlockSize);
- if (!FixupUpdateSequenceArray(Vcb,
&((PFILE_RECORD_HEADER)IndexRecord)->Ntfs))
+ if (!NT_SUCCESS(FixupUpdateSequenceArray(Vcb,
&((PFILE_RECORD_HEADER)IndexRecord)->Ntfs)))
{
break;
}
@@ -677,10 +677,10 @@
PULONGLONG MFTIndex,
ULONGLONG CurrentMFTIndex)
{
- UNICODE_STRING Current, Remaining, Found;
+ UNICODE_STRING Current, Remaining;
NTSTATUS Status;
WCHAR FoundName[MAX_PATH + 1];
- ULONG FirstEntry = 0;
+ ULONG FirstEntry = 0, Length;
DPRINT1("NtfsLookupFileAt(%p, %wZ, %p, %p, %I64x)\n", Vcb, PathName,
FileRecord, DataContext, CurrentMFTIndex);
@@ -714,9 +714,9 @@
return Status;
}
- RtlInitUnicodeString(&Found, FoundName);
-
- Status = FindAttribute(Vcb, *FileRecord, AttributeData, &Found, DataContext);
+ Length = wcslen(FoundName) * sizeof(WCHAR);
+
+ Status = FindAttribute(Vcb, *FileRecord, AttributeData, FoundName, Length,
DataContext);
if (!NT_SUCCESS(Status))
{
DPRINT("NtfsLookupFileAt: Can't find data attribute\n");
@@ -748,9 +748,9 @@
PULONGLONG MFTIndex,
ULONGLONG CurrentMFTIndex)
{
- UNICODE_STRING Found;
NTSTATUS Status;
WCHAR FoundName[MAX_PATH + 1];
+ ULONG Length;
DPRINT1("NtfsFindFileAt(%p, %wZ, %p, %p, %p, %p, %I64x)\n", Vcb,
SearchPattern, FirstEntry, FileRecord, DataContext, MFTIndex, CurrentMFTIndex);
@@ -775,9 +775,9 @@
return Status;
}
- RtlInitUnicodeString(&Found, FoundName);
-
- Status = FindAttribute(Vcb, *FileRecord, AttributeData, &Found, DataContext);
+ Length = wcslen(FoundName) * sizeof(WCHAR);
+
+ Status = FindAttribute(Vcb, *FileRecord, AttributeData, FoundName, Length,
DataContext);
if (!NT_SUCCESS(Status))
{
DPRINT("NtfsFindFileAt: Can't find data attribute\n");
Modified: trunk/reactos/drivers/filesystems/ntfs/ntfs.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/n…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/ntfs.h [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/ntfs.h [iso-8859-1] Thu Oct 16 20:05:36 2014
@@ -613,7 +613,8 @@
FindAttribute(PDEVICE_EXTENSION Vcb,
PFILE_RECORD_HEADER MftRecord,
ULONG Type,
- PUNICODE_STRING Name,
+ PCWSTR Name,
+ ULONG NameLength,
PNTFS_ATTR_CONTEXT * AttrCtx);
VOID