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, struct btrfs_item *item,
66 struct btrfs_dir_item *di)
73 char namebuf[BTRFS_NAME_LEN];
74 struct btrfs_disk_key location;
76 total = btrfs_item_size(eb, item);
78 btrfs_dir_item_key(eb, di, &location);
79 printf("\t\tlocation ");
80 btrfs_print_key(&location);
82 print_dir_item_type(eb, di);
84 name_len = btrfs_dir_name_len(eb, di);
85 data_len = btrfs_dir_data_len(eb, di);
86 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
87 read_extent_buffer(eb, namebuf, (unsigned long)(di + 1), len);
88 printf("\t\ttransid %llu data_len %u name_len %u\n",
89 btrfs_dir_transid(eb, di),
91 printf("\t\tname: %.*s\n", len, namebuf);
93 len = (data_len <= sizeof(namebuf))? data_len: sizeof(namebuf);
94 read_extent_buffer(eb, namebuf,
95 (unsigned long)(di + 1) + name_len, len);
96 printf("\t\tdata %.*s\n", len, namebuf);
98 len = sizeof(*di) + name_len + data_len;
99 di = (struct btrfs_dir_item *)((char *)di + len);
105 static int print_inode_extref_item(struct extent_buffer *eb,
106 struct btrfs_item *item,
107 struct btrfs_inode_extref *extref)
115 char namebuf[BTRFS_NAME_LEN];
117 total = btrfs_item_size(eb, item);
119 while (cur < total) {
120 index = btrfs_inode_extref_index(eb, extref);
121 name_len = btrfs_inode_extref_name_len(eb, extref);
122 parent_objid = btrfs_inode_extref_parent(eb, extref);
124 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
126 read_extent_buffer(eb, namebuf, (unsigned long)(extref->name), len);
128 printf("\t\tinode extref index %llu parent %llu namelen %u "
130 (unsigned long long)index,
131 (unsigned long long)parent_objid,
132 name_len, len, namebuf);
134 len = sizeof(*extref) + name_len;
135 extref = (struct btrfs_inode_extref *)((char *)extref + len);
141 static int print_inode_ref_item(struct extent_buffer *eb, struct btrfs_item *item,
142 struct btrfs_inode_ref *ref)
149 char namebuf[BTRFS_NAME_LEN];
150 total = btrfs_item_size(eb, item);
152 name_len = btrfs_inode_ref_name_len(eb, ref);
153 index = btrfs_inode_ref_index(eb, ref);
154 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
155 read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len);
156 printf("\t\tinode ref index %llu namelen %u name: %.*s\n",
157 (unsigned long long)index, name_len, len, namebuf);
158 len = sizeof(*ref) + name_len;
159 ref = (struct btrfs_inode_ref *)((char *)ref + len);
165 /* Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10" */
166 static void bg_flags_to_str(u64 flags, char *ret)
170 if (flags & BTRFS_BLOCK_GROUP_DATA) {
174 if (flags & BTRFS_BLOCK_GROUP_METADATA) {
177 strcat(ret, "METADATA");
179 if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
182 strcat(ret, "SYSTEM");
184 switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
185 case BTRFS_BLOCK_GROUP_RAID0:
186 strcat(ret, "|RAID0");
188 case BTRFS_BLOCK_GROUP_RAID1:
189 strcat(ret, "|RAID1");
191 case BTRFS_BLOCK_GROUP_DUP:
194 case BTRFS_BLOCK_GROUP_RAID10:
195 strcat(ret, "|RAID10");
197 case BTRFS_BLOCK_GROUP_RAID5:
198 strcat(ret, "|RAID5");
200 case BTRFS_BLOCK_GROUP_RAID6:
201 strcat(ret, "|RAID6");
208 /* Caller should ensure sizeof(*ret)>= 26 "OFF|SCANNING|INCONSISTENT" */
209 static void qgroup_flags_to_str(u64 flags, char *ret)
211 if (flags & BTRFS_QGROUP_STATUS_FLAG_ON)
216 if (flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN)
217 strcat(ret, "|SCANNING");
218 if (flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
219 strcat(ret, "|INCONSISTENT");
222 void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
224 int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
226 char chunk_flags_str[32] = {0};
228 bg_flags_to_str(btrfs_chunk_type(eb, chunk), chunk_flags_str);
229 printf("\t\tlength %llu owner %llu stripe_len %llu type %s\n",
230 (unsigned long long)btrfs_chunk_length(eb, chunk),
231 (unsigned long long)btrfs_chunk_owner(eb, chunk),
232 (unsigned long long)btrfs_chunk_stripe_len(eb, chunk),
234 printf("\t\tio_align %u io_width %u sector_size %u\n",
235 btrfs_chunk_io_align(eb, chunk),
236 btrfs_chunk_io_width(eb, chunk),
237 btrfs_chunk_sector_size(eb, chunk));
238 printf("\t\tnum_stripes %hu sub_stripes %hu\n", num_stripes,
239 btrfs_chunk_sub_stripes(eb, chunk));
240 for (i = 0 ; i < num_stripes ; i++) {
241 unsigned char dev_uuid[BTRFS_UUID_SIZE];
242 char str_dev_uuid[BTRFS_UUID_UNPARSED_SIZE];
244 read_extent_buffer(eb, dev_uuid,
245 (unsigned long)btrfs_stripe_dev_uuid_nr(chunk, i),
247 uuid_unparse(dev_uuid, str_dev_uuid);
248 printf("\t\t\tstripe %d devid %llu offset %llu\n", i,
249 (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i),
250 (unsigned long long)btrfs_stripe_offset_nr(eb, chunk, i));
251 printf("\t\t\tdev_uuid %s\n", str_dev_uuid);
255 static void print_dev_item(struct extent_buffer *eb,
256 struct btrfs_dev_item *dev_item)
258 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
259 char fsid_str[BTRFS_UUID_UNPARSED_SIZE];
260 u8 uuid[BTRFS_UUID_SIZE];
261 u8 fsid[BTRFS_UUID_SIZE];
263 read_extent_buffer(eb, uuid,
264 (unsigned long)btrfs_device_uuid(dev_item),
266 uuid_unparse(uuid, uuid_str);
267 read_extent_buffer(eb, fsid,
268 (unsigned long)btrfs_device_fsid(dev_item),
270 uuid_unparse(fsid, fsid_str);
271 printf("\t\tdevid %llu total_bytes %llu bytes_used %Lu\n"
272 "\t\tio_align %u io_width %u sector_size %u type %llu\n"
273 "\t\tgeneration %llu start_offset %llu dev_group %u\n"
274 "\t\tseek_speed %hhu bandwidth %hhu\n"
277 (unsigned long long)btrfs_device_id(eb, dev_item),
278 (unsigned long long)btrfs_device_total_bytes(eb, dev_item),
279 (unsigned long long)btrfs_device_bytes_used(eb, dev_item),
280 btrfs_device_io_align(eb, dev_item),
281 btrfs_device_io_width(eb, dev_item),
282 btrfs_device_sector_size(eb, dev_item),
283 (unsigned long long)btrfs_device_type(eb, dev_item),
284 (unsigned long long)btrfs_device_generation(eb, dev_item),
285 (unsigned long long)btrfs_device_start_offset(eb, dev_item),
286 btrfs_device_group(eb, dev_item),
287 btrfs_device_seek_speed(eb, dev_item),
288 btrfs_device_bandwidth(eb, dev_item),
292 static void print_uuids(struct extent_buffer *eb)
294 char fs_uuid[BTRFS_UUID_UNPARSED_SIZE];
295 char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE];
296 u8 disk_uuid[BTRFS_UUID_SIZE];
298 read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(),
301 fs_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
302 uuid_unparse(disk_uuid, fs_uuid);
304 read_extent_buffer(eb, disk_uuid,
305 btrfs_header_chunk_tree_uuid(eb),
308 chunk_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
309 uuid_unparse(disk_uuid, chunk_uuid);
310 printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid);
313 static void compress_type_to_str(u8 compress_type, char *ret)
315 switch (compress_type) {
316 case BTRFS_COMPRESS_NONE:
319 case BTRFS_COMPRESS_ZLIB:
322 case BTRFS_COMPRESS_LZO:
326 sprintf(ret, "UNKNOWN.%d", compress_type);
330 static const char* file_extent_type_to_str(u8 type)
333 case BTRFS_FILE_EXTENT_INLINE: return "inline";
334 case BTRFS_FILE_EXTENT_PREALLOC: return "prealloc";
335 case BTRFS_FILE_EXTENT_REG: return "regular";
336 default: return "unknown";
340 static void print_file_extent_item(struct extent_buffer *eb,
341 struct btrfs_item *item,
343 struct btrfs_file_extent_item *fi)
345 int extent_type = btrfs_file_extent_type(eb, fi);
346 char compress_str[16];
348 compress_type_to_str(btrfs_file_extent_compression(eb, fi),
351 printf("\t\tgeneration %llu type %hhu (%s)\n",
352 btrfs_file_extent_generation(eb, fi),
353 extent_type, file_extent_type_to_str(extent_type));
355 if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
356 printf("\t\tinline extent data size %u ram_bytes %u compression %hhu (%s)\n",
357 btrfs_file_extent_inline_item_len(eb, item),
358 btrfs_file_extent_inline_len(eb, slot, fi),
359 btrfs_file_extent_compression(eb, fi),
363 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
364 printf("\t\tprealloc data disk byte %llu nr %llu\n",
365 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
366 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
367 printf("\t\tprealloc data offset %llu nr %llu\n",
368 (unsigned long long)btrfs_file_extent_offset(eb, fi),
369 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi));
372 printf("\t\textent data disk byte %llu nr %llu\n",
373 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
374 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
375 printf("\t\textent data offset %llu nr %llu ram %llu\n",
376 (unsigned long long)btrfs_file_extent_offset(eb, fi),
377 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi),
378 (unsigned long long)btrfs_file_extent_ram_bytes(eb, fi));
379 printf("\t\textent compression %hhu (%s)\n",
380 btrfs_file_extent_compression(eb, fi),
384 /* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
385 static void extent_flags_to_str(u64 flags, char *ret)
389 if (flags & BTRFS_EXTENT_FLAG_DATA) {
393 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
398 strcat(ret, "TREE_BLOCK");
400 if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
402 strcat(ret, "FULL_BACKREF");
406 void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
408 struct btrfs_extent_item *ei;
409 struct btrfs_extent_inline_ref *iref;
410 struct btrfs_extent_data_ref *dref;
411 struct btrfs_shared_data_ref *sref;
412 struct btrfs_disk_key key;
416 u32 item_size = btrfs_item_size_nr(eb, slot);
419 char flags_str[32] = {0};
421 if (item_size < sizeof(*ei)) {
422 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
423 struct btrfs_extent_item_v0 *ei0;
424 BUG_ON(item_size != sizeof(*ei0));
425 ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0);
426 printf("\t\textent refs %u\n",
427 btrfs_extent_refs_v0(eb, ei0));
434 ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
435 flags = btrfs_extent_flags(eb, ei);
436 extent_flags_to_str(flags, flags_str);
438 printf("\t\textent refs %llu gen %llu flags %s\n",
439 (unsigned long long)btrfs_extent_refs(eb, ei),
440 (unsigned long long)btrfs_extent_generation(eb, ei),
443 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !metadata) {
444 struct btrfs_tree_block_info *info;
445 info = (struct btrfs_tree_block_info *)(ei + 1);
446 btrfs_tree_block_key(eb, info, &key);
447 printf("\t\ttree block ");
448 btrfs_print_key(&key);
449 printf(" level %d\n", btrfs_tree_block_level(eb, info));
450 iref = (struct btrfs_extent_inline_ref *)(info + 1);
451 } else if (metadata) {
452 struct btrfs_key tmp;
454 btrfs_item_key_to_cpu(eb, &tmp, slot);
455 printf("\t\ttree block skinny level %d\n", (int)tmp.offset);
456 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
458 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
461 ptr = (unsigned long)iref;
462 end = (unsigned long)ei + item_size;
464 iref = (struct btrfs_extent_inline_ref *)ptr;
465 type = btrfs_extent_inline_ref_type(eb, iref);
466 offset = btrfs_extent_inline_ref_offset(eb, iref);
468 case BTRFS_TREE_BLOCK_REF_KEY:
469 printf("\t\ttree block backref root %llu\n",
470 (unsigned long long)offset);
472 case BTRFS_SHARED_BLOCK_REF_KEY:
473 printf("\t\tshared block backref parent %llu\n",
474 (unsigned long long)offset);
476 case BTRFS_EXTENT_DATA_REF_KEY:
477 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
478 printf("\t\textent data backref root %llu "
479 "objectid %llu offset %llu count %u\n",
480 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
481 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
482 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
483 btrfs_extent_data_ref_count(eb, dref));
485 case BTRFS_SHARED_DATA_REF_KEY:
486 sref = (struct btrfs_shared_data_ref *)(iref + 1);
487 printf("\t\tshared data backref parent %llu count %u\n",
488 (unsigned long long)offset,
489 btrfs_shared_data_ref_count(eb, sref));
494 ptr += btrfs_extent_inline_ref_size(type);
499 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
500 static void print_extent_ref_v0(struct extent_buffer *eb, int slot)
502 struct btrfs_extent_ref_v0 *ref0;
504 ref0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_ref_v0);
505 printf("\t\textent back ref root %llu gen %llu "
506 "owner %llu num_refs %lu\n",
507 (unsigned long long)btrfs_ref_root_v0(eb, ref0),
508 (unsigned long long)btrfs_ref_generation_v0(eb, ref0),
509 (unsigned long long)btrfs_ref_objectid_v0(eb, ref0),
510 (unsigned long)btrfs_ref_count_v0(eb, ref0));
514 static void print_root_ref(struct extent_buffer *leaf, int slot, char *tag)
516 struct btrfs_root_ref *ref;
517 char namebuf[BTRFS_NAME_LEN];
520 ref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref);
521 namelen = btrfs_root_ref_name_len(leaf, ref);
522 read_extent_buffer(leaf, namebuf, (unsigned long)(ref + 1), namelen);
523 printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag,
524 (unsigned long long)btrfs_root_ref_dirid(leaf, ref),
525 (unsigned long long)btrfs_root_ref_sequence(leaf, ref),
529 static int count_bytes(void *buf, int len, char b)
533 for (i = 0; i < len; i++) {
534 if (((char*)buf)[i] == b)
541 * Caller must ensure sizeof(*ret) >= 7 "RDONLY"
543 static void root_flags_to_str(u64 flags, char *ret)
545 if (flags & BTRFS_ROOT_SUBVOL_RDONLY)
546 strcat(ret, "RDONLY");
551 static void print_root(struct extent_buffer *leaf, int slot)
553 struct btrfs_root_item *ri;
554 struct btrfs_root_item root_item;
556 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
557 char flags_str[32] = {0};
558 struct btrfs_key drop_key;
560 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
561 len = btrfs_item_size_nr(leaf, slot);
563 memset(&root_item, 0, sizeof(root_item));
564 read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);
565 root_flags_to_str(btrfs_root_flags(&root_item), flags_str);
567 printf("\t\tgeneration %llu root_dirid %llu bytenr %llu level %hhu refs %u\n",
568 (unsigned long long)btrfs_root_generation(&root_item),
569 (unsigned long long)btrfs_root_dirid(&root_item),
570 (unsigned long long)btrfs_root_bytenr(&root_item),
571 btrfs_root_level(&root_item),
572 btrfs_root_refs(&root_item));
573 printf("\t\tlastsnap %llu byte_limit %llu bytes_used %llu flags 0x%llx(%s)\n",
574 (unsigned long long)btrfs_root_last_snapshot(&root_item),
575 (unsigned long long)btrfs_root_limit(&root_item),
576 (unsigned long long)btrfs_root_used(&root_item),
577 (unsigned long long)btrfs_root_flags(&root_item),
580 if (root_item.generation == root_item.generation_v2) {
581 uuid_unparse(root_item.uuid, uuid_str);
582 printf("\t\tuuid %s\n", uuid_str);
583 if (count_bytes(root_item.parent_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
584 uuid_unparse(root_item.parent_uuid, uuid_str);
585 printf("\t\tparent_uuid %s\n", uuid_str);
587 if (count_bytes(root_item.received_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
588 uuid_unparse(root_item.received_uuid, uuid_str);
589 printf("\t\treceived_uuid %s\n", uuid_str);
591 if (root_item.ctransid) {
592 printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
593 btrfs_root_ctransid(&root_item),
594 btrfs_root_otransid(&root_item),
595 btrfs_root_stransid(&root_item),
596 btrfs_root_rtransid(&root_item));
600 btrfs_disk_key_to_cpu(&drop_key, &root_item.drop_progress);
602 btrfs_print_key(&root_item.drop_progress);
603 printf(" level %hhu\n", root_item.drop_level);
606 static void print_free_space_header(struct extent_buffer *leaf, int slot)
608 struct btrfs_free_space_header *header;
609 struct btrfs_disk_key location;
611 header = btrfs_item_ptr(leaf, slot, struct btrfs_free_space_header);
612 btrfs_free_space_key(leaf, header, &location);
613 printf("\t\tlocation ");
614 btrfs_print_key(&location);
616 printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
617 (unsigned long long)btrfs_free_space_generation(leaf, header),
618 (unsigned long long)btrfs_free_space_entries(leaf, header),
619 (unsigned long long)btrfs_free_space_bitmaps(leaf, header));
622 void print_key_type(FILE *stream, u64 objectid, u8 type)
624 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
625 fprintf(stream, "UNTYPED");
630 case BTRFS_INODE_ITEM_KEY:
631 fprintf(stream, "INODE_ITEM");
633 case BTRFS_INODE_REF_KEY:
634 fprintf(stream, "INODE_REF");
636 case BTRFS_INODE_EXTREF_KEY:
637 fprintf(stream, "INODE_EXTREF");
639 case BTRFS_DIR_ITEM_KEY:
640 fprintf(stream, "DIR_ITEM");
642 case BTRFS_DIR_INDEX_KEY:
643 fprintf(stream, "DIR_INDEX");
645 case BTRFS_DIR_LOG_ITEM_KEY:
646 fprintf(stream, "DIR_LOG_ITEM");
648 case BTRFS_DIR_LOG_INDEX_KEY:
649 fprintf(stream, "DIR_LOG_INDEX");
651 case BTRFS_XATTR_ITEM_KEY:
652 fprintf(stream, "XATTR_ITEM");
654 case BTRFS_ORPHAN_ITEM_KEY:
655 fprintf(stream, "ORPHAN_ITEM");
657 case BTRFS_ROOT_ITEM_KEY:
658 fprintf(stream, "ROOT_ITEM");
660 case BTRFS_ROOT_REF_KEY:
661 fprintf(stream, "ROOT_REF");
663 case BTRFS_ROOT_BACKREF_KEY:
664 fprintf(stream, "ROOT_BACKREF");
666 case BTRFS_EXTENT_ITEM_KEY:
667 fprintf(stream, "EXTENT_ITEM");
669 case BTRFS_METADATA_ITEM_KEY:
670 fprintf(stream, "METADATA_ITEM");
672 case BTRFS_TREE_BLOCK_REF_KEY:
673 fprintf(stream, "TREE_BLOCK_REF");
675 case BTRFS_SHARED_BLOCK_REF_KEY:
676 fprintf(stream, "SHARED_BLOCK_REF");
678 case BTRFS_EXTENT_DATA_REF_KEY:
679 fprintf(stream, "EXTENT_DATA_REF");
681 case BTRFS_SHARED_DATA_REF_KEY:
682 fprintf(stream, "SHARED_DATA_REF");
684 case BTRFS_EXTENT_REF_V0_KEY:
685 fprintf(stream, "EXTENT_REF_V0");
687 case BTRFS_CSUM_ITEM_KEY:
688 fprintf(stream, "CSUM_ITEM");
690 case BTRFS_EXTENT_CSUM_KEY:
691 fprintf(stream, "EXTENT_CSUM");
693 case BTRFS_EXTENT_DATA_KEY:
694 fprintf(stream, "EXTENT_DATA");
696 case BTRFS_BLOCK_GROUP_ITEM_KEY:
697 fprintf(stream, "BLOCK_GROUP_ITEM");
699 case BTRFS_FREE_SPACE_INFO_KEY:
700 fprintf(stream, "FREE_SPACE_INFO");
702 case BTRFS_FREE_SPACE_EXTENT_KEY:
703 fprintf(stream, "FREE_SPACE_EXTENT");
705 case BTRFS_FREE_SPACE_BITMAP_KEY:
706 fprintf(stream, "FREE_SPACE_BITMAP");
708 case BTRFS_CHUNK_ITEM_KEY:
709 fprintf(stream, "CHUNK_ITEM");
711 case BTRFS_DEV_ITEM_KEY:
712 fprintf(stream, "DEV_ITEM");
714 case BTRFS_DEV_EXTENT_KEY:
715 fprintf(stream, "DEV_EXTENT");
717 case BTRFS_BALANCE_ITEM_KEY:
718 fprintf(stream, "BALANCE_ITEM");
720 case BTRFS_DEV_REPLACE_KEY:
721 fprintf(stream, "DEV_REPLACE");
723 case BTRFS_STRING_ITEM_KEY:
724 fprintf(stream, "STRING_ITEM");
726 case BTRFS_QGROUP_STATUS_KEY:
727 fprintf(stream, "QGROUP_STATUS");
729 case BTRFS_QGROUP_RELATION_KEY:
730 fprintf(stream, "QGROUP_RELATION");
732 case BTRFS_QGROUP_INFO_KEY:
733 fprintf(stream, "QGROUP_INFO");
735 case BTRFS_QGROUP_LIMIT_KEY:
736 fprintf(stream, "QGROUP_LIMIT");
738 case BTRFS_DEV_STATS_KEY:
739 fprintf(stream, "DEV_STATS");
741 case BTRFS_UUID_KEY_SUBVOL:
742 fprintf(stream, "UUID_KEY_SUBVOL");
744 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
745 fprintf(stream, "UUID_KEY_RECEIVED_SUBVOL");
748 fprintf(stream, "UNKNOWN.%d", type);
752 void print_objectid(FILE *stream, u64 objectid, u8 type)
755 case BTRFS_DEV_EXTENT_KEY:
757 fprintf(stream, "%llu", (unsigned long long)objectid);
759 case BTRFS_QGROUP_RELATION_KEY:
760 fprintf(stream, "%llu/%llu", btrfs_qgroup_level(objectid),
761 btrfs_qgroup_subvid(objectid));
763 case BTRFS_UUID_KEY_SUBVOL:
764 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
765 fprintf(stream, "0x%016llx", (unsigned long long)objectid);
770 case BTRFS_ROOT_TREE_OBJECTID:
771 if (type == BTRFS_DEV_ITEM_KEY)
772 fprintf(stream, "DEV_ITEMS");
774 fprintf(stream, "ROOT_TREE");
776 case BTRFS_EXTENT_TREE_OBJECTID:
777 fprintf(stream, "EXTENT_TREE");
779 case BTRFS_CHUNK_TREE_OBJECTID:
780 fprintf(stream, "CHUNK_TREE");
782 case BTRFS_DEV_TREE_OBJECTID:
783 fprintf(stream, "DEV_TREE");
785 case BTRFS_FS_TREE_OBJECTID:
786 fprintf(stream, "FS_TREE");
788 case BTRFS_ROOT_TREE_DIR_OBJECTID:
789 fprintf(stream, "ROOT_TREE_DIR");
791 case BTRFS_CSUM_TREE_OBJECTID:
792 fprintf(stream, "CSUM_TREE");
794 case BTRFS_BALANCE_OBJECTID:
795 fprintf(stream, "BALANCE");
797 case BTRFS_ORPHAN_OBJECTID:
798 fprintf(stream, "ORPHAN");
800 case BTRFS_TREE_LOG_OBJECTID:
801 fprintf(stream, "TREE_LOG");
803 case BTRFS_TREE_LOG_FIXUP_OBJECTID:
804 fprintf(stream, "LOG_FIXUP");
806 case BTRFS_TREE_RELOC_OBJECTID:
807 fprintf(stream, "TREE_RELOC");
809 case BTRFS_DATA_RELOC_TREE_OBJECTID:
810 fprintf(stream, "DATA_RELOC_TREE");
812 case BTRFS_EXTENT_CSUM_OBJECTID:
813 fprintf(stream, "EXTENT_CSUM");
815 case BTRFS_FREE_SPACE_OBJECTID:
816 fprintf(stream, "FREE_SPACE");
818 case BTRFS_FREE_INO_OBJECTID:
819 fprintf(stream, "FREE_INO");
821 case BTRFS_QUOTA_TREE_OBJECTID:
822 fprintf(stream, "QUOTA_TREE");
824 case BTRFS_UUID_TREE_OBJECTID:
825 fprintf(stream, "UUID_TREE");
827 case BTRFS_FREE_SPACE_TREE_OBJECTID:
828 fprintf(stream, "FREE_SPACE_TREE");
830 case BTRFS_MULTIPLE_OBJECTIDS:
831 fprintf(stream, "MULTIPLE");
834 fprintf(stream, "-1");
836 case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
837 if (type == BTRFS_CHUNK_ITEM_KEY) {
838 fprintf(stream, "FIRST_CHUNK_TREE");
843 fprintf(stream, "%llu", (unsigned long long)objectid);
847 void btrfs_print_key(struct btrfs_disk_key *disk_key)
849 u64 objectid = btrfs_disk_key_objectid(disk_key);
850 u8 type = btrfs_disk_key_type(disk_key);
851 u64 offset = btrfs_disk_key_offset(disk_key);
854 print_objectid(stdout, objectid, type);
856 print_key_type(stdout, objectid, type);
858 case BTRFS_QGROUP_RELATION_KEY:
859 case BTRFS_QGROUP_INFO_KEY:
860 case BTRFS_QGROUP_LIMIT_KEY:
861 printf(" %llu/%llu)", btrfs_qgroup_level(offset),
862 btrfs_qgroup_subvid(offset));
864 case BTRFS_UUID_KEY_SUBVOL:
865 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
866 printf(" 0x%016llx)", (unsigned long long)offset);
869 if (offset == (u64)-1)
872 printf(" %llu)", (unsigned long long)offset);
877 static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
880 if (item_size & (sizeof(u64) - 1)) {
881 printf("btrfs: uuid item with illegal size %lu!\n",
882 (unsigned long)item_size);
888 read_extent_buffer(l, &subvol_id, offset, sizeof(u64));
889 printf("\t\tsubvol_id %llu\n",
890 (unsigned long long)le64_to_cpu(subvol_id));
891 item_size -= sizeof(u64);
892 offset += sizeof(u64);
896 /* Btrfs inode flag stringification helper */
897 #define STRCAT_ONE_INODE_FLAG(flags, name, empty, dst) ({ \
898 if (flags & BTRFS_INODE_##name) { \
901 strcat(dst, #name); \
907 * Caller should ensure sizeof(*ret) >= 102: all charactors plus '|' of
908 * BTRFS_INODE_* flags
910 static void inode_flags_to_str(u64 flags, char *ret)
914 STRCAT_ONE_INODE_FLAG(flags, NODATASUM, empty, ret);
915 STRCAT_ONE_INODE_FLAG(flags, NODATACOW, empty, ret);
916 STRCAT_ONE_INODE_FLAG(flags, READONLY, empty, ret);
917 STRCAT_ONE_INODE_FLAG(flags, NOCOMPRESS, empty, ret);
918 STRCAT_ONE_INODE_FLAG(flags, PREALLOC, empty, ret);
919 STRCAT_ONE_INODE_FLAG(flags, SYNC, empty, ret);
920 STRCAT_ONE_INODE_FLAG(flags, IMMUTABLE, empty, ret);
921 STRCAT_ONE_INODE_FLAG(flags, APPEND, empty, ret);
922 STRCAT_ONE_INODE_FLAG(flags, NODUMP, empty, ret);
923 STRCAT_ONE_INODE_FLAG(flags, NOATIME, empty, ret);
924 STRCAT_ONE_INODE_FLAG(flags, DIRSYNC, empty, ret);
925 STRCAT_ONE_INODE_FLAG(flags, COMPRESS, empty, ret);
930 static void print_timespec(struct extent_buffer *eb,
931 struct btrfs_timespec *timespec, const char *prefix,
940 tmp_u64 = btrfs_timespec_sec(eb, timespec);
941 tmp_u32 = btrfs_timespec_nsec(eb, timespec);
943 localtime_r(&tmp_time, &tm);
944 strftime(timestamp, sizeof(timestamp),
945 "%Y-%m-%d %H:%M:%S", &tm);
946 printf("%s%llu.%u (%s)%s", prefix, (unsigned long long)tmp_u64, tmp_u32,
950 static void print_inode_item(struct extent_buffer *eb,
951 struct btrfs_inode_item *ii)
955 memset(flags_str, 0, sizeof(flags_str));
956 inode_flags_to_str(btrfs_inode_flags(eb, ii), flags_str);
957 printf("\t\tinode generation %llu transid %llu size %llu nbytes %llu\n"
958 "\t\tblock group %llu mode %o links %u uid %u gid %u rdev %llu\n"
959 "\t\tsequence %llu flags 0x%llx(%s)\n",
960 (unsigned long long)btrfs_inode_generation(eb, ii),
961 (unsigned long long)btrfs_inode_transid(eb, ii),
962 (unsigned long long)btrfs_inode_size(eb, ii),
963 (unsigned long long)btrfs_inode_nbytes(eb, ii),
964 (unsigned long long)btrfs_inode_block_group(eb,ii),
965 btrfs_inode_mode(eb, ii),
966 btrfs_inode_nlink(eb, ii),
967 btrfs_inode_uid(eb, ii),
968 btrfs_inode_gid(eb, ii),
969 (unsigned long long)btrfs_inode_rdev(eb,ii),
970 (unsigned long long)btrfs_inode_flags(eb,ii),
971 (unsigned long long)btrfs_inode_sequence(eb, ii),
973 print_timespec(eb, btrfs_inode_atime(ii), "\t\tatime ", "\n");
974 print_timespec(eb, btrfs_inode_ctime(ii), "\t\tctime ", "\n");
975 print_timespec(eb, btrfs_inode_mtime(ii), "\t\tmtime ", "\n");
976 print_timespec(eb, btrfs_inode_otime(ii), "\t\totime ", "\n");
979 static void print_disk_balance_args(struct btrfs_disk_balance_args *ba)
981 printf("\t\tprofiles %llu devid %llu target %llu flags %llu\n",
982 (unsigned long long)le64_to_cpu(ba->profiles),
983 (unsigned long long)le64_to_cpu(ba->devid),
984 (unsigned long long)le64_to_cpu(ba->target),
985 (unsigned long long)le64_to_cpu(ba->flags));
986 printf("\t\tusage_min %u usage_max %u pstart %llu pend %llu\n",
987 le32_to_cpu(ba->usage_min),
988 le32_to_cpu(ba->usage_max),
989 (unsigned long long)le64_to_cpu(ba->pstart),
990 (unsigned long long)le64_to_cpu(ba->pend));
991 printf("\t\tvstart %llu vend %llu limit_min %u limit_max %u\n",
992 (unsigned long long)le64_to_cpu(ba->vstart),
993 (unsigned long long)le64_to_cpu(ba->vend),
994 le32_to_cpu(ba->limit_min),
995 le32_to_cpu(ba->limit_max));
996 printf("\t\tstripes_min %u stripes_max %u\n",
997 le32_to_cpu(ba->stripes_min),
998 le32_to_cpu(ba->stripes_max));
1001 static void print_balance_item(struct extent_buffer *eb,
1002 struct btrfs_balance_item *bi)
1004 printf("\t\tbalance status flags %llu\n",
1005 btrfs_balance_item_flags(eb, bi));
1007 printf("\t\tDATA\n");
1008 print_disk_balance_args(btrfs_balance_item_data(eb, bi));
1009 printf("\t\tMETADATA\n");
1010 print_disk_balance_args(btrfs_balance_item_meta(eb, bi));
1011 printf("\t\tSYSTEM\n");
1012 print_disk_balance_args(btrfs_balance_item_sys(eb, bi));
1015 static void print_dev_stats(struct extent_buffer *eb,
1016 struct btrfs_dev_stats_item *stats, u32 size)
1019 u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64);
1020 __le64 *values = btrfs_dev_stats_values(eb, stats);
1022 printf("\t\tdevice stats\n");
1023 printf("\t\twrite_errs %llu read_errs %llu flush_errs %llu corruption_errs %llu generation %llu\n",
1024 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_WRITE_ERRS]),
1025 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_READ_ERRS]),
1026 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_FLUSH_ERRS]),
1027 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_CORRUPTION_ERRS]),
1028 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_GENERATION_ERRS]));
1031 printf("\t\tunknown stats item bytes %u", size - known);
1032 for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
1033 printf("\t\tunknown item %u offset %lu value %llu\n",
1034 i, i * sizeof(__le64),
1035 (unsigned long long)le64_to_cpu(values[i]));
1040 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
1044 struct btrfs_item *item;
1045 struct btrfs_dir_item *di;
1046 struct btrfs_inode_item *ii;
1047 struct btrfs_file_extent_item *fi;
1048 struct btrfs_block_group_item *bi;
1049 struct btrfs_extent_data_ref *dref;
1050 struct btrfs_shared_data_ref *sref;
1051 struct btrfs_inode_ref *iref;
1052 struct btrfs_inode_extref *iref2;
1053 struct btrfs_dev_extent *dev_extent;
1054 struct btrfs_disk_key disk_key;
1055 struct btrfs_block_group_item bg_item;
1056 struct btrfs_free_space_info *free_info;
1057 struct btrfs_dir_log_item *dlog;
1058 struct btrfs_qgroup_info_item *qg_info;
1059 struct btrfs_qgroup_limit_item *qg_limit;
1060 struct btrfs_qgroup_status_item *qg_status;
1061 u32 nr = btrfs_header_nritems(l);
1065 char flags_str[256];
1066 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
1067 u8 uuid[BTRFS_UUID_SIZE];
1069 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
1070 (unsigned long long)btrfs_header_bytenr(l), nr,
1071 btrfs_leaf_free_space(root, l),
1072 (unsigned long long)btrfs_header_generation(l),
1073 (unsigned long long)btrfs_header_owner(l));
1076 for (i = 0 ; i < nr ; i++) {
1077 item = btrfs_item_nr(i);
1078 btrfs_item_key(l, &disk_key, i);
1079 objectid = btrfs_disk_key_objectid(&disk_key);
1080 type = btrfs_disk_key_type(&disk_key);
1081 offset = btrfs_disk_key_offset(&disk_key);
1082 printf("\titem %d ", i);
1083 btrfs_print_key(&disk_key);
1084 printf(" itemoff %d itemsize %d\n",
1085 btrfs_item_offset(l, item),
1086 btrfs_item_size(l, item));
1088 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID)
1089 print_free_space_header(l, i);
1092 case BTRFS_INODE_ITEM_KEY:
1093 ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
1094 print_inode_item(l, ii);
1096 case BTRFS_INODE_REF_KEY:
1097 iref = btrfs_item_ptr(l, i, struct btrfs_inode_ref);
1098 print_inode_ref_item(l, item, iref);
1100 case BTRFS_INODE_EXTREF_KEY:
1101 iref2 = btrfs_item_ptr(l, i, struct btrfs_inode_extref);
1102 print_inode_extref_item(l, item, iref2);
1104 case BTRFS_DIR_ITEM_KEY:
1105 case BTRFS_DIR_INDEX_KEY:
1106 case BTRFS_XATTR_ITEM_KEY:
1107 di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
1108 print_dir_item(l, item, di);
1110 case BTRFS_DIR_LOG_INDEX_KEY:
1111 case BTRFS_DIR_LOG_ITEM_KEY:
1112 dlog = btrfs_item_ptr(l, i, struct btrfs_dir_log_item);
1113 printf("\t\tdir log end %Lu\n",
1114 (unsigned long long)btrfs_dir_log_end(l, dlog));
1116 case BTRFS_ORPHAN_ITEM_KEY:
1117 printf("\t\torphan item\n");
1119 case BTRFS_ROOT_ITEM_KEY:
1122 case BTRFS_ROOT_REF_KEY:
1123 print_root_ref(l, i, "ref");
1125 case BTRFS_ROOT_BACKREF_KEY:
1126 print_root_ref(l, i, "backref");
1128 case BTRFS_EXTENT_ITEM_KEY:
1129 print_extent_item(l, i, 0);
1131 case BTRFS_METADATA_ITEM_KEY:
1132 print_extent_item(l, i, 1);
1134 case BTRFS_TREE_BLOCK_REF_KEY:
1135 printf("\t\ttree block backref\n");
1137 case BTRFS_SHARED_BLOCK_REF_KEY:
1138 printf("\t\tshared block backref\n");
1140 case BTRFS_EXTENT_DATA_REF_KEY:
1141 dref = btrfs_item_ptr(l, i, struct btrfs_extent_data_ref);
1142 printf("\t\textent data backref root %llu "
1143 "objectid %llu offset %llu count %u\n",
1144 (unsigned long long)btrfs_extent_data_ref_root(l, dref),
1145 (unsigned long long)btrfs_extent_data_ref_objectid(l, dref),
1146 (unsigned long long)btrfs_extent_data_ref_offset(l, dref),
1147 btrfs_extent_data_ref_count(l, dref));
1149 case BTRFS_SHARED_DATA_REF_KEY:
1150 sref = btrfs_item_ptr(l, i, struct btrfs_shared_data_ref);
1151 printf("\t\tshared data backref count %u\n",
1152 btrfs_shared_data_ref_count(l, sref));
1154 case BTRFS_EXTENT_REF_V0_KEY:
1155 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1156 print_extent_ref_v0(l, i);
1161 case BTRFS_CSUM_ITEM_KEY:
1162 printf("\t\tcsum item\n");
1164 case BTRFS_EXTENT_CSUM_KEY:
1165 printf("\t\textent csum item\n");
1167 case BTRFS_EXTENT_DATA_KEY:
1168 fi = btrfs_item_ptr(l, i,
1169 struct btrfs_file_extent_item);
1170 print_file_extent_item(l, item, i, fi);
1172 case BTRFS_BLOCK_GROUP_ITEM_KEY:
1173 bi = btrfs_item_ptr(l, i,
1174 struct btrfs_block_group_item);
1175 read_extent_buffer(l, &bg_item, (unsigned long)bi,
1177 memset(flags_str, 0, sizeof(flags_str));
1178 bg_flags_to_str(btrfs_block_group_flags(&bg_item),
1180 printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
1181 (unsigned long long)btrfs_block_group_used(&bg_item),
1182 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
1185 case BTRFS_FREE_SPACE_INFO_KEY:
1186 free_info = btrfs_item_ptr(l, i, struct btrfs_free_space_info);
1187 printf("\t\tfree space info extent count %u flags %u\n",
1188 (unsigned)btrfs_free_space_extent_count(l, free_info),
1189 (unsigned)btrfs_free_space_flags(l, free_info));
1191 case BTRFS_FREE_SPACE_EXTENT_KEY:
1192 printf("\t\tfree space extent\n");
1194 case BTRFS_FREE_SPACE_BITMAP_KEY:
1195 printf("\t\tfree space bitmap\n");
1197 case BTRFS_CHUNK_ITEM_KEY:
1198 print_chunk(l, btrfs_item_ptr(l, i, struct btrfs_chunk));
1200 case BTRFS_DEV_ITEM_KEY:
1201 print_dev_item(l, btrfs_item_ptr(l, i,
1202 struct btrfs_dev_item));
1204 case BTRFS_DEV_EXTENT_KEY:
1205 dev_extent = btrfs_item_ptr(l, i,
1206 struct btrfs_dev_extent);
1207 read_extent_buffer(l, uuid,
1208 (unsigned long)btrfs_dev_extent_chunk_tree_uuid(dev_extent),
1210 uuid_unparse(uuid, uuid_str);
1211 printf("\t\tdev extent chunk_tree %llu\n"
1212 "\t\tchunk_objectid %llu chunk_offset %llu "
1214 "\t\tchunk_tree_uuid %s\n",
1215 (unsigned long long)
1216 btrfs_dev_extent_chunk_tree(l, dev_extent),
1217 (unsigned long long)
1218 btrfs_dev_extent_chunk_objectid(l, dev_extent),
1219 (unsigned long long)
1220 btrfs_dev_extent_chunk_offset(l, dev_extent),
1221 (unsigned long long)
1222 btrfs_dev_extent_length(l, dev_extent),
1225 case BTRFS_QGROUP_STATUS_KEY:
1226 qg_status = btrfs_item_ptr(l, i,
1227 struct btrfs_qgroup_status_item);
1228 memset(flags_str, 0, sizeof(flags_str));
1229 qgroup_flags_to_str(btrfs_qgroup_status_flags(l, qg_status),
1231 printf("\t\tversion %llu generation %llu flags %s "
1233 (unsigned long long)
1234 btrfs_qgroup_status_version(l, qg_status),
1235 (unsigned long long)
1236 btrfs_qgroup_status_generation(l, qg_status),
1238 (unsigned long long)
1239 btrfs_qgroup_status_rescan(l, qg_status));
1241 case BTRFS_QGROUP_RELATION_KEY:
1243 case BTRFS_QGROUP_INFO_KEY:
1244 qg_info = btrfs_item_ptr(l, i,
1245 struct btrfs_qgroup_info_item);
1246 printf("\t\tgeneration %llu\n"
1247 "\t\treferenced %llu referenced_compressed %llu\n"
1248 "\t\texclusive %llu exclusive_compressed %llu\n",
1249 (unsigned long long)
1250 btrfs_qgroup_info_generation(l, qg_info),
1251 (unsigned long long)
1252 btrfs_qgroup_info_referenced(l, qg_info),
1253 (unsigned long long)
1254 btrfs_qgroup_info_referenced_compressed(l,
1256 (unsigned long long)
1257 btrfs_qgroup_info_exclusive(l, qg_info),
1258 (unsigned long long)
1259 btrfs_qgroup_info_exclusive_compressed(l,
1262 case BTRFS_QGROUP_LIMIT_KEY:
1263 qg_limit = btrfs_item_ptr(l, i,
1264 struct btrfs_qgroup_limit_item);
1265 printf("\t\tflags %llx\n"
1266 "\t\tmax_referenced %lld max_exclusive %lld\n"
1267 "\t\trsv_referenced %lld rsv_exclusive %lld\n",
1268 (unsigned long long)
1269 btrfs_qgroup_limit_flags(l, qg_limit),
1271 btrfs_qgroup_limit_max_referenced(l, qg_limit),
1273 btrfs_qgroup_limit_max_exclusive(l, qg_limit),
1275 btrfs_qgroup_limit_rsv_referenced(l, qg_limit),
1277 btrfs_qgroup_limit_rsv_exclusive(l, qg_limit));
1279 case BTRFS_UUID_KEY_SUBVOL:
1280 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
1281 print_uuid_item(l, btrfs_item_ptr_offset(l, i),
1282 btrfs_item_size_nr(l, i));
1284 case BTRFS_STRING_ITEM_KEY:
1285 /* dirty, but it's simple */
1286 str = l->data + btrfs_item_ptr_offset(l, i);
1287 printf("\t\titem data %.*s\n", btrfs_item_size(l, item), str);
1289 case BTRFS_PERSISTENT_ITEM_KEY:
1290 printf("\t\tpersistent item objectid ");
1291 print_objectid(stdout, objectid, BTRFS_PERSISTENT_ITEM_KEY);
1292 printf(" offset %llu\n", (unsigned long long)offset);
1294 case BTRFS_DEV_STATS_OBJECTID:
1295 print_dev_stats(l, btrfs_item_ptr(l, i,
1296 struct btrfs_dev_stats_item),
1297 btrfs_item_size(l, item));
1300 printf("\t\tunknown persistent item objectid %llu\n",
1304 case BTRFS_TEMPORARY_ITEM_KEY:
1305 printf("\t\ttemporary item objectid ");
1306 print_objectid(stdout, objectid, BTRFS_TEMPORARY_ITEM_KEY);
1307 printf(" offset %llu\n", (unsigned long long)offset);
1309 case BTRFS_BALANCE_OBJECTID:
1310 print_balance_item(l, btrfs_item_ptr(l, i,
1311 struct btrfs_balance_item));
1314 printf("\t\tunknown temporary item objectid %llu\n",
1323 void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
1328 struct btrfs_disk_key disk_key;
1329 struct btrfs_key key;
1330 struct extent_buffer *next;
1334 nr = btrfs_header_nritems(eb);
1335 if (btrfs_is_leaf(eb)) {
1336 btrfs_print_leaf(root, eb);
1339 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
1340 (unsigned long long)eb->start,
1341 btrfs_header_level(eb), nr,
1342 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
1343 (unsigned long long)btrfs_header_generation(eb),
1344 (unsigned long long)btrfs_header_owner(eb));
1347 size = root->nodesize;
1348 for (i = 0; i < nr; i++) {
1349 u64 blocknr = btrfs_node_blockptr(eb, i);
1350 btrfs_node_key(eb, &disk_key, i);
1351 btrfs_disk_key_to_cpu(&key, &disk_key);
1353 btrfs_print_key(&disk_key);
1354 printf(" block %llu (%llu) gen %llu\n",
1355 (unsigned long long)blocknr,
1356 (unsigned long long)blocknr / size,
1357 (unsigned long long)btrfs_node_ptr_generation(eb, i));
1363 for (i = 0; i < nr; i++) {
1364 next = read_tree_block(root, btrfs_node_blockptr(eb, i), size,
1365 btrfs_node_ptr_generation(eb, i));
1366 if (!extent_buffer_uptodate(next)) {
1367 fprintf(stderr, "failed to read %llu in tree %llu\n",
1368 (unsigned long long)btrfs_node_blockptr(eb, i),
1369 (unsigned long long)btrfs_header_owner(eb));
1372 if (btrfs_is_leaf(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 if (btrfs_header_level(next) != btrfs_header_level(eb) - 1) {
1381 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1382 i, btrfs_header_level(next),
1383 btrfs_header_level(eb));
1386 btrfs_print_tree(root, next, 1);
1387 free_extent_buffer(next);
1393 free_extent_buffer(next);