fixes and changes to support IDE driver

svn path=/trunk/; revision=45
This commit is contained in:
Rex Jolliff 1998-09-15 14:31:18 +00:00
parent 4bbc8ea6ef
commit 7967ac94a2
8 changed files with 129 additions and 103 deletions

View file

@ -118,11 +118,12 @@ VOID KeRaiseIrql(KIRQL NewIrql, PKIRQL OldIrql)
/* /*
* sanity check * sanity check
*/ */
// printk("CurrentIrql %x NewIrql %x OldIrql %x\n",CurrentIrql,NewIrql, DPRINT("CurrentIrql %x NewIrql %x OldIrql %x\n",CurrentIrql,NewIrql,
// OldIrql); OldIrql);
if (NewIrql < CurrentIrql) if (NewIrql < CurrentIrql)
{ {
DbgPrint("%s:%d\n",__FILE__,__LINE__); DbgPrint("%s:%d CurrentIrql %x NewIrql %x OldIrql %x\n",__FILE__,__LINE__,
CurrentIrql,NewIrql,OldIrql);
for(;;); for(;;);
} }

View file

@ -192,6 +192,10 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
{ {
return(NULL); return(NULL);
} }
if (MajorFunction == IRP_MJ_WRITE)
{
RtlCopyMemory(Irp->AssociatedIrp.SystemBuffer, Buffer, Length);
}
Irp->UserBuffer = NULL; Irp->UserBuffer = NULL;
} }
if (DeviceObject->Flags&DO_DIRECT_IO) if (DeviceObject->Flags&DO_DIRECT_IO)
@ -199,7 +203,14 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
DPRINT("Doing direct i/o\n",0); DPRINT("Doing direct i/o\n",0);
Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length); Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length);
if (MajorFunction == IRP_MJ_READ)
{
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess); MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoWriteAccess);
}
else
{
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoReadAccess);
}
Irp->UserBuffer = NULL; Irp->UserBuffer = NULL;
Irp->AssociatedIrp.SystemBuffer = NULL; Irp->AssociatedIrp.SystemBuffer = NULL;
} }
@ -215,6 +226,23 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
StackPtr->DeviceObject = DeviceObject; StackPtr->DeviceObject = DeviceObject;
StackPtr->FileObject = NULL; StackPtr->FileObject = NULL;
StackPtr->Parameters.Write.Length = Length; StackPtr->Parameters.Write.Length = Length;
if (MajorFunction == IRP_MJ_READ)
{
if (StartingOffset!=NULL)
{
StackPtr->Parameters.Read.ByteOffset.LowPart =
StartingOffset->LowPart;
StackPtr->Parameters.Read.ByteOffset.HighPart =
StartingOffset->HighPart;
}
else
{
StackPtr->Parameters.Read.ByteOffset.LowPart = 0;
StackPtr->Parameters.Read.ByteOffset.HighPart = 0;
}
}
else
{
if (StartingOffset!=NULL) if (StartingOffset!=NULL)
{ {
StackPtr->Parameters.Write.ByteOffset.LowPart = StackPtr->Parameters.Write.ByteOffset.LowPart =
@ -227,6 +255,7 @@ PIRP IoBuildSynchronousFsdRequest(ULONG MajorFunction,
StackPtr->Parameters.Write.ByteOffset.LowPart = 0; StackPtr->Parameters.Write.ByteOffset.LowPart = 0;
StackPtr->Parameters.Write.ByteOffset.HighPart = 0; StackPtr->Parameters.Write.ByteOffset.HighPart = 0;
} }
}
return(Irp); return(Irp);
} }

View file

