0

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 run an external utility each time I want this info... wheres the API for this ?

ThinkingStiff
  • 64,767
  • 30
  • 146
  • 239
Yoni Shalom
  • 489
  • 4
  • 11

1 Answers1

1

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.

Community
  • 1
  • 1
Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • Sure it does. The code to which I linked detects the very situation you described (even if it's intended for a different purpose) so it can offer to move/copy the app into the Applications folder. Therefore, it's reasonable to expect to find the answer to your question in this example, no? – Joshua Nozzi Apr 14 '10 at 13:25
  • That link no longer works, but I tracked down the relevant code and added it to my similar question here: http://stackoverflow.com/questions/31545381/determine-if-a-volume-is-a-disk-image-dmg-from-code – Stan James Jul 21 '15 at 20:35
  • I've updated my answer here based on the answer to Stan James' question. – Joshua Nozzi Jul 22 '15 at 15:44