Cocoa:检测无法安装的卷
伙计们,
我正在开发一个小型应用程序,它应该能够卸载卷。
目前,我使用以下代码来确定卷是否不可安装:
BOOL isRemovable, isWritable, isUnmountable;
NSString *description, *type;
BOOL succ = [ws getFileSystemInfoForPath:[itemInfo objectForKey:@"path"]
isRemovable:&isRemovable
isWritable:&isWritable
isUnmountable:&isUnmountable
description:&description
type:&type];
问题是只有物理可移动卷(例如 CD 或 DVD)才会获得 isUnmountable=YES 标志。 USB 设备则不然,尽管它们也是不可安装的。
你们有解决办法吗?
---- 编辑
我用另一个 FAT 格式的 USB 记忆棒进行了尝试。我的 Mac 连接了 2 个 USB 硬盘,这些硬盘无法通过 Finder 或磁盘实用程序卸载 - 这些硬盘都是 HFS 格式的。我创建了一个使用上面代码的输出:
/,hfs,不可安装:否,可移动:否
/Volumes/Elephant,hfs,不可安装:否,可移动:否
/Volumes/Time Machine,hfs,不可安装:否,可移动:否
/Volumes/USBSTICK,msdos,不可安装:是,可移动:
是 看起来该方法仅在设备为 FAT 或 MSDOS 格式时返回 YES。这很奇怪,因为其他 2 个(大象、时间机器)是通过 USB 连接的卷,并且必须是可移动和不可安装的。是否有其他方法来获取该信息或者我在代码中做错了什么?
——
问候
马可
I folks,
I am developing a small app which should be able to unmount volumes.
Currently, I am using the following code to determine whether a volume is unmountable or not:
BOOL isRemovable, isWritable, isUnmountable;
NSString *description, *type;
BOOL succ = [ws getFileSystemInfoForPath:[itemInfo objectForKey:@"path"]
isRemovable:&isRemovable
isWritable:&isWritable
isUnmountable:&isUnmountable
description:&description
type:&type];
The problem is that only physically removable volumes like a CD or DVD get isUnmountable=YES flag. USB devices don't, although these are unmountable, too.
Do you guys have a solution for that?
---- Edit
I tried it out with another USB stick which is FAT formatted. I got 2 USB hard disks connected to my mac which are unmountable via the Finder or Disk Utility - these are HFS formatted. I created an output which uses the code from above:
/, hfs, unmountable: NO, removable: NO
/Volumes/Elephant, hfs, unmountable: NO, removable: NO
/Volumes/Time Machine, hfs, unmountable: NO, removable: NO
/Volumes/USBSTICK, msdos, unmountable: YES, removable: YES
It looks like the method only returns YES if the device is FAT or MSDOS formatted. This is weird because the other 2 (Elephant, Time Machine) are volumes that are connected via USB and have to be removable and unmountable. Is there another way to get that information or have I done something wrong in my code?
--
Regards
Marco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用您的确切代码,使用我自己的 USB 记忆棒(1GB Cruzer - 是的,我知道我落后了),我得到 isRemovable 的“是”。
虽然 BOOL 通常表示为 YES 或 NO,但 TRUE 也可以。为了确定这一点,我也进行了测试。我每次都会得到 isRemovable == TRUE/YES 。
因此,由于“可以卸载/删除”条件可能取决于某些内容是否实际使用卷上的资源,因此很可能这就是阻止此方法回答“继续并卸载它”的原因。您问题中的更多上下文可能有助于识别该内容。
Using your exact code, with my own USB stick (a 1GB Cruzer - yes, I know I'm behind), I'm getting a YES for isRemovable.
Though BOOL is usually represented as YES or NO, TRUE works. To make sure, I tested that as well. I'm getting isRemovable == TRUE/YES every time.
So since the condition "can be unmounted/removed" can depend on whether something is actually using a resource on the volume, it's likely that's what's preventing this method from answering with a "go ahead and unmount it." More context in your question might help identify that something.