阅读:3589回复:0
win7下驱动写磁盘扇区问题。。。。。
XP下好像没问题,
win7的话 执行到iocalldriver时 会hang住,成阻塞状态。 SL_FORCE_DIRECT_WRITE标志也加了,搞了几天了,不知道是原因。。。。 求解啊。。。。。。。。。。。。。 相关代码如下 NTSTATUS fastFsdRequest( IN PDEVICE_OBJECT DeviceObject, ULONG majorFunction, IN PLARGE_INTEGER ByteOffset, OUT PVOID Buffer, IN ULONG Length, IN BOOLEAN Wait ) { PIRP irp; IO_STATUS_BLOCK iosb; KEVENT event; NTSTATUS status; // irp = IoBuildAsynchronousFsdRequest(majorFunction, DeviceObject, Buffer, Length,ByteOffset, &iosb); if (!irp) { return STATUS_INSUFFICIENT_RESOURCES; } // vista 对直接磁盘写入进行了保护, 驱动操作需要在IRP的FLAGS加上SL_FORCE_DIRECT_WRITE标志 /* If the SL_FORCE_DIRECT_WRITE flag is set, kernel-mode drivers can write to volume areas that they normally cannot write to because of direct write blocking. Direct write blocking was implemented for security reasons in Windows Vista and later operating systems. This flag is checked both at the file system layer and storage stack layer. For more information about direct write blocking, see Blocking Direct Write Operations to Volumes and Disks. The SL_FORCE_DIRECT_WRITE flag is available in Windows Vista and later versions of Windows. http://msdn.microsoft.com/en-us/library/ms795960.aspx */ if (IRP_MJ_WRITE == majorFunction) { IoGetNextIrpStackLocation(irp)->Flags |= SL_FORCE_DIRECT_WRITE; } MmBuildMdlForNonPagedPool(irp->MdlAddress); if (Wait) { KeInitializeEvent(&event, NotificationEvent, FALSE); IoSetCompletionRoutine(irp, FltReadWriteSectorsCompletion, &event, TRUE, TRUE, TRUE); status = IoCallDriver(DeviceObject, irp); if (STATUS_PENDING == status) { KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL); status = iosb.Status; } } else { IoSetCompletionRoutine(irp, FltReadWriteSectorsCompletion, NULL, TRUE, TRUE, TRUE); irp->UserIosb = NULL; status = IoCallDriver(DeviceObject, irp); } if (!NT_SUCCESS(status)) { KdPrint(("IoCallDriver 0x%x fail 0x%x\n", majorFunction, status)); } return status; } pAdd=MmGetSystemAddressForMdlSafe(pIrp->MdlAddress,NormalPagePriority); KdPrint(("%s",pAdd)); g_dwWriteType=OLS_WRITE_UNKNOWN; RtlInitUnicodeString(&uniNameString, L"\\??\\PhysicalDrive1"); status=IoGetDeviceObjectPointer(&uniNameString,FILE_ALL_ACCESS,&pFile_Obj,&pDev_Obj_PhyDrv); if (status==STATUS_SUCCESS) { //__asm int 3; ObReferenceObject(pFile_Obj); pIrpSp=IoGetCurrentIrpStackLocation(pIrp); pIrpSp->Parameters.Write.ByteOffset.HighPart=0; pIrpSp->Parameters.Write.ByteOffset.LowPart=0; fastFsdRequest(pDev_Obj_PhyDrv,IRP_MJ_WRITE,&pIrpSp->Parameters.Write,ByteOffset,pAdd,512,TRUE); } |
|