Example #1
0
func main() {
	flag.Usage = Usage
	flag.Parse()

	if flag.NArg() != 1 {
		Usage()
		os.Exit(2)
	}
	mountpoint := flag.Arg(0)

	c, err := fuse.Mount(mountpoint)
	if err != nil {
		log.Fatal(err)
	}
	defer c.Close()

	err = fs.Serve(c, FS{})
	if err != nil {
		log.Fatal(err)
	}

	// check if the mount process has an error to report
	<-c.Ready
	if err := c.MountError; err != nil {
		log.Fatal(err)
	}
}
Example #2
0
func ncmount(xfs zx.Tree) error {
	if rflag {
		xfs = zx.ROTreeFor(xfs)
	}
	zfs, err := zxfs.New(xfs)
	if err != nil {
		return fmt.Errorf("new zxfs: %s", err)
	}
	dmp = zfs
	c, err := fuse.Mount(mntdir)
	if err != nil {
		return fmt.Errorf("mount zxfs: %s", err)
	}
	defer c.Close()
	err = fs.Serve(c, zfs)
	if err != nil {
		return fmt.Errorf("serve zxfs: %s", err)
	}

	<-c.Ready
	if err := c.MountError; err != nil {
		return fmt.Errorf("mount error: %s", err)
	}
	return nil
}
Example #3
0
// Serve the tree for FUSE and mount it at the given path.
// Returns when unmounted.
func MountServer(t zx.Getter, mntdir string) error {
	zfs, err := New(t)
	if err != nil {
		return fmt.Errorf("new zxfs: %s", err)
	}
	c, err := fuse.Mount(mntdir)
	if err != nil {
		return fmt.Errorf("mount zxfs: %s", err)
	}
	defer c.Close()
	err = fs.Serve(c, zfs)
	if err != nil {
		return fmt.Errorf("serve zxfs: %s", err)
	}
	<-c.Ready
	if err := c.MountError; err != nil {
		return fmt.Errorf("mount error: %s", err)
	}
	return nil
}
Example #4
0
// Mounted mounts the fuse.Server at a temporary directory.
//
// It also waits until the filesystem is known to be visible (OS X
// workaround).
//
// After successful return, caller must clean up by calling Close.
func Mounted(srv *fs.Server) (*Mount, error) {
	dir, err := ioutil.TempDir("", "fusetest")
	if err != nil {
		return nil, err
	}
	c, err := fuse.Mount(dir)
	if err != nil {
		return nil, err
	}

	done := make(chan struct{})
	serveErr := make(chan error, 1)
	mnt := &Mount{
		Dir:   dir,
		Conn:  c,
		Error: serveErr,
		done:  done,
	}
	go func() {
		defer close(done)
		serveErr <- srv.Serve(c)
	}()

	select {
	case <-mnt.Conn.Ready:
		if mnt.Conn.MountError != nil {
			return nil, err
		}
		return mnt, err
	case err = <-mnt.Error:
		// Serve quit early
		if err != nil {
			return nil, err
		}
		return nil, errors.New("Serve exited early")
	}
}