如何共享对 FAT32 文件系统的访问

发布于 2024-12-19 19:39:51 字数 370 浏览 3 评论 0原文

我正在开发一种使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独木成林 2024-12-26 19:39:51

据我所知,两个设备无法使用FAT等通用文件系统协作共享块设备。 (除非它可能是只读文件系统)

解决方案是只有一个设备(即相机)拥有低级别(块级别)的文件系统。然后该设备可以使用更高级别的协议(高于原始块操作)共享文件。正如您所说,USB媒体传输协议就是一个例子。高级文件共享协议的其他示例是 NFS 和 SMB,尽管我认为这些协议不适用于这种情况。

引用维基百科上的媒体传输协议

使用 MTP 而不是 USB 大容量存储设备类 (MSC) 的主要原因是后者以大容量存储设备块(通常在实践中为 FAT 块)的粒度进行操作,而不是在逻辑文件级别。换句话说,USB 大容量存储类旨在为主机提供对大容量存储(例如紧凑型闪存)的无差别访问,而不是对文件系统的访问,该文件系统可以安全地与目标设备共享(除了特定文件)主机可能正在修改/访问)。因此,在实践中,当 USB 主机安装了 MSC 分区时,它会假定对存储的绝对控制,然后设备可能无法安全地修改该存储,而不会出现数据损坏的风险,直到主机切断连接为止。 p>

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:

A main reason for using MTP rather than for example the USB mass-storage device class (MSC) is that the latter operates at the granularity of a mass storage device block (usually in practice, a FAT block), rather than at the logical file level. In other words, the USB mass storage class is designed to give a host computer undifferentiated access to bulk mass storage, such as compact flash, rather than to a file system, which might be safely shared with the target device (except for specific files which the host might be modifying/accessing). In practice, therefore, when a USB host computer has mounted an MSC partition, it assumes absolute control of the storage, which then may not be safely modified by the device without risk of data corruption until the host computer has severed the connection.

你是年少的欢喜 2024-12-26 19:39:51

在同一张 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文