有谁知道LowerFilters中IOCTL_STORAGE_GET_DEVICE_NUMBER这个不行,但在UpperFilters中这个行的原因,
怎么才能让他行。
我在DispatchAddDevice中获得磁盘号代码:
KEVENT event2;
PIRP irp;
STORAGE_DEVICE_NUMBER number={0};
IO_STATUS_BLOCK ioStatus={0};
NTSTATUS status2,status3;
PDEVICE_OBJECT physicalob;
KeInitializeEvent(&event2, NotificationEvent, FALSE);
//
// Request for the device number
//
irp = IoBuildDeviceIoControlRequest(
IOCTL_STORAGE_GET_DEVICE_NUMBER,
pdx->LowerDeviceObject,
NULL,
0,
&number,
sizeof(number),
FALSE,
&event2,
&ioStatus);
if (!irp) {
DbgPrint("Device: Fail to build irp\n");
//return STATUS_INSUFFICIENT_RESOURCES;
}else{
status3 = IoCallDriver(pdx->LowerDeviceObject, irp);
if (status3 == STATUS_PENDING) {
KeWaitForSingleObject(&event2, Executive, KernelMode, FALSE, NULL);
status2 = ioStatus.Status;
}else{
DbgPrint("Device: Fail.Status:%d\n",status3);
status2 = ioStatus.Status;
}
if (NT_SUCCESS(status2)) {
pdx->disknumber=number.DeviceNumber;
KdPrint(("DeviceNumber: %d ",number.DeviceNumber));
}else{
KdPrint(("fail to IoCallDriver."));
}
}pdx->LowerDeviceObject是如何获得的?UpFilter和LowerFilter的这个对象是不一样的吧?
另外,你在LowerFilter里面发IOCTL后,返回的错误代码是什么?
不太知道Storage设备驱动的具体Stack是什么样的。但是大概是下面的样子:
-1 UpFilter Driver
-2 Function Driver
-3 LowerFiler Driver
-4 Bus Driver
如果说IOCTL_STORAGE_GET_DEVICE_NUMBER是在2 Function Driver里面实现,那么在Upfilter Driver里面发该IOCTL是会得到响应的。
如果在LowerFilter Driver里面发IOCTL_STORAGE_GET_DEVICE_NUMBER,那么LowerDeviceObject就会是Bus Driver。而Bus Driver没有实现该IOCTL,所以就不支持该IOCTL。
可以考虑将值写入注册表进行通讯;
或者实现两个驱动间的通讯。
Beyond IRPs: Driver to Driver Communications