forked from unprofession-al/scum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mount.go
58 lines (50 loc) · 1.13 KB
/
mount.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"fmt"
"log"
"os"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
)
type RootFS struct {
fs.Inode
data map[string][]byte
}
func (r *RootFS) OnAdd(ctx context.Context) {
counter := uint64(2)
for filename, data := range r.data {
ch := r.NewPersistentInode(
ctx, &fs.MemRegularFile{
Data: data,
Attr: fuse.Attr{
Mode: 0600,
},
}, fs.StableAttr{Ino: counter})
r.AddChild(filename, ch, false)
counter++
}
}
func (r *RootFS) Getattr(ctx context.Context, fh fs.FileHandle, out *fuse.AttrOut) syscall.Errno {
out.Mode = 0700
return 0
}
var _ = (fs.NodeGetattrer)((*RootFS)(nil))
var _ = (fs.NodeOnAdder)((*RootFS)(nil))
func mount(mountpoint string, data map[string][]byte, timeout int, debug bool) {
opts := &fs.Options{}
opts.Debug = debug
server, err := fs.Mount(mountpoint, &RootFS{data: data}, opts)
if err != nil {
log.Fatalf("Mount fail: %v\n", err)
}
fmt.Printf("Mounted for %d seconds or until Ctrl+C is pressed...\n", timeout)
w := Wait{
Seconds: timeout,
Out: os.Stderr,
}
w.Start()
fmt.Printf("\n")
server.Unmount()
}