syscall.Mount cannot mount nfs server by URL

Hello everyone.
I got a nfs server and I want to mount it in my program. So I use the Code like below (just for example)

import (
	"fmt"
	"os"
	"syscall"
)

func main() {
	nfsServer := os.Args[1]
	nfsPath := os.Args[2]

	data := "./data"
	err := syscall.Mount(":"+nfsPath, data, "nfs", 0, "nolock,addr="+nfsServer)
	if err != nil {
		fmt.Println(err)
	}
}

It works fine. In this case my nfs server is a IP address like 10.1.1.1

The other day I changed. my nfs server to Cloud file server which is a URL like xxx.xxx.amazon.com
then I found my program is not working. When I try to mount the nfs I just got a error which is 「invalid parameter」.

So I wonder what’s wrong with my Code.

In addition. I tried mount the nfs file system by shell it works fine.
Thank you

Have a look at https://linux.die.net/man/8/mount :

For most types all the mount program has to do is issue a simple mount(2) system call, and no detailed knowledge of the filesystem type is required. For a few types however (like nfs, nfs4, cifs, smbfs, ncpfs) ad hoc code is necessary. The nfs, nfs4, cifs, smbfs, and ncpfs filesystems have a separate mount program. In order to make it possible to treat all types in a uniform way, mount will execute the program /sbin/mount.TYPE (if that exists) when called with type TYPE. Since various versions of the smbmount program have different calling conventions, /sbin/mount.smbfs may have to be a shell script that sets up the desired call.

So the mount command might do some extra work for the syscall.Mount

As a workaround, you can call the shell from Go using os/exec.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.