NetFSMountURLSync not able to use custom mount points?

macos, osx-mountain-lion

Solution

Creating the mountpoint beforehand, and enabling the `kNetFSMountAtMountDirKey` in the mount options works:

CFMutableDictionaryRef mountOpts = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(mountOpts, kNetFSMountAtMountDirKey, CFSTR("true"));
int ret = NetFSMountURLSync(
    (__bridge CFURLRef) url,
    (__bridge CFURLRef) mountPath,
    NULL,
    NULL,
    0,
    mountOpts,
    &mountPoints
);

Problem

I'm trying to programmatically mount some WebDAV and SMB shares and I'd like to give the volumes specific names other than the default. For example, if I mount https://my.sharepoint.school.edu/personal/grigutis I'd like it to appear in the Finder as /Volumes/My SharePoint Site or ~/Desktop/My SharePoint Site Instead of /Volumes/grigutis or ~/Desktop/grigutis I can do this with the mount_webdav command: ``` $ mkdir /Volumes/My\ SharePoint\ Site $ mount_webdav -s -i https://my.sharepoint.school.edu/personal/grigutis /Volumes/My\ SharePoint\ Site or $ mkdir ~/Desktop/My\ SharePoint\ Site $ mount_webdav -s -i https://my.sharepoint.school.edu/personal/grigutis ~/Desktop/My\ SharePoint\ Site ``` But I can't get this working with NetFSMountURLSync (assume that I've already created the directory): ``` NSURL *url = [NSURL URLWithString:@"https://my.sharepoint.school.edu/personal/grigutis"]; NSURL *mountpath = [NSURL fileURLWithPath:@"/Volumes/My SharePoint Site" isDirectory:YES]; or NSURL *mountpath = [NSURL fileURLWithPath:[@"~/Desktop/My SharePoint Site" stringByExpandingTildeInPath] isDirectory:YES]; CFArrayRef mountpoints = NULL; int result = 0; result = NetFSMountURLSync((__bridge CFURLRef)url, (__bridge CFURLRef)mountpath, CFSTR("Kerberos"), CFSTR("NoPassword"), NULL, NULL, &mountpoints); ``` If I try mounting to /Volumes/My SharePoint Site, I get the Finder dialog: 'There was a problem connecting to the server "my.sharepoint.school.edu". You do not have permission to access this server.' and the function returns result 13 (Permission denied). If I try mounting to ~/Desktop/My SharePoint Site, then it mounts like this ~/Desktop/My SharePoint Site/grigutis Which is not what I want. I've filed a bug report about this. Any ideas? I'd like to avoid NSTask if possible.

Original source