About IoBuildSynchronousFsdRequest

Hi,

I built an IRP using the following code fragment:

========================================
offset.QuadPart = (LONGLONG) 0;

bus_siz = 64;
buf = (PUCHAR) ExAllocatePool(NonPagedPool, buf_siz);

Irp = IoBuildSynchronousFsdRequest (
IRP_MJ_READ,
lowerDeviceObject,
buf,
buf_siz-1,
&offset,
&event,
&iosb);

if(Irp == NULL)
return;

/* try to see if Irp->AssociatedIrp.SystemBuffer points to buf after the IRP is created */
KdPrint("SystemBuffer = %x\n",Irp->AssociatedIrp.SystemBuffer); /* output: SystemBuffer = 0 */.
KdPrint("Data Buffer = %x\n",buf); /* output: Data Buffer = 85CEAF29 */

stack = IoGetNextIrpStackLocation(Irp);
KdPrint("Data Length = %d\n",stack->Parameters.Read.Length); /* output: Data Length = 63 */
.
.
.

I would like to ask if I pass the IRP to lower driver, then how can I recover the Data Buffer (buf) to store data from device.
At first, I thought that the Data Buffer can be recovered from Irp->AssociatedIrp.SystemBuffer, but it points to NULL.
Could anyone give me some hints?

Many Thanks!
Edward

You have the buffer, you allocated it, you know exactly where it is. As this
is a synchronous request you will be handling the completion in the same
context as your call to IoCallDriver, so the question of 'where is my
buffer' is solved, in your example, by your local variable 'buf'.

If this was an asynchronous operation then you could figure out where the
buffer is from the IRP (Irp.UserBuffer, Irp.MdlAddress,
Irp.AssociatedIrp.SystemBuffer, you need to know what type of IO the
'lowerDeviceObject supports) but a simpler solution would be to just
communicate with your completion handler using the Context parameter in
IoSetCompletionRoutine. (Typically the initiating thread allocates a
'context' object and initializes it with state information such as the
buffer address. The completion handler casts the Context pointer parameter
back into the object type and fetches the buffer, and any other state
information from this object, and of course deletes the context.)

But to reiterate: for the synchronous case you know where the buffer is.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Edward Cheung
Sent: Monday, October 18, 2004 7:29 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] About IoBuildSynchronousFsdRequest

Hi,

I built an IRP using the following code fragment:

========================================
offset.QuadPart = (LONGLONG) 0;

bus_siz = 64;
buf = (PUCHAR) ExAllocatePool(NonPagedPool, buf_siz);

Irp = IoBuildSynchronousFsdRequest (
IRP_MJ_READ,
lowerDeviceObject,
buf,
buf_siz-1,
&offset,
&event,
&iosb);

if(Irp == NULL)
return;

/* try to see if Irp->AssociatedIrp.SystemBuffer points to buf after the IRP
is created */
KdPrint("SystemBuffer = %x\n",Irp->AssociatedIrp.SystemBuffer); /*
output: SystemBuffer = 0 */.
KdPrint("Data Buffer = %x\n",buf);
/* output: Data Buffer = 85CEAF29 */

stack = IoGetNextIrpStackLocation(Irp);
KdPrint("Data Length = %d\n",stack->Parameters.Read.Length); /* output:
Data Length = 63 */
.
.
.

I would like to ask if I pass the IRP to lower driver, then how can I
recover the Data Buffer (buf) to store data from device.
At first, I thought that the Data Buffer can be recovered from
Irp->AssociatedIrp.SystemBuffer, but it points to NULL.
Could anyone give me some hints?

Many Thanks!
Edward


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 Mark!

I am sorry that my question is not clear enough.
My implementation includes a bus driver and a function driver for my device.
The function driver is layering directly on top of the bus driver and both drivers use DO_BUFFERED_IO.
My function driver will have a system thread to poll for some event. I built an IRP, with MajorFunction = IRP_MJ_READ, to be passed to my bus driver in this thread.
I used IoBuildSynchronousFsdRequest to build the IRP and supplied a resident buffer (created by ExAllocatePool) as the 3rd parameters. Then I passed the IRP down for my bus driver to process. My bus driver needs to locate the buffer set by the function driver in order to fill in the event information.

