阅读:2100回复:3
sfilter里面在MountVolume的时候对该卷发送读IRP操作失败,返回STATUS_INVALID_DOMAIN_STATE,内有代码
请问要怎么解决啊
NTSTATUS ReadMbr(PDEVICE_OBJECT pDeviceObject) { //试试在IRP完成的时候读取 NTSTATUS status; PIRP pIrp; KEVENT Event; IO_STATUS_BLOCK IoStatus; LARGE_INTEGER Offset; PVOID pBuffer; PIO_STACK_LOCATION pStackLocation; __asm int 3; Offset.QuadPart = (LONGLONG)0; KeInitializeEvent(&Event,NotificationEvent,FALSE); pBuffer = ExAllocatePoolWithTag(NonPagedPool, sizeof(MBR), MY_USB_TAG); if (pBuffer == NULL) { return STATUS_INSUFFICIENT_RESOURCES; } pIrp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,pDeviceObject,pBuffer,sizeof(MBR),&Offset,&Event,&IoStatus); pIrp->UserEvent = &Event; status = IoCallDriver(pDeviceObject,pIrp); if (status == STATUS_PENDING) { KeWaitForSingleObject(&Event,Executive,KernelMode,FALSE,NULL); status = IoStatus.Status; } if (!NT_SUCCESS(status)) { KdPrint(("Irp Faild! IRP = %p, status = 0x%x",pIrp,status)); } // ExFreePoolWithTag(pBuffer,MY_USB_TAG); return status; } |
|
沙发#
发布于:2010-04-15 09:05
这里的参数是挂载插入的U盘的时候,SfFsControlMountVolume中的storageStackDeviceObject
NTSTATUS SfFsControlMountVolume ( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { PSFILTER_DEVICE_EXTENSION devExt = DeviceObject->DeviceExtension; PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp ); PDEVICE_OBJECT newDeviceObject; PDEVICE_OBJECT storageStackDeviceObject; PSFILTER_DEVICE_EXTENSION newDevExt; NTSTATUS status; BOOLEAN isShadowCopyVolume; PFSCTRL_COMPLETION_CONTEXT completionContext; PAGED_CODE(); ASSERT(IS_MY_DEVICE_OBJECT( DeviceObject )); ASSERT(IS_DESIRED_DEVICE_TYPE(DeviceObject->DeviceType)); storageStackDeviceObject = irpSp->Parameters.MountVolume.Vpb->RealDevice; ReadMbr(storageStackDeviceObject ); // 这个storageStackDeviceObject 应该是真实的U盘卷设备了吧?应该允许发读操作的IRP吧,可是却失败了,我还以为是卷没挂载好不能发IRP,在后面等卷挂载完毕了再发IRP操作还是失败了 ...... KeInitializeEvent( &waitEvent, NotificationEvent, FALSE ); IoCopyCurrentIrpStackLocationToNext ( Irp ); IoSetCompletionRoutine( Irp, SfFsControlCompletion, &waitEvent, //context parameter TRUE, TRUE, TRUE ); status = IoCallDriver( devExt->AttachedToDeviceObject, Irp ); // // Wait for the operation to complete // if (STATUS_PENDING == status) { status = KeWaitForSingleObject( &waitEvent, Executive, KernelMode, FALSE, NULL ); ASSERT( STATUS_SUCCESS == status ); } // // Verify the IoCompleteRequest was called // ASSERT(KeReadStateEvent(&waitEvent) || !NT_SUCCESS(Irp->IoStatus.Status)); status = SfFsControlMountVolumeComplete( DeviceObject, Irp, newDeviceObject ); ReadMbr(storageStackDeviceObject ); //这里等卷挂载完毕了再发IRP_MJ_READ读取该卷的头512字节还是失败 } 大家帮帮忙把,谢谢了 |
|
板凳#
发布于:2010-04-16 12:35
我觉得您确认挂载了之后,直接读取它,就和读文件一样更方便,不用再发IRP,
|
|
地板#
发布于:2010-04-16 13:54
谢谢,可是我试过挂载完了再读取也是失败啊,
我又试了用SCSI命令的读取,读不到内容 是不是这个设备有问题 我一直用vpb->RealDevice来读的, 用vpb->DeviceObject也试过,这个不行,会在BuildFsdRequest的时候卡死 |
|