feat: Implement example in alternative FUSE library

This commit is contained in:
Felicitas Pojtinger
2021-11-12 23:32:06 +01:00
parent 73b830d3cf
commit 962459d1e9
4 changed files with 82 additions and 6 deletions
+5 -5
View File
@@ -9,14 +9,14 @@ import (
"github.com/hanwen/go-fuse/v2/fuse"
)
type Root struct {
type FileSystem struct {
fs.Inode
}
func (r *Root) OnAdd(ctx context.Context) {
r.AddChild(
func (f *FileSystem) OnAdd(ctx context.Context) {
f.AddChild(
"hello_world.txt",
r.NewPersistentInode(
f.NewPersistentInode(
ctx,
&fs.MemRegularFile{
Data: []byte("Hello, world!"),
@@ -38,7 +38,7 @@ func main() {
server, err := fs.Mount(
*mountpoint,
&Root{},
&FileSystem{},
&fs.Options{
Logger: func() *log.Logger {
if *verbose {
+55
View File
@@ -0,0 +1,55 @@
package main
import (
"context"
"flag"
"log"
"os"
"github.com/jacobsa/fuse"
"github.com/jacobsa/fuse/fuseops"
"github.com/jacobsa/fuse/fuseutil"
)
type FileSystem struct {
fuseutil.NotImplementedFileSystem
}
func (f *FileSystem) GetInodeAttributes(ctx context.Context, op *fuseops.GetInodeAttributesOp) error {
op.Attributes = fuseops.InodeAttributes{
Nlink: 1,
Mode: 0555 | os.ModeDir,
}
log.Println(op.Inode)
return nil
}
func main() {
mountpoint := flag.String("mountpoint", ".", "Directory to mount the FUSE in")
verbose := flag.Bool("verbose", false, "Enable verbose logging")
flag.Parse()
srv, err := fuse.Mount(
*mountpoint,
fuseutil.NewFileSystemServer(&FileSystem{}),
&fuse.MountConfig{
DebugLogger: func() *log.Logger {
if *verbose {
return log.Default()
}
return nil
}(),
},
)
if err != nil {
panic(err)
}
if err := srv.Join(context.Background()); err != nil {
panic(err)
}
}