blob: aa2d3fac8804852ffb8d9dc05b4f807a3aea8cc8 [file] [log] [blame]
Chris Mason2e635a22007-03-21 11:12:56 -04001#include <linux/module.h>
Chris Mason5de08d72007-02-24 06:24:44 -05002#include "ctree.h"
3#include "disk-io.h"
4
Chris Mason123abc82007-03-14 14:14:43 -04005void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
Chris Mason5de08d72007-02-24 06:24:44 -05006{
7 int i;
Chris Mason7518a232007-03-12 12:01:18 -04008 u32 nr = btrfs_header_nritems(&l->header);
Chris Mason0783fcf2007-03-12 20:12:07 -04009 struct btrfs_item *item;
Chris Mason234b63a2007-03-13 10:46:10 -040010 struct btrfs_extent_item *ei;
Chris Mason3768f362007-03-13 16:47:54 -040011 struct btrfs_root_item *ri;
Chris Mason1d4f6402007-03-15 15:18:43 -040012 struct btrfs_dir_item *di;
Chris Mason9f5fae22007-03-20 14:38:32 -040013 struct btrfs_inode_map_item *mi;
Chris Mason293ffd52007-03-20 15:57:25 -040014 struct btrfs_inode_item *ii;
Chris Mason62e27492007-03-15 12:56:47 -040015 u32 type;
Chris Mason1d4f6402007-03-15 15:18:43 -040016
Chris Mason2e635a22007-03-21 11:12:56 -040017 printk("leaf %Lu total ptrs %d free space %d\n",
Chris Mason123abc82007-03-14 14:14:43 -040018 btrfs_header_blocknr(&l->header), nr,
19 btrfs_leaf_free_space(root, l));
Chris Mason5de08d72007-02-24 06:24:44 -050020 fflush(stdout);
21 for (i = 0 ; i < nr ; i++) {
22 item = l->items + i;
Chris Mason62e27492007-03-15 12:56:47 -040023 type = btrfs_disk_key_type(&item->key);
Chris Mason2e635a22007-03-21 11:12:56 -040024 printk("\titem %d key (%Lu %u %Lu) itemoff %d itemsize %d\n",
Chris Mason5de08d72007-02-24 06:24:44 -050025 i,
Chris Mason62e27492007-03-15 12:56:47 -040026 btrfs_disk_key_objectid(&item->key),
Chris Mason62e27492007-03-15 12:56:47 -040027 btrfs_disk_key_flags(&item->key),
Chris Masona8a2ee02007-03-16 08:46:49 -040028 btrfs_disk_key_offset(&item->key),
Chris Mason0783fcf2007-03-12 20:12:07 -040029 btrfs_item_offset(item),
30 btrfs_item_size(item));
Chris Mason62e27492007-03-15 12:56:47 -040031 switch (type) {
32 case BTRFS_INODE_ITEM_KEY:
Chris Mason293ffd52007-03-20 15:57:25 -040033 ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
Chris Mason2e635a22007-03-21 11:12:56 -040034 printk("\t\tinode generation %Lu size %Lu mode %o\n",
Chris Mason293ffd52007-03-20 15:57:25 -040035 btrfs_inode_generation(ii),
Chris Mason2e635a22007-03-21 11:12:56 -040036 btrfs_inode_size(ii),
37 btrfs_inode_mode(ii));
Chris Mason62e27492007-03-15 12:56:47 -040038 break;
39 case BTRFS_DIR_ITEM_KEY:
Chris Mason1d4f6402007-03-15 15:18:43 -040040 di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
Chris Mason2e635a22007-03-21 11:12:56 -040041 printk("\t\tdir oid %Lu flags %u type %u\n",
Chris Mason1d4f6402007-03-15 15:18:43 -040042 btrfs_dir_objectid(di),
43 btrfs_dir_flags(di),
44 btrfs_dir_type(di));
Chris Mason2e635a22007-03-21 11:12:56 -040045 printk("\t\tname %.*s\n",
Chris Mason9f5fae22007-03-20 14:38:32 -040046 btrfs_dir_name_len(di),(char *)(di + 1));
Chris Mason62e27492007-03-15 12:56:47 -040047 break;
48 case BTRFS_ROOT_ITEM_KEY:
49 ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
Chris Mason2e635a22007-03-21 11:12:56 -040050 printk("\t\troot data blocknr %Lu refs %u\n",
Chris Mason62e27492007-03-15 12:56:47 -040051 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 Mason2e635a22007-03-21 11:12:56 -040055 printk("\t\textent data refs %u owner %Lu\n",
Chris Mason62e27492007-03-15 12:56:47 -040056 btrfs_extent_refs(ei), btrfs_extent_owner(ei));
57 break;
Chris Mason9f5fae22007-03-20 14:38:32 -040058 case BTRFS_INODE_MAP_ITEM_KEY:
59 mi = btrfs_item_ptr(l, i, struct btrfs_inode_map_item);
Chris Mason2e635a22007-03-21 11:12:56 -040060 printk("\t\tinode map key %Lu %u %Lu\n",
Chris Mason9f5fae22007-03-20 14:38:32 -040061 btrfs_disk_key_objectid(&mi->key),
62 btrfs_disk_key_flags(&mi->key),
63 btrfs_disk_key_offset(&mi->key));
64 break;
Chris Mason62e27492007-03-15 12:56:47 -040065 case BTRFS_STRING_ITEM_KEY:
Chris Mason2e635a22007-03-21 11:12:56 -040066 printk("\t\titem data %.*s\n", btrfs_item_size(item),
Chris Mason62e27492007-03-15 12:56:47 -040067 btrfs_leaf_data(l) + btrfs_item_offset(item));
68 break;
69 };
Chris Mason5de08d72007-02-24 06:24:44 -050070 fflush(stdout);
71 }
72}
Chris Mason234b63a2007-03-13 10:46:10 -040073void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
Chris Mason5de08d72007-02-24 06:24:44 -050074{
75 int i;
Chris Mason7518a232007-03-12 12:01:18 -040076 u32 nr;
Chris Mason234b63a2007-03-13 10:46:10 -040077 struct btrfs_node *c;
Chris Mason5de08d72007-02-24 06:24:44 -050078
79 if (!t)
80 return;
81 c = &t->node;
Chris Mason7518a232007-03-12 12:01:18 -040082 nr = btrfs_header_nritems(&c->header);
83 if (btrfs_is_leaf(c)) {
Chris Mason123abc82007-03-14 14:14:43 -040084 btrfs_print_leaf(root, (struct btrfs_leaf *)c);
Chris Mason5de08d72007-02-24 06:24:44 -050085 return;
86 }
Chris Mason2e635a22007-03-21 11:12:56 -040087 printk("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr,
Chris Mason7518a232007-03-12 12:01:18 -040088 btrfs_header_level(&c->header), nr,
Chris Mason123abc82007-03-14 14:14:43 -040089 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr);
Chris Mason5de08d72007-02-24 06:24:44 -050090 fflush(stdout);
91 for (i = 0; i < nr; i++) {
Chris Mason2e635a22007-03-21 11:12:56 -040092 printk("\tkey %d (%Lu %u %Lu) block %Lu\n",
Chris Mason5de08d72007-02-24 06:24:44 -050093 i,
Chris Masona1516c82007-03-14 14:26:53 -040094 c->ptrs[i].key.objectid,
Chris Masona1516c82007-03-14 14:26:53 -040095 c->ptrs[i].key.flags,
Chris Masona8a2ee02007-03-16 08:46:49 -040096 c->ptrs[i].key.offset,
Chris Masona1516c82007-03-14 14:26:53 -040097 btrfs_node_blockptr(c, i));
Chris Mason5de08d72007-02-24 06:24:44 -050098 fflush(stdout);
99 }
100 for (i = 0; i < nr; i++) {
Chris Mason234b63a2007-03-13 10:46:10 -0400101 struct btrfs_buffer *next_buf = read_tree_block(root,
Chris Mason1d4f8a02007-03-13 09:28:32 -0400102 btrfs_node_blockptr(c, i));
Chris Mason234b63a2007-03-13 10:46:10 -0400103 struct btrfs_node *next = &next_buf->node;
Chris Mason7518a232007-03-12 12:01:18 -0400104 if (btrfs_is_leaf(next) &&
105 btrfs_header_level(&c->header) != 1)
Chris Mason5de08d72007-02-24 06:24:44 -0500106 BUG();
Chris Mason7518a232007-03-12 12:01:18 -0400107 if (btrfs_header_level(&next->header) !=
108 btrfs_header_level(&c->header) - 1)
Chris Mason5de08d72007-02-24 06:24:44 -0500109 BUG();
Chris Mason234b63a2007-03-13 10:46:10 -0400110 btrfs_print_tree(root, next_buf);
111 btrfs_block_release(root, next_buf);
Chris Mason5de08d72007-02-24 06:24:44 -0500112 }
Chris Mason5de08d72007-02-24 06:24:44 -0500113}
114