(MACOSX) - knowing if a mounted device is mounted from DMG

Could not find this information using DiskArbitration or FSGetVolumeInfo / GetVolumeParms ...

I know that hdiutil uses a private framework called the DiskImages framework, but I wouldn't want to run an external utility every time I need this information ... for this API?

0


source to share


1 answer


July 2015 Update

This update was suggested by Stan James in a new question .

You can get this information using DiskArbitration . To use the example below, you have to link it and #import

.

#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;

}

      

Using:

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

      

Hope this helps.

+1


source







All Articles