Mapping to an SMB file share is something I'm working on now. I understand from other threads that instead of specifying a mount path of "/Volumes/mountdir", which for some reason is not allowed, you can use "/../Volumes/mountdir" which is both not the same (it is allowed) and the same…(it does what you wanted to do originally).
Don't do this. The issue here isn't actually whether or not you can specify a mount point in "/Volumes/", it's race conditions. Volume names aren't unique, so if two volumes with the same name attempt to mount at the same time, one mount will "win" (mounting at the expected point) and the other will "lose", failing the mount.
At that point, you'd then need to attempt the mount again with a new mount point like:
"/Volumes/mountdir 1"
...but it's entirely possible that this will ALSO fail, forcing you to repeat that entire process again.
...And, of course, it's also possible that a volume is ALREADY mounted at "mountdir", so you really should check for its existence before you use that mount point.
...And, of course, it's also possible that "mountdir" is unmounting after your check above, but before your mount, so now you end up mounting in "/Volumes/mountdir 1" even though "/Volumes/mountdir" no longer exists.
Now, you could deal with all of those issues... or you could just pass in "NULL" as the mountpath, let the system deal with all the issues above, and then use whatever path it actually ends up mounting at, which the API helpfully returns in the "mountpoints" argument.
That leads to my final point which is that, in my experience, code that makes ANY assumptions about the mount point name in "/Volumes/" is VERY likely to be broken. As designed, the system itself should not (and generally doesn’t) make ANY assumptions about the relationship between these two things:
-
"The Volume” -> meaning "the logical storage object users interact with".
-
"The mount point” -> meaning "the file system path the system happened to attach #1 at".
macOS has a longstanding convention that where we use the volume name (from #1) as the initial mountpoint name, then append a number as needed to generate a unique path if/when a collision occurs.
However, the critical word there is "convention". NOTHING actually requires the system to work this way and, in fact, iOS does NOT work this way. It simply generates a UUID for each new mount and uses that instead. Aside from the confusion it would create for command line users, there's no reason macOS couldn't work exactly the same way. I really do mean that quite literally—if you mount the volume "foo" at "/Volumes/bar", the Finder will show the volume’s name as "foo" because that's what the volume’s name actually is. It does not care what path the volume mounted out and never has.
That's the basic approach all apps should be using. That is, the volume path should be treated as an opaque value and APIs like "NSURLVolumeNameKey", "NSURLLocalizedNameKey", displayName(atPath:), and componentsToDisplay(forPath:) should be used to retrieve user presentation names for those objects.
__
Kevin Elliott
DTS Engineer, CoreOS/Hardware