I am want to unmount a disk WITHOUT EJECTING. To do that I tried following code
{
NSString *path;
CFStringRef *volumeName=(__bridge CFStringRef)path;
DASessionRef session = DASessionCreate(kCFAllocatorDefault);
CFURLRef pathRef = CFURLCreateWithString(NULL, CFSTR("/volumes/Untitled"), NULL);
DADiskRef disk = DADiskCreateFromVolumePath(kCFAllocatorDefault, session, pathRef);
DADiskUnmount(disk, kDADiskUnmountOptionForce, NULL, NULL);
}
This code is from this question, Thanks to @zeFree
Its working but I want dynamic path to the volume where as in the code its static. I tried changing NSString to CFStringRef and then tried to use at place of path("/volumes/Untitled") mention but its still same.
Any suggestion is welcome.
First of all, you are strongly discouraged from using
kDADiskUnmountOptionForce
.This is a method to unmount a volume at given URL with basic error handling and memory management.
The error handling could be still improved by providing a callback handler in the
DADiskUnmount
function.