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