2

I have a problem using DiskArbitration framework, to catch disk image mounting I register for DARegisterDiskMountApprovalCallback. The problem is that each time a disk image is mounted, the callback is called twice. Why is that and how can I solve this?

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
Nyx0uf
  • 4,609
  • 1
  • 25
  • 26

4 Answers4

1

When a disk is mounted you often see an event for the whole disk and then events for distinct partitions on that disk. You'll need to distinguish.

static void got_disk(DADiskRef disk, void *context)
{
    CFDictionaryRef dict = DADiskCopyDescription(disk);
    NSNumber *whole = CFDictionaryGetValue(dict, kDADiskDescriptionMediaWholeKey);
    if (![whole boolValue]) {
        // Handle your event only with the partition, not the "whole" disk
        ...
    }
}

It's very handy to put a CFShow(dict) in your event handler and see what you get.

frankleonrose
  • 355
  • 2
  • 11
1

I ended up coding something to detect the 2nd mount and ignore it.

Cezar
  • 55,636
  • 19
  • 86
  • 87
Nyx0uf
  • 4,609
  • 1
  • 25
  • 26
0

I use these the catch that. I'm not sure of the difference these are to what you're doing but they work.

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(mediaMounted:) name:NSWorkspaceDidMountNotification object:[NSWorkspace sharedWorkspace]];

[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(mediaUnmounted:) name:NSWorkspaceWillUnmountNotification object:[NSWorkspace sharedWorkspace]];
Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
regulus6633
  • 18,848
  • 5
  • 41
  • 49
  • 1
    I can't use NSWorkspace, it comes from appKit which isn't not daemon safe, and I need to run this as a daemon. – Nyx0uf May 26 '10 at 18:23
0

Did you put a breakpoint in your callback to see what are the call-stack when it is called ? It can gives you some hints on what is going on.

Laurent Etiemble
  • 27,111
  • 5
  • 56
  • 81