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_device_item *devi;
17 struct btrfs_inode_item *ii;
18 struct btrfs_file_extent_item *fi;
19 struct btrfs_csum_item *ci;
23 printf("leaf %Lu ptrs %d free space %d generation %Lu\n",
24 btrfs_header_blocknr(&l->header), nr,
25 btrfs_leaf_free_space(root, l),
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 %u %Lu) itemoff %d itemsize %d\n",
33 btrfs_disk_key_objectid(&item->key),
34 btrfs_disk_key_flags(&item->key),
35 btrfs_disk_key_offset(&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\n",
78 btrfs_extent_refs(ei));
80 case BTRFS_CSUM_ITEM_KEY:
81 ci = btrfs_item_ptr(l, i,
82 struct btrfs_csum_item);
83 printf("\t\tcsum item\n");
85 case BTRFS_EXTENT_DATA_KEY:
86 fi = btrfs_item_ptr(l, i,
87 struct btrfs_file_extent_item);
88 printf("\t\textent data disk block %Lu nr %Lu\n",
89 btrfs_file_extent_disk_blocknr(fi),
90 btrfs_file_extent_disk_num_blocks(fi));
91 printf("\t\textent data offset %Lu nr %Lu\n",
92 btrfs_file_extent_offset(fi),
93 btrfs_file_extent_num_blocks(fi));
95 case BTRFS_DEV_ITEM_KEY:
96 devi = btrfs_item_ptr(l, i, struct btrfs_device_item);
97 printf("\t\tdev id %Lu namelen %u name %.*s\n",
98 btrfs_device_id(devi),
99 btrfs_device_pathlen(devi),
100 btrfs_device_pathlen(devi),
103 case BTRFS_STRING_ITEM_KEY:
104 printf("\t\titem data %.*s\n", btrfs_item_size(item),
105 btrfs_leaf_data(l) + btrfs_item_offset(item));
111 void btrfs_print_tree(struct btrfs_root *root, struct btrfs_buffer *t)
115 struct btrfs_node *c;
120 nr = btrfs_header_nritems(&c->header);
121 if (btrfs_is_leaf(c)) {
122 btrfs_print_leaf(root, (struct btrfs_leaf *)c);
125 printf("node %Lu level %d ptrs %d free %u generation %Lu\n",
127 btrfs_header_level(&c->header), nr,
128 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
129 btrfs_header_generation(&c->header));
131 for (i = 0; i < nr; i++) {
132 printf("\tkey %d (%Lu %u %Lu) block %Lu\n",
134 c->ptrs[i].key.objectid,
135 c->ptrs[i].key.flags,
136 c->ptrs[i].key.offset,
137 btrfs_node_blockptr(c, i));
140 for (i = 0; i < nr; i++) {
141 struct btrfs_buffer *next_buf = read_tree_block(root,
142 btrfs_node_blockptr(c, i));
143 struct btrfs_node *next = &next_buf->node;
144 if (btrfs_is_leaf(next) &&
145 btrfs_header_level(&c->header) != 1)
147 if (btrfs_header_level(&next->header) !=
148 btrfs_header_level(&c->header) - 1)
150 btrfs_print_tree(root, next_buf);
151 btrfs_block_release(root, next_buf);