如何共享对 FAT32 文件系统的访问
我正在开发一种使用 SD 卡进行存储的嵌入式设备,并且需要允许 PC 通过 USB 访问该 SD 卡。
我能想到的最好方法是虚拟化磁盘并将虚拟化图片呈现给 PC。这将允许 PC 读取和写入文件,而我的设备也在读取和写入。
当您考虑到 PC 可能已缓存读取内容时,问题就出现了,因此 PC 用户在设备创建新文件时不可能看到新文件 - PC 只能看到连接时存在的文件。
另一个缺点是,在与 PC 断开连接之前取出闪存卡并不安全。
有没有解决方法?现代相机如何处理它?我相信媒体传输协议就是为了这个目的而创建的,但是它并没有以透明的方式得到广泛支持。我不处理“媒体”文件,尽管我认为这并不重要。
我是否缺少一些常用的巧妙解决方法?
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知,两个设备无法使用FAT等通用文件系统协作共享块设备。 (除非它可能是只读文件系统)
解决方案是只有一个设备(即相机)拥有低级别(块级别)的文件系统。然后该设备可以使用更高级别的协议(高于原始块操作)共享文件。正如您所说,USB媒体传输协议就是一个例子。高级文件共享协议的其他示例是 NFS 和 SMB,尽管我认为这些协议不适用于这种情况。
引用维基百科上的媒体传输协议:
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:
在同一张 SD 卡上构建两个不同的分区 - 让您的设备使用其中一个并将其中一个暴露给 PC。由于不会对同一文件系统进行并发访问,因此问题得以解决。
Build two different partitions on the same SD card - have your device use one and expose one to the PC. Since there will be no concurrent access to the same file system the problem is solved.