int diskarb_unmount( const char * dir, int flags ) { int status; status = -1; if ( dir ) { DASessionRef session; session = DASessionCreate( kCFAllocatorDefault ); if ( session ) { CFURLRef path; path = CFURLCreateFromFileSystemRepresentation( kCFAllocatorDefault, ( void * ) dir, strlen( dir ), TRUE ); if ( path ) { DADiskRef disk; disk = DADiskCreateFromVolumePath( kCFAllocatorDefault, session, path ); if ( disk ) { DADiskUnmountOptions options; options = kDADiskUnmountOptionDefault; if ( ( flags & MNT_FORCE ) ) { options |= kDADiskUnmountOptionForce; } DASessionScheduleWithRunLoop( session, CFRunLoopGetCurrent( ), kCFRunLoopDefaultMode ); DADiskUnmount( disk, options, __diskarb_unmount, &status ); if ( status == -1 ) { CFRunLoopRun( ); } status = status ? -1 : 0; DASessionUnscheduleFromRunLoop( session, CFRunLoopGetCurrent( ), kCFRunLoopDefaultMode ); CFRelease( disk ); } CFRelease( path ); } CFRelease( session ); } } return status; }
/** * Use the DiskArbitration Daemon to inform us of media changes */ void MonitorThreadDarwin::run(void) { CFDictionaryRef match = kDADiskDescriptionMatchVolumeMountable; DASessionRef daSession = DASessionCreate(kCFAllocatorDefault); IOMasterPort(MACH_PORT_NULL, &sMasterPort); DARegisterDiskAppearedCallback(daSession, match, diskAppearedCallback, this); DARegisterDiskDisappearedCallback(daSession, match, diskDisappearedCallback, this); DARegisterDiskDescriptionChangedCallback(daSession, match, kDADiskDescriptionWatchVolumeName, diskChangedCallback, this); DASessionScheduleWithRunLoop(daSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); // Nice and simple, as long as our monitor is valid and active, // loop and let daSession check the devices. while (m_Monitor && m_Monitor->IsActive()) { // Run the run loop for interval (milliseconds) - this will // handle any disk arbitration appeared/dissappeared events CFRunLoopRunInMode(kCFRunLoopDefaultMode, (float) m_Interval / 1000.0f, false ); } DAUnregisterCallback(daSession, (void(*))diskChangedCallback, this); DAUnregisterCallback(daSession, (void(*))diskDisappearedCallback, this); DAUnregisterCallback(daSession, (void(*))diskAppearedCallback, this); CFRelease(daSession); }
void DiskArbitrationDispatcher::start() { std::lock_guard<std::mutex> lock(m_impl->mutex); if (!m_impl->scheduled) { DASessionScheduleWithRunLoop(m_impl->session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); m_impl->scheduled = true; } }
void QDeviceWatcherPrivate::run() { mStop = false; DASessionScheduleWithRunLoop(mSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); SInt32 result; do { result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true); } while (!mStop && result); DASessionUnscheduleFromRunLoop(mSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); }
__private_extern__ void ExternalMedia_prime(void) { gExternalMediaSet = CFSetCreateMutable(0, 0, &kCFTypeSetCallBacks); if (!gExternalMediaSet) return; gDASession = DASessionCreate(0); DARegisterDiskAppearedCallback(gDASession, kDADiskDescriptionMatchVolumeMountable, _DiskAppeared, NULL); DARegisterDiskDisappearedCallback(gDASession, kDADiskDescriptionMatchVolumeMountable, _DiskDisappeared, NULL); DASessionScheduleWithRunLoop(gDASession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); }
/* * Check if there are any mountable partitions on the disk. If there are any * mountable partitions, then we don't want to display the dialog. CoreStorage * and Apple_Boot partitions don't count as mountable for our purposes. */ static bool check_all_partitions(char *devname) { bool found_mountable_fs = false; SInt32 rc; CFNumberRef num = NULL; CFDictionaryRef description = NULL, matchDict = NULL; DASessionRef session = (DASessionRef)0; DADiskRef disk = (DADiskRef)0; session = DASessionCreate(kCFAllocatorDefault); if (session == (DASessionRef)0) goto exit; disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, devname); if (disk == (DADiskRef)0) goto exit; description = DADiskCopyDescription(disk); num = CFDictionaryGetValue(description, kDADiskDescriptionMediaBSDUnitKey); matchDict = CFDictionaryCreate(kCFAllocatorDefault, (const void **)&kDADiskDescriptionMediaBSDUnitKey, (const void **)&num, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); DASessionScheduleWithRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); DARegisterIdleCallback(session, idle_cb, &found_mountable_fs); DARegisterDiskAppearedCallback(session, matchDict, disk_appeared_cb, &found_mountable_fs); rc = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 10, false); DAUnregisterCallback(session, idle_cb, &found_mountable_fs); DAUnregisterCallback(session, disk_appeared_cb, &found_mountable_fs); DASessionUnscheduleFromRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); exit: if (disk) CFRelease(disk); if (session) CFRelease(session); if (description) CFRelease(description); if (matchDict) CFRelease(matchDict); return (!found_mountable_fs); }
void DiskArbitrationEventPublisher::restart() { if (run_loop_ == nullptr) { return; } stop(); WriteLock lock(mutex_); session_ = DASessionCreate(kCFAllocatorDefault); DARegisterDiskAppearedCallback( session_, nullptr, DiskArbitrationEventPublisher::DiskAppearedCallback, nullptr); DARegisterDiskDisappearedCallback( session_, nullptr, DiskArbitrationEventPublisher::DiskDisappearedCallback, nullptr); DASessionScheduleWithRunLoop(session_, run_loop_, kCFRunLoopDefaultMode); }
/** * Initialize mmc support */ void mmc_init() { da_session = DASessionCreate(kCFAllocatorDefault); DASessionScheduleWithRunLoop(da_session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); }