2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
21 #include <uuid/uuid.h>
22 #include "kerncompat.h"
23 #include "radix-tree.h"
26 #include "print-tree.h"
27 #include "transaction.h"
29 int main(int ac, char **av) {
30 struct btrfs_super_block super;
31 struct btrfs_root *root;
32 struct btrfs_path path;
34 struct btrfs_root_item *ri;
35 struct btrfs_leaf *leaf;
36 struct btrfs_key found_key;
42 fprintf(stderr, "usage: %s device\n", av[0]);
46 root = open_ctree(av[1], &super);
48 fprintf(stderr, "unable to open %s\n", av[1]);
51 printf("root tree\n");
52 btrfs_print_tree(root->fs_info->tree_root,
53 root->fs_info->tree_root->node);
54 btrfs_init_path(&path);
57 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
58 ret = btrfs_search_slot(NULL, root->fs_info->tree_root,
62 leaf = &path.nodes[0]->leaf;
64 if (slot >= btrfs_header_nritems(&leaf->header)) {
65 ret = btrfs_next_leaf(root, &path);
68 leaf = &path.nodes[0]->leaf;
71 btrfs_disk_key_to_cpu(&found_key,
72 &leaf->items[path.slots[0]].key);
73 if (btrfs_key_type(&found_key) == BTRFS_ROOT_ITEM_KEY) {
74 struct btrfs_buffer *buf;
75 ri = btrfs_item_ptr(leaf, path.slots[0],
76 struct btrfs_root_item);
77 buf = read_tree_block(root->fs_info->tree_root,
78 btrfs_root_bytenr(ri),
80 switch(found_key.objectid) {
81 case BTRFS_ROOT_TREE_OBJECTID:
84 case BTRFS_EXTENT_TREE_OBJECTID:
85 printf("extent tree ");
88 printf("tree %llu %u %llu\n",
89 (unsigned long long)found_key.objectid,
91 (unsigned long long)found_key.offset);
92 btrfs_print_tree(root, buf);
96 btrfs_release_path(root, &path);
97 printf("total bytes %llu\n",
98 (unsigned long long)btrfs_super_total_bytes(&super));
99 printf("bytes used %llu\n",
100 (unsigned long long)btrfs_super_bytes_used(&super));
102 uuid_unparse(super.fsid, uuidbuf);
103 printf("uuid %s\n", uuidbuf);