Btrfs: trivial include fixups
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / btrfs / print-tree.c
blobbafa78603bd2c6099ca12db30103126abf49b614
1 /*
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.
19 #include "ctree.h"
20 #include "disk-io.h"
21 #include "print-tree.h"
23 void btrfs_print_leaf(struct btrfs_root *root, struct btrfs_leaf *l)
25 int i;
26 u32 nr = btrfs_header_nritems(&l->header);
27 struct btrfs_item *item;
28 struct btrfs_extent_item *ei;
29 struct btrfs_root_item *ri;
30 struct btrfs_dir_item *di;
31 struct btrfs_inode_item *ii;
32 struct btrfs_block_group_item *bi;
33 struct btrfs_file_extent_item *fi;
34 u32 type;
36 printk("leaf %llu total ptrs %d free space %d\n",
37 (unsigned long long)btrfs_header_blocknr(&l->header), nr,
38 btrfs_leaf_free_space(root, l));
39 for (i = 0 ; i < nr ; i++) {
40 item = l->items + i;
41 type = btrfs_disk_key_type(&item->key);
42 printk("\titem %d key (%llu %x %llu) itemoff %d itemsize %d\n",
44 (unsigned long long)btrfs_disk_key_objectid(&item->key),
45 btrfs_disk_key_flags(&item->key),
46 (unsigned long long)btrfs_disk_key_offset(&item->key),
47 btrfs_item_offset(item),
48 btrfs_item_size(item));
49 switch (type) {
50 case BTRFS_INODE_ITEM_KEY:
51 ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
52 printk("\t\tinode generation %llu size %llu mode %o\n",
53 (unsigned long long)btrfs_inode_generation(ii),
54 (unsigned long long)btrfs_inode_size(ii),
55 btrfs_inode_mode(ii));
56 break;
57 case BTRFS_DIR_ITEM_KEY:
58 di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
59 printk("\t\tdir oid %llu flags %u type %u\n",
60 (unsigned long long)btrfs_disk_key_objectid(
61 &di->location),
62 btrfs_dir_flags(di),
63 btrfs_dir_type(di));
64 printk("\t\tname %.*s\n",
65 btrfs_dir_name_len(di),(char *)(di + 1));
66 break;
67 case BTRFS_ROOT_ITEM_KEY:
68 ri = btrfs_item_ptr(l, i, struct btrfs_root_item);
69 printk("\t\troot data blocknr %llu refs %u\n",
70 (unsigned long long)btrfs_root_blocknr(ri),
71 btrfs_root_refs(ri));
72 break;
73 case BTRFS_EXTENT_ITEM_KEY:
74 ei = btrfs_item_ptr(l, i, struct btrfs_extent_item);
75 printk("\t\textent data refs %u\n",
76 btrfs_extent_refs(ei));
77 break;
79 case BTRFS_EXTENT_DATA_KEY:
80 fi = btrfs_item_ptr(l, i,
81 struct btrfs_file_extent_item);
82 if (btrfs_file_extent_type(fi) ==
83 BTRFS_FILE_EXTENT_INLINE) {
84 printk("\t\tinline extent data size %u\n",
85 btrfs_file_extent_inline_len(l->items + i));
86 break;
88 printk("\t\textent data disk block %llu nr %llu\n",
89 (unsigned long long)btrfs_file_extent_disk_blocknr(fi),
90 (unsigned long long)btrfs_file_extent_disk_num_blocks(fi));
91 printk("\t\textent data offset %llu nr %llu\n",
92 (unsigned long long)btrfs_file_extent_offset(fi),
93 (unsigned long long)btrfs_file_extent_num_blocks(fi));
94 break;
95 case BTRFS_BLOCK_GROUP_ITEM_KEY:
96 bi = btrfs_item_ptr(l, i,
97 struct btrfs_block_group_item);
98 printk("\t\tblock group used %llu\n",
99 (unsigned long long)btrfs_block_group_used(bi));
100 break;
101 case BTRFS_STRING_ITEM_KEY:
102 printk("\t\titem data %.*s\n", btrfs_item_size(item),
103 btrfs_leaf_data(l) + btrfs_item_offset(item));
104 break;
109 void btrfs_print_tree(struct btrfs_root *root, struct buffer_head *t)
111 int i;
112 u32 nr;
113 struct btrfs_node *c;
115 if (!t)
116 return;
117 c = btrfs_buffer_node(t);
118 nr = btrfs_header_nritems(&c->header);
119 if (btrfs_is_leaf(c)) {
120 btrfs_print_leaf(root, (struct btrfs_leaf *)c);
121 return;
123 printk("node %llu level %d total ptrs %d free spc %u\n",
124 (unsigned long long)btrfs_header_blocknr(&c->header),
125 btrfs_header_level(&c->header), nr,
126 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr);
127 for (i = 0; i < nr; i++) {
128 printk("\tkey %d (%llu %u %llu) block %llu\n",
130 (unsigned long long)c->ptrs[i].key.objectid,
131 c->ptrs[i].key.flags,
132 (unsigned long long)c->ptrs[i].key.offset,
133 (unsigned long long)btrfs_node_blockptr(c, i));
135 for (i = 0; i < nr; i++) {
136 struct buffer_head *next_buf = read_tree_block(root,
137 btrfs_node_blockptr(c, i));
138 struct btrfs_node *next = btrfs_buffer_node(next_buf);
139 if (btrfs_is_leaf(next) &&
140 btrfs_header_level(&c->header) != 1)
141 BUG();
142 if (btrfs_header_level(&next->header) !=
143 btrfs_header_level(&c->header) - 1)
144 BUG();
145 btrfs_print_tree(root, next_buf);
146 btrfs_block_release(root, next_buf);