USB Mass Storage communication with PassThrough / more than 64K data length

http://social.msdn.microsoft.com/Forums/windowsdesktop/zh-CN/35620a05-43be-46a8-8cbe-846bc8295d85/usb-mass-storage-cWe have an USB mass storage / Memory Stick device with an additional device on it. We communicate with PassThrough mechanism to the device. 

Normally USB spec says that on USB level not more than 64K can
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.
 
This is currently  not longer working on Win8.
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.

Does anybody know why this was changed. 
Is that behavior wanted and if yes, why?  
Is that a bug? 
复制代码
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.

 

posted @   IAmAProgrammer  阅读(1580)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 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搭建本
点击右上角即可分享
微信分享提示