blob: 1d591270f4c4bfcdbf7ad9b5b2408e834c5029ca [file] [log] [blame]
Chris Mason5de08d72007-02-24 06:24:44 -05001#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;
Chris Mason7cf75962007-02-26 10:55:01 -050014 printf("leaf %Lu total ptrs %d free space %d\n", l->header.blocknr, nr,
Chris Mason5de08d72007-02-24 06:24:44 -050015 leaf_free_space(l));
16 fflush(stdout);
17 for (i = 0 ; i < nr ; i++) {
18 item = l->items + i;
Chris Mason7cf75962007-02-26 10:55:01 -050019 printf("\titem %d key (%Lu %u %Lu) itemoff %d itemsize %d\n",
Chris Mason5de08d72007-02-24 06:24:44 -050020 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);
Chris Mason7cf75962007-02-26 10:55:01 -050026 printf("\t\textent data %u %Lu\n", ei->refs, ei->owner);
Chris Mason5de08d72007-02-24 06:24:44 -050027 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 }
Chris Mason7cf75962007-02-26 10:55:01 -050046 printf("node %Lu level %d total ptrs %d free spc %lu\n", t->blocknr,
Chris Mason5de08d72007-02-24 06:24:44 -050047 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++) {
Chris Mason7cf75962007-02-26 10:55:01 -050051 printf("\tkey %d (%Lu %u %Lu) block %Lu\n",
Chris Mason5de08d72007-02-24 06:24:44 -050052 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