3 #include "kerncompat.h"
4 #include "radix-tree.h"
8 static int print_dir_item(struct btrfs_item
*item
,
9 struct btrfs_dir_item
*di
)
14 total
= btrfs_item_size(item
);
16 printf("\t\tdir index %Lu flags %u type %u\n",
17 btrfs_disk_key_objectid(&di
->location
),
20 printf("\t\tname %.*s\n",
21 btrfs_dir_name_len(di
),(char *)(di
+ 1));
22 len
= sizeof(*di
) + btrfs_dir_name_len(di
);
23 di
= (struct btrfs_dir_item
*)((char *)di
+ len
);
28 void btrfs_print_leaf(struct btrfs_root
*root
, struct btrfs_leaf
*l
)
31 u32 nr
= btrfs_header_nritems(&l
->header
);
32 struct btrfs_item
*item
;
33 struct btrfs_extent_item
*ei
;
34 struct btrfs_root_item
*ri
;
35 struct btrfs_dir_item
*di
;
36 struct btrfs_device_item
*devi
;
37 struct btrfs_inode_item
*ii
;
38 struct btrfs_file_extent_item
*fi
;
39 struct btrfs_csum_item
*ci
;
40 struct btrfs_block_group_item
*bi
;
43 printf("leaf %Lu ptrs %d free space %d generation %Lu owner %Lu\n",
44 btrfs_header_blocknr(&l
->header
), nr
,
45 btrfs_leaf_free_space(root
, l
),
46 btrfs_header_generation(&l
->header
),
47 btrfs_header_owner(&l
->header
));
49 for (i
= 0 ; i
< nr
; i
++) {
51 type
= btrfs_disk_key_type(&item
->key
);
52 printf("\titem %d key (%Lu %x %Lu) itemoff %d itemsize %d\n",
54 btrfs_disk_key_objectid(&item
->key
),
55 btrfs_disk_key_flags(&item
->key
),
56 btrfs_disk_key_offset(&item
->key
),
57 btrfs_item_offset(item
),
58 btrfs_item_size(item
));
60 case BTRFS_INODE_ITEM_KEY
:
61 ii
= btrfs_item_ptr(l
, i
, struct btrfs_inode_item
);
62 printf("\t\tinode generation %Lu size %Lu block group %Lu mode %o\n",
63 btrfs_inode_generation(ii
),
65 btrfs_inode_block_group(ii
),
66 btrfs_inode_mode(ii
));
68 case BTRFS_DIR_ITEM_KEY
:
69 di
= btrfs_item_ptr(l
, i
, struct btrfs_dir_item
);
70 print_dir_item(l
->items
+ i
, di
);
72 case BTRFS_DIR_INDEX_KEY
:
73 di
= btrfs_item_ptr(l
, i
, struct btrfs_dir_item
);
74 print_dir_item(l
->items
+ i
, di
);
76 case BTRFS_ROOT_ITEM_KEY
:
77 ri
= btrfs_item_ptr(l
, i
, struct btrfs_root_item
);
78 printf("\t\troot data blocknr %Lu dirid %Lu refs %u\n",
79 btrfs_root_blocknr(ri
),
83 case BTRFS_EXTENT_ITEM_KEY
:
84 ei
= btrfs_item_ptr(l
, i
, struct btrfs_extent_item
);
85 printf("\t\textent data refs %u owner %Lu\n",
86 btrfs_extent_refs(ei
),
87 btrfs_extent_owner(ei
));
89 case BTRFS_CSUM_ITEM_KEY
:
90 ci
= btrfs_item_ptr(l
, i
,
91 struct btrfs_csum_item
);
92 printf("\t\tcsum item\n");
94 case BTRFS_EXTENT_DATA_KEY
:
95 fi
= btrfs_item_ptr(l
, i
,
96 struct btrfs_file_extent_item
);
97 if (btrfs_file_extent_type(fi
) ==
98 BTRFS_FILE_EXTENT_INLINE
) {
99 printf("\t\tinline extent data size %u\n",
100 btrfs_file_extent_inline_len(l
->items
+ i
));
103 printf("\t\textent data disk block %Lu nr %Lu\n",
104 btrfs_file_extent_disk_blocknr(fi
),
105 btrfs_file_extent_disk_num_blocks(fi
));
106 printf("\t\textent data offset %Lu nr %Lu\n",
107 btrfs_file_extent_offset(fi
),
108 btrfs_file_extent_num_blocks(fi
));
110 case BTRFS_BLOCK_GROUP_ITEM_KEY
:
111 bi
= btrfs_item_ptr(l
, i
,
112 struct btrfs_block_group_item
);
113 printf("\t\tblock group used %Lu flags %x\n",
114 btrfs_block_group_used(bi
), bi
->flags
);
116 case BTRFS_DEV_ITEM_KEY
:
117 devi
= btrfs_item_ptr(l
, i
, struct btrfs_device_item
);
118 printf("\t\tdev id %Lu namelen %u name %.*s\n",
119 btrfs_device_id(devi
),
120 btrfs_device_pathlen(devi
),
121 btrfs_device_pathlen(devi
),
124 case BTRFS_STRING_ITEM_KEY
:
125 printf("\t\titem data %.*s\n", btrfs_item_size(item
),
126 btrfs_leaf_data(l
) + btrfs_item_offset(item
));
132 void btrfs_print_tree(struct btrfs_root
*root
, struct btrfs_buffer
*t
)
136 struct btrfs_node
*c
;
141 nr
= btrfs_header_nritems(&c
->header
);
142 if (btrfs_is_leaf(c
)) {
143 btrfs_print_leaf(root
, (struct btrfs_leaf
*)c
);
146 printf("node %Lu level %d ptrs %d free %u generation %Lu owner %Lu\n",
148 btrfs_header_level(&c
->header
), nr
,
149 (u32
)BTRFS_NODEPTRS_PER_BLOCK(root
) - nr
,
150 btrfs_header_generation(&c
->header
),
151 btrfs_header_owner(&c
->header
));
153 for (i
= 0; i
< nr
; i
++) {
154 printf("\tkey %d (%Lu %x %Lu) block %Lu\n",
156 c
->ptrs
[i
].key
.objectid
,
157 c
->ptrs
[i
].key
.flags
,
158 c
->ptrs
[i
].key
.offset
,
159 btrfs_node_blockptr(c
, i
));
162 for (i
= 0; i
< nr
; i
++) {
163 struct btrfs_buffer
*next_buf
= read_tree_block(root
,
164 btrfs_node_blockptr(c
, i
));
165 struct btrfs_node
*next
= &next_buf
->node
;
166 if (btrfs_is_leaf(next
) &&
167 btrfs_header_level(&c
->header
) != 1)
169 if (btrfs_header_level(&next
->header
) !=
170 btrfs_header_level(&c
->header
) - 1)
172 btrfs_print_tree(root
, next_buf
);
173 btrfs_block_release(root
, next_buf
);