|
USB过滤驱动:在OnStartDevice中构造IRP读U盘0扇区的问题
[复制链接]
开发U盘过滤驱动,在OnStartDevice中构造IRP,功能号为IRP_MJ_READ,然后发送此IRP包,读取U盘的0扇区,但是读不到。
代码:
/*
Buffer : 存放读取数据的缓冲区.
Length : 需要读取的长度.(单位?)
*/
NTSTATUS TyReadSectorZero(PDEVICE_OBJECT DeviceObject, PVOID Buffer,ULONG Length)
{
KEVENT event;
NTSTATUS ntstatus = STATUS_SUCCESS;
//初始化事件
KeInitializeEvent(&event, NotificationEvent, FALSE);
//取得中断级别,判断是否可用IoBuildSynchronousFsdRequest
if(KeGetCurrentIrql() <= APC_LEVEL)
{
PIRP pReadIrp;
LARGE_INTEGER lioffset = {0};
IO_STATUS_BLOCK ioblock = {0};
//调用IoBuildSynchronousFsdRequest构造IRP包,返回值即为指向IRP的指针.
pReadIrp = IoBuildSynchronousFsdRequest(IRP_MJ_READ, DeviceObject, Buffer, Length, &lioffset, &event, &ioblock);
//构造IRP包失败
if(0 == pReadIrp)
{
KdPrint(("IoBuildSynchronousFsdRequest fail! \n"));
goto _end;
}
//发送IRP
ntstatus = IoCallDriver(DeviceObject, pReadIrp);
//等待事件
if(STATUS_PENDING == ntstatus)
{
KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, 0);
}
if(ioblock.Information == 0)
{
KdPrint(("ioblock.Information == 0 \n"));
goto _end;
}
KdPrint(("ioblock.Information == 0x%x \n", ioblock.Information));
//函数返回
}
_end:
return ntstatus;
}
不知问题出在哪里?请高手指点
|
|