You have set the parameters for the transfer, but you have not set up the transfer buffer, or may have set it up incorrectly.
Who is the lower device object? i.e. who are you submitting IRPs to? Is it an I/O device, or a filesystem?
You’re going to need to learn a few things about IRP_MJ_READ and IRP_MJ_WRITE before you continue. Read/write IRPs can be quite complicated. They can potentially be part of the paging path, they can be submitted at various dispatch levels, etc.
You’ll need to understand buffered vs. direct I/O, and you’ll need to make sure that you’re building the kind of read/write IRPs that the target device object is expecting. Read the documentation on IRP_MJ_READ. If the device is using buffered I/O, you’ll need to set Irp->AssociatedIrp.SystemBuffer to a pointer to kernel pool (*not* a user-mode process-relative address). In all likelihood, it needs to be non-paged, unless you have a really firm grasp of paged vs. non-paged pool, and you know what your lower driver is expecting. But I don’t think you’re there yet. If the device is using direct I/O, you’ll need to understand what MDLs (Memory Descriptor Lists) are and how to properly use them. The transfer MDL is stored at Irp->MdlAddress.
Also, if you are a layered device driver, i.e. a FDO or an FiDO, you can simply use the IRP stacks, as they were intended, rather than building a whole new IRP.
Honestly, I think you need to read more and understand the architecture more before you just pound away on a driver until it limps along. There are a lot of good resources, both in print and on the web.
If you want to continue, please post the output of !analyze -v, and make sure your symbols are loaded correctly. People here are willing to help, but only if you are willing to do your homework.
– arlie
-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Friday, September 08, 2006 4:45 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Making a new IRP and Copy IRP Parameters
Hello All,
I have changed my code as guided but still getting the same problem. Below is my code:
PIrpLocal = IoAllocateIrp (DeviceObject->StackSize,FALSE);
if(PIrpLocal==NULL)
{
DbgPrint(“GenerateIRP()…PIrpLocal Not Allocated IRP\n”);
DbgPrint(“GenerateIRP()…IoBuildAsynchronousFsdRequest FAILED\n”);
return STATUS_INSUFFICIENT_RESOURCES;
}
else
{
DbgPrint(“GenerateIRP()…PIrpLocal Allocated Successfully IRP\n”);
//IoInitializeIrp (PIrpLocal,IoManagerIrp->Size,(CCHAR)(IoManagerIrp->StackCount));
MyIrpStack= IoGetNextIrpStackLocation(PIrpLocal);
switch (irpStack->MajorFunction)
{
case IRP_MJ_READ:
{
MyIrpStack->Parameters.Read.Length = irpStack->Parameters.Read.Length;
MyIrpStack->Parameters.Read.Key = irpStack->Parameters.Read.Key;
MyIrpStack->Parameters.Read.ByteOffset = irpStack
->Parameters.Read.ByteOffset;
MyIrpStack->MajorFunction = irpStack->MajorFunction;
MyIrpStack->MinorFunction = irpStack->MinorFunction;
PDiskIrp->ReadWriteOffset= irpStack->Parameters.Read.ByteOffset;
break;
}
case IRP_MJ_WRITE:
{
MyIrpStack->Parameters.Write.Length = irpStack->Parameters.Write.Length;
MyIrpStack->Parameters.Write.Key = irpStack->Parameters.Write.Key;
MyIrpStack->Parameters.Write.ByteOffset = irpStack- >Parameters.Write.ByteOffset;
MyIrpStack->MajorFunction = irpStack->MajorFunction;
MyIrpStack->MinorFunction = irpStack->MinorFunction;
PDiskIrp->ReadWriteOffset= irpStack->Parameters.Write.ByteOffset;
break;
}
}
/*New*/FillingIrpArguments(PIrpLocal,IoManagerIrp);
IoSetCompletionRoutine( PIrpLocal,
(PIO_COMPLETION_ROUTINE)CompletionRoutine,
(PDISK_IRP)PDiskIrp,
TRUE,
TRUE,
TRUE);
}
status = IoCallDriver(DeviceObject, PIrpLocal);
if (status == STATUS_PENDING){
IoMarkIrpPending (IoManagerIrp);
return STATUS_PENDING;
}
return status;
}
NTSTATUS CompletionRoutine(PDEVICE_OBJECT fdo, PIRP Irp, PDISK_IRP PDisk_Irp)
{
PIRP OriginalIrp;
PMDL mdl, nextMdl;
ULONG ReadWriteLength;
NTSTATUS Status;
ULONG Information;
PIO_STACK_LOCATION irpStack;
PUCHAR OriginalBuffVA,MyBuffVA;
OriginalIrp = PDisk_Irp->POriginalIrp;
OriginalIrp->IoStatus.Status = Irp->IoStatus.Status;
OriginalIrp->IoStatus.Information = Irp->IoStatus.Information;
IoCompleteRequest(OriginalIrp, IO_NO_INCREMENT);
IoFreeIrp(Irp);
return STATUS_MORE_PROCESSING_REQUIRED;
}
void FillingIrpArguments(PIRP PIrpLocal,PIRP IoManagerIrp)
{
PIrpLocal->MdlAddress = IoManagerIrp->MdlAddress;
PIrpLocal->UserBuffer = IoManagerIrp->UserBuffer;
PIrpLocal->RequestorMode=IoManagerIrp->RequestorMode;
}
Thanks,
Uzair Lakhani
Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer