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

1

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 ?

Foreleg answered 12/4, 2010 at 10:50 Comment(0)
S
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.

Sidle answered 12/4, 2010 at 13:49 Comment(3)
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?Sidle
That link no longer works, but I tracked down the relevant code and added it to my similar question here: #31545881Holt
I've updated my answer here based on the answer to Stan James' question.Sidle

© 2022 - 2024 — McMap. All rights reserved.