Is there a more modern API than Disk Arbitration to know when a volume has been mounted?

There seems to be at least 3 possible APIs to detect the mounting of a volume on macOS:

  • Endpoint Security APIs through the NOTIFY_MOUNT event.
  • Disk Arbitration
  • NSWorkspace notifications.

If we omit NSWorkspace for different reasons (headless, background context), this leaves only 2 choices.

From what I'm reading and understanding, the NOTIFY_MOUNT event is just telling that a volume is being mounted. It does not guarantee that the volume is mounted at the time of the event.

So this seems to leave only Disk Arbitration.

Since the Disk Arbitration API has been there for a long time, the question is:

Is there a more modern API than Disk Arbitration to know when a volume has been mounted?

Answered by DTS Engineer in 770395022

There’s nowt wrong with using Disk Arb for this.

I wouldn’t use ES. That’s a whole world of complexity you don’t need for something this simple.

It’s a shame that the NSWorkspace stuff never got submerged into Foundation. Feel free to file an enhancement request for that.

The option you missed is Darwin notifications. The system posts kNotifyVFSMount when it mounts a volume. See <notify_keys.h> and the notify man page (section 3).

To work out what got mounted you must compare a snapshot of the current mount list against a previous snapshot. Build the snapshots by calling getfsstat.

Or just use Disk Arb (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

There’s nowt wrong with using Disk Arb for this.

I wouldn’t use ES. That’s a whole world of complexity you don’t need for something this simple.

It’s a shame that the NSWorkspace stuff never got submerged into Foundation. Feel free to file an enhancement request for that.

The option you missed is Darwin notifications. The system posts kNotifyVFSMount when it mounts a volume. See <notify_keys.h> and the notify man page (section 3).

To work out what got mounted you must compare a snapshot of the current mount list against a previous snapshot. Build the snapshots by calling getfsstat.

Or just use Disk Arb (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Is there a more modern API than Disk Arbitration to know when a volume has been mounted?
 
 
Q