aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/print-tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/btrfs/print-tree.c')
-rw-r--r--fs/btrfs/print-tree.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
new file mode 100644
index 000000000000..594d23b5b24c
--- /dev/null
+++ b/fs/btrfs/print-tree.c
@@ -0,0 +1,72 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include "kerncompat.h"
4#include "radix-tree.h"
5#include "ctree.h"
6#include "disk-io.h"
7
8void print_leaf(struct leaf *l)
9{
10 int i;
11 int nr = l->header.nritems;
12 struct item *item;
13 struct extent_item *ei;
14 printf("leaf %lu total ptrs %d free space %d\n", l->header.blocknr, nr,
15 leaf_free_space(l));
16 fflush(stdout);
17 for (i = 0 ; i < nr ; i++) {
18 item = l->items + i;
19 printf("\titem %d key (%lu %u %lu) itemoff %d itemsize %d\n",
20 i,
21 item->key.objectid, item->key.flags, item->key.offset,
22 item->offset, item->size);
23 fflush(stdout);
24 printf("\t\titem data %.*s\n", item->size, l->data+item->offset);
25 ei = (struct extent_item *)(l->data + item->offset);
26 printf("\t\textent data %u %lu\n", ei->refs, ei->owner);
27 fflush(stdout);
28 }
29}
30void print_tree(struct ctree_root *root, struct tree_buffer *t)
31{
32 int i;
33 int nr;
34 struct node *c;
35
36 if (!t)
37 return;
38 c = &t->node;
39 nr = c->header.nritems;
40 if (c->header.blocknr != t->blocknr)
41 BUG();
42 if (is_leaf(c->header.flags)) {
43 print_leaf((struct leaf *)c);
44 return;
45 }
46 printf("node %lu level %d total ptrs %d free spc %lu\n", t->blocknr,
47 node_level(c->header.flags), c->header.nritems,
48 NODEPTRS_PER_BLOCK - c->header.nritems);
49 fflush(stdout);
50 for (i = 0; i < nr; i++) {
51 printf("\tkey %d (%lu %u %lu) block %lu\n",
52 i,
53 c->keys[i].objectid, c->keys[i].flags, c->keys[i].offset,
54 c->blockptrs[i]);
55 fflush(stdout);
56 }
57 for (i = 0; i < nr; i++) {
58 struct tree_buffer *next_buf = read_tree_block(root,
59 c->blockptrs[i]);
60 struct node *next = &next_buf->node;
61 if (is_leaf(next->header.flags) &&
62 node_level(c->header.flags) != 1)
63 BUG();
64 if (node_level(next->header.flags) !=
65 node_level(c->header.flags) - 1)
66 BUG();
67 print_tree(root, next_buf);
68 tree_block_release(root, next_buf);
69 }
70
71}
72