removable drive (thumb drive, harddisk), CD/DVD drive and network share (SMB, AFP), regardless of the their connection types.
This is a tricky business. Part of the problem is one of definition. Let’s say I have a DVD mounted over iSCSI. Is that a DVD drive? Or a network drive? It kinda depends on how you look at it. It’s a DVD drive in terms of it drive access semantics but it’s a network drive in terms of latency and reliability.
Note This is not a theoretical example. For a long time macOS supported System Preferences > Sharing > DVD or CD Sharing.
Anyway, to start you can distinguish between network volumes and non-network volumes by looking at the
MNT_LOCAL
flag. In general, a volume with
MNT_LOCAL
set is expected to have a mount-from value (for example,
f_mntfromname
in
statfs
) that leads to a dev node.
Be warned:
Local volumes can actually be running over the network, as in the iSCSI example I gave above.
Non-local volumes are often used for completely virtual file systems, like the
procfs
example in Fuse for macOS.Even for a local volume, the mount-from value may be virtual (for example, a disk image).
Beyond that, things get even trickier. You can use the mount-from value on a local volume to get to an I/O Registry entry, and then monkey around in the I/O Registry looking for key information about the volume. You will end up with a bunch of special cases, and those special cases will have to be updated over time.
My general advice would be to bounce out to user space and ask DiskArbitration about the volume. It already calculates the info, so relying on it saves you a bunch of work and ensures you use the same values as the rest of the OS.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"