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.
Selecting any option will automatically load the page