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"
30 static void print_dir_item_type(struct extent_buffer *eb,
31 struct btrfs_dir_item *di)
33 u8 type = btrfs_dir_type(eb, di);
36 case BTRFS_FT_REG_FILE:
54 case BTRFS_FT_SYMLINK:
65 static void print_dir_item(struct extent_buffer *eb, u32 size,
66 struct btrfs_dir_item *di)
72 char namebuf[BTRFS_NAME_LEN];
73 struct btrfs_disk_key location;
76 btrfs_dir_item_key(eb, di, &location);
77 printf("\t\tlocation ");
78 btrfs_print_key(&location);
80 print_dir_item_type(eb, di);
82 name_len = btrfs_dir_name_len(eb, di);
83 data_len = btrfs_dir_data_len(eb, di);
84 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
85 read_extent_buffer(eb, namebuf, (unsigned long)(di + 1), len);
86 printf("\t\ttransid %llu data_len %u name_len %u\n",
87 btrfs_dir_transid(eb, di),
89 printf("\t\tname: %.*s\n", len, namebuf);
91 len = (data_len <= sizeof(namebuf))? data_len: sizeof(namebuf);
92 read_extent_buffer(eb, namebuf,
93 (unsigned long)(di + 1) + name_len, len);
94 printf("\t\tdata %.*s\n", len, namebuf);
96 len = sizeof(*di) + name_len + data_len;
97 di = (struct btrfs_dir_item *)((char *)di + len);
102 static void print_inode_extref_item(struct extent_buffer *eb, u32 size,
103 struct btrfs_inode_extref *extref)
110 char namebuf[BTRFS_NAME_LEN];
113 index = btrfs_inode_extref_index(eb, extref);
114 name_len = btrfs_inode_extref_name_len(eb, extref);
115 parent_objid = btrfs_inode_extref_parent(eb, extref);
117 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
119 read_extent_buffer(eb, namebuf, (unsigned long)(extref->name), len);
121 printf("\t\tinode extref index %llu parent %llu namelen %u "
123 (unsigned long long)index,
124 (unsigned long long)parent_objid,
125 name_len, len, namebuf);
127 len = sizeof(*extref) + name_len;
128 extref = (struct btrfs_inode_extref *)((char *)extref + len);
133 static void print_inode_ref_item(struct extent_buffer *eb, u32 size,
134 struct btrfs_inode_ref *ref)
140 char namebuf[BTRFS_NAME_LEN];
143 name_len = btrfs_inode_ref_name_len(eb, ref);
144 index = btrfs_inode_ref_index(eb, ref);
145 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
146 read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len);
147 printf("\t\tinode ref index %llu namelen %u name: %.*s\n",
148 (unsigned long long)index, name_len, len, namebuf);
149 len = sizeof(*ref) + name_len;
150 ref = (struct btrfs_inode_ref *)((char *)ref + len);
155 /* Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10" */
156 static void bg_flags_to_str(u64 flags, char *ret)
160 if (flags & BTRFS_BLOCK_GROUP_DATA) {
164 if (flags & BTRFS_BLOCK_GROUP_METADATA) {
167 strcat(ret, "METADATA");
169 if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
172 strcat(ret, "SYSTEM");
174 switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
175 case BTRFS_BLOCK_GROUP_RAID0:
176 strcat(ret, "|RAID0");
178 case BTRFS_BLOCK_GROUP_RAID1:
179 strcat(ret, "|RAID1");
181 case BTRFS_BLOCK_GROUP_DUP:
184 case BTRFS_BLOCK_GROUP_RAID10:
185 strcat(ret, "|RAID10");
187 case BTRFS_BLOCK_GROUP_RAID5:
188 strcat(ret, "|RAID5");
190 case BTRFS_BLOCK_GROUP_RAID6:
191 strcat(ret, "|RAID6");
198 /* Caller should ensure sizeof(*ret)>= 26 "OFF|SCANNING|INCONSISTENT" */
199 static void qgroup_flags_to_str(u64 flags, char *ret)
201 if (flags & BTRFS_QGROUP_STATUS_FLAG_ON)
206 if (flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN)
207 strcat(ret, "|SCANNING");
208 if (flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
209 strcat(ret, "|INCONSISTENT");
212 void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
214 int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
216 char chunk_flags_str[32] = {0};
218 bg_flags_to_str(btrfs_chunk_type(eb, chunk), chunk_flags_str);
219 printf("\t\tlength %llu owner %llu stripe_len %llu type %s\n",
220 (unsigned long long)btrfs_chunk_length(eb, chunk),
221 (unsigned long long)btrfs_chunk_owner(eb, chunk),
222 (unsigned long long)btrfs_chunk_stripe_len(eb, chunk),
224 printf("\t\tio_align %u io_width %u sector_size %u\n",
225 btrfs_chunk_io_align(eb, chunk),
226 btrfs_chunk_io_width(eb, chunk),
227 btrfs_chunk_sector_size(eb, chunk));
228 printf("\t\tnum_stripes %hu sub_stripes %hu\n", num_stripes,
229 btrfs_chunk_sub_stripes(eb, chunk));
230 for (i = 0 ; i < num_stripes ; i++) {
231 unsigned char dev_uuid[BTRFS_UUID_SIZE];
232 char str_dev_uuid[BTRFS_UUID_UNPARSED_SIZE];
234 read_extent_buffer(eb, dev_uuid,
235 (unsigned long)btrfs_stripe_dev_uuid_nr(chunk, i),
237 uuid_unparse(dev_uuid, str_dev_uuid);
238 printf("\t\t\tstripe %d devid %llu offset %llu\n", i,
239 (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i),
240 (unsigned long long)btrfs_stripe_offset_nr(eb, chunk, i));
241 printf("\t\t\tdev_uuid %s\n", str_dev_uuid);
245 static void print_dev_item(struct extent_buffer *eb,
246 struct btrfs_dev_item *dev_item)
248 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
249 char fsid_str[BTRFS_UUID_UNPARSED_SIZE];
250 u8 uuid[BTRFS_UUID_SIZE];
251 u8 fsid[BTRFS_UUID_SIZE];
253 read_extent_buffer(eb, uuid,
254 (unsigned long)btrfs_device_uuid(dev_item),
256 uuid_unparse(uuid, uuid_str);
257 read_extent_buffer(eb, fsid,
258 (unsigned long)btrfs_device_fsid(dev_item),
260 uuid_unparse(fsid, fsid_str);
261 printf("\t\tdevid %llu total_bytes %llu bytes_used %Lu\n"
262 "\t\tio_align %u io_width %u sector_size %u type %llu\n"
263 "\t\tgeneration %llu start_offset %llu dev_group %u\n"
264 "\t\tseek_speed %hhu bandwidth %hhu\n"
267 (unsigned long long)btrfs_device_id(eb, dev_item),
268 (unsigned long long)btrfs_device_total_bytes(eb, dev_item),
269 (unsigned long long)btrfs_device_bytes_used(eb, dev_item),
270 btrfs_device_io_align(eb, dev_item),
271 btrfs_device_io_width(eb, dev_item),
272 btrfs_device_sector_size(eb, dev_item),
273 (unsigned long long)btrfs_device_type(eb, dev_item),
274 (unsigned long long)btrfs_device_generation(eb, dev_item),
275 (unsigned long long)btrfs_device_start_offset(eb, dev_item),
276 btrfs_device_group(eb, dev_item),
277 btrfs_device_seek_speed(eb, dev_item),
278 btrfs_device_bandwidth(eb, dev_item),
282 static void print_uuids(struct extent_buffer *eb)
284 char fs_uuid[BTRFS_UUID_UNPARSED_SIZE];
285 char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE];
286 u8 disk_uuid[BTRFS_UUID_SIZE];
288 read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(),
291 fs_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
292 uuid_unparse(disk_uuid, fs_uuid);
294 read_extent_buffer(eb, disk_uuid,
295 btrfs_header_chunk_tree_uuid(eb),
298 chunk_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
299 uuid_unparse(disk_uuid, chunk_uuid);
300 printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid);
303 static void compress_type_to_str(u8 compress_type, char *ret)
305 switch (compress_type) {
306 case BTRFS_COMPRESS_NONE:
309 case BTRFS_COMPRESS_ZLIB:
312 case BTRFS_COMPRESS_LZO:
316 sprintf(ret, "UNKNOWN.%d", compress_type);
320 static const char* file_extent_type_to_str(u8 type)
323 case BTRFS_FILE_EXTENT_INLINE: return "inline";
324 case BTRFS_FILE_EXTENT_PREALLOC: return "prealloc";
325 case BTRFS_FILE_EXTENT_REG: return "regular";
326 default: return "unknown";
330 static void print_file_extent_item(struct extent_buffer *eb,
331 struct btrfs_item *item,
333 struct btrfs_file_extent_item *fi)
335 int extent_type = btrfs_file_extent_type(eb, fi);
336 char compress_str[16];
338 compress_type_to_str(btrfs_file_extent_compression(eb, fi),
341 printf("\t\tgeneration %llu type %hhu (%s)\n",
342 btrfs_file_extent_generation(eb, fi),
343 extent_type, file_extent_type_to_str(extent_type));
345 if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
346 printf("\t\tinline extent data size %u ram_bytes %u compression %hhu (%s)\n",
347 btrfs_file_extent_inline_item_len(eb, item),
348 btrfs_file_extent_inline_len(eb, slot, fi),
349 btrfs_file_extent_compression(eb, fi),
353 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
354 printf("\t\tprealloc data disk byte %llu nr %llu\n",
355 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
356 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
357 printf("\t\tprealloc data offset %llu nr %llu\n",
358 (unsigned long long)btrfs_file_extent_offset(eb, fi),
359 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi));
362 printf("\t\textent data disk byte %llu nr %llu\n",
363 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
364 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
365 printf("\t\textent data offset %llu nr %llu ram %llu\n",
366 (unsigned long long)btrfs_file_extent_offset(eb, fi),
367 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi),
368 (unsigned long long)btrfs_file_extent_ram_bytes(eb, fi));
369 printf("\t\textent compression %hhu (%s)\n",
370 btrfs_file_extent_compression(eb, fi),
374 /* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
375 static void extent_flags_to_str(u64 flags, char *ret)
379 if (flags & BTRFS_EXTENT_FLAG_DATA) {
383 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
388 strcat(ret, "TREE_BLOCK");
390 if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
392 strcat(ret, "FULL_BACKREF");
396 void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
398 struct btrfs_extent_item *ei;
399 struct btrfs_extent_inline_ref *iref;
400 struct btrfs_extent_data_ref *dref;
401 struct btrfs_shared_data_ref *sref;
402 struct btrfs_disk_key key;
406 u32 item_size = btrfs_item_size_nr(eb, slot);
409 char flags_str[32] = {0};
411 if (item_size < sizeof(*ei)) {
412 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
413 struct btrfs_extent_item_v0 *ei0;
414 BUG_ON(item_size != sizeof(*ei0));
415 ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0);
416 printf("\t\textent refs %u\n",
417 btrfs_extent_refs_v0(eb, ei0));
424 ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
425 flags = btrfs_extent_flags(eb, ei);
426 extent_flags_to_str(flags, flags_str);
428 printf("\t\textent refs %llu gen %llu flags %s\n",
429 (unsigned long long)btrfs_extent_refs(eb, ei),
430 (unsigned long long)btrfs_extent_generation(eb, ei),
433 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !metadata) {
434 struct btrfs_tree_block_info *info;
435 info = (struct btrfs_tree_block_info *)(ei + 1);
436 btrfs_tree_block_key(eb, info, &key);
437 printf("\t\ttree block ");
438 btrfs_print_key(&key);
439 printf(" level %d\n", btrfs_tree_block_level(eb, info));
440 iref = (struct btrfs_extent_inline_ref *)(info + 1);
441 } else if (metadata) {
442 struct btrfs_key tmp;
444 btrfs_item_key_to_cpu(eb, &tmp, slot);
445 printf("\t\ttree block skinny level %d\n", (int)tmp.offset);
446 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
448 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
451 ptr = (unsigned long)iref;
452 end = (unsigned long)ei + item_size;
454 iref = (struct btrfs_extent_inline_ref *)ptr;
455 type = btrfs_extent_inline_ref_type(eb, iref);
456 offset = btrfs_extent_inline_ref_offset(eb, iref);
458 case BTRFS_TREE_BLOCK_REF_KEY:
459 printf("\t\ttree block backref root %llu\n",
460 (unsigned long long)offset);
462 case BTRFS_SHARED_BLOCK_REF_KEY:
463 printf("\t\tshared block backref parent %llu\n",
464 (unsigned long long)offset);
466 case BTRFS_EXTENT_DATA_REF_KEY:
467 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
468 printf("\t\textent data backref root %llu "
469 "objectid %llu offset %llu count %u\n",
470 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
471 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
472 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
473 btrfs_extent_data_ref_count(eb, dref));
475 case BTRFS_SHARED_DATA_REF_KEY:
476 sref = (struct btrfs_shared_data_ref *)(iref + 1);
477 printf("\t\tshared data backref parent %llu count %u\n",
478 (unsigned long long)offset,
479 btrfs_shared_data_ref_count(eb, sref));
484 ptr += btrfs_extent_inline_ref_size(type);
489 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
490 static void print_extent_ref_v0(struct extent_buffer *eb, int slot)
492 struct btrfs_extent_ref_v0 *ref0;
494 ref0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_ref_v0);
495 printf("\t\textent back ref root %llu gen %llu "
496 "owner %llu num_refs %lu\n",
497 (unsigned long long)btrfs_ref_root_v0(eb, ref0),
498 (unsigned long long)btrfs_ref_generation_v0(eb, ref0),
499 (unsigned long long)btrfs_ref_objectid_v0(eb, ref0),
500 (unsigned long)btrfs_ref_count_v0(eb, ref0));
504 static void print_root_ref(struct extent_buffer *leaf, int slot, const char *tag)
506 struct btrfs_root_ref *ref;
507 char namebuf[BTRFS_NAME_LEN];
510 ref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref);
511 namelen = btrfs_root_ref_name_len(leaf, ref);
512 read_extent_buffer(leaf, namebuf, (unsigned long)(ref + 1), namelen);
513 printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag,
514 (unsigned long long)btrfs_root_ref_dirid(leaf, ref),
515 (unsigned long long)btrfs_root_ref_sequence(leaf, ref),
519 static int empty_uuid(const u8 *uuid)
523 for (i = 0; i < BTRFS_UUID_SIZE; i++)
530 * Caller must ensure sizeof(*ret) >= 7 "RDONLY"
532 static void root_flags_to_str(u64 flags, char *ret)
534 if (flags & BTRFS_ROOT_SUBVOL_RDONLY)
535 strcat(ret, "RDONLY");
540 static void print_root(struct extent_buffer *leaf, int slot)
542 struct btrfs_root_item *ri;
543 struct btrfs_root_item root_item;
545 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
546 char flags_str[32] = {0};
547 struct btrfs_key drop_key;
549 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
550 len = btrfs_item_size_nr(leaf, slot);
552 memset(&root_item, 0, sizeof(root_item));
553 read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);
554 root_flags_to_str(btrfs_root_flags(&root_item), flags_str);
556 printf("\t\tgeneration %llu root_dirid %llu bytenr %llu level %hhu refs %u\n",
557 (unsigned long long)btrfs_root_generation(&root_item),
558 (unsigned long long)btrfs_root_dirid(&root_item),
559 (unsigned long long)btrfs_root_bytenr(&root_item),
560 btrfs_root_level(&root_item),
561 btrfs_root_refs(&root_item));
562 printf("\t\tlastsnap %llu byte_limit %llu bytes_used %llu flags 0x%llx(%s)\n",
563 (unsigned long long)btrfs_root_last_snapshot(&root_item),
564 (unsigned long long)btrfs_root_limit(&root_item),
565 (unsigned long long)btrfs_root_used(&root_item),
566 (unsigned long long)btrfs_root_flags(&root_item),
569 if (root_item.generation == root_item.generation_v2) {
570 uuid_unparse(root_item.uuid, uuid_str);
571 printf("\t\tuuid %s\n", uuid_str);
572 if (!empty_uuid(root_item.parent_uuid)) {
573 uuid_unparse(root_item.parent_uuid, uuid_str);
574 printf("\t\tparent_uuid %s\n", uuid_str);
576 if (!empty_uuid(root_item.received_uuid)) {
577 uuid_unparse(root_item.received_uuid, uuid_str);
578 printf("\t\treceived_uuid %s\n", uuid_str);
580 if (root_item.ctransid) {
581 printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
582 btrfs_root_ctransid(&root_item),
583 btrfs_root_otransid(&root_item),
584 btrfs_root_stransid(&root_item),
585 btrfs_root_rtransid(&root_item));
589 btrfs_disk_key_to_cpu(&drop_key, &root_item.drop_progress);
591 btrfs_print_key(&root_item.drop_progress);
592 printf(" level %hhu\n", root_item.drop_level);
595 static void print_free_space_header(struct extent_buffer *leaf, int slot)
597 struct btrfs_free_space_header *header;
598 struct btrfs_disk_key location;
600 header = btrfs_item_ptr(leaf, slot, struct btrfs_free_space_header);
601 btrfs_free_space_key(leaf, header, &location);
602 printf("\t\tlocation ");
603 btrfs_print_key(&location);
605 printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
606 (unsigned long long)btrfs_free_space_generation(leaf, header),
607 (unsigned long long)btrfs_free_space_entries(leaf, header),
608 (unsigned long long)btrfs_free_space_bitmaps(leaf, header));
611 void print_key_type(FILE *stream, u64 objectid, u8 type)
613 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
614 fprintf(stream, "UNTYPED");
619 case BTRFS_INODE_ITEM_KEY:
620 fprintf(stream, "INODE_ITEM");
622 case BTRFS_INODE_REF_KEY:
623 fprintf(stream, "INODE_REF");
625 case BTRFS_INODE_EXTREF_KEY:
626 fprintf(stream, "INODE_EXTREF");
628 case BTRFS_DIR_ITEM_KEY:
629 fprintf(stream, "DIR_ITEM");
631 case BTRFS_DIR_INDEX_KEY:
632 fprintf(stream, "DIR_INDEX");
634 case BTRFS_DIR_LOG_ITEM_KEY:
635 fprintf(stream, "DIR_LOG_ITEM");
637 case BTRFS_DIR_LOG_INDEX_KEY:
638 fprintf(stream, "DIR_LOG_INDEX");
640 case BTRFS_XATTR_ITEM_KEY:
641 fprintf(stream, "XATTR_ITEM");
643 case BTRFS_ORPHAN_ITEM_KEY:
644 fprintf(stream, "ORPHAN_ITEM");
646 case BTRFS_ROOT_ITEM_KEY:
647 fprintf(stream, "ROOT_ITEM");
649 case BTRFS_ROOT_REF_KEY:
650 fprintf(stream, "ROOT_REF");
652 case BTRFS_ROOT_BACKREF_KEY:
653 fprintf(stream, "ROOT_BACKREF");
655 case BTRFS_EXTENT_ITEM_KEY:
656 fprintf(stream, "EXTENT_ITEM");
658 case BTRFS_METADATA_ITEM_KEY:
659 fprintf(stream, "METADATA_ITEM");
661 case BTRFS_TREE_BLOCK_REF_KEY:
662 fprintf(stream, "TREE_BLOCK_REF");
664 case BTRFS_SHARED_BLOCK_REF_KEY:
665 fprintf(stream, "SHARED_BLOCK_REF");
667 case BTRFS_EXTENT_DATA_REF_KEY:
668 fprintf(stream, "EXTENT_DATA_REF");
670 case BTRFS_SHARED_DATA_REF_KEY:
671 fprintf(stream, "SHARED_DATA_REF");
673 case BTRFS_EXTENT_REF_V0_KEY:
674 fprintf(stream, "EXTENT_REF_V0");
676 case BTRFS_CSUM_ITEM_KEY:
677 fprintf(stream, "CSUM_ITEM");
679 case BTRFS_EXTENT_CSUM_KEY:
680 fprintf(stream, "EXTENT_CSUM");
682 case BTRFS_EXTENT_DATA_KEY:
683 fprintf(stream, "EXTENT_DATA");
685 case BTRFS_BLOCK_GROUP_ITEM_KEY:
686 fprintf(stream, "BLOCK_GROUP_ITEM");
688 case BTRFS_FREE_SPACE_INFO_KEY:
689 fprintf(stream, "FREE_SPACE_INFO");
691 case BTRFS_FREE_SPACE_EXTENT_KEY:
692 fprintf(stream, "FREE_SPACE_EXTENT");
694 case BTRFS_FREE_SPACE_BITMAP_KEY:
695 fprintf(stream, "FREE_SPACE_BITMAP");
697 case BTRFS_CHUNK_ITEM_KEY:
698 fprintf(stream, "CHUNK_ITEM");
700 case BTRFS_DEV_ITEM_KEY:
701 fprintf(stream, "DEV_ITEM");
703 case BTRFS_DEV_EXTENT_KEY:
704 fprintf(stream, "DEV_EXTENT");
706 case BTRFS_BALANCE_ITEM_KEY:
707 fprintf(stream, "BALANCE_ITEM");
709 case BTRFS_DEV_REPLACE_KEY:
710 fprintf(stream, "DEV_REPLACE");
712 case BTRFS_STRING_ITEM_KEY:
713 fprintf(stream, "STRING_ITEM");
715 case BTRFS_QGROUP_STATUS_KEY:
716 fprintf(stream, "QGROUP_STATUS");
718 case BTRFS_QGROUP_RELATION_KEY:
719 fprintf(stream, "QGROUP_RELATION");
721 case BTRFS_QGROUP_INFO_KEY:
722 fprintf(stream, "QGROUP_INFO");
724 case BTRFS_QGROUP_LIMIT_KEY:
725 fprintf(stream, "QGROUP_LIMIT");
727 case BTRFS_DEV_STATS_KEY:
728 fprintf(stream, "DEV_STATS");
730 case BTRFS_UUID_KEY_SUBVOL:
731 fprintf(stream, "UUID_KEY_SUBVOL");
733 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
734 fprintf(stream, "UUID_KEY_RECEIVED_SUBVOL");
737 fprintf(stream, "UNKNOWN.%d", type);
741 void print_objectid(FILE *stream, u64 objectid, u8 type)
744 case BTRFS_DEV_EXTENT_KEY:
746 fprintf(stream, "%llu", (unsigned long long)objectid);
748 case BTRFS_QGROUP_RELATION_KEY:
749 fprintf(stream, "%llu/%llu", btrfs_qgroup_level(objectid),
750 btrfs_qgroup_subvid(objectid));
752 case BTRFS_UUID_KEY_SUBVOL:
753 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
754 fprintf(stream, "0x%016llx", (unsigned long long)objectid);
759 case BTRFS_ROOT_TREE_OBJECTID:
760 if (type == BTRFS_DEV_ITEM_KEY)
761 fprintf(stream, "DEV_ITEMS");
763 fprintf(stream, "ROOT_TREE");
765 case BTRFS_EXTENT_TREE_OBJECTID:
766 fprintf(stream, "EXTENT_TREE");
768 case BTRFS_CHUNK_TREE_OBJECTID:
769 fprintf(stream, "CHUNK_TREE");
771 case BTRFS_DEV_TREE_OBJECTID:
772 fprintf(stream, "DEV_TREE");
774 case BTRFS_FS_TREE_OBJECTID:
775 fprintf(stream, "FS_TREE");
777 case BTRFS_ROOT_TREE_DIR_OBJECTID:
778 fprintf(stream, "ROOT_TREE_DIR");
780 case BTRFS_CSUM_TREE_OBJECTID:
781 fprintf(stream, "CSUM_TREE");
783 case BTRFS_BALANCE_OBJECTID:
784 fprintf(stream, "BALANCE");
786 case BTRFS_ORPHAN_OBJECTID:
787 fprintf(stream, "ORPHAN");
789 case BTRFS_TREE_LOG_OBJECTID:
790 fprintf(stream, "TREE_LOG");
792 case BTRFS_TREE_LOG_FIXUP_OBJECTID:
793 fprintf(stream, "LOG_FIXUP");
795 case BTRFS_TREE_RELOC_OBJECTID:
796 fprintf(stream, "TREE_RELOC");
798 case BTRFS_DATA_RELOC_TREE_OBJECTID:
799 fprintf(stream, "DATA_RELOC_TREE");
801 case BTRFS_EXTENT_CSUM_OBJECTID:
802 fprintf(stream, "EXTENT_CSUM");
804 case BTRFS_FREE_SPACE_OBJECTID:
805 fprintf(stream, "FREE_SPACE");
807 case BTRFS_FREE_INO_OBJECTID:
808 fprintf(stream, "FREE_INO");
810 case BTRFS_QUOTA_TREE_OBJECTID:
811 fprintf(stream, "QUOTA_TREE");
813 case BTRFS_UUID_TREE_OBJECTID:
814 fprintf(stream, "UUID_TREE");
816 case BTRFS_FREE_SPACE_TREE_OBJECTID:
817 fprintf(stream, "FREE_SPACE_TREE");
819 case BTRFS_MULTIPLE_OBJECTIDS:
820 fprintf(stream, "MULTIPLE");
823 fprintf(stream, "-1");
825 case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
826 if (type == BTRFS_CHUNK_ITEM_KEY) {
827 fprintf(stream, "FIRST_CHUNK_TREE");
832 fprintf(stream, "%llu", (unsigned long long)objectid);
836 void btrfs_print_key(struct btrfs_disk_key *disk_key)
838 u64 objectid = btrfs_disk_key_objectid(disk_key);
839 u8 type = btrfs_disk_key_type(disk_key);
840 u64 offset = btrfs_disk_key_offset(disk_key);
843 print_objectid(stdout, objectid, type);
845 print_key_type(stdout, objectid, type);
847 case BTRFS_QGROUP_RELATION_KEY:
848 case BTRFS_QGROUP_INFO_KEY:
849 case BTRFS_QGROUP_LIMIT_KEY:
850 printf(" %llu/%llu)", btrfs_qgroup_level(offset),
851 btrfs_qgroup_subvid(offset));
853 case BTRFS_UUID_KEY_SUBVOL:
854 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
855 printf(" 0x%016llx)", (unsigned long long)offset);
858 if (offset == (u64)-1)
861 printf(" %llu)", (unsigned long long)offset);
866 static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
869 if (item_size & (sizeof(u64) - 1)) {
870 printf("btrfs: uuid item with illegal size %lu!\n",
871 (unsigned long)item_size);
877 read_extent_buffer(l, &subvol_id, offset, sizeof(u64));
878 printf("\t\tsubvol_id %llu\n",
879 (unsigned long long)le64_to_cpu(subvol_id));
880 item_size -= sizeof(u64);
881 offset += sizeof(u64);
885 /* Btrfs inode flag stringification helper */
886 #define STRCAT_ONE_INODE_FLAG(flags, name, empty, dst) ({ \
887 if (flags & BTRFS_INODE_##name) { \
890 strcat(dst, #name); \
896 * Caller should ensure sizeof(*ret) >= 102: all charactors plus '|' of
897 * BTRFS_INODE_* flags
899 static void inode_flags_to_str(u64 flags, char *ret)
903 STRCAT_ONE_INODE_FLAG(flags, NODATASUM, empty, ret);
904 STRCAT_ONE_INODE_FLAG(flags, NODATACOW, empty, ret);
905 STRCAT_ONE_INODE_FLAG(flags, READONLY, empty, ret);
906 STRCAT_ONE_INODE_FLAG(flags, NOCOMPRESS, empty, ret);
907 STRCAT_ONE_INODE_FLAG(flags, PREALLOC, empty, ret);
908 STRCAT_ONE_INODE_FLAG(flags, SYNC, empty, ret);
909 STRCAT_ONE_INODE_FLAG(flags, IMMUTABLE, empty, ret);
910 STRCAT_ONE_INODE_FLAG(flags, APPEND, empty, ret);
911 STRCAT_ONE_INODE_FLAG(flags, NODUMP, empty, ret);
912 STRCAT_ONE_INODE_FLAG(flags, NOATIME, empty, ret);
913 STRCAT_ONE_INODE_FLAG(flags, DIRSYNC, empty, ret);
914 STRCAT_ONE_INODE_FLAG(flags, COMPRESS, empty, ret);
919 static void print_timespec(struct extent_buffer *eb,
920 struct btrfs_timespec *timespec, const char *prefix,
929 tmp_u64 = btrfs_timespec_sec(eb, timespec);
930 tmp_u32 = btrfs_timespec_nsec(eb, timespec);
932 localtime_r(&tmp_time, &tm);
933 strftime(timestamp, sizeof(timestamp),
934 "%Y-%m-%d %H:%M:%S", &tm);
935 printf("%s%llu.%u (%s)%s", prefix, (unsigned long long)tmp_u64, tmp_u32,
939 static void print_inode_item(struct extent_buffer *eb,
940 struct btrfs_inode_item *ii)
944 memset(flags_str, 0, sizeof(flags_str));
945 inode_flags_to_str(btrfs_inode_flags(eb, ii), flags_str);
946 printf("\t\tinode generation %llu transid %llu size %llu nbytes %llu\n"
947 "\t\tblock group %llu mode %o links %u uid %u gid %u rdev %llu\n"
948 "\t\tsequence %llu flags 0x%llx(%s)\n",
949 (unsigned long long)btrfs_inode_generation(eb, ii),
950 (unsigned long long)btrfs_inode_transid(eb, ii),
951 (unsigned long long)btrfs_inode_size(eb, ii),
952 (unsigned long long)btrfs_inode_nbytes(eb, ii),
953 (unsigned long long)btrfs_inode_block_group(eb,ii),
954 btrfs_inode_mode(eb, ii),
955 btrfs_inode_nlink(eb, ii),
956 btrfs_inode_uid(eb, ii),
957 btrfs_inode_gid(eb, ii),
958 (unsigned long long)btrfs_inode_rdev(eb,ii),
959 (unsigned long long)btrfs_inode_flags(eb,ii),
960 (unsigned long long)btrfs_inode_sequence(eb, ii),
962 print_timespec(eb, btrfs_inode_atime(ii), "\t\tatime ", "\n");
963 print_timespec(eb, btrfs_inode_ctime(ii), "\t\tctime ", "\n");
964 print_timespec(eb, btrfs_inode_mtime(ii), "\t\tmtime ", "\n");
965 print_timespec(eb, btrfs_inode_otime(ii), "\t\totime ", "\n");
968 static void print_disk_balance_args(struct btrfs_disk_balance_args *ba)
970 printf("\t\tprofiles %llu devid %llu target %llu flags %llu\n",
971 (unsigned long long)le64_to_cpu(ba->profiles),
972 (unsigned long long)le64_to_cpu(ba->devid),
973 (unsigned long long)le64_to_cpu(ba->target),
974 (unsigned long long)le64_to_cpu(ba->flags));
975 printf("\t\tusage_min %u usage_max %u pstart %llu pend %llu\n",
976 le32_to_cpu(ba->usage_min),
977 le32_to_cpu(ba->usage_max),
978 (unsigned long long)le64_to_cpu(ba->pstart),
979 (unsigned long long)le64_to_cpu(ba->pend));
980 printf("\t\tvstart %llu vend %llu limit_min %u limit_max %u\n",
981 (unsigned long long)le64_to_cpu(ba->vstart),
982 (unsigned long long)le64_to_cpu(ba->vend),
983 le32_to_cpu(ba->limit_min),
984 le32_to_cpu(ba->limit_max));
985 printf("\t\tstripes_min %u stripes_max %u\n",
986 le32_to_cpu(ba->stripes_min),
987 le32_to_cpu(ba->stripes_max));
990 static void print_balance_item(struct extent_buffer *eb,
991 struct btrfs_balance_item *bi)
993 printf("\t\tbalance status flags %llu\n",
994 btrfs_balance_item_flags(eb, bi));
996 printf("\t\tDATA\n");
997 print_disk_balance_args(btrfs_balance_item_data(eb, bi));
998 printf("\t\tMETADATA\n");
999 print_disk_balance_args(btrfs_balance_item_meta(eb, bi));
1000 printf("\t\tSYSTEM\n");
1001 print_disk_balance_args(btrfs_balance_item_sys(eb, bi));
1004 static void print_dev_stats(struct extent_buffer *eb,
1005 struct btrfs_dev_stats_item *stats, u32 size)
1008 u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64);
1009 __le64 *values = btrfs_dev_stats_values(eb, stats);
1011 printf("\t\tdevice stats\n");
1012 printf("\t\twrite_errs %llu read_errs %llu flush_errs %llu corruption_errs %llu generation %llu\n",
1013 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_WRITE_ERRS]),
1014 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_READ_ERRS]),
1015 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_FLUSH_ERRS]),
1016 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_CORRUPTION_ERRS]),
1017 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_GENERATION_ERRS]));
1020 printf("\t\tunknown stats item bytes %u", size - known);
1021 for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
1022 printf("\t\tunknown item %u offset %lu value %llu\n",
1023 i, i * sizeof(__le64),
1024 (unsigned long long)le64_to_cpu(values[i]));
1029 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
1033 struct btrfs_item *item;
1034 struct btrfs_extent_data_ref *dref;
1035 struct btrfs_shared_data_ref *sref;
1036 struct btrfs_dev_extent *dev_extent;
1037 struct btrfs_disk_key disk_key;
1038 struct btrfs_block_group_item bg_item;
1039 struct btrfs_free_space_info *free_info;
1040 struct btrfs_dir_log_item *dlog;
1041 struct btrfs_qgroup_info_item *qg_info;
1042 struct btrfs_qgroup_limit_item *qg_limit;
1043 struct btrfs_qgroup_status_item *qg_status;
1044 u32 nr = btrfs_header_nritems(eb);
1048 char flags_str[256];
1049 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
1050 u8 uuid[BTRFS_UUID_SIZE];
1052 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
1053 (unsigned long long)btrfs_header_bytenr(eb), nr,
1054 btrfs_leaf_free_space(root, eb),
1055 (unsigned long long)btrfs_header_generation(eb),
1056 (unsigned long long)btrfs_header_owner(eb));
1059 for (i = 0 ; i < nr ; i++) {
1063 item = btrfs_item_nr(i);
1064 item_size = btrfs_item_size(eb, item);
1065 /* Untyped extraction of slot from btrfs_item_ptr */
1066 ptr = btrfs_item_ptr(eb, i, void*);
1067 btrfs_item_key(eb, &disk_key, i);
1068 objectid = btrfs_disk_key_objectid(&disk_key);
1069 type = btrfs_disk_key_type(&disk_key);
1070 offset = btrfs_disk_key_offset(&disk_key);
1071 printf("\titem %d ", i);
1072 btrfs_print_key(&disk_key);
1073 printf(" itemoff %d itemsize %d\n",
1074 btrfs_item_offset(eb, item),
1075 btrfs_item_size(eb, item));
1077 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID)
1078 print_free_space_header(eb, i);
1081 case BTRFS_INODE_ITEM_KEY:
1082 print_inode_item(eb, ptr);
1084 case BTRFS_INODE_REF_KEY:
1085 print_inode_ref_item(eb, item_size, ptr);
1087 case BTRFS_INODE_EXTREF_KEY:
1088 print_inode_extref_item(eb, item_size, ptr);
1090 case BTRFS_DIR_ITEM_KEY:
1091 case BTRFS_DIR_INDEX_KEY:
1092 case BTRFS_XATTR_ITEM_KEY:
1093 print_dir_item(eb, item_size, ptr);
1095 case BTRFS_DIR_LOG_INDEX_KEY:
1096 case BTRFS_DIR_LOG_ITEM_KEY:
1097 dlog = btrfs_item_ptr(eb, i, struct btrfs_dir_log_item);
1098 printf("\t\tdir log end %Lu\n",
1099 (unsigned long long)btrfs_dir_log_end(eb, dlog));
1101 case BTRFS_ORPHAN_ITEM_KEY:
1102 printf("\t\torphan item\n");
1104 case BTRFS_ROOT_ITEM_KEY:
1107 case BTRFS_ROOT_REF_KEY:
1108 print_root_ref(eb, i, "ref");
1110 case BTRFS_ROOT_BACKREF_KEY:
1111 print_root_ref(eb, i, "backref");
1113 case BTRFS_EXTENT_ITEM_KEY:
1114 print_extent_item(eb, i, 0);
1116 case BTRFS_METADATA_ITEM_KEY:
1117 print_extent_item(eb, i, 1);
1119 case BTRFS_TREE_BLOCK_REF_KEY:
1120 printf("\t\ttree block backref\n");
1122 case BTRFS_SHARED_BLOCK_REF_KEY:
1123 printf("\t\tshared block backref\n");
1125 case BTRFS_EXTENT_DATA_REF_KEY:
1126 dref = btrfs_item_ptr(eb, i, struct btrfs_extent_data_ref);
1127 printf("\t\textent data backref root %llu "
1128 "objectid %llu offset %llu count %u\n",
1129 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
1130 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
1131 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
1132 btrfs_extent_data_ref_count(eb, dref));
1134 case BTRFS_SHARED_DATA_REF_KEY:
1135 sref = btrfs_item_ptr(eb, i, struct btrfs_shared_data_ref);
1136 printf("\t\tshared data backref count %u\n",
1137 btrfs_shared_data_ref_count(eb, sref));
1139 case BTRFS_EXTENT_REF_V0_KEY:
1140 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1141 print_extent_ref_v0(eb, i);
1146 case BTRFS_CSUM_ITEM_KEY:
1147 printf("\t\tcsum item\n");
1149 case BTRFS_EXTENT_CSUM_KEY:
1150 printf("\t\textent csum item\n");
1152 case BTRFS_EXTENT_DATA_KEY:
1153 print_file_extent_item(eb, item, i, ptr);
1155 case BTRFS_BLOCK_GROUP_ITEM_KEY:
1156 read_extent_buffer(eb, &bg_item, (unsigned long)ptr,
1158 memset(flags_str, 0, sizeof(flags_str));
1159 bg_flags_to_str(btrfs_block_group_flags(&bg_item),
1161 printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
1162 (unsigned long long)btrfs_block_group_used(&bg_item),
1163 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
1166 case BTRFS_FREE_SPACE_INFO_KEY:
1167 free_info = btrfs_item_ptr(eb, i, struct btrfs_free_space_info);
1168 printf("\t\tfree space info extent count %u flags %u\n",
1169 (unsigned)btrfs_free_space_extent_count(eb, free_info),
1170 (unsigned)btrfs_free_space_flags(eb, free_info));
1172 case BTRFS_FREE_SPACE_EXTENT_KEY:
1173 printf("\t\tfree space extent\n");
1175 case BTRFS_FREE_SPACE_BITMAP_KEY:
1176 printf("\t\tfree space bitmap\n");
1178 case BTRFS_CHUNK_ITEM_KEY:
1179 print_chunk(eb, ptr);
1181 case BTRFS_DEV_ITEM_KEY:
1182 print_dev_item(eb, ptr);
1184 case BTRFS_DEV_EXTENT_KEY:
1185 dev_extent = btrfs_item_ptr(eb, i,
1186 struct btrfs_dev_extent);
1187 read_extent_buffer(eb, uuid,
1188 (unsigned long)btrfs_dev_extent_chunk_tree_uuid(dev_extent),
1190 uuid_unparse(uuid, uuid_str);
1191 printf("\t\tdev extent chunk_tree %llu\n"
1192 "\t\tchunk_objectid %llu chunk_offset %llu "
1194 "\t\tchunk_tree_uuid %s\n",
1195 (unsigned long long)
1196 btrfs_dev_extent_chunk_tree(eb, dev_extent),
1197 (unsigned long long)
1198 btrfs_dev_extent_chunk_objectid(eb, dev_extent),
1199 (unsigned long long)
1200 btrfs_dev_extent_chunk_offset(eb, dev_extent),
1201 (unsigned long long)
1202 btrfs_dev_extent_length(eb, dev_extent),
1205 case BTRFS_QGROUP_STATUS_KEY:
1206 qg_status = btrfs_item_ptr(eb, i,
1207 struct btrfs_qgroup_status_item);
1208 memset(flags_str, 0, sizeof(flags_str));
1209 qgroup_flags_to_str(btrfs_qgroup_status_flags(eb, qg_status),
1211 printf("\t\tversion %llu generation %llu flags %s "
1213 (unsigned long long)
1214 btrfs_qgroup_status_version(eb, qg_status),
1215 (unsigned long long)
1216 btrfs_qgroup_status_generation(eb, qg_status),
1218 (unsigned long long)
1219 btrfs_qgroup_status_rescan(eb, qg_status));
1221 case BTRFS_QGROUP_RELATION_KEY:
1223 case BTRFS_QGROUP_INFO_KEY:
1224 qg_info = btrfs_item_ptr(eb, i,
1225 struct btrfs_qgroup_info_item);
1226 printf("\t\tgeneration %llu\n"
1227 "\t\treferenced %llu referenced_compressed %llu\n"
1228 "\t\texclusive %llu exclusive_compressed %llu\n",
1229 (unsigned long long)
1230 btrfs_qgroup_info_generation(eb, qg_info),
1231 (unsigned long long)
1232 btrfs_qgroup_info_referenced(eb, qg_info),
1233 (unsigned long long)
1234 btrfs_qgroup_info_referenced_compressed(eb,
1236 (unsigned long long)
1237 btrfs_qgroup_info_exclusive(eb, qg_info),
1238 (unsigned long long)
1239 btrfs_qgroup_info_exclusive_compressed(eb,
1242 case BTRFS_QGROUP_LIMIT_KEY:
1243 qg_limit = btrfs_item_ptr(eb, i,
1244 struct btrfs_qgroup_limit_item);
1245 printf("\t\tflags %llx\n"
1246 "\t\tmax_referenced %lld max_exclusive %lld\n"
1247 "\t\trsv_referenced %lld rsv_exclusive %lld\n",
1248 (unsigned long long)
1249 btrfs_qgroup_limit_flags(eb, qg_limit),
1251 btrfs_qgroup_limit_max_referenced(eb, qg_limit),
1253 btrfs_qgroup_limit_max_exclusive(eb, qg_limit),
1255 btrfs_qgroup_limit_rsv_referenced(eb, qg_limit),
1257 btrfs_qgroup_limit_rsv_exclusive(eb, qg_limit));
1259 case BTRFS_UUID_KEY_SUBVOL:
1260 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
1261 print_uuid_item(eb, btrfs_item_ptr_offset(eb, i),
1262 btrfs_item_size_nr(eb, i));
1264 case BTRFS_STRING_ITEM_KEY:
1265 /* dirty, but it's simple */
1266 str = eb->data + btrfs_item_ptr_offset(eb, i);
1267 printf("\t\titem data %.*s\n", item_size, str);
1269 case BTRFS_PERSISTENT_ITEM_KEY:
1270 printf("\t\tpersistent item objectid ");
1271 print_objectid(stdout, objectid, BTRFS_PERSISTENT_ITEM_KEY);
1272 printf(" offset %llu\n", (unsigned long long)offset);
1274 case BTRFS_DEV_STATS_OBJECTID:
1275 print_dev_stats(eb, ptr, item_size);
1278 printf("\t\tunknown persistent item objectid %llu\n",
1282 case BTRFS_TEMPORARY_ITEM_KEY:
1283 printf("\t\ttemporary item objectid ");
1284 print_objectid(stdout, objectid, BTRFS_TEMPORARY_ITEM_KEY);
1285 printf(" offset %llu\n", (unsigned long long)offset);
1287 case BTRFS_BALANCE_OBJECTID:
1288 print_balance_item(eb, ptr);
1291 printf("\t\tunknown temporary item objectid %llu\n",
1300 void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
1305 struct btrfs_disk_key disk_key;
1306 struct btrfs_key key;
1307 struct extent_buffer *next;
1311 nr = btrfs_header_nritems(eb);
1312 if (btrfs_is_leaf(eb)) {
1313 btrfs_print_leaf(root, eb);
1316 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
1317 (unsigned long long)eb->start,
1318 btrfs_header_level(eb), nr,
1319 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
1320 (unsigned long long)btrfs_header_generation(eb),
1321 (unsigned long long)btrfs_header_owner(eb));
1324 size = root->nodesize;
1325 for (i = 0; i < nr; i++) {
1326 u64 blocknr = btrfs_node_blockptr(eb, i);
1327 btrfs_node_key(eb, &disk_key, i);
1328 btrfs_disk_key_to_cpu(&key, &disk_key);
1330 btrfs_print_key(&disk_key);
1331 printf(" block %llu (%llu) gen %llu\n",
1332 (unsigned long long)blocknr,
1333 (unsigned long long)blocknr / size,
1334 (unsigned long long)btrfs_node_ptr_generation(eb, i));
1340 for (i = 0; i < nr; i++) {
1341 next = read_tree_block(root, btrfs_node_blockptr(eb, i), size,
1342 btrfs_node_ptr_generation(eb, i));
1343 if (!extent_buffer_uptodate(next)) {
1344 fprintf(stderr, "failed to read %llu in tree %llu\n",
1345 (unsigned long long)btrfs_node_blockptr(eb, i),
1346 (unsigned long long)btrfs_header_owner(eb));
1349 if (btrfs_is_leaf(next) && btrfs_header_level(eb) != 1) {
1351 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1352 i, btrfs_header_level(next),
1353 btrfs_header_level(eb));
1356 if (btrfs_header_level(next) != btrfs_header_level(eb) - 1) {
1358 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1359 i, btrfs_header_level(next),
1360 btrfs_header_level(eb));
1363 btrfs_print_tree(root, next, 1);
1364 free_extent_buffer(next);
1370 free_extent_buffer(next);