I have a remote filesystem I can mount through webdav via
sudo mount -t davfs https://myserver.com /tmp/dav
It prompts me for a username and password at this point.
I then added an entry to fstab and created a ~/.davfs2/secrets file
.
If I now run
mount /tmp/dav
It works.
Now I need this to be mounted from within my app automatically from C code.
If I call:
int result = mount("https://myserver.com", "/tmp/dav", "davfs", 0, "user,noauto,file_mode=600,dir_mode=700");
Mount returns result -1 and and errno is set to 19: strerror prints "no such device".
The mount man page shows:
ENODEV filesystemtype not configured in the kernel.
How can I get this to work? Is it because davfs is fuse based?
The answer turned out to be simpler than I thought. I should point out I wanted to also remove the prompt for password. This is how I solved it.
It turned out mount.davfs is a server that gets executed by the mount command. But it's not a registered filesystem so you can't use the system mount(2) call. Instead we must exec the mount command directly.
To provide my own secrets file I did this.
Mount tmpfs at /etc/davfs2 (hides real davfs2.conf etc)
mount("none", "/etc/davfs2/secrets", "tmpfs", 0, NULL);
Create /etc/davfs2/secrets mode 0600 containing our secret
In addition I used unshare to hide the mount from outside the process.