Mounting a disk with the DiskArbitration framework I have the following code that makes use of the DiskArbitration framework to mount a disk to its default location:

#import &lt;CoreFoundation/CoreFoundation.h&gt;
#import &lt;DiskArbitration/DiskArbitration.h&gt;

void MountCallback(DADiskRef disk, DADissenterRef dissenter, void *context);

int main(int argc, const char *argv[]) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s &lt;disk&gt;\n", argv[0]);
    return EXIT_FAILURE;
  }

  const char *deviceName = argv[1];

  DASessionRef session = DASessionCreate(kCFAllocatorDefault);
  DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, deviceName);

  // Pass NULL for a "standard" mount path.
  DADiskMount(disk, NULL, kDADiskMountOptionWhole, MountCallback, (void *)deviceName);

  DASessionSetDispatchQueue(session, NULL);
  CFRelease(session);
  session = NULL;

  return EXIT_SUCCESS;
}

void MountCallback(DADiskRef disk, DADissenterRef dissenter, void *context) {
  const char *mountedDisk = context;
  fprintf(stderr, "Device mounted: %s\n", mountedDisk);
  fflush(stderr);
  return;
}


To compile the code:

clang -Wall -Werror -g -v main.m -lobjc -framework DiskArbitration -framework Foundation -o mount


To run the program:

./mount diskN




The program works fine, however as a developer without much knowledge on the Apple platform, I'm interested in the following points:


The MountCallback function doesn't appear to be called. I don't see the line I'm printing to stderr.
In case the mount operation fails, how do I access the error, and use it return a different exit status on main? (I assume the error is caught from the callback, but can't find documentation about it).
Am I releasing the session and other resources I'm using for the task correctly?
A few years later, and not being a C expert; 
As far as I know (using Pascal myself), your application needs to wait for the callback to happen. By the looks of it though (again: not an expert) your application may already closed/finished before the callback actually happened.