Is It A Disk Image?

A comment on an old StackOverflow answer of mine took me to task for a “partial answer” so I decided to improve it. Both posters wanted to know if a mounted device is a disk image. I wrote a simple routine using the DiskArbitration framework to test this given a file URL.

The Code

#import <DiskArbitration/DiskArbitration.h>
– (BOOL)isDMGVolumeAtURL:(NSURL *)url
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"]);
return isDMG;
view raw SomeObject.m hosted with ❤ by GitHub


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

In the above someObject refers to whatever object you put this method in, of course. It should probably be a category on NSURL (so you could ask the url directly: BOOL isDMG = [volumeMountPointURL isDMG];). I hope you find it useful!