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;
19 printf("leaf %Lu total ptrs %d free space %d\n",
20 btrfs_header_blocknr(&l->header), nr,
21 btrfs_leaf_free_space(root, l));
23 for (i = 0 ; i < nr ; i++) {
25 type = btrfs_disk_key_type(&item->key);
26 printf("\titem %d key (%Lu %Lu %u) itemoff %d itemsize %d\n",
28 btrfs_disk_key_objectid(&item->key),
29 btrfs_disk_key_offset(&item->key),
30 btrfs_disk_key_flags(&item->key),
31 btrfs_item_offset(item),
32 btrfs_item_size(item));
34 case BTRFS_INODE_ITEM_KEY:
36 case BTRFS_DIR_ITEM_KEY:
37 namelen = btrfs_item_size(l->items + i) - sizeof(*di);
38 di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
39 printf("\t\tdir oid %Lu flags %u type %u\n",
40 btrfs_dir_objectid(di),
43 printf("\t\tname %.*s\n",
44 namelen, (char *)(di + 1));
47 case BTRFS_ROOT_ITEM_KEY:
48 ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
49 printf("\t\troot data blocknr %Lu refs %u\n",
50 btrfs_root_blocknr(ri), btrfs_root_refs(ri));
52 case BTRFS_EXTENT_ITEM_KEY:
53 ei = btrfs_item_ptr(l, i, struct btrfs_extent_item);
54 printf("\t\textent data refs %u owner %Lu\n",
55 btrfs_extent_refs(ei), btrfs_extent_owner(ei));
57 case BTRFS_STRING_ITEM_KEY:
58 printf("\t\titem data %.*s\n", btrfs_item_size(item),
59 btrfs_leaf_data(l) + btrfs_item_offset(item));
65 void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
74 nr = btrfs_header_nritems(&c->header);
75 if (btrfs_is_leaf(c)) {
76 btrfs_print_leaf(root, (struct btrfs_leaf *)c);
79 printf("node %Lu level %d total ptrs %d free spc %u\n", t->blocknr,
80 btrfs_header_level(&c->header), nr,
81 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr);
83 for (i = 0; i < nr; i++) {
84 printf("\tkey %d (%Lu %Lu %u) block %Lu\n",
86 c->ptrs[i].key.objectid,
87 c->ptrs[i].key.offset,
89 btrfs_node_blockptr(c, i));
92 for (i = 0; i < nr; i++) {
93 struct btrfs_buffer *next_buf = read_tree_block(root,
94 btrfs_node_blockptr(c, i));
95 struct btrfs_node *next = &next_buf->node;
96 if (btrfs_is_leaf(next) &&
97 btrfs_header_level(&c->header) != 1)
99 if (btrfs_header_level(&next->header) !=
100 btrfs_header_level(&c->header) - 1)
102 btrfs_print_tree(root, next_buf);
103 btrfs_block_release(root, next_buf);