Help: unix.Mount undefined on Mac

Hello, just getting into go these last few days.

I wrote some code on an Ubuntu VM that compiles and runs fine. Then I decided to develop on my Mac workstation, but the same code fails to compile.

I get the following error:

./ds-as-mounter.go:57:9: undefined: unix.Mount
./ds-as-mounter.go:57:35: undefined: unix.MS_BIND

Oddly it seems OK with unix.Unmount.

I did install the unix package with go get -u golang.org/x/sys/unix.

Here is the top of my package:

package main

import (
	"fmt"
	"golang.org/x/sys/unix"
	"os"
	"regexp"
	"sync"
)

//....

And here is where the Mount and Unmount calls are made:

func mount(src, dest string, wg *sync.WaitGroup) {
	defer wg.Done()
	//fmt.Println("Mounting", src, dest)
	err := unix.Mount(src, dest, "", unix.MS_BIND, "")
	if err != nil {
		fmt.Println(src, dest, err)
	}
}

func unmount(dest string, wg *sync.WaitGroup) {
	defer wg.Done()
	//fmt.Println("Unmounting", dest)
	err := unix.Unmount(dest, 0)
	if err != nil {
		fmt.Println("Unmount", dest, err)
	}
}

Note that the compiler complains about unix.Mount and unix.MS_BIND, not unix.Unmount.

I’m quite confused. Any help would be appreciated. Thanks!

go version go1.11.2 darwin/amd64

The mount call is indeed only implemented for Linux.

jb@kvin:~/g/s/g/x/s/unix $ git grep Mount\(
syscall_linux.go:func Mount(source string, target string, fstype string, flags uintptr, data string) (err error) {

Unmount is implemented for lots more. If I were to guess, I would say that Unmount is “easy” as it probably behaves the same roughly everywhere. Mount, on the other hand, takes lots and lots of flags and options all of which are system and filesystem specific.

For example, macOS doesn’t have bind mounts that you are trying to do. So it cannot be implemented.

The mount call is indeed only implemented for Linux.

This makes sense, however I would have expected the docs to reflect this.

Thank-you for the help.

If you do go doc on your system they do. The online docs though are generated for Linux.

2 Likes

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