1

如何以编程方式确定哪些(如果有)挂载的卷是 DVD?

我目前正在寻找一个权限为 555 的目录,但我更喜欢一些不那么 hacky 的东西。谢谢!!

$ ls -l /Volumes/
total 12
dr-xr-xr-x  4 mh    gfx    136 Aug  3  2001 DQRMX2102
lrwxr-xr-x  1 root  admin    1 Apr  6 15:09 Macintosh HD -> /
drwxrwxr-x  9 mh    gfx    374 Feb  3 12:55 data
4

2 回答 2

5

您使用的是什么编程语言/工具包?

如果你在 Objective-C 中使用 Cocoa,你可以NSWorkspace

NSArray *volumes = [[NSWorkspace sharedWorkspace] mountedRemovableMedia];

如果你想从命令行或者脚本之类的东西中找出来,diskutil应该会派上用场的。

$ diskutil info -plist /Volumes/Foobar
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
...snip...
    <key>OpticalMediaType</key>
    <string>CD-ROM</string>
...snip...
</dict>
</plist>
于 2009-04-07T00:56:12.153 回答
3

对于 Cocoa,您可以使用 NSWorkspace mountedRemovableMedia:获取卷列表,并使用 NSWorkspace getFileSystemInfo:...获取有关每个已挂载卷的更多信息。

- (BOOL)getFileSystemInfoForPath:(NSString *)fullPath 
                     isRemovable:(BOOL *)removableFlag 
                      isWritable:(BOOL *)writableFlag 
                   isUnmountable:(BOOL *)unmountableFlag 
                     description:(NSString **)description 
                            type:(NSString **)fileSystemType

如果要进行系统调用,可以在相同的信息处使用statfs 。

int statfs(const char *path, struct statfs *buf);
于 2009-04-07T01:11:38.840 回答