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 | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame^] | 15 | struct btrfs_dir_item *di; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 16 | u32 type; |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame^] | 17 | u32 namelen; |
| 18 | |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 19 | printf("leaf %Lu total ptrs %d free space %d\n", |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 20 | btrfs_header_blocknr(&l->header), nr, |
| 21 | btrfs_leaf_free_space(root, l)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 22 | fflush(stdout); |
| 23 | for (i = 0 ; i < nr ; i++) { |
| 24 | item = l->items + i; |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 25 | type = btrfs_disk_key_type(&item->key); |
Chris Mason | a1516c8 | 2007-03-14 14:26:53 -0400 | [diff] [blame] | 26 | printf("\titem %d key (%Lu %Lu %u) itemoff %d itemsize %d\n", |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 27 | i, |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 28 | btrfs_disk_key_objectid(&item->key), |
| 29 | btrfs_disk_key_offset(&item->key), |
| 30 | btrfs_disk_key_flags(&item->key), |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 31 | btrfs_item_offset(item), |
| 32 | btrfs_item_size(item)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 33 | switch (type) { |
| 34 | case BTRFS_INODE_ITEM_KEY: |
| 35 | break; |
| 36 | case BTRFS_DIR_ITEM_KEY: |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame^] | 37 | namelen = btrfs_item_size(l->items + i) - sizeof(*di); |
| 38 | di = btrfs_item_ptr(l, i, struct btrfs_dir_item); |
| 39 | printf("\t\tdir oid %Lu flags %u type %u\n", |
| 40 | btrfs_dir_objectid(di), |
| 41 | btrfs_dir_flags(di), |
| 42 | btrfs_dir_type(di)); |
| 43 | printf("\t\tname %.*s\n", |
| 44 | namelen, (char *)(di + 1)); |
| 45 | |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 46 | break; |
| 47 | case BTRFS_ROOT_ITEM_KEY: |
| 48 | ri = btrfs_item_ptr(l, i, struct btrfs_root_item); |
| 49 | printf("\t\troot data blocknr %Lu refs %u\n", |
| 50 | btrfs_root_blocknr(ri), btrfs_root_refs(ri)); |
| 51 | break; |
| 52 | case BTRFS_EXTENT_ITEM_KEY: |
| 53 | ei = btrfs_item_ptr(l, i, struct btrfs_extent_item); |
| 54 | printf("\t\textent data refs %u owner %Lu\n", |
| 55 | btrfs_extent_refs(ei), btrfs_extent_owner(ei)); |
| 56 | break; |
| 57 | case BTRFS_STRING_ITEM_KEY: |
| 58 | printf("\t\titem data %.*s\n", btrfs_item_size(item), |
| 59 | btrfs_leaf_data(l) + btrfs_item_offset(item)); |
| 60 | break; |
| 61 | }; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 62 | fflush(stdout); |
| 63 | } |
| 64 | } |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 65 | void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 66 | { |
| 67 | int i; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 68 | u32 nr; |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 69 | struct btrfs_node *c; |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 70 | |
| 71 | if (!t) |
| 72 | return; |
| 73 | c = &t->node; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 74 | nr = btrfs_header_nritems(&c->header); |
| 75 | if (btrfs_is_leaf(c)) { |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 76 | btrfs_print_leaf(root, (struct btrfs_leaf *)c); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 77 | return; |
| 78 | } |
Chris Mason | 41903fe | 2007-02-26 10:55:42 -0500 | [diff] [blame] | 79 | 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] | 80 | btrfs_header_level(&c->header), nr, |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 81 | (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 82 | fflush(stdout); |
| 83 | for (i = 0; i < nr; i++) { |
Chris Mason | a1516c8 | 2007-03-14 14:26:53 -0400 | [diff] [blame] | 84 | printf("\tkey %d (%Lu %Lu %u) block %Lu\n", |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 85 | i, |
Chris Mason | a1516c8 | 2007-03-14 14:26:53 -0400 | [diff] [blame] | 86 | c->ptrs[i].key.objectid, |
| 87 | c->ptrs[i].key.offset, |
| 88 | c->ptrs[i].key.flags, |
| 89 | btrfs_node_blockptr(c, i)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 90 | fflush(stdout); |
| 91 | } |
| 92 | for (i = 0; i < nr; i++) { |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 93 | struct btrfs_buffer *next_buf = read_tree_block(root, |
Chris Mason | 1d4f8a0 | 2007-03-13 09:28:32 -0400 | [diff] [blame] | 94 | btrfs_node_blockptr(c, i)); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 95 | struct btrfs_node *next = &next_buf->node; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 96 | if (btrfs_is_leaf(next) && |
| 97 | btrfs_header_level(&c->header) != 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 98 | BUG(); |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 99 | if (btrfs_header_level(&next->header) != |
| 100 | btrfs_header_level(&c->header) - 1) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 101 | BUG(); |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 102 | btrfs_print_tree(root, next_buf); |
| 103 | btrfs_block_release(root, next_buf); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 104 | } |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 105 | } |
| 106 | |