Jonukas
Jonukas

Reputation: 696

NetFSMountURLSync not able to use custom mount points?

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.

Upvotes: 3

Views: 2751

Answers (2)

user894627
user894627

Reputation: 1

As an answer to:

"Also, where did you find out what the error codes meant?" – Matt Aug 13 '14 at 21:15

The error codes can be read from the file: /usr/include/sys/errno.h

I.e if you open your terminal and run the following:

$ cat /usr/include/sys/errno.h | less

which will output the errno.h file and send it to less so you can navigate the result with pgup and pgdwn keys.

Upvotes: 0

tripod
tripod

Reputation: 126

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
);

Upvotes: 4

Related Questions