Re: send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Here’s the snippet of code:

//g_psDeviceObject - is the device object created by the filter and attached to the stack

psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
if (!psIRP)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
psIRP->RequestorMode = KernelMode;
psIRP->UserIosb = &sIOStatusBlock;
psIRP->UserEvent = NULL;
psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;
psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with ExAllocate pool and is aligned on the 512 boundy
psIRP->UserBuffer = NULL;

psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
psIOStackLocation->DeviceObject = g_psDeviceObject;
psIOStackLocation->FileObject = NULL;
psIOStackLocation->Parameters.Read.Length = dwBytesToWrite; //dwBytesToWrite = 512
psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER) &qwOffset; ;//qwOffset = 0

IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE) &ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
if (nStatus == STATUS_PENDING)
{
KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
}
ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
*pdwBytesWritten = sIOStatusBlock.Information;

///////////////////////////////

Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well, but probably there was additional bug…

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Now I receive ‘invalid parameter’ error if I try to allocate and to send a IRP_MJ_READ request to the underlying driver.

My driver is the disk upper-filter, I allocate and send the request from the dispatch routine (IRP_MJ_READ handler).

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Hi all,

I’m trying to accomplish something which acts similarly to chkdsk and developed the lower-filter driver for this purpose (I need the lower-filter not upper-filter). This lower-filter attaches to the device stack properly but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate IRP_MJ_READ request and send it to the lower device. I try to accomplish this in the dispatch routine (during processing of the 1st arrived IRP_MJ_CREATE request).

What can be the problem?

Thanks,
Roman

Ugh - try IoBuildSynchronousFsdRequest.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 5:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Here’s the snippet of code:

//g_psDeviceObject - is the device object created by the filter and attached
to the stack

psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
if (!psIRP)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
psIRP->RequestorMode = KernelMode;
psIRP->UserIosb = &sIOStatusBlock;
psIRP->UserEvent = NULL;
psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;

psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with
ExAllocate pool and is aligned on the 512 boundy
psIRP->UserBuffer = NULL;

psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
psIOStackLocation->DeviceObject = g_psDeviceObject;
psIOStackLocation->FileObject = NULL;
psIOStackLocation->Parameters.Read.Length = dwBytesToWrite;
//dwBytesToWrite = 512
psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER) &qwOffset;
;//qwOffset = 0

IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE)
&ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
if (nStatus == STATUS_PENDING)
{
KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
}
ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
*pdwBytesWritten = sIOStatusBlock.Information;

///////////////////////////////

Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying
device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well,
but probably there was additional bug…

“Roman Kudinov” ???/??? ? ??? ???:
news:xxxxx@ntdev…
Now I receive ‘invalid parameter’ error if I try to allocate and to send a
IRP_MJ_READ request to the underlying driver.

My driver is the disk upper-filter, I allocate and send the request from the
dispatch routine (IRP_MJ_READ handler).

“Roman Kudinov” ???/??? ? ??? ???:
news:xxxxx@ntdev…
Hi all,

I’m trying to accomplish something which acts similarly to chkdsk and
developed the lower-filter driver for this purpose (I need the lower-filter
not upper-filter). This lower-filter attaches to the device stack properly
but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate
IRP_MJ_READ request and send it to the lower device. I try to accomplish
this in the dispatch routine (during processing of the 1st arrived
IRP_MJ_CREATE request).

What can be the problem?

Thanks,
Roman


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

We tried this as well but failed :frowning:

Are there any specific parameters I should specify?
Can I roll the custom IRP_MJ_READ directly to the underlying device without sending to the top of the stack at all?
Can I roll the IRP from the dispatch routine?
Can I roll the bufferred IRP if the device has a flag DO_DIRECT_IO?

I’m not too familiar with the device drivers, I worked with filesystem filters before and such technique worked without problems there.

“Mark Roddy” ???/??? ? ??? ???: news:xxxxx@ntdev…
Ugh - try IoBuildSynchronousFsdRequest.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

----------------------------------------------------------------------------
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 5:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Here’s the snippet of code:

//g_psDeviceObject - is the device object created by the filter and attached to the stack

psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
if (!psIRP)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
psIRP->RequestorMode = KernelMode;
psIRP->UserIosb = &sIOStatusBlock;
psIRP->UserEvent = NULL;
psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;
psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with ExAllocate pool and is aligned on the 512 boundy
psIRP->UserBuffer = NULL;

psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
psIOStackLocation->DeviceObject = g_psDeviceObject;
psIOStackLocation->FileObject = NULL;
psIOStackLocation->Parameters.Read.Length = dwBytesToWrite; //dwBytesToWrite = 512
psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER) &qwOffset; ;//qwOffset = 0

IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE) &ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
if (nStatus == STATUS_PENDING)
{
KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
}
ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
*pdwBytesWritten = sIOStatusBlock.Information;

///////////////////////////////

Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well, but probably there was additional bug…

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Now I receive ‘invalid parameter’ error if I try to allocate and to send a IRP_MJ_READ request to the underlying driver.

My driver is the disk upper-filter, I allocate and send the request from the dispatch routine (IRP_MJ_READ handler).

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Hi all,

I’m trying to accomplish something which acts similarly to chkdsk and developed the lower-filter driver for this purpose (I need the lower-filter not upper-filter). This lower-filter attaches to the device stack properly but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate IRP_MJ_READ request and send it to the lower device. I try to accomplish this in the dispatch routine (during processing of the 1st arrived IRP_MJ_CREATE request).

What can be the problem?

Thanks,
Roman


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

The DDK comes with the full source code for disk.sys
(src\storage\class\disk). Build your own copy, install it on the machine
running your filter, and step through with the debugger. Much quicker than
debugging via NNTP…

-scott


Scott Noone
Software Engineer
OSR Open Systems Resources, Inc.
http://www.osronline.com

“Roman Kudinov” wrote in message news:xxxxx@ntdev…
We tried this as well but failed :frowning:

Are there any specific parameters I should specify?
Can I roll the custom IRP_MJ_READ directly to the underlying device without
sending to the top of the stack at all?
Can I roll the IRP from the dispatch routine?
Can I roll the bufferred IRP if the device has a flag DO_DIRECT_IO?

I’m not too familiar with the device drivers, I worked with filesystem
filters before and such technique worked without problems there.

“Mark Roddy” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:xxxxx@ntdev…
Ugh - try IoBuildSynchronousFsdRequest.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 5:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Here’s the snippet of code:

//g_psDeviceObject - is the device object created by the filter and attached
to the stack

psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
if (!psIRP)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
psIRP->RequestorMode = KernelMode;
psIRP->UserIosb = &sIOStatusBlock;
psIRP->UserEvent = NULL;
psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;
psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with
ExAllocate pool and is aligned on the 512 boundy
psIRP->UserBuffer = NULL;

psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
psIOStackLocation->DeviceObject = g_psDeviceObject;
psIOStackLocation->FileObject = NULL;
psIOStackLocation->Parameters.Read.Length = dwBytesToWrite;
//dwBytesToWrite = 512
psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER) &qwOffset;
;//qwOffset = 0

IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE)
&ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
if (nStatus == STATUS_PENDING)
{
KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
}
ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
*pdwBytesWritten = sIOStatusBlock.Information;

///////////////////////////////

Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying
device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well,
but probably there was additional bug…

“Roman Kudinov” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:xxxxx@ntdev…
Now I receive ‘invalid parameter’ error if I try to allocate and to send a
IRP_MJ_READ request to the underlying driver.

My driver is the disk upper-filter, I allocate and send the request from the
dispatch routine (IRP_MJ_READ handler).

“Roman Kudinov” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:xxxxx@ntdev…
Hi all,

I’m trying to accomplish something which acts similarly to chkdsk and
developed the lower-filter driver for this purpose (I need the lower-filter
not upper-filter). This lower-filter attaches to the device stack properly
but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate
IRP_MJ_READ request and send it to the lower device. I try to accomplish
this in the dispatch routine (during processing of the 1st arrived
IRP_MJ_CREATE request).

What can be the problem?

Thanks,
Roman


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

IoBuildSynchronousFsdRequest ought to work just fine - what was the error
code and what parameters did you set?

You cannot send a SYSTEM_BUFFER to a device that is expecting an MDL, that
just won’t work and will quite frequently not work in spectacular fashion
:slight_smile:

Send the IRP to the next lower device - the device object returned to you
when you called IoAttachDeviceToDeviceStack.