@ -72,7 +72,6 @@ NTSTATUS ZwReadFile(HANDLE FileHandle,
PIRP Irp; PIRP Irp;
PIO_STACK_LOCATION StackPtr; PIO_STACK_LOCATION StackPtr;
KEVENT Event; KEVENT Event;
NTSTATUS Status;
DPRINT("ZwReadFile(FileHandle %x Buffer %x Length %x ByteOffset %x, " DPRINT("ZwReadFile(FileHandle %x Buffer %x Length %x ByteOffset %x, "
"IoStatusBlock %x)\n", "IoStatusBlock %x)\n",
@ -138,7 +137,7 @@ NTSTATUS ZwReadFile(HANDLE FileHandle,
} }
NTSTATUS ZwWriteFile(HANDLE FileHandle, NTSTATUS ZwWriteFile(HANDLE FileHandle,
HANDLE Event, HANDLE EventHandle,
PIO_APC_ROUTINE ApcRoutine, PIO_APC_ROUTINE ApcRoutine,
PVOID ApcContext, PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock, PIO_STATUS_BLOCK IoStatusBlock,
@ -152,76 +151,27 @@ NTSTATUS ZwWriteFile(HANDLE FileHandle,
PFILE_OBJECT FileObject = (PFILE_OBJECT)hdr; PFILE_OBJECT FileObject = (PFILE_OBJECT)hdr;
PIRP Irp; PIRP Irp;
PIO_STACK_LOCATION StackPtr; PIO_STACK_LOCATION StackPtr;
NTSTATUS Status; KEVENT Event;
if (hdr==NULL) if (hdr==NULL)
{ {
return(STATUS_INVALID_HANDLE); return(STATUS_INVALID_HANDLE);
} }
Irp = IoAllocateIrp(FileObject->DeviceObject->StackSize,TRUE); KeInitializeEvent(&Event,NotificationEvent,FALSE);
if (Irp==NULL) Irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
{ FileObject->DeviceObject,
return(STATUS_UNSUCCESSFUL); Buffer,
} Length,
ByteOffset,
Irp->UserBuffer = (LPVOID)Buffer; &Event,
if (FileObject->DeviceObject->Flags&DO_BUFFERED_IO) IoStatusBlock);
{
DPRINT1("Doing buffer i/o\n");
Irp->AssociatedIrp.SystemBuffer = (PVOID)
ExAllocatePool(NonPagedPool,Length);
if (Irp->AssociatedIrp.SystemBuffer==NULL)
{
return(STATUS_UNSUCCESSFUL);
}
memcpy(Irp->AssociatedIrp.SystemBuffer,Buffer,Length);
Irp->UserBuffer = NULL;
}
if (FileObject->DeviceObject->Flags&DO_DIRECT_IO)
{
DPRINT1("Doing direct i/o\n");
Irp->MdlAddress = MmCreateMdl(NULL,Buffer,Length);
MmProbeAndLockPages(Irp->MdlAddress,UserMode,IoReadAccess);
Irp->UserBuffer = NULL;
Irp->AssociatedIrp.SystemBuffer = NULL;
}
StackPtr = IoGetNextIrpStackLocation(Irp);
DPRINT("StackPtr %x\n",StackPtr);
StackPtr->MajorFunction = IRP_MJ_WRITE;
StackPtr->MinorFunction = 0;
StackPtr->Flags = 0;
StackPtr->Control = 0;
StackPtr->DeviceObject = FileObject->DeviceObject;
StackPtr->FileObject = FileObject;
StackPtr->Parameters.Write.Length = Length;
if (ByteOffset!=NULL)
{
StackPtr->Parameters.Write.ByteOffset.LowPart = ByteOffset->LowPart;
StackPtr->Parameters.Write.ByteOffset.HighPart = ByteOffset->HighPart;
}
else
{
StackPtr->Parameters.Write.ByteOffset.LowPart = 0;
StackPtr->Parameters.Write.ByteOffset.HighPart = 0;
}
if (Key!=NULL)
{
StackPtr->Parameters.Write.Key = *Key;
}
else
{
StackPtr->Parameters.Write.Key = 0;
}
DPRINT("FileObject->DeviceObject %x\n",FileObject->DeviceObject); DPRINT("FileObject->DeviceObject %x\n",FileObject->DeviceObject);
Status = IoCallDriver(FileObject->DeviceObject,Irp); Status = IoCallDriver(FileObject->DeviceObject,Irp);
if (Status==STATUS_PENDING) if (Status==STATUS_PENDING)
{ {
KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL); KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL);
Status = IoStatusBlock->Status; Status = Irp->IoStatus.Status;
} }
return(Status); return(Status);
} }

