我正在尝试使用磁盘仲裁框架卸载我的 Cocoa 应用程序中的卷。
调用前:
DADiskUnmount(disk,
kDADiskUnmountOptionDefault,
unmountCallback,
self );
我注册了一个回调函数,之后会被调用:
void unmountCallback(DADiskRef disk, DADissenterRef dissenter, void *context )
{
if (dissenter != NULL)
{
DAReturn ret = DADissenterGetStatus(dissenter);
switch (ret) {
case kDAReturnBusy:
printf("kDAReturnBusy\n");
break;
}
}
在这个函数中,我尝试解释异议者的返回值,但卡住了。我想它应该是 DAReturn 类型并且具有类似 kDAReturnBusy 的值但是当例如iTunes 正在使用该卷,无法卸载“ret”的值为 0xc010,我不太明白。
如果卸载失败,我想找出无法卸载该卷的原因,如果另一个应用程序正在使用它,我会提醒用户关闭此应用程序。
最佳答案
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.
您链接到的文档,用于 DAReturn
类型,列出所有磁盘仲裁常量,如下所示:
kDAReturnError = err_local | err_local_diskarbitration | 0x01, /* ( 0xF8DA0001 ) */
因此,DA 的错误返回全部由三个部分组成,通过“或”运算组合在一起。
如果你看the documentation for DADissenterGetStatus
,它说:
A BSD return code, if applicable, is encoded with unix_err().
如果您随后在 header 中搜索 unix_err
,您会在/usr/include/mach/error.h 中找到它,它说:
/* unix errors get lumped into one subsystem */ #define unix_err(errno) (err_kern|err_sub(3)|errno)
和:
/* * error number layout as follows: * * hi lo * | system(6) | subsystem(12) | code(14) | */
又是这三个组件。 error.h 中的一些其他宏将系统和子系统值(例如 err_kern
和 err_sub(3)
)排列到这些位置。
那么现在,让我们打开计算器,按 ⌘3 将其置于程序员模式,将其切换为 base-16,然后输入您的错误代码,看看它会显示什么:
0xC010
0000 0000 0000 0000 1100 0000 0001 0000 31 15 0
按照上面的布局把它拆开,我们发现:
0000 00 31
系统:0,error.h 说的是 err_kern
.此错误来自内核。
00 0000 0000 11 31 15
子系统:3 (0b11)。这加上系统代码匹配上述 unix_err
的定义.所以这是一个 BSD 返回码,如 DADissenterGetStatus
说。
00 0000 0001 0000 31 15 0
个别错误码:16 (0x10, 0b10000)。
UNIX/BSD 错误在 <sys/errno.h>
中定义,它说:
#define EBUSY 16 /* Device / Resource busy */
这表明您无法卸载该设备,因为它正在使用中。
关于objective-c - 尝试在 OS X 中卸载卷时解释返回值(反对者),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8565302/