-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathffsinterface.go
80 lines (65 loc) · 1.88 KB
/
ffsinterface.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
69
70
71
72
73
74
75
76
77
78
79
80
/* TACIXAT 2020 */
package main
import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"context"
"sync"
"syscall"
)
type FFSIReadHandler func() ([]byte, error)
type FFSIAttrHandler func(*fuse.Attr) error
type FFSIWriteHandler func(*fuse.WriteRequest, *fuse.WriteResponse) error
type FFSISetAttrHandler func(*fuse.SetattrRequest, *fuse.SetattrResponse) error
// Mutation
type FFSInterface struct {
Name string
Index uint64
ReadHandler FFSIReadHandler
AttrHandler FFSIAttrHandler
WriteHandler FFSIWriteHandler
SetAttrHandler FFSISetAttrHandler
Mutex *sync.Mutex
}
func NewFFSInterface(name string) *FFSInterface {
return &FFSInterface{
Name: name,
Index: lidx.Next(),
Mutex: new(sync.Mutex),
}
}
func (ffsi *FFSInterface) Attr(ctx context.Context, a *fuse.Attr) error {
if ffsi.AttrHandler != nil {
return ffsi.AttrHandler(a)
}
return syscall.ENOSYS
}
func (ffsi *FFSInterface) Flush(ctx context.Context, req *fuse.FlushRequest) error {
return nil
}
func (ffsi *FFSInterface) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *fuse.GetxattrResponse) error {
return nil
}
func (ffsi *FFSInterface) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
return ffsi, nil
}
func (ffsi *FFSInterface) ReadAll(ctx context.Context) ([]byte, error) {
if ffsi.ReadHandler != nil {
return ffsi.ReadHandler()
}
return nil, syscall.ENOSYS
}
func (ffsi *FFSInterface) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
if ffsi.SetAttrHandler != nil {
return ffsi.SetAttrHandler(req, resp)
}
return syscall.ENOSYS
}
func (ffsi *FFSInterface) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error {
ffsi.Mutex.Lock()
defer ffsi.Mutex.Unlock()
if ffsi.WriteHandler != nil {
return ffsi.WriteHandler(req, resp)
}
return syscall.ENOSYS
}