I am writing a device driver that creates a disk device whose reads and
writes are redirected to reads and writes to a disk device.
In my read dispatch routine I am calling IoBuildAsynchronousFsdRequest() to
create a new request. I then set a completion routine passing the original
IRP as the context parameter. Then I mark the original IRP pending by
calling IoMarkIrpPending(). I then call IoCallDriver and return its status
which, I think, should either be STATUS_PENDING or a failure.
PUCHAR currentAddress;
ASSERT ( Irp->MdlAddress != NULL );
currentAddress = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
NormalPagePriority );
.
.
.
case IRP_MJ_READ:
// Get the length and offset
length = MmGetMdlByteCount(Irp->MdlAddress) ;
// liAdd is a wrapper around the way-too-long RtlLargIntegerAdd() call
byteOffset = liAdd (devExt->StartByte,
irpStack->Parameters.Read.ByteOffset) ;
irp0 = IoBuildAsynchronousFsdRequest (IRP_MJ_READ,
devExt->DiskDevice,
currentAddress,
length,
&byteOffset,
NULL) ;
if (irp0 == NULL)
{
status = STATUS_INSUFFICIENT_RESOURCES ;
COMPLETE_REQUEST( Irp, status, information );
IoReleaseRemoveLock(&devExt->RemoveLock, Irp);
return status;
}
IoSetCompletionRoutine (irp0,
VfDiskReadWriteCompletionRoutine,
Irp, // Pass in the original IRP as the context for the completion
routine.
TRUE,
TRUE,
TRUE) ;
// Mark the original IRP as pending
IoMarkIrpPending (Irp) ;
// Call the disk driver
status = IoCallDriver (devExt->DiskDevice, irp0) ;
return status ;
I’m not quite sure what to do in my completion routine. Should I complete
the original IRP? How do I know what status to return?
NTSTATUS VfDiskReadWriteCompletionRoutine (IN PDEVICE_OBJECT deviceObject,
IN PIRP irp,
IN PVOID context)
{
NTSTATUS status ;
PIRP masterIrp ;
ULONG information = 0 ;
// We passed in the master IRP as the context ;
masterIrp = (PIRP)context ;
if( irp->PendingReturned )
{
IoMarkIrpPending(irp);
status = STATUS_MORE_PROCESSING_REQUIRED ;
return status ;
}
status = STATUS_SUCCESS ;
COMPLETE_REQUEST ( masterIrp, status, information );
IoFreeIrp (irp) ;
return status ;
}
Thanks,
Jonathan
You are currently subscribed to ntfsd as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntfsd-$subst(‘Recip.MemberIDChar’)@lists.osr.com