blob: 33f5ee4052c104f7914fc64598b3918d477fa294 [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;
Chris Mason7518a232007-03-12 12:01:18 -040011 u32 nr = btrfs_header_nritems(&l->header);
Chris Mason0783fcf2007-03-12 20:12:07 -040012 struct btrfs_item *item;
Chris Mason5de08d72007-02-24 06:24:44 -050013 struct extent_item *ei;
Chris Mason7518a232007-03-12 12:01:18 -040014 printf("leaf %Lu total ptrs %d free space %d\n",
15 btrfs_header_blocknr(&l->header), nr, leaf_free_space(l));
Chris Mason5de08d72007-02-24 06:24:44 -050016 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,
Chris Mason0783fcf2007-03-12 20:12:07 -040021 btrfs_key_objectid(&item->key),
22 btrfs_key_flags(&item->key),
23 btrfs_key_offset(&item->key),
24 btrfs_item_offset(item),
25 btrfs_item_size(item));
Chris Mason5de08d72007-02-24 06:24:44 -050026 fflush(stdout);
Chris Mason0783fcf2007-03-12 20:12:07 -040027 printf("\t\titem data %.*s\n", btrfs_item_size(item),
28 l->data + btrfs_item_offset(item));
29 ei = (struct extent_item *)(l->data + btrfs_item_offset(item));
Chris Masona28ec192007-03-06 20:08:01 -050030 printf("\t\textent data refs %u owner %Lu\n", ei->refs,
31 ei->owner);
Chris Mason5de08d72007-02-24 06:24:44 -050032 fflush(stdout);
33 }
34}
35void print_tree(struct ctree_root *root, struct tree_buffer *t)
36{
37 int i;
Chris Mason7518a232007-03-12 12:01:18 -040038 u32 nr;
Chris Mason5de08d72007-02-24 06:24:44 -050039 struct node *c;
40
41 if (!t)
42 return;
43 c = &t->node;
Chris Mason7518a232007-03-12 12:01:18 -040044 nr = btrfs_header_nritems(&c->header);
45 if (btrfs_is_leaf(c)) {
Chris Mason5de08d72007-02-24 06:24:44 -050046 print_leaf((struct leaf *)c);
47 return;
48 }
Chris Mason41903fe2007-02-26 10:55:42 -050049 printf("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr,
Chris Mason7518a232007-03-12 12:01:18 -040050 btrfs_header_level(&c->header), nr,
51 (u32)NODEPTRS_PER_BLOCK - nr);
Chris Mason5de08d72007-02-24 06:24:44 -050052 fflush(stdout);
53 for (i = 0; i < nr; i++) {
Chris Mason7cf75962007-02-26 10:55:01 -050054 printf("\tkey %d (%Lu %u %Lu) block %Lu\n",
Chris Mason5de08d72007-02-24 06:24:44 -050055 i,
56 c->keys[i].objectid, c->keys[i].flags, c->keys[i].offset,
57 c->blockptrs[i]);
58 fflush(stdout);
59 }
60 for (i = 0; i < nr; i++) {
61 struct tree_buffer *next_buf = read_tree_block(root,
62 c->blockptrs[i]);
63 struct node *next = &next_buf->node;
Chris Mason7518a232007-03-12 12:01:18 -040064 if (btrfs_is_leaf(next) &&
65 btrfs_header_level(&c->header) != 1)
Chris Mason5de08d72007-02-24 06:24:44 -050066 BUG();
Chris Mason7518a232007-03-12 12:01:18 -040067 if (btrfs_header_level(&next->header) !=
68 btrfs_header_level(&c->header) - 1)
Chris Mason5de08d72007-02-24 06:24:44 -050069 BUG();
70 print_tree(root, next_buf);
71 tree_block_release(root, next_buf);
72 }
73
74}
75