仅在Mac OS X中使用给定的文件路径以编程方式挂载磁盘/卷 [英] Programmatically mount a disk/volume using only a given file path in Mac OS X

查看:174
本文介绍了仅在Mac OS X中使用给定的文件路径以编程方式挂载磁盘/卷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件路径列表。这些路径可能导致未安装的卷上的文件。在尝试访问文件之前,我如何以编程方式告诉操作系统挂载卷?

I have a list of file paths. These paths may lead to files on unmounted Volumes. How can I programmatically tell the OS to mount the volume before I try to access the file?

我知道这是可能的,因为iTunes似乎可以做到。例如,如果我在iTunes中启动了一个位于未安装的网络附加卷上的歌曲的播放,则该音量会自动为我安装。

I know this is possible somehow, as iTunes appears to do it. For example, if I initiate playback of a song located on an unmounted network attached volume in iTunes, the volume is mounted automatically for me.

操作系统应该挂载音量自动为我,如果我试图在指定的路径以编程方式打开文件?或者我需要使用磁盘仲裁框架或类似的方法手动挂载驱动器吗?

Is the OS supposed to mount the volume automatically for me if I attempt to open the file programmatically at the specified path? Or do I need to mount the drive manually using the Disk Arbitration framework or something similar?

如果我需要使用磁盘仲裁框架,具体需要做什么?

If I need to use the Disk Arbitration framework, what specifically needs to be done?

推荐答案

简短的答案:不需要乱搞磁盘仲裁框架。别名管理员可以为您处理这一切。

Short answer: No need to mess with the "Disk Arbitration framework". The Alias Manager can handle it all for you.

Chris Suter已经相当接近了。有两种解决方案,API明确:

Chris Suter was already pretty close. There are two solutions, API wise:


  1. 别名。这些已经存在于OSX Mac OS之前,并且是结构化文件,包含用于定位文件或文件夹的多种方式,即使它已被移动或重命名。它们还包含有关它们所在卷的信息,包括安装信息(如果它在网络卷上)。如果您只是创建文件的别名(使用Finder的文件菜单中的Make Alias命令),然后重命名或移动文件,或卸载其卷,您可以自己查看这些内容。 Finder将尝试将音量调回,甚至要求您在必要时提供登录信息。还有Alias ManagerAPI,包括函数FSResolveAliasFileWithMountFlags,这正是你要求的:它不仅可以找到别名的目标,而且还可以选择磁盘是否可以在卸载时使用,如果

  1. Aliases. Those existed already in pre-OSX MacOS and are structured files that contain several ways to locate a file or folder, even it it has been moved or renamed. They also contain information about the volume they were on, including mounting information if it's on a network volumes. You can see these in action for yourself if you simply create an Alias of a file (using the Finder's "Make Alias" command in the File menu), then rename or move it, or unmount its volume. The Finder will attempt to bring the volume back, even ask you to provide the login information if necessary. There is also the "Alias Manager" API, including the function FSResolveAliasFileWithMountFlags which is exactly what you asked for: It lets you not only find the target of an alias but also choose if the disk shall be made available if it's unmounted, and if the user should be asked to login if necessary.

CFURL书签。这是Alias API的现代替换,仅存在于OSX 10.6之后。 CFURL书签由系统在运行时更好地管理。我不知道他们是否有一个等效的磁盘文件表示,如经典的Alias文件,但也许他们甚至是一样的。

CFURL Bookmarks. This is the the modern replacement of the Alias API and exists only since OSX 10.6. CFURL Bookmarks are better managed by the system at runtime. I do not know if they have a equivalent on-disk file representation such as the classic Alias files do, but maybe they're even the very same.

在任何情况下,这些都应该是你需要的所有指针,我希望。

In any case, those should be all the pointers you need, I hope.

这篇关于仅在Mac OS X中使用给定的文件路径以编程方式挂载磁盘/卷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