blob: 28813411de66bafacbfd999c03dbaa274c2d547f [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"
Chris Mason35b7e472007-05-02 15:53:43 -04004#include "print-tree.h"
Chris Mason5de08d72007-02-24 06:24:44 -05005
Chris Mason123abc82007-03-14 14:14:43 -04006void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
Chris Mason5de08d72007-02-24 06:24:44 -05007{
8 int i;
Chris Mason7518a232007-03-12 12:01:18 -04009 u32 nr = btrfs_header_nritems(&l->header);
Chris Mason0783fcf2007-03-12 20:12:07 -040010 struct btrfs_item *item;
Chris Mason234b63a2007-03-13 10:46:10 -040011 struct btrfs_extent_item *ei;
Chris Mason3768f362007-03-13 16:47:54 -040012 struct btrfs_root_item *ri;
Chris Mason1d4f6402007-03-15 15:18:43 -040013 struct btrfs_dir_item *di;
Chris Mason293ffd52007-03-20 15:57:25 -040014 struct btrfs_inode_item *ii;
Chris Mason9078a3e2007-04-26 16:46:15 -040015 struct btrfs_block_group_item *bi;
Chris Mason62e27492007-03-15 12:56:47 -040016 u32 type;
Chris Mason1d4f6402007-03-15 15:18:43 -040017
Chris Mason2e635a22007-03-21 11:12:56 -040018 printk("leaf %Lu total ptrs %d free space %d\n",
Chris Mason123abc82007-03-14 14:14:43 -040019 btrfs_header_blocknr(&l->header), nr,
20 btrfs_leaf_free_space(root, l));
Chris Mason5de08d72007-02-24 06:24:44 -050021 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 Masona429e512007-04-18 16:15:28 -040024 printk("\titem %d key (%Lu %x %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 Masond6e4a422007-04-06 15:37:36 -040042 btrfs_disk_key_objectid(&di->location),
Chris Mason1d4f6402007-03-15 15:18:43 -040043 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 Masond0dbc622007-04-10 12:36:36 -040055 printk("\t\textent data refs %u\n",
56 btrfs_extent_refs(ei));
Chris Mason62e27492007-03-15 12:56:47 -040057 break;
Chris Mason9078a3e2007-04-26 16:46:15 -040058 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 Mason62e27492007-03-15 12:56:47 -040064 case BTRFS_STRING_ITEM_KEY:
Chris Mason2e635a22007-03-21 11:12:56 -040065 printk("\t\titem data %.*s\n", btrfs_item_size(item),
Chris Mason62e27492007-03-15 12:56:47 -040066 btrfs_leaf_data(l) + btrfs_item_offset(item));
67 break;
68 };
Chris Mason5de08d72007-02-24 06:24:44 -050069 }
70}
Chris Masone20d96d2007-03-22 12:13:20 -040071
72void btrfs_print_tree(struct btrfs_root *root, struct buffer_head *t)
Chris Mason5de08d72007-02-24 06:24:44 -050073{
74 int i;
Chris Mason7518a232007-03-12 12:01:18 -040075 u32 nr;
Chris Mason234b63a2007-03-13 10:46:10 -040076 struct btrfs_node *c;
Chris Mason5de08d72007-02-24 06:24:44 -050077
78 if (!t)
79 return;
Chris Masone20d96d2007-03-22 12:13:20 -040080 c = btrfs_buffer_node(t);
Chris Mason7518a232007-03-12 12:01:18 -040081 nr = btrfs_header_nritems(&c->header);
82 if (btrfs_is_leaf(c)) {
Chris Mason123abc82007-03-14 14:14:43 -040083 btrfs_print_leaf(root, (struct btrfs_leaf *)c);
Chris Mason5de08d72007-02-24 06:24:44 -050084 return;
85 }
Chris Masone20d96d2007-03-22 12:13:20 -040086 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 Mason5de08d72007-02-24 06:24:44 -050090 for (i = 0; i < nr; i++) {
Chris Mason2e635a22007-03-21 11:12:56 -040091 printk("\tkey %d (%Lu %u %Lu) block %Lu\n",
Chris Mason5de08d72007-02-24 06:24:44 -050092 i,
Chris Masona1516c82007-03-14 14:26:53 -040093 c->ptrs[i].key.objectid,
Chris Masona1516c82007-03-14 14:26:53 -040094 c->ptrs[i].key.flags,
Chris Masona8a2ee02007-03-16 08:46:49 -040095 c->ptrs[i].key.offset,
Chris Masona1516c82007-03-14 14:26:53 -040096 btrfs_node_blockptr(c, i));
Chris Mason5de08d72007-02-24 06:24:44 -050097 }
98 for (i = 0; i < nr; i++) {
Chris Masone20d96d2007-03-22 12:13:20 -040099 struct buffer_head *next_buf = read_tree_block(root,
Chris Mason1d4f8a02007-03-13 09:28:32 -0400100 btrfs_node_blockptr(c, i));
Chris Masone20d96d2007-03-22 12:13:20 -0400101 struct btrfs_node *next = btrfs_buffer_node(next_buf);
Chris Mason7518a232007-03-12 12:01:18 -0400102 if (btrfs_is_leaf(next) &&
103 btrfs_header_level(&c->header) != 1)
Chris Mason5de08d72007-02-24 06:24:44 -0500104 BUG();
Chris Mason7518a232007-03-12 12:01:18 -0400105 if (btrfs_header_level(&next->header) !=
106 btrfs_header_level(&c->header) - 1)
Chris Mason5de08d72007-02-24 06:24:44 -0500107 BUG();
Chris Mason234b63a2007-03-13 10:46:10 -0400108 btrfs_print_tree(root, next_buf);
109 btrfs_block_release(root, next_buf);
Chris Mason5de08d72007-02-24 06:24:44 -0500110 }
Chris Mason5de08d72007-02-24 06:24:44 -0500111}
112