Failing an IRP

Hi,

I have implemented a filter driver to handle a custom IOCTL called by an
user mode application.My idea for implementaion is that the driver should
return the size required for the buffer when a NULL input and output buffer
is provided.
I find that if I complete the IRP with a status other than STATUS_SUCCESS ,
the Io Manager updates the IoStatus.Information with some default value.
WDK help says that

[quote] "Unless a driver’s dispatch routine completes an IRP with an error
status value, the lowest-level driver in the chain frequently sets the IRP’s
I/O status block to the values that will be returned to the original
requester of the I/O operation.

Now I want to return an ERROR STATUS to the user app and have the required
the size returned in IoStatus.Information. http: Is
there any way to do this without the IoManager modifying the contents of
IoStatus.Information http:</http:> ?

Thanks
Abdul</http:>

STATUS_BUFFER_TOO_SMALL does what you want.

When user mode calls DeviceIoControl(), the required buffer size is
returned in dwBytesReturned.

At 13:25 21/09/2010, Abdul Qader wrote:

Hi,

I have implemented a filter driver to handle a custom IOCTL called
by an user mode application.My idea for implementaion is that the
driver should return the size required for the buffer when a NULL
input and output buffer is provided.
I find that if I complete the IRP with a status other than
STATUS_SUCCESS , the Io Manager updates the IoStatus.Information
with some default value.
WDK help says that

[quote] "Unless a driver’s dispatch routine completes an IRP with an
error status value, the lowest-level driver in the chain frequently
sets the IRP’s I/O status block to the values that will be returned
to the original requester of the I/O operation.
>
>Now I want to return an ERROR STATUS to the user app and have the
>required the size returned in
>http:IoStatus.Information. Is there any
>way to do this without the IoManager modifying the contents of
>http:</http:>IoStatus.Information ?
>
>Thanks
>Abdul
></http:>

Thanks Mark…

Mark,

Even on returning such a status I find that the IoManager updates the
Information with value 148.

Here is my code:

case IOCTL_KEYBOARD_TRANSFER_DATA:
/*Buffered IO: */
if(NULL == Irp->AssociatedIrp.SystemBuffer)
{
DebugPrint((“System Buffer NULL”));
Irp->IoStatus.Information = 4 ;
status = STATUS_BUFFER_TOO_SMALL;
}
else
{
…extra code
}
break;
}

if (!NT_SUCCESS(status)) {
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}

On debugging I find Irp->IoStatus.Information = 148 once IoCompleteRequest
is called.

Thanks
Abdul

Set “ba w4” (on 32bit builds) on the field before IoCompleteRequest, and look at where and how it is updated.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

“Abdul Qader” wrote in message news:xxxxx@ntdev…
Mark,

Even on returning such a status I find that the IoManager updates the Information with value 148.

Here is my code:

case IOCTL_KEYBOARD_TRANSFER_DATA:
/*Buffered IO: */
if(NULL == Irp->AssociatedIrp.SystemBuffer)
{
DebugPrint((“System Buffer NULL”));
Irp->IoStatus.Information = 4 ;
status = STATUS_BUFFER_TOO_SMALL;
}
else
{
…extra code
}
break;
}

if (!NT_SUCCESS(status)) {
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}

On debugging I find Irp->IoStatus.Information = 148 once IoCompleteRequest is called.

Thanks
Abdul

Did you leave out setting Irp->IoStatus.Status?

Bill Wandel

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Abdul Qader
Sent: Tuesday, September 21, 2010 10:50 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Failing an IRP

Mark,

Even on returning such a status I find that the IoManager updates the
Information with value 148.

Here is my code:

case IOCTL_KEYBOARD_TRANSFER_DATA:

/*Buffered IO: */

if(NULL == Irp->AssociatedIrp.SystemBuffer)

{

DebugPrint((“System Buffer NULL”));

Irp->IoStatus.Information = 4 ;

status = STATUS_BUFFER_TOO_SMALL;

}

else

{

…extra code

}

break;

}

if (!NT_SUCCESS(status)) {

IoCompleteRequest(Irp, IO_NO_INCREMENT);

return status;

}

On debugging I find Irp->IoStatus.Information = 148 once IoCompleteRequest
is called.

Thanks

Abdul

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

I don’t think dwBytesReturned is updated on failed status.

Sorry Maxim … Can you elaborate…?
what is “ba w4”?

Thanks

On Tue, Sep 21, 2010 at 8:47 PM, Maxim S. Shatskih
wrote:

> Set “ba w4” (on 32bit builds) on the field before IoCompleteRequest, and
> look at where and how it is updated.
>
>
>
>

The usual way to do this for win32 style applications is for the IOCTL to
have a output data structure with a default non-zero length that contains
the required additional (buffer) length, and have the driver indicate a
STATUS_BUFFER_TOO_SMALL status as noted elsewhere.

For example:

struct foo
{
ULONG bytesNeeded;
UCHAR buffer[1];
}

Your driver fills in the 'bytesNeeded value and returns sizeof(foo) bytes
(Irp->IoStatus.Information = sizeof(foo);). The app then allocates a big
enough block of data and resends the IOCTL.

What you are trying to do actually can be done but is non-standard for
windows application programming.

Mark Roddy

On Tue, Sep 21, 2010 at 8:25 AM, Abdul Qader wrote:

> Hi,
>
> I have implemented a filter driver to handle a custom IOCTL called by an
> user mode application.My idea for implementaion is that the driver should
> return the size required for the buffer when a NULL input and output buffer
> is provided.
> I find that if I complete the IRP with a status other than STATUS_SUCCESS ,
> the Io Manager updates the IoStatus.Information with some default value.
> WDK help says that
>

[quote]
"Unless a driver’s dispatch routine completes an IRP with an error
> status value, the lowest-level driver in the chain frequently sets the IRP’s
> I/O status block to the values that will be returned to the original
> requester of the I/O operation.
>
> Now I want to return an ERROR STATUS to the user app and have the required
> the size returned in IoStatus.Information.http:</http:> Is
> there any way to do this without the IoManager modifying the contents of
> IoStatus.Information http:</http:> ?
>
> Thanks
> Abdul
>
>
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

At 16:34 21/09/2010, xxxxx@broadcom.com wrote:

I don’t think dwBytesReturned is updated on failed status.

if (ulBufLength < ulTotalLength)
{
pIrp->IoStatus.Status = ntStatus = STATUS_BUFFER_TOO_SMALL;
pIrp->IoStatus.Information = ulTotalLength;
IoCompleteRequest (pIrp, IO_NO_INCREMENT);
return (ntStatus);
}

Does exactly that. As Bill Wandel noted, the OP doesn’t appear to
have set IoStatus.Status.

Mark.

http://blogs.msdn.com/b/doronh/archive/2006/12/12/how-to-return-the-number-of-bytes-required-for-a-subsequent-operation.aspx

d

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Abdul Qader
Sent: Tuesday, September 21, 2010 7:50 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] Failing an IRP

Mark,

Even on returning such a status I find that the IoManager updates the Information with value 148.

Here is my code:

case IOCTL_KEYBOARD_TRANSFER_DATA:
/*Buffered IO: */
if(NULL == Irp->AssociatedIrp.SystemBuffer)
{
DebugPrint((“System Buffer NULL”));
Irp->IoStatus.Information = 4 ;
status = STATUS_BUFFER_TOO_SMALL;
}
else
{
…extra code
}

break;
}

if (!NT_SUCCESS(status)) {
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return status;
}

On debugging I find Irp->IoStatus.Information = 148 once IoCompleteRequest is called.

Thanks
Abdul
— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

>what is “ba w4”?

WinDbg’s “set a breakpoint for writes” command.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

Thanks Doron…

Cool blog you got there…

On Tue, Sep 21, 2010 at 10:20 PM, Doron Holan wrote:

>
> http://blogs.msdn.com/b/doronh/archive/2006/12/12/how-to-return-the-number-of-bytes-required-for-a-subsequent-operation.aspx
>
>
>
> d
>
>
>
> From: xxxxx@lists.osr.com [mailto:
> xxxxx@lists.osr.com] *On Behalf Of *Abdul Qader
> Sent: Tuesday, September 21, 2010 7:50 AM
>
> To: Windows System Software Devs Interest List
> Subject: Re: [ntdev] Failing an IRP
>
>
>
> Mark,
>
>
>
> Even on returning such a status I find that the IoManager updates the
> Information with value 148.
>
>
>
> Here is my code:
>
>
>
> case IOCTL_KEYBOARD_TRANSFER_DATA:
>
> /*Buffered IO: */
>
> if(NULL == Irp->AssociatedIrp.SystemBuffer)
>
> {
>
> DebugPrint((“System Buffer NULL”));
>
> Irp->IoStatus.Information = 4 ;
>
> status = STATUS_BUFFER_TOO_SMALL;
>
> }
>
> else
>
> {
>
> …extra code
>
> }
>
>
>
>
>
>
>
> break;
>
> }
>
>
>
> if (!NT_SUCCESS(status)) {
>
> IoCompleteRequest(Irp, IO_NO_INCREMENT);
>
> return status;
>
> }
>
>
>
>
>
> On debugging I find Irp->IoStatus.Information = 148 once IoCompleteRequest
> is called.
>
>
>
> Thanks
>
> Abdul
>
> — NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
> other seminars visit: http://www.osr.com/seminars To unsubscribe, visit
> the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>