I want to mount a directory that resides on another host on my network. So far I've been successfully doing this via afp, using mount(8) via a system call, like so:
std::string syscmd = "mount -v -t afp -r \"afp://user:password@host/dir\" \"/tmp/foo/bar\"";
FILE *fd;
if(!(fd = popen(syscmd.c_str(), "r"))) {
std::cout << "oops. popen() failed." << std::endl;
exit(1);
}
But I'd like to mount directly with a function call, without the added overhead of invoking a shell with popen(). I can't figure out how to do this using mount(2), which has this signature:
int mount(const char *type, const char *dir, int flags, void *data);
What should data be? The man page doesn't explain this in any detail. For example, it says:
Datais a pointer to a structure that contains the type specific arguments to mount. The format for these argument structures is described in the manual page for each filesystem.
Where is that manual page it refers to? Is there some other documentation that I'm missing? Can anyone point me to a simple working example to illustrate the use of mount(2) over afp? Is there a better way to do this?
Do you have a reason to require that it be done via
mount(2)?Apple provides the
NetFSMountURLSync()function, from the NetFS framework, to mount network file systems. Sadly, the only documentation is the header file, so I can't link to it, but here's the relevant declaration:There's also an async version if that's useful for your use case.
As shown in this answer, you will need to use the
kNetFSMountAtMountDirKeyoption if you want to dictate the mount point.