more stats from fsck
[btrfs-progs-unstable.git] / debug-tree.c
blob229546aea12aebf1734d5fed1ed971494e85cd89
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 printf("dev tree\n");
37 btrfs_print_tree(root->fs_info->dev_root,
38 root->fs_info->dev_root->node);
39 btrfs_init_path(&path);
40 key.offset = 0;
41 key.objectid = 0;
42 key.flags = 0;
43 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
44 ret = btrfs_search_slot(NULL, root->fs_info->tree_root,
45 &key, &path, 0, 0);
46 BUG_ON(ret < 0);
47 while(1) {
48 leaf = &path.nodes[0]->leaf;
49 slot = path.slots[0];
50 if (slot >= btrfs_header_nritems(&leaf->header)) {
51 ret = btrfs_next_leaf(root, &path);
52 if (ret != 0)
53 break;
54 leaf = &path.nodes[0]->leaf;
55 slot = path.slots[0];
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:
67 printf("root ");
68 break;
69 case BTRFS_DEV_TREE_OBJECTID:
70 printf("dev tree ");
71 break;
72 case BTRFS_EXTENT_TREE_OBJECTID:
73 printf("extent tree ");
74 break;
76 printf("tree %Lu %Lu %u\n", found_key.objectid,
77 found_key.offset, found_key.flags);
78 btrfs_print_tree(root, buf);
80 path.slots[0]++;
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));
85 uuidbuf[36] = '\0';
86 uuid_unparse(super.fsid, uuidbuf);
87 printf("uuid %s\n", uuidbuf);
88 return 0;