mount(2) always returning errno 63 (File name too long) when mounting NFS share

I've been trying use the mount(2) function to programmatically mount an NFS share on my application, although I seem to be having issues with the function signature and the parameters that I'm supposed to be passing. According to the man pages this is the function's signature:

int mount(const char *type, const char *dir, int flags, void *data);

As the documentation is vague on the value of type, I've assumed that it was the network location, in the form of server.name:/some/location. So I've written the following test code:

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/param.h>
#include <sys/mount.h>

int main(int argc, char **argv) {
    const char *type = "nfsserver.lan:/some/path";
    const char *mntp = "/Users/localuser/tmpmount";

    int ret = mount(type, mntp, 0, NULL);
    printf("ret = %d\n", ret);
    printf("errno = %d (%s)\n", errno, strerror(errno));

    return 0;
}

Upon running this program on my Mac Pro running macOS 12.7.4 I got the following output:

ret = -1
errno = 63 (File name too long)

The NFS share location string I'm actually using is exactly 46 characters long and I am able to mount the share using the mount(8) command. I'm also able to use the unmount(2) function for testing after I've used the mount(8) command.

What am I missing and how can I fix this issue? I think I'm probably passing the parameters in the wrong way, but sadly the documentation is quite vague.

Answered by DTS Engineer in 795542022

Is there a reason you’re not using NetFS framework [1] for this? In general, when there’s an API and a command-line tool, I recommend the former over the latter.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] I was gonna make this a link to the framework documentation, but there isn’t any framework documentation (r. 7267861)-: [2]. Fortunately, the headers have a bunch of doc comments that should be sufficient to get you started.

[2] Check out that low bug number!

Somewhere there will be nfs-specific mount syscall documentation, but I can't immediately find it. (man mount_nfs is for the mount command, not the syscall.) I bet you need to pass some NFS-specific struct to mount's data argument.

Is there a reason you’re not using NetFS framework [1] for this? In general, when there’s an API and a command-line tool, I recommend the former over the latter.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] I was gonna make this a link to the framework documentation, but there isn’t any framework documentation (r. 7267861)-: [2]. Fortunately, the headers have a bunch of doc comments that should be sufficient to get you started.

[2] Check out that low bug number!

mount(2) always returning errno 63 (File name too long) when mounting NFS share
 
 
Q