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
*/
// printk("CurrentIrql %x NewIrql %x OldIrql %x\n",CurrentIrql,NewIrql,
// OldIrql);
DPRINT("CurrentIrql %x NewIrql %x OldIrql %x\n",CurrentIrql,NewIrql,
OldIrql);
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(;;);
}

View file

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

View file

@ -72,7 +72,6 @@ NTSTATUS ZwReadFile(HANDLE FileHandle,
PIRP Irp;
PIO_STACK_LOCATION StackPtr;
KEVENT Event;
NTSTATUS Status;
DPRINT("ZwReadFile(FileHandle %x Buffer %x Length %x ByteOffset %x, "
"IoStatusBlock %x)\n",
@ -138,7 +137,7 @@ NTSTATUS ZwReadFile(HANDLE FileHandle,
}
NTSTATUS ZwWriteFile(HANDLE FileHandle,
HANDLE Event,
HANDLE EventHandle,
PIO_APC_ROUTINE ApcRoutine,
PVOID ApcContext,
PIO_STATUS_BLOCK IoStatusBlock,
@ -152,76 +151,27 @@ NTSTATUS ZwWriteFile(HANDLE FileHandle,
PFILE_OBJECT FileObject = (PFILE_OBJECT)hdr;
PIRP Irp;
PIO_STACK_LOCATION StackPtr;
NTSTATUS Status;
KEVENT Event;
if (hdr==NULL)
{
return(STATUS_INVALID_HANDLE);
}
Irp = IoAllocateIrp(FileObject->DeviceObject->StackSize,TRUE);
if (Irp==NULL)
{
return(STATUS_UNSUCCESSFUL);
}
Irp->UserBuffer = (LPVOID)Buffer;
if (FileObject->DeviceObject->Flags&DO_BUFFERED_IO)
{
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;
}
KeInitializeEvent(&Event,NotificationEvent,FALSE);
Irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
FileObject->DeviceObject,
Buffer,
Length,
ByteOffset,
&Event,
IoStatusBlock);
DPRINT("FileObject->DeviceObject %x\n",FileObject->DeviceObject);
Status = IoCallDriver(FileObject->DeviceObject,Irp);
if (Status==STATUS_PENDING)
{
KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL);
Status = IoStatusBlock->Status;
Status = Irp->IoStatus.Status;
}
return(Status);
}

View file

@ -35,7 +35,7 @@ NTSTATUS IoAttachVpb(PDEVICE_OBJECT DeviceObject)
Vpb->RealDevice = DeviceObject;
Vpb->SerialNumber = 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;
}

View file

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

View file

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

View file

@ -56,12 +56,12 @@ PVOID MmMapLockedPages(PMDL Mdl, KPROCESSOR_MODE AccessMode)
MmCreateMemoryArea(KernelMode,
MEMORY_AREA_MDL_MAPPING,
&base,
Mdl->ByteCount,
Mdl->ByteCount + Mdl->ByteOffset,
0,
&Result);
CHECKPOINT;
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",
base+(i*PAGESIZE),mdl_pages[i]);

View file

@ -244,14 +244,15 @@ void TstFileRead(VOID)
void TstIDERead(void)
{
BOOLEAN TestFailed;
int Entry, i;
int Entry, i, j;
HANDLE FileHandle;
NTSTATUS Status;
LARGE_INTEGER BlockOffset;
ANSI_STRING AnsiDeviceName;
UNICODE_STRING UnicodeDeviceName;
OBJECT_ATTRIBUTES ObjectAttributes;
char SectorBuffer[512];
// static char SectorBuffer2[512 ];
static char SectorBuffer[512 * 10];
PBOOT_BLOCK BootBlock;
ROOT_DIR_ENTRY DirectoryBlock[ENTRIES_PER_BLOCK];
@ -260,7 +261,7 @@ void TstIDERead(void)
/* open the first partition */
DbgPrint("Opening Partition1\n");
RtlInitAnsiString(&AnsiDeviceName, "\\Device\\HardDrive0\\Partition0");
RtlInitAnsiString(&AnsiDeviceName, "\\Device\\HardDrive0\\Partition1");
RtlAnsiStringToUnicodeString(&UnicodeDeviceName, &AnsiDeviceName, TRUE);
InitializeObjectAttributes(&ObjectAttributes,
&UnicodeDeviceName,
@ -279,17 +280,16 @@ void TstIDERead(void)
{
DbgPrint("Reading boot block from Partition1\n");
RtlZeroMemory(SectorBuffer, sizeof(SectorBuffer));
DbgPrint("addr %x\n", SectorBuffer);
Status = ZwReadFile(FileHandle,
NULL,
NULL,
NULL,
NULL,
SectorBuffer,
sizeof(SectorBuffer),
512,
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);
TestFailed = TRUE;
@ -301,17 +301,6 @@ DbgPrint("addr %x\n", SectorBuffer);
/* Spew info about boot block */
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;
DbgPrint("boot block on Partition1:\n");
DbgPrint(" OEM Name: %.8s Bytes/Sector:%d Sectors/Cluster:%d\n",
@ -332,7 +321,6 @@ DbgPrint("addr %x\n", SectorBuffer);
BootBlock->BootParameters.HiddenSectorCount);
DbgPrint(" VolumeLabel:%.11s\n", BootBlock->VolumeLabel);
}
for(;;);
/* Read the first root directory block */
if (!TestFailed)
@ -351,7 +339,7 @@ for(;;);
sizeof(DirectoryBlock),
&BlockOffset,
0);
if (Status != STATUS_SUCCESS /* !NT_SUCCESS(Status) */)
if (!NT_SUCCESS(Status))
{
DbgPrint("Failed to read root directory block from partition1\n");
TestFailed = TRUE;
@ -397,7 +385,7 @@ for(;;);
default:
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].FileAttribute,
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)
{
ZwClose(FileHandle);