【求助】简单的过滤驱动测试为何通不过
以下是一个简单的过滤驱动,简单将所有irp转发到下一层。我把它注册为卷过滤驱动,当只有1个卷的时候,运行正常,当有2个卷的时候就蓝屏了,为什么?
如果把它注册为磁盘过滤驱动,则不管1个磁盘还是2个磁盘,都蓝屏,为什么?
求驱动大牛指教。
#include <ntddk.h>
#include <wdm.h>
typedef struct MYFILTER_DEV_EXTENSION_
{
PDEVICE_OBJECT FltDevObj;
PDEVICE_OBJECT LowerDevObj;
PDEVICE_OBJECT PhyDevObj;
} MYFILTER_DEV_EXTENSION, *PMYFILTER_DEV_EXTENSION;
NTSTATUS
myAddDevice(
IN PDRIVER_OBJECT DriverObject,
IN PDEVICE_OBJECT PhysicalDeviceObject
)
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PMYFILTER_DEV_EXTENSION MyFlt_Ext;
PDEVICE_OBJECT FltDevObj = NULL;
PDEVICE_OBJECT LowerDevObj = NULL;
ntStatus = IoCreateDevice(
DriverObject,
sizeof(MYFILTER_DEV_EXTENSION),
NULL,
FILE_DEVICE_DISK,
FILE_DEVICE_SECURE_OPEN,
FALSE,
&FltDevObj);
ntStatus = IoAttachDeviceToDeviceStackSafe(
FltDevObj,
PhysicalDeviceObject,
&LowerDevObj);
MyFlt_Ext=(PMYFILTER_DEV_EXTENSION)FltDevObj->DeviceExtension;
MyFlt_Ext->LowerDevObj=LowerDevObj;
return STATUS_SUCCESS;
}
VOID
myUnload(
IN PDRIVER_OBJECT DriverObject
)
{
UNREFERENCED_PARAMETER(DriverObject);
return;
}
NTSTATUS myDispatchAny( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp )
{
PMYFILTER_DEV_EXTENSION MyFlt_Ext;
PDEVICE_OBJECT lowdev;
IoSkipCurrentIrpStackLocation(Irp);
MyFlt_Ext=PMYFILTER_DEV_EXTENSION (DeviceObject->DeviceExtension);
lowdev=MyFlt_Ext->LowerDevObj;
return(IoCallDriver(lowdev, Irp));
}
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
{
int i;
for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++)
{
DriverObject->MajorFunction[i] = myDispatchAny;
}
DriverObject->DriverExtension->AddDevice = myAddDevice;
DriverObject->DriverUnload = myUnload;
return STATUS_SUCCESS;
}
[解决办法]
注册成卷过滤驱动(Volume,你懂得);
要注意的地方:
对Pnp请求,必须对分页请求进行计数,设置相关的设备对象Flag标记。
你上面的代码,在AddDevice例程中对设备对象的重要标志位都没处理,自己去看看MSDN或书吧。