I am working on an embedded device that uses an SD-Card for storage and needs to allow a PC to access that SD-Card over USB.
The best approach I could come up with is virtualizing the disk and presenting that virtualized picture to the PC. That would allow the PC to read and write files, while my device is also reading and writing.
The problem comes up when you consider that the PC may have cached reads, so it becomes impossible for the PC user to see new files as the device creates them — The PC will only see files that existed at the time it was connected.
Another drawback is that it is not safe to remove the flash card until the PC has been disconnected.
Are there any workarounds for this? How do modern cameras handle it? I believe that media transfer protocol was created for just this purpose, however it is not widely supported in a transparent manner. And I’m not dealing with “media” files, although I assume that doesn’t matter.
Is there some commonly used clever workaround that I am missing?
Thank you
As far as I know, there is no way for two devices to cooperatively share a block device using common file systems such as FAT. (unless perhaps it’s a read-only file system)
The solution is for only one device (i.e. the camera) to own the file system at the low level (block level). Then that device can share files using a higher-level protocol (higher than raw block operations). As you said, the USB Media Transfer Protocol is an example of that. Other examples of a higher-level file sharing protocol are NFS and SMB, although I don’t think those would be applicable in this scenario.
Quoting from Media Transfer Protocol on Wikipedia: