1

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 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks for the fantastic answer! Do you also know what is more lower level - Disk Arbitration or the BSD functions? Who calls whom? Also, is there a BSD function to get the mount path by BSD name? I only found how to do it in Disk Arbitration.
BSD is lower level - it's in the kernel. Disk Arbitration (diskarbitrationd) is responsible for all the auto-mounting etc., so it may track more metadata, however. statfs has the device node and mount point in the f_mntfromname and f_mntonname fields, although they'll not always be populated depending on file system specifics (snapshots, etc.).
The getfsstat function will return the statfs structures for all currently mounted file systems, so you can just scan that array for the device you're looking for.
Thanks, does statfs() accept BSD name on the input? I thought it requires a file path. I tried to call it with "/dev/disk1s1" as the path but I'm getting strange results.
The statfs function takes a file path and looks up the file system on which the file described by that path resides. The getfsstat function returns an array of statfs structs for all mounted file systems, which you can then search through by whatever criteria you like, and this struct has fields for both file system location (BSD block device path, network file system's URL, etc) and mount point path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.