remove device tree
[btrfs-progs-unstable.git] / debug-tree.c
blob9699e3c434bb8e36ac9a97d38b1b4621b0ce23b3
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <uuid/uuid.h>
4 #include "kerncompat.h"
5 #include "radix-tree.h"
6 #include "ctree.h"
7 #include "disk-io.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;
15 struct btrfs_key key;
16 struct btrfs_root_item *ri;
17 struct btrfs_leaf *leaf;
18 struct btrfs_key found_key;
19 char uuidbuf[37];
20 int ret;
21 int slot;
23 if (ac != 2) {
24 fprintf(stderr, "usage: %s device\n", av[0]);
25 exit(1);
27 radix_tree_init();
28 root = open_ctree(av[1], &super);
29 if (!root) {
30 fprintf(stderr, "unable to open %s\n", av[1]);
31 exit(1);
33 printf("root tree\n");
34 btrfs_print_tree(root->fs_info->tree_root,
35 root->fs_info->tree_root->node);
36 btrfs_init_path(&path);
37 key.offset = 0;
38 key.objectid = 0;
39 key.flags = 0;
40 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
41 ret = btrfs_search_slot(NULL, root->fs_info->tree_root,
42 &key, &path, 0, 0);
43 BUG_ON(ret < 0);
44 while(1) {
45 leaf = &path.nodes[0]->leaf;
46 slot = path.slots[0];
47 if (slot >= btrfs_header_nritems(&leaf->header)) {
48 ret = btrfs_next_leaf(root, &path);
49 if (ret != 0)
50 break;
51 leaf = &path.nodes[0]->leaf;
52 slot = path.slots[0];
54 btrfs_disk_key_to_cpu(&found_key,
55 &leaf->items[path.slots[0]].key);
56 if (btrfs_key_type(&found_key) == BTRFS_ROOT_ITEM_KEY) {
57 struct btrfs_buffer *buf;
58 ri = btrfs_item_ptr(leaf, path.slots[0],
59 struct btrfs_root_item);
60 buf = read_tree_block(root->fs_info->tree_root,
61 btrfs_root_blocknr(ri));
62 switch(found_key.objectid) {
63 case BTRFS_ROOT_TREE_OBJECTID:
64 printf("root ");
65 break;
66 case BTRFS_EXTENT_TREE_OBJECTID:
67 printf("extent tree ");
68 break;
70 printf("tree %Lu %Lu %u\n", found_key.objectid,
71 found_key.offset, found_key.flags);
72 btrfs_print_tree(root, buf);
74 path.slots[0]++;
76 btrfs_release_path(root, &path);
77 printf("total blocks %Lu\n", btrfs_super_total_blocks(&super));
78 printf("blocks used %Lu\n", btrfs_super_blocks_used(&super));
79 uuidbuf[36] = '\0';
80 uuid_unparse(super.fsid, uuidbuf);
81 printf("uuid %s\n", uuidbuf);
82 return 0;