5

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?

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?

BigMacAttack
  • 4,479
  • 3
  • 30
  • 39

2 Answers2

3

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.

Thomas Tempelmann
  • 11,045
  • 8
  • 74
  • 149
  • Unfortunately CFURL Bookmarks (and by association likely aliases as well) will not work in my situation. In order to use a bookmark, the volume must be mounted during the creation of the bookmark. Since I'm getting a list of paths from a file created by a 3rd party program, I can't guarantee the volume will be mounted at the time I get the paths such that I can create bookmarks for next time. – BigMacAttack Jan 03 '13 at 21:20
  • Perhaps there is a way to get the bookmarks from the 3rd party program? Or to derive the volume to mount based on the given file path? – BigMacAttack Jan 03 '13 at 21:23
  • Well... Can that 3rd party program mount the missing volume? If it can, then it has the info somewhere, and then you just have to find it. The Disk Arb framework is still not the right one for that, though, I think, because it only deals with local disks and/or tells you when a disk gets mounted. It this about iTunes? I've dealt with iTunes's libs myself, and IIRC, it contains just paths, and if a vol is missing it does NOT auto-mount it when trying to access such a missing file, or does it? – Thomas Tempelmann Jan 04 '13 at 22:30
  • 1
    Oh, turns out that iTunes does indeed remount such volumes. And it's clearly using Aliases for it (I got an "code sample" of iTunes while it was busy mounting the network volume, which showed that it invokes FSMatchAliasBulk and FSMountServerVolumeSync). But the xml version of the lib file contains only the raw path, not the Alias. So you'll have to try getting it via the AppleScript API... – Thomas Tempelmann Jan 04 '13 at 22:46
  • Oh bummer! AppleScript won't help either. Getting the location of a track doesn't work if it's not mounted. Which leaves you only with trying to decypher the .itl file, which looks not so easy as it appears to be encoded or maybe even encrypted. The only other way is to ask the user to mount the missing vol(s) once, then create an alias of them so you can remount them later automatically. – Thomas Tempelmann Jan 04 '13 at 23:01
  • Reverse engineering work has been done on deciphering the .itl: (http://code.google.com/p/titl/). So it is possible to get the bookmark from it, if the right hohm can be found. Looks like I'm in for some reverse engineering work to get this done right. But thank you for the help! – BigMacAttack Jan 05 '13 at 20:21
  • If you figure this out, please let me know, too! I have a product in the works that cleans up iTunes libs, e.g. finding lost files, and currently I'm stuck with AppleEvents. – Thomas Tempelmann Jan 07 '13 at 12:52
1

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.

Chris Suter
  • 2,897
  • 2
  • 19
  • 10