macosvolumedeviceiokitdiskarbitration

Detecting appearance/disappearance of volumes on osx


I want to update a list of storage devices as the user inserts USB keys, adds external disks and mounts disk images. IOKit's IOServiceAddInterestNotification looks like the way to go, but the obvious use of registering general interest in kIOMediaClass only gives you notifications for unmounting of volumes and then only sometimes.

What's the right way to do this?


Solution

  • The following calls in DiskArbitration.h do exactly what I want:

    These cover insertion, removal (even of unmountable volumes)
    metadata change events.

    P.S. Don't forget to add your DASession to a runloop
    or you won't get any callbacks.