如何从Mac上的API获取挂载点信息? [英] How to get mount point information from an API on Mac?
问题描述
当我发出mount
命令时,我得到如下条目:
When I issue the mount
command, I get entries like the following:
//abc@host/b1 on /Volumes/b1 (smbfs, nodev, nosuid, mounted by abc)
//abc@host/b2 on /Volumes/b2 (smbfs, nodev, nosuid, mounted by abc)
这些表明我安装了两个Samba共享.
These indicate that I have two samba shares mounted.
我宁愿不尝试解析mount
命令输出,但我确实想检索附加文件系统的挂载点,尤其是从samba中检索.
I'd rather not try to parse mount
command outputs, but I do want to retrieve the mount points of of attached filesystems, especially from samba.
Mac上是否有API允许我以C或Shell或Python等方式执行此操作?
Is there a API on the Mac that allows me to do this, either in C, or shell, or Python, etc. ?
推荐答案
您将使用以下方法获得已安装卷的URL数组:
You get an array of URLs for the mounted volumes using:
NSArray* keys = @[ /* ... */ ];
NSArray* urls = [[NSFileManager defaultManager] mountedVolumeURLsIncludingResourceValuesForKeys:keys
options:NSVolumeEnumerationSkipHiddenVolumes];
我马上进入keys
数组.一旦有了这些URL,就可以使用NSURL
的资源值" API获得有关它们的信息.您可以使用-[NSURL getResourceValue:forKey:error:]
获得单个值.使用-resourceValuesForKeys:error:
一次可以得到几个.您可以通过在上面传递给NSFileManager
方法的keys
数组中指定它们来优化对所需值的获取.
I'll get to the keys
array in a moment. Once you have those URLs, you can obtain information about them using the "resource value" APIs of NSURL
. You get a single value using -[NSURL getResourceValue:forKey:error:]
. You get several at a time using -resourceValuesForKeys:error:
. You can optimize the fetching of whatever values you're interested in by specifying them in the keys
array passed to the NSFileManager
method, above.
对于使用网络共享可能很重要的键是NSURLVolumeURLForRemountingKey
.其他键在NSURL
文档中列出. Command键和Volume键都适用.
A key that may be significant for working with network shares is NSURLVolumeURLForRemountingKey
. Other keys are listed in the NSURL
docs. Both the Command and Volume keys apply.
这篇关于如何从Mac上的API获取挂载点信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!