func TestNonseekable(t *testing.T) { fs := &nonseekFs{FileSystem: pathfs.NewDefaultFileSystem()} fs.Length = 200 * 1024 dir := testutil.TempDir() defer os.RemoveAll(dir) nfs := pathfs.NewPathNodeFs(fs, nil) opts := nodefs.NewOptions() opts.Debug = testutil.VerboseTest() state, _, err := nodefs.MountRoot(dir, nfs.Root(), opts) if err != nil { t.Fatalf("failed: %v", err) } defer state.Unmount() go state.Serve() if err := state.WaitMount(); err != nil { t.Fatal("WaitMount", err) } f, err := os.Open(dir + "/file") if err != nil { t.Fatalf("failed: %v", err) } defer f.Close() b := make([]byte, 200) n, err := f.ReadAt(b, 20) if err == nil || n > 0 { t.Errorf("file was opened nonseekable, but seek successful") } }
func main() { if len(os.Args) != 2 { fmt.Println("Usage: %s <mountpath>") os.Exit(1) } root := os.Args[1] hfs := &HelloFs{FileSystem: pathfs.NewDefaultFileSystem()} nfs := pathfs.NewPathNodeFs(hfs, nil) fuseSrv, _, err := nodefs.MountRoot(root, nfs.Root(), nil) if err != nil { log.Fatal(err) } go fuseSrv.Serve() l, err := net.Listen("tcp", "127.0.0.1:50000") if err != nil { log.Fatal(err) } s := grpc.NewServer() pb.RegisterPathFSServer(s, server.New(hfs)) go s.Serve(l) log.Printf("Listen on %s for dir %s", l.Addr(), root) sigCh := make(chan os.Signal) signal.Notify(sigCh, os.Interrupt) for range sigCh { fuseSrv.Unmount() s.Stop() os.Exit(0) } }
func TestNonseekable(t *testing.T) { fs := &nonseekFs{FileSystem: pathfs.NewDefaultFileSystem()} fs.Length = 200 * 1024 dir, err := ioutil.TempDir("", "go-fuse-cache_test") if err != nil { t.Fatalf("failed: %v", err) } defer os.RemoveAll(dir) nfs := pathfs.NewPathNodeFs(fs, nil) state, _, err := nodefs.MountRoot(dir, nfs.Root(), nil) if err != nil { t.Fatalf("failed: %v", err) } state.SetDebug(VerboseTest()) defer state.Unmount() go state.Serve() f, err := os.Open(dir + "/file") if err != nil { t.Fatalf("failed: %v", err) } defer f.Close() b := make([]byte, 200) n, err := f.ReadAt(b, 20) if err == nil || n > 0 { t.Errorf("file was opened nonseekable, but seek successful") } }
func New(config *conf.Fuse, logger log_driver.Logger) (*GitFs, error) { gitfsDir, err := gitfsDir(logger) if err != nil { return nil, err } defaultfs := pathfs.NewDefaultFileSystem() gitfs := &GitFs{FileSystem: pathfs.NewReadonlyFileSystem(defaultfs), GitRepoDir: config.GitRepoDir, GitFsDir: gitfsDir, logger: logger} fs := pathfs.NewPathNodeFs(gitfs, nil) server, _, err := nodefs.MountRoot(gitfsDir, fs.Root(), nil) if err != nil { logger.Errorf("Failed to mount GitFS on %s due to %s", gitfsDir, err) return nil, err } logger.Debugf("Mount GitFs on %s", gitfsDir) gitfs.server = server server.SetDebug(config.Debug) gitfs.cache, err = cache.New(1024) if err != nil { logger.Errorf("Failed to initialize object cache due to %s\n", err) return nil, err } return gitfs, nil }
func main() { if len(os.Args) != 2 { fmt.Println("Usage: %s <mountpath>") os.Exit(1) } root := os.Args[1] dialOpts := []grpc.DialOption{grpc.WithInsecure()} conn, err := grpc.Dial("127.0.0.1:50000", dialOpts...) if err != nil { log.Fatal(err) } cli := pb.NewPathFSClient(conn) fs := grpcfs.New(cli) nfs := pathfs.NewPathNodeFs(fs, nil) server, _, err := nodefs.MountRoot(root, nfs.Root(), nil) if err != nil { log.Fatal(err) } go server.Serve() log.Printf("Fs mounted to root %s", root) sigCh := make(chan os.Signal) signal.Notify(sigCh, os.Interrupt) for range sigCh { server.Unmount() os.Exit(0) } }
func setupFs(fs pathfs.FileSystem) (string, func()) { opts := &nodefs.Options{ EntryTimeout: 0.0, AttrTimeout: 0.0, NegativeTimeout: 0.0, } mountPoint, _ := ioutil.TempDir("", "stat_test") nfs := pathfs.NewPathNodeFs(fs, nil) state, _, err := nodefs.MountRoot(mountPoint, nfs.Root(), opts) if err != nil { panic(fmt.Sprintf("cannot mount %v", err)) // ugh - benchmark has no error methods. } lmap := NewLatencyMap() state.RecordLatencies(lmap) // state.SetDebug(true) go state.Serve() return mountPoint, func() { lc, lns := lmap.Get("LOOKUP") gc, gns := lmap.Get("GETATTR") fmt.Printf("GETATTR %v/call n=%d, LOOKUP %v/call n=%d\n", gns/time.Duration(gc), gc, lns/time.Duration(lc), lc) err := state.Unmount() if err != nil { log.Println("error during unmount", err) } else { os.RemoveAll(mountPoint) } } }
func (d *etcDriver) Create(rq dkvolume.Request) dkvolume.Response { var res dkvolume.Response if !strings.HasPrefix(rq.Name, "@") { return responseErrorString("a etcd path has to start with a @") } d.mux.Lock() defer d.mux.Unlock() _, ok := d.mountpoints[rq.Name] if ok { return res } pt := d.createPath(rq.Name) if err := os.MkdirAll(pt, 0755); err != nil { return responseError(fmt.Errorf("cannot mkdir: %s", err)) } rootfs := "/" + d.asEtcdRoot(rq.Name) root := pathfs.NewPrefixFileSystem(&d.etcdbackend, rootfs) nfs := pathfs.NewPathNodeFs(root, nil) server, _, err := nodefs.MountRoot(pt, nfs.Root(), nil) if err != nil { return responseError(fmt.Errorf("cannot mount root : %s", err)) } es := etcdFuseServer{pt, server, 0} d.mountpoints[rq.Name] = &es go server.Serve() return res }
// Start takes a path to the directory where the goinfo file system // should be mounted. If the directory does not exist, it will be // created. Start will return an error if the directory cannot be // created or if the file system cannot be mounted at this location // for any reason. func Start(mountpoint string) error { //already mounted there if _, found := servers[mountpoint]; found { return nil } if _, err := os.Stat(mountpoint); os.IsNotExist(err) { if err = os.Mkdir(mountpoint, 0755); err != nil { return err } } nfs := pathfs.NewPathNodeFs(gfs, nil) conn := nodefs.NewFileSystemConnector(nfs.Root(), nil) server, err := fuse.NewServer(conn.RawFS(), mountpoint, &fuse.MountOptions{AllowOther: true}) if err != nil { return errors.New("Failed to mount monitoring fs at " + mountpoint + ": " + err.Error()) } servers[mountpoint] = server //start handling the fs calls go server.Serve() return nil }
func NewNotifyTest(t *testing.T) *NotifyTest { me := &NotifyTest{} me.fs = newNotifyFs() var err error me.dir, err = ioutil.TempDir("", "go-fuse-notify_test") if err != nil { t.Fatalf("TempDir failed: %v", err) } entryTtl := 100 * time.Millisecond opts := &nodefs.Options{ EntryTimeout: entryTtl, AttrTimeout: entryTtl, NegativeTimeout: entryTtl, Debug: VerboseTest(), } me.pathfs = pathfs.NewPathNodeFs(me.fs, nil) me.state, me.connector, err = nodefs.MountRoot(me.dir, me.pathfs.Root(), opts) if err != nil { t.Fatalf("MountNodeFileSystem failed: %v", err) } go me.state.Serve() if err := me.state.WaitMount(); err != nil { t.Fatal("WaitMount", err) } return me }
func setupCacheTest(t *testing.T) (string, *pathfs.PathNodeFs, func()) { dir, err := ioutil.TempDir("", "go-fuse-cachetest") if err != nil { t.Fatalf("TempDir failed: %v", err) } os.Mkdir(dir+"/mnt", 0755) os.Mkdir(dir+"/orig", 0755) fs := &cacheFs{ pathfs.NewLoopbackFileSystem(dir + "/orig"), } pfs := pathfs.NewPathNodeFs(fs, nil) state, conn, err := nodefs.MountRoot(dir+"/mnt", pfs.Root(), nil) if err != nil { t.Fatalf("MountNodeFileSystem failed: %v", err) } state.SetDebug(VerboseTest()) conn.SetDebug(VerboseTest()) pfs.SetDebug(VerboseTest()) go state.Serve() return dir, pfs, func() { err := state.Unmount() if err == nil { os.RemoveAll(dir) } } }
func setupFAttrTest(t *testing.T, fs pathfs.FileSystem) (dir string, clean func()) { dir, err := ioutil.TempDir("", "go-fuse-fsetattr_test") if err != nil { t.Fatalf("TempDir failed: %v", err) } nfs := pathfs.NewPathNodeFs(fs, nil) opts := nodefs.NewOptions() opts.Debug = VerboseTest() state, _, err := nodefs.MountRoot(dir, nfs.Root(), opts) if err != nil { t.Fatalf("MountNodeFileSystem failed: %v", err) } go state.Serve() if err := state.WaitMount(); err != nil { t.Fatal("WaitMount", err) } if state.KernelSettings().Flags&fuse.CAP_FILE_OPS == 0 { t.Skip("Mount does not support file operations") } return dir, func() { if err := state.Unmount(); err != nil { t.Errorf("cleanup: Unmount: %v", err) } else { os.RemoveAll(dir) } } }
func setupFAttrTest(t *testing.T, fs pathfs.FileSystem) (dir string, clean func()) { dir, err := ioutil.TempDir("", "go-fuse-fsetattr_test") if err != nil { t.Fatalf("TempDir failed: %v", err) } nfs := pathfs.NewPathNodeFs(fs, nil) state, _, err := nodefs.MountRoot(dir, nfs.Root(), nil) if err != nil { t.Fatalf("MountNodeFileSystem failed: %v", err) } state.SetDebug(VerboseTest()) go state.Serve() // Trigger INIT. os.Lstat(dir) if state.KernelSettings().Flags&fuse.CAP_FILE_OPS == 0 { t.Log("Mount does not support file operations") } return dir, func() { if state.Unmount() == nil { os.RemoveAll(dir) } } }
func setupCacheTest(t *testing.T) (string, *pathfs.PathNodeFs, func()) { dir := testutil.TempDir() os.Mkdir(dir+"/mnt", 0755) os.Mkdir(dir+"/orig", 0755) fs := &cacheFs{ pathfs.NewLoopbackFileSystem(dir + "/orig"), } pfs := pathfs.NewPathNodeFs(fs, &pathfs.PathNodeFsOptions{Debug: testutil.VerboseTest()}) opts := nodefs.NewOptions() opts.Debug = testutil.VerboseTest() state, _, err := nodefs.MountRoot(dir+"/mnt", pfs.Root(), opts) if err != nil { t.Fatalf("MountNodeFileSystem failed: %v", err) } go state.Serve() if err := state.WaitMount(); err != nil { t.Fatal("WaitMount", err) } return dir, pfs, func() { err := state.Unmount() if err == nil { os.RemoveAll(dir) } } }
func defaultReadTest(t *testing.T) (root string, cleanup func()) { fs := &DefaultReadFS{ FileSystem: pathfs.NewDefaultFileSystem(), size: 22, } var err error dir, err := ioutil.TempDir("", "go-fuse") if err != nil { t.Fatalf("TempDir failed: %v", err) } pathfs := pathfs.NewPathNodeFs(fs, nil) opts := nodefs.NewOptions() opts.Debug = VerboseTest() state, _, err := nodefs.MountRoot(dir, pathfs.Root(), opts) if err != nil { t.Fatalf("MountNodeFileSystem failed: %v", err) } go state.Serve() if err := state.WaitMount(); err != nil { t.Fatal("WaitMount", err) } return dir, func() { state.Unmount() os.Remove(dir) } }
func setup(t *testing.T) (workdir string, cleanup func()) { wd, _ := ioutil.TempDir("", "") err := os.Mkdir(wd+"/mnt", 0700) if err != nil { t.Fatalf("Mkdir failed: %v", err) } err = os.Mkdir(wd+"/store", 0700) if err != nil { t.Fatalf("Mkdir failed: %v", err) } os.Mkdir(wd+"/ro", 0700) if err != nil { t.Fatalf("Mkdir failed: %v", err) } WriteFile(t, wd+"/ro/file1", "file1") WriteFile(t, wd+"/ro/file2", "file2") fs := NewAutoUnionFs(wd+"/store", testAOpts) nfs := pathfs.NewPathNodeFs(fs, nil) state, _, err := nodefs.MountRoot(wd+"/mnt", nfs.Root(), &testAOpts.Options) if err != nil { t.Fatalf("MountNodeFileSystem failed: %v", err) } fs.SetDebug(VerboseTest()) go state.Serve() return wd, func() { state.Unmount() os.RemoveAll(wd) } }
func TestOriginalIsSymlink(t *testing.T) { tmpDir := testutil.TempDir() defer os.RemoveAll(tmpDir) orig := tmpDir + "/orig" err := os.Mkdir(orig, 0755) if err != nil { t.Fatalf("Mkdir failed: %v", err) } link := tmpDir + "/link" mnt := tmpDir + "/mnt" if err := os.Mkdir(mnt, 0755); err != nil { t.Fatalf("Mkdir failed: %v", err) } if err := os.Symlink("orig", link); err != nil { t.Fatalf("Symlink failed: %v", err) } fs := pathfs.NewLoopbackFileSystem(link) nfs := pathfs.NewPathNodeFs(fs, nil) state, _, err := nodefs.MountRoot(mnt, nfs.Root(), nil) if err != nil { t.Fatalf("MountNodeFileSystem failed: %v", err) } defer state.Unmount() go state.Serve() if err := state.WaitMount(); err != nil { t.Fatal("WaitMount", err) } if _, err := os.Lstat(mnt); err != nil { t.Fatalf("Lstat failed: %v", err) } }
func pathfsFrontend(key []byte, cipherdir string, mountpoint string, debug bool, openssl bool) *fuse.Server { finalFs := pathfs_frontend.NewFS(key, cipherdir, openssl) pathFsOpts := &pathfs.PathNodeFsOptions{ClientInodes: true} pathFs := pathfs.NewPathNodeFs(finalFs, pathFsOpts) fuseOpts := &nodefs.Options{ // These options are to be compatible with libfuse defaults, // making benchmarking easier. NegativeTimeout: time.Second, AttrTimeout: time.Second, EntryTimeout: time.Second, } conn := nodefs.NewFileSystemConnector(pathFs.Root(), fuseOpts) var mOpts fuse.MountOptions mOpts.AllowOther = false // Set values shown in "df -T" and friends // First column, "Filesystem" mOpts.Options = append(mOpts.Options, "fsname="+cipherdir) // Second column, "Type", will be shown as "fuse." + Name mOpts.Name = "gocryptfs" srv, err := fuse.NewServer(conn.RawFS(), mountpoint, &mOpts) if err != nil { fmt.Printf("Mount failed: %v", err) os.Exit(ERREXIT_MOUNT) } srv.SetDebug(debug) return srv }
func newFuseFS(tmpDir string, rpcFS *RpcFs, writableRoot string) (*fuseFS, error) { tmpDir, err := ioutil.TempDir(tmpDir, "termite-task") if err != nil { return nil, err } fs := &fuseFS{ writableRoot: strings.TrimLeft(writableRoot, "/"), workers: map[string]*workerFS{}, rpcFS: rpcFS, rpcNodeFS: pathfs.NewPathNodeFs(&multiRPCFS{rpcFS}, &pathfs.PathNodeFsOptions{ClientInodes: true}), tmpDir: tmpDir, mount: filepath.Join(tmpDir, "mnt"), } if err := os.Mkdir(fs.mount, 0755); err != nil { return nil, err } fs.fsConnector = nodefs.NewFileSystemConnector(fs.rpcNodeFS.Root(), nodeFSOptions()) fuseOpts := fuse.MountOptions{} if os.Geteuid() == 0 { fuseOpts.AllowOther = true } fs.server, err = fuse.NewServer(fs.fsConnector.RawFS(), fs.mount, &fuseOpts) if err != nil { return nil, err } go fs.server.Serve() return fs, nil }
func mount() error { var err error if fs != nil || server != nil { // already mounting return nil } // create mountpoint os.Mkdir(TEST_MOUNTPOINT, 0777) // config config := &config.Config{ MountPoint: TEST_MOUNTPOINT, ContainerName: TEST_CONTAINER_NAME, CreateContainer: true, Debug: true, NoDaemon: true, } // swift swift := openstack.NewSwift(config) if err = swift.Auth(); err != nil { return err } swift.DeleteContainer() // mapper mapper, err := mapper.NewObjectMapper(config) if err != nil { return err } // initialize filesystem fs = NewObjectFileSystem(config, mapper) path := pathfs.NewPathNodeFs(fs, nil) con := nodefs.NewFileSystemConnector(path.Root(), &nodefs.Options{}) opts := &fuse.MountOptions{ Name: "test-filesystem", FsName: "test-filesystem", } // create server and do mount with dedicated goroutine server, err = fuse.NewServer(con.RawFS(), TEST_MOUNTPOINT, opts) if err != nil { return err } go func() { server.Serve() }() server.WaitMount() return nil }
// Creates a temporary dir "wd" with 3 directories: // mnt ... overlayed (unionfs) mount // rw .... modifiable data // ro .... read-only data func setupUfs(t *testing.T) (wd string, cleanup func()) { // Make sure system setting does not affect test. syscall.Umask(0) wd = testutil.TempDir() err := os.Mkdir(wd+"/mnt", 0700) if err != nil { t.Fatalf("Mkdir failed: %v", err) } err = os.Mkdir(wd+"/rw", 0700) if err != nil { t.Fatalf("Mkdir failed: %v", err) } os.Mkdir(wd+"/ro", 0700) if err != nil { t.Fatalf("Mkdir failed: %v", err) } var fses []pathfs.FileSystem fses = append(fses, pathfs.NewLoopbackFileSystem(wd+"/rw")) fses = append(fses, NewCachingFileSystem(pathfs.NewLoopbackFileSystem(wd+"/ro"), 0)) ufs, err := NewUnionFs(fses, testOpts) if err != nil { t.Fatalf("NewUnionFs: %v", err) } // We configure timeouts are smaller, so we can check for // UnionFs's cache consistency. opts := &nodefs.Options{ EntryTimeout: entryTtl / 2, AttrTimeout: entryTtl / 2, NegativeTimeout: entryTtl / 2, PortableInodes: true, Debug: testutil.VerboseTest(), } pathfs := pathfs.NewPathNodeFs(ufs, &pathfs.PathNodeFsOptions{ClientInodes: true, Debug: opts.Debug, }) state, _, err := nodefs.MountRoot(wd+"/mnt", pathfs.Root(), opts) if err != nil { t.Fatalf("MountNodeFileSystem failed: %v", err) } go state.Serve() state.WaitMount() return wd, func() { err := state.Unmount() if err != nil { return } setRecursiveWritable(t, wd, true) os.RemoveAll(wd) } }
// NewKeywhizFs readies a KeywhizFs struct and its parent filesystem objects. func NewFs(client *api.Client, owner keywhizfs.Ownership) (*fs, nodefs.Node) { defaultfs := pathfs.NewDefaultFileSystem() // Returns ENOSYS by default readonlyfs := pathfs.NewReadonlyFileSystem(defaultfs) // R/W calls return EPERM kwfs := &fs{readonlyfs, client, owner} nfs := pathfs.NewPathNodeFs(kwfs, nil) nfs.SetDebug(true) return kwfs, nfs.Root() }
func main() { debug := flag.Bool("debug", false, "debug on") hardlinks := flag.Bool("hardlinks", false, "support hardlinks") delcache_ttl := flag.Float64("deletion_cache_ttl", 5.0, "Deletion cache TTL in seconds.") branchcache_ttl := flag.Float64("branchcache_ttl", 5.0, "Branch cache TTL in seconds.") deldirname := flag.String( "deletion_dirname", "GOUNIONFS_DELETIONS", "Directory name to use for deletions.") hide_readonly_link := flag.Bool("hide_readonly_link", true, "Hides READONLY link from the top mountpoints. "+ "Enabled by default.") portableInodes := flag.Bool("portable-inodes", false, "Use sequential 32-bit inode numbers.") flag.Parse() if len(flag.Args()) < 2 { fmt.Println("Usage:\n main MOUNTPOINT BASEDIR") os.Exit(2) } ufsOptions := unionfs.UnionFsOptions{ DeletionCacheTTL: time.Duration(*delcache_ttl * float64(time.Second)), BranchCacheTTL: time.Duration(*branchcache_ttl * float64(time.Second)), DeletionDirName: *deldirname, } options := unionfs.AutoUnionFsOptions{ UnionFsOptions: ufsOptions, Options: nodefs.Options{ EntryTimeout: time.Second, AttrTimeout: time.Second, NegativeTimeout: time.Second, Owner: fuse.CurrentOwner(), }, UpdateOnMount: true, PathNodeFsOptions: pathfs.PathNodeFsOptions{ ClientInodes: *hardlinks, }, HideReadonly: *hide_readonly_link, } fsOpts := nodefs.Options{ PortableInodes: *portableInodes, } gofs := unionfs.NewAutoUnionFs(flag.Arg(1), options) pathfs := pathfs.NewPathNodeFs(gofs, nil) state, conn, err := nodefs.MountRoot(flag.Arg(0), pathfs.Root(), &fsOpts) if err != nil { fmt.Printf("Mount fail: %v\n", err) os.Exit(1) } pathfs.SetDebug(*debug) conn.SetDebug(*debug) state.SetDebug(*debug) state.Serve() time.Sleep(1 * time.Second) }
// //func (me *HelloFs) OpenDir(name string, context *fuse.Context) (c []fuse.DirEntry, code fuse.Status) { // if name == "" { // c = []fuse.DirEntry{{Name: "file.txt", Mode: fuse.S_IFREG}} // return c, fuse.OK // } // return nil, fuse.ENOENT //} // //func (me *HelloFs) Open(name string, flags uint32, context *fuse.Context) (file nodefs.File, code fuse.Status) { // if name != "file.txt" { // return nil, fuse.ENOENT // } // if flags&fuse.O_ANYWRITE != 0 { // return nil, fuse.EPERM // } // return nodefs.NewDataFile([]byte(name)), fuse.OK //} // func main() { use_hammer2 := false flag.Parse() if len(flag.Args()) < 1 { log.Fatal("Usage:\n hello MOUNTPOINT") } var nfs *pathfs.PathNodeFs if use_hammer2 { nfs = pathfs.NewPathNodeFs(&Hammer2Fs{FileSystem: pathfs.NewDefaultFileSystem()}, nil) } else { nfs = pathfs.NewPathNodeFs(&HammerFs{FileSystem: pathfs.NewDefaultFileSystem()}, nil) } fmt.Println("nfs ==", nfs) // server, _, err := nodefs.MountFileSystem(flag.Arg(0), nfs, nil) // if err != nil { // log.Fatal("Mount fail: %v\n", err) // } // server.Serve() }
func MountFs(path string) { LoadSession() CacheInit() nfs := pathfs.NewPathNodeFs(&DropboxFs{FileSystem: pathfs.NewDefaultFileSystem()}, nil) server, _, err := nodefs.MountRoot(path, nfs.Root(), nil) if err != nil { log.Fatalf("Mount fail: %v\n", err) } server.Serve() }
// Create and mount filesystem. func NewTestCase(t *testing.T) *testCase { tc := &testCase{} tc.tester = t // Make sure system setting does not affect test. syscall.Umask(0) const name string = "hello.txt" const subdir string = "subdir" var err error tc.tmpDir, err = ioutil.TempDir("", "go-fuse") if err != nil { t.Fatalf("TempDir failed: %v", err) } tc.orig = tc.tmpDir + "/orig" tc.mnt = tc.tmpDir + "/mnt" tc.Mkdir(tc.orig, 0700) tc.Mkdir(tc.mnt, 0700) tc.mountFile = filepath.Join(tc.mnt, name) tc.mountSubdir = filepath.Join(tc.mnt, subdir) tc.origFile = filepath.Join(tc.orig, name) tc.origSubdir = filepath.Join(tc.orig, subdir) var pfs pathfs.FileSystem pfs = pathfs.NewLoopbackFileSystem(tc.orig) pfs = pathfs.NewLockingFileSystem(pfs) tc.pathFs = pathfs.NewPathNodeFs(pfs, &pathfs.PathNodeFsOptions{ ClientInodes: true}) tc.connector = nodefs.NewFileSystemConnector(tc.pathFs.Root(), &nodefs.Options{ EntryTimeout: testTtl, AttrTimeout: testTtl, NegativeTimeout: 0.0, Debug: VerboseTest(), }) tc.state, err = fuse.NewServer( fuse.NewRawFileSystem(tc.connector.RawFS()), tc.mnt, &fuse.MountOptions{ SingleThreaded: true, Debug: VerboseTest(), }) if err != nil { t.Fatal("NewServer:", err) } go tc.state.Serve() if err := tc.state.WaitMount(); err != nil { t.Fatal("WaitMount", err) } return tc }
func main() { flag.Parse() if len(flag.Args()) < 1 { log.Fatal("Usage:\n hello MOUNTPOINT") } nfs := pathfs.NewPathNodeFs(&HelloFs{FileSystem: pathfs.NewDefaultFileSystem()}, nil) server, _, err := nodefs.MountRoot(flag.Arg(0), nfs.Root(), nil) if err != nil { log.Fatalf("Mount fail: %v\n", err) } server.Serve() }
// Create and mount filesystem. func NewTestCase(t *testing.T) *testCase { me := &testCase{} me.tester = t // Make sure system setting does not affect test. syscall.Umask(0) const name string = "hello.txt" const subdir string = "subdir" var err error me.tmpDir, err = ioutil.TempDir("", "go-fuse") if err != nil { t.Fatalf("TempDir failed: %v", err) } me.orig = me.tmpDir + "/orig" me.mnt = me.tmpDir + "/mnt" os.Mkdir(me.orig, 0700) os.Mkdir(me.mnt, 0700) me.mountFile = filepath.Join(me.mnt, name) me.mountSubdir = filepath.Join(me.mnt, subdir) me.origFile = filepath.Join(me.orig, name) me.origSubdir = filepath.Join(me.orig, subdir) var pfs pathfs.FileSystem pfs = pathfs.NewLoopbackFileSystem(me.orig) pfs = pathfs.NewLockingFileSystem(pfs) me.pathFs = pathfs.NewPathNodeFs(pfs, &pathfs.PathNodeFsOptions{ ClientInodes: true}) me.connector = nodefs.NewFileSystemConnector(me.pathFs.Root(), &nodefs.Options{ EntryTimeout: testTtl, AttrTimeout: testTtl, NegativeTimeout: 0.0, }) me.connector.SetDebug(VerboseTest()) me.state, err = fuse.NewServer( fuse.NewRawFileSystem(me.connector.RawFS()), me.mnt, &fuse.MountOptions{SingleThreaded: true}) if err != nil { t.Fatal("NewServer:", err) } me.state.SetDebug(VerboseTest()) // Unthreaded, but in background. go me.state.Serve() me.state.WaitMount() return me }
// NewKeywhizFs readies a KeywhizFs struct and its parent filesystem objects. func NewKeywhizFs(client *Client, ownership Ownership, timeouts Timeouts, logConfig log.Config) (kwfs *KeywhizFs, root nodefs.Node, err error) { logger := log.New("kwfs", logConfig) cache := NewCache(client, timeouts, logConfig) defaultfs := pathfs.NewDefaultFileSystem() // Returns ENOSYS by default readonlyfs := pathfs.NewReadonlyFileSystem(defaultfs) // R/W calls return EPERM kwfs = &KeywhizFs{readonlyfs, logger, client, cache, time.Now(), ownership} nfs := pathfs.NewPathNodeFs(kwfs, nil) nfs.SetDebug(logConfig.Debug) return kwfs, nfs.Root(), nil }
func main() { flag.Parse() if len(flag.Args()) < 2 { log.Fatal("Usage:\n etcd-fs MOUNTPOINT ETCDENDPOINT") } etcdFs := EtcdFs{FileSystem: pathfs.NewDefaultFileSystem(), EtcdEndpoint: flag.Arg(1)} nfs := pathfs.NewPathNodeFs(&etcdFs, nil) server, _, err := nodefs.MountRoot(flag.Arg(0), nfs.Root(), nil) if err != nil { log.Fatalf("Mount fail: %v\n", err) } server.Serve() }
func main() { if len(os.Args) < 3 { log.Fatal("More Args Pls. path username") } gf := &GistFs{FileSystem: pathfs.NewDefaultFileSystem(), user: os.Args[2]} nfs := pathfs.NewPathNodeFs(gf, nil) server, _, err := nodefs.MountRoot(os.Args[1], nfs.Root(), nil) if err != nil { log.Fatal(err) } server.Serve() }