How to write a function to deal with IOCTLs for a filter driver?

Hi all:
I have wrote a function to deal with IOCTLs for my filter dirver(in
fact I only want to deal with a self-defined IOCTL_SFILTER_SETKEY).But it
often result in system crash.Could anybody give any advice on how to write
such function?
The following is my function:

NTSTATUS
FilterDeviceControl (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
PIO_STACK_LOCATION iostack;
NTSTATUS status;
iostack = IoGetCurrentIrpStackLocation(Irp);
switch (iostack->Parameters.DeviceIoControl.IoControlCode)
{
case IOCTL_SFILTER_SETKEY:
{
//do something here
status=STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
break;
}
default :
{
status = STATUS_INVALID_DEVICE_REQUEST;
Irp->IoStatus.Information = 0;
break;
}
}
return status;
}

Thanks for your advice.

Jim


ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger: http://messenger.msn.com/cn

What kind of system crash do you get. I can see two possible troubles.

  1. You’re failing IOCTLs targeted to the lower FSD. You must destinguish
    between IOCTLs for your control device object and the ones that issued for
    the FS. You must always pass FS IOCTL requests down, until you know what
    you’re doing.

  2. I don’t see if you complete request in code. If don’t, this will
    definitely cause a crash.

If send bugcheck details I could see what happened.

-htfv

----- Original Message -----
From: “Zhong Jim”
To: “File Systems Developers”
Sent: Thursday, June 12, 2003 12:56 PM
Subject: [ntfsd] How to write a function to deal with IOCTLs for a filter
driver?

> Hi all:
> I have wrote a function to deal with IOCTLs for my filter dirver(in
> fact I only want to deal with a self-defined IOCTL_SFILTER_SETKEY).But it
> often result in system crash.Could anybody give any advice on how to write
> such function?
> The following is my function:
>
> NTSTATUS
> FilterDeviceControl (
> IN PDEVICE_OBJECT DeviceObject,
> IN PIRP Irp
> )
> {
> PIO_STACK_LOCATION iostack;
> NTSTATUS status;
> iostack = IoGetCurrentIrpStackLocation(Irp);
> switch (iostack->Parameters.DeviceIoControl.IoControlCode)
> {
> case IOCTL_SFILTER_SETKEY:
> {
> //do something here
> status=STATUS_SUCCESS;
> Irp->IoStatus.Information = 0;
> break;
> }
> default :
> {
> status = STATUS_INVALID_DEVICE_REQUEST;
> Irp->IoStatus.Information = 0;
> break;
> }
> }
> return status;
> }
>
> Thanks for your advice.
>
>
> Jim
>
> _________________________________________________________________
> ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger: http://messenger.msn.com/cn
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@vba.com.by
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

usually ioctls come to the filter driver at FastIoDeviceControl 1st. do u
handle ioctls there as well? what i do is fail FastIoDeviceControl so that
all ioctls go through the IRP way.

also, if ur filter driver is above another driver, u cannot return
STATUS_INVALID_DEVICE_REQUEST for any ioctl other than ur own. there are
other legitimate ioctls that may be targeted to the driver below ur filter
driver. what u should do is pass down those ioctls that u do not handle. u
can only fail ioctls u don’t handle if there is no driver below u.

Ampsi

----- Original Message -----
From: “Zhong Jim”
To: “File Systems Developers”
Sent: Thursday, June 12, 2003 17:56
Subject: [ntfsd] How to write a function to deal with IOCTLs for a filter
driver?

Hi all:
I have wrote a function to deal with IOCTLs for my filter dirver(in
fact I only want to deal with a self-defined IOCTL_SFILTER_SETKEY).But it
often result in system crash.Could anybody give any advice on how to write
such function?
The following is my function:

NTSTATUS
FilterDeviceControl (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
{
PIO_STACK_LOCATION iostack;
NTSTATUS status;
iostack = IoGetCurrentIrpStackLocation(Irp);
switch (iostack->Parameters.DeviceIoControl.IoControlCode)
{
case IOCTL_SFILTER_SETKEY:
{
//do something here
status=STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
break;
}
default :
{
status = STATUS_INVALID_DEVICE_REQUEST;
Irp->IoStatus.Information = 0;
break;
}
}
return status;
}

Thanks for your advice.

Jim

_________________________________________________________________
ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger: http://messenger.msn.com/cn


You are currently subscribed to ntfsd as: xxxxx@pmail.ntu.edu.sg
To unsubscribe send a blank email to xxxxx@lists.osr.com