Cocoa: detect unmountable volume
I folks,
I am developing a small app which should be able to unmount volumes.
Currently, I am using the following code to determine whether a volume is unmountable or not:
BOOL isRemovable, isWritabl开发者_运维百科e, isUnmountable;
NSString *description, *type;
BOOL succ = [ws getFileSystemInfoForPath:[itemInfo objectForKey:@"path"]
isRemovable:&isRemovable
isWritable:&isWritable
isUnmountable:&isUnmountable
description:&description
type:&type];
The problem is that only physically removable volumes like a CD or DVD get isUnmountable=YES flag. USB devices don't, although these are unmountable, too.
Do you guys have a solution for that?
---- Edit
I tried it out with another USB stick which is FAT formatted. I got 2 USB hard disks connected to my mac which are unmountable via the Finder or Disk Utility - these are HFS formatted. I created an output which uses the code from above:
/, hfs, unmountable: NO, removable: NO
/Volumes/Elephant, hfs, unmountable: NO, removable: NO /Volumes/Time Machine, hfs, unmountable: NO, removable: NO /Volumes/USBSTICK, msdos, unmountable: YES, removable: YESIt looks like the method only returns YES if the device is FAT or MSDOS formatted. This is weird because the other 2 (Elephant, Time Machine) are volumes that are connected via USB and have to be removable and unmountable. Is there another way to get that information or have I done something wrong in my code?
--
Regards
Marco
Using your exact code, with my own USB stick (a 1GB Cruzer - yes, I know I'm behind), I'm getting a YES for isRemovable.
Though BOOL is usually represented as YES or NO, TRUE works. To make sure, I tested that as well. I'm getting isRemovable == TRUE/YES every time.
So since the condition "can be unmounted/removed" can depend on whether something is actually using a resource on the volume, it's likely that's what's preventing this method from answering with a "go ahead and unmount it." More context in your question might help identify that something.
精彩评论