site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Le 8 mai 08 à 10:21, Andy Green a écrit : Cheers, Andy 8<---- struct Nothing { bool dummy; }; static void AndygDiskArbCallback( DADiskRef disk, DADissenterRef dissenter, void * context) { printf("If I ever see this, my problems are over\n"); Nothing * n = (Nothing *)context; n->dummy = true; // I want to give a semaphore here to unlock the main thread } int main(int argc, char *argv[]) { const char * cStr = "disk0s2"; Nothing * n = new Nothing; n->dummy = false; DASessionRef diskArbSession = DASessionCreate(kCFAllocatorDefault); assert(diskArbSession); DADiskRef disk = DADiskCreateFromBSDName( kCFAllocatorDefault, diskArbSession, cStr ); assert(disk); printf("confirming %s == %s??\n", DADiskGetBSDName(disk), cStr); DADiskRef whole = DADiskCopyWholeDisk( disk ); if ( whole ) { printf("wholedisk == %s\n", DADiskGetBSDName(whole)); DADiskUnmount(whole, kDADiskUnmountOptionWhole | kDADiskUnmountOptionForce, AndygDiskArbCallback, n); CFRelease(whole); } // I'll do this too, once I get the callback from Unmount... // DADiskEject( disk, kDADiskEjectOptionDefault, AndygDiskArbCallback, NULL ); CFRelease(disk); CFRelease(diskArbSession); printf("AT THE END OF IT ALL, n=%d\n", n->dummy); delete(n); } Hello Andy, HTH, Axel #include <stdio.h> #include <DiskArbitration/DiskArbitration.h> typedef struct { int dummy; } Nothing; int main(int argc, char *argv[]) { const char * cStr; static Nothing * n; DASessionRef diskArbSession; DADiskRef disk; DADiskRef whole; SInt32 rc; cStr = "disk1s1"; n = (Nothing *) malloc(sizeof(Nothing)); n->dummy = -1; diskArbSession = NULL; disk = NULL; whole = NULL; rc = -1; free(n); return(0); } _______________________________________________ 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... I've written some code which uses the diskArbitration framework to unmount (and eject) a disk. It works, in that the disk gets unmounted, but my callback isn't being called, even though the operation is successful. Any chance of spotting the mistake in this code fragment? :- printf("------Wait..."); sleep(1); // instead of sleep, I want to wait on a semaphore here, until the unmount is complete. // unfortunately the callback isn't being called! You'll find hereafter an amended version of your code. For legibility purposes, I kept it very verbose and as as close as possible to your own version. But please check and double-check! I wrote it very quickly and am not very well versed myself into those matters. ;-) void AndygDiskArbCallback( DADiskRef disk, DADissenterRef dissenter, void * context); void AndygDiskArbCallback( DADiskRef disk, DADissenterRef dissenter, void * context) { printf("If I ever see this, my problems are over\n"); if (dissenter == NULL) ((Nothing *)context)->dummy = 0; else ((Nothing *)context)->dummy = DADissenterGetStatus(dissenter) ? DADissenterGetStatus(dissenter) : -1; // I want to give a semaphore here to unlock the main thread CFRunLoopStop(CFRunLoopGetCurrent()); } diskArbSession = DASessionCreate(kCFAllocatorDefault); if (diskArbSession != NULL) { DASessionScheduleWithRunLoop(diskArbSession, CFRunLoopGetCurrent(), CFSTR("drvHostBaseDA")); disk = DADiskCreateFromBSDName(kCFAllocatorDefault, diskArbSession, cStr); if (disk != NULL) { printf("Got disk bearing BSD name '%s' starting with string '%s'. \n", DADiskGetBSDName(disk), cStr); whole = DADiskCopyWholeDisk(disk); if (whole != NULL) { printf("Going to unmount whole disk with BSD name '%s'.\n", DADiskGetBSDName(whole)); DADiskUnmount(whole, kDADiskUnmountOptionWhole | kDADiskUnmountOptionForce, AndygDiskArbCallback, n); rc = CFRunLoopRunInMode(CFSTR("drvHostBaseDA"), 10.0, TRUE); if (rc == kCFRunLoopRunHandledSource) { printf("Something happened.\n"); if (n->dummy == 0) { printf("Unmount has been successful.\n"); // I'll do this too, once I get the callback from Unmount... // DADiskEject( disk, kDADiskEjectOptionDefault, AndygDiskArbCallback, NULL ); } else { printf("Unmount failed with code '%d'.\n", n->dummy); } } CFRelease(whole); } CFRelease(diskArbSession); } DASessionUnscheduleFromRunLoop(diskArbSession, CFRunLoopGetCurrent(), CFSTR("drvHostBaseDA")); CFRelease(disk); } This email sent to site_archiver@lists.apple.com
participants (1)
-
Axel Luttgens