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