/
fs.go
49 lines (40 loc) · 1.59 KB
/
fs.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
package main
import (
// "log"
"log"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"golang.org/x/net/context"
)
type FS struct {
root *Dir
}
func (f *FS) Root() (fs.Node, error) {
log.Printf("[Root]")
return f.root, nil
}
func (f *FS) Statfs(ctx context.Context, req *fuse.StatfsRequest, res *fuse.StatfsResponse) error {
// log.Printf("[Statfs]")
var totalData uint64
err := db.QueryRow("SELECT SUM(tape_format.capacity) FROM tapes tapes LEFT JOIN tape_format tape_format ON tapes.tape_format = tape_format.type WHERE tapes.broken = 0").Scan(&totalData)
checkerr(err)
// totalData = totalData / uint64(config.numberOfCopies)
var occupiedData uint64
// err = db.QueryRow("SELECT COALESCE(SUM(size),0) FROM kts.index WHERE deleted = 0").Scan(&occupiedData)
err = db.QueryRow("SELECT COALESCE(SUM(size),0) FROM root_index WHERE deleted = 0").Scan(&occupiedData)
checkerr(err)
// res.Blocks = 100 // Total data blocks in file system.
res.Bfree = 100 // Free blocks in file system.
// res.Bavail = 1 << 34 // Free blocks in file system if you're not root.
res.Files = 1 << 29 // Total files in file system.
res.Ffree = 1 << 28 // Free files in file system.
// res.Ffree = 1024000
res.Namelen = 256 // Maximum file name length?
res.Bsize = 128 * 1024 // Block size
// res.Bsize = 49152
// resp.Frsize = 1 // Fragment size, smallest addressable data size in the file system.
res.Blocks = totalData / uint64(config.numberOfCopies) / uint64(res.Bsize)
res.Bfree = (res.Blocks - (occupiedData/uint64(config.numberOfCopies))/uint64(res.Bsize))
// log.Printf("[Statfs] %v", res)
return nil
}