以下是一个简单的过滤驱动,简单将所有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;
}
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课