I’m trying to unmount a volume in my Cocoa application using the Disk Arbitration Framework.
Before calling:
DADiskUnmount(disk,
kDADiskUnmountOptionDefault,
unmountCallback,
self );
I register a callback function that get’s called afterwards:
void unmountCallback(DADiskRef disk, DADissenterRef dissenter, void *context )
{
if (dissenter != NULL)
{
DAReturn ret = DADissenterGetStatus(dissenter);
switch (ret) {
case kDAReturnBusy:
printf("kDAReturnBusy\n");
break;
}
}
In this function I try to interpret the dissenter return value but get stuck. I suppose it should be of type DAReturn and have a value like kDAReturnBusy But when e.g. iTunes is using the volume and it can not be unmounted “ret” has a value of 0xc010 that I don’t quite understand.
In case unmounting fails I’d like to find out why the volume can’t be unmounted and in case another application is using it remind the user of closing this application.
The documentation you linked to, for the
DAReturntype, lists all the Disk Arbitration constants as looking like this:So, DA’s error returns are all made of three components, OR’d together.
If you look at the documentation for
DADissenterGetStatus, it says:If you then search the headers for
unix_err, you find it in /usr/include/mach/error.h, which says:and:
There’s those three components again. Some other macros in error.h arrange the system and subsystem values (e.g.,
err_kernanderr_sub(3)) into those positions.So now, let’s open the Calculator, press ⌘3 to put it into programmer mode, switch it to base-16, and type in your error code, and see what it says:
Breaking that apart according to the above layout, we find:
System: 0, which error.h says is
err_kern. This error came from the kernel.Subsystem: 3 (0b11). This plus the system code matches the aforementioned definition of
unix_err. So this is a BSD return code, asDADissenterGetStatussaid.Individual error code: 16 (0x10, 0b10000).
UNIX/BSD errors are defined in
<sys/errno.h>, which says:This suggests to me that you can’t unmount that device because it’s in use.