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_root *root;
31 struct btrfs_path path;
33 struct btrfs_root_item ri;
34 struct extent_buffer *leaf;
35 struct btrfs_key found_key;
41 fprintf(stderr, "usage: %s device\n", av[0]);
45 root = open_ctree(av[1], 0);
47 fprintf(stderr, "unable to open %s\n", av[1]);
50 printf("root tree\n");
51 btrfs_print_tree(root->fs_info->tree_root,
52 root->fs_info->tree_root->node);
53 btrfs_init_path(&path);
56 btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY);
57 ret = btrfs_search_slot(NULL, root->fs_info->tree_root,
63 if (slot >= btrfs_header_nritems(leaf)) {
64 ret = btrfs_next_leaf(root, &path);
70 btrfs_item_key_to_cpu(leaf, &found_key, path.slots[0]);
71 if (btrfs_key_type(&found_key) == BTRFS_ROOT_ITEM_KEY) {
73 struct extent_buffer *buf;
74 offset = btrfs_item_ptr_offset(leaf, slot);
75 read_extent_buffer(leaf, &ri, offset, sizeof(ri));
76 buf = read_tree_block(root->fs_info->tree_root,
77 btrfs_root_bytenr(&ri),
79 switch(found_key.objectid) {
80 case BTRFS_ROOT_TREE_OBJECTID:
83 case BTRFS_EXTENT_TREE_OBJECTID:
84 printf("extent tree ");
87 printf("tree %llu %u %llu\n",
88 (unsigned long long)found_key.objectid,
90 (unsigned long long)found_key.offset);
91 btrfs_print_tree(root, buf);
95 btrfs_release_path(root, &path);
96 printf("total bytes %llu\n",
97 (unsigned long long)btrfs_super_total_bytes(&root->fs_info->super_copy));
98 printf("bytes used %llu\n",
99 (unsigned long long)btrfs_super_bytes_used(&root->fs_info->super_copy));
101 uuid_unparse(root->fs_info->super_copy.fsid, uuidbuf);
102 printf("uuid %s\n", uuidbuf);