DiskArb DiskChangedCallback bug?
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 extern CFArrayRef kDADiskDescriptionWatchVolumePath; Thanks. static DASessionRef daSession = NULL; int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; if (NULL == (daSession = DASessionCreate(kCFAllocatorDefault))) return (ENOMEM); [[NSRunLoop currentRunLoop] run]; return (0); } -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.3 (Darwin) iD8DBQFEjaUIedHYW7bHtqIRAlOWAKCD6piZOd8pCmlL0Up3wV5gBd+FuACcDxa4 RnR8Zbu1Sea7TFxZcYHfEXg= =CE3t -----END PGP SIGNATURE----- _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... With the new 10.4 DiskArb API, the explicit mount/unmount callbacks were removed and instead you are supposed to use DARegisterDiskDescriptionChangedCallback(): /*! * @constant kDADiskDescriptionWatchVolumePath * Predefined CFArray object containing a set of disk description keys appropriate for * watching volume mount changes using DARegisterDiskDescriptionChangedCallback(). */ However, there's seems to be a bug with this on 10.4.6 (PPC, haven't tried Intel) in that the callback is never called for volume mounts, only for volume unmounts. Here's a test case. If you set a break point on DiskArbCallback_ChangeNotification(), and then insert a disk (I tried an AudioCD and a USB FAT flash drive), the breakpoint is not hit when the volume mounts, but when you eject it, gdb stops. I've opened a bug report: rdar://4582301, but I wanted to see if perhaps I'm missing something or if there is an actual bug, is there some kind of workaround to detect a mount? // cc -g -O0 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -framework Foundation -framework DiskArbitration -o datest datest.m #import <DiskArbitration/DiskArbitration.h> #import <Foundation/Foundation.h> static void DiskArbCallback_ChangeNotification(DADiskRef disk, CFArrayRef keys, void * context) { NSDictionary *d = (NSDictionary*)DADiskCopyDescription(disk); NSURL *path; if (d && (path = [d objectForKey:(NSString*) kDADiskDescriptionVolumePathKey]) && [[NSFileManager defaultManager] fileExistsAtPath:[path path]]) { printf("Volume mounted on: %s\n", [[path path] fileSystemRepresentation]); } else if (d && (!path || NO == [[NSFileManager defaultManager] fileExistsAtPath:[path path]])) { printf("Volume unmounted"); } [d release]; } DASessionScheduleWithRunLoop(daSession, [[NSRunLoop currentRunLoop] getCFRunLoop], kCFRunLoopDefaultMode); // Since there is no explicit mount callback, the Change callback is how we detect a mount. DARegisterDiskDescriptionChangedCallback(daSession, NULL, kDADiskDescriptionWatchVolumePath, DiskArbCallback_ChangeNotification, NULL); This email sent to site_archiver@lists.apple.com
participants (1)
-
Brian Bergstrand