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 int 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);
103 static int print_inode_extref_item(struct extent_buffer *eb, u32 size,
104 struct btrfs_inode_extref *extref)
111 char namebuf[BTRFS_NAME_LEN];
114 index = btrfs_inode_extref_index(eb, extref);
115 name_len = btrfs_inode_extref_name_len(eb, extref);
116 parent_objid = btrfs_inode_extref_parent(eb, extref);
118 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
120 read_extent_buffer(eb, namebuf, (unsigned long)(extref->name), len);
122 printf("\t\tinode extref index %llu parent %llu namelen %u "
124 (unsigned long long)index,
125 (unsigned long long)parent_objid,
126 name_len, len, namebuf);
128 len = sizeof(*extref) + name_len;
129 extref = (struct btrfs_inode_extref *)((char *)extref + len);
135 static int print_inode_ref_item(struct extent_buffer *eb, u32 size,
136 struct btrfs_inode_ref *ref)
142 char namebuf[BTRFS_NAME_LEN];
145 name_len = btrfs_inode_ref_name_len(eb, ref);
146 index = btrfs_inode_ref_index(eb, ref);
147 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
148 read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len);
149 printf("\t\tinode ref index %llu namelen %u name: %.*s\n",
150 (unsigned long long)index, name_len, len, namebuf);
151 len = sizeof(*ref) + name_len;
152 ref = (struct btrfs_inode_ref *)((char *)ref + len);
158 /* Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10" */
159 static void bg_flags_to_str(u64 flags, char *ret)
163 if (flags & BTRFS_BLOCK_GROUP_DATA) {
167 if (flags & BTRFS_BLOCK_GROUP_METADATA) {
170 strcat(ret, "METADATA");
172 if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
175 strcat(ret, "SYSTEM");
177 switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
178 case BTRFS_BLOCK_GROUP_RAID0:
179 strcat(ret, "|RAID0");
181 case BTRFS_BLOCK_GROUP_RAID1:
182 strcat(ret, "|RAID1");
184 case BTRFS_BLOCK_GROUP_DUP:
187 case BTRFS_BLOCK_GROUP_RAID10:
188 strcat(ret, "|RAID10");
190 case BTRFS_BLOCK_GROUP_RAID5:
191 strcat(ret, "|RAID5");
193 case BTRFS_BLOCK_GROUP_RAID6:
194 strcat(ret, "|RAID6");
201 /* Caller should ensure sizeof(*ret)>= 26 "OFF|SCANNING|INCONSISTENT" */
202 static void qgroup_flags_to_str(u64 flags, char *ret)
204 if (flags & BTRFS_QGROUP_STATUS_FLAG_ON)
209 if (flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN)
210 strcat(ret, "|SCANNING");
211 if (flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
212 strcat(ret, "|INCONSISTENT");
215 void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
217 int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
219 char chunk_flags_str[32] = {0};
221 bg_flags_to_str(btrfs_chunk_type(eb, chunk), chunk_flags_str);
222 printf("\t\tlength %llu owner %llu stripe_len %llu type %s\n",
223 (unsigned long long)btrfs_chunk_length(eb, chunk),
224 (unsigned long long)btrfs_chunk_owner(eb, chunk),
225 (unsigned long long)btrfs_chunk_stripe_len(eb, chunk),
227 printf("\t\tio_align %u io_width %u sector_size %u\n",
228 btrfs_chunk_io_align(eb, chunk),
229 btrfs_chunk_io_width(eb, chunk),
230 btrfs_chunk_sector_size(eb, chunk));
231 printf("\t\tnum_stripes %hu sub_stripes %hu\n", num_stripes,
232 btrfs_chunk_sub_stripes(eb, chunk));
233 for (i = 0 ; i < num_stripes ; i++) {
234 unsigned char dev_uuid[BTRFS_UUID_SIZE];
235 char str_dev_uuid[BTRFS_UUID_UNPARSED_SIZE];
237 read_extent_buffer(eb, dev_uuid,
238 (unsigned long)btrfs_stripe_dev_uuid_nr(chunk, i),
240 uuid_unparse(dev_uuid, str_dev_uuid);
241 printf("\t\t\tstripe %d devid %llu offset %llu\n", i,
242 (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i),
243 (unsigned long long)btrfs_stripe_offset_nr(eb, chunk, i));
244 printf("\t\t\tdev_uuid %s\n", str_dev_uuid);
248 static void print_dev_item(struct extent_buffer *eb,
249 struct btrfs_dev_item *dev_item)
251 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
252 char fsid_str[BTRFS_UUID_UNPARSED_SIZE];
253 u8 uuid[BTRFS_UUID_SIZE];
254 u8 fsid[BTRFS_UUID_SIZE];
256 read_extent_buffer(eb, uuid,
257 (unsigned long)btrfs_device_uuid(dev_item),
259 uuid_unparse(uuid, uuid_str);
260 read_extent_buffer(eb, fsid,
261 (unsigned long)btrfs_device_fsid(dev_item),
263 uuid_unparse(fsid, fsid_str);
264 printf("\t\tdevid %llu total_bytes %llu bytes_used %Lu\n"
265 "\t\tio_align %u io_width %u sector_size %u type %llu\n"
266 "\t\tgeneration %llu start_offset %llu dev_group %u\n"
267 "\t\tseek_speed %hhu bandwidth %hhu\n"
270 (unsigned long long)btrfs_device_id(eb, dev_item),
271 (unsigned long long)btrfs_device_total_bytes(eb, dev_item),
272 (unsigned long long)btrfs_device_bytes_used(eb, dev_item),
273 btrfs_device_io_align(eb, dev_item),
274 btrfs_device_io_width(eb, dev_item),
275 btrfs_device_sector_size(eb, dev_item),
276 (unsigned long long)btrfs_device_type(eb, dev_item),
277 (unsigned long long)btrfs_device_generation(eb, dev_item),
278 (unsigned long long)btrfs_device_start_offset(eb, dev_item),
279 btrfs_device_group(eb, dev_item),
280 btrfs_device_seek_speed(eb, dev_item),
281 btrfs_device_bandwidth(eb, dev_item),
285 static void print_uuids(struct extent_buffer *eb)
287 char fs_uuid[BTRFS_UUID_UNPARSED_SIZE];
288 char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE];
289 u8 disk_uuid[BTRFS_UUID_SIZE];
291 read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(),
294 fs_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
295 uuid_unparse(disk_uuid, fs_uuid);
297 read_extent_buffer(eb, disk_uuid,
298 btrfs_header_chunk_tree_uuid(eb),
301 chunk_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
302 uuid_unparse(disk_uuid, chunk_uuid);
303 printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid);
306 static void compress_type_to_str(u8 compress_type, char *ret)
308 switch (compress_type) {
309 case BTRFS_COMPRESS_NONE:
312 case BTRFS_COMPRESS_ZLIB:
315 case BTRFS_COMPRESS_LZO:
319 sprintf(ret, "UNKNOWN.%d", compress_type);
323 static const char* file_extent_type_to_str(u8 type)
326 case BTRFS_FILE_EXTENT_INLINE: return "inline";
327 case BTRFS_FILE_EXTENT_PREALLOC: return "prealloc";
328 case BTRFS_FILE_EXTENT_REG: return "regular";
329 default: return "unknown";
333 static void print_file_extent_item(struct extent_buffer *eb,
334 struct btrfs_item *item,
336 struct btrfs_file_extent_item *fi)
338 int extent_type = btrfs_file_extent_type(eb, fi);
339 char compress_str[16];
341 compress_type_to_str(btrfs_file_extent_compression(eb, fi),
344 printf("\t\tgeneration %llu type %hhu (%s)\n",
345 btrfs_file_extent_generation(eb, fi),
346 extent_type, file_extent_type_to_str(extent_type));
348 if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
349 printf("\t\tinline extent data size %u ram_bytes %u compression %hhu (%s)\n",
350 btrfs_file_extent_inline_item_len(eb, item),
351 btrfs_file_extent_inline_len(eb, slot, fi),
352 btrfs_file_extent_compression(eb, fi),
356 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
357 printf("\t\tprealloc data disk byte %llu nr %llu\n",
358 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
359 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
360 printf("\t\tprealloc data offset %llu nr %llu\n",
361 (unsigned long long)btrfs_file_extent_offset(eb, fi),
362 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi));
365 printf("\t\textent data disk byte %llu nr %llu\n",
366 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
367 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
368 printf("\t\textent data offset %llu nr %llu ram %llu\n",
369 (unsigned long long)btrfs_file_extent_offset(eb, fi),
370 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi),
371 (unsigned long long)btrfs_file_extent_ram_bytes(eb, fi));
372 printf("\t\textent compression %hhu (%s)\n",
373 btrfs_file_extent_compression(eb, fi),
377 /* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
378 static void extent_flags_to_str(u64 flags, char *ret)
382 if (flags & BTRFS_EXTENT_FLAG_DATA) {
386 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
391 strcat(ret, "TREE_BLOCK");
393 if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
395 strcat(ret, "FULL_BACKREF");
399 void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
401 struct btrfs_extent_item *ei;
402 struct btrfs_extent_inline_ref *iref;
403 struct btrfs_extent_data_ref *dref;
404 struct btrfs_shared_data_ref *sref;
405 struct btrfs_disk_key key;
409 u32 item_size = btrfs_item_size_nr(eb, slot);
412 char flags_str[32] = {0};
414 if (item_size < sizeof(*ei)) {
415 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
416 struct btrfs_extent_item_v0 *ei0;
417 BUG_ON(item_size != sizeof(*ei0));
418 ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0);
419 printf("\t\textent refs %u\n",
420 btrfs_extent_refs_v0(eb, ei0));
427 ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
428 flags = btrfs_extent_flags(eb, ei);
429 extent_flags_to_str(flags, flags_str);
431 printf("\t\textent refs %llu gen %llu flags %s\n",
432 (unsigned long long)btrfs_extent_refs(eb, ei),
433 (unsigned long long)btrfs_extent_generation(eb, ei),
436 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !metadata) {
437 struct btrfs_tree_block_info *info;
438 info = (struct btrfs_tree_block_info *)(ei + 1);
439 btrfs_tree_block_key(eb, info, &key);
440 printf("\t\ttree block ");
441 btrfs_print_key(&key);
442 printf(" level %d\n", btrfs_tree_block_level(eb, info));
443 iref = (struct btrfs_extent_inline_ref *)(info + 1);
444 } else if (metadata) {
445 struct btrfs_key tmp;
447 btrfs_item_key_to_cpu(eb, &tmp, slot);
448 printf("\t\ttree block skinny level %d\n", (int)tmp.offset);
449 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
451 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
454 ptr = (unsigned long)iref;
455 end = (unsigned long)ei + item_size;
457 iref = (struct btrfs_extent_inline_ref *)ptr;
458 type = btrfs_extent_inline_ref_type(eb, iref);
459 offset = btrfs_extent_inline_ref_offset(eb, iref);
461 case BTRFS_TREE_BLOCK_REF_KEY:
462 printf("\t\ttree block backref root %llu\n",
463 (unsigned long long)offset);
465 case BTRFS_SHARED_BLOCK_REF_KEY:
466 printf("\t\tshared block backref parent %llu\n",
467 (unsigned long long)offset);
469 case BTRFS_EXTENT_DATA_REF_KEY:
470 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
471 printf("\t\textent data backref root %llu "
472 "objectid %llu offset %llu count %u\n",
473 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
474 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
475 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
476 btrfs_extent_data_ref_count(eb, dref));
478 case BTRFS_SHARED_DATA_REF_KEY:
479 sref = (struct btrfs_shared_data_ref *)(iref + 1);
480 printf("\t\tshared data backref parent %llu count %u\n",
481 (unsigned long long)offset,
482 btrfs_shared_data_ref_count(eb, sref));
487 ptr += btrfs_extent_inline_ref_size(type);
492 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
493 static void print_extent_ref_v0(struct extent_buffer *eb, int slot)
495 struct btrfs_extent_ref_v0 *ref0;
497 ref0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_ref_v0);
498 printf("\t\textent back ref root %llu gen %llu "
499 "owner %llu num_refs %lu\n",
500 (unsigned long long)btrfs_ref_root_v0(eb, ref0),
501 (unsigned long long)btrfs_ref_generation_v0(eb, ref0),
502 (unsigned long long)btrfs_ref_objectid_v0(eb, ref0),
503 (unsigned long)btrfs_ref_count_v0(eb, ref0));
507 static void print_root_ref(struct extent_buffer *leaf, int slot, char *tag)
509 struct btrfs_root_ref *ref;
510 char namebuf[BTRFS_NAME_LEN];
513 ref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref);
514 namelen = btrfs_root_ref_name_len(leaf, ref);
515 read_extent_buffer(leaf, namebuf, (unsigned long)(ref + 1), namelen);
516 printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag,
517 (unsigned long long)btrfs_root_ref_dirid(leaf, ref),
518 (unsigned long long)btrfs_root_ref_sequence(leaf, ref),
522 static int count_bytes(void *buf, int len, char b)
526 for (i = 0; i < len; i++) {
527 if (((char*)buf)[i] == b)
534 * Caller must ensure sizeof(*ret) >= 7 "RDONLY"
536 static void root_flags_to_str(u64 flags, char *ret)
538 if (flags & BTRFS_ROOT_SUBVOL_RDONLY)
539 strcat(ret, "RDONLY");
544 static void print_root(struct extent_buffer *leaf, int slot)
546 struct btrfs_root_item *ri;
547 struct btrfs_root_item root_item;
549 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
550 char flags_str[32] = {0};
551 struct btrfs_key drop_key;
553 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
554 len = btrfs_item_size_nr(leaf, slot);
556 memset(&root_item, 0, sizeof(root_item));
557 read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);
558 root_flags_to_str(btrfs_root_flags(&root_item), flags_str);
560 printf("\t\tgeneration %llu root_dirid %llu bytenr %llu level %hhu refs %u\n",
561 (unsigned long long)btrfs_root_generation(&root_item),
562 (unsigned long long)btrfs_root_dirid(&root_item),
563 (unsigned long long)btrfs_root_bytenr(&root_item),
564 btrfs_root_level(&root_item),
565 btrfs_root_refs(&root_item));
566 printf("\t\tlastsnap %llu byte_limit %llu bytes_used %llu flags 0x%llx(%s)\n",
567 (unsigned long long)btrfs_root_last_snapshot(&root_item),
568 (unsigned long long)btrfs_root_limit(&root_item),
569 (unsigned long long)btrfs_root_used(&root_item),
570 (unsigned long long)btrfs_root_flags(&root_item),
573 if (root_item.generation == root_item.generation_v2) {
574 uuid_unparse(root_item.uuid, uuid_str);
575 printf("\t\tuuid %s\n", uuid_str);
576 if (count_bytes(root_item.parent_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
577 uuid_unparse(root_item.parent_uuid, uuid_str);
578 printf("\t\tparent_uuid %s\n", uuid_str);
580 if (count_bytes(root_item.received_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
581 uuid_unparse(root_item.received_uuid, uuid_str);
582 printf("\t\treceived_uuid %s\n", uuid_str);
584 if (root_item.ctransid) {
585 printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
586 btrfs_root_ctransid(&root_item),
587 btrfs_root_otransid(&root_item),
588 btrfs_root_stransid(&root_item),
589 btrfs_root_rtransid(&root_item));
593 btrfs_disk_key_to_cpu(&drop_key, &root_item.drop_progress);
595 btrfs_print_key(&root_item.drop_progress);
596 printf(" level %hhu\n", root_item.drop_level);
599 static void print_free_space_header(struct extent_buffer *leaf, int slot)
601 struct btrfs_free_space_header *header;
602 struct btrfs_disk_key location;
604 header = btrfs_item_ptr(leaf, slot, struct btrfs_free_space_header);
605 btrfs_free_space_key(leaf, header, &location);
606 printf("\t\tlocation ");
607 btrfs_print_key(&location);
609 printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
610 (unsigned long long)btrfs_free_space_generation(leaf, header),
611 (unsigned long long)btrfs_free_space_entries(leaf, header),
612 (unsigned long long)btrfs_free_space_bitmaps(leaf, header));
615 void print_key_type(FILE *stream, u64 objectid, u8 type)
617 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
618 fprintf(stream, "UNTYPED");
623 case BTRFS_INODE_ITEM_KEY:
624 fprintf(stream, "INODE_ITEM");
626 case BTRFS_INODE_REF_KEY:
627 fprintf(stream, "INODE_REF");
629 case BTRFS_INODE_EXTREF_KEY:
630 fprintf(stream, "INODE_EXTREF");
632 case BTRFS_DIR_ITEM_KEY:
633 fprintf(stream, "DIR_ITEM");
635 case BTRFS_DIR_INDEX_KEY:
636 fprintf(stream, "DIR_INDEX");
638 case BTRFS_DIR_LOG_ITEM_KEY:
639 fprintf(stream, "DIR_LOG_ITEM");
641 case BTRFS_DIR_LOG_INDEX_KEY:
642 fprintf(stream, "DIR_LOG_INDEX");
644 case BTRFS_XATTR_ITEM_KEY:
645 fprintf(stream, "XATTR_ITEM");
647 case BTRFS_ORPHAN_ITEM_KEY:
648 fprintf(stream, "ORPHAN_ITEM");
650 case BTRFS_ROOT_ITEM_KEY:
651 fprintf(stream, "ROOT_ITEM");
653 case BTRFS_ROOT_REF_KEY:
654 fprintf(stream, "ROOT_REF");
656 case BTRFS_ROOT_BACKREF_KEY:
657 fprintf(stream, "ROOT_BACKREF");
659 case BTRFS_EXTENT_ITEM_KEY:
660 fprintf(stream, "EXTENT_ITEM");
662 case BTRFS_METADATA_ITEM_KEY:
663 fprintf(stream, "METADATA_ITEM");
665 case BTRFS_TREE_BLOCK_REF_KEY:
666 fprintf(stream, "TREE_BLOCK_REF");
668 case BTRFS_SHARED_BLOCK_REF_KEY:
669 fprintf(stream, "SHARED_BLOCK_REF");
671 case BTRFS_EXTENT_DATA_REF_KEY:
672 fprintf(stream, "EXTENT_DATA_REF");
674 case BTRFS_SHARED_DATA_REF_KEY:
675 fprintf(stream, "SHARED_DATA_REF");
677 case BTRFS_EXTENT_REF_V0_KEY:
678 fprintf(stream, "EXTENT_REF_V0");
680 case BTRFS_CSUM_ITEM_KEY:
681 fprintf(stream, "CSUM_ITEM");
683 case BTRFS_EXTENT_CSUM_KEY:
684 fprintf(stream, "EXTENT_CSUM");
686 case BTRFS_EXTENT_DATA_KEY:
687 fprintf(stream, "EXTENT_DATA");
689 case BTRFS_BLOCK_GROUP_ITEM_KEY:
690 fprintf(stream, "BLOCK_GROUP_ITEM");
692 case BTRFS_FREE_SPACE_INFO_KEY:
693 fprintf(stream, "FREE_SPACE_INFO");
695 case BTRFS_FREE_SPACE_EXTENT_KEY:
696 fprintf(stream, "FREE_SPACE_EXTENT");
698 case BTRFS_FREE_SPACE_BITMAP_KEY:
699 fprintf(stream, "FREE_SPACE_BITMAP");
701 case BTRFS_CHUNK_ITEM_KEY:
702 fprintf(stream, "CHUNK_ITEM");
704 case BTRFS_DEV_ITEM_KEY:
705 fprintf(stream, "DEV_ITEM");
707 case BTRFS_DEV_EXTENT_KEY:
708 fprintf(stream, "DEV_EXTENT");
710 case BTRFS_BALANCE_ITEM_KEY:
711 fprintf(stream, "BALANCE_ITEM");
713 case BTRFS_DEV_REPLACE_KEY:
714 fprintf(stream, "DEV_REPLACE");
716 case BTRFS_STRING_ITEM_KEY:
717 fprintf(stream, "STRING_ITEM");
719 case BTRFS_QGROUP_STATUS_KEY:
720 fprintf(stream, "QGROUP_STATUS");
722 case BTRFS_QGROUP_RELATION_KEY:
723 fprintf(stream, "QGROUP_RELATION");
725 case BTRFS_QGROUP_INFO_KEY:
726 fprintf(stream, "QGROUP_INFO");
728 case BTRFS_QGROUP_LIMIT_KEY:
729 fprintf(stream, "QGROUP_LIMIT");
731 case BTRFS_DEV_STATS_KEY:
732 fprintf(stream, "DEV_STATS");
734 case BTRFS_UUID_KEY_SUBVOL:
735 fprintf(stream, "UUID_KEY_SUBVOL");
737 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
738 fprintf(stream, "UUID_KEY_RECEIVED_SUBVOL");
741 fprintf(stream, "UNKNOWN.%d", type);
745 void print_objectid(FILE *stream, u64 objectid, u8 type)
748 case BTRFS_DEV_EXTENT_KEY:
750 fprintf(stream, "%llu", (unsigned long long)objectid);
752 case BTRFS_QGROUP_RELATION_KEY:
753 fprintf(stream, "%llu/%llu", btrfs_qgroup_level(objectid),
754 btrfs_qgroup_subvid(objectid));
756 case BTRFS_UUID_KEY_SUBVOL:
757 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
758 fprintf(stream, "0x%016llx", (unsigned long long)objectid);
763 case BTRFS_ROOT_TREE_OBJECTID:
764 if (type == BTRFS_DEV_ITEM_KEY)
765 fprintf(stream, "DEV_ITEMS");
767 fprintf(stream, "ROOT_TREE");
769 case BTRFS_EXTENT_TREE_OBJECTID:
770 fprintf(stream, "EXTENT_TREE");
772 case BTRFS_CHUNK_TREE_OBJECTID:
773 fprintf(stream, "CHUNK_TREE");
775 case BTRFS_DEV_TREE_OBJECTID:
776 fprintf(stream, "DEV_TREE");
778 case BTRFS_FS_TREE_OBJECTID:
779 fprintf(stream, "FS_TREE");
781 case BTRFS_ROOT_TREE_DIR_OBJECTID:
782 fprintf(stream, "ROOT_TREE_DIR");
784 case BTRFS_CSUM_TREE_OBJECTID:
785 fprintf(stream, "CSUM_TREE");
787 case BTRFS_BALANCE_OBJECTID:
788 fprintf(stream, "BALANCE");
790 case BTRFS_ORPHAN_OBJECTID:
791 fprintf(stream, "ORPHAN");
793 case BTRFS_TREE_LOG_OBJECTID:
794 fprintf(stream, "TREE_LOG");
796 case BTRFS_TREE_LOG_FIXUP_OBJECTID:
797 fprintf(stream, "LOG_FIXUP");
799 case BTRFS_TREE_RELOC_OBJECTID:
800 fprintf(stream, "TREE_RELOC");
802 case BTRFS_DATA_RELOC_TREE_OBJECTID:
803 fprintf(stream, "DATA_RELOC_TREE");
805 case BTRFS_EXTENT_CSUM_OBJECTID:
806 fprintf(stream, "EXTENT_CSUM");
808 case BTRFS_FREE_SPACE_OBJECTID:
809 fprintf(stream, "FREE_SPACE");
811 case BTRFS_FREE_INO_OBJECTID:
812 fprintf(stream, "FREE_INO");
814 case BTRFS_QUOTA_TREE_OBJECTID:
815 fprintf(stream, "QUOTA_TREE");
817 case BTRFS_UUID_TREE_OBJECTID:
818 fprintf(stream, "UUID_TREE");
820 case BTRFS_FREE_SPACE_TREE_OBJECTID:
821 fprintf(stream, "FREE_SPACE_TREE");
823 case BTRFS_MULTIPLE_OBJECTIDS:
824 fprintf(stream, "MULTIPLE");
827 fprintf(stream, "-1");
829 case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
830 if (type == BTRFS_CHUNK_ITEM_KEY) {
831 fprintf(stream, "FIRST_CHUNK_TREE");
836 fprintf(stream, "%llu", (unsigned long long)objectid);
840 void btrfs_print_key(struct btrfs_disk_key *disk_key)
842 u64 objectid = btrfs_disk_key_objectid(disk_key);
843 u8 type = btrfs_disk_key_type(disk_key);
844 u64 offset = btrfs_disk_key_offset(disk_key);
847 print_objectid(stdout, objectid, type);
849 print_key_type(stdout, objectid, type);
851 case BTRFS_QGROUP_RELATION_KEY:
852 case BTRFS_QGROUP_INFO_KEY:
853 case BTRFS_QGROUP_LIMIT_KEY:
854 printf(" %llu/%llu)", btrfs_qgroup_level(offset),
855 btrfs_qgroup_subvid(offset));
857 case BTRFS_UUID_KEY_SUBVOL:
858 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
859 printf(" 0x%016llx)", (unsigned long long)offset);
862 if (offset == (u64)-1)
865 printf(" %llu)", (unsigned long long)offset);
870 static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
873 if (item_size & (sizeof(u64) - 1)) {
874 printf("btrfs: uuid item with illegal size %lu!\n",
875 (unsigned long)item_size);
881 read_extent_buffer(l, &subvol_id, offset, sizeof(u64));
882 printf("\t\tsubvol_id %llu\n",
883 (unsigned long long)le64_to_cpu(subvol_id));
884 item_size -= sizeof(u64);
885 offset += sizeof(u64);
889 /* Btrfs inode flag stringification helper */
890 #define STRCAT_ONE_INODE_FLAG(flags, name, empty, dst) ({ \
891 if (flags & BTRFS_INODE_##name) { \
894 strcat(dst, #name); \
900 * Caller should ensure sizeof(*ret) >= 102: all charactors plus '|' of
901 * BTRFS_INODE_* flags
903 static void inode_flags_to_str(u64 flags, char *ret)
907 STRCAT_ONE_INODE_FLAG(flags, NODATASUM, empty, ret);
908 STRCAT_ONE_INODE_FLAG(flags, NODATACOW, empty, ret);
909 STRCAT_ONE_INODE_FLAG(flags, READONLY, empty, ret);
910 STRCAT_ONE_INODE_FLAG(flags, NOCOMPRESS, empty, ret);
911 STRCAT_ONE_INODE_FLAG(flags, PREALLOC, empty, ret);
912 STRCAT_ONE_INODE_FLAG(flags, SYNC, empty, ret);
913 STRCAT_ONE_INODE_FLAG(flags, IMMUTABLE, empty, ret);
914 STRCAT_ONE_INODE_FLAG(flags, APPEND, empty, ret);
915 STRCAT_ONE_INODE_FLAG(flags, NODUMP, empty, ret);
916 STRCAT_ONE_INODE_FLAG(flags, NOATIME, empty, ret);
917 STRCAT_ONE_INODE_FLAG(flags, DIRSYNC, empty, ret);
918 STRCAT_ONE_INODE_FLAG(flags, COMPRESS, empty, ret);
923 static void print_timespec(struct extent_buffer *eb,
924 struct btrfs_timespec *timespec, const char *prefix,
933 tmp_u64 = btrfs_timespec_sec(eb, timespec);
934 tmp_u32 = btrfs_timespec_nsec(eb, timespec);
936 localtime_r(&tmp_time, &tm);
937 strftime(timestamp, sizeof(timestamp),
938 "%Y-%m-%d %H:%M:%S", &tm);
939 printf("%s%llu.%u (%s)%s", prefix, (unsigned long long)tmp_u64, tmp_u32,
943 static void print_inode_item(struct extent_buffer *eb,
944 struct btrfs_inode_item *ii)
948 memset(flags_str, 0, sizeof(flags_str));
949 inode_flags_to_str(btrfs_inode_flags(eb, ii), flags_str);
950 printf("\t\tinode generation %llu transid %llu size %llu nbytes %llu\n"
951 "\t\tblock group %llu mode %o links %u uid %u gid %u rdev %llu\n"
952 "\t\tsequence %llu flags 0x%llx(%s)\n",
953 (unsigned long long)btrfs_inode_generation(eb, ii),
954 (unsigned long long)btrfs_inode_transid(eb, ii),
955 (unsigned long long)btrfs_inode_size(eb, ii),
956 (unsigned long long)btrfs_inode_nbytes(eb, ii),
957 (unsigned long long)btrfs_inode_block_group(eb,ii),
958 btrfs_inode_mode(eb, ii),
959 btrfs_inode_nlink(eb, ii),
960 btrfs_inode_uid(eb, ii),
961 btrfs_inode_gid(eb, ii),
962 (unsigned long long)btrfs_inode_rdev(eb,ii),
963 (unsigned long long)btrfs_inode_flags(eb,ii),
964 (unsigned long long)btrfs_inode_sequence(eb, ii),
966 print_timespec(eb, btrfs_inode_atime(ii), "\t\tatime ", "\n");
967 print_timespec(eb, btrfs_inode_ctime(ii), "\t\tctime ", "\n");
968 print_timespec(eb, btrfs_inode_mtime(ii), "\t\tmtime ", "\n");
969 print_timespec(eb, btrfs_inode_otime(ii), "\t\totime ", "\n");
972 static void print_disk_balance_args(struct btrfs_disk_balance_args *ba)
974 printf("\t\tprofiles %llu devid %llu target %llu flags %llu\n",
975 (unsigned long long)le64_to_cpu(ba->profiles),
976 (unsigned long long)le64_to_cpu(ba->devid),
977 (unsigned long long)le64_to_cpu(ba->target),
978 (unsigned long long)le64_to_cpu(ba->flags));
979 printf("\t\tusage_min %u usage_max %u pstart %llu pend %llu\n",
980 le32_to_cpu(ba->usage_min),
981 le32_to_cpu(ba->usage_max),
982 (unsigned long long)le64_to_cpu(ba->pstart),
983 (unsigned long long)le64_to_cpu(ba->pend));
984 printf("\t\tvstart %llu vend %llu limit_min %u limit_max %u\n",
985 (unsigned long long)le64_to_cpu(ba->vstart),
986 (unsigned long long)le64_to_cpu(ba->vend),
987 le32_to_cpu(ba->limit_min),
988 le32_to_cpu(ba->limit_max));
989 printf("\t\tstripes_min %u stripes_max %u\n",
990 le32_to_cpu(ba->stripes_min),
991 le32_to_cpu(ba->stripes_max));
994 static void print_balance_item(struct extent_buffer *eb,
995 struct btrfs_balance_item *bi)
997 printf("\t\tbalance status flags %llu\n",
998 btrfs_balance_item_flags(eb, bi));
1000 printf("\t\tDATA\n");
1001 print_disk_balance_args(btrfs_balance_item_data(eb, bi));
1002 printf("\t\tMETADATA\n");
1003 print_disk_balance_args(btrfs_balance_item_meta(eb, bi));
1004 printf("\t\tSYSTEM\n");
1005 print_disk_balance_args(btrfs_balance_item_sys(eb, bi));
1008 static void print_dev_stats(struct extent_buffer *eb,
1009 struct btrfs_dev_stats_item *stats, u32 size)
1012 u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64);
1013 __le64 *values = btrfs_dev_stats_values(eb, stats);
1015 printf("\t\tdevice stats\n");
1016 printf("\t\twrite_errs %llu read_errs %llu flush_errs %llu corruption_errs %llu generation %llu\n",
1017 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_WRITE_ERRS]),
1018 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_READ_ERRS]),
1019 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_FLUSH_ERRS]),
1020 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_CORRUPTION_ERRS]),
1021 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_GENERATION_ERRS]));
1024 printf("\t\tunknown stats item bytes %u", size - known);
1025 for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
1026 printf("\t\tunknown item %u offset %lu value %llu\n",
1027 i, i * sizeof(__le64),
1028 (unsigned long long)le64_to_cpu(values[i]));
1033 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
1037 struct btrfs_item *item;
1038 struct btrfs_dir_item *di;
1039 struct btrfs_inode_item *ii;
1040 struct btrfs_file_extent_item *fi;
1041 struct btrfs_block_group_item *bi;
1042 struct btrfs_extent_data_ref *dref;
1043 struct btrfs_shared_data_ref *sref;
1044 struct btrfs_inode_ref *iref;
1045 struct btrfs_inode_extref *iref2;
1046 struct btrfs_dev_extent *dev_extent;
1047 struct btrfs_disk_key disk_key;
1048 struct btrfs_block_group_item bg_item;
1049 struct btrfs_free_space_info *free_info;
1050 struct btrfs_dir_log_item *dlog;
1051 struct btrfs_qgroup_info_item *qg_info;
1052 struct btrfs_qgroup_limit_item *qg_limit;
1053 struct btrfs_qgroup_status_item *qg_status;
1054 u32 nr = btrfs_header_nritems(l);
1058 char flags_str[256];
1059 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
1060 u8 uuid[BTRFS_UUID_SIZE];
1062 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
1063 (unsigned long long)btrfs_header_bytenr(l), nr,
1064 btrfs_leaf_free_space(root, l),
1065 (unsigned long long)btrfs_header_generation(l),
1066 (unsigned long long)btrfs_header_owner(l));
1069 for (i = 0 ; i < nr ; i++) {
1072 item = btrfs_item_nr(i);
1073 item_size = btrfs_item_size(l, item);
1074 btrfs_item_key(l, &disk_key, i);
1075 objectid = btrfs_disk_key_objectid(&disk_key);
1076 type = btrfs_disk_key_type(&disk_key);
1077 offset = btrfs_disk_key_offset(&disk_key);
1078 printf("\titem %d ", i);
1079 btrfs_print_key(&disk_key);
1080 printf(" itemoff %d itemsize %d\n",
1081 btrfs_item_offset(l, item),
1082 btrfs_item_size(l, item));
1084 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID)
1085 print_free_space_header(l, i);
1088 case BTRFS_INODE_ITEM_KEY:
1089 ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
1090 print_inode_item(l, ii);
1092 case BTRFS_INODE_REF_KEY:
1093 iref = btrfs_item_ptr(l, i, struct btrfs_inode_ref);
1094 print_inode_ref_item(l, item_size, iref);
1096 case BTRFS_INODE_EXTREF_KEY:
1097 iref2 = btrfs_item_ptr(l, i, struct btrfs_inode_extref);
1098 print_inode_extref_item(l, item_size, iref2);
1100 case BTRFS_DIR_ITEM_KEY:
1101 case BTRFS_DIR_INDEX_KEY:
1102 case BTRFS_XATTR_ITEM_KEY:
1103 di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
1104 print_dir_item(l, item_size, di);
1106 case BTRFS_DIR_LOG_INDEX_KEY:
1107 case BTRFS_DIR_LOG_ITEM_KEY:
1108 dlog = btrfs_item_ptr(l, i, struct btrfs_dir_log_item);
1109 printf("\t\tdir log end %Lu\n",
1110 (unsigned long long)btrfs_dir_log_end(l, dlog));
1112 case BTRFS_ORPHAN_ITEM_KEY:
1113 printf("\t\torphan item\n");
1115 case BTRFS_ROOT_ITEM_KEY:
1118 case BTRFS_ROOT_REF_KEY:
1119 print_root_ref(l, i, "ref");
1121 case BTRFS_ROOT_BACKREF_KEY:
1122 print_root_ref(l, i, "backref");
1124 case BTRFS_EXTENT_ITEM_KEY:
1125 print_extent_item(l, i, 0);
1127 case BTRFS_METADATA_ITEM_KEY:
1128 print_extent_item(l, i, 1);
1130 case BTRFS_TREE_BLOCK_REF_KEY:
1131 printf("\t\ttree block backref\n");
1133 case BTRFS_SHARED_BLOCK_REF_KEY:
1134 printf("\t\tshared block backref\n");
1136 case BTRFS_EXTENT_DATA_REF_KEY:
1137 dref = btrfs_item_ptr(l, i, struct btrfs_extent_data_ref);
1138 printf("\t\textent data backref root %llu "
1139 "objectid %llu offset %llu count %u\n",
1140 (unsigned long long)btrfs_extent_data_ref_root(l, dref),
1141 (unsigned long long)btrfs_extent_data_ref_objectid(l, dref),
1142 (unsigned long long)btrfs_extent_data_ref_offset(l, dref),
1143 btrfs_extent_data_ref_count(l, dref));
1145 case BTRFS_SHARED_DATA_REF_KEY:
1146 sref = btrfs_item_ptr(l, i, struct btrfs_shared_data_ref);
1147 printf("\t\tshared data backref count %u\n",
1148 btrfs_shared_data_ref_count(l, sref));
1150 case BTRFS_EXTENT_REF_V0_KEY:
1151 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1152 print_extent_ref_v0(l, i);
1157 case BTRFS_CSUM_ITEM_KEY:
1158 printf("\t\tcsum item\n");
1160 case BTRFS_EXTENT_CSUM_KEY:
1161 printf("\t\textent csum item\n");
1163 case BTRFS_EXTENT_DATA_KEY:
1164 fi = btrfs_item_ptr(l, i,
1165 struct btrfs_file_extent_item);
1166 print_file_extent_item(l, item, i, fi);
1168 case BTRFS_BLOCK_GROUP_ITEM_KEY:
1169 bi = btrfs_item_ptr(l, i,
1170 struct btrfs_block_group_item);
1171 read_extent_buffer(l, &bg_item, (unsigned long)bi,
1173 memset(flags_str, 0, sizeof(flags_str));
1174 bg_flags_to_str(btrfs_block_group_flags(&bg_item),
1176 printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
1177 (unsigned long long)btrfs_block_group_used(&bg_item),
1178 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
1181 case BTRFS_FREE_SPACE_INFO_KEY:
1182 free_info = btrfs_item_ptr(l, i, struct btrfs_free_space_info);
1183 printf("\t\tfree space info extent count %u flags %u\n",
1184 (unsigned)btrfs_free_space_extent_count(l, free_info),
1185 (unsigned)btrfs_free_space_flags(l, free_info));
1187 case BTRFS_FREE_SPACE_EXTENT_KEY:
1188 printf("\t\tfree space extent\n");
1190 case BTRFS_FREE_SPACE_BITMAP_KEY:
1191 printf("\t\tfree space bitmap\n");
1193 case BTRFS_CHUNK_ITEM_KEY:
1194 print_chunk(l, btrfs_item_ptr(l, i, struct btrfs_chunk));
1196 case BTRFS_DEV_ITEM_KEY:
1197 print_dev_item(l, btrfs_item_ptr(l, i,
1198 struct btrfs_dev_item));
1200 case BTRFS_DEV_EXTENT_KEY:
1201 dev_extent = btrfs_item_ptr(l, i,
1202 struct btrfs_dev_extent);
1203 read_extent_buffer(l, uuid,
1204 (unsigned long)btrfs_dev_extent_chunk_tree_uuid(dev_extent),
1206 uuid_unparse(uuid, uuid_str);
1207 printf("\t\tdev extent chunk_tree %llu\n"
1208 "\t\tchunk_objectid %llu chunk_offset %llu "
1210 "\t\tchunk_tree_uuid %s\n",
1211 (unsigned long long)
1212 btrfs_dev_extent_chunk_tree(l, dev_extent),
1213 (unsigned long long)
1214 btrfs_dev_extent_chunk_objectid(l, dev_extent),
1215 (unsigned long long)
1216 btrfs_dev_extent_chunk_offset(l, dev_extent),
1217 (unsigned long long)
1218 btrfs_dev_extent_length(l, dev_extent),
1221 case BTRFS_QGROUP_STATUS_KEY:
1222 qg_status = btrfs_item_ptr(l, i,
1223 struct btrfs_qgroup_status_item);
1224 memset(flags_str, 0, sizeof(flags_str));
1225 qgroup_flags_to_str(btrfs_qgroup_status_flags(l, qg_status),
1227 printf("\t\tversion %llu generation %llu flags %s "
1229 (unsigned long long)
1230 btrfs_qgroup_status_version(l, qg_status),
1231 (unsigned long long)
1232 btrfs_qgroup_status_generation(l, qg_status),
1234 (unsigned long long)
1235 btrfs_qgroup_status_rescan(l, qg_status));
1237 case BTRFS_QGROUP_RELATION_KEY:
1239 case BTRFS_QGROUP_INFO_KEY:
1240 qg_info = btrfs_item_ptr(l, i,
1241 struct btrfs_qgroup_info_item);
1242 printf("\t\tgeneration %llu\n"
1243 "\t\treferenced %llu referenced_compressed %llu\n"
1244 "\t\texclusive %llu exclusive_compressed %llu\n",
1245 (unsigned long long)
1246 btrfs_qgroup_info_generation(l, qg_info),
1247 (unsigned long long)
1248 btrfs_qgroup_info_referenced(l, qg_info),
1249 (unsigned long long)
1250 btrfs_qgroup_info_referenced_compressed(l,
1252 (unsigned long long)
1253 btrfs_qgroup_info_exclusive(l, qg_info),
1254 (unsigned long long)
1255 btrfs_qgroup_info_exclusive_compressed(l,
1258 case BTRFS_QGROUP_LIMIT_KEY:
1259 qg_limit = btrfs_item_ptr(l, i,
1260 struct btrfs_qgroup_limit_item);
1261 printf("\t\tflags %llx\n"
1262 "\t\tmax_referenced %lld max_exclusive %lld\n"
1263 "\t\trsv_referenced %lld rsv_exclusive %lld\n",
1264 (unsigned long long)
1265 btrfs_qgroup_limit_flags(l, qg_limit),
1267 btrfs_qgroup_limit_max_referenced(l, qg_limit),
1269 btrfs_qgroup_limit_max_exclusive(l, qg_limit),
1271 btrfs_qgroup_limit_rsv_referenced(l, qg_limit),
1273 btrfs_qgroup_limit_rsv_exclusive(l, qg_limit));
1275 case BTRFS_UUID_KEY_SUBVOL:
1276 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
1277 print_uuid_item(l, btrfs_item_ptr_offset(l, i),
1278 btrfs_item_size_nr(l, i));
1280 case BTRFS_STRING_ITEM_KEY:
1281 /* dirty, but it's simple */
1282 str = l->data + btrfs_item_ptr_offset(l, i);
1283 printf("\t\titem data %.*s\n", item_size, str);
1285 case BTRFS_PERSISTENT_ITEM_KEY:
1286 printf("\t\tpersistent item objectid ");
1287 print_objectid(stdout, objectid, BTRFS_PERSISTENT_ITEM_KEY);
1288 printf(" offset %llu\n", (unsigned long long)offset);
1290 case BTRFS_DEV_STATS_OBJECTID:
1291 print_dev_stats(l, btrfs_item_ptr(l, i,
1292 struct btrfs_dev_stats_item),
1296 printf("\t\tunknown persistent item objectid %llu\n",
1300 case BTRFS_TEMPORARY_ITEM_KEY:
1301 printf("\t\ttemporary item objectid ");
1302 print_objectid(stdout, objectid, BTRFS_TEMPORARY_ITEM_KEY);
1303 printf(" offset %llu\n", (unsigned long long)offset);
1305 case BTRFS_BALANCE_OBJECTID:
1306 print_balance_item(l, btrfs_item_ptr(l, i,
1307 struct btrfs_balance_item));
1310 printf("\t\tunknown temporary item objectid %llu\n",
1319 void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
1324 struct btrfs_disk_key disk_key;
1325 struct btrfs_key key;
1326 struct extent_buffer *next;
1330 nr = btrfs_header_nritems(eb);
1331 if (btrfs_is_leaf(eb)) {
1332 btrfs_print_leaf(root, eb);
1335 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
1336 (unsigned long long)eb->start,
1337 btrfs_header_level(eb), nr,
1338 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
1339 (unsigned long long)btrfs_header_generation(eb),
1340 (unsigned long long)btrfs_header_owner(eb));
1343 size = root->nodesize;
1344 for (i = 0; i < nr; i++) {
1345 u64 blocknr = btrfs_node_blockptr(eb, i);
1346 btrfs_node_key(eb, &disk_key, i);
1347 btrfs_disk_key_to_cpu(&key, &disk_key);
1349 btrfs_print_key(&disk_key);
1350 printf(" block %llu (%llu) gen %llu\n",
1351 (unsigned long long)blocknr,
1352 (unsigned long long)blocknr / size,
1353 (unsigned long long)btrfs_node_ptr_generation(eb, i));
1359 for (i = 0; i < nr; i++) {
1360 next = read_tree_block(root, btrfs_node_blockptr(eb, i), size,
1361 btrfs_node_ptr_generation(eb, i));
1362 if (!extent_buffer_uptodate(next)) {
1363 fprintf(stderr, "failed to read %llu in tree %llu\n",
1364 (unsigned long long)btrfs_node_blockptr(eb, i),
1365 (unsigned long long)btrfs_header_owner(eb));
1368 if (btrfs_is_leaf(next) && btrfs_header_level(eb) != 1) {
1370 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1371 i, btrfs_header_level(next),
1372 btrfs_header_level(eb));
1375 if (btrfs_header_level(next) != btrfs_header_level(eb) - 1) {
1377 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1378 i, btrfs_header_level(next),
1379 btrfs_header_level(eb));
1382 btrfs_print_tree(root, next, 1);
1383 free_extent_buffer(next);
1389 free_extent_buffer(next);