Author: arty
Date: Sat Sep 6 14:03:00 2008
New Revision: 35998
URL:
http://svn.reactos.org/svn/reactos?rev=35998&view=rev
Log:
Switch back to our simple read method that includes short reads at EOF.
Implement misaligned reads in cdfs. We can boot to 'Detecting devices' and
get a moving mouse on the livecd.
Modified:
branches/arty-newcc/drivers/filesystems/cdfs/rw.c
branches/arty-newcc/ntoskrnl/mm/section.c
Modified: branches/arty-newcc/drivers/filesystems/cdfs/rw.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/drivers/filesystems/…
==============================================================================
--- branches/arty-newcc/drivers/filesystems/cdfs/rw.c [iso-8859-1] (original)
+++ branches/arty-newcc/drivers/filesystems/cdfs/rw.c [iso-8859-1] Sat Sep 6 14:03:00
2008
@@ -87,6 +87,10 @@
FileSizes.FileSize = Fcb->RFCB.FileSize;
FileSizes.ValidDataLength = Fcb->RFCB.ValidDataLength;
+ DPRINT("Attach FCB to File: Size %08x%08x\n",
+ Fcb->RFCB.ValidDataLength.HighPart,
+ Fcb->RFCB.ValidDataLength.LowPart);
+
CcInitializeCacheMap(FileObject,
&FileSizes,
FALSE,
@@ -108,25 +112,65 @@
if ((ReadOffset % BLOCKSIZE) != 0 || (Length % BLOCKSIZE) != 0)
{
- return STATUS_INVALID_PARAMETER;
- }
-
- if (ReadOffset + Length > ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE))
- Length = ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE) - ReadOffset;
-
- Status = CdfsReadSectors(DeviceExt->StorageDevice,
- Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE),
- Length / BLOCKSIZE,
- Buffer,
- FALSE);
- if (NT_SUCCESS(Status))
- {
- *LengthRead = Length;
- if (Length + ReadOffset > Fcb->Entry.DataLengthL)
- {
- memset(Buffer + Fcb->Entry.DataLengthL - ReadOffset,
- 0,
- Length + ReadOffset - Fcb->Entry.DataLengthL);
+ /* Then we need to do a partial or misaligned read ... */
+ PVOID PageBuf = ExAllocatePool(NonPagedPool, BLOCKSIZE);
+ PCHAR ReadInPage = (PCHAR)PageBuf + (ReadOffset & (BLOCKSIZE - 1));
+ PCHAR TargetRead = (PCHAR)Buffer;
+ ULONG ActualReadOffset, EndOfExtent, ReadLen;
+
+ if (!PageBuf)
+ {
+ return STATUS_NO_MEMORY;
+ }
+
+ ActualReadOffset = ReadOffset & ~(BLOCKSIZE - 1);
+ EndOfExtent = ReadOffset + Length;
+
+ while (ActualReadOffset < EndOfExtent)
+ {
+ Status = CdfsReadSectors
+ (DeviceExt->StorageDevice,
+ Fcb->Entry.ExtentLocationL + (ActualReadOffset / BLOCKSIZE),
+ 1,
+ PageBuf,
+ FALSE);
+
+ if (!NT_SUCCESS(Status))
+ break;
+
+ ReadLen = BLOCKSIZE - (ActualReadOffset & (BLOCKSIZE - 1));
+ if (ReadLen > EndOfExtent - ActualReadOffset)
+ {
+ ReadLen = EndOfExtent - ActualReadOffset;
+ }
+
+ RtlCopyMemory(TargetRead, ReadInPage, ReadLen);
+
+ ActualReadOffset += ReadLen;
+ TargetRead += ReadLen;
+ }
+
+ ExFreePool(PageBuf);
+ }
+ else
+ {
+ if (ReadOffset + Length > ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE))
+ Length = ROUND_UP(Fcb->Entry.DataLengthL, BLOCKSIZE) - ReadOffset;
+
+ Status = CdfsReadSectors(DeviceExt->StorageDevice,
+ Fcb->Entry.ExtentLocationL + (ReadOffset / BLOCKSIZE),
+ Length / BLOCKSIZE,
+ Buffer,
+ FALSE);
+ if (NT_SUCCESS(Status))
+ {
+ *LengthRead = Length;
+ if (Length + ReadOffset > Fcb->Entry.DataLengthL)
+ {
+ memset(Buffer + Fcb->Entry.DataLengthL - ReadOffset,
+ 0,
+ Length + ReadOffset - Fcb->Entry.DataLengthL);
+ }
}
}
Modified: branches/arty-newcc/ntoskrnl/mm/section.c
URL:
http://svn.reactos.org/svn/reactos/branches/arty-newcc/ntoskrnl/mm/section.…
==============================================================================
--- branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] (original)
+++ branches/arty-newcc/ntoskrnl/mm/section.c [iso-8859-1] Sat Sep 6 14:03:00 2008
@@ -147,34 +147,54 @@
ULONG Length,
PIO_STATUS_BLOCK ReadStatus)
{
- PMDL Mdl;
+ NTSTATUS Status;
+ PIRP Irp = NULL;
KEVENT ReadWait;
- NTSTATUS Status = STATUS_SUCCESS;
-
- KeInitializeEvent(&ReadWait, SynchronizationEvent, FALSE);
-
- Mdl = IoAllocateMdl(Buffer, Length, FALSE, TRUE, NULL);
-
- if (!Mdl) return STATUS_NO_MEMORY;
-
- _SEH_TRY
+ PDEVICE_OBJECT DeviceObject;
+ PIO_STACK_LOCATION IrpSp;
+
+ ASSERT(FileObject);
+ ASSERT(FileOffset);
+ ASSERT(Buffer);
+ ASSERT(ReadStatus);
+
+ DeviceObject = MmGetDeviceObjectForFile(FileObject);
+
+ ASSERT(DeviceObject);
+
+ DPRINT1
+ ("PAGING READ: FileObject %x Offset %x Length %d\n",
+ &FileObject,
+ FileOffset->LowPart,
+ Length);
+
+ KeInitializeEvent(&ReadWait, NotificationEvent, FALSE);
+
+ Irp = IoBuildAsynchronousFsdRequest
+ (IRP_MJ_READ,
+ DeviceObject,
+ Buffer,
+ Length,
+ FileOffset,
+ ReadStatus);
+
+ if (!Irp)
{
- MmProbeAndLockPages(Mdl, KernelMode, IoWriteAccess);
- }
- _SEH_HANDLE
- {
- /* Allocating failed, clean up */
- Status = _SEH_GetExceptionCode();
- }
- _SEH_END;
-
- if (!NT_SUCCESS(Status))
- {
- IoFreeMdl(Mdl);
- return Status;
+ return STATUS_NO_MEMORY;
}
- Status = IoPageRead(FileObject, Mdl, FileOffset, &ReadWait, ReadStatus);
+ Irp->Flags |= IRP_PAGING_IO | IRP_SYNCHRONOUS_PAGING_IO | IRP_NOCACHE;
+
+ ObReferenceObject(FileObject);
+
+ Irp->UserEvent = &ReadWait;
+ Irp->Tail.Overlay.OriginalFileObject = FileObject;
+ Irp->Tail.Overlay.Thread = PsGetCurrentThread();
+ IrpSp = IoGetNextIrpStackLocation(Irp);
+ IrpSp->FileObject = FileObject;
+ IrpSp->CompletionRoutine = MiSimpleReadComplete;
+
+ Status = IoCallDriver(DeviceObject, Irp);
if (Status == STATUS_PENDING)
{
if (!NT_SUCCESS
@@ -186,22 +206,15 @@
NULL)))
{
DPRINT1("Warning: Failed to wait for synchronous IRP\n");
- MmUnlockPages(Mdl);
- IoFreeMdl(Mdl);
+ ASSERT(FALSE);
+ ObDereferenceObject(FileObject);
return Status;
}
}
-
- DPRINT("MmUnlockPages(%p)\n", Mdl);
- MmUnlockPages(Mdl);
- IoFreeMdl(Mdl);
-
- DPRINT("Paging IO Done: %08x [%02x %02x %02x %02x ...]\n",
ReadStatus->Status,
- ((PCHAR)Buffer)[0] & 0xff,
- ((PCHAR)Buffer)[1] & 0xff,
- ((PCHAR)Buffer)[2] & 0xff,
- ((PCHAR)Buffer)[3] & 0xff);
-
+
+ ObDereferenceObject(FileObject);
+
+ DPRINT("Paging IO Done: %08x\n", ReadStatus->Status);
return ReadStatus->Status;
}