USB mass storage: device side data changes not visible on PC filesystem
usage detail: USB is being used as mass storage device. The device itself is an intelligent component and can create files at run time.
why using mass storage then? Since I did not want to develop USB DD for different platforms for transferring data. Existing universal mass storage driver can be used for the communication between PC and device
Issue: When my device is plugged in to a PC, it gets discovered as a separate drive and is visible in the file system. Now if I create a file on the device side, memory is visible to the PC, it does not reflect on PC's filesystem. The updated data is only visible once I perform a soft reset of my USB device or plug out and plug in my device, 开发者_StackOverflowsince device enumeration would take place again from the beginning.
Question: Why the modified data in the device memory not visible on the PC? Is there any method in USB low layer, using which I can send command to PC to perform device enumeration again?
This is fairly predictable, the host most likely caches the filesystem structure as it does not expect it to be changed externally. You may want to try making your media "removable", then inform the host of removal/insertion, but I suspect that may annoy the OS (if the medium is not read only) and also your users. This will probably be slightly less traumatic than the device resetting itself.
I solved this problem by indicating the media as "removable" in the lower SCSI protocol layer. When the device changes the filesystem, it then reports the media status as "removed" for a few seconds. Windows (and Linux too IMO) checks the media state about once in a second, and will show that the media is removed.
Once you make the media available again, the OS will re-read the filesystem with your changes. You don't want to do that too often, because this will also trigger those annoying Autorun dialogs.
The best way to do this is with test unit ready (TUR) command response and the request sense command response. Windows will send test unit ready commands about once a second when the media is idle. When you are done editing a file, mark the following TUR response as failed (0x01), the host will then issue a Request sense command which you should respond with 'unit attention' (0x06). Then make the following test unit command response pass (0x00). This will make windows invalidate the file cache and it will refetch the memory.
精彩评论