Is it possible to get file system type and disk mount path by BSD name using only IO Registry?

huangapple go评论49阅读模式
英文:

Is it possible to get file system type and disk mount path by BSD name using only IO Registry?

问题

我知道可以使用磁盘仲裁框架和POSIX的statfs()函数来查找文件系统类型(apfs、hfs、msdos等)以及磁盘的挂载路径,通过磁盘的BSD名称来实现。

不过,我想知道这些信息是否也在IO注册表中有记录,以便我能够仅使用IOKit框架来提取它?

我在我的Mac的IO注册表中进行了搜索,但没有找到类似的信息,但仍然怀疑它可能存在。

有任何想法吗?

英文:

I'm aware that it's possible to find the file system type (apfs, hfs, msdos etc.) and also the disks's mount path by disk's BSD name using the Disk Arbitration framework and also the POSIX statfs() function.

However, I'm wondering if this information is also written somewhere in the IO Registry, so that I could extract it using only IOKit framework?

I've searched my own Mac's IO Registry but didn't find anything like that, but still suspect it's there.

Any ideas?

答案1

得分: 2

I/O Kit 不涉及挂载的文件系统,这是在 BSD 层发生的,因此 IOKit “看到”的只是来自 BSD 子系统的设备的读取、写入和 ioctl,并由 IOMediaBSDClient 转换为 IOStorage 方法调用。I/O Kit 不关心哪个文件系统发出这些 I/O 操作。

但是,它有“内容提示”(kIOMediaContentHintKey)属性,位于 IOMedia 节点上。内容提示会影响哪个文件系统尝试挂载块设备。

内容提示来自分区或卷管理方案:在 GPT 磁盘上,内容提示将是分区类型 GUID。每个文件系统实现都会宣传它正在寻找的内容提示,而操作系统(磁盘仲裁)会为任何声称支持新出现的块设备节点的内容提示的文件系统运行挂载命令。

请注意,内容提示仅仅是一个提示:

  • 这并不保证块设备实际包含特定类型的可挂载文件系统。
  • 即使块设备包含可挂载文件系统,I/O Kit 无法确定它是否当前已挂载。 (除了 IOStorage 节点可能是“打开的”或不打开的外,任何进程都可以打开块设备,内核中并不一定是文件系统实现在执行此操作。)
  • GPT 分区类型 GUID 和 MBR 分区类型号码未必是唯一的。

总之,BSD 和磁盘仲裁子系统中的精确等效挂载点信息在 I/O Kit 中是不存在的,尽管有一些关于块设备声称包含的文件系统类型的信息。

英文:

I/O Kit is not involved with mounted file systems: that happens at the BSD layer, so the only thing IOKit "sees" are the reads, writes, and ioctls to the device coming from the BSD subsystem and being converted into IOStorage method calls by the IOMediaBSDClient. I/O Kit does not care what file system is issuing those IO operations.

However, it does have the concept of a "content hint" (kIOMediaContentHintKey) property on an IOMedia node. The content hint influences which file system(s) will attempt to mount the block device.

The content hint comes from the partitioning or volume management scheme: on GPT disks, the content hint will be the partition type GUID. Each file system implementation advertises the content hints it is looking for, and the OS (Disk Arbitration) runs the mount command for any file systems claiming to support the content hint of a newly appeared block device node.

Note that the content hint is only a hint:

  • It is not a guarantee that the block device actually contains a mountable file system of any particular type.
  • Even if the block device contains a mountable file system, I/O Kit has no concept of whether or not it is currently mounted. (Except that an IOStorage node may be "open" or not, but any process can open a block device, it doesn't have to be a file system implementation in the kernel doing this.)
  • GPT partition type GUIDs and MBR partition type numbers are not necessarily unique.

So in short, no, the precisely equivalent mount point information from the BSD and Disk Arbitration subsystems does not exist in I/O Kit, although there is some information about file system types which the block device claims to contain.

huangapple
  • 本文由 发表于 2023年4月6日 21:51:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950316.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定