Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 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 | |
| 8 | void print_leaf(struct leaf *l) |
| 9 | { |
| 10 | int i; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 11 | u32 nr = btrfs_header_nritems(&l->header); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame^] | 12 | struct btrfs_item *item; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 13 | struct extent_item *ei; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 14 | printf("leaf %Lu total ptrs %d free space %d\n", |
| 15 | btrfs_header_blocknr(&l->header), nr, leaf_free_space(l)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 16 | fflush(stdout); |
| 17 | for (i = 0 ; i < nr ; i++) { |
| 18 | item = l->items + i; |
Chris Mason | 7cf7596 | 2007-02-26 10:55:01 -0500 | [diff] [blame] | 19 | printf("\titem %d key (%Lu %u %Lu) itemoff %d itemsize %d\n", |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 20 | i, |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame^] | 21 | 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 Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 26 | fflush(stdout); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame^] | 27 | 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 Mason | a28ec19 | 2007-03-06 20:08:01 -0500 | [diff] [blame] | 30 | printf("\t\textent data refs %u owner %Lu\n", ei->refs, |
| 31 | ei->owner); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 32 | fflush(stdout); |
| 33 | } |
| 34 | } |
| 35 | void print_tree(struct ctree_root *root, struct tree_buffer *t) |
| 36 | { |
| 37 | int i; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 38 | u32 nr; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 39 | struct node *c; |
| 40 | |
| 41 | if (!t) |
| 42 | return; |
| 43 | c = &t->node; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 44 | nr = btrfs_header_nritems(&c->header); |
| 45 | if (btrfs_is_leaf(c)) { |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 46 | print_leaf((struct leaf *)c); |
| 47 | return; |
| 48 | } |
Chris Mason | 41903fe | 2007-02-26 10:55:42 -0500 | [diff] [blame] | 49 | printf("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr, |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 50 | btrfs_header_level(&c->header), nr, |
| 51 | (u32)NODEPTRS_PER_BLOCK - nr); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 52 | fflush(stdout); |
| 53 | for (i = 0; i < nr; i++) { |
Chris Mason | 7cf7596 | 2007-02-26 10:55:01 -0500 | [diff] [blame] | 54 | printf("\tkey %d (%Lu %u %Lu) block %Lu\n", |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 55 | 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 Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 64 | if (btrfs_is_leaf(next) && |
| 65 | btrfs_header_level(&c->header) != 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 66 | BUG(); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 67 | if (btrfs_header_level(&next->header) != |
| 68 | btrfs_header_level(&c->header) - 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 69 | BUG(); |
| 70 | print_tree(root, next_buf); |
| 71 | tree_block_release(root, next_buf); |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |