Author: pschweitzer
Date: Tue Nov 4 07:56:20 2014
New Revision: 65240
URL:
http://svn.reactos.org/svn/reactos?rev=65240&view=rev
Log:
[NTFS]
- Move the ROUND_UP & ROUND_DOWN macro definition to header
- Make NtfsReadDisk() sector size aware so that it can properly align read on the disk
(and thus prevent them from failing)
- If $ATTRIBUTE_LIST is non resident, then display a message and continue, don't
assert on it. This is to be implemented later on.
This fixes directory enumeration on a Windows 7 NTFS volume.
Modified:
trunk/reactos/drivers/filesystems/ntfs/blockdev.c
trunk/reactos/drivers/filesystems/ntfs/mft.c
trunk/reactos/drivers/filesystems/ntfs/ntfs.h
trunk/reactos/drivers/filesystems/ntfs/rw.c
Modified: trunk/reactos/drivers/filesystems/ntfs/blockdev.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/b…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/blockdev.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/blockdev.c [iso-8859-1] Tue Nov 4 07:56:20
2014
@@ -36,6 +36,7 @@
NtfsReadDisk(IN PDEVICE_OBJECT DeviceObject,
IN LONGLONG StartingOffset,
IN ULONG Length,
+ IN ULONG SectorSize,
IN OUT PUCHAR Buffer,
IN BOOLEAN Override)
{
@@ -45,20 +46,41 @@
KEVENT Event;
PIRP Irp;
NTSTATUS Status;
+ ULONGLONG RealReadOffset;
+ ULONG RealLength;
+ BOOLEAN AllocatedBuffer = FALSE;
+ PUCHAR ReadBuffer = Buffer;
- DPRINT("NtfsReadDisk(%p, %I64x, %u, %p, %d)\n", DeviceObject,
StartingOffset, Length, Buffer, Override);
+ DPRINT("NtfsReadDisk(%p, %I64x, %u, %u, %p, %d)\n", DeviceObject,
StartingOffset, Length, SectorSize, Buffer, Override);
KeInitializeEvent(&Event,
NotificationEvent,
FALSE);
- Offset.QuadPart = StartingOffset;
+ RealReadOffset = (ULONGLONG)StartingOffset;
+ RealLength = Length;
+
+ if ((RealReadOffset % SectorSize) != 0 || (RealLength % SectorSize) != 0)
+ {
+ RealReadOffset = ROUND_DOWN(StartingOffset, SectorSize);
+ RealLength = ROUND_UP(Length, SectorSize);
+
+ ReadBuffer = ExAllocatePoolWithTag(NonPagedPool, RealLength + SectorSize,
TAG_NTFS);
+ if (ReadBuffer == NULL)
+ {
+ DPRINT1("Not enough memory!\n");
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+ AllocatedBuffer = TRUE;
+ }
+
+ Offset.QuadPart = RealReadOffset;
DPRINT("Building synchronous FSD Request...\n");
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
DeviceObject,
- Buffer,
- Length,
+ ReadBuffer,
+ RealLength,
&Offset,
&Event,
&IoStatus);
@@ -86,6 +108,12 @@
Status = IoStatus.Status;
}
+ if (NT_SUCCESS(Status) && AllocatedBuffer)
+ {
+ RtlCopyMemory(Buffer, ReadBuffer + (StartingOffset - RealReadOffset), Length);
+ ExFreePoolWithTag(ReadBuffer, TAG_NTFS);
+ }
+
DPRINT("NtfsReadDisk() done (Status %x)\n", Status);
return Status;
@@ -105,7 +133,7 @@
Offset = (LONGLONG)DiskSector * (LONGLONG)SectorSize;
BlockSize = SectorCount * SectorSize;
- return NtfsReadDisk(DeviceObject, Offset, BlockSize, Buffer, Override);
+ return NtfsReadDisk(DeviceObject, Offset, BlockSize, SectorSize, Buffer, Override);
}
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] Tue Nov 4 07:56:20 2014
@@ -106,37 +106,43 @@
PNTFS_ATTR_RECORD ListAttrRecordEnd;
// Do not handle non-resident yet
- ASSERT(!(AttrRecord->IsNonResident & 1));
-
- ListContext = PrepareAttributeContext(AttrRecord);
-
- ListSize = AttributeDataLength(&ListContext->Record);
- if(ListSize <= 0xFFFFFFFF)
- ListBuffer = ExAllocatePoolWithTag(NonPagedPool, (ULONG)ListSize,
TAG_NTFS);
+ if (AttrRecord->IsNonResident)
+ {
+ UNIMPLEMENTED;
+ continue;
+ }
else
- ListBuffer = NULL;
-
- if(!ListBuffer)
- {
- DPRINT("Failed to allocate memory: %x\n", (ULONG)ListSize);
- continue;
- }
-
- ListAttrRecord = (PNTFS_ATTR_RECORD)ListBuffer;
- ListAttrRecordEnd = (PNTFS_ATTR_RECORD)((PCHAR)ListBuffer + ListSize);
-
- if (ReadAttribute(Vcb, ListContext, 0, ListBuffer, (ULONG)ListSize) ==
ListSize)
- {
- Context = FindAttributeHelper(Vcb, ListAttrRecord, ListAttrRecordEnd,
- Type, Name, NameLength);
-
- ReleaseAttributeContext(ListContext);
- ExFreePoolWithTag(ListBuffer, TAG_NTFS);
-
- if (Context != NULL)
+ {
+ ListContext = PrepareAttributeContext(AttrRecord);
+
+ ListSize = AttributeDataLength(&ListContext->Record);
+ if(ListSize <= 0xFFFFFFFF)
+ ListBuffer = ExAllocatePoolWithTag(NonPagedPool, (ULONG)ListSize,
TAG_NTFS);
+ else
+ ListBuffer = NULL;
+
+ if(!ListBuffer)
{
- DPRINT("Found context = %p\n", Context);
- return Context;
+ DPRINT("Failed to allocate memory: %x\n",
(ULONG)ListSize);
+ continue;
+ }
+
+ ListAttrRecord = (PNTFS_ATTR_RECORD)ListBuffer;
+ ListAttrRecordEnd = (PNTFS_ATTR_RECORD)((PCHAR)ListBuffer + ListSize);
+
+ if (ReadAttribute(Vcb, ListContext, 0, ListBuffer, (ULONG)ListSize) ==
ListSize)
+ {
+ Context = FindAttributeHelper(Vcb, ListAttrRecord,
ListAttrRecordEnd,
+ Type, Name, NameLength);
+
+ ReleaseAttributeContext(ListContext);
+ ExFreePoolWithTag(ListBuffer, TAG_NTFS);
+
+ if (Context != NULL)
+ {
+ DPRINT("Found context = %p\n", Context);
+ return Context;
+ }
}
}
}
@@ -310,6 +316,7 @@
Status = NtfsReadDisk(Vcb->StorageDevice,
DataRunStartLCN * Vcb->NtfsInfo.BytesPerCluster + Offset -
CurrentOffset,
ReadLength,
+ Vcb->NtfsInfo.BytesPerSector,
(PVOID)Buffer,
FALSE);
if (NT_SUCCESS(Status))
@@ -344,6 +351,7 @@
Status = NtfsReadDisk(Vcb->StorageDevice,
DataRunStartLCN *
Vcb->NtfsInfo.BytesPerCluster,
ReadLength,
+ Vcb->NtfsInfo.BytesPerSector,
(PVOID)Buffer,
FALSE);
if (!NT_SUCCESS(Status))
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] Tue Nov 4 07:56:20 2014
@@ -10,6 +10,7 @@
#define TAG_NTFS 'SFTN'
#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
+#define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
#define DEVICE_NAME L"\\Ntfs"
@@ -456,6 +457,7 @@
NtfsReadDisk(IN PDEVICE_OBJECT DeviceObject,
IN LONGLONG StartingOffset,
IN ULONG Length,
+ IN ULONG SectorSize,
IN OUT PUCHAR Buffer,
IN BOOLEAN Override);
Modified: trunk/reactos/drivers/filesystems/ntfs/rw.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/drivers/filesystems/ntfs/r…
==============================================================================
--- trunk/reactos/drivers/filesystems/ntfs/rw.c [iso-8859-1] (original)
+++ trunk/reactos/drivers/filesystems/ntfs/rw.c [iso-8859-1] Tue Nov 4 07:56:20 2014
@@ -31,11 +31,6 @@
#define NDEBUG
#include <debug.h>
-
-/* GLOBALS *******************************************************************/
-
-#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
-#define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
/* FUNCTIONS ****************************************************************/