-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathffsfile.go
58 lines (49 loc) · 1.24 KB
/
ffsfile.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
/* TACIXAT 2020 */
package main
import (
"bazil.org/fuse"
"bazil.org/fuse/fs"
"context"
// "fmt"
)
// Mutant
type FFSFile struct {
Name string
Worm *FFSWorm
Index uint64
Underlying uint
}
func NewFFSFile(name string, worm *FFSWorm) *FFSFile {
return &FFSFile{
Name: name,
Worm: worm,
Index: lidx.Next(),
Underlying: worm.Current,
}
}
func (ffsf *FFSFile) getBytes() []byte {
data := ffsf.Worm.Data[ffsf.Underlying]
return ffsf.Worm.Strategies["bit_flip"].Synthesize(data, ffsf.Name)
}
func (ffsf *FFSFile) Attr(ctx context.Context, a *fuse.Attr) error {
a.Valid = 0
a.Inode = ffsf.Index
a.Mode = 0o444
a.Size = uint64(len(ffsf.Worm.Data[ffsf.Underlying]))
return nil
}
func (ffsf *FFSFile) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fs.Handle, error) {
return ffsf, nil
}
func (ffsf *FFSFile) ReadAll(ctx context.Context) ([]byte, error) {
return ffsf.getBytes(), nil
}
func (ffsf *FFSFile) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
if req.Valid.MtimeNow() {
ffsf.Worm.Mutex.Lock()
defer ffsf.Worm.Mutex.Unlock()
ffsf.Worm.Data = append(ffsf.Worm.Data, ffsf.getBytes())
ffsf.Worm.Current++
}
return nil
}