View file

@ -35,7 +35,7 @@ NTSTATUS IoAttachVpb(PDEVICE_OBJECT DeviceObject)
Vpb->RealDevice = DeviceObject; Vpb->RealDevice = DeviceObject;
Vpb->SerialNumber = 0; Vpb->SerialNumber = 0;
Vpb->ReferenceCount = 0; Vpb->ReferenceCount = 0;
memset(Vpb->VolumeLabel,0,sizeof(WCHAR)*MAXIMUM_VOLUME_LABEL_LENGTH); RtlZeroMemory(Vpb->VolumeLabel,sizeof(WCHAR)*MAXIMUM_VOLUME_LABEL_LENGTH);
DeviceObject->Vpb = Vpb; DeviceObject->Vpb = Vpb;
} }

View file

@ -102,7 +102,7 @@ BOOLEAN KeInsertQueueDpc(PKDPC dpc, PVOID SystemArgument1,
*/ */
{ {
DPRINT("KeInsertQueueDpc()\n",0); DPRINT("KeInsertQueueDpc()\n",0);
assert(KeGetCurrentIrql()==DISPATCH_LEVEL); assert(KeGetCurrentIrql()>=DISPATCH_LEVEL);
dpc->Number=0; dpc->Number=0;
dpc->Importance=Medium; dpc->Importance=Medium;
@ -115,7 +115,7 @@ BOOLEAN KeInsertQueueDpc(PKDPC dpc, PVOID SystemArgument1,
KeAcquireSpinLockAtDpcLevel(&DpcQueueLock); KeAcquireSpinLockAtDpcLevel(&DpcQueueLock);
InsertHeadList(&DpcQueueHead,&dpc->DpcListEntry); InsertHeadList(&DpcQueueHead,&dpc->DpcListEntry);
KeReleaseSpinLockFromDpcLevel(&DpcQueueLock); KeReleaseSpinLockFromDpcLevel(&DpcQueueLock);
dpc->Lock=1; dpc->Lock=(PULONG)1;
DPRINT("DpcQueueHead.Flink %x\n",DpcQueueHead.Flink); DPRINT("DpcQueueHead.Flink %x\n",DpcQueueHead.Flink);
DPRINT("Leaving KeInsertQueueDpc()\n",0); DPRINT("Leaving KeInsertQueueDpc()\n",0);
return(TRUE); return(TRUE);

View file

@ -21,7 +21,7 @@
#include <internal/mm.h> #include <internal/mm.h>
#include <internal/module.h> #include <internal/module.h>
//#define NDEBUG #define NDEBUG
#include <internal/debug.h> #include <internal/debug.h>
/* FUNCTIONS **************************************************************/ /* FUNCTIONS **************************************************************/

View file

@ -56,12 +56,12 @@ PVOID MmMapLockedPages(PMDL Mdl, KPROCESSOR_MODE AccessMode)
MmCreateMemoryArea(KernelMode, MmCreateMemoryArea(KernelMode,
MEMORY_AREA_MDL_MAPPING, MEMORY_AREA_MDL_MAPPING,
&base, &base,
Mdl->ByteCount, Mdl->ByteCount + Mdl->ByteOffset,
0, 0,
&Result); &Result);
CHECKPOINT; CHECKPOINT;
mdl_pages = (ULONG *)(Mdl + 1); mdl_pages = (ULONG *)(Mdl + 1);
for (i=0; i<(PAGE_ROUND_UP(Mdl->ByteCount)/PAGESIZE); i++) for (i=0; i<(PAGE_ROUND_UP(Mdl->ByteCount + Mdl->ByteOffset)/PAGESIZE); i++)
{ {
DPRINT("Writing %x with physical address %x\n", DPRINT("Writing %x with physical address %x\n",
base+(i*PAGESIZE),mdl_pages[i]); base+(i*PAGESIZE),mdl_pages[i]);

View file

@ -244,14 +244,15 @@ void TstFileRead(VOID)
void TstIDERead(void) void TstIDERead(void)
{ {
BOOLEAN TestFailed; BOOLEAN TestFailed;
int Entry, i; int Entry, i, j;
HANDLE FileHandle; HANDLE FileHandle;
NTSTATUS Status; NTSTATUS Status;
LARGE_INTEGER BlockOffset; LARGE_INTEGER BlockOffset;
ANSI_STRING AnsiDeviceName; ANSI_STRING AnsiDeviceName;
UNICODE_STRING UnicodeDeviceName; UNICODE_STRING UnicodeDeviceName;
OBJECT_ATTRIBUTES ObjectAttributes; OBJECT_ATTRIBUTES ObjectAttributes;
char SectorBuffer[512]; // static char SectorBuffer2[512 ];
static char SectorBuffer[512 * 10];
PBOOT_BLOCK BootBlock; PBOOT_BLOCK BootBlock;
ROOT_DIR_ENTRY DirectoryBlock[ENTRIES_PER_BLOCK]; ROOT_DIR_ENTRY DirectoryBlock[ENTRIES_PER_BLOCK];
@ -260,7 +261,7 @@ void TstIDERead(void)
/* open the first partition */ /* open the first partition */
DbgPrint("Opening Partition1\n"); DbgPrint("Opening Partition1\n");
RtlInitAnsiString(&AnsiDeviceName, "\\Device\\HardDrive0\\Partition0"); RtlInitAnsiString(&AnsiDeviceName, "\\Device\\HardDrive0\\Partition1");
RtlAnsiStringToUnicodeString(&UnicodeDeviceName, &AnsiDeviceName, TRUE); RtlAnsiStringToUnicodeString(&UnicodeDeviceName, &AnsiDeviceName, TRUE);
InitializeObjectAttributes(&ObjectAttributes, InitializeObjectAttributes(&ObjectAttributes,
&UnicodeDeviceName, &UnicodeDeviceName,
@ -279,17 +280,16 @@ void TstIDERead(void)
{ {
DbgPrint("Reading boot block from Partition1\n"); DbgPrint("Reading boot block from Partition1\n");
RtlZeroMemory(SectorBuffer, sizeof(SectorBuffer)); RtlZeroMemory(SectorBuffer, sizeof(SectorBuffer));
DbgPrint("addr %x\n", SectorBuffer);
Status = ZwReadFile(FileHandle, Status = ZwReadFile(FileHandle,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
SectorBuffer, SectorBuffer,
sizeof(SectorBuffer), 512,
0, 0,
0); 0);
if (Status != STATUS_SUCCESS /* !NT_SUCCESS(Status) */) if (!NT_SUCCESS(Status))
{ {
DbgPrint("Failed to read book block from partition1 status:%x\n", Status); DbgPrint("Failed to read book block from partition1 status:%x\n", Status);
TestFailed = TRUE; TestFailed = TRUE;
@ -301,17 +301,6 @@ DbgPrint("addr %x\n", SectorBuffer);
/* Spew info about boot block */ /* Spew info about boot block */
if (!TestFailed) if (!TestFailed)
{ {
for (i = 0; i < 64; i++)
{
if (!(i % 16))
{
DbgPrint("\n%04d: ", i);
}
DbgPrint("%02x ", (unsigned char)SectorBuffer[i]);
}
DbgPrint("\n");
BootBlock = (PBOOT_BLOCK) SectorBuffer; BootBlock = (PBOOT_BLOCK) SectorBuffer;
DbgPrint("boot block on Partition1:\n"); DbgPrint("boot block on Partition1:\n");
DbgPrint(" OEM Name: %.8s Bytes/Sector:%d Sectors/Cluster:%d\n", DbgPrint(" OEM Name: %.8s Bytes/Sector:%d Sectors/Cluster:%d\n",
@ -332,7 +321,6 @@ DbgPrint("addr %x\n", SectorBuffer);
BootBlock->BootParameters.HiddenSectorCount); BootBlock->BootParameters.HiddenSectorCount);
DbgPrint(" VolumeLabel:%.11s\n", BootBlock->VolumeLabel); DbgPrint(" VolumeLabel:%.11s\n", BootBlock->VolumeLabel);
} }
for(;;);
/* Read the first root directory block */ /* Read the first root directory block */
if (!TestFailed) if (!TestFailed)
@ -351,7 +339,7 @@ for(;;);
sizeof(DirectoryBlock), sizeof(DirectoryBlock),
&BlockOffset, &BlockOffset,
0); 0);
if (Status != STATUS_SUCCESS /* !NT_SUCCESS(Status) */) if (!NT_SUCCESS(Status))
{ {
DbgPrint("Failed to read root directory block from partition1\n"); DbgPrint("Failed to read root directory block from partition1\n");
TestFailed = TRUE; TestFailed = TRUE;
@ -397,7 +385,7 @@ for(;;);
default: default:
DbgPrint(" FILE: %.8s.%.3s ATTR:%x Time:%04x Date:%04x offset:%d size:%d\n", DbgPrint(" FILE: %.8s.%.3s ATTR:%x Time:%04x Date:%04x offset:%d size:%d\n",
&DirectoryBlock[Entry].Filename[1], DirectoryBlock[Entry].Filename,
DirectoryBlock[Entry].Extension, DirectoryBlock[Entry].Extension,
DirectoryBlock[Entry].FileAttribute, DirectoryBlock[Entry].FileAttribute,
DirectoryBlock[Entry].ModifiedTime, DirectoryBlock[Entry].ModifiedTime,
@ -408,6 +396,64 @@ for(;;);
} }
} }
} }
/* Execute a multiblock disk read/write test */
if (!TestFailed)
{
DbgPrint("Reading data from blocks 10000-4 from Partition1\n");
RtlFillMemory(SectorBuffer, sizeof(SectorBuffer), 0xea);
BlockOffset.HighPart = 0;
BlockOffset.LowPart = 10000 * 512;
Status = ZwReadFile(FileHandle,
NULL,
NULL,
NULL,
NULL,
SectorBuffer,
512 * 5,
&BlockOffset,
0);
if (!NT_SUCCESS(Status))
{
DbgPrint("Failed to read blocks 10000-4 from partition1 status:%x\n",
Status);
TestFailed = TRUE;
}
else
{
for (j = 0; j < 10; j++)
{
DbgPrint("%04x: ", j * 256);
for (i = 0; i < 16; i++)
{
DbgPrint("%02x ", (unsigned char)SectorBuffer[j * 256 + i]);
SectorBuffer[j * 256 + i]++;
}
DbgPrint("\n");
}
for(;;);
Status = ZwWriteFile(FileHandle,
NULL,
NULL,
NULL,
NULL,
SectorBuffer,
512 * 5,
&BlockOffset,
0);
if (!NT_SUCCESS(Status))
{
DbgPrint("Failed to write blocks 10000-4 to partition1 status:%x\n",
Status);
TestFailed = TRUE;
}
else
{
DbgPrint("Block written\n");
}
}
}
if (FileHandle != NULL) if (FileHandle != NULL)
{ {
ZwClose(FileHandle); ZwClose(FileHandle);