4 #include "kerncompat.h"
5 #include "radix-tree.h"
8 #include "print-tree.h"
9 #include "transaction.h"
11 int main(int ac
, char **av
) {
12 struct btrfs_super_block super
;
13 struct btrfs_root
*root
;
14 struct btrfs_path path
;
16 struct btrfs_root_item
*ri
;
17 struct btrfs_leaf
*leaf
;
18 struct btrfs_key found_key
;
24 fprintf(stderr
, "usage: %s device\n", av
[0]);
28 root
= open_ctree(av
[1], &super
);
30 fprintf(stderr
, "unable to open %s\n", av
[1]);
33 printf("root tree\n");
34 btrfs_print_tree(root
->fs_info
->tree_root
,
35 root
->fs_info
->tree_root
->node
);
37 btrfs_print_tree(root
->fs_info
->dev_root
,
38 root
->fs_info
->dev_root
->node
);
39 btrfs_init_path(&path
);
43 btrfs_set_key_type(&key
, BTRFS_ROOT_ITEM_KEY
);
44 ret
= btrfs_search_slot(NULL
, root
->fs_info
->tree_root
,
48 leaf
= &path
.nodes
[0]->leaf
;
50 if (slot
>= btrfs_header_nritems(&leaf
->header
)) {
51 ret
= btrfs_next_leaf(root
, &path
);
54 leaf
= &path
.nodes
[0]->leaf
;
57 btrfs_disk_key_to_cpu(&found_key
,
58 &leaf
->items
[path
.slots
[0]].key
);
59 if (btrfs_key_type(&found_key
) == BTRFS_ROOT_ITEM_KEY
) {
60 struct btrfs_buffer
*buf
;
61 ri
= btrfs_item_ptr(leaf
, path
.slots
[0],
62 struct btrfs_root_item
);
63 buf
= read_tree_block(root
->fs_info
->tree_root
,
64 btrfs_root_blocknr(ri
));
65 switch(found_key
.objectid
) {
66 case BTRFS_ROOT_TREE_OBJECTID
:
69 case BTRFS_DEV_TREE_OBJECTID
:
72 case BTRFS_EXTENT_TREE_OBJECTID
:
73 printf("extent tree ");
76 printf("tree %Lu %Lu %u\n", found_key
.objectid
,
77 found_key
.offset
, found_key
.flags
);
78 btrfs_print_tree(root
, buf
);
82 btrfs_release_path(root
, &path
);
83 printf("total blocks %Lu\n", btrfs_super_total_blocks(&super
));
84 printf("blocks used %Lu\n", btrfs_super_blocks_used(&super
));
86 uuid_unparse(super
.fsid
, uuidbuf
);
87 printf("uuid %s\n", uuidbuf
);