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 | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 12 | struct item *item; |
| 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, |
| 21 | item->key.objectid, item->key.flags, item->key.offset, |
| 22 | item->offset, item->size); |
| 23 | fflush(stdout); |
Chris Mason | a28ec19 | 2007-03-06 20:08:01 -0500 | [diff] [blame] | 24 | printf("\t\titem data %.*s\n", item->size, |
| 25 | l->data+item->offset); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 26 | ei = (struct extent_item *)(l->data + item->offset); |
Chris Mason | a28ec19 | 2007-03-06 20:08:01 -0500 | [diff] [blame] | 27 | printf("\t\textent data refs %u owner %Lu\n", ei->refs, |
| 28 | ei->owner); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 29 | fflush(stdout); |
| 30 | } |
| 31 | } |
| 32 | void print_tree(struct ctree_root *root, struct tree_buffer *t) |
| 33 | { |
| 34 | int i; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame^] | 35 | u32 nr; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 36 | struct node *c; |
| 37 | |
| 38 | if (!t) |
| 39 | return; |
| 40 | c = &t->node; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame^] | 41 | nr = btrfs_header_nritems(&c->header); |
| 42 | if (btrfs_is_leaf(c)) { |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 43 | print_leaf((struct leaf *)c); |
| 44 | return; |
| 45 | } |
Chris Mason | 41903fe | 2007-02-26 10:55:42 -0500 | [diff] [blame] | 46 | 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^] | 47 | btrfs_header_level(&c->header), nr, |
| 48 | (u32)NODEPTRS_PER_BLOCK - nr); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 49 | fflush(stdout); |
| 50 | for (i = 0; i < nr; i++) { |
Chris Mason | 7cf7596 | 2007-02-26 10:55:01 -0500 | [diff] [blame] | 51 | printf("\tkey %d (%Lu %u %Lu) block %Lu\n", |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 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; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame^] | 61 | if (btrfs_is_leaf(next) && |
| 62 | btrfs_header_level(&c->header) != 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 63 | BUG(); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame^] | 64 | if (btrfs_header_level(&next->header) != |
| 65 | btrfs_header_level(&c->header) - 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 66 | BUG(); |
| 67 | print_tree(root, next_buf); |
| 68 | tree_block_release(root, next_buf); |
| 69 | } |
| 70 | |
| 71 | } |
| 72 | |