-
Notifications
You must be signed in to change notification settings - Fork 0
/
root.go
68 lines (56 loc) · 1.35 KB
/
root.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
59
60
61
62
63
64
65
66
67
68
package main
import (
"context"
"os"
"syscall"
"bazil.org/fuse"
"bazil.org/fuse/fs"
)
const (
control = "tags"
browse = "browse"
debug = "debug"
)
type filesystem struct{}
func emptyDir() []fuse.Dirent {
return emptyDirAlloc(10)
}
func emptyDirAlloc(c int) []fuse.Dirent {
result := make([]fuse.Dirent, 0, c)
result = append(result,
fuse.Dirent{Inode: 0, Name: ".", Type: fuse.DT_Dir},
fuse.Dirent{Inode: 0, Name: "..", Type: fuse.DT_Dir},
)
return result
}
func (filesystem) Root() (fs.Node, error) {
return rootDir{}, nil
}
type rootDir struct {
}
func (d rootDir) Attr(ctx context.Context, attr *fuse.Attr) error {
attr.Inode = 1
attr.Mode = os.ModeDir | 0755
attr.Size = 4096
return nil
}
func (d rootDir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
var result = emptyDir()
result = append(result,
fuse.Dirent{Inode: 1, Name: control, Type: fuse.DT_Dir},
fuse.Dirent{Inode: 2, Name: browse, Type: fuse.DT_Dir},
)
return result, nil
}
func (d rootDir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) {
return nil, nil, syscall.EACCES
}
func (d rootDir) Lookup(ctx context.Context, name string) (fs.Node, error) {
switch name {
case control:
return tagsDir{}, nil
case browse:
return browseDir{cache: newCache()}, nil
}
return nil, syscall.ENOENT
}