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 static const char* key_to_str[256] = {
614 [BTRFS_INODE_ITEM_KEY] = "INODE_ITEM",
615 [BTRFS_INODE_REF_KEY] = "INODE_REF",
616 [BTRFS_INODE_EXTREF_KEY] = "INODE_EXTREF",
617 [BTRFS_DIR_ITEM_KEY] = "DIR_ITEM",
618 [BTRFS_DIR_INDEX_KEY] = "DIR_INDEX",
619 [BTRFS_DIR_LOG_ITEM_KEY] = "DIR_LOG_ITEM",
620 [BTRFS_DIR_LOG_INDEX_KEY] = "DIR_LOG_INDEX",
621 [BTRFS_XATTR_ITEM_KEY] = "XATTR_ITEM",
622 [BTRFS_ORPHAN_ITEM_KEY] = "ORPHAN_ITEM",
623 [BTRFS_ROOT_ITEM_KEY] = "ROOT_ITEM",
624 [BTRFS_ROOT_REF_KEY] = "ROOT_REF",
625 [BTRFS_ROOT_BACKREF_KEY] = "ROOT_BACKREF",
626 [BTRFS_EXTENT_ITEM_KEY] = "EXTENT_ITEM",
627 [BTRFS_METADATA_ITEM_KEY] = "METADATA_ITEM",
628 [BTRFS_TREE_BLOCK_REF_KEY] = "TREE_BLOCK_REF",
629 [BTRFS_SHARED_BLOCK_REF_KEY] = "SHARED_BLOCK_REF",
630 [BTRFS_EXTENT_DATA_REF_KEY] = "EXTENT_DATA_REF",
631 [BTRFS_SHARED_DATA_REF_KEY] = "SHARED_DATA_REF",
632 [BTRFS_EXTENT_REF_V0_KEY] = "EXTENT_REF_V0",
633 [BTRFS_CSUM_ITEM_KEY] = "CSUM_ITEM",
634 [BTRFS_EXTENT_CSUM_KEY] = "EXTENT_CSUM",
635 [BTRFS_EXTENT_DATA_KEY] = "EXTENT_DATA",
636 [BTRFS_BLOCK_GROUP_ITEM_KEY] = "BLOCK_GROUP_ITEM",
637 [BTRFS_FREE_SPACE_INFO_KEY] = "FREE_SPACE_INFO",
638 [BTRFS_FREE_SPACE_EXTENT_KEY] = "FREE_SPACE_EXTENT",
639 [BTRFS_FREE_SPACE_BITMAP_KEY] = "FREE_SPACE_BITMAP",
640 [BTRFS_CHUNK_ITEM_KEY] = "CHUNK_ITEM",
641 [BTRFS_DEV_ITEM_KEY] = "DEV_ITEM",
642 [BTRFS_DEV_EXTENT_KEY] = "DEV_EXTENT",
643 [BTRFS_BALANCE_ITEM_KEY] = "BALANCE_ITEM",
644 [BTRFS_DEV_REPLACE_KEY] = "DEV_REPLACE",
645 [BTRFS_STRING_ITEM_KEY] = "STRING_ITEM",
646 [BTRFS_QGROUP_STATUS_KEY] = "QGROUP_STATUS",
647 [BTRFS_QGROUP_RELATION_KEY] = "QGROUP_RELATION",
648 [BTRFS_QGROUP_INFO_KEY] = "QGROUP_INFO",
649 [BTRFS_QGROUP_LIMIT_KEY] = "QGROUP_LIMIT",
650 [BTRFS_DEV_STATS_KEY] = "DEV_STATS",
651 [BTRFS_UUID_KEY_SUBVOL] = "UUID_KEY_SUBVOL",
652 [BTRFS_UUID_KEY_RECEIVED_SUBVOL] = "UUID_KEY_RECEIVED_SUBVOL",
655 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
656 fprintf(stream, "UNTYPED");
661 if (key_to_str[type])
662 fputs(key_to_str[type], stream);
664 fprintf(stream, "UNKNOWN.%d", type);
667 void print_objectid(FILE *stream, u64 objectid, u8 type)
670 case BTRFS_DEV_EXTENT_KEY:
672 fprintf(stream, "%llu", (unsigned long long)objectid);
674 case BTRFS_QGROUP_RELATION_KEY:
675 fprintf(stream, "%llu/%llu", btrfs_qgroup_level(objectid),
676 btrfs_qgroup_subvid(objectid));
678 case BTRFS_UUID_KEY_SUBVOL:
679 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
680 fprintf(stream, "0x%016llx", (unsigned long long)objectid);
685 case BTRFS_ROOT_TREE_OBJECTID:
686 if (type == BTRFS_DEV_ITEM_KEY)
687 fprintf(stream, "DEV_ITEMS");
689 fprintf(stream, "ROOT_TREE");
691 case BTRFS_EXTENT_TREE_OBJECTID:
692 fprintf(stream, "EXTENT_TREE");
694 case BTRFS_CHUNK_TREE_OBJECTID:
695 fprintf(stream, "CHUNK_TREE");
697 case BTRFS_DEV_TREE_OBJECTID:
698 fprintf(stream, "DEV_TREE");
700 case BTRFS_FS_TREE_OBJECTID:
701 fprintf(stream, "FS_TREE");
703 case BTRFS_ROOT_TREE_DIR_OBJECTID:
704 fprintf(stream, "ROOT_TREE_DIR");
706 case BTRFS_CSUM_TREE_OBJECTID:
707 fprintf(stream, "CSUM_TREE");
709 case BTRFS_BALANCE_OBJECTID:
710 fprintf(stream, "BALANCE");
712 case BTRFS_ORPHAN_OBJECTID:
713 fprintf(stream, "ORPHAN");
715 case BTRFS_TREE_LOG_OBJECTID:
716 fprintf(stream, "TREE_LOG");
718 case BTRFS_TREE_LOG_FIXUP_OBJECTID:
719 fprintf(stream, "LOG_FIXUP");
721 case BTRFS_TREE_RELOC_OBJECTID:
722 fprintf(stream, "TREE_RELOC");
724 case BTRFS_DATA_RELOC_TREE_OBJECTID:
725 fprintf(stream, "DATA_RELOC_TREE");
727 case BTRFS_EXTENT_CSUM_OBJECTID:
728 fprintf(stream, "EXTENT_CSUM");
730 case BTRFS_FREE_SPACE_OBJECTID:
731 fprintf(stream, "FREE_SPACE");
733 case BTRFS_FREE_INO_OBJECTID:
734 fprintf(stream, "FREE_INO");
736 case BTRFS_QUOTA_TREE_OBJECTID:
737 fprintf(stream, "QUOTA_TREE");
739 case BTRFS_UUID_TREE_OBJECTID:
740 fprintf(stream, "UUID_TREE");
742 case BTRFS_FREE_SPACE_TREE_OBJECTID:
743 fprintf(stream, "FREE_SPACE_TREE");
745 case BTRFS_MULTIPLE_OBJECTIDS:
746 fprintf(stream, "MULTIPLE");
749 fprintf(stream, "-1");
751 case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
752 if (type == BTRFS_CHUNK_ITEM_KEY) {
753 fprintf(stream, "FIRST_CHUNK_TREE");
758 fprintf(stream, "%llu", (unsigned long long)objectid);
762 void btrfs_print_key(struct btrfs_disk_key *disk_key)
764 u64 objectid = btrfs_disk_key_objectid(disk_key);
765 u8 type = btrfs_disk_key_type(disk_key);
766 u64 offset = btrfs_disk_key_offset(disk_key);
769 print_objectid(stdout, objectid, type);
771 print_key_type(stdout, objectid, type);
773 case BTRFS_QGROUP_RELATION_KEY:
774 case BTRFS_QGROUP_INFO_KEY:
775 case BTRFS_QGROUP_LIMIT_KEY:
776 printf(" %llu/%llu)", btrfs_qgroup_level(offset),
777 btrfs_qgroup_subvid(offset));
779 case BTRFS_UUID_KEY_SUBVOL:
780 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
781 printf(" 0x%016llx)", (unsigned long long)offset);
784 if (offset == (u64)-1)
787 printf(" %llu)", (unsigned long long)offset);
792 static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
795 if (item_size & (sizeof(u64) - 1)) {
796 printf("btrfs: uuid item with illegal size %lu!\n",
797 (unsigned long)item_size);
803 read_extent_buffer(l, &subvol_id, offset, sizeof(u64));
804 printf("\t\tsubvol_id %llu\n",
805 (unsigned long long)le64_to_cpu(subvol_id));
806 item_size -= sizeof(u64);
807 offset += sizeof(u64);
811 /* Btrfs inode flag stringification helper */
812 #define STRCAT_ONE_INODE_FLAG(flags, name, empty, dst) ({ \
813 if (flags & BTRFS_INODE_##name) { \
816 strcat(dst, #name); \
822 * Caller should ensure sizeof(*ret) >= 102: all charactors plus '|' of
823 * BTRFS_INODE_* flags
825 static void inode_flags_to_str(u64 flags, char *ret)
829 STRCAT_ONE_INODE_FLAG(flags, NODATASUM, empty, ret);
830 STRCAT_ONE_INODE_FLAG(flags, NODATACOW, empty, ret);
831 STRCAT_ONE_INODE_FLAG(flags, READONLY, empty, ret);
832 STRCAT_ONE_INODE_FLAG(flags, NOCOMPRESS, empty, ret);
833 STRCAT_ONE_INODE_FLAG(flags, PREALLOC, empty, ret);
834 STRCAT_ONE_INODE_FLAG(flags, SYNC, empty, ret);
835 STRCAT_ONE_INODE_FLAG(flags, IMMUTABLE, empty, ret);
836 STRCAT_ONE_INODE_FLAG(flags, APPEND, empty, ret);
837 STRCAT_ONE_INODE_FLAG(flags, NODUMP, empty, ret);
838 STRCAT_ONE_INODE_FLAG(flags, NOATIME, empty, ret);
839 STRCAT_ONE_INODE_FLAG(flags, DIRSYNC, empty, ret);
840 STRCAT_ONE_INODE_FLAG(flags, COMPRESS, empty, ret);
845 static void print_timespec(struct extent_buffer *eb,
846 struct btrfs_timespec *timespec, const char *prefix,
855 tmp_u64 = btrfs_timespec_sec(eb, timespec);
856 tmp_u32 = btrfs_timespec_nsec(eb, timespec);
858 localtime_r(&tmp_time, &tm);
859 strftime(timestamp, sizeof(timestamp),
860 "%Y-%m-%d %H:%M:%S", &tm);
861 printf("%s%llu.%u (%s)%s", prefix, (unsigned long long)tmp_u64, tmp_u32,
865 static void print_inode_item(struct extent_buffer *eb,
866 struct btrfs_inode_item *ii)
870 memset(flags_str, 0, sizeof(flags_str));
871 inode_flags_to_str(btrfs_inode_flags(eb, ii), flags_str);
872 printf("\t\tinode generation %llu transid %llu size %llu nbytes %llu\n"
873 "\t\tblock group %llu mode %o links %u uid %u gid %u rdev %llu\n"
874 "\t\tsequence %llu flags 0x%llx(%s)\n",
875 (unsigned long long)btrfs_inode_generation(eb, ii),
876 (unsigned long long)btrfs_inode_transid(eb, ii),
877 (unsigned long long)btrfs_inode_size(eb, ii),
878 (unsigned long long)btrfs_inode_nbytes(eb, ii),
879 (unsigned long long)btrfs_inode_block_group(eb,ii),
880 btrfs_inode_mode(eb, ii),
881 btrfs_inode_nlink(eb, ii),
882 btrfs_inode_uid(eb, ii),
883 btrfs_inode_gid(eb, ii),
884 (unsigned long long)btrfs_inode_rdev(eb,ii),
885 (unsigned long long)btrfs_inode_flags(eb,ii),
886 (unsigned long long)btrfs_inode_sequence(eb, ii),
888 print_timespec(eb, btrfs_inode_atime(ii), "\t\tatime ", "\n");
889 print_timespec(eb, btrfs_inode_ctime(ii), "\t\tctime ", "\n");
890 print_timespec(eb, btrfs_inode_mtime(ii), "\t\tmtime ", "\n");
891 print_timespec(eb, btrfs_inode_otime(ii), "\t\totime ", "\n");
894 static void print_disk_balance_args(struct btrfs_disk_balance_args *ba)
896 printf("\t\tprofiles %llu devid %llu target %llu flags %llu\n",
897 (unsigned long long)le64_to_cpu(ba->profiles),
898 (unsigned long long)le64_to_cpu(ba->devid),
899 (unsigned long long)le64_to_cpu(ba->target),
900 (unsigned long long)le64_to_cpu(ba->flags));
901 printf("\t\tusage_min %u usage_max %u pstart %llu pend %llu\n",
902 le32_to_cpu(ba->usage_min),
903 le32_to_cpu(ba->usage_max),
904 (unsigned long long)le64_to_cpu(ba->pstart),
905 (unsigned long long)le64_to_cpu(ba->pend));
906 printf("\t\tvstart %llu vend %llu limit_min %u limit_max %u\n",
907 (unsigned long long)le64_to_cpu(ba->vstart),
908 (unsigned long long)le64_to_cpu(ba->vend),
909 le32_to_cpu(ba->limit_min),
910 le32_to_cpu(ba->limit_max));
911 printf("\t\tstripes_min %u stripes_max %u\n",
912 le32_to_cpu(ba->stripes_min),
913 le32_to_cpu(ba->stripes_max));
916 static void print_balance_item(struct extent_buffer *eb,
917 struct btrfs_balance_item *bi)
919 printf("\t\tbalance status flags %llu\n",
920 btrfs_balance_item_flags(eb, bi));
922 printf("\t\tDATA\n");
923 print_disk_balance_args(btrfs_balance_item_data(eb, bi));
924 printf("\t\tMETADATA\n");
925 print_disk_balance_args(btrfs_balance_item_meta(eb, bi));
926 printf("\t\tSYSTEM\n");
927 print_disk_balance_args(btrfs_balance_item_sys(eb, bi));
930 static void print_dev_stats(struct extent_buffer *eb,
931 struct btrfs_dev_stats_item *stats, u32 size)
934 u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64);
935 __le64 *values = btrfs_dev_stats_values(eb, stats);
937 printf("\t\tdevice stats\n");
938 printf("\t\twrite_errs %llu read_errs %llu flush_errs %llu corruption_errs %llu generation %llu\n",
939 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_WRITE_ERRS]),
940 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_READ_ERRS]),
941 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_FLUSH_ERRS]),
942 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_CORRUPTION_ERRS]),
943 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_GENERATION_ERRS]));
946 printf("\t\tunknown stats item bytes %u", size - known);
947 for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
948 printf("\t\tunknown item %u offset %lu value %llu\n",
949 i, i * sizeof(__le64),
950 (unsigned long long)le64_to_cpu(values[i]));
955 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
957 struct btrfs_item *item;
958 struct btrfs_disk_key disk_key;
962 nr = btrfs_header_nritems(eb);
964 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
965 (unsigned long long)btrfs_header_bytenr(eb), nr,
966 btrfs_leaf_free_space(root, eb),
967 (unsigned long long)btrfs_header_generation(eb),
968 (unsigned long long)btrfs_header_owner(eb));
972 for (i = 0; i < nr; i++) {
979 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
980 u8 uuid[BTRFS_UUID_SIZE];
982 item = btrfs_item_nr(i);
983 item_size = btrfs_item_size(eb, item);
984 /* Untyped extraction of slot from btrfs_item_ptr */
985 ptr = btrfs_item_ptr(eb, i, void*);
987 btrfs_item_key(eb, &disk_key, i);
988 objectid = btrfs_disk_key_objectid(&disk_key);
989 type = btrfs_disk_key_type(&disk_key);
990 offset = btrfs_disk_key_offset(&disk_key);
992 printf("\titem %d ", i);
993 btrfs_print_key(&disk_key);
994 printf(" itemoff %d itemsize %d\n",
995 btrfs_item_offset(eb, item),
996 btrfs_item_size(eb, item));
998 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID)
999 print_free_space_header(eb, i);
1002 case BTRFS_INODE_ITEM_KEY:
1003 print_inode_item(eb, ptr);
1005 case BTRFS_INODE_REF_KEY:
1006 print_inode_ref_item(eb, item_size, ptr);
1008 case BTRFS_INODE_EXTREF_KEY:
1009 print_inode_extref_item(eb, item_size, ptr);
1011 case BTRFS_DIR_ITEM_KEY:
1012 case BTRFS_DIR_INDEX_KEY:
1013 case BTRFS_XATTR_ITEM_KEY:
1014 print_dir_item(eb, item_size, ptr);
1016 case BTRFS_DIR_LOG_INDEX_KEY:
1017 case BTRFS_DIR_LOG_ITEM_KEY: {
1018 struct btrfs_dir_log_item *dlog;
1020 dlog = btrfs_item_ptr(eb, i, struct btrfs_dir_log_item);
1021 printf("\t\tdir log end %Lu\n",
1022 (unsigned long long)btrfs_dir_log_end(eb, dlog));
1025 case BTRFS_ORPHAN_ITEM_KEY:
1026 printf("\t\torphan item\n");
1028 case BTRFS_ROOT_ITEM_KEY:
1031 case BTRFS_ROOT_REF_KEY:
1032 print_root_ref(eb, i, "ref");
1034 case BTRFS_ROOT_BACKREF_KEY:
1035 print_root_ref(eb, i, "backref");
1037 case BTRFS_EXTENT_ITEM_KEY:
1038 print_extent_item(eb, i, 0);
1040 case BTRFS_METADATA_ITEM_KEY:
1041 print_extent_item(eb, i, 1);
1043 case BTRFS_TREE_BLOCK_REF_KEY:
1044 printf("\t\ttree block backref\n");
1046 case BTRFS_SHARED_BLOCK_REF_KEY:
1047 printf("\t\tshared block backref\n");
1049 case BTRFS_EXTENT_DATA_REF_KEY: {
1050 struct btrfs_extent_data_ref *dref;
1052 dref = btrfs_item_ptr(eb, i, struct btrfs_extent_data_ref);
1053 printf("\t\textent data backref root %llu "
1054 "objectid %llu offset %llu count %u\n",
1055 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
1056 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
1057 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
1058 btrfs_extent_data_ref_count(eb, dref));
1061 case BTRFS_SHARED_DATA_REF_KEY: {
1062 struct btrfs_shared_data_ref *sref;
1063 sref = btrfs_item_ptr(eb, i, struct btrfs_shared_data_ref);
1064 printf("\t\tshared data backref count %u\n",
1065 btrfs_shared_data_ref_count(eb, sref));
1068 case BTRFS_EXTENT_REF_V0_KEY:
1069 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1070 print_extent_ref_v0(eb, i);
1075 case BTRFS_CSUM_ITEM_KEY:
1076 printf("\t\tcsum item\n");
1078 case BTRFS_EXTENT_CSUM_KEY:
1079 printf("\t\textent csum item\n");
1081 case BTRFS_EXTENT_DATA_KEY:
1082 print_file_extent_item(eb, item, i, ptr);
1084 case BTRFS_BLOCK_GROUP_ITEM_KEY: {
1085 struct btrfs_block_group_item bg_item;
1087 read_extent_buffer(eb, &bg_item, (unsigned long)ptr,
1089 memset(flags_str, 0, sizeof(flags_str));
1090 bg_flags_to_str(btrfs_block_group_flags(&bg_item),
1092 printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
1093 (unsigned long long)btrfs_block_group_used(&bg_item),
1094 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
1098 case BTRFS_FREE_SPACE_INFO_KEY: {
1099 struct btrfs_free_space_info *free_info;
1101 free_info = btrfs_item_ptr(eb, i, struct btrfs_free_space_info);
1102 printf("\t\tfree space info extent count %u flags %u\n",
1103 (unsigned)btrfs_free_space_extent_count(eb, free_info),
1104 (unsigned)btrfs_free_space_flags(eb, free_info));
1107 case BTRFS_FREE_SPACE_EXTENT_KEY:
1108 printf("\t\tfree space extent\n");
1110 case BTRFS_FREE_SPACE_BITMAP_KEY:
1111 printf("\t\tfree space bitmap\n");
1113 case BTRFS_CHUNK_ITEM_KEY:
1114 print_chunk(eb, ptr);
1116 case BTRFS_DEV_ITEM_KEY:
1117 print_dev_item(eb, ptr);
1119 case BTRFS_DEV_EXTENT_KEY: {
1120 struct btrfs_dev_extent *dev_extent;
1122 dev_extent = btrfs_item_ptr(eb, i,
1123 struct btrfs_dev_extent);
1124 read_extent_buffer(eb, uuid,
1125 (unsigned long)btrfs_dev_extent_chunk_tree_uuid(dev_extent),
1127 uuid_unparse(uuid, uuid_str);
1128 printf("\t\tdev extent chunk_tree %llu\n"
1129 "\t\tchunk_objectid %llu chunk_offset %llu "
1131 "\t\tchunk_tree_uuid %s\n",
1132 (unsigned long long)
1133 btrfs_dev_extent_chunk_tree(eb, dev_extent),
1134 (unsigned long long)
1135 btrfs_dev_extent_chunk_objectid(eb, dev_extent),
1136 (unsigned long long)
1137 btrfs_dev_extent_chunk_offset(eb, dev_extent),
1138 (unsigned long long)
1139 btrfs_dev_extent_length(eb, dev_extent),
1143 case BTRFS_QGROUP_STATUS_KEY: {
1144 struct btrfs_qgroup_status_item *qg_status;
1146 qg_status = btrfs_item_ptr(eb, i,
1147 struct btrfs_qgroup_status_item);
1148 memset(flags_str, 0, sizeof(flags_str));
1149 qgroup_flags_to_str(btrfs_qgroup_status_flags(eb, qg_status),
1151 printf("\t\tversion %llu generation %llu flags %s "
1153 (unsigned long long)
1154 btrfs_qgroup_status_version(eb, qg_status),
1155 (unsigned long long)
1156 btrfs_qgroup_status_generation(eb, qg_status),
1158 (unsigned long long)
1159 btrfs_qgroup_status_rescan(eb, qg_status));
1162 case BTRFS_QGROUP_RELATION_KEY:
1164 case BTRFS_QGROUP_INFO_KEY: {
1165 struct btrfs_qgroup_info_item *qg_info;
1167 qg_info = btrfs_item_ptr(eb, i,
1168 struct btrfs_qgroup_info_item);
1169 printf("\t\tgeneration %llu\n"
1170 "\t\treferenced %llu referenced_compressed %llu\n"
1171 "\t\texclusive %llu exclusive_compressed %llu\n",
1172 (unsigned long long)
1173 btrfs_qgroup_info_generation(eb, qg_info),
1174 (unsigned long long)
1175 btrfs_qgroup_info_referenced(eb, qg_info),
1176 (unsigned long long)
1177 btrfs_qgroup_info_referenced_compressed(eb,
1179 (unsigned long long)
1180 btrfs_qgroup_info_exclusive(eb, qg_info),
1181 (unsigned long long)
1182 btrfs_qgroup_info_exclusive_compressed(eb,
1186 case BTRFS_QGROUP_LIMIT_KEY: {
1187 struct btrfs_qgroup_limit_item *qg_limit;
1189 qg_limit = btrfs_item_ptr(eb, i,
1190 struct btrfs_qgroup_limit_item);
1191 printf("\t\tflags %llx\n"
1192 "\t\tmax_referenced %lld max_exclusive %lld\n"
1193 "\t\trsv_referenced %lld rsv_exclusive %lld\n",
1194 (unsigned long long)
1195 btrfs_qgroup_limit_flags(eb, qg_limit),
1197 btrfs_qgroup_limit_max_referenced(eb, qg_limit),
1199 btrfs_qgroup_limit_max_exclusive(eb, qg_limit),
1201 btrfs_qgroup_limit_rsv_referenced(eb, qg_limit),
1203 btrfs_qgroup_limit_rsv_exclusive(eb, qg_limit));
1206 case BTRFS_UUID_KEY_SUBVOL:
1207 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
1208 print_uuid_item(eb, btrfs_item_ptr_offset(eb, i),
1209 btrfs_item_size_nr(eb, i));
1211 case BTRFS_STRING_ITEM_KEY: {
1212 const char *str = eb->data + btrfs_item_ptr_offset(eb, i);
1214 printf("\t\titem data %.*s\n", item_size, str);
1217 case BTRFS_PERSISTENT_ITEM_KEY:
1218 printf("\t\tpersistent item objectid ");
1219 print_objectid(stdout, objectid, BTRFS_PERSISTENT_ITEM_KEY);
1220 printf(" offset %llu\n", (unsigned long long)offset);
1222 case BTRFS_DEV_STATS_OBJECTID:
1223 print_dev_stats(eb, ptr, item_size);
1226 printf("\t\tunknown persistent item objectid %llu\n",
1230 case BTRFS_TEMPORARY_ITEM_KEY:
1231 printf("\t\ttemporary item objectid ");
1232 print_objectid(stdout, objectid, BTRFS_TEMPORARY_ITEM_KEY);
1233 printf(" offset %llu\n", (unsigned long long)offset);
1235 case BTRFS_BALANCE_OBJECTID:
1236 print_balance_item(eb, ptr);
1239 printf("\t\tunknown temporary item objectid %llu\n",
1248 void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
1253 struct btrfs_disk_key disk_key;
1254 struct btrfs_key key;
1255 struct extent_buffer *next;
1259 nr = btrfs_header_nritems(eb);
1260 if (btrfs_is_leaf(eb)) {
1261 btrfs_print_leaf(root, eb);
1264 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
1265 (unsigned long long)eb->start,
1266 btrfs_header_level(eb), nr,
1267 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
1268 (unsigned long long)btrfs_header_generation(eb),
1269 (unsigned long long)btrfs_header_owner(eb));
1272 size = root->nodesize;
1273 for (i = 0; i < nr; i++) {
1274 u64 blocknr = btrfs_node_blockptr(eb, i);
1275 btrfs_node_key(eb, &disk_key, i);
1276 btrfs_disk_key_to_cpu(&key, &disk_key);
1278 btrfs_print_key(&disk_key);
1279 printf(" block %llu (%llu) gen %llu\n",
1280 (unsigned long long)blocknr,
1281 (unsigned long long)blocknr / size,
1282 (unsigned long long)btrfs_node_ptr_generation(eb, i));
1288 for (i = 0; i < nr; i++) {
1289 next = read_tree_block(root, btrfs_node_blockptr(eb, i), size,
1290 btrfs_node_ptr_generation(eb, i));
1291 if (!extent_buffer_uptodate(next)) {
1292 fprintf(stderr, "failed to read %llu in tree %llu\n",
1293 (unsigned long long)btrfs_node_blockptr(eb, i),
1294 (unsigned long long)btrfs_header_owner(eb));
1297 if (btrfs_is_leaf(next) && btrfs_header_level(eb) != 1) {
1299 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1300 i, btrfs_header_level(next),
1301 btrfs_header_level(eb));
1304 if (btrfs_header_level(next) != btrfs_header_level(eb) - 1) {
1306 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1307 i, btrfs_header_level(next),
1308 btrfs_header_level(eb));
1311 btrfs_print_tree(root, next, 1);
1312 free_extent_buffer(next);
1318 free_extent_buffer(next);