views:

274

answers:

2

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?

A: 

Would watching /Volumes for changes do what you need?

No, there's no guarantee that the device inserted will be mounted. It could be blank or damaged or an unrecognized format.
Rhythmic Fistman
+2  A: 

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

  • DARegisterDiskAppearedCallback
  • DARegisterDiskDisappearedCallback
  • DARegisterDiskDescriptionChangedCallback

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.

Rhythmic Fistman