IRP_MJ_READ

Hi,

I want to adjust what read by a lower driver in my filter driver. where can
I do that and how? my driver use buffered I/O and it’s operation is
asychronous.

It’s a hard question to answer, because (a) You’re not specific of exactly what you want to “adjust” and (b) It sounds like your basic question comes down to “How do I write a filter driver?”

Having said that, you can “adjust what read” by changing (for example) the starting offset parameter in the next IO_STACK_LOCATION.

We might be able to help more if you give us more details.

Peter
OSR

Also, is the device you are filtering also buffered i/o? you need to
match the I/O type of the device you are filtering w/out hard coding the
type

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@osr.com
Sent: Saturday, August 05, 2006 6:24 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] IRP_MJ_READ

It’s a hard question to answer, because (a) You’re not specific of
exactly what you want to “adjust” and (b) It sounds like your basic
question comes down to “How do I write a filter driver?”

Having said that, you can “adjust what read” by changing (for example)
the starting offset parameter in the next IO_STACK_LOCATION.

We might be able to help more if you give us more details.

Peter
OSR


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

I want to read data from a lower driver such as modem,
and modfiy data that read from that. I used following code for doing this.
but when it reaches “KeWaitForSingleObject” it will stops. and if I try to
disable device , Windows asks me to restart the computer.

NTSTATUS DRV3ReadDispatch(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
PDRV3_DEVICE_EXTENSION deviceExtension;
NTSTATUS status;
KEVENT event;

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION"++. IRP %p", Irp);

// Get our device extension from the device object
deviceExtension = (PDRV3_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

// Make sure we can accept IRPs
if (!DRV3AcquireRemoveLock(deviceExtension))
{
status = STATUS_DELETE_PENDING;

Irp->IoStatus.Status = status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);

DRV3DebugPrint(DBG_GENERAL, DBG_WARN, FUNCTION"–. IRP %p STATUS
%x", Irp, status);

return status;
}

KeInitializeEvent(&event, NotificationEvent, FALSE);

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION".After
KeInitializeEvent. IRP %p", Irp);

IoCopyCurrentIrpStackLocationToNext(Irp);

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION".After
IoCopyCurrentIrpStackLocationToNext. IRP %p", Irp);

IoSetCompletionRoutine(
Irp,
(PIO_COMPLETION_ROUTINE)DRV3IoCompletionRead,
&event,
TRUE,
FALSE,
FALSE
);

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION".After
IoSetCompletionRoutine. IRP %p", Irp);

status = IoCallDriver(deviceExtension->LowerDeviceObject, Irp);
DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION".After IoCallDriver.
IRP %p %x", Irp, status);

if (status == STATUS_PENDING)
{
KeWaitForSingleObject(
&event,
Executive,
KernelMode,
FALSE,
NULL
);

status = Irp->IoStatus.Status;

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION".After
KeWaitForSingleObject. IRP %p %x", Irp, status);
}

IoCompleteRequest(Irp, IO_NO_INCREMENT);

DRV3ReleaseRemoveLock(deviceExtension);

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION"–. IRP %p STATUS
%x", Irp, status);

return status;
}

NTSTATUS DRV3IoCompletionRead(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)
{
PKEVENT event = (PKEVENT)Context;

if (Irp->PendingReturned)
{
KeSetEvent(event, IO_NO_INCREMENT, FALSE);
}

return STATUS_MORE_PROCESSING_REQUIRED;
}

Is the device actually sending data? If not, you will block until it
does. I suggest 2 things

  1. consider writing your filter driver in KMDF. This will greatly
    simplify what you want to do and how you will do it.

  2. process the read results asynchronously in the completion routine so
    that you do not block the calling thread. Serial port stacks can have
    i/o sent to them at dispatch level, so blocking in the dispatch routine
    might not even be possible

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of david whitename
Sent: Saturday, August 05, 2006 8:14 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] IRP_MJ_READ

I want to read data from a lower driver such as modem,
and modfiy data that read from that. I used following code for doing
this.
but when it reaches “KeWaitForSingleObject” it will stops. and if I try
to
disable device , Windows asks me to restart the computer.

NTSTATUS DRV3ReadDispatch(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
PDRV3_DEVICE_EXTENSION deviceExtension;
NTSTATUS status;
KEVENT event;

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION"++. IRP %p",
Irp);

// Get our device extension from the device object
deviceExtension =
(PDRV3_DEVICE_EXTENSION)DeviceObject->DeviceExtension;

// Make sure we can accept IRPs
if (!DRV3AcquireRemoveLock(deviceExtension))
{
status = STATUS_DELETE_PENDING;

Irp->IoStatus.Status = status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);

DRV3DebugPrint(DBG_GENERAL, DBG_WARN, FUNCTION"–. IRP %p
STATUS
%x", Irp, status);

return status;
}

KeInitializeEvent(&event, NotificationEvent, FALSE);

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION".After
KeInitializeEvent. IRP %p", Irp);

IoCopyCurrentIrpStackLocationToNext(Irp);

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION".After
IoCopyCurrentIrpStackLocationToNext. IRP %p", Irp);

IoSetCompletionRoutine(
Irp,
(PIO_COMPLETION_ROUTINE)DRV3IoCompletionRead,
&event,
TRUE,
FALSE,
FALSE
);

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION".After
IoSetCompletionRoutine. IRP %p", Irp);

status = IoCallDriver(deviceExtension->LowerDeviceObject, Irp);
DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION".After
IoCallDriver.
IRP %p %x", Irp, status);

if (status == STATUS_PENDING)
{
KeWaitForSingleObject(
&event,
Executive,
KernelMode,
FALSE,
NULL
);

status = Irp->IoStatus.Status;

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION".After
KeWaitForSingleObject. IRP %p %x", Irp, status);
}

IoCompleteRequest(Irp, IO_NO_INCREMENT);

DRV3ReleaseRemoveLock(deviceExtension);

DRV3DebugPrint(DBG_GENERAL, DBG_TRACE, FUNCTION"–. IRP %p
STATUS
%x", Irp, status);

return status;
}

NTSTATUS DRV3IoCompletionRead(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)
{
PKEVENT event = (PKEVENT)Context;

if (Irp->PendingReturned)
{
KeSetEvent(event, IO_NO_INCREMENT, FALSE);
}

return STATUS_MORE_PROCESSING_REQUIRED;
}


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