Programmatically mount a disk/volume using only a given file path in Mac OS X

只愿长相守 提交于 2019-12-05 10:05:58

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

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

  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.

  2. 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.

Have you tried using aliases? I think they're now known as bookmarks. It's possible that they will cause volumes to be mounted when you resolve them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!