开发者

(MACOSX) - Knowing whether a mounted device was mounted from a DMG

Couldn't find that info using DiskArbitration or FSGetVolumeInfo/GetVolumeParms...

I know that hdiutil uses a private framework called DiskImages framework, but I wouldn't want to 开发者_StackOverflow社区run an external utility each time I want this info... wheres the API for this ?


July 2015 Update

This update was prompted by Stan James' new question.

You can obtain this information using the DiskArbitration framework. To use the example below, you must link against and #import it.

#import <DiskArbitration/DiskArbitration.h>

...

- (BOOL)isDMGVolumeAtURL:(NSURL *)url
{

  BOOL isDMG = NO;

  if (url.isFileURL) {

    DASessionRef session = DASessionCreate(kCFAllocatorDefault);
    if (session != nil) {

      DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, (__bridge CFURLRef)url);
      if (disk != nil) {

        NSDictionary * desc = CFBridgingRelease(DADiskCopyDescription(disk));
        NSString * model = desc[(NSString *)kDADiskDescriptionDeviceModelKey];
        isDMG = ([model isEqualToString:@"Disk Image"]);

        CFRelease(disk);

      }

      CFRelease(session);

    }

  }

  return isDMG;

}

Usage:

BOOL isDMG = [someObject isDMGVolumeAtURL:[NSURL fileURLWithPath:@"/Volumes/Some Volume"]];

I hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