IRP Creation Problem in Volume Filter Driver

Hi everybody

i am getting problem with the irp created by the driver (which is acting as
Volume Filter Driver).

Normally the below routine works well for read irp sent for the non-os drive
and for sometime on OS drive also.
But occasionally it fails with PAGE_FAULT<0eh> fault=0000
Actually this error comes as after a call to IoCallDriver function and Its
completion routine (i.e. IoCompletionRead) is called.

Is this because of error in lower driver or their is something wrong with
the IRP creation part in the function.

NTSTATUS ReadFromVolume(
IN PDEVICE_OBJECT DeviceObject,
PIRP pOriginalIrp,
LARGE_INTEGER StartingByteOffset,
ULONG Length ,
PMDL pMdl,
PVOID pUserBuffer,
PIO_STATUS_BLOCK IoStatusBlock
)
{
PIRP pNewIrp;
PDEVICE_EXTENSION deviceExtension;
NTSTATUS status;
PDEVICE_OBJECT pLowerDevice;
PIO_STACK_LOCATION pNextIrpStack;
PIO_STACK_LOCATION pCurrentIrpStack;
KEVENT event;
int i=0;

deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
pLowerDevice=deviceExtension->NextLowerDriver;

//
// Set up the event we’ll use.
//

KeInitializeEvent(&event, SynchronizationEvent, FALSE);

//////////////////////////////////////
pNewIrp=IoAllocateIrp((deviceExtension->NextLowerDriver->StackSize),FALSE );

if (!pNewIrp) {

//
// Allocation failed, presumably due to memory allocation failure.
//

IoStatusBlock->Status = STATUS_INSUFFICIENT_RESOURCES;

IoStatusBlock->Information = 0;

}

pNewIrp->MdlAddress =pMdl;
pNewIrp->RequestorMode =KernelMode;
pNewIrp->UserEvent = &event;
pNewIrp->UserIosb = IoStatusBlock;
pNewIrp->UserBuffer= pUserBuffer;
pNewIrp->Flags=IRP_PAGING_IO ;

pNextIrpStack=IoGetNextIrpStackLocation(pNewIrp);
pNextIrpStack->MinorFunction=0;
pNextIrpStack->MajorFunction=IRP_MJ_READ;
pNextIrpStack->
Parameters.Read.ByteOffset.QuadPart=StartingByteOffset.QuadPart;
pNextIrpStack->Parameters.Read.Length=Length;
///////////////////////////////////////

pNewIrp->Tail.Overlay.Thread=PsGetCurrentThread();//pOriginalIrp->
Tail.Overlay.Thread;
IoSetCompletionRoutine(pNewIrp,IoCompletionRead,NULL,TRUE,TRUE,TRUE);
status=IoCallDriver(deviceExtension->NextLowerDriver,pNewIrp);

DbgPrint(“ReadFromVolume: IoCallDriver return status=0x%x \n”,status);
KeWaitForSingleObject(&event, Executive, KernelMode, TRUE, 0);

return 0;
}

Completion Routine:

NTSTATUS IoCompletionRead(
IN PDEVICE_OBJECT pDevObj,
IN PIRP pIrp,
IN PVOID pContext
)
{
// Copy the status information back into the “user” IOSB.

DbgPrint(“IoCompletionRead: Irp return status=0x%x
\n”,(pIrp->IoStatus).Status);

(pIrp->UserIosb)->Status =(pIrp->IoStatus).Status;
(pIrp->UserIosb)->Information =(pIrp->IoStatus).Information;

// Set the user event - wakes up the mainline code doing this.

KeSetEvent(pIrp->UserEvent, 0, FALSE);

// Free the IRP now that we are done with it.

pIrp->MdlAddress = NULL;

IoFreeIrp(pIrp);

return STATUS_MORE_PROCESSING_REQUIRED;
}

Thanks in Advance
Santosh k


Life is Small and Lots of Things to Learn
Lets Share the Knowledge