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