github.com/hanwen/go-fuse@v1.0.0/example/autounionfs/main.go (about) 1 // Copyright 2016 the Go-FUSE Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main 6 7 import ( 8 "flag" 9 "fmt" 10 "os" 11 "time" 12 13 "github.com/hanwen/go-fuse/fuse" 14 "github.com/hanwen/go-fuse/fuse/nodefs" 15 "github.com/hanwen/go-fuse/fuse/pathfs" 16 "github.com/hanwen/go-fuse/unionfs" 17 ) 18 19 func main() { 20 debug := flag.Bool("debug", false, "debug on") 21 hardlinks := flag.Bool("hardlinks", false, "support hardlinks") 22 delcache_ttl := flag.Float64("deletion_cache_ttl", 5.0, "Deletion cache TTL in seconds.") 23 branchcache_ttl := flag.Float64("branchcache_ttl", 5.0, "Branch cache TTL in seconds.") 24 deldirname := flag.String( 25 "deletion_dirname", "GOUNIONFS_DELETIONS", "Directory name to use for deletions.") 26 hide_readonly_link := flag.Bool("hide_readonly_link", true, 27 "Hides READONLY link from the top mountpoints. "+ 28 "Enabled by default.") 29 portableInodes := flag.Bool("portable-inodes", false, 30 "Use sequential 32-bit inode numbers.") 31 32 flag.Parse() 33 34 if len(flag.Args()) < 2 { 35 fmt.Println("Usage:\n main MOUNTPOINT BASEDIR") 36 os.Exit(2) 37 } 38 ufsOptions := unionfs.UnionFsOptions{ 39 DeletionCacheTTL: time.Duration(*delcache_ttl * float64(time.Second)), 40 BranchCacheTTL: time.Duration(*branchcache_ttl * float64(time.Second)), 41 DeletionDirName: *deldirname, 42 } 43 options := unionfs.AutoUnionFsOptions{ 44 UnionFsOptions: ufsOptions, 45 Options: nodefs.Options{ 46 EntryTimeout: time.Second, 47 AttrTimeout: time.Second, 48 NegativeTimeout: time.Second, 49 Owner: fuse.CurrentOwner(), 50 Debug: *debug, 51 }, 52 UpdateOnMount: true, 53 PathNodeFsOptions: pathfs.PathNodeFsOptions{ 54 ClientInodes: *hardlinks, 55 }, 56 HideReadonly: *hide_readonly_link, 57 } 58 fsOpts := nodefs.Options{ 59 PortableInodes: *portableInodes, 60 Debug: *debug, 61 } 62 gofs := unionfs.NewAutoUnionFs(flag.Arg(1), options) 63 pathfs := pathfs.NewPathNodeFs(gofs, &pathfs.PathNodeFsOptions{ 64 Debug: *debug, 65 }) 66 state, _, err := nodefs.MountRoot(flag.Arg(0), pathfs.Root(), &fsOpts) 67 if err != nil { 68 fmt.Printf("Mount fail: %v\n", err) 69 os.Exit(1) 70 } 71 72 state.Serve() 73 time.Sleep(1 * time.Second) 74 }