概述
NTSTATUS DRIVER_DispatchRead(PDEVICE_OBJECT pDeviceObject,PIRP pIrp)
{
NTSTATUS ntStatus=STATUS_UNSUCCESSFUL;
__try
{
PIO_STACK_LOCATION pStack=IoGetCurrentIrpStackLocation(pIrp);
PDEVICE_EXTENSION pdx=(PDEVICE_EXTENSION)pDeviceObject->DeviceExtension;
ULONG ulReadLen=pStack->Parameters.Read.Length; // 要读取的长度
LONGLONG ulReadOffset=pStack->Parameters.Read.ByteOffset.QuadPart;
PVOID pMdlAdd=MmGetMdlVirtualAddress(pIrp->MdlAddress); // 锁定缓冲区虚拟地址
ULONG ulMdlOffset=MmGetMdlByteOffset(pIrp->MdlAddress); // 锁定缓冲区虚拟偏移
ULONG ulMdlLen=MmGetMdlByteCount(pIrp->MdlAddress); // 锁定缓冲区长度
if (ulReadLen==ulMdlLen)
{
PVOID pKernelAdd=MmGetSystemAddressForMdlSafe(pIrp->MdlAddress,NormalPagePriority); //锁定缓冲区内核映射
RtlCopyMemory(pKernelAdd,pdx->pBuf+ulReadOffset,ulReadLen);
pIrp->IoStatus.Information=ulReadLen;
pIrp->IoStatus.Status=STATUS_SUCCESS;
ntStatus=STATUS_SUCCESS;
IoCompleteRequest(pIrp,IO_NO_INCREMENT);
KdPrint(("Read Successfulrn"));
}
else
{
pIrp->IoStatus.Information=0;
pIrp->IoStatus.Status=STATUS_UNSUCCESSFUL;
ntStatus=STATUS_UNSUCCESSFUL;
KdPrint(("Read exceptrn"));
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
KdPrint(("Read Failern"));
pIrp->IoStatus.Information=0;
pIrp->IoStatus.Status=STATUS_UNSUCCESSFUL;
ntStatus=STATUS_UNSUCCESSFUL;
}
return ntStatus;
}
NTSTATUS DRIVER_DispatchWrite(PDEVICE_OBJECT pDeviceObject,PIRP pIrp)
{
NTSTATUS ntStatus=STATUS_UNSUCCESSFUL;
__try
{
PIO_STACK_LOCATION pStack=IoGetCurrentIrpStackLocation(pIrp);
PDEVICE_EXTENSION pdx=(PDEVICE_EXTENSION)pDeviceObject->DeviceExtension;
PVOID pMdlAdd=MmGetMdlVirtualAddress(pIrp->MdlAddress); // 锁定缓冲区虚拟地址
ULONG ulMdlOffset=MmGetMdlByteOffset(pIrp->MdlAddress); // 锁定缓冲区虚拟偏移
ULONG ulMdlLen=MmGetMdlByteCount(pIrp->MdlAddress); // 锁定缓冲区长度
ULONG ulWriteLen=pStack->Parameters.Write.Length;
LONGLONG ulWriteOffset=pStack->Parameters.Write.ByteOffset.QuadPart;
PVOID pKernelAdd=MmGetSystemAddressForMdlSafe(pIrp->MdlAddress,NormalPagePriority);
RtlCopyMemory(pdx->pBuf+ulWriteOffset,pKernelAdd,ulWriteLen); // 将用户数据存储至设备扩展
pdx->ulFileLen+=ulWriteLen;
pIrp->IoStatus.Information=ulWriteLen;
pIrp->IoStatus.Status=STATUS_SUCCESS;
ntStatus=STATUS_SUCCESS;
KdPrint(("Write successfulrn"));
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
pIrp->IoStatus.Information=0;
pIrp->IoStatus.Status=STATUS_UNSUCCESSFUL;
ntStatus=STATUS_UNSUCCESSFUL;
KdPrint(("Write exceptrn"));
}
IoCompleteRequest(pIrp,IO_NO_INCREMENT);
return ntStatus;
}
最后
以上就是无语篮球为你收集整理的直接方式读写的全部内容,希望文章能够帮你解决直接方式读写所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复