Do you know you to unmount a drive without ejecting it. NSWorkspace
has some methods to unmount drives but it also eject them.
Any idea ?
Do you know you to unmount a drive without ejecting it. NSWorkspace
has some methods to unmount drives but it also eject them.
Any idea ?
I am doing it as follows and it un-mounts the drive but doesn't eject it.
(Actually I want to eject the disk, I can only un-mount the disk. :P Please share how to eject a disk.)
DASessionRef session = DASessionCreate(kCFAllocatorDefault);
CFURLRef path = CFURLCreateWithString(NULL, CFSTR("<path_to_your_volume_here>"), NULL);
DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, path);
DADiskUnmount(disk, kDADiskUnmountOptionDefault, __unmountCallback, NULL);
This is the code I am still working on and is under development and testing.
I am creating the "path" manually. You can use (and share) a better method to get the path of volume in a generic way. Perhaps this answer has hints of doing it the right way.
I'll update when my development is refined and complete.
To eject the disk, unmount the disk as you stated, and then in your __unmountCallback do the following:
DADiskRef disk2 = DADiskCopyWholeDisk(disk);
DADiskEject(disk2,
kDADiskEjectOptionDefault,
NULL,
NULL);
You can pass any object as context to the DADiskUnmount() and then, for example, use it to determine if the respective disk should be ejected in the __unmountCallback.