Initially I thought that I can recover the buffer set by function driver at Irp->AssociatedIrp.SystemBuffer when my bus receives the Irp. But this pointer points to NULL when my bus driver receives it.

I can pass the buffer address from function driver to bus driver if I use IoAllocateIrp() and setup Irp->AssociatedIrp.SystemBuffer manually.
Am I using IoBuildSynchronousFsdRequest incorrectly in this case or I just shouldn't use this API in this case??

Thanks!
Edward

----- Original Message -----
From: Mark Roddy
To: Windows System Software Devs Interest List
Sent: Monday, October 18, 2004 8:24 PM
Subject: RE: [ntdev] About IoBuildSynchronousFsdRequest

You have the buffer, you allocated it, you know exactly where it is. As this is a synchronous request you will be handling the completion in the same context as your call to IoCallDriver, so the question of 'where is my buffer' is solved, in your example, by your local variable 'buf'.

If this was an asynchronous operation then you could figure out where the buffer is from the IRP (Irp.UserBuffer, Irp.MdlAddress, Irp.AssociatedIrp.SystemBuffer, you need to know what type of IO the 'lowerDeviceObject supports) but a simpler solution would be to just communicate with your completion handler using the Context parameter in IoSetCompletionRoutine. (Typically the initiating thread allocates a 'context' object and initializes it with state information such as the buffer address. The completion handler casts the Context pointer parameter back into the object type and fetches the buffer, and any other state information from this object, and of course deletes the context.)

But to reiterate: for the synchronous case you know where the buffer is.


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Edward Cheung
Sent: Monday, October 18, 2004 7:29 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] About IoBuildSynchronousFsdRequest

Hi,

I built an IRP using the following code fragment:

========================================
offset.QuadPart = (LONGLONG) 0;

bus_siz = 64;
buf = (PUCHAR) ExAllocatePool(NonPagedPool, buf_siz);

Irp = IoBuildSynchronousFsdRequest (
IRP_MJ_READ,
lowerDeviceObject,
buf,
buf_siz-1,
&offset,
&event,
&iosb);

if(Irp == NULL)
return;

/* try to see if Irp->AssociatedIrp.SystemBuffer points to buf after the IRP is created */
KdPrint("SystemBuffer = %x\n",Irp->AssociatedIrp.SystemBuffer); /* output: SystemBuffer = 0 */.
KdPrint("Data Buffer = %x\n",buf); /* output: Data Buffer = 85CEAF29 */

stack = IoGetNextIrpStackLocation(Irp);
KdPrint("Data Length = %d\n",stack->Parameters.Read.Length); /* output: Data Length = 63 */
.
.
.

I would like to ask if I pass the IRP to lower driver, then how can I recover the Data Buffer (buf) to store data from device.
At first, I thought that the Data Buffer can be recovered from Irp->AssociatedIrp.SystemBuffer, but it points to NULL.
Could anyone give me some hints?

Many Thanks!
Edward


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

If the target device object uses DO_BUFFERED_IO then the data buffer will be
in Irp.AssociatedIrp.SystemBuffer. If this field is NULL then either you
have specified a buffer length of zero or the target device object is not
using DO_BUFFERED_IO. You can examine the Flags field of the
lowerDeviceObject to verify that it is using the method you expect it to be
using. IoBuildSynchronousFsdRequest is exactly what you should be using for
this operation.


From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Edward Cheung
Sent: Monday, October 18, 2004 10:41 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] About IoBuildSynchronousFsdRequest

Thanks Mark!

I am sorry that my question is not clear enough.
My implementation includes a bus driver and a function driver for my device.
The function driver is layering directly on top of the bus driver and both
drivers use DO_BUFFERED_IO.
My function driver will have a system thread to poll for some event. I built
an IRP, with MajorFunction = IRP_MJ_READ, to be passed to my bus driver in
this thread.
I used IoBuildSynchronousFsdRequest to build the IRP and supplied a resident
buffer (created by ExAllocatePool) as the 3rd parameters. Then I passed the
IRP down for my bus driver to process. My bus driver needs to locate the
buffer set by the function driver in order to fill in the event information.

Initially I thought that I can recover the buffer set by function driver at
Irp->AssociatedIrp.SystemBuffer when my bus receives the Irp. But this
pointer points to NULL when my bus driver receives it.

I can pass the buffer address from function driver to bus driver if I use
IoAllocateIrp() and setup Irp->AssociatedIrp.SystemBuffer manually.
Am I using IoBuildSynchronousFsdRequest incorrectly in this case or I just
shouldn’t use this API in this case??

Thanks!
Edward

----- Original Message -----
From: Mark mailto:xxxxx Roddy
To: Windows System Software Devs Interest mailto:xxxxx List

Sent: Monday, October 18, 2004 8:24 PM
Subject: RE: [ntdev] About IoBuildSynchronousFsdRequest

You have the buffer, you allocated it, you know exactly where it is. As this
is a synchronous request you will be handling the completion in the same
context as your call to IoCallDriver, so the question of ‘where is my
buffer’ is solved, in your example, by your local variable ‘buf’.

If this was an asynchronous operation then you could figure out where the
buffer is from the IRP (Irp.UserBuffer, Irp.MdlAddress,
Irp.AssociatedIrp.SystemBuffer, you need to know what type of IO the
'lowerDeviceObject supports) but a simpler solution would be to just
communicate with your completion handler using the Context parameter in
IoSetCompletionRoutine. (Typically the initiating thread allocates a
‘context’ object and initializes it with state information such as the
buffer address. The completion handler casts the Context pointer parameter
back into the object type and fetches the buffer, and any other state
information from this object, and of course deletes the context.)

But to reiterate: for the synchronous case you know where the buffer is.

_____

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Edward Cheung
Sent: Monday, October 18, 2004 7:29 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] About IoBuildSynchronousFsdRequest

Hi,

I built an IRP using the following code fragment:

========================================
offset.QuadPart = (LONGLONG) 0;

bus_siz = 64;
buf = (PUCHAR) ExAllocatePool(NonPagedPool, buf_siz);

Irp = IoBuildSynchronousFsdRequest (
IRP_MJ_READ,
lowerDeviceObject,
buf,
buf_siz-1,
&offset,
&event,
&iosb);

if(Irp == NULL)
return;

/* try to see if Irp->AssociatedIrp.SystemBuffer points to buf after the IRP
is created /
KdPrint(“SystemBuffer = %x\n”,Irp->AssociatedIrp.SystemBuffer); /

output: SystemBuffer = 0 /.
KdPrint(“Data Buffer = %x\n”,buf);
/
output: Data Buffer = 85CEAF29 /

stack = IoGetNextIrpStackLocation(Irp);
KdPrint(“Data Length = %d\n”,stack->Parameters.Read.Length); /
output:
Data Length = 63 */
.
.
.
========================================

I would like to ask if I pass the IRP to lower driver, then how can I
recover the Data Buffer (buf) to store data from device.
At first, I thought that the Data Buffer can be recovered from
Irp->AssociatedIrp.SystemBuffer, but it points to NULL.
Could anyone give me some hints?

Many Thanks!
Edward


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</mailto:xxxxx></mailto:xxxxx>

Hi Mark,

You are right!
I mixed up the PDO and FDO of the bus driver (flag of FDO is set with DO_BUFFERED_IO, but not for PDO :P)
Now I set DO_BUFFERED_IO for both PDO and FDO of bus driver and IoBuildSynchronousFsdRequest gives me a non-NULL Irp->AssociatedIrp.SystemBuffer.

Many Thanks for your hints!!
Edward
----- Original Message -----
From: Mark Roddy
To: Windows System Software Devs Interest List
Sent: Tuesday, October 19, 2004 7:36 PM
Subject: RE: [ntdev] About IoBuildSynchronousFsdRequest

If the target device object uses DO_BUFFERED_IO then the data buffer will be in Irp.AssociatedIrp.SystemBuffer. If this field is NULL then either you have specified a buffer length of zero or the target device object is not using DO_BUFFERED_IO. You can examine the Flags field of the lowerDeviceObject to verify that it is using the method you expect it to be using. IoBuildSynchronousFsdRequest is exactly what you should be using for this operation.


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Edward Cheung
Sent: Monday, October 18, 2004 10:41 PM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] About IoBuildSynchronousFsdRequest

Thanks Mark!

I am sorry that my question is not clear enough.
My implementation includes a bus driver and a function driver for my device.
The function driver is layering directly on top of the bus driver and both drivers use DO_BUFFERED_IO.
My function driver will have a system thread to poll for some event. I built an IRP, with MajorFunction = IRP_MJ_READ, to be passed to my bus driver in this thread.
I used IoBuildSynchronousFsdRequest to build the IRP and supplied a resident buffer (created by ExAllocatePool) as the 3rd parameters. Then I passed the IRP down for my bus driver to process. My bus driver needs to locate the buffer set by the function driver in order to fill in the event information.

Initially I thought that I can recover the buffer set by function driver at Irp->AssociatedIrp.SystemBuffer when my bus receives the Irp. But this pointer points to NULL when my bus driver receives it.

I can pass the buffer address from function driver to bus driver if I use IoAllocateIrp() and setup Irp->AssociatedIrp.SystemBuffer manually.
Am I using IoBuildSynchronousFsdRequest incorrectly in this case or I just shouldn't use this API in this case??

Thanks!
Edward

----- Original Message -----
From: Mark Roddy
To: Windows System Software Devs Interest List
Sent: Monday, October 18, 2004 8:24 PM
Subject: RE: [ntdev] About IoBuildSynchronousFsdRequest

You have the buffer, you allocated it, you know exactly where it is. As this is a synchronous request you will be handling the completion in the same context as your call to IoCallDriver, so the question of 'where is my buffer' is solved, in your example, by your local variable 'buf'.

If this was an asynchronous operation then you could figure out where the buffer is from the IRP (Irp.UserBuffer, Irp.MdlAddress, Irp.AssociatedIrp.SystemBuffer, you need to know what type of IO the 'lowerDeviceObject supports) but a simpler solution would be to just communicate with your completion handler using the Context parameter in IoSetCompletionRoutine. (Typically the initiating thread allocates a 'context' object and initializes it with state information such as the buffer address. The completion handler casts the Context pointer parameter back into the object type and fetches the buffer, and any other state information from this object, and of course deletes the context.)

But to reiterate: for the synchronous case you know where the buffer is.


From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Edward Cheung
Sent: Monday, October 18, 2004 7:29 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] About IoBuildSynchronousFsdRequest

Hi,

I built an IRP using the following code fragment:

========================================
offset.QuadPart = (LONGLONG) 0;

bus_siz = 64;
buf = (PUCHAR) ExAllocatePool(NonPagedPool, buf_siz);

Irp = IoBuildSynchronousFsdRequest (
IRP_MJ_READ,
lowerDeviceObject,
buf,
buf_siz-1,
&offset,
&event,
&iosb);

if(Irp == NULL)
return;

/* try to see if Irp->AssociatedIrp.SystemBuffer points to buf after the IRP is created */
KdPrint("SystemBuffer = %x\n",Irp->AssociatedIrp.SystemBuffer); /* output: SystemBuffer = 0 */.
KdPrint("Data Buffer = %x\n",buf); /* output: Data Buffer = 85CEAF29 */

stack = IoGetNextIrpStackLocation(Irp);
KdPrint("Data Length = %d\n",stack->Parameters.Read.Length); /* output: Data Length = 63 */
.
.
.

I would like to ask if I pass the IRP to lower driver, then how can I recover the Data Buffer (buf) to store data from device.
At first, I thought that the Data Buffer can be recovered from Irp->AssociatedIrp.SystemBuffer, but it points to NULL.
Could anyone give me some hints?

Many Thanks!
Edward


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

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