path: root/print-tree.c
diff options
authorQu Wenruo <>2018-04-30 11:15:44 +0800
committerDavid Sterba <>2018-06-07 16:37:35 +0200
commit8606fe4bcb8ff88a67a939911af9336499486c85 (patch)
treed5af5760632ff52c14d84f29e234ed6408f8f95e /print-tree.c
parent41750fe660cd51ca318976761c1938fa70d7ffa2 (diff)
btrfs-progs: Allow tree to be printed without an fs_info
For btrfs_print_tree() and btrfs_print_leaf(), the usage of fs_info is mainly for nodesize and sectorsize. However for nodesize, we can get it from @eb->len without the need for fs_info at all. For nodesize, introduce new helper BTRFS_NODEPTR_PER_EXTENT_BUFFER() to get nodesize from @eb directly. And with the help of previous modified btrfs_leaf_free_space(), btrfs_print_tree() can live without fs_info at all. For btrfs_print_leaf(), we modify print_extent_csum() to accept NULL fs_info by skipping csum length calculation. With all these modification, btrfs_print_tree/leaf() can be called without accessing @fs_info at all, and make it more flexible to handle binary tree block dump, or inside gdb. Signed-off-by: Qu Wenruo <> Reviewed-by: Su Yue <> Signed-off-by: David Sterba <>
Diffstat (limited to 'print-tree.c')
1 files changed, 13 insertions, 2 deletions
diff --git a/print-tree.c b/print-tree.c
index 4ebf7492..b86a7541 100644
--- a/print-tree.c
+++ b/print-tree.c
@@ -1150,6 +1150,14 @@ static void print_extent_csum(struct extent_buffer *eb,
u32 size;
+ /*
+ * If we don't have fs_info, only output its start position as we
+ * don't have sectorsize for the calculation
+ */
+ if (!fs_info) {
+ printf("\t\trange start %llu\n", (unsigned long long)start);
+ return;
+ }
size = (item_size / btrfs_super_csum_size(fs_info->super_copy)) *
printf("\t\trange start %llu end %llu length %u\n",
@@ -1389,7 +1397,7 @@ void btrfs_print_tree(struct extent_buffer *eb, int follow)
printf("node %llu level %d items %d free %u generation %llu owner ",
(unsigned long long)eb->start,
btrfs_header_level(eb), nr,
- (u32)BTRFS_NODEPTRS_PER_BLOCK(fs_info) - nr,
(unsigned long long)btrfs_header_generation(eb));
print_objectid(stdout, btrfs_header_owner(eb), 0);
@@ -1403,13 +1411,16 @@ void btrfs_print_tree(struct extent_buffer *eb, int follow)
printf(" block %llu (%llu) gen %llu\n",
(unsigned long long)blocknr,
- (unsigned long long)blocknr / fs_info->nodesize,
+ (unsigned long long)blocknr / eb->len,
(unsigned long long)btrfs_node_ptr_generation(eb, i));
if (!follow)
+ if (follow && !fs_info)
+ return;
for (i = 0; i < nr; i++) {
next = read_tree_block(fs_info,
btrfs_node_blockptr(eb, i),