3 #include "kerncompat.h"
4 #include "radix-tree.h"
8 void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
11 u32 nr = btrfs_header_nritems(&l->header);
12 struct btrfs_item *item;
13 struct btrfs_extent_item *ei;
14 struct btrfs_root_item *ri;
15 struct btrfs_dir_item *di;
16 struct btrfs_inode_map_item *mi;
17 struct btrfs_inode_item *ii;
18 struct btrfs_file_extent_item *fi;
22 printf("leaf %Lu ptrs %d free space %d parent %Lu generation %Lu\n",
23 btrfs_header_blocknr(&l->header), nr,
24 btrfs_leaf_free_space(root, l),
25 btrfs_header_parentid(&l->header),
26 btrfs_header_generation(&l->header));
28 for (i = 0 ; i < nr ; i++) {
30 type = btrfs_disk_key_type(&item->key);
31 printf("\titem %d key (%Lu %Lu %u) itemoff %d itemsize %d\n",
33 btrfs_disk_key_objectid(&item->key),
34 btrfs_disk_key_offset(&item->key),
35 btrfs_disk_key_flags(&item->key),
36 btrfs_item_offset(item),
37 btrfs_item_size(item));
39 case BTRFS_INODE_ITEM_KEY:
40 ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
41 printf("\t\tinode generation %Lu size %Lu mode %o\n",
42 btrfs_inode_generation(ii),
44 btrfs_inode_mode(ii));
46 case BTRFS_INLINE_DATA_KEY:
47 p = btrfs_item_ptr(l, i, char);
48 printf("\t\tinline data %.*s\n", 10, p);
50 case BTRFS_DIR_ITEM_KEY:
51 di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
52 printf("\t\tdir oid %Lu flags %u type %u\n",
53 btrfs_disk_key_objectid(&di->location),
56 printf("\t\tname %.*s\n",
57 btrfs_dir_name_len(di),(char *)(di + 1));
59 case BTRFS_DIR_INDEX_KEY:
60 di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
61 printf("\t\tdir index %Lu flags %u type %u\n",
62 btrfs_disk_key_objectid(&di->location),
65 printf("\t\tname %.*s\n",
66 btrfs_dir_name_len(di),(char *)(di + 1));
68 case BTRFS_ROOT_ITEM_KEY:
69 ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
70 printf("\t\troot data blocknr %Lu dirid %Lu refs %u\n",
71 btrfs_root_blocknr(ri),
75 case BTRFS_EXTENT_ITEM_KEY:
76 ei = btrfs_item_ptr(l, i, struct btrfs_extent_item);
77 printf("\t\textent data refs %u owner %Lu\n",
78 btrfs_extent_refs(ei), btrfs_extent_owner(ei));
80 case BTRFS_INODE_MAP_ITEM_KEY:
81 mi = btrfs_item_ptr(l, i, struct btrfs_inode_map_item);
82 printf("\t\tinode map key %Lu %Lu %u\n",
83 btrfs_disk_key_objectid(&mi->key),
84 btrfs_disk_key_offset(&mi->key),
85 btrfs_disk_key_flags(&mi->key));
87 case BTRFS_EXTENT_DATA_KEY:
88 fi = btrfs_item_ptr(l, i,
89 struct btrfs_file_extent_item);
90 printf("\t\textent data disk block %Lu nr %Lu\n",
91 btrfs_file_extent_disk_blocknr(fi),
92 btrfs_file_extent_disk_num_blocks(fi));
93 printf("\t\textent data offset %Lu nr %Lu\n",
94 btrfs_file_extent_offset(fi),
95 btrfs_file_extent_num_blocks(fi));
97 case BTRFS_STRING_ITEM_KEY:
98 printf("\t\titem data %.*s\n", btrfs_item_size(item),
99 btrfs_leaf_data(l) + btrfs_item_offset(item));
105 void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
109 struct btrfs_node *c;
114 nr = btrfs_header_nritems(&c->header);
115 if (btrfs_is_leaf(c)) {
116 btrfs_print_leaf(root, (struct btrfs_leaf *)c);
119 printf("node %Lu level %d ptrs %d free %u parent %Lu generation %Lu\n",
121 btrfs_header_level(&c->header), nr,
122 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
123 btrfs_header_parentid(&c->header),
124 btrfs_header_generation(&c->header));
126 for (i = 0; i < nr; i++) {
127 printf("\tkey %d (%Lu %u %Lu) block %Lu\n",
129 c->ptrs[i].key.objectid,
130 c->ptrs[i].key.flags,
131 c->ptrs[i].key.offset,
132 btrfs_node_blockptr(c, i));
135 for (i = 0; i < nr; i++) {
136 struct btrfs_buffer *next_buf = read_tree_block(root,
137 btrfs_node_blockptr(c, i));
138 struct btrfs_node *next = &next_buf->node;
139 if (btrfs_is_leaf(next) &&
140 btrfs_header_level(&c->header) != 1)
142 if (btrfs_header_level(&next->header) !=
143 btrfs_header_level(&c->header) - 1)
145 btrfs_print_tree(root, next_buf);
146 btrfs_block_release(root, next_buf);