摘要: 使用QT进行SCSI指令操作时遇到问题,0x28读取正常,但0x2A写入失败,原因是系统对0x2A命令的写入权限控制严格。解决方法是通过FSCTL_LOCK_VOLUME实现独占访问,实现对USB设备的写操作。 问题参考:https://blog.csdn.net/kifea/article/details/103696099 0x2A命令参考: https://www.usbzh.com/article/detail-1014.html 问题:使用SCSI指令0x28读可以,0x2A进行写不成功,抓包看根本没有下发0x2A命令 原因:Win7之后,系统对2A命令写要求严格,设备必须加锁或者卸载卷才能操作。 解决方案: 独占访问,即通过FSCTL_LOCK_VOLUME 来设置独占访问。(相应的也解除独占访问设置 FSCTL_UNLOCK_VOLUME )。 (1). FSCTL_LOCK_VOLUME 的设置,参考:https://learn.microsoft.com/zh-cn/windows/win32/api/winioctl/ni-winioctl-fsctl_lock_volume 正常情况下 DeviceIoControl 函数返回1, lpBytesReturned 返回0
BOOL DeviceIoControl( (HANDLE) hVolume, // handle to a volume (DWORD) FSCTL_LOCK_VOLUME, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) lpBytesReturned, // number of bytes returned NULL // OVERLAPPED structure );(2). FSCTL_UNLOCK_VOLUME 的设置,参考:https://learn.microsoft.com/zh-cn/windows/win32/api/winioctl/ni-winioctl-fsctl_unlock_volume
BOOL DeviceIoControl( (HANDLE) hDevice, // handle to a volume FSCTL_UNLOCK_VOLUME, // dwIoControlCode NULL, // lpInBuffer 0, // nInBufferSize NULL, // lpOutBuffer 0, // nOutBufferSize (LPDWORD) lpBytesReturned, // number of bytes returned (LPOVERLAPPED) lpOverlapped // OVERLAPPED structure );
标签:NULL,USB,winioctl,VOLUME,FSCTL,SCSI,0x2A,QT From: https://www.cnblogs.com/-tbd-/p/18316600