-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrealfs.go
More file actions
55 lines (45 loc) · 929 Bytes
/
realfs.go
File metadata and controls
55 lines (45 loc) · 929 Bytes
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
package hellofs
import (
"time"
"bazil.org/fuse"
)
type RealFS struct {
GeneraterInode uint64
Dirs map[uint64][]*Dentry
Inodes map[uint64]*Inode
}
func NewRealFS() *RealFS {
return &RealFS{
GeneraterInode: 1,
Dirs: make(map[uint64][]*Dentry),
Inodes: make(map[uint64]*Inode),
}
}
func (r *RealFS) CreateInode() *Inode {
r.GeneraterInode = r.GeneraterInode + 1
inode := &Inode{
ino: r.GeneraterInode,
size: 100 * 1024,
nlink: 1,
uid: 0,
gid: 0,
ctime: time.Now(),
mtime: time.Now(),
atime: time.Now(),
target: []byte{},
}
r.Inodes[inode.ino] = inode
return inode
}
func (r *RealFS) CreateDentry(dino, ino uint64, name string, t fuse.DirentType) *Dentry {
d := &Dentry{
Inode: ino,
Name: name,
Type: t,
}
r.Dirs[dino] = append(r.Dirs[dino], d)
if t == fuse.DT_Dir {
r.Dirs[ino] = make([]*Dentry, 0, 1024)
}
return d
}