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, 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 count_bytes(void *buf, int len, char b)
523 for (i = 0; i < len; i++) {
524 if (((char*)buf)[i] == b)
531 * Caller must ensure sizeof(*ret) >= 7 "RDONLY"
533 static void root_flags_to_str(u64 flags, char *ret)
535 if (flags & BTRFS_ROOT_SUBVOL_RDONLY)
536 strcat(ret, "RDONLY");
541 static void print_root(struct extent_buffer *leaf, int slot)
543 struct btrfs_root_item *ri;
544 struct btrfs_root_item root_item;
546 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
547 char flags_str[32] = {0};
548 struct btrfs_key drop_key;
550 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
551 len = btrfs_item_size_nr(leaf, slot);
553 memset(&root_item, 0, sizeof(root_item));
554 read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);
555 root_flags_to_str(btrfs_root_flags(&root_item), flags_str);
557 printf("\t\tgeneration %llu root_dirid %llu bytenr %llu level %hhu refs %u\n",
558 (unsigned long long)btrfs_root_generation(&root_item),
559 (unsigned long long)btrfs_root_dirid(&root_item),
560 (unsigned long long)btrfs_root_bytenr(&root_item),
561 btrfs_root_level(&root_item),
562 btrfs_root_refs(&root_item));
563 printf("\t\tlastsnap %llu byte_limit %llu bytes_used %llu flags 0x%llx(%s)\n",
564 (unsigned long long)btrfs_root_last_snapshot(&root_item),
565 (unsigned long long)btrfs_root_limit(&root_item),
566 (unsigned long long)btrfs_root_used(&root_item),
567 (unsigned long long)btrfs_root_flags(&root_item),
570 if (root_item.generation == root_item.generation_v2) {
571 uuid_unparse(root_item.uuid, uuid_str);
572 printf("\t\tuuid %s\n", uuid_str);
573 if (count_bytes(root_item.parent_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
574 uuid_unparse(root_item.parent_uuid, uuid_str);
575 printf("\t\tparent_uuid %s\n", uuid_str);
577 if (count_bytes(root_item.received_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
578 uuid_unparse(root_item.received_uuid, uuid_str);
579 printf("\t\treceived_uuid %s\n", uuid_str);
581 if (root_item.ctransid) {
582 printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
583 btrfs_root_ctransid(&root_item),
584 btrfs_root_otransid(&root_item),
585 btrfs_root_stransid(&root_item),
586 btrfs_root_rtransid(&root_item));
590 btrfs_disk_key_to_cpu(&drop_key, &root_item.drop_progress);
592 btrfs_print_key(&root_item.drop_progress);
593 printf(" level %hhu\n", root_item.drop_level);
596 static void print_free_space_header(struct extent_buffer *leaf, int slot)
598 struct btrfs_free_space_header *header;
599 struct btrfs_disk_key location;
601 header = btrfs_item_ptr(leaf, slot, struct btrfs_free_space_header);
602 btrfs_free_space_key(leaf, header, &location);
603 printf("\t\tlocation ");
604 btrfs_print_key(&location);
606 printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
607 (unsigned long long)btrfs_free_space_generation(leaf, header),
608 (unsigned long long)btrfs_free_space_entries(leaf, header),
609 (unsigned long long)btrfs_free_space_bitmaps(leaf, header));
612 void print_key_type(FILE *stream, u64 objectid, u8 type)
614 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
615 fprintf(stream, "UNTYPED");
620 case BTRFS_INODE_ITEM_KEY:
621 fprintf(stream, "INODE_ITEM");
623 case BTRFS_INODE_REF_KEY:
624 fprintf(stream, "INODE_REF");
626 case BTRFS_INODE_EXTREF_KEY:
627 fprintf(stream, "INODE_EXTREF");
629 case BTRFS_DIR_ITEM_KEY:
630 fprintf(stream, "DIR_ITEM");
632 case BTRFS_DIR_INDEX_KEY:
633 fprintf(stream, "DIR_INDEX");
635 case BTRFS_DIR_LOG_ITEM_KEY:
636 fprintf(stream, "DIR_LOG_ITEM");
638 case BTRFS_DIR_LOG_INDEX_KEY:
639 fprintf(stream, "DIR_LOG_INDEX");
641 case BTRFS_XATTR_ITEM_KEY:
642 fprintf(stream, "XATTR_ITEM");
644 case BTRFS_ORPHAN_ITEM_KEY:
645 fprintf(stream, "ORPHAN_ITEM");
647 case BTRFS_ROOT_ITEM_KEY:
648 fprintf(stream, "ROOT_ITEM");
650 case BTRFS_ROOT_REF_KEY:
651 fprintf(stream, "ROOT_REF");
653 case BTRFS_ROOT_BACKREF_KEY:
654 fprintf(stream, "ROOT_BACKREF");
656 case BTRFS_EXTENT_ITEM_KEY:
657 fprintf(stream, "EXTENT_ITEM");
659 case BTRFS_METADATA_ITEM_KEY:
660 fprintf(stream, "METADATA_ITEM");
662 case BTRFS_TREE_BLOCK_REF_KEY:
663 fprintf(stream, "TREE_BLOCK_REF");
665 case BTRFS_SHARED_BLOCK_REF_KEY:
666 fprintf(stream, "SHARED_BLOCK_REF");
668 case BTRFS_EXTENT_DATA_REF_KEY:
669 fprintf(stream, "EXTENT_DATA_REF");
671 case BTRFS_SHARED_DATA_REF_KEY:
672 fprintf(stream, "SHARED_DATA_REF");
674 case BTRFS_EXTENT_REF_V0_KEY:
675 fprintf(stream, "EXTENT_REF_V0");
677 case BTRFS_CSUM_ITEM_KEY:
678 fprintf(stream, "CSUM_ITEM");
680 case BTRFS_EXTENT_CSUM_KEY:
681 fprintf(stream, "EXTENT_CSUM");
683 case BTRFS_EXTENT_DATA_KEY:
684 fprintf(stream, "EXTENT_DATA");
686 case BTRFS_BLOCK_GROUP_ITEM_KEY:
687 fprintf(stream, "BLOCK_GROUP_ITEM");
689 case BTRFS_FREE_SPACE_INFO_KEY:
690 fprintf(stream, "FREE_SPACE_INFO");
692 case BTRFS_FREE_SPACE_EXTENT_KEY:
693 fprintf(stream, "FREE_SPACE_EXTENT");
695 case BTRFS_FREE_SPACE_BITMAP_KEY:
696 fprintf(stream, "FREE_SPACE_BITMAP");
698 case BTRFS_CHUNK_ITEM_KEY:
699 fprintf(stream, "CHUNK_ITEM");
701 case BTRFS_DEV_ITEM_KEY:
702 fprintf(stream, "DEV_ITEM");
704 case BTRFS_DEV_EXTENT_KEY:
705 fprintf(stream, "DEV_EXTENT");
707 case BTRFS_BALANCE_ITEM_KEY:
708 fprintf(stream, "BALANCE_ITEM");
710 case BTRFS_DEV_REPLACE_KEY:
711 fprintf(stream, "DEV_REPLACE");
713 case BTRFS_STRING_ITEM_KEY:
714 fprintf(stream, "STRING_ITEM");
716 case BTRFS_QGROUP_STATUS_KEY:
717 fprintf(stream, "QGROUP_STATUS");
719 case BTRFS_QGROUP_RELATION_KEY:
720 fprintf(stream, "QGROUP_RELATION");
722 case BTRFS_QGROUP_INFO_KEY:
723 fprintf(stream, "QGROUP_INFO");
725 case BTRFS_QGROUP_LIMIT_KEY:
726 fprintf(stream, "QGROUP_LIMIT");
728 case BTRFS_DEV_STATS_KEY:
729 fprintf(stream, "DEV_STATS");
731 case BTRFS_UUID_KEY_SUBVOL:
732 fprintf(stream, "UUID_KEY_SUBVOL");
734 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
735 fprintf(stream, "UUID_KEY_RECEIVED_SUBVOL");
738 fprintf(stream, "UNKNOWN.%d", type);
742 void print_objectid(FILE *stream, u64 objectid, u8 type)
745 case BTRFS_DEV_EXTENT_KEY:
747 fprintf(stream, "%llu", (unsigned long long)objectid);
749 case BTRFS_QGROUP_RELATION_KEY:
750 fprintf(stream, "%llu/%llu", btrfs_qgroup_level(objectid),
751 btrfs_qgroup_subvid(objectid));
753 case BTRFS_UUID_KEY_SUBVOL:
754 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
755 fprintf(stream, "0x%016llx", (unsigned long long)objectid);
760 case BTRFS_ROOT_TREE_OBJECTID:
761 if (type == BTRFS_DEV_ITEM_KEY)
762 fprintf(stream, "DEV_ITEMS");
764 fprintf(stream, "ROOT_TREE");
766 case BTRFS_EXTENT_TREE_OBJECTID:
767 fprintf(stream, "EXTENT_TREE");
769 case BTRFS_CHUNK_TREE_OBJECTID:
770 fprintf(stream, "CHUNK_TREE");
772 case BTRFS_DEV_TREE_OBJECTID:
773 fprintf(stream, "DEV_TREE");
775 case BTRFS_FS_TREE_OBJECTID:
776 fprintf(stream, "FS_TREE");
778 case BTRFS_ROOT_TREE_DIR_OBJECTID:
779 fprintf(stream, "ROOT_TREE_DIR");
781 case BTRFS_CSUM_TREE_OBJECTID:
782 fprintf(stream, "CSUM_TREE");
784 case BTRFS_BALANCE_OBJECTID:
785 fprintf(stream, "BALANCE");
787 case BTRFS_ORPHAN_OBJECTID:
788 fprintf(stream, "ORPHAN");
790 case BTRFS_TREE_LOG_OBJECTID:
791 fprintf(stream, "TREE_LOG");
793 case BTRFS_TREE_LOG_FIXUP_OBJECTID:
794 fprintf(stream, "LOG_FIXUP");
796 case BTRFS_TREE_RELOC_OBJECTID:
797 fprintf(stream, "TREE_RELOC");
799 case BTRFS_DATA_RELOC_TREE_OBJECTID:
800 fprintf(stream, "DATA_RELOC_TREE");
802 case BTRFS_EXTENT_CSUM_OBJECTID:
803 fprintf(stream, "EXTENT_CSUM");
805 case BTRFS_FREE_SPACE_OBJECTID:
806 fprintf(stream, "FREE_SPACE");
808 case BTRFS_FREE_INO_OBJECTID:
809 fprintf(stream, "FREE_INO");
811 case BTRFS_QUOTA_TREE_OBJECTID:
812 fprintf(stream, "QUOTA_TREE");
814 case BTRFS_UUID_TREE_OBJECTID:
815 fprintf(stream, "UUID_TREE");
817 case BTRFS_FREE_SPACE_TREE_OBJECTID:
818 fprintf(stream, "FREE_SPACE_TREE");
820 case BTRFS_MULTIPLE_OBJECTIDS:
821 fprintf(stream, "MULTIPLE");
824 fprintf(stream, "-1");
826 case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
827 if (type == BTRFS_CHUNK_ITEM_KEY) {
828 fprintf(stream, "FIRST_CHUNK_TREE");
833 fprintf(stream, "%llu", (unsigned long long)objectid);
837 void btrfs_print_key(struct btrfs_disk_key *disk_key)
839 u64 objectid = btrfs_disk_key_objectid(disk_key);
840 u8 type = btrfs_disk_key_type(disk_key);
841 u64 offset = btrfs_disk_key_offset(disk_key);
844 print_objectid(stdout, objectid, type);
846 print_key_type(stdout, objectid, type);
848 case BTRFS_QGROUP_RELATION_KEY:
849 case BTRFS_QGROUP_INFO_KEY:
850 case BTRFS_QGROUP_LIMIT_KEY:
851 printf(" %llu/%llu)", btrfs_qgroup_level(offset),
852 btrfs_qgroup_subvid(offset));
854 case BTRFS_UUID_KEY_SUBVOL:
855 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
856 printf(" 0x%016llx)", (unsigned long long)offset);
859 if (offset == (u64)-1)
862 printf(" %llu)", (unsigned long long)offset);
867 static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
870 if (item_size & (sizeof(u64) - 1)) {
871 printf("btrfs: uuid item with illegal size %lu!\n",
872 (unsigned long)item_size);
878 read_extent_buffer(l, &subvol_id, offset, sizeof(u64));
879 printf("\t\tsubvol_id %llu\n",
880 (unsigned long long)le64_to_cpu(subvol_id));
881 item_size -= sizeof(u64);
882 offset += sizeof(u64);
886 /* Btrfs inode flag stringification helper */
887 #define STRCAT_ONE_INODE_FLAG(flags, name, empty, dst) ({ \
888 if (flags & BTRFS_INODE_##name) { \
891 strcat(dst, #name); \
897 * Caller should ensure sizeof(*ret) >= 102: all charactors plus '|' of
898 * BTRFS_INODE_* flags
900 static void inode_flags_to_str(u64 flags, char *ret)
904 STRCAT_ONE_INODE_FLAG(flags, NODATASUM, empty, ret);
905 STRCAT_ONE_INODE_FLAG(flags, NODATACOW, empty, ret);
906 STRCAT_ONE_INODE_FLAG(flags, READONLY, empty, ret);
907 STRCAT_ONE_INODE_FLAG(flags, NOCOMPRESS, empty, ret);
908 STRCAT_ONE_INODE_FLAG(flags, PREALLOC, empty, ret);
909 STRCAT_ONE_INODE_FLAG(flags, SYNC, empty, ret);
910 STRCAT_ONE_INODE_FLAG(flags, IMMUTABLE, empty, ret);
911 STRCAT_ONE_INODE_FLAG(flags, APPEND, empty, ret);
912 STRCAT_ONE_INODE_FLAG(flags, NODUMP, empty, ret);
913 STRCAT_ONE_INODE_FLAG(flags, NOATIME, empty, ret);
914 STRCAT_ONE_INODE_FLAG(flags, DIRSYNC, empty, ret);
915 STRCAT_ONE_INODE_FLAG(flags, COMPRESS, empty, ret);
920 static void print_timespec(struct extent_buffer *eb,
921 struct btrfs_timespec *timespec, const char *prefix,
930 tmp_u64 = btrfs_timespec_sec(eb, timespec);
931 tmp_u32 = btrfs_timespec_nsec(eb, timespec);
933 localtime_r(&tmp_time, &tm);
934 strftime(timestamp, sizeof(timestamp),
935 "%Y-%m-%d %H:%M:%S", &tm);
936 printf("%s%llu.%u (%s)%s", prefix, (unsigned long long)tmp_u64, tmp_u32,
940 static void print_inode_item(struct extent_buffer *eb,
941 struct btrfs_inode_item *ii)
945 memset(flags_str, 0, sizeof(flags_str));
946 inode_flags_to_str(btrfs_inode_flags(eb, ii), flags_str);
947 printf("\t\tinode generation %llu transid %llu size %llu nbytes %llu\n"
948 "\t\tblock group %llu mode %o links %u uid %u gid %u rdev %llu\n"
949 "\t\tsequence %llu flags 0x%llx(%s)\n",
950 (unsigned long long)btrfs_inode_generation(eb, ii),
951 (unsigned long long)btrfs_inode_transid(eb, ii),
952 (unsigned long long)btrfs_inode_size(eb, ii),
953 (unsigned long long)btrfs_inode_nbytes(eb, ii),
954 (unsigned long long)btrfs_inode_block_group(eb,ii),
955 btrfs_inode_mode(eb, ii),
956 btrfs_inode_nlink(eb, ii),
957 btrfs_inode_uid(eb, ii),
958 btrfs_inode_gid(eb, ii),
959 (unsigned long long)btrfs_inode_rdev(eb,ii),
960 (unsigned long long)btrfs_inode_flags(eb,ii),
961 (unsigned long long)btrfs_inode_sequence(eb, ii),
963 print_timespec(eb, btrfs_inode_atime(ii), "\t\tatime ", "\n");
964 print_timespec(eb, btrfs_inode_ctime(ii), "\t\tctime ", "\n");
965 print_timespec(eb, btrfs_inode_mtime(ii), "\t\tmtime ", "\n");
966 print_timespec(eb, btrfs_inode_otime(ii), "\t\totime ", "\n");
969 static void print_disk_balance_args(struct btrfs_disk_balance_args *ba)
971 printf("\t\tprofiles %llu devid %llu target %llu flags %llu\n",
972 (unsigned long long)le64_to_cpu(ba->profiles),
973 (unsigned long long)le64_to_cpu(ba->devid),
974 (unsigned long long)le64_to_cpu(ba->target),
975 (unsigned long long)le64_to_cpu(ba->flags));
976 printf("\t\tusage_min %u usage_max %u pstart %llu pend %llu\n",
977 le32_to_cpu(ba->usage_min),
978 le32_to_cpu(ba->usage_max),
979 (unsigned long long)le64_to_cpu(ba->pstart),
980 (unsigned long long)le64_to_cpu(ba->pend));
981 printf("\t\tvstart %llu vend %llu limit_min %u limit_max %u\n",
982 (unsigned long long)le64_to_cpu(ba->vstart),
983 (unsigned long long)le64_to_cpu(ba->vend),
984 le32_to_cpu(ba->limit_min),
985 le32_to_cpu(ba->limit_max));
986 printf("\t\tstripes_min %u stripes_max %u\n",
987 le32_to_cpu(ba->stripes_min),
988 le32_to_cpu(ba->stripes_max));
991 static void print_balance_item(struct extent_buffer *eb,
992 struct btrfs_balance_item *bi)
994 printf("\t\tbalance status flags %llu\n",
995 btrfs_balance_item_flags(eb, bi));
997 printf("\t\tDATA\n");
998 print_disk_balance_args(btrfs_balance_item_data(eb, bi));
999 printf("\t\tMETADATA\n");
1000 print_disk_balance_args(btrfs_balance_item_meta(eb, bi));
1001 printf("\t\tSYSTEM\n");
1002 print_disk_balance_args(btrfs_balance_item_sys(eb, bi));
1005 static void print_dev_stats(struct extent_buffer *eb,
1006 struct btrfs_dev_stats_item *stats, u32 size)
1009 u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64);
1010 __le64 *values = btrfs_dev_stats_values(eb, stats);
1012 printf("\t\tdevice stats\n");
1013 printf("\t\twrite_errs %llu read_errs %llu flush_errs %llu corruption_errs %llu generation %llu\n",
1014 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_WRITE_ERRS]),
1015 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_READ_ERRS]),
1016 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_FLUSH_ERRS]),
1017 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_CORRUPTION_ERRS]),
1018 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_GENERATION_ERRS]));
1021 printf("\t\tunknown stats item bytes %u", size - known);
1022 for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
1023 printf("\t\tunknown item %u offset %lu value %llu\n",
1024 i, i * sizeof(__le64),
1025 (unsigned long long)le64_to_cpu(values[i]));
1030 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
1034 struct btrfs_item *item;
1035 struct btrfs_dir_item *di;
1036 struct btrfs_inode_item *ii;
1037 struct btrfs_file_extent_item *fi;
1038 struct btrfs_block_group_item *bi;
1039 struct btrfs_extent_data_ref *dref;
1040 struct btrfs_shared_data_ref *sref;
1041 struct btrfs_inode_ref *iref;
1042 struct btrfs_inode_extref *iref2;
1043 struct btrfs_dev_extent *dev_extent;
1044 struct btrfs_disk_key disk_key;
1045 struct btrfs_block_group_item bg_item;
1046 struct btrfs_free_space_info *free_info;
1047 struct btrfs_dir_log_item *dlog;
1048 struct btrfs_qgroup_info_item *qg_info;
1049 struct btrfs_qgroup_limit_item *qg_limit;
1050 struct btrfs_qgroup_status_item *qg_status;
1051 u32 nr = btrfs_header_nritems(l);
1055 char flags_str[256];
1056 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
1057 u8 uuid[BTRFS_UUID_SIZE];
1059 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
1060 (unsigned long long)btrfs_header_bytenr(l), nr,
1061 btrfs_leaf_free_space(root, l),
1062 (unsigned long long)btrfs_header_generation(l),
1063 (unsigned long long)btrfs_header_owner(l));
1066 for (i = 0 ; i < nr ; i++) {
1069 item = btrfs_item_nr(i);
1070 item_size = btrfs_item_size(l, item);
1071 btrfs_item_key(l, &disk_key, i);
1072 objectid = btrfs_disk_key_objectid(&disk_key);
1073 type = btrfs_disk_key_type(&disk_key);
1074 offset = btrfs_disk_key_offset(&disk_key);
1075 printf("\titem %d ", i);
1076 btrfs_print_key(&disk_key);
1077 printf(" itemoff %d itemsize %d\n",
1078 btrfs_item_offset(l, item),
1079 btrfs_item_size(l, item));
1081 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID)
1082 print_free_space_header(l, i);
1085 case BTRFS_INODE_ITEM_KEY:
1086 ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
1087 print_inode_item(l, ii);
1089 case BTRFS_INODE_REF_KEY:
1090 iref = btrfs_item_ptr(l, i, struct btrfs_inode_ref);
1091 print_inode_ref_item(l, item_size, iref);
1093 case BTRFS_INODE_EXTREF_KEY:
1094 iref2 = btrfs_item_ptr(l, i, struct btrfs_inode_extref);
1095 print_inode_extref_item(l, item_size, iref2);
1097 case BTRFS_DIR_ITEM_KEY:
1098 case BTRFS_DIR_INDEX_KEY:
1099 case BTRFS_XATTR_ITEM_KEY:
1100 di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
1101 print_dir_item(l, item_size, di);
1103 case BTRFS_DIR_LOG_INDEX_KEY:
1104 case BTRFS_DIR_LOG_ITEM_KEY:
1105 dlog = btrfs_item_ptr(l, i, struct btrfs_dir_log_item);
1106 printf("\t\tdir log end %Lu\n",
1107 (unsigned long long)btrfs_dir_log_end(l, dlog));
1109 case BTRFS_ORPHAN_ITEM_KEY:
1110 printf("\t\torphan item\n");
1112 case BTRFS_ROOT_ITEM_KEY:
1115 case BTRFS_ROOT_REF_KEY:
1116 print_root_ref(l, i, "ref");
1118 case BTRFS_ROOT_BACKREF_KEY:
1119 print_root_ref(l, i, "backref");
1121 case BTRFS_EXTENT_ITEM_KEY:
1122 print_extent_item(l, i, 0);
1124 case BTRFS_METADATA_ITEM_KEY:
1125 print_extent_item(l, i, 1);
1127 case BTRFS_TREE_BLOCK_REF_KEY:
1128 printf("\t\ttree block backref\n");
1130 case BTRFS_SHARED_BLOCK_REF_KEY:
1131 printf("\t\tshared block backref\n");
1133 case BTRFS_EXTENT_DATA_REF_KEY:
1134 dref = btrfs_item_ptr(l, i, struct btrfs_extent_data_ref);
1135 printf("\t\textent data backref root %llu "
1136 "objectid %llu offset %llu count %u\n",
1137 (unsigned long long)btrfs_extent_data_ref_root(l, dref),
1138 (unsigned long long)btrfs_extent_data_ref_objectid(l, dref),
1139 (unsigned long long)btrfs_extent_data_ref_offset(l, dref),
1140 btrfs_extent_data_ref_count(l, dref));
1142 case BTRFS_SHARED_DATA_REF_KEY:
1143 sref = btrfs_item_ptr(l, i, struct btrfs_shared_data_ref);
1144 printf("\t\tshared data backref count %u\n",
1145 btrfs_shared_data_ref_count(l, sref));
1147 case BTRFS_EXTENT_REF_V0_KEY:
1148 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1149 print_extent_ref_v0(l, i);
1154 case BTRFS_CSUM_ITEM_KEY:
1155 printf("\t\tcsum item\n");
1157 case BTRFS_EXTENT_CSUM_KEY:
1158 printf("\t\textent csum item\n");
1160 case BTRFS_EXTENT_DATA_KEY:
1161 fi = btrfs_item_ptr(l, i,
1162 struct btrfs_file_extent_item);
1163 print_file_extent_item(l, item, i, fi);
1165 case BTRFS_BLOCK_GROUP_ITEM_KEY:
1166 bi = btrfs_item_ptr(l, i,
1167 struct btrfs_block_group_item);
1168 read_extent_buffer(l, &bg_item, (unsigned long)bi,
1170 memset(flags_str, 0, sizeof(flags_str));
1171 bg_flags_to_str(btrfs_block_group_flags(&bg_item),
1173 printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
1174 (unsigned long long)btrfs_block_group_used(&bg_item),
1175 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
1178 case BTRFS_FREE_SPACE_INFO_KEY:
1179 free_info = btrfs_item_ptr(l, i, struct btrfs_free_space_info);
1180 printf("\t\tfree space info extent count %u flags %u\n",
1181 (unsigned)btrfs_free_space_extent_count(l, free_info),
1182 (unsigned)btrfs_free_space_flags(l, free_info));
1184 case BTRFS_FREE_SPACE_EXTENT_KEY:
1185 printf("\t\tfree space extent\n");
1187 case BTRFS_FREE_SPACE_BITMAP_KEY:
1188 printf("\t\tfree space bitmap\n");
1190 case BTRFS_CHUNK_ITEM_KEY:
1191 print_chunk(l, btrfs_item_ptr(l, i, struct btrfs_chunk));
1193 case BTRFS_DEV_ITEM_KEY:
1194 print_dev_item(l, btrfs_item_ptr(l, i,
1195 struct btrfs_dev_item));
1197 case BTRFS_DEV_EXTENT_KEY:
1198 dev_extent = btrfs_item_ptr(l, i,
1199 struct btrfs_dev_extent);
1200 read_extent_buffer(l, uuid,
1201 (unsigned long)btrfs_dev_extent_chunk_tree_uuid(dev_extent),
1203 uuid_unparse(uuid, uuid_str);
1204 printf("\t\tdev extent chunk_tree %llu\n"
1205 "\t\tchunk_objectid %llu chunk_offset %llu "
1207 "\t\tchunk_tree_uuid %s\n",
1208 (unsigned long long)
1209 btrfs_dev_extent_chunk_tree(l, dev_extent),
1210 (unsigned long long)
1211 btrfs_dev_extent_chunk_objectid(l, dev_extent),
1212 (unsigned long long)
1213 btrfs_dev_extent_chunk_offset(l, dev_extent),
1214 (unsigned long long)
1215 btrfs_dev_extent_length(l, dev_extent),
1218 case BTRFS_QGROUP_STATUS_KEY:
1219 qg_status = btrfs_item_ptr(l, i,
1220 struct btrfs_qgroup_status_item);
1221 memset(flags_str, 0, sizeof(flags_str));
1222 qgroup_flags_to_str(btrfs_qgroup_status_flags(l, qg_status),
1224 printf("\t\tversion %llu generation %llu flags %s "
1226 (unsigned long long)
1227 btrfs_qgroup_status_version(l, qg_status),
1228 (unsigned long long)
1229 btrfs_qgroup_status_generation(l, qg_status),
1231 (unsigned long long)
1232 btrfs_qgroup_status_rescan(l, qg_status));
1234 case BTRFS_QGROUP_RELATION_KEY:
1236 case BTRFS_QGROUP_INFO_KEY:
1237 qg_info = btrfs_item_ptr(l, i,
1238 struct btrfs_qgroup_info_item);
1239 printf("\t\tgeneration %llu\n"
1240 "\t\treferenced %llu referenced_compressed %llu\n"
1241 "\t\texclusive %llu exclusive_compressed %llu\n",
1242 (unsigned long long)
1243 btrfs_qgroup_info_generation(l, qg_info),
1244 (unsigned long long)
1245 btrfs_qgroup_info_referenced(l, qg_info),
1246 (unsigned long long)
1247 btrfs_qgroup_info_referenced_compressed(l,
1249 (unsigned long long)
1250 btrfs_qgroup_info_exclusive(l, qg_info),
1251 (unsigned long long)
1252 btrfs_qgroup_info_exclusive_compressed(l,
1255 case BTRFS_QGROUP_LIMIT_KEY:
1256 qg_limit = btrfs_item_ptr(l, i,
1257 struct btrfs_qgroup_limit_item);
1258 printf("\t\tflags %llx\n"
1259 "\t\tmax_referenced %lld max_exclusive %lld\n"
1260 "\t\trsv_referenced %lld rsv_exclusive %lld\n",
1261 (unsigned long long)
1262 btrfs_qgroup_limit_flags(l, qg_limit),
1264 btrfs_qgroup_limit_max_referenced(l, qg_limit),
1266 btrfs_qgroup_limit_max_exclusive(l, qg_limit),
1268 btrfs_qgroup_limit_rsv_referenced(l, qg_limit),
1270 btrfs_qgroup_limit_rsv_exclusive(l, qg_limit));
1272 case BTRFS_UUID_KEY_SUBVOL:
1273 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
1274 print_uuid_item(l, btrfs_item_ptr_offset(l, i),
1275 btrfs_item_size_nr(l, i));
1277 case BTRFS_STRING_ITEM_KEY:
1278 /* dirty, but it's simple */
1279 str = l->data + btrfs_item_ptr_offset(l, i);
1280 printf("\t\titem data %.*s\n", item_size, str);
1282 case BTRFS_PERSISTENT_ITEM_KEY:
1283 printf("\t\tpersistent item objectid ");
1284 print_objectid(stdout, objectid, BTRFS_PERSISTENT_ITEM_KEY);
1285 printf(" offset %llu\n", (unsigned long long)offset);
1287 case BTRFS_DEV_STATS_OBJECTID:
1288 print_dev_stats(l, btrfs_item_ptr(l, i,
1289 struct btrfs_dev_stats_item),
1293 printf("\t\tunknown persistent item objectid %llu\n",
1297 case BTRFS_TEMPORARY_ITEM_KEY:
1298 printf("\t\ttemporary item objectid ");
1299 print_objectid(stdout, objectid, BTRFS_TEMPORARY_ITEM_KEY);
1300 printf(" offset %llu\n", (unsigned long long)offset);
1302 case BTRFS_BALANCE_OBJECTID:
1303 print_balance_item(l, btrfs_item_ptr(l, i,
1304 struct btrfs_balance_item));
1307 printf("\t\tunknown temporary item objectid %llu\n",
1316 void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
1321 struct btrfs_disk_key disk_key;
1322 struct btrfs_key key;
1323 struct extent_buffer *next;
1327 nr = btrfs_header_nritems(eb);
1328 if (btrfs_is_leaf(eb)) {
1329 btrfs_print_leaf(root, eb);
1332 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
1333 (unsigned long long)eb->start,
1334 btrfs_header_level(eb), nr,
1335 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
1336 (unsigned long long)btrfs_header_generation(eb),
1337 (unsigned long long)btrfs_header_owner(eb));
1340 size = root->nodesize;
1341 for (i = 0; i < nr; i++) {
1342 u64 blocknr = btrfs_node_blockptr(eb, i);
1343 btrfs_node_key(eb, &disk_key, i);
1344 btrfs_disk_key_to_cpu(&key, &disk_key);
1346 btrfs_print_key(&disk_key);
1347 printf(" block %llu (%llu) gen %llu\n",
1348 (unsigned long long)blocknr,
1349 (unsigned long long)blocknr / size,
1350 (unsigned long long)btrfs_node_ptr_generation(eb, i));
1356 for (i = 0; i < nr; i++) {
1357 next = read_tree_block(root, btrfs_node_blockptr(eb, i), size,
1358 btrfs_node_ptr_generation(eb, i));
1359 if (!extent_buffer_uptodate(next)) {
1360 fprintf(stderr, "failed to read %llu in tree %llu\n",
1361 (unsigned long long)btrfs_node_blockptr(eb, i),
1362 (unsigned long long)btrfs_header_owner(eb));
1365 if (btrfs_is_leaf(next) && btrfs_header_level(eb) != 1) {
1367 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1368 i, btrfs_header_level(next),
1369 btrfs_header_level(eb));
1372 if (btrfs_header_level(next) != btrfs_header_level(eb) - 1) {
1374 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1375 i, btrfs_header_level(next),
1376 btrfs_header_level(eb));
1379 btrfs_print_tree(root, next, 1);
1380 free_extent_buffer(next);
1386 free_extent_buffer(next);