Interpret return value (dissident) when trying to disable volume in OS X

I am trying to disconnect a volume in my Cocoa application using a disk arbitration structure.

Before calling:

DADiskUnmount(disk, kDADiskUnmountOptionDefault, unmountCallback, self ); 

I register a callback function that is called later:

 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 am trying to interpret the return value of a dissident, but I am stuck. I assume that it should be of type DAReturn and have a value similar to kDAReturnBusy But when, for example, iTunes uses volume and cannot be unmounted. "ret" has a value of 0xc010, which I do not quite understand.

In the event of a failure, I would like to know why this volume cannot be unmounted, and if another application is used, it reminds the user to close this application.

+7
source share
1 answer

But when, for example, iTunes uses volume and cannot be unmounted. "ret" has a value of 0xc010, which I do not quite understand.

The documentation that you are attached to for the DAReturn type lists all disk arbitration constants that look like this:

  kDAReturnError = err_local | err_local_diskarbitration | 0x01, /* ( 0xF8DA0001 ) */ 

Thus, DA error return consists of three components, OR'd together.

If you look at the documentation for DADissenterGetStatus , it says:

The BSD return code, if applicable, is encoded using unix_err ().

If you then look at the headers for unix_err , you will find it in /usr/include/mach/error.h which says:

 /* unix errors get lumped into one subsystem */ #define unix_err(errno) (err_kern|err_sub(3)|errno) 

and

 /* * error number layout as follows: * * hi lo * | system(6) | subsystem(12) | code(14) | */ 

These three components again. Some other macros with the .h error arrange the values โ€‹โ€‹of the system and subsystem (for example, err_kern and err_sub(3) ) at these positions.

So, open the calculator, press โŒ˜3 to put it into programming mode, switch it to base-16 and enter the error code and see what it says:

0xC010

 0000 0000 0000 0000 1100 0000 0001 0000 31 15 0 

Separating this in accordance with the above diagram, we find:

 0000 00 31 

System: 0, which error.h is talking about err_kern . This error has arisen from a kernel.

  00 0000 0000 11 31 15 

Subsystem: 3 (0b11). This plus system code matches the definition of unix_err above. So this is the BSD return code, as DADissenterGetStatus said.

  00 0000 0001 0000 31 15 0 

Individual error code: 16 (0x10, 0b10000).

UNIX / BSD errors are defined in <sys/errno.h> , which states:

 #define EBUSY 16 /* Device / Resource busy */ 

This suggests that you cannot disconnect this device because it is being used.

+16
source

All Articles