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 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 8 | void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 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 | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 13 | struct btrfs_extent_item *ei; |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 14 | struct btrfs_root_item *ri; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 15 | printf("leaf %Lu total ptrs %d free space %d\n", |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 16 | btrfs_header_blocknr(&l->header), nr, |
| 17 | btrfs_leaf_free_space(root, l)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 18 | fflush(stdout); |
| 19 | for (i = 0 ; i < nr ; i++) { |
| 20 | item = l->items + i; |
Chris Mason | a1516c8 | 2007-03-14 14:26:53 -0400 | [diff] [blame^] | 21 | printf("\titem %d key (%Lu %Lu %u) itemoff %d itemsize %d\n", |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 22 | i, |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 23 | btrfs_key_objectid(&item->key), |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 24 | btrfs_key_offset(&item->key), |
Chris Mason | a1516c8 | 2007-03-14 14:26:53 -0400 | [diff] [blame^] | 25 | btrfs_key_flags(&item->key), |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 26 | btrfs_item_offset(item), |
| 27 | btrfs_item_size(item)); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 28 | printf("\t\titem data %.*s\n", btrfs_item_size(item), |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 29 | btrfs_leaf_data(l) + btrfs_item_offset(item)); |
Chris Mason | 4beb1b8 | 2007-03-14 10:31:29 -0400 | [diff] [blame] | 30 | ei = btrfs_item_ptr(l, i, struct btrfs_extent_item); |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 31 | printf("\t\textent data refs %u owner %Lu\n", |
| 32 | btrfs_extent_refs(ei), btrfs_extent_owner(ei)); |
Chris Mason | 4beb1b8 | 2007-03-14 10:31:29 -0400 | [diff] [blame] | 33 | ri = btrfs_item_ptr(l, i, struct btrfs_root_item); |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 34 | printf("\t\troot data blocknr %Lu refs %u\n", |
| 35 | btrfs_root_blocknr(ri), btrfs_root_refs(ri)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 36 | fflush(stdout); |
| 37 | } |
| 38 | } |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 39 | void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 40 | { |
| 41 | int i; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 42 | u32 nr; |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 43 | struct btrfs_node *c; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 44 | |
| 45 | if (!t) |
| 46 | return; |
| 47 | c = &t->node; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 48 | nr = btrfs_header_nritems(&c->header); |
| 49 | if (btrfs_is_leaf(c)) { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 50 | btrfs_print_leaf(root, (struct btrfs_leaf *)c); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 51 | return; |
| 52 | } |
Chris Mason | 41903fe | 2007-02-26 10:55:42 -0500 | [diff] [blame] | 53 | 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] | 54 | btrfs_header_level(&c->header), nr, |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 55 | (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 56 | fflush(stdout); |
| 57 | for (i = 0; i < nr; i++) { |
Chris Mason | a1516c8 | 2007-03-14 14:26:53 -0400 | [diff] [blame^] | 58 | printf("\tkey %d (%Lu %Lu %u) block %Lu\n", |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 59 | i, |
Chris Mason | a1516c8 | 2007-03-14 14:26:53 -0400 | [diff] [blame^] | 60 | c->ptrs[i].key.objectid, |
| 61 | c->ptrs[i].key.offset, |
| 62 | c->ptrs[i].key.flags, |
| 63 | btrfs_node_blockptr(c, i)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 64 | fflush(stdout); |
| 65 | } |
| 66 | for (i = 0; i < nr; i++) { |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 67 | struct btrfs_buffer *next_buf = read_tree_block(root, |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 68 | btrfs_node_blockptr(c, i)); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 69 | struct btrfs_node *next = &next_buf->node; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 70 | if (btrfs_is_leaf(next) && |
| 71 | btrfs_header_level(&c->header) != 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 72 | BUG(); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 73 | if (btrfs_header_level(&next->header) != |
| 74 | btrfs_header_level(&c->header) - 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 75 | BUG(); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 76 | btrfs_print_tree(root, next_buf); |
| 77 | btrfs_block_release(root, next_buf); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 78 | } |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 79 | } |
| 80 | |