コード例 #1
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;
}
コード例 #2
0
QString DeviceInfo::deviceId() const
{
    QString uuid;

    DADiskRef disk;
    CFDictionaryRef descDict;
    DASessionRef session = DASessionCreate(NULL);

    if (session)
    {
        const char *mountPoint = "/";
        CFURLRef url = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8 *)mountPoint, strlen(mountPoint), TRUE);
        disk = DADiskCreateFromVolumePath(NULL, session, url);
        CFRelease(url);

        if (disk)
        {
            descDict = DADiskCopyDescription(disk);

            if (descDict)
            {
                CFTypeRef value = (CFTypeRef)CFDictionaryGetValue(descDict,
                                                                  CFSTR("DAVolumeUUID"));
                CFStringRef strValue = CFStringCreateWithFormat(NULL, NULL,
                                                                CFSTR("%@"), value);

                uuid = QString::fromCFString(strValue);

                CFRelease(strValue);
                CFRelease(descDict);
            }

            CFRelease(disk);
        }

        CFRelease(session);
    }

    QCryptographicHash hash(QCryptographicHash::Sha224);
    hash.addData(uuid.toLatin1());

    return QString::fromLatin1(hash.result().toHex());
}