I decide to check the volume type in user space.
Wise choice!
Could you please take a look at my code. Is it correct?
You can do this more easily by calling
statfs
and then passing
f_mntfromname
to
DADiskCreateFromBSDName
.
Also, it’s a lot easier to wrangle dictionaries from Objective-C (or Objective-C++, if you’re so inclined). For example:
struct statfs stfs;
int err = statfs("/", &stfs);
… check error …
if ( !(stfs.f_flags & MNT_LOCAL) ) {
… bail out …
}
DASessionRef session = DASessionCreate(NULL);
CFAutorelease(session);
DADiskRef disk = DADiskCreateFromBSDName(NULL, session, stfs.f_mntfromname);
CFAutorelease(disk);
NSDictionary * diskInfo = CFBridgingRelease( DADiskCopyDescription(disk) );
BOOL isRemovable = [diskInfo[(__bridge NSString *) kDADiskDescriptionMediaRemovableKey] boolValue];
NSLog(@"removable: %@", isRemovable ? @"YES" : @"NO");
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"