views:

61

answers:

1

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, isWritable, 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: YES

It 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

+2  A: 

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.

Joshua Nozzi
Thanks for your input. I edited my post with more context and tried the code another time with a USB stick myself. Do you have any idea why it only works with MSDOS formatted devices?
Marco Nätlitz
I just wiped and reformatted my stick as HFS+ and repeated the test. Works fine. Both isUnmountable and isRemovable are YES.
Joshua Nozzi
Hmm... So why do USB sticks work and USB hard disks not? Doesn't sound like real problem. There must be a reason why the same code acts differently. Btw: I am using 10.6.4 along with the latest development tools...
Marco Nätlitz
I'm using the same environment. Not at all sure what's going on. Just checked with a 2-partition HFS+ USB hard drive. Again, works fine. :-} You should probably name the hardware. Also, test under a newly-created user account (with your current account logged out) to make sure nothing "non-vanilla" gets busy with your drive in the user space. The next step would be testing it on a fresh OS X install.
Joshua Nozzi