USB Mass Storage communication with PassThrough / more than 64K data length
send with one Bulk-Only-Transport (BOT) command to the device.
On Win7 (and earlier) the mass storage driver has split the package
automatically into smaller BOT packages if the original package
has a volume of more than 64K.
If I send an answer buffer length of more than 64k then the DeviceIoControl()
was failing with error 87 (invalid Parameter).
If I send an answer buffer less the 64K it is working.
But I need a bigger buffer because our device can send more than 64K answer contents.
THIS_SCSI_PASS_THROUGH_DIRECT sptd; memset(&sptd, 0, sizeof(THIS_SCSI_PASS_THROUGH_DIRECT)); sptd.msptd.Length = sizeof(SCSI_PASS_THROUGH_DIRECT); ... sptd.msptd.DataTransferLength = cbData; // <<==== !!! sptd.msptd.DataBuffer = pData; // send receive command if ( !DeviceIoControl(hDevice, IOCTL_SCSI_PASS_THROUGH_DIRECT,&sptd, sizeof(THIS_SCSI_PASS_THROUGH_DIRECT), &sptd, sizeof(THIS_SCSI_PASS_THROUGH_DIRECT), &cbRecvData, NULL)) { // failed int nErrD= (int)wbs::SystemInfo::GetLastError();// error 87 (invalid parameter)
There is a known problem in Win8 builds before 8320,
where non-page aligned transfers fail for lengths falling
within the range [(64K - 4K), 64K].
The problem is fixed in builds 8320 or later.
I'm not sure when a newer build will be generally available.
In the meantime here are a few things to try.
The following per-device setting can be used to
increase the maximum transfer length from 64K to 128K,
enabling IOCTL_SCSI_PASS_THROUGH_DIRECT to transfer
more than 64K to the device.
As an added bonus it may also increase general I/O throughput to the device.
This setting is implemented on Windows Vista and above,
however use it with caution and thoroughly test with
a particular device to ensure the device can tolerate this change.
Some devices have been observed to have problems functioning properly
when this setting is modified.
With bit value 0x8 set on this DWORD registry value,
USBSTOR increases the maximum transfer length reported
for the specific device to 128KB. Otherwise the default value is 64KB.
HKLM\System\CurrentControlSet\Control\usbstor\VVVVPPPP DWORD: "DeviceHackFlags"
Where “VVVV” represents the 4-digit USB Vendor ID for the device
and “PPPP” represents the 4-digit Product ID.
Leading 0’s are required. Restart the device
(e.g. enable/disable or unplug/plug) for this setting to take effect.
To obtain Vendor/Product ID for the device open device manager
and select View -> Devices by connection.
Right click on “USB Mass Storage Device”
which is the parent of the recognized disk device.
Then select Propertiesfrom the pop-up menu to bring up the Properties dialog.
From the Properties dialog, select Details tab, then Hardware Idsproperty:
Also in Windows 8, a larger maximum transfer length value
is enabled by default for USB 3.0 mass storage devices.
The problem seems to be solved with Windows 8 Build 8400.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本