我用IRP_MJ_READ命令构造的IRP失败了,是不是U盘一定要SCSI命令才能进行读写?
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 = IoBuildAsynchronousFsdRequest(IRP_MJ_READ,pDeviceObject,pBuffer,sizeof(MBR),&Offset,&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\n",pIrp,status));
}
// ExFreePoolWithTag(pBuffer,MY_USB_TAG);
return status;
}
上面这个是发送IRP_MJ_READ,结果下层设备返回STATUS_INVALID_PARAMETER
//
// MessageId: STATUS_INVALID_PARAMETER
//
// MessageText:
//
// An invalid parameter was passed to a service or function.
//
#define STATUS_INVALID_PARAMETER ((NTSTATUS)0xC000000DL)
帮帮忙吧,多谢了
------解决方案--------------------
U盘读写还可以基于BulkOnly协议啊.你可以看看相关的资料!
------解决方案--------------------
不许在那个 mj_internal_control 里面做的, 读 mbr 和读其他都是一样的,只是扇区不同而已,不能有 read, 下层驱动不会响应的;
在 mj_internal_cntrol 构造一个 urb