コード例 #1
0
static int iokit_unmount (MMCDEV *mmc) {
    if (0 == mmc->is_mounted) {
        return 0; /* nothing to do */
    }

    BD_DEBUG(DBG_MMC, "Unmounting disk\n");

    mmc->session = DASessionCreate (kCFAllocatorDefault);
    if (NULL == mmc->session) {
        BD_DEBUG(DBG_MMC, "Could not create a disc arbitration session\n");
        return -1;
    }

    mmc->disk = DADiskCreateFromBSDName (kCFAllocatorDefault, mmc->session, mmc->bsd_name);
    if (NULL == mmc->disk) {
        BD_DEBUG(DBG_MMC, "Could not create a disc arbitration disc for the device\n");
        CFRelease (mmc->session);
        mmc->session = NULL;
        return -1;
    }

    DAApprovalSessionScheduleWithRunLoop (mmc->session, CFRunLoopGetCurrent (),
                                          kCFRunLoopDefaultMode);

    DADiskUnmount (mmc->disk, kDADiskUnmountOptionForce, iokit_unmount_complete, mmc);

    CFRunLoopRunInMode (kCFRunLoopDefaultMode, 10, true);

    return mmc->is_mounted ? -1 : 0;
}
コード例 #2
0
ファイル: libzfs_mount.c プロジェクト: roddi/maczfs-10a286
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;
}
コード例 #3
0
ファイル: mmc_osx.c プロジェクト: GregMefford/fwup
int mmc_umount_all(const char *mmc_device)
{
    DADiskRef disk = mmc_device_to_diskref(mmc_device);
    int rc = -1;
    if (disk) {
        struct disk_op_context context;
        context.operation = "unmount";
        DADiskUnmount(disk, kDADiskUnmountOptionWhole, disk_op_done_cb, &context);

        // Wait for a while since unmounting sometimes takes time.
        if (run_loop_for_time(10) < 0)
            fwup_warnx("unmount timed out");

        if (context.succeeded)
            rc = 0;
        CFRelease(disk);
    }
    return rc;
}