/* druErase Called to do a erase. Pass in the device and a flag to indicate a full or quick erase. */ int druErase(DRDeviceRef device, int fullErase) { DREraseRef erase = NULL; DRNotificationCenterRef notificationCenter = NULL; CFRunLoopSourceRef source = NULL; druBurnStatus status = {0, NULL, NULL, NULL, {0}, 0}; CFMutableDictionaryRef properties; erase = DREraseCreate(device); if (erase != NULL) { /* Create a progress bar. */ status.progressBar = druProgressBarCreate(); /* Sign up for notifications from the erase object. */ notificationCenter = DRNotificationCenterCreate(); source = DRNotificationCenterCreateRunLoopSource(notificationCenter); CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes); DRNotificationCenterAddObserver(notificationCenter,&status,druProgressCallback,kDREraseStatusChangedNotification, erase); /* setup erase properties for type of erase to be performed */ properties = CFDictionaryCreateMutable(NULL,0,&kCFTypeDictionaryKeyCallBacks,&kCFTypeDictionaryValueCallBacks); if (fullErase) CFDictionaryAddValue(properties,kDREraseTypeKey,kDREraseTypeComplete); else CFDictionaryAddValue(properties,kDREraseTypeKey,kDREraseTypeQuick); DREraseSetProperties(erase, properties); /* Okay, start the erase. */ DREraseStart(erase); /* Enter a runloop until the burn finishes. */ CFRunLoopRun(); /* Clean up memory and exit. */ CFRunLoopSourceInvalidate(source); if (notificationCenter != NULL) CFRelease(notificationCenter); if (source != NULL) CFRelease(source); if (status.progressBar != NULL) druProgressBarDispose(status.progressBar,status.success); CFRelease(erase); } if (status.success) printf("Erase completed.\n"); else druPrintFailureMessage("Erase", status.completionStatus); if (status.completionStatus != NULL) CFRelease(status.completionStatus); return status.success; }
/* Erase the media in the currently opened device */ int PortBurn_StartErasing(void *handle, int type) { CFMutableDictionaryRef props; PBHandle *h = (PBHandle *)handle; if (h == NULL) { return pbErrNoHandle; } if (h->device == NULL) { return pbErrDeviceNotOpen; } if (h->burn != NULL || h->erase != NULL) { return pbErrCannotStartErasing; } h->erase = DREraseCreate(h->device); if (h->erase == NULL) { return pbErrCannotPrepareToErase; } props = CFDictionaryCreateMutableCopy(NULL, 0, DREraseGetProperties(h->erase)); if (props == NULL) { CFRelease(h->erase); h->erase = NULL; return pbErrCannotPrepareToErase; } CFDictionaryAddValue(props, kDREraseTypeKey, type ? kDREraseTypeComplete : kDREraseTypeQuick); DREraseSetProperties(h->erase, props); CFRelease(props); h->frac = 0.0; h->err = DREraseStart(h->erase); if (h->err != noErr) { CFRelease(h->erase); h->erase = NULL; return pbErrCannotStartErasing; } return pbSuccess; }