问题描述
限时送ChatGPT账号..当我发出 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 上是否有允许我在 C、shell 或 Python 等中执行此操作的 API?
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
文档中列出了其他键.命令和音量键都适用.
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屋!
更多推荐
[db:关键词]
发布评论