如何从 Mac 上的 API 获取挂载点信息?

编程入门 行业动态 更新时间:2024-10-12 18:21:47
本文介绍了如何从 Mac 上的 API 获取挂载点信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-18 04:18:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/930416.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:信息   Mac   API   挂载点

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!