func main() { flag.Usage = usage flag.Parse() if flag.NArg() != 1 { usage() os.Exit(2) } mountpoint := flag.Arg(0) c, err := fuse.Mount( mountpoint, fuse.FSName("clock"), fuse.Subtype("clockfsfs"), fuse.LocalVolume(), fuse.VolumeName("Clock filesystem"), ) if err != nil { log.Fatal(err) } defer c.Close() srv := fs.New(c, nil) filesys := &FS{ // We pre-create the clock node so that it's always the same // object returned from all the Lookups. You could carefully // track its lifetime between Lookup&Forget, and have the // ticking & invalidation happen only when active, but let's // keep this example simple. clockFile: &File{ fuse: srv, }, } filesys.clockFile.tick() // This goroutine never exits. That's fine for this example. go filesys.clockFile.update() if err := srv.Serve(filesys); 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) } }
// Convert to mount options to be passed to package bazilfuse. func (c *MountConfig) bazilfuseOptions() (opts []bazilfuse.MountOption) { isDarwin := runtime.GOOS == "darwin" // Enable permissions checking in the kernel. See the comments on // InodeAttributes.Mode. opts = append(opts, bazilfuse.SetOption("default_permissions", "")) // HACK(jacobsa): Work around what appears to be a bug in systemd v219, as // shipped in Ubuntu 15.04, where it automatically unmounts any file system // that doesn't set an explicit name. // // When Ubuntu contains systemd v220, this workaround should be removed and // the systemd bug reopened if the problem persists. // // Cf. https://github.com/bazil/fuse/issues/89 // Cf. https://bugs.freedesktop.org/show_bug.cgi?id=90907 fsname := c.FSName if runtime.GOOS == "linux" && fsname == "" { fsname = "some_fuse_file_system" } // Special file system name? if fsname != "" { opts = append(opts, bazilfuse.FSName(fsname)) } // Read only? if c.ReadOnly { opts = append(opts, bazilfuse.ReadOnly()) } // OS X: set novncache when appropriate. if isDarwin && !c.EnableVnodeCaching { opts = append(opts, bazilfuse.SetOption("novncache", "")) } // OS X: disable the use of "Apple Double" (._foo and .DS_Store) files, which // just add noise to debug output and can have significant cost on // network-based file systems. // // Cf. https://github.com/osxfuse/osxfuse/wiki/Mount-options if isDarwin { opts = append(opts, bazilfuse.SetOption("noappledouble", "")) } // Ask the Linux kernel for larger read requests. // // As of 2015-03-26, the behavior in the kernel is: // // * (http://goo.gl/bQ1f1i, http://goo.gl/HwBrR6) Set the local variable // ra_pages to be init_response->max_readahead divided by the page size. // // * (http://goo.gl/gcIsSh, http://goo.gl/LKV2vA) Set // backing_dev_info::ra_pages to the min of that value and what was sent // in the request's max_readahead field. // // * (http://goo.gl/u2SqzH) Use backing_dev_info::ra_pages when deciding // how much to read ahead. // // * (http://goo.gl/JnhbdL) Don't read ahead at all if that field is zero. // // Reading a page at a time is a drag. Ask for a larger size. const maxReadahead = 1 << 20 opts = append(opts, bazilfuse.MaxReadahead(maxReadahead)) // Last but not least: other user-supplied options. for k, v := range c.Options { opts = append(opts, bazilfuse.SetOption(k, v)) } return }