feat: Add basic FUSE read-only FS example

This commit is contained in:
Felix Pojtinger
2021-11-11 21:45:55 +01:00
parent b577f55cc9
commit c321d52076
4 changed files with 71 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
package main
import (
"context"
"flag"
"log"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
)
type Root struct {
fs.Inode
}
func (r *Root) OnAdd(ctx context.Context) {
r.AddChild(
"hello_world.txt",
r.NewPersistentInode(
ctx,
&fs.MemRegularFile{
Data: []byte("Hello, world!"),
Attr: fuse.Attr{
Mode: 0644,
},
},
fs.StableAttr{},
),
false,
)
}
func main() {
mountpoint := flag.String("mountpoint", ".", "Directory to mount the FUSE in")
verbose := flag.Bool("verbose", false, "Enable verbose logging")
flag.Parse()
server, err := fs.Mount(
*mountpoint,
&Root{},
&fs.Options{
Logger: func() *log.Logger {
if *verbose {
return log.Default()
}
return nil
}(),
},
)
if err != nil {
panic(err)
}
defer server.Unmount()
server.Wait()
}
View File
+4
View File
@@ -1,3 +1,7 @@
module github.com/pojntfx/stfs
go 1.17
require github.com/hanwen/go-fuse/v2 v2.1.0
require golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 // indirect
+9
View File
@@ -0,0 +1,9 @@
github.com/hanwen/go-fuse v1.0.0 h1:GxS9Zrn6c35/BnfiVsZVWmsG803xwE7eVRDvcf/BEVc=
github.com/hanwen/go-fuse v1.0.0/go.mod h1:unqXarDXqzAk0rt98O2tVndEPIpUgLD9+rwFisZH3Ok=
github.com/hanwen/go-fuse/v2 v2.1.0 h1:+32ffteETaLYClUj0a3aHjZ1hOPxxaNEHiZiujuDaek=
github.com/hanwen/go-fuse/v2 v2.1.0/go.mod h1:oRyA5eK+pvJyv5otpO/DgccS8y/RvYMaO00GgRLGryc=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3vkb4ax0b5D2DHbNAUsen0Gx5wZoq3lV4=
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522 h1:Ve1ORMCxvRmSXBwJK+t3Oy+V2vRW2OetUQBq4rJIkZE=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=