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"
28 static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item,
29 struct btrfs_dir_item *di)
36 char namebuf[BTRFS_NAME_LEN];
37 struct btrfs_disk_key location;
39 total = btrfs_item_size(eb, item);
41 btrfs_dir_item_key(eb, di, &location);
42 printf("\t\tlocation ");
43 btrfs_print_key(&location);
44 printf(" type %u\n", btrfs_dir_type(eb, di));
45 name_len = btrfs_dir_name_len(eb, di);
46 data_len = btrfs_dir_data_len(eb, di);
47 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
48 read_extent_buffer(eb, namebuf, (unsigned long)(di + 1), len);
49 printf("\t\tnamelen %u datalen %u name: %.*s\n",
50 name_len, data_len, len, namebuf);
52 len = (data_len <= sizeof(namebuf))? data_len: sizeof(namebuf);
53 read_extent_buffer(eb, namebuf,
54 (unsigned long)(di + 1) + name_len, len);
55 printf("\t\tdata %.*s\n", len, namebuf);
57 len = sizeof(*di) + name_len + data_len;
58 di = (struct btrfs_dir_item *)((char *)di + len);
64 static int print_inode_extref_item(struct extent_buffer *eb,
65 struct btrfs_item *item,
66 struct btrfs_inode_extref *extref)
74 char namebuf[BTRFS_NAME_LEN];
76 total = btrfs_item_size(eb, item);
79 index = btrfs_inode_extref_index(eb, extref);
80 name_len = btrfs_inode_extref_name_len(eb, extref);
81 parent_objid = btrfs_inode_extref_parent(eb, extref);
83 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
85 read_extent_buffer(eb, namebuf, (unsigned long)(extref->name), len);
87 printf("\t\tinode extref index %llu parent %llu namelen %u "
89 (unsigned long long)index,
90 (unsigned long long)parent_objid,
91 name_len, len, namebuf);
93 len = sizeof(*extref) + name_len;
94 extref = (struct btrfs_inode_extref *)((char *)extref + len);
100 static int print_inode_ref_item(struct extent_buffer *eb, struct btrfs_item *item,
101 struct btrfs_inode_ref *ref)
108 char namebuf[BTRFS_NAME_LEN];
109 total = btrfs_item_size(eb, item);
111 name_len = btrfs_inode_ref_name_len(eb, ref);
112 index = btrfs_inode_ref_index(eb, ref);
113 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
114 read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len);
115 printf("\t\tinode ref index %llu namelen %u name: %.*s\n",
116 (unsigned long long)index, name_len, len, namebuf);
117 len = sizeof(*ref) + name_len;
118 ref = (struct btrfs_inode_ref *)((char *)ref + len);
124 static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
126 int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
128 printf("\t\tchunk length %llu owner %llu type %llu num_stripes %d\n",
129 (unsigned long long)btrfs_chunk_length(eb, chunk),
130 (unsigned long long)btrfs_chunk_owner(eb, chunk),
131 (unsigned long long)btrfs_chunk_type(eb, chunk),
133 for (i = 0 ; i < num_stripes ; i++) {
134 printf("\t\t\tstripe %d devid %llu offset %llu\n", i,
135 (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i),
136 (unsigned long long)btrfs_stripe_offset_nr(eb, chunk, i));
140 static void print_dev_item(struct extent_buffer *eb,
141 struct btrfs_dev_item *dev_item)
143 printf("\t\tdev item devid %llu "
144 "total_bytes %llu bytes used %Lu\n",
145 (unsigned long long)btrfs_device_id(eb, dev_item),
146 (unsigned long long)btrfs_device_total_bytes(eb, dev_item),
147 (unsigned long long)btrfs_device_bytes_used(eb, dev_item));
150 static void print_uuids(struct extent_buffer *eb)
154 u8 disk_uuid[BTRFS_UUID_SIZE];
156 read_extent_buffer(eb, disk_uuid, (unsigned long)btrfs_header_fsid(eb),
160 uuid_unparse(disk_uuid, fs_uuid);
162 read_extent_buffer(eb, disk_uuid,
163 (unsigned long)btrfs_header_chunk_tree_uuid(eb),
166 chunk_uuid[36] = '\0';
167 uuid_unparse(disk_uuid, chunk_uuid);
168 printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid);
171 static void print_file_extent_item(struct extent_buffer *eb,
172 struct btrfs_item *item,
173 struct btrfs_file_extent_item *fi)
175 int extent_type = btrfs_file_extent_type(eb, fi);
177 if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
178 printf("\t\tinline extent data size %u "
179 "ram %u compress %d\n",
180 btrfs_file_extent_inline_item_len(eb, item),
181 btrfs_file_extent_inline_len(eb, fi),
182 btrfs_file_extent_compression(eb, fi));
185 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
186 printf("\t\tprealloc data disk byte %llu nr %llu\n",
187 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
188 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
189 printf("\t\tprealloc data offset %llu nr %llu\n",
190 (unsigned long long)btrfs_file_extent_offset(eb, fi),
191 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi));
194 printf("\t\textent data disk byte %llu nr %llu\n",
195 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
196 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
197 printf("\t\textent data offset %llu nr %llu ram %llu\n",
198 (unsigned long long)btrfs_file_extent_offset(eb, fi),
199 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi),
200 (unsigned long long)btrfs_file_extent_ram_bytes(eb, fi));
201 printf("\t\textent compression %d\n",
202 btrfs_file_extent_compression(eb, fi));
205 static void print_extent_item(struct extent_buffer *eb, int slot)
207 struct btrfs_extent_item *ei;
208 struct btrfs_extent_inline_ref *iref;
209 struct btrfs_extent_data_ref *dref;
210 struct btrfs_shared_data_ref *sref;
211 struct btrfs_disk_key key;
215 u32 item_size = btrfs_item_size_nr(eb, slot);
219 if (item_size < sizeof(*ei)) {
220 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
221 struct btrfs_extent_item_v0 *ei0;
222 BUG_ON(item_size != sizeof(*ei0));
223 ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0);
224 printf("\t\textent refs %u\n",
225 btrfs_extent_refs_v0(eb, ei0));
232 ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
233 flags = btrfs_extent_flags(eb, ei);
235 printf("\t\textent refs %llu gen %llu flags %llu\n",
236 (unsigned long long)btrfs_extent_refs(eb, ei),
237 (unsigned long long)btrfs_extent_generation(eb, ei),
238 (unsigned long long)flags);
240 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
241 struct btrfs_tree_block_info *info;
242 info = (struct btrfs_tree_block_info *)(ei + 1);
243 btrfs_tree_block_key(eb, info, &key);
244 printf("\t\ttree block ");
245 btrfs_print_key(&key);
246 printf(" level %d\n", btrfs_tree_block_level(eb, info));
247 iref = (struct btrfs_extent_inline_ref *)(info + 1);
249 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
252 ptr = (unsigned long)iref;
253 end = (unsigned long)ei + item_size;
255 iref = (struct btrfs_extent_inline_ref *)ptr;
256 type = btrfs_extent_inline_ref_type(eb, iref);
257 offset = btrfs_extent_inline_ref_offset(eb, iref);
259 case BTRFS_TREE_BLOCK_REF_KEY:
260 printf("\t\ttree block backref root %llu\n",
261 (unsigned long long)offset);
263 case BTRFS_SHARED_BLOCK_REF_KEY:
264 printf("\t\tshared block backref parent %llu\n",
265 (unsigned long long)offset);
267 case BTRFS_EXTENT_DATA_REF_KEY:
268 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
269 printf("\t\textent data backref root %llu "
270 "objectid %llu offset %llu count %u\n",
271 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
272 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
273 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
274 btrfs_extent_data_ref_count(eb, dref));
276 case BTRFS_SHARED_DATA_REF_KEY:
277 sref = (struct btrfs_shared_data_ref *)(iref + 1);
278 printf("\t\tshared data backref parent %llu count %u\n",
279 (unsigned long long)offset,
280 btrfs_shared_data_ref_count(eb, sref));
285 ptr += btrfs_extent_inline_ref_size(type);
290 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
291 static void print_extent_ref_v0(struct extent_buffer *eb, int slot)
293 struct btrfs_extent_ref_v0 *ref0;
295 ref0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_ref_v0);
296 printf("\t\textent back ref root %llu gen %llu "
297 "owner %llu num_refs %lu\n",
298 (unsigned long long)btrfs_ref_root_v0(eb, ref0),
299 (unsigned long long)btrfs_ref_generation_v0(eb, ref0),
300 (unsigned long long)btrfs_ref_objectid_v0(eb, ref0),
301 (unsigned long)btrfs_ref_count_v0(eb, ref0));
305 static void print_root_ref(struct extent_buffer *leaf, int slot, char *tag)
307 struct btrfs_root_ref *ref;
308 char namebuf[BTRFS_NAME_LEN];
311 ref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref);
312 namelen = btrfs_root_ref_name_len(leaf, ref);
313 read_extent_buffer(leaf, namebuf, (unsigned long)(ref + 1), namelen);
314 printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag,
315 (unsigned long long)btrfs_root_ref_dirid(leaf, ref),
316 (unsigned long long)btrfs_root_ref_sequence(leaf, ref),
320 static int count_bytes(void *buf, int len, char b)
324 for (i = 0; i < len; i++) {
325 if (((char*)buf)[i] == b)
331 static void print_root(struct extent_buffer *leaf, int slot)
333 struct btrfs_root_item *ri;
334 struct btrfs_root_item root_item;
338 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
339 len = btrfs_item_size_nr(leaf, slot);
341 memset(&root_item, 0, sizeof(root_item));
342 read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);
344 printf("\t\troot data bytenr %llu level %d dirid %llu refs %u gen %llu\n",
345 (unsigned long long)btrfs_root_bytenr(&root_item),
346 btrfs_root_level(&root_item),
347 (unsigned long long)btrfs_root_dirid(&root_item),
348 btrfs_root_refs(&root_item),
349 (unsigned long long)btrfs_root_generation(&root_item));
351 if (root_item.generation == root_item.generation_v2) {
352 uuid_unparse(root_item.uuid, uuid_str);
353 printf("\t\tuuid %s\n", uuid_str);
354 if (count_bytes(root_item.parent_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
355 uuid_unparse(root_item.parent_uuid, uuid_str);
356 printf("\t\tparent_uuid %s\n", uuid_str);
358 if (count_bytes(root_item.received_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
359 uuid_unparse(root_item.received_uuid, uuid_str);
360 printf("\t\treceived_uuid %s\n", uuid_str);
362 if (root_item.ctransid) {
363 printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
364 btrfs_root_ctransid(&root_item),
365 btrfs_root_otransid(&root_item),
366 btrfs_root_stransid(&root_item),
367 btrfs_root_rtransid(&root_item));
370 if (btrfs_root_refs(&root_item) == 0) {
371 struct btrfs_key drop_key;
372 btrfs_disk_key_to_cpu(&drop_key,
373 &root_item.drop_progress);
375 btrfs_print_key(&root_item.drop_progress);
376 printf(" level %d\n", root_item.drop_level);
380 static void print_free_space_header(struct extent_buffer *leaf, int slot)
382 struct btrfs_free_space_header *header;
383 struct btrfs_disk_key location;
385 header = btrfs_item_ptr(leaf, slot, struct btrfs_free_space_header);
386 btrfs_free_space_key(leaf, header, &location);
387 printf("\t\tlocation ");
388 btrfs_print_key(&location);
390 printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
391 (unsigned long long)btrfs_free_space_generation(leaf, header),
392 (unsigned long long)btrfs_free_space_entries(leaf, header),
393 (unsigned long long)btrfs_free_space_bitmaps(leaf, header));
396 static void print_key_type(u64 objectid, u8 type)
398 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
404 case BTRFS_INODE_ITEM_KEY:
405 printf("INODE_ITEM");
407 case BTRFS_INODE_REF_KEY:
410 case BTRFS_INODE_EXTREF_KEY:
411 printf("INODE_EXTREF");
413 case BTRFS_DIR_ITEM_KEY:
416 case BTRFS_DIR_INDEX_KEY:
419 case BTRFS_DIR_LOG_ITEM_KEY:
420 printf("DIR_LOG_ITEM");
422 case BTRFS_DIR_LOG_INDEX_KEY:
423 printf("DIR_LOG_INDEX");
425 case BTRFS_XATTR_ITEM_KEY:
426 printf("XATTR_ITEM");
428 case BTRFS_ORPHAN_ITEM_KEY:
429 printf("ORPHAN_ITEM");
431 case BTRFS_ROOT_ITEM_KEY:
434 case BTRFS_ROOT_REF_KEY:
437 case BTRFS_ROOT_BACKREF_KEY:
438 printf("ROOT_BACKREF");
440 case BTRFS_EXTENT_ITEM_KEY:
441 printf("EXTENT_ITEM");
443 case BTRFS_TREE_BLOCK_REF_KEY:
444 printf("TREE_BLOCK_REF");
446 case BTRFS_SHARED_BLOCK_REF_KEY:
447 printf("SHARED_BLOCK_REF");
449 case BTRFS_EXTENT_DATA_REF_KEY:
450 printf("EXTENT_DATA_REF");
452 case BTRFS_SHARED_DATA_REF_KEY:
453 printf("SHARED_DATA_REF");
455 case BTRFS_EXTENT_REF_V0_KEY:
456 printf("EXTENT_REF_V0");
458 case BTRFS_CSUM_ITEM_KEY:
461 case BTRFS_EXTENT_CSUM_KEY:
462 printf("EXTENT_CSUM");
464 case BTRFS_EXTENT_DATA_KEY:
465 printf("EXTENT_DATA");
467 case BTRFS_BLOCK_GROUP_ITEM_KEY:
468 printf("BLOCK_GROUP_ITEM");
470 case BTRFS_CHUNK_ITEM_KEY:
471 printf("CHUNK_ITEM");
473 case BTRFS_DEV_ITEM_KEY:
476 case BTRFS_DEV_EXTENT_KEY:
477 printf("DEV_EXTENT");
479 case BTRFS_BALANCE_ITEM_KEY:
480 printf("BALANCE_ITEM");
482 case BTRFS_DEV_REPLACE_KEY:
483 printf("DEV_REPLACE_ITEM");
485 case BTRFS_STRING_ITEM_KEY:
486 printf("STRING_ITEM");
488 case BTRFS_QGROUP_STATUS_KEY:
489 printf("BTRFS_STATUS_KEY");
491 case BTRFS_QGROUP_RELATION_KEY:
492 printf("BTRFS_QGROUP_RELATION_KEY");
494 case BTRFS_QGROUP_INFO_KEY:
495 printf("BTRFS_QGROUP_INFO_KEY");
497 case BTRFS_QGROUP_LIMIT_KEY:
498 printf("BTRFS_QGROUP_LIMIT_KEY");
500 case BTRFS_DEV_STATS_KEY:
501 printf("DEV_STATS_ITEM");
504 printf("UNKNOWN.%d", type);
508 static void print_objectid(u64 objectid, u8 type)
510 if (type == BTRFS_DEV_EXTENT_KEY) {
511 printf("%llu", (unsigned long long)objectid); /* device id */
515 case BTRFS_QGROUP_RELATION_KEY:
516 printf("%llu/%llu", objectid >> 48,
517 objectid & ((1ll << 48) - 1));
522 case BTRFS_ROOT_TREE_OBJECTID:
523 if (type == BTRFS_DEV_ITEM_KEY)
528 case BTRFS_EXTENT_TREE_OBJECTID:
529 printf("EXTENT_TREE");
531 case BTRFS_CHUNK_TREE_OBJECTID:
532 printf("CHUNK_TREE");
534 case BTRFS_DEV_TREE_OBJECTID:
537 case BTRFS_FS_TREE_OBJECTID:
540 case BTRFS_ROOT_TREE_DIR_OBJECTID:
541 printf("ROOT_TREE_DIR");
543 case BTRFS_CSUM_TREE_OBJECTID:
546 case BTRFS_BALANCE_OBJECTID:
549 case BTRFS_ORPHAN_OBJECTID:
552 case BTRFS_TREE_LOG_OBJECTID:
555 case BTRFS_TREE_LOG_FIXUP_OBJECTID:
558 case BTRFS_TREE_RELOC_OBJECTID:
559 printf("TREE_RELOC");
561 case BTRFS_DATA_RELOC_TREE_OBJECTID:
562 printf("DATA_RELOC_TREE");
564 case BTRFS_EXTENT_CSUM_OBJECTID:
565 printf("EXTENT_CSUM");
567 case BTRFS_FREE_SPACE_OBJECTID:
568 printf("FREE_SPACE");
570 case BTRFS_FREE_INO_OBJECTID:
573 case BTRFS_QUOTA_TREE_OBJECTID:
574 printf("QUOTA_TREE");
576 case BTRFS_MULTIPLE_OBJECTIDS:
579 case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
580 if (type == BTRFS_CHUNK_ITEM_KEY) {
581 printf("FIRST_CHUNK_TREE");
586 printf("%llu", (unsigned long long)objectid);
590 void btrfs_print_key(struct btrfs_disk_key *disk_key)
592 u64 objectid = btrfs_disk_key_objectid(disk_key);
593 u8 type = btrfs_disk_key_type(disk_key);
594 u64 offset = btrfs_disk_key_offset(disk_key);
597 print_objectid(objectid, type);
599 print_key_type(objectid, type);
601 case BTRFS_QGROUP_RELATION_KEY:
602 case BTRFS_QGROUP_INFO_KEY:
603 case BTRFS_QGROUP_LIMIT_KEY:
604 printf(" %llu/%llu)", (unsigned long long)(offset >> 48),
605 (unsigned long long)(offset & ((1ll << 48) - 1)));
608 printf(" %llu)", (unsigned long long)offset);
613 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
617 struct btrfs_item *item;
618 struct btrfs_dir_item *di;
619 struct btrfs_inode_item *ii;
620 struct btrfs_file_extent_item *fi;
621 struct btrfs_block_group_item *bi;
622 struct btrfs_extent_data_ref *dref;
623 struct btrfs_shared_data_ref *sref;
624 struct btrfs_inode_ref *iref;
625 struct btrfs_inode_extref *iref2;
626 struct btrfs_dev_extent *dev_extent;
627 struct btrfs_disk_key disk_key;
628 struct btrfs_block_group_item bg_item;
629 struct btrfs_dir_log_item *dlog;
630 struct btrfs_qgroup_info_item *qg_info;
631 struct btrfs_qgroup_limit_item *qg_limit;
632 struct btrfs_qgroup_status_item *qg_status;
633 u32 nr = btrfs_header_nritems(l);
637 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
638 (unsigned long long)btrfs_header_bytenr(l), nr,
639 btrfs_leaf_free_space(root, l),
640 (unsigned long long)btrfs_header_generation(l),
641 (unsigned long long)btrfs_header_owner(l));
644 for (i = 0 ; i < nr ; i++) {
645 item = btrfs_item_nr(l, i);
646 btrfs_item_key(l, &disk_key, i);
647 objectid = btrfs_disk_key_objectid(&disk_key);
648 type = btrfs_disk_key_type(&disk_key);
649 printf("\titem %d ", i);
650 btrfs_print_key(&disk_key);
651 printf(" itemoff %d itemsize %d\n",
652 btrfs_item_offset(l, item),
653 btrfs_item_size(l, item));
655 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID)
656 print_free_space_header(l, i);
659 case BTRFS_INODE_ITEM_KEY:
660 ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
661 printf("\t\tinode generation %llu transid %llu size %llu block group %llu mode %o links %u\n",
662 (unsigned long long)btrfs_inode_generation(l, ii),
663 (unsigned long long)btrfs_inode_transid(l, ii),
664 (unsigned long long)btrfs_inode_size(l, ii),
665 (unsigned long long)btrfs_inode_block_group(l,ii),
666 btrfs_inode_mode(l, ii),
667 btrfs_inode_nlink(l, ii));
669 case BTRFS_INODE_REF_KEY:
670 iref = btrfs_item_ptr(l, i, struct btrfs_inode_ref);
671 print_inode_ref_item(l, item, iref);
673 case BTRFS_INODE_EXTREF_KEY:
674 iref2 = btrfs_item_ptr(l, i, struct btrfs_inode_extref);
675 print_inode_extref_item(l, item, iref2);
677 case BTRFS_DIR_ITEM_KEY:
678 case BTRFS_DIR_INDEX_KEY:
679 case BTRFS_XATTR_ITEM_KEY:
680 di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
681 print_dir_item(l, item, di);
683 case BTRFS_DIR_LOG_INDEX_KEY:
684 case BTRFS_DIR_LOG_ITEM_KEY:
685 dlog = btrfs_item_ptr(l, i, struct btrfs_dir_log_item);
686 printf("\t\tdir log end %Lu\n",
687 (unsigned long long)btrfs_dir_log_end(l, dlog));
689 case BTRFS_ORPHAN_ITEM_KEY:
690 printf("\t\torphan item\n");
692 case BTRFS_ROOT_ITEM_KEY:
695 case BTRFS_ROOT_REF_KEY:
696 print_root_ref(l, i, "ref");
698 case BTRFS_ROOT_BACKREF_KEY:
699 print_root_ref(l, i, "backref");
701 case BTRFS_EXTENT_ITEM_KEY:
702 print_extent_item(l, i);
704 case BTRFS_TREE_BLOCK_REF_KEY:
705 printf("\t\ttree block backref\n");
707 case BTRFS_SHARED_BLOCK_REF_KEY:
708 printf("\t\tshared block backref\n");
710 case BTRFS_EXTENT_DATA_REF_KEY:
711 dref = btrfs_item_ptr(l, i, struct btrfs_extent_data_ref);
712 printf("\t\textent data backref root %llu "
713 "objectid %llu offset %llu count %u\n",
714 (unsigned long long)btrfs_extent_data_ref_root(l, dref),
715 (unsigned long long)btrfs_extent_data_ref_objectid(l, dref),
716 (unsigned long long)btrfs_extent_data_ref_offset(l, dref),
717 btrfs_extent_data_ref_count(l, dref));
719 case BTRFS_SHARED_DATA_REF_KEY:
720 sref = btrfs_item_ptr(l, i, struct btrfs_shared_data_ref);
721 printf("\t\tshared data backref count %u\n",
722 btrfs_shared_data_ref_count(l, sref));
724 case BTRFS_EXTENT_REF_V0_KEY:
725 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
726 print_extent_ref_v0(l, i);
731 case BTRFS_CSUM_ITEM_KEY:
732 printf("\t\tcsum item\n");
734 case BTRFS_EXTENT_CSUM_KEY:
735 printf("\t\textent csum item\n");
737 case BTRFS_EXTENT_DATA_KEY:
738 fi = btrfs_item_ptr(l, i,
739 struct btrfs_file_extent_item);
740 print_file_extent_item(l, item, fi);
742 case BTRFS_BLOCK_GROUP_ITEM_KEY:
743 bi = btrfs_item_ptr(l, i,
744 struct btrfs_block_group_item);
745 read_extent_buffer(l, &bg_item, (unsigned long)bi,
747 printf("\t\tblock group used %llu chunk_objectid %llu flags %llu\n",
748 (unsigned long long)btrfs_block_group_used(&bg_item),
749 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
750 (unsigned long long)btrfs_block_group_flags(&bg_item));
752 case BTRFS_CHUNK_ITEM_KEY:
753 print_chunk(l, btrfs_item_ptr(l, i, struct btrfs_chunk));
755 case BTRFS_DEV_ITEM_KEY:
756 print_dev_item(l, btrfs_item_ptr(l, i,
757 struct btrfs_dev_item));
759 case BTRFS_DEV_EXTENT_KEY:
760 dev_extent = btrfs_item_ptr(l, i,
761 struct btrfs_dev_extent);
762 printf("\t\tdev extent chunk_tree %llu\n"
763 "\t\tchunk objectid %llu chunk offset %llu "
766 btrfs_dev_extent_chunk_tree(l, dev_extent),
768 btrfs_dev_extent_chunk_objectid(l, dev_extent),
770 btrfs_dev_extent_chunk_offset(l, dev_extent),
772 btrfs_dev_extent_length(l, dev_extent));
774 case BTRFS_QGROUP_STATUS_KEY:
775 qg_status = btrfs_item_ptr(l, i,
776 struct btrfs_qgroup_status_item);
777 printf("\t\tversion %llu generation %llu flags %#llx "
780 btrfs_qgroup_status_version(l, qg_status),
782 btrfs_qgroup_status_generation(l, qg_status),
784 btrfs_qgroup_status_flags(l, qg_status),
786 btrfs_qgroup_status_scan(l, qg_status));
788 case BTRFS_QGROUP_RELATION_KEY:
790 case BTRFS_QGROUP_INFO_KEY:
791 qg_info = btrfs_item_ptr(l, i,
792 struct btrfs_qgroup_info_item);
793 printf("\t\tgeneration %llu\n"
794 "\t\treferenced %lld referenced compressed %lld\n"
795 "\t\texclusive %lld exclusive compressed %lld\n",
797 btrfs_qgroup_info_generation(l, qg_info),
799 btrfs_qgroup_info_referenced(l, qg_info),
801 btrfs_qgroup_info_referenced_compressed(l,
804 btrfs_qgroup_info_exclusive(l, qg_info),
806 btrfs_qgroup_info_exclusive_compressed(l,
809 case BTRFS_QGROUP_LIMIT_KEY:
810 qg_limit = btrfs_item_ptr(l, i,
811 struct btrfs_qgroup_limit_item);
812 printf("\t\tflags %llx\n"
813 "\t\tmax referenced %lld max exclusive %lld\n"
814 "\t\trsv referenced %lld rsv exclusive %lld\n",
816 btrfs_qgroup_limit_flags(l, qg_limit),
818 btrfs_qgroup_limit_max_referenced(l, qg_limit),
820 btrfs_qgroup_limit_max_exclusive(l, qg_limit),
822 btrfs_qgroup_limit_rsv_referenced(l, qg_limit),
824 btrfs_qgroup_limit_rsv_exclusive(l, qg_limit));
826 case BTRFS_STRING_ITEM_KEY:
827 /* dirty, but it's simple */
828 str = l->data + btrfs_item_ptr_offset(l, i);
829 printf("\t\titem data %.*s\n", btrfs_item_size(l, item), str);
831 case BTRFS_DEV_STATS_KEY:
832 printf("\t\tdevice stats\n");
839 void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
844 struct btrfs_disk_key disk_key;
845 struct btrfs_key key;
849 nr = btrfs_header_nritems(eb);
850 if (btrfs_is_leaf(eb)) {
851 btrfs_print_leaf(root, eb);
854 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
855 (unsigned long long)eb->start,
856 btrfs_header_level(eb), nr,
857 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
858 (unsigned long long)btrfs_header_generation(eb),
859 (unsigned long long)btrfs_header_owner(eb));
862 size = btrfs_level_size(root, btrfs_header_level(eb) - 1);
863 for (i = 0; i < nr; i++) {
864 u64 blocknr = btrfs_node_blockptr(eb, i);
865 btrfs_node_key(eb, &disk_key, i);
866 btrfs_disk_key_to_cpu(&key, &disk_key);
868 btrfs_print_key(&disk_key);
869 printf(" block %llu (%llu) gen %llu\n",
870 (unsigned long long)blocknr,
871 (unsigned long long)blocknr / size,
872 (unsigned long long)btrfs_node_ptr_generation(eb, i));
878 for (i = 0; i < nr; i++) {
879 struct extent_buffer *next = read_tree_block(root,
880 btrfs_node_blockptr(eb, i),
882 btrfs_node_ptr_generation(eb, i));
884 fprintf(stderr, "failed to read %llu in tree %llu\n",
885 (unsigned long long)btrfs_node_blockptr(eb, i),
886 (unsigned long long)btrfs_header_owner(eb));
889 if (btrfs_is_leaf(next) &&
890 btrfs_header_level(eb) != 1)
892 if (btrfs_header_level(next) !=
893 btrfs_header_level(eb) - 1)
895 btrfs_print_tree(root, next, 1);
896 free_extent_buffer(next);