You must respect all of the DDI IRQL restrictions - just because you are in
a dispatch routine do not assume that you are executing at PASSIVE_LEVEL. As
you are going to execute the IO synchronously you have to be at <
DISPATCH_LEVEL - if you aren’t you need to hand the operation off to a
worker thread or perform the operation asynchronously.

There are lots of specific parameters you have to apply, which is why you
should be using either IoBuildSynchronousFsdRequest or
IoBuildAsynchronousFsdRequest, as they supply the correct parameters.

You have the code for disk.sys/classpnp in the ddk. Work your way through
the read/write IRP processing code paths and figure out what you are doing
wrong.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 10:28 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

We tried this as well but failed :frowning:

Are there any specific parameters I should specify?
Can I roll the custom IRP_MJ_READ directly to the underlying device without
sending to the top of the stack at all?
Can I roll the IRP from the dispatch routine?
Can I roll the bufferred IRP if the device has a flag DO_DIRECT_IO?

I’m not too familiar with the device drivers, I worked with filesystem
filters before and such technique worked without problems there.

“Mark Roddy” ???/??? ? ??? ???:
news:xxxxx@ntdev…
Ugh - try IoBuildSynchronousFsdRequest.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

_____

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 5:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Here’s the snippet of code:

//g_psDeviceObject - is the device object created by the filter and attached
to the stack

psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
if (!psIRP)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
psIRP->RequestorMode = KernelMode;
psIRP->UserIosb = &sIOStatusBlock;
psIRP->UserEvent = NULL;
psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;

psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with
ExAllocate pool and is aligned on the 512 boundy
psIRP->UserBuffer = NULL;

psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
psIOStackLocation->DeviceObject = g_psDeviceObject;
psIOStackLocation->FileObject = NULL;
psIOStackLocation->Parameters.Read.Length = dwBytesToWrite;
//dwBytesToWrite = 512
psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER) &qwOffset;
;//qwOffset = 0

IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE)
&ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
if (nStatus == STATUS_PENDING)
{
KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
}
ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
*pdwBytesWritten = sIOStatusBlock.Information;

///////////////////////////////

Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying
device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well,
but probably there was additional bug…

“Roman Kudinov” ???/??? ? ??? ???:
news:xxxxx@ntdev…
Now I receive ‘invalid parameter’ error if I try to allocate and to send a
IRP_MJ_READ request to the underlying driver.

My driver is the disk upper-filter, I allocate and send the request from the
dispatch routine (IRP_MJ_READ handler).

“Roman Kudinov” ???/??? ? ??? ???:
news:xxxxx@ntdev…
Hi all,

I’m trying to accomplish something which acts similarly to chkdsk and
developed the lower-filter driver for this purpose (I need the lower-filter
not upper-filter). This lower-filter attaches to the device stack properly
but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate
IRP_MJ_READ request and send it to the lower device. I try to accomplish
this in the dispatch routine (during processing of the 1st arrived
IRP_MJ_CREATE request).

What can be the problem?

Thanks,
Roman


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Quoting Roman Kudinov :

>
> I’m trying to accomplish something which acts similarly to chkdsk and
> developed the lower-filter driver for this purpose (I need the lower-filter
> not upper-filter). This lower-filter attaches to the device stack properly
> but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate
> IRP_MJ_READ request and send it to the lower device. I try to accomplish this
> in the dispatch routine (during processing of the 1st arrived IRP_MJ_CREATE
> request).
>
> What can be the problem?
>

Is your lower device driver receiving the IRP_MJ_READ that should be easy enough
to decide. Does your lower device driver handle IRP_MJ_READ completely? If you
are just passing it on this would certainly be an invalid device request. In
general lower device drivers only handle io with IRP_MJ_INTERNAL_DEVICE_CONTROL
and IRP_MJ_DEVICE_CONTROL

This post might confuse you. My driver is the upper filter for the disk
device, so obviously the lower dirver must handle IRP_MJ_READ request
moreover if I just pass through the incoming IRP_MJ_READ it works fine but
if I generate own IRP and send it to the same device it fails.

“ian blake” ???/??? ? ??? ???:
news:xxxxx@ntdev…
> Quoting Roman Kudinov :
>
> >
> > I’m trying to accomplish something which acts similarly to
chkdsk and
> > developed the lower-filter driver for this purpose (I need the
lower-filter
> > not upper-filter). This lower-filter attaches to the device stack
properly
> > but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate
> > IRP_MJ_READ request and send it to the lower device. I try to accomplish
this
> > in the dispatch routine (during processing of the 1st arrived
IRP_MJ_CREATE
> > request).
> >
> > What can be the problem?
> >
>
> Is your lower device driver receiving the IRP_MJ_READ that should be easy
enough
> to decide. Does your lower device driver handle IRP_MJ_READ completely?
If you
> are just passing it on this would certainly be an invalid device request.
In
> general lower device drivers only handle io with
IRP_MJ_INTERNAL_DEVICE_CONTROL
> and IRP_MJ_DEVICE_CONTROL
>
>
>

Thank you for the advise, I will try

“Scott Noone” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
news:xxxxx@ntdev…
> The DDK comes with the full source code for disk.sys
> (src\storage\class\disk). Build your own copy, install it on the machine
> running your filter, and step through with the debugger. Much quicker than
> debugging via NNTP…
>
> -scott
>
> –
> Scott Noone
> Software Engineer
> OSR Open Systems Resources, Inc.
> http://www.osronline.com
>
> “Roman Kudinov” wrote in message news:xxxxx@ntdev…
> We tried this as well but failed :frowning:
>
> Are there any specific parameters I should specify?
> Can I roll the custom IRP_MJ_READ directly to the underlying device
without
> sending to the top of the stack at all?
> Can I roll the IRP from the dispatch routine?
> Can I roll the bufferred IRP if the device has a flag DO_DIRECT_IO?
>
> I’m not too familiar with the device drivers, I worked with filesystem
> filters before and such technique worked without problems there.
>
>
> “Mark Roddy” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
> news:xxxxx@ntdev…
> Ugh - try IoBuildSynchronousFsdRequest.
>
> =====================
> Mark Roddy DDK MVP
> Windows 2003/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com
>
>
>
>
>
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
> Sent: Friday, October 14, 2005 5:33 AM
> To: Windows System Software Devs Interest List
> Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk
device
>
>
> Here’s the snippet of code:
>
> //g_psDeviceObject - is the device object created by the filter and
attached
> to the stack
>
> psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
> if (!psIRP)
> {
> return STATUS_INSUFFICIENT_RESOURCES;
> }
> psIRP->RequestorMode = KernelMode;
> psIRP->UserIosb = &sIOStatusBlock;
> psIRP->UserEvent = NULL;
> psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;
> psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with
> ExAllocate pool and is aligned on the 512 boundy
> psIRP->UserBuffer = NULL;
>
> psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
> psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
> psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
> psIOStackLocation->DeviceObject = g_psDeviceObject;
> psIOStackLocation->FileObject = NULL;
> psIOStackLocation->Parameters.Read.Length = dwBytesToWrite;
> //dwBytesToWrite = 512
> psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER)
&qwOffset;
> ;//qwOffset = 0
>
> IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE)
> &ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
> nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
> if (nStatus == STATUS_PENDING)
> {
> KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
> }
> ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
> *pdwBytesWritten = sIOStatusBlock.Information;
>
> ///////////////////////////////
>
> Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying
> device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well,
> but probably there was additional bug…
>
>
> “Roman Kudinov” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
> news:xxxxx@ntdev…
> Now I receive ‘invalid parameter’ error if I try to allocate and to send a
> IRP_MJ_READ request to the underlying driver.
>
> My driver is the disk upper-filter, I allocate and send the request from
the
> dispatch routine (IRP_MJ_READ handler).
>
> “Roman Kudinov” ÓÏÏÂÝÉÌ/ÓÏÏÂÝÉÌÁ × ÎÏ×ÏÓÔÑÈ ÓÌÅÄÕÀÝÅÅ:
> news:xxxxx@ntdev…
> Hi all,
>
> I’m trying to accomplish something which acts similarly to chkdsk and
> developed the lower-filter driver for this purpose (I need the
lower-filter
> not upper-filter). This lower-filter attaches to the device stack properly
> but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate
> IRP_MJ_READ request and send it to the lower device. I try to accomplish
> this in the dispatch routine (during processing of the 1st arrived
> IRP_MJ_CREATE request).
>
> What can be the problem?
>
>
> Thanks,
> Roman
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
>

Thanks for the help, I’ll try to use the MDL and async operations.

“Mark Roddy” ???/??? ? ??? ???: news:xxxxx@ntdev…
IoBuildSynchronousFsdRequest ought to work just fine - what was the error code and what parameters did you set?

You cannot send a SYSTEM_BUFFER to a device that is expecting an MDL, that just won’t work and will quite frequently not work in spectacular fashion :slight_smile:

Send the IRP to the next lower device - the device object returned to you when you called IoAttachDeviceToDeviceStack.

You must respect all of the DDI IRQL restrictions - just because you are in a dispatch routine do not assume that you are executing at PASSIVE_LEVEL. As you are going to execute the IO synchronously you have to be at < DISPATCH_LEVEL - if you aren’t you need to hand the operation off to a worker thread or perform the operation asynchronously.

There are lots of specific parameters you have to apply, which is why you should be using either IoBuildSynchronousFsdRequest or IoBuildAsynchronousFsdRequest, as they supply the correct parameters.

You have the code for disk.sys/classpnp in the ddk. Work your way through the read/write IRP processing code paths and figure out what you are doing wrong.
=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

----------------------------------------------------------------------------
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 10:28 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

We tried this as well but failed :frowning:

Are there any specific parameters I should specify?
Can I roll the custom IRP_MJ_READ directly to the underlying device without sending to the top of the stack at all?
Can I roll the IRP from the dispatch routine?
Can I roll the bufferred IRP if the device has a flag DO_DIRECT_IO?

I’m not too familiar with the device drivers, I worked with filesystem filters before and such technique worked without problems there.

“Mark Roddy” ???/??? ? ??? ???: news:xxxxx@ntdev…
Ugh - try IoBuildSynchronousFsdRequest.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

------------------------------------------------------------------------
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 5:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Here’s the snippet of code:

//g_psDeviceObject - is the device object created by the filter and attached to the stack

psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
if (!psIRP)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
psIRP->RequestorMode = KernelMode;
psIRP->UserIosb = &sIOStatusBlock;
psIRP->UserEvent = NULL;
psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;
psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with ExAllocate pool and is aligned on the 512 boundy
psIRP->UserBuffer = NULL;

psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
psIOStackLocation->DeviceObject = g_psDeviceObject;
psIOStackLocation->FileObject = NULL;
psIOStackLocation->Parameters.Read.Length = dwBytesToWrite; //dwBytesToWrite = 512
psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER) &qwOffset; ;//qwOffset = 0

IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE) &ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
if (nStatus == STATUS_PENDING)
{
KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
}
ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
*pdwBytesWritten = sIOStatusBlock.Information;

///////////////////////////////

Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well, but probably there was additional bug…

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Now I receive ‘invalid parameter’ error if I try to allocate and to send a IRP_MJ_READ request to the underlying driver.

My driver is the disk upper-filter, I allocate and send the request from the dispatch routine (IRP_MJ_READ handler).

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Hi all,

I’m trying to accomplish something which acts similarly to chkdsk and developed the lower-filter driver for this purpose (I need the lower-filter not upper-filter). This lower-filter attaches to the device stack properly but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate IRP_MJ_READ request and send it to the lower device. I try to accomplish this in the dispatch routine (during processing of the 1st arrived IRP_MJ_CREATE request).

What can be the problem?

Thanks,
Roman


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

You don’t have an SRB attached to the IRP you are sending down. Definitely look at how the DDK disk class source sends a request down to the port/function driver.

In response to another instance of this thread, the disk class driver does accept the IRP_MJ_READ command, so the upper filter will see this type of command. It’s the lower filter that doesn’t see IRP_MJ_READ/WRITE because the class is replacing the IRP with an internal ioctl request.


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 7:28 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

We tried this as well but failed :frowning:

Are there any specific parameters I should specify?
Can I roll the custom IRP_MJ_READ directly to the underlying device without sending to the top of the stack at all?
Can I roll the IRP from the dispatch routine?
Can I roll the bufferred IRP if the device has a flag DO_DIRECT_IO?

I’m not too familiar with the device drivers, I worked with filesystem filters before and such technique worked without problems there.

“Mark Roddy” ???/??? ? ??? ???: news:xxxxx@ntdev…
Ugh - try IoBuildSynchronousFsdRequest.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

________________________________

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 5:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Here’s the snippet of code:

//g_psDeviceObject - is the device object created by the filter and attached to the stack

psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
if (!psIRP)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
psIRP->RequestorMode = KernelMode;
psIRP->UserIosb = &sIOStatusBlock;
psIRP->UserEvent = NULL;
psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;

psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with ExAllocate pool and is aligned on the 512 boundy
psIRP->UserBuffer = NULL;

psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
psIOStackLocation->DeviceObject = g_psDeviceObject;
psIOStackLocation->FileObject = NULL;
psIOStackLocation->Parameters.Read.Length = dwBytesToWrite; //dwBytesToWrite = 512
psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER) &qwOffset; ;//qwOffset = 0

IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE) &ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
if (nStatus == STATUS_PENDING)
{
KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
}
ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
*pdwBytesWritten = sIOStatusBlock.Information;

///////////////////////////////

Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well, but probably there was additional bug…

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Now I receive ‘invalid parameter’ error if I try to allocate and to send a IRP_MJ_READ request to the underlying driver.

My driver is the disk upper-filter, I allocate and send the request from the dispatch routine (IRP_MJ_READ handler).

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Hi all,

I’m trying to accomplish something which acts similarly to chkdsk and developed the lower-filter driver for this purpose (I need the lower-filter not upper-filter). This lower-filter attaches to the device stack properly but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate IRP_MJ_READ request and send it to the lower device. I try to accomplish this in the dispatch routine (during processing of the 1st arrived IRP_MJ_CREATE request).

What can be the problem?

Thanks,
Roman


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Do you mean that even in the upper filter I should attach SRB with IRP?

“Eschmann, Michael K” ???/??? ? ??? ???: news:xxxxx@ntdev…
You don’t have an SRB attached to the IRP you are sending down. Definitely look at how the DDK disk class source sends a request down to the port/function driver.

In response to another instance of this thread, the disk class driver does accept the IRP_MJ_READ command, so the upper filter will see this type of command. It’s the lower filter that doesn’t see IRP_MJ_READ/WRITE because the class is replacing the IRP with an internal ioctl request.

------------------------------------------------------------------------------
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 7:28 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

We tried this as well but failed :frowning:

Are there any specific parameters I should specify?
Can I roll the custom IRP_MJ_READ directly to the underlying device without sending to the top of the stack at all?
Can I roll the IRP from the dispatch routine?
Can I roll the bufferred IRP if the device has a flag DO_DIRECT_IO?

I’m not too familiar with the device drivers, I worked with filesystem filters before and such technique worked without problems there.

“Mark Roddy” ???/??? ? ??? ???: news:xxxxx@ntdev…
Ugh - try IoBuildSynchronousFsdRequest.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

--------------------------------------------------------------------------
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 5:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Here’s the snippet of code:

//g_psDeviceObject - is the device object created by the filter and attached to the stack

psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
if (!psIRP)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
psIRP->RequestorMode = KernelMode;
psIRP->UserIosb = &sIOStatusBlock;
psIRP->UserEvent = NULL;
psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;
psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with ExAllocate pool and is aligned on the 512 boundy
psIRP->UserBuffer = NULL;

psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
psIOStackLocation->DeviceObject = g_psDeviceObject;
psIOStackLocation->FileObject = NULL;
psIOStackLocation->Parameters.Read.Length = dwBytesToWrite; //dwBytesToWrite = 512
psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER) &qwOffset; ;//qwOffset = 0

IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE) &ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
if (nStatus == STATUS_PENDING)
{
KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
}
ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
*pdwBytesWritten = sIOStatusBlock.Information;

///////////////////////////////

Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well, but probably there was additional bug…

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Now I receive ‘invalid parameter’ error if I try to allocate and to send a IRP_MJ_READ request to the underlying driver.

My driver is the disk upper-filter, I allocate and send the request from the dispatch routine (IRP_MJ_READ handler).

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Hi all,

I’m trying to accomplish something which acts similarly to chkdsk and developed the lower-filter driver for this purpose (I need the lower-filter not upper-filter). This lower-filter attaches to the device stack properly but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate IRP_MJ_READ request and send it to the lower device. I try to accomplish this in the dispatch routine (during processing of the 1st arrived IRP_MJ_CREATE request).

What can be the problem?

Thanks,
Roman


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

No, what I said applies to lower class filters. I was responding based on your statement “(I need the lower-filter not upper-filter)”. Upper filters do deal with IRP_M_READ/WRITE, while lower filters will receive IRP_MJ_INTERNAL_DEVICE_CONTROL in order to read/write and expects to see a SRB.


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Wednesday, October 26, 2005 7:39 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Do you mean that even in the upper filter I should attach SRB with IRP?

“Eschmann, Michael K” ???/??? ? ??? ???: news:xxxxx@ntdev…
You don’t have an SRB attached to the IRP you are sending down. Definitely look at how the DDK disk class source sends a request down to the port/function driver.

In response to another instance of this thread, the disk class driver does accept the IRP_MJ_READ command, so the upper filter will see this type of command. It’s the lower filter that doesn’t see IRP_MJ_READ/WRITE because the class is replacing the IRP with an internal ioctl request.



From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 7:28 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

We tried this as well but failed :frowning:

Are there any specific parameters I should specify?
Can I roll the custom IRP_MJ_READ directly to the underlying device without sending to the top of the stack at all?
Can I roll the IRP from the dispatch routine?
Can I roll the bufferred IRP if the device has a flag DO_DIRECT_IO?

I’m not too familiar with the device drivers, I worked with filesystem filters before and such technique worked without problems there.

“Mark Roddy” ???/??? ? ??? ???: news:xxxxx@ntdev…
Ugh - try IoBuildSynchronousFsdRequest.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com



From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 5:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Here’s the snippet of code:

//g_psDeviceObject - is the device object created by the filter and attached to the stack

psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
if (!psIRP)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
psIRP->RequestorMode = KernelMode;
psIRP->UserIosb = &sIOStatusBlock;
psIRP->UserEvent = NULL;
psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;

psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with ExAllocate pool and is aligned on the 512 boundy
psIRP->UserBuffer = NULL;

psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
psIOStackLocation->DeviceObject = g_psDeviceObject;
psIOStackLocation->FileObject = NULL;
psIOStackLocation->Parameters.Read.Length = dwBytesToWrite; //dwBytesToWrite = 512
psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER) &qwOffset; ;//qwOffset = 0

IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE) &ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
if (nStatus == STATUS_PENDING)
{
KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
}
ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
*pdwBytesWritten = sIOStatusBlock.Information;

///////////////////////////////

Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well, but probably there was additional bug…

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Now I receive ‘invalid parameter’ error if I try to allocate and to send a IRP_MJ_READ request to the underlying driver.

My driver is the disk upper-filter, I allocate and send the request from the dispatch routine (IRP_MJ_READ handler).

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Hi all,

I’m trying to accomplish something which acts similarly to chkdsk and developed the lower-filter driver for this purpose (I need the lower-filter not upper-filter). This lower-filter attaches to the device stack properly but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate IRP_MJ_READ request and send it to the lower device. I try to accomplish this in the dispatch routine (during processing of the 1st arrived IRP_MJ_CREATE request).

What can be the problem?

Thanks,
Roman


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Hi,

Finally I resolved the issue and the solution confuses me a lot. I have two harddisks, that is the driver attaches to two devices. If driver sends IRP_MJ_READ/IRP_MJ_WRITE requests from the dispatch routine to the 2nd device then it works if dispatch routine processes IRP_MJ_READ directed to the 2nd device only. If the dispatch routine (at the moment of rolling custom IRP down) handles a request to the 1st device than my custom IRP_MJ_READ/IRP_MJ_WRITE request fails though it doesn’t depend on the intercepted request at all…
It seems to be very strange

“Mark Roddy” ???/??? ? ??? ???: news:xxxxx@ntdev…
IoBuildSynchronousFsdRequest ought to work just fine - what was the error code and what parameters did you set?

You cannot send a SYSTEM_BUFFER to a device that is expecting an MDL, that just won’t work and will quite frequently not work in spectacular fashion :slight_smile:

Send the IRP to the next lower device - the device object returned to you when you called IoAttachDeviceToDeviceStack.

You must respect all of the DDI IRQL restrictions - just because you are in a dispatch routine do not assume that you are executing at PASSIVE_LEVEL. As you are going to execute the IO synchronously you have to be at < DISPATCH_LEVEL - if you aren’t you need to hand the operation off to a worker thread or perform the operation asynchronously.

There are lots of specific parameters you have to apply, which is why you should be using either IoBuildSynchronousFsdRequest or IoBuildAsynchronousFsdRequest, as they supply the correct parameters.

You have the code for disk.sys/classpnp in the ddk. Work your way through the read/write IRP processing code paths and figure out what you are doing wrong.
=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

----------------------------------------------------------------------------
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 10:28 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

We tried this as well but failed :frowning:

Are there any specific parameters I should specify?
Can I roll the custom IRP_MJ_READ directly to the underlying device without sending to the top of the stack at all?
Can I roll the IRP from the dispatch routine?
Can I roll the bufferred IRP if the device has a flag DO_DIRECT_IO?

I’m not too familiar with the device drivers, I worked with filesystem filters before and such technique worked without problems there.

“Mark Roddy” ???/??? ? ??? ???: news:xxxxx@ntdev…
Ugh - try IoBuildSynchronousFsdRequest.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

------------------------------------------------------------------------
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Roman Kudinov
Sent: Friday, October 14, 2005 5:33 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] send IRP_MJ_READ/IRP_MJ_WRITE to lower-level disk device

Here’s the snippet of code:

//g_psDeviceObject - is the device object created by the filter and attached to the stack

psIRP = IoAllocateIrp(g_psDeviceObject->StackSize, FALSE);
if (!psIRP)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
psIRP->RequestorMode = KernelMode;
psIRP->UserIosb = &sIOStatusBlock;
psIRP->UserEvent = NULL;
psIRP->Flags = IRP_SYNCHRONOUS_API;// | DO_DIRECT_IO;
psIRP->AssociatedIrp.SystemBuffer = pvBuffer; //pvBuffer is allocated with ExAllocate pool and is aligned on the 512 boundy
psIRP->UserBuffer = NULL;

psIOStackLocation = IoGetNextIrpStackLocation(psIRP);
psIOStackLocation->MajorFunction = IRP_MJ_WRITE;
psIOStackLocation->MinorFunction = IRP_MN_NORMAL;
psIOStackLocation->DeviceObject = g_psDeviceObject;
psIOStackLocation->FileObject = NULL;
psIOStackLocation->Parameters.Read.Length = dwBytesToWrite; //dwBytesToWrite = 512
psIOStackLocation->Parameters.Read.ByteOffset = *(PLARGE_INTEGER) &qwOffset; ;//qwOffset = 0

IoSetCompletionRoutine(psIRP, (PIO_COMPLETION_ROUTINE) &ReadWriteSectorCompletion, &sEvent, TRUE, TRUE, TRUE);
nStatus = IoCallDriver(psTargetDeviceObject, psIRP);
if (nStatus == STATUS_PENDING)
{
KeWaitForSingleObject(&sEvent, Executive, KernelMode, FALSE, NULL);
}
ASSERT(KeReadStateEvent(&sEvent) || !NT_SUCCESS(sIOStatusBlock.Status));
*pdwBytesWritten = sIOStatusBlock.Information;

///////////////////////////////

Can I use the bufferred IO for IRP_MJ_READ/IRP_MJ_WRITE if the underlying device has a flag DO_DIRECT_IO? I tried to use MDL but it failed as well, but probably there was additional bug…

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Now I receive ‘invalid parameter’ error if I try to allocate and to send a IRP_MJ_READ request to the underlying driver.

My driver is the disk upper-filter, I allocate and send the request from the dispatch routine (IRP_MJ_READ handler).

“Roman Kudinov” ???/??? ? ??? ???: news:xxxxx@ntdev…
Hi all,

I’m trying to accomplish something which acts similarly to chkdsk and developed the lower-filter driver for this purpose (I need the lower-filter not upper-filter). This lower-filter attaches to the device stack properly but I get the STATUS_INVALID_DEVICE_REQUEST error code when generate IRP_MJ_READ request and send it to the lower device. I try to accomplish this in the dispatch routine (during processing of the 1st arrived IRP_MJ_CREATE request).

What can be the problem?

Thanks,
Roman


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com