Source

go-extra / fuse / mount_freebsd.go

Full commit
Taru Karttunen 7b2b848 


































package fuse

import (
	"os"
	"strconv"
	"strings"
)

const mountProgram = "/usr/sbin/mount_fusefs"

func MountFuse(mountpoint string, options []string) (ff *os.File, err os.Error) {
	var args []string

	ff, err = os.Open("/dev/fuse", os.O_RDWR, 0)

	fname := strconv.Itoa(ff.Fd())
	if len(options) == 0 {
		args = []string{mountProgram, "-S", fname, mountpoint}
	} else {
		args = []string{mountProgram, "-o", strings.Join(options, ","), "auto", mountpoint}
	}

	fds := make([]*os.File, ff.Fd()+1)
	fds[0] = os.Stdin
	fds[1] = os.Stdout
	fds[2] = os.Stderr
	fds[ff.Fd()] = ff

	pid, err := os.ForkExec(mountProgram, args, []string{}, "", fds)
	if err != nil {
		return
	}
	os.Wait(pid, 0)

	return
}