Skip to content

Commit f03fa74

Browse files
committed
implement subvolumes list; regenerate headers; generate btrfs_tree.h
1 parent b300237 commit f03fa74

10 files changed

Lines changed: 1047 additions & 44 deletions

File tree

btrfs_h.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package btrfs
22

33
import "strings"
44

5+
const maxUint64 = 1<<64 - 1
6+
57
const BTRFS_LABEL_SIZE = 256
68

79
type FeatureFlags uint64

btrfs_tree.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package btrfs
2+
3+
import (
4+
"time"
5+
"unsafe"
6+
)
7+
8+
const (
9+
_BTRFS_BLOCK_GROUP_PROFILE_MASK = (blockGroupRaid0 |
10+
blockGroupRaid1 |
11+
blockGroupRaid5 |
12+
blockGroupRaid6 |
13+
blockGroupDup |
14+
blockGroupRaid10)
15+
)
16+
17+
type rootRef struct {
18+
DirID uint64
19+
Sequence uint64
20+
Name string
21+
}
22+
23+
func (rootRef) btrfsSize() int { return 18 }
24+
25+
func asUint64(p []byte) uint64 {
26+
return *(*uint64)(unsafe.Pointer(&p[0]))
27+
}
28+
29+
func asUint32(p []byte) uint32 {
30+
return *(*uint32)(unsafe.Pointer(&p[0]))
31+
}
32+
33+
func asUint16(p []byte) uint16 {
34+
return *(*uint16)(unsafe.Pointer(&p[0]))
35+
}
36+
37+
func asTime(p []byte) time.Time {
38+
sec, nsec := asUint64(p[0:]), asUint32(p[8:])
39+
return time.Unix(int64(sec), int64(nsec))
40+
}
41+
42+
func asRootRef(p []byte) rootRef {
43+
const sz = 18
44+
// assuming that it is highly unsafe to have sizeof(struct) > len(data)
45+
// (*btrfs_root_ref)(unsafe.Pointer(&p[0])) and sizeof(btrfs_root_ref) == 24
46+
ref := rootRef{
47+
DirID: asUint64(p[0:]),
48+
Sequence: asUint64(p[8:]),
49+
}
50+
if n := asUint16(p[16:]); n > 0 {
51+
ref.Name = string(p[sz : sz+n : sz+n])
52+
}
53+
return ref
54+
}

0 commit comments

Comments
 (0)