blob: e32a959dd3e5b93831eef9e1d357726c01f2e48c [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);
Chris Masona28ec192007-03-06 20:08:01 -050024 printf("\t\titem data %.*s\n", item->size,
25 l->data+item->offset);
Chris Mason5de08d72007-02-24 06:24:44 -050026 ei = (struct extent_item *)(l->data + item->offset);
Chris Masona28ec192007-03-06 20:08:01 -050027 printf("\t\textent data refs %u owner %Lu\n", ei->refs,
28 ei->owner);
Chris Mason5de08d72007-02-24 06:24:44 -050029 fflush(stdout);
30 }
31}
32void print_tree(struct ctree_root *root, struct tree_buffer *t)
33{
34 int i;
35 int nr;
36 struct node *c;
37
38 if (!t)
39 return;
40 c = &t->node;
41 nr = c->header.nritems;
42 if (c->header.blocknr != t->blocknr)
43 BUG();
44 if (is_leaf(c->header.flags)) {
45 print_leaf((struct leaf *)c);
46 return;
47 }
Chris Mason41903fe2007-02-26 10:55:42 -050048 printf("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr,
Chris Mason5de08d72007-02-24 06:24:44 -050049 node_level(c->header.flags), c->header.nritems,
Chris Masond16302a2007-02-26 14:26:58 -050050 (u32)NODEPTRS_PER_BLOCK - c->header.nritems);
Chris Mason5de08d72007-02-24 06:24:44 -050051 fflush(stdout);
52 for (i = 0; i < nr; i++) {
Chris Mason7cf75962007-02-26 10:55:01 -050053 printf("\tkey %d (%Lu %u %Lu) block %Lu\n",
Chris Mason5de08d72007-02-24 06:24:44 -050054 i,
55 c->keys[i].objectid, c->keys[i].flags, c->keys[i].offset,
56 c->blockptrs[i]);
57 fflush(stdout);
58 }
59 for (i = 0; i < nr; i++) {
60 struct tree_buffer *next_buf = read_tree_block(root,
61 c->blockptrs[i]);
62 struct node *next = &next_buf->node;
63 if (is_leaf(next->header.flags) &&
64 node_level(c->header.flags) != 1)
65 BUG();
66 if (node_level(next->header.flags) !=
67 node_level(c->header.flags) - 1)
68 BUG();
69 print_tree(root, next_buf);
70 tree_block_release(root, next_buf);
71 }
72
73}
74