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; }
void DiskArbitrationDispatcher::stop() { std::lock_guard<std::mutex> lock(m_impl->mutex); if (m_impl->scheduled) { DASessionUnscheduleFromRunLoop(m_impl->session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); m_impl->scheduled = false; } }
void QDeviceWatcherPrivate::run() { mStop = false; DASessionScheduleWithRunLoop(mSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); SInt32 result; do { result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1, true); } while (!mStop && result); DASessionUnscheduleFromRunLoop(mSession, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); }
void DiskArbitrationEventPublisher::stop() { if (run_loop_ == nullptr) { return; } WriteLock lock(mutex_); if (session_ != nullptr) { DASessionUnscheduleFromRunLoop(session_, run_loop_, kCFRunLoopDefaultMode); CFRelease(session_); session_ = nullptr; } CFRunLoopStop(run_loop_); }
/* * 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); }