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" |
Chris Mason | 35b7e47 | 2007-05-02 15:53:43 -0400 | [diff] [blame^] | 4 | #include "print-tree.h" |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 5 | |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 6 | void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l) |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 7 | { |
| 8 | int i; |
Chris Mason | 7518a23 | 2007-03-12 12:01:18 -0400 | [diff] [blame] | 9 | u32 nr = btrfs_header_nritems(&l->header); |
Chris Mason | 0783fcf | 2007-03-12 20:12:07 -0400 | [diff] [blame] | 10 | struct btrfs_item *item; |
Chris Mason | 234b63a | 2007-03-13 10:46:10 -0400 | [diff] [blame] | 11 | struct btrfs_extent_item *ei; |
Chris Mason | 3768f36 | 2007-03-13 16:47:54 -0400 | [diff] [blame] | 12 | struct btrfs_root_item *ri; |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 13 | struct btrfs_dir_item *di; |
Chris Mason | 293ffd5 | 2007-03-20 15:57:25 -0400 | [diff] [blame] | 14 | struct btrfs_inode_item *ii; |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 15 | struct btrfs_block_group_item *bi; |
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 | |
Chris Mason | 2e635a2 | 2007-03-21 11:12:56 -0400 | [diff] [blame] | 18 | printk("leaf %Lu total ptrs %d free space %d\n", |
Chris Mason | 123abc8 | 2007-03-14 14:14:43 -0400 | [diff] [blame] | 19 | btrfs_header_blocknr(&l->header), nr, |
| 20 | btrfs_leaf_free_space(root, l)); |
Chris Mason | 5de08d7 | 2007-02-24 06:24:44 -0500 | [diff] [blame] | 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 | a429e51 | 2007-04-18 16:15:28 -0400 | [diff] [blame] | 24 | printk("\titem %d key (%Lu %x %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 | d6e4a42 | 2007-04-06 15:37:36 -0400 | [diff] [blame] | 42 | btrfs_disk_key_objectid(&di->location), |
Chris Mason | 1d4f640 | 2007-03-15 15:18:43 -0400 | [diff] [blame] | 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 | d0dbc62 | 2007-04-10 12:36:36 -0400 | [diff] [blame] | 55 | printk("\t\textent data refs %u\n", |
| 56 | btrfs_extent_refs(ei)); |
Chris Mason | 62e2749 | 2007-03-15 12:56:47 -0400 | [diff] [blame] | 57 | break; |
Chris Mason | 9078a3e | 2007-04-26 16:46:15 -0400 | [diff] [blame] | 58 | case BTRFS_BLOCK_GROUP_ITEM_KEY: |
| 59 | bi = btrfs_item_ptr(l, i, |
| 60 | struct btrfs_block_group_item); |
| 61 | printk("\t\tblock group used %Lu\n", |
| 62 | btrfs_block_group_used(bi)); |
| 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 | |