summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs/btrfsinspect/print_tree.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/print_tree.go')
-rw-r--r--lib/btrfsprogs/btrfsinspect/print_tree.go82
1 files changed, 42 insertions, 40 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/print_tree.go b/lib/btrfsprogs/btrfsinspect/print_tree.go
index 1568245..9e5a5d1 100644
--- a/lib/btrfsprogs/btrfsinspect/print_tree.go
+++ b/lib/btrfsprogs/btrfsinspect/print_tree.go
@@ -16,7 +16,9 @@ import (
"git.lukeshu.com/btrfs-progs-ng/lib/binstruct"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsitem"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsprim"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfssum"
+ "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfstree"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol"
"git.lukeshu.com/btrfs-progs-ng/lib/diskio"
"git.lukeshu.com/btrfs-progs-ng/lib/slices"
@@ -31,50 +33,50 @@ func DumpTrees(ctx context.Context, out io.Writer, fs *btrfs.FS) {
if superblock.RootTree != 0 {
fmt.Fprintf(out, "root tree\n")
- printTree(ctx, out, fs, btrfs.ROOT_TREE_OBJECTID)
+ printTree(ctx, out, fs, btrfsprim.ROOT_TREE_OBJECTID)
}
if superblock.ChunkTree != 0 {
fmt.Fprintf(out, "chunk tree\n")
- printTree(ctx, out, fs, btrfs.CHUNK_TREE_OBJECTID)
+ printTree(ctx, out, fs, btrfsprim.CHUNK_TREE_OBJECTID)
}
if superblock.LogTree != 0 {
fmt.Fprintf(out, "log root tree\n")
- printTree(ctx, out, fs, btrfs.TREE_LOG_OBJECTID)
+ printTree(ctx, out, fs, btrfsprim.TREE_LOG_OBJECTID)
}
if superblock.BlockGroupRoot != 0 {
fmt.Fprintf(out, "block group tree\n")
- printTree(ctx, out, fs, btrfs.BLOCK_GROUP_TREE_OBJECTID)
+ printTree(ctx, out, fs, btrfsprim.BLOCK_GROUP_TREE_OBJECTID)
}
fs.TreeWalk(
ctx,
- btrfs.ROOT_TREE_OBJECTID,
- func(err *btrfs.TreeError) {
+ btrfsprim.ROOT_TREE_OBJECTID,
+ func(err *btrfstree.TreeError) {
dlog.Error(ctx, err)
},
- btrfs.TreeWalkHandler{
- Item: func(_ btrfs.TreePath, item btrfs.Item) error {
+ btrfstree.TreeWalkHandler{
+ Item: func(_ btrfstree.TreePath, item btrfstree.Item) error {
if item.Key.ItemType != btrfsitem.ROOT_ITEM_KEY {
return nil
}
- treeName, ok := map[btrfs.ObjID]string{
- btrfs.ROOT_TREE_OBJECTID: "root",
- btrfs.EXTENT_TREE_OBJECTID: "extent",
- btrfs.CHUNK_TREE_OBJECTID: "chunk",
- btrfs.DEV_TREE_OBJECTID: "device",
- btrfs.FS_TREE_OBJECTID: "fs",
- btrfs.ROOT_TREE_DIR_OBJECTID: "directory",
- btrfs.CSUM_TREE_OBJECTID: "checksum",
- btrfs.ORPHAN_OBJECTID: "orphan",
- btrfs.TREE_LOG_OBJECTID: "log",
- btrfs.TREE_LOG_FIXUP_OBJECTID: "log fixup",
- btrfs.TREE_RELOC_OBJECTID: "reloc",
- btrfs.DATA_RELOC_TREE_OBJECTID: "data reloc",
- btrfs.EXTENT_CSUM_OBJECTID: "extent checksum",
- btrfs.QUOTA_TREE_OBJECTID: "quota",
- btrfs.UUID_TREE_OBJECTID: "uuid",
- btrfs.FREE_SPACE_TREE_OBJECTID: "free space",
- btrfs.MULTIPLE_OBJECTIDS: "multiple",
- btrfs.BLOCK_GROUP_TREE_OBJECTID: "block group",
+ treeName, ok := map[btrfsprim.ObjID]string{
+ btrfsprim.ROOT_TREE_OBJECTID: "root",
+ btrfsprim.EXTENT_TREE_OBJECTID: "extent",
+ btrfsprim.CHUNK_TREE_OBJECTID: "chunk",
+ btrfsprim.DEV_TREE_OBJECTID: "device",
+ btrfsprim.FS_TREE_OBJECTID: "fs",
+ btrfsprim.ROOT_TREE_DIR_OBJECTID: "directory",
+ btrfsprim.CSUM_TREE_OBJECTID: "checksum",
+ btrfsprim.ORPHAN_OBJECTID: "orphan",
+ btrfsprim.TREE_LOG_OBJECTID: "log",
+ btrfsprim.TREE_LOG_FIXUP_OBJECTID: "log fixup",
+ btrfsprim.TREE_RELOC_OBJECTID: "reloc",
+ btrfsprim.DATA_RELOC_TREE_OBJECTID: "data reloc",
+ btrfsprim.EXTENT_CSUM_OBJECTID: "extent checksum",
+ btrfsprim.QUOTA_TREE_OBJECTID: "quota",
+ btrfsprim.UUID_TREE_OBJECTID: "uuid",
+ btrfsprim.FREE_SPACE_TREE_OBJECTID: "free space",
+ btrfsprim.MULTIPLE_OBJECTIDS: "multiple",
+ btrfsprim.BLOCK_GROUP_TREE_OBJECTID: "block group",
}[item.Key.ObjectID]
if !ok {
treeName = "file"
@@ -93,22 +95,22 @@ func DumpTrees(ctx context.Context, out io.Writer, fs *btrfs.FS) {
// printTree mimics btrfs-progs
// kernel-shared/print-tree.c:btrfs_print_tree() and
// kernel-shared/print-tree.c:btrfs_print_leaf()
-func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfs.ObjID) {
+func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfsprim.ObjID) {
var itemOffset uint32
- handlers := btrfs.TreeWalkHandler{
- Node: func(path btrfs.TreePath, nodeRef *diskio.Ref[btrfsvol.LogicalAddr, btrfs.Node]) error {
+ handlers := btrfstree.TreeWalkHandler{
+ Node: func(path btrfstree.TreePath, nodeRef *diskio.Ref[btrfsvol.LogicalAddr, btrfstree.Node]) error {
printHeaderInfo(out, nodeRef.Data)
- itemOffset = nodeRef.Data.Size - uint32(binstruct.StaticSize(btrfs.NodeHeader{}))
+ itemOffset = nodeRef.Data.Size - uint32(binstruct.StaticSize(btrfstree.NodeHeader{}))
return nil
},
- PreKeyPointer: func(_ btrfs.TreePath, item btrfs.KeyPointer) error {
+ PreKeyPointer: func(_ btrfstree.TreePath, item btrfstree.KeyPointer) error {
fmt.Fprintf(out, "\t%v block %v gen %v\n",
fmtKey(item.Key),
item.BlockPtr,
item.Generation)
return nil
},
- Item: func(path btrfs.TreePath, item btrfs.Item) error {
+ Item: func(path btrfstree.TreePath, item btrfstree.Item) error {
i := path.Node(-1).FromItemIdx
bs, _ := binstruct.Marshal(item.Body)
itemSize := uint32(len(bs))
@@ -303,7 +305,7 @@ func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfs.Ob
fmt.Fprintf(out, "\t\tpersistent item objectid %v offset %v\n",
item.Key.ObjectID.Format(item.Key.ItemType), item.Key.Offset)
switch item.Key.ObjectID {
- case btrfs.DEV_STATS_OBJECTID:
+ case btrfsprim.DEV_STATS_OBJECTID:
fmt.Fprintf(out, "\t\tdevice stats\n")
fmt.Fprintf(out, "\t\twrite_errs %v read_errs %v flush_errs %v corruption_errs %v generation %v\n",
body.Values[btrfsitem.DEV_STAT_WRITE_ERRS],
@@ -347,7 +349,7 @@ func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfs.Ob
fs.TreeWalk(
ctx,
treeID,
- func(err *btrfs.TreeError) {
+ func(err *btrfstree.TreeError) {
dlog.Error(ctx, err)
},
handlers,
@@ -355,7 +357,7 @@ func printTree(ctx context.Context, out io.Writer, fs *btrfs.FS, treeID btrfs.Ob
}
// printHeaderInfo mimics btrfs-progs kernel-shared/print-tree.c:print_header_info()
-func printHeaderInfo(out io.Writer, node btrfs.Node) {
+func printHeaderInfo(out io.Writer, node btrfstree.Node) {
var typename string
if node.Head.Level > 0 { // internal node
typename = "node"
@@ -400,7 +402,7 @@ func printExtentInlineRefs(out io.Writer, refs []btrfsitem.ExtentInlineRef) {
switch ref.Type {
case btrfsitem.TREE_BLOCK_REF_KEY:
fmt.Fprintf(out, "\t\ttree block backref root %v\n",
- btrfs.ObjID(ref.Offset))
+ btrfsprim.ObjID(ref.Offset))
case btrfsitem.SHARED_BLOCK_REF_KEY:
fmt.Fprintf(out, "\t\tshared block backref parent %v\n",
ref.Offset)
@@ -420,7 +422,7 @@ func printExtentInlineRefs(out io.Writer, refs []btrfsitem.ExtentInlineRef) {
}
// mimics print-tree.c:btrfs_print_key()
-func fmtKey(key btrfs.Key) string {
+func fmtKey(key btrfsprim.Key) string {
var out strings.Builder
fmt.Fprintf(&out, "key (%v %v", key.ObjectID.Format(key.ItemType), key.ItemType)
switch key.ItemType {
@@ -429,7 +431,7 @@ func fmtKey(key btrfs.Key) string {
case btrfsitem.UUID_SUBVOL_KEY, btrfsitem.UUID_RECEIVED_SUBVOL_KEY:
fmt.Fprintf(&out, " %#08x)", key.Offset)
case btrfsitem.ROOT_ITEM_KEY:
- fmt.Fprintf(&out, " %v)", btrfs.ObjID(key.Offset))
+ fmt.Fprintf(&out, " %v)", btrfsprim.ObjID(key.Offset))
default:
if key.Offset == math.MaxUint64 {
fmt.Fprintf(&out, " -1)")
@@ -440,7 +442,7 @@ func fmtKey(key btrfs.Key) string {
return out.String()
}
-func fmtTime(t btrfs.Time) string {
+func fmtTime(t btrfsprim.Time) string {
return fmt.Sprintf("%v.%v (%v)",
t.Sec, t.NSec, t.ToStd().Format("2006-01-02 15:04:05"))
}