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
;
21 printf("leaf %Lu ptrs %d free space %d parent %Lu generation %Lu\n",
22 btrfs_header_blocknr(&l
->header
), nr
,
23 btrfs_leaf_free_space(root
, l
),
24 btrfs_header_parentid(&l
->header
),
25 btrfs_header_generation(&l
->header
));
27 for (i
= 0 ; i
< nr
; i
++) {
29 type
= btrfs_disk_key_type(&item
->key
);
30 printf("\titem %d key (%Lu %u %Lu) itemoff %d itemsize %d\n",
32 btrfs_disk_key_objectid(&item
->key
),
33 btrfs_disk_key_flags(&item
->key
),
34 btrfs_disk_key_offset(&item
->key
),
35 btrfs_item_offset(item
),
36 btrfs_item_size(item
));
38 case BTRFS_INODE_ITEM_KEY
:
39 ii
= btrfs_item_ptr(l
, i
, struct btrfs_inode_item
);
40 printf("\t\tinode generation %Lu size %Lu mode %o\n",
41 btrfs_inode_generation(ii
),
43 btrfs_inode_mode(ii
));
45 case BTRFS_DIR_ITEM_KEY
:
46 di
= btrfs_item_ptr(l
, i
, struct btrfs_dir_item
);
47 printf("\t\tdir oid %Lu flags %u type %u\n",
48 btrfs_dir_objectid(di
),
51 printf("\t\tname %.*s\n",
52 btrfs_dir_name_len(di
),(char *)(di
+ 1));
54 case BTRFS_ROOT_ITEM_KEY
:
55 ri
= btrfs_item_ptr(l
, i
, struct btrfs_root_item
);
56 printf("\t\troot data blocknr %Lu refs %u\n",
57 btrfs_root_blocknr(ri
), btrfs_root_refs(ri
));
59 case BTRFS_EXTENT_ITEM_KEY
:
60 ei
= btrfs_item_ptr(l
, i
, struct btrfs_extent_item
);
61 printf("\t\textent data refs %u owner %Lu\n",
62 btrfs_extent_refs(ei
), btrfs_extent_owner(ei
));
64 case BTRFS_INODE_MAP_ITEM_KEY
:
65 mi
= btrfs_item_ptr(l
, i
, struct btrfs_inode_map_item
);
66 printf("\t\tinode map key %Lu %u %Lu\n",
67 btrfs_disk_key_objectid(&mi
->key
),
68 btrfs_disk_key_flags(&mi
->key
),
69 btrfs_disk_key_offset(&mi
->key
));
71 case BTRFS_EXTENT_DATA_KEY
:
72 fi
= btrfs_item_ptr(l
, i
,
73 struct btrfs_file_extent_item
);
74 printf("\t\textent data disk block %Lu nr %Lu\n",
75 btrfs_file_extent_disk_blocknr(fi
),
76 btrfs_file_extent_disk_num_blocks(fi
));
77 printf("\t\textent data offset %Lu nr %Lu\n",
78 btrfs_file_extent_offset(fi
),
79 btrfs_file_extent_num_blocks(fi
));
81 case BTRFS_STRING_ITEM_KEY
:
82 printf("\t\titem data %.*s\n", btrfs_item_size(item
),
83 btrfs_leaf_data(l
) + btrfs_item_offset(item
));
89 void btrfs_print_tree(struct btrfs_root
*root
, struct btrfs_buffer
*t
)
98 nr
= btrfs_header_nritems(&c
->header
);
99 if (btrfs_is_leaf(c
)) {
100 btrfs_print_leaf(root
, (struct btrfs_leaf
*)c
);
103 printf("node %Lu level %d ptrs %d free %u parent %Lu generation %Lu\n",
105 btrfs_header_level(&c
->header
), nr
,
106 (u32
)BTRFS_NODEPTRS_PER_BLOCK(root
) - nr
,
107 btrfs_header_parentid(&c
->header
),
108 btrfs_header_generation(&c
->header
));
110 for (i
= 0; i
< nr
; i
++) {
111 printf("\tkey %d (%Lu %u %Lu) block %Lu\n",
113 c
->ptrs
[i
].key
.objectid
,
114 c
->ptrs
[i
].key
.flags
,
115 c
->ptrs
[i
].key
.offset
,
116 btrfs_node_blockptr(c
, i
));
119 for (i
= 0; i
< nr
; i
++) {
120 struct btrfs_buffer
*next_buf
= read_tree_block(root
,
121 btrfs_node_blockptr(c
, i
));
122 struct btrfs_node
*next
= &next_buf
->node
;
123 if (btrfs_is_leaf(next
) &&
124 btrfs_header_level(&c
->header
) != 1)
126 if (btrfs_header_level(&next
->header
) !=
127 btrfs_header_level(&c
->header
) - 1)
129 btrfs_print_tree(root
, next_buf
);
130 btrfs_block_release(root
, next_buf
);