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);
34 static const char* dir_item_str[] = {
35 [BTRFS_FT_REG_FILE] = "FILE",
36 [BTRFS_FT_DIR] = "DIR",
37 [BTRFS_FT_CHRDEV] = "CHRDEV",
38 [BTRFS_FT_BLKDEV] = "BLKDEV",
39 [BTRFS_FT_FIFO] = "FIFO",
40 [BTRFS_FT_SOCK] = "SOCK",
41 [BTRFS_FT_SYMLINK] = "SYMLINK",
42 [BTRFS_FT_XATTR] = "XATTR"
45 if (type < ARRAY_SIZE(dir_item_str) && dir_item_str[type])
46 printf("%s", dir_item_str[type]);
48 printf("DIR_ITEM.%u", type);
51 static void print_dir_item(struct extent_buffer *eb, u32 size,
52 struct btrfs_dir_item *di)
58 char namebuf[BTRFS_NAME_LEN];
59 struct btrfs_disk_key location;
62 btrfs_dir_item_key(eb, di, &location);
63 printf("\t\tlocation ");
64 btrfs_print_key(&location);
66 print_dir_item_type(eb, di);
68 name_len = btrfs_dir_name_len(eb, di);
69 data_len = btrfs_dir_data_len(eb, di);
70 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
71 read_extent_buffer(eb, namebuf, (unsigned long)(di + 1), len);
72 printf("\t\ttransid %llu data_len %u name_len %u\n",
73 btrfs_dir_transid(eb, di),
75 printf("\t\tname: %.*s\n", len, namebuf);
77 len = (data_len <= sizeof(namebuf))? data_len: sizeof(namebuf);
78 read_extent_buffer(eb, namebuf,
79 (unsigned long)(di + 1) + name_len, len);
80 printf("\t\tdata %.*s\n", len, namebuf);
82 len = sizeof(*di) + name_len + data_len;
83 di = (struct btrfs_dir_item *)((char *)di + len);
88 static void print_inode_extref_item(struct extent_buffer *eb, u32 size,
89 struct btrfs_inode_extref *extref)
96 char namebuf[BTRFS_NAME_LEN];
99 index = btrfs_inode_extref_index(eb, extref);
100 name_len = btrfs_inode_extref_name_len(eb, extref);
101 parent_objid = btrfs_inode_extref_parent(eb, extref);
103 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
105 read_extent_buffer(eb, namebuf, (unsigned long)(extref->name), len);
107 printf("\t\tinode extref index %llu parent %llu namelen %u "
109 (unsigned long long)index,
110 (unsigned long long)parent_objid,
111 name_len, len, namebuf);
113 len = sizeof(*extref) + name_len;
114 extref = (struct btrfs_inode_extref *)((char *)extref + len);
119 static void print_inode_ref_item(struct extent_buffer *eb, u32 size,
120 struct btrfs_inode_ref *ref)
126 char namebuf[BTRFS_NAME_LEN];
129 name_len = btrfs_inode_ref_name_len(eb, ref);
130 index = btrfs_inode_ref_index(eb, ref);
131 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
132 read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len);
133 printf("\t\tinode ref index %llu namelen %u name: %.*s\n",
134 (unsigned long long)index, name_len, len, namebuf);
135 len = sizeof(*ref) + name_len;
136 ref = (struct btrfs_inode_ref *)((char *)ref + len);
141 /* Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10" */
142 static void bg_flags_to_str(u64 flags, char *ret)
146 if (flags & BTRFS_BLOCK_GROUP_DATA) {
150 if (flags & BTRFS_BLOCK_GROUP_METADATA) {
153 strcat(ret, "METADATA");
155 if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
158 strcat(ret, "SYSTEM");
160 switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
161 case BTRFS_BLOCK_GROUP_RAID0:
162 strcat(ret, "|RAID0");
164 case BTRFS_BLOCK_GROUP_RAID1:
165 strcat(ret, "|RAID1");
167 case BTRFS_BLOCK_GROUP_DUP:
170 case BTRFS_BLOCK_GROUP_RAID10:
171 strcat(ret, "|RAID10");
173 case BTRFS_BLOCK_GROUP_RAID5:
174 strcat(ret, "|RAID5");
176 case BTRFS_BLOCK_GROUP_RAID6:
177 strcat(ret, "|RAID6");
184 /* Caller should ensure sizeof(*ret)>= 26 "OFF|SCANNING|INCONSISTENT" */
185 static void qgroup_flags_to_str(u64 flags, char *ret)
187 if (flags & BTRFS_QGROUP_STATUS_FLAG_ON)
192 if (flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN)
193 strcat(ret, "|SCANNING");
194 if (flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
195 strcat(ret, "|INCONSISTENT");
198 void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
200 int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
202 char chunk_flags_str[32] = {0};
204 bg_flags_to_str(btrfs_chunk_type(eb, chunk), chunk_flags_str);
205 printf("\t\tlength %llu owner %llu stripe_len %llu type %s\n",
206 (unsigned long long)btrfs_chunk_length(eb, chunk),
207 (unsigned long long)btrfs_chunk_owner(eb, chunk),
208 (unsigned long long)btrfs_chunk_stripe_len(eb, chunk),
210 printf("\t\tio_align %u io_width %u sector_size %u\n",
211 btrfs_chunk_io_align(eb, chunk),
212 btrfs_chunk_io_width(eb, chunk),
213 btrfs_chunk_sector_size(eb, chunk));
214 printf("\t\tnum_stripes %hu sub_stripes %hu\n", num_stripes,
215 btrfs_chunk_sub_stripes(eb, chunk));
216 for (i = 0 ; i < num_stripes ; i++) {
217 unsigned char dev_uuid[BTRFS_UUID_SIZE];
218 char str_dev_uuid[BTRFS_UUID_UNPARSED_SIZE];
220 read_extent_buffer(eb, dev_uuid,
221 (unsigned long)btrfs_stripe_dev_uuid_nr(chunk, i),
223 uuid_unparse(dev_uuid, str_dev_uuid);
224 printf("\t\t\tstripe %d devid %llu offset %llu\n", i,
225 (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i),
226 (unsigned long long)btrfs_stripe_offset_nr(eb, chunk, i));
227 printf("\t\t\tdev_uuid %s\n", str_dev_uuid);
231 static void print_dev_item(struct extent_buffer *eb,
232 struct btrfs_dev_item *dev_item)
234 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
235 char fsid_str[BTRFS_UUID_UNPARSED_SIZE];
236 u8 uuid[BTRFS_UUID_SIZE];
237 u8 fsid[BTRFS_UUID_SIZE];
239 read_extent_buffer(eb, uuid,
240 (unsigned long)btrfs_device_uuid(dev_item),
242 uuid_unparse(uuid, uuid_str);
243 read_extent_buffer(eb, fsid,
244 (unsigned long)btrfs_device_fsid(dev_item),
246 uuid_unparse(fsid, fsid_str);
247 printf("\t\tdevid %llu total_bytes %llu bytes_used %Lu\n"
248 "\t\tio_align %u io_width %u sector_size %u type %llu\n"
249 "\t\tgeneration %llu start_offset %llu dev_group %u\n"
250 "\t\tseek_speed %hhu bandwidth %hhu\n"
253 (unsigned long long)btrfs_device_id(eb, dev_item),
254 (unsigned long long)btrfs_device_total_bytes(eb, dev_item),
255 (unsigned long long)btrfs_device_bytes_used(eb, dev_item),
256 btrfs_device_io_align(eb, dev_item),
257 btrfs_device_io_width(eb, dev_item),
258 btrfs_device_sector_size(eb, dev_item),
259 (unsigned long long)btrfs_device_type(eb, dev_item),
260 (unsigned long long)btrfs_device_generation(eb, dev_item),
261 (unsigned long long)btrfs_device_start_offset(eb, dev_item),
262 btrfs_device_group(eb, dev_item),
263 btrfs_device_seek_speed(eb, dev_item),
264 btrfs_device_bandwidth(eb, dev_item),
268 static void print_uuids(struct extent_buffer *eb)
270 char fs_uuid[BTRFS_UUID_UNPARSED_SIZE];
271 char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE];
272 u8 disk_uuid[BTRFS_UUID_SIZE];
274 read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(),
277 fs_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
278 uuid_unparse(disk_uuid, fs_uuid);
280 read_extent_buffer(eb, disk_uuid,
281 btrfs_header_chunk_tree_uuid(eb),
284 chunk_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
285 uuid_unparse(disk_uuid, chunk_uuid);
286 printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid);
289 static void compress_type_to_str(u8 compress_type, char *ret)
291 switch (compress_type) {
292 case BTRFS_COMPRESS_NONE:
295 case BTRFS_COMPRESS_ZLIB:
298 case BTRFS_COMPRESS_LZO:
302 sprintf(ret, "UNKNOWN.%d", compress_type);
306 static const char* file_extent_type_to_str(u8 type)
309 case BTRFS_FILE_EXTENT_INLINE: return "inline";
310 case BTRFS_FILE_EXTENT_PREALLOC: return "prealloc";
311 case BTRFS_FILE_EXTENT_REG: return "regular";
312 default: return "unknown";
316 static void print_file_extent_item(struct extent_buffer *eb,
317 struct btrfs_item *item,
319 struct btrfs_file_extent_item *fi)
321 int extent_type = btrfs_file_extent_type(eb, fi);
322 char compress_str[16];
324 compress_type_to_str(btrfs_file_extent_compression(eb, fi),
327 printf("\t\tgeneration %llu type %hhu (%s)\n",
328 btrfs_file_extent_generation(eb, fi),
329 extent_type, file_extent_type_to_str(extent_type));
331 if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
332 printf("\t\tinline extent data size %u ram_bytes %u compression %hhu (%s)\n",
333 btrfs_file_extent_inline_item_len(eb, item),
334 btrfs_file_extent_inline_len(eb, slot, fi),
335 btrfs_file_extent_compression(eb, fi),
339 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
340 printf("\t\tprealloc data disk byte %llu nr %llu\n",
341 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
342 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
343 printf("\t\tprealloc data offset %llu nr %llu\n",
344 (unsigned long long)btrfs_file_extent_offset(eb, fi),
345 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi));
348 printf("\t\textent data disk byte %llu nr %llu\n",
349 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
350 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
351 printf("\t\textent data offset %llu nr %llu ram %llu\n",
352 (unsigned long long)btrfs_file_extent_offset(eb, fi),
353 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi),
354 (unsigned long long)btrfs_file_extent_ram_bytes(eb, fi));
355 printf("\t\textent compression %hhu (%s)\n",
356 btrfs_file_extent_compression(eb, fi),
360 /* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
361 static void extent_flags_to_str(u64 flags, char *ret)
365 if (flags & BTRFS_EXTENT_FLAG_DATA) {
369 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
374 strcat(ret, "TREE_BLOCK");
376 if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
378 strcat(ret, "FULL_BACKREF");
382 void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
384 struct btrfs_extent_item *ei;
385 struct btrfs_extent_inline_ref *iref;
386 struct btrfs_extent_data_ref *dref;
387 struct btrfs_shared_data_ref *sref;
388 struct btrfs_disk_key key;
392 u32 item_size = btrfs_item_size_nr(eb, slot);
395 char flags_str[32] = {0};
397 if (item_size < sizeof(*ei)) {
398 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
399 struct btrfs_extent_item_v0 *ei0;
400 BUG_ON(item_size != sizeof(*ei0));
401 ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0);
402 printf("\t\textent refs %u\n",
403 btrfs_extent_refs_v0(eb, ei0));
410 ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
411 flags = btrfs_extent_flags(eb, ei);
412 extent_flags_to_str(flags, flags_str);
414 printf("\t\textent refs %llu gen %llu flags %s\n",
415 (unsigned long long)btrfs_extent_refs(eb, ei),
416 (unsigned long long)btrfs_extent_generation(eb, ei),
419 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !metadata) {
420 struct btrfs_tree_block_info *info;
421 info = (struct btrfs_tree_block_info *)(ei + 1);
422 btrfs_tree_block_key(eb, info, &key);
423 printf("\t\ttree block ");
424 btrfs_print_key(&key);
425 printf(" level %d\n", btrfs_tree_block_level(eb, info));
426 iref = (struct btrfs_extent_inline_ref *)(info + 1);
427 } else if (metadata) {
428 struct btrfs_key tmp;
430 btrfs_item_key_to_cpu(eb, &tmp, slot);
431 printf("\t\ttree block skinny level %d\n", (int)tmp.offset);
432 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
434 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
437 ptr = (unsigned long)iref;
438 end = (unsigned long)ei + item_size;
440 iref = (struct btrfs_extent_inline_ref *)ptr;
441 type = btrfs_extent_inline_ref_type(eb, iref);
442 offset = btrfs_extent_inline_ref_offset(eb, iref);
444 case BTRFS_TREE_BLOCK_REF_KEY:
445 printf("\t\ttree block backref root %llu\n",
446 (unsigned long long)offset);
448 case BTRFS_SHARED_BLOCK_REF_KEY:
449 printf("\t\tshared block backref parent %llu\n",
450 (unsigned long long)offset);
452 case BTRFS_EXTENT_DATA_REF_KEY:
453 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
454 printf("\t\textent data backref root %llu "
455 "objectid %llu offset %llu count %u\n",
456 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
457 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
458 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
459 btrfs_extent_data_ref_count(eb, dref));
461 case BTRFS_SHARED_DATA_REF_KEY:
462 sref = (struct btrfs_shared_data_ref *)(iref + 1);
463 printf("\t\tshared data backref parent %llu count %u\n",
464 (unsigned long long)offset,
465 btrfs_shared_data_ref_count(eb, sref));
470 ptr += btrfs_extent_inline_ref_size(type);
475 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
476 static void print_extent_ref_v0(struct extent_buffer *eb, int slot)
478 struct btrfs_extent_ref_v0 *ref0;
480 ref0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_ref_v0);
481 printf("\t\textent back ref root %llu gen %llu "
482 "owner %llu num_refs %lu\n",
483 (unsigned long long)btrfs_ref_root_v0(eb, ref0),
484 (unsigned long long)btrfs_ref_generation_v0(eb, ref0),
485 (unsigned long long)btrfs_ref_objectid_v0(eb, ref0),
486 (unsigned long)btrfs_ref_count_v0(eb, ref0));
490 static void print_root_ref(struct extent_buffer *leaf, int slot, const char *tag)
492 struct btrfs_root_ref *ref;
493 char namebuf[BTRFS_NAME_LEN];
496 ref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref);
497 namelen = btrfs_root_ref_name_len(leaf, ref);
498 read_extent_buffer(leaf, namebuf, (unsigned long)(ref + 1), namelen);
499 printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag,
500 (unsigned long long)btrfs_root_ref_dirid(leaf, ref),
501 (unsigned long long)btrfs_root_ref_sequence(leaf, ref),
505 static int empty_uuid(const u8 *uuid)
509 for (i = 0; i < BTRFS_UUID_SIZE; i++)
516 * Caller must ensure sizeof(*ret) >= 7 "RDONLY"
518 static void root_flags_to_str(u64 flags, char *ret)
520 if (flags & BTRFS_ROOT_SUBVOL_RDONLY)
521 strcat(ret, "RDONLY");
526 static void print_root(struct extent_buffer *leaf, int slot)
528 struct btrfs_root_item *ri;
529 struct btrfs_root_item root_item;
531 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
532 char flags_str[32] = {0};
533 struct btrfs_key drop_key;
535 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
536 len = btrfs_item_size_nr(leaf, slot);
538 memset(&root_item, 0, sizeof(root_item));
539 read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);
540 root_flags_to_str(btrfs_root_flags(&root_item), flags_str);
542 printf("\t\tgeneration %llu root_dirid %llu bytenr %llu level %hhu refs %u\n",
543 (unsigned long long)btrfs_root_generation(&root_item),
544 (unsigned long long)btrfs_root_dirid(&root_item),
545 (unsigned long long)btrfs_root_bytenr(&root_item),
546 btrfs_root_level(&root_item),
547 btrfs_root_refs(&root_item));
548 printf("\t\tlastsnap %llu byte_limit %llu bytes_used %llu flags 0x%llx(%s)\n",
549 (unsigned long long)btrfs_root_last_snapshot(&root_item),
550 (unsigned long long)btrfs_root_limit(&root_item),
551 (unsigned long long)btrfs_root_used(&root_item),
552 (unsigned long long)btrfs_root_flags(&root_item),
555 if (root_item.generation == root_item.generation_v2) {
556 uuid_unparse(root_item.uuid, uuid_str);
557 printf("\t\tuuid %s\n", uuid_str);
558 if (!empty_uuid(root_item.parent_uuid)) {
559 uuid_unparse(root_item.parent_uuid, uuid_str);
560 printf("\t\tparent_uuid %s\n", uuid_str);
562 if (!empty_uuid(root_item.received_uuid)) {
563 uuid_unparse(root_item.received_uuid, uuid_str);
564 printf("\t\treceived_uuid %s\n", uuid_str);
566 if (root_item.ctransid) {
567 printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
568 btrfs_root_ctransid(&root_item),
569 btrfs_root_otransid(&root_item),
570 btrfs_root_stransid(&root_item),
571 btrfs_root_rtransid(&root_item));
575 btrfs_disk_key_to_cpu(&drop_key, &root_item.drop_progress);
577 btrfs_print_key(&root_item.drop_progress);
578 printf(" level %hhu\n", root_item.drop_level);
581 static void print_free_space_header(struct extent_buffer *leaf, int slot)
583 struct btrfs_free_space_header *header;
584 struct btrfs_disk_key location;
586 header = btrfs_item_ptr(leaf, slot, struct btrfs_free_space_header);
587 btrfs_free_space_key(leaf, header, &location);
588 printf("\t\tlocation ");
589 btrfs_print_key(&location);
591 printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
592 (unsigned long long)btrfs_free_space_generation(leaf, header),
593 (unsigned long long)btrfs_free_space_entries(leaf, header),
594 (unsigned long long)btrfs_free_space_bitmaps(leaf, header));
597 void print_key_type(FILE *stream, u64 objectid, u8 type)
599 static const char* key_to_str[256] = {
600 [BTRFS_INODE_ITEM_KEY] = "INODE_ITEM",
601 [BTRFS_INODE_REF_KEY] = "INODE_REF",
602 [BTRFS_INODE_EXTREF_KEY] = "INODE_EXTREF",
603 [BTRFS_DIR_ITEM_KEY] = "DIR_ITEM",
604 [BTRFS_DIR_INDEX_KEY] = "DIR_INDEX",
605 [BTRFS_DIR_LOG_ITEM_KEY] = "DIR_LOG_ITEM",
606 [BTRFS_DIR_LOG_INDEX_KEY] = "DIR_LOG_INDEX",
607 [BTRFS_XATTR_ITEM_KEY] = "XATTR_ITEM",
608 [BTRFS_ORPHAN_ITEM_KEY] = "ORPHAN_ITEM",
609 [BTRFS_ROOT_ITEM_KEY] = "ROOT_ITEM",
610 [BTRFS_ROOT_REF_KEY] = "ROOT_REF",
611 [BTRFS_ROOT_BACKREF_KEY] = "ROOT_BACKREF",
612 [BTRFS_EXTENT_ITEM_KEY] = "EXTENT_ITEM",
613 [BTRFS_METADATA_ITEM_KEY] = "METADATA_ITEM",
614 [BTRFS_TREE_BLOCK_REF_KEY] = "TREE_BLOCK_REF",
615 [BTRFS_SHARED_BLOCK_REF_KEY] = "SHARED_BLOCK_REF",
616 [BTRFS_EXTENT_DATA_REF_KEY] = "EXTENT_DATA_REF",
617 [BTRFS_SHARED_DATA_REF_KEY] = "SHARED_DATA_REF",
618 [BTRFS_EXTENT_REF_V0_KEY] = "EXTENT_REF_V0",
619 [BTRFS_CSUM_ITEM_KEY] = "CSUM_ITEM",
620 [BTRFS_EXTENT_CSUM_KEY] = "EXTENT_CSUM",
621 [BTRFS_EXTENT_DATA_KEY] = "EXTENT_DATA",
622 [BTRFS_BLOCK_GROUP_ITEM_KEY] = "BLOCK_GROUP_ITEM",
623 [BTRFS_FREE_SPACE_INFO_KEY] = "FREE_SPACE_INFO",
624 [BTRFS_FREE_SPACE_EXTENT_KEY] = "FREE_SPACE_EXTENT",
625 [BTRFS_FREE_SPACE_BITMAP_KEY] = "FREE_SPACE_BITMAP",
626 [BTRFS_CHUNK_ITEM_KEY] = "CHUNK_ITEM",
627 [BTRFS_DEV_ITEM_KEY] = "DEV_ITEM",
628 [BTRFS_DEV_EXTENT_KEY] = "DEV_EXTENT",
629 [BTRFS_TEMPORARY_ITEM_KEY] = "TEMPORARY_ITEM",
630 [BTRFS_DEV_REPLACE_KEY] = "DEV_REPLACE",
631 [BTRFS_STRING_ITEM_KEY] = "STRING_ITEM",
632 [BTRFS_QGROUP_STATUS_KEY] = "QGROUP_STATUS",
633 [BTRFS_QGROUP_RELATION_KEY] = "QGROUP_RELATION",
634 [BTRFS_QGROUP_INFO_KEY] = "QGROUP_INFO",
635 [BTRFS_QGROUP_LIMIT_KEY] = "QGROUP_LIMIT",
636 [BTRFS_PERSISTENT_ITEM_KEY] = "PERSISTENT_ITEM",
637 [BTRFS_UUID_KEY_SUBVOL] = "UUID_KEY_SUBVOL",
638 [BTRFS_UUID_KEY_RECEIVED_SUBVOL] = "UUID_KEY_RECEIVED_SUBVOL",
641 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
642 fprintf(stream, "UNTYPED");
647 if (key_to_str[type])
648 fputs(key_to_str[type], stream);
650 fprintf(stream, "UNKNOWN.%d", type);
653 void print_objectid(FILE *stream, u64 objectid, u8 type)
656 case BTRFS_DEV_EXTENT_KEY:
658 fprintf(stream, "%llu", (unsigned long long)objectid);
660 case BTRFS_QGROUP_RELATION_KEY:
661 fprintf(stream, "%llu/%llu", btrfs_qgroup_level(objectid),
662 btrfs_qgroup_subvid(objectid));
664 case BTRFS_UUID_KEY_SUBVOL:
665 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
666 fprintf(stream, "0x%016llx", (unsigned long long)objectid);
671 case BTRFS_ROOT_TREE_OBJECTID:
672 if (type == BTRFS_DEV_ITEM_KEY)
673 fprintf(stream, "DEV_ITEMS");
675 fprintf(stream, "ROOT_TREE");
677 case BTRFS_EXTENT_TREE_OBJECTID:
678 fprintf(stream, "EXTENT_TREE");
680 case BTRFS_CHUNK_TREE_OBJECTID:
681 fprintf(stream, "CHUNK_TREE");
683 case BTRFS_DEV_TREE_OBJECTID:
684 fprintf(stream, "DEV_TREE");
686 case BTRFS_FS_TREE_OBJECTID:
687 fprintf(stream, "FS_TREE");
689 case BTRFS_ROOT_TREE_DIR_OBJECTID:
690 fprintf(stream, "ROOT_TREE_DIR");
692 case BTRFS_CSUM_TREE_OBJECTID:
693 fprintf(stream, "CSUM_TREE");
695 case BTRFS_BALANCE_OBJECTID:
696 fprintf(stream, "BALANCE");
698 case BTRFS_ORPHAN_OBJECTID:
699 fprintf(stream, "ORPHAN");
701 case BTRFS_TREE_LOG_OBJECTID:
702 fprintf(stream, "TREE_LOG");
704 case BTRFS_TREE_LOG_FIXUP_OBJECTID:
705 fprintf(stream, "LOG_FIXUP");
707 case BTRFS_TREE_RELOC_OBJECTID:
708 fprintf(stream, "TREE_RELOC");
710 case BTRFS_DATA_RELOC_TREE_OBJECTID:
711 fprintf(stream, "DATA_RELOC_TREE");
713 case BTRFS_EXTENT_CSUM_OBJECTID:
714 fprintf(stream, "EXTENT_CSUM");
716 case BTRFS_FREE_SPACE_OBJECTID:
717 fprintf(stream, "FREE_SPACE");
719 case BTRFS_FREE_INO_OBJECTID:
720 fprintf(stream, "FREE_INO");
722 case BTRFS_QUOTA_TREE_OBJECTID:
723 fprintf(stream, "QUOTA_TREE");
725 case BTRFS_UUID_TREE_OBJECTID:
726 fprintf(stream, "UUID_TREE");
728 case BTRFS_FREE_SPACE_TREE_OBJECTID:
729 fprintf(stream, "FREE_SPACE_TREE");
731 case BTRFS_MULTIPLE_OBJECTIDS:
732 fprintf(stream, "MULTIPLE");
735 fprintf(stream, "-1");
737 case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
738 if (type == BTRFS_CHUNK_ITEM_KEY) {
739 fprintf(stream, "FIRST_CHUNK_TREE");
744 fprintf(stream, "%llu", (unsigned long long)objectid);
748 void btrfs_print_key(struct btrfs_disk_key *disk_key)
750 u64 objectid = btrfs_disk_key_objectid(disk_key);
751 u8 type = btrfs_disk_key_type(disk_key);
752 u64 offset = btrfs_disk_key_offset(disk_key);
755 print_objectid(stdout, objectid, type);
757 print_key_type(stdout, objectid, type);
759 case BTRFS_QGROUP_RELATION_KEY:
760 case BTRFS_QGROUP_INFO_KEY:
761 case BTRFS_QGROUP_LIMIT_KEY:
762 printf(" %llu/%llu)", btrfs_qgroup_level(offset),
763 btrfs_qgroup_subvid(offset));
765 case BTRFS_UUID_KEY_SUBVOL:
766 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
767 printf(" 0x%016llx)", (unsigned long long)offset);
770 if (offset == (u64)-1)
773 printf(" %llu)", (unsigned long long)offset);
778 static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
781 if (item_size & (sizeof(u64) - 1)) {
782 printf("btrfs: uuid item with illegal size %lu!\n",
783 (unsigned long)item_size);
789 read_extent_buffer(l, &subvol_id, offset, sizeof(u64));
790 printf("\t\tsubvol_id %llu\n",
791 (unsigned long long)le64_to_cpu(subvol_id));
792 item_size -= sizeof(u64);
793 offset += sizeof(u64);
797 /* Btrfs inode flag stringification helper */
798 #define STRCAT_ONE_INODE_FLAG(flags, name, empty, dst) ({ \
799 if (flags & BTRFS_INODE_##name) { \
802 strcat(dst, #name); \
808 * Caller should ensure sizeof(*ret) >= 102: all charactors plus '|' of
809 * BTRFS_INODE_* flags
811 static void inode_flags_to_str(u64 flags, char *ret)
815 STRCAT_ONE_INODE_FLAG(flags, NODATASUM, empty, ret);
816 STRCAT_ONE_INODE_FLAG(flags, NODATACOW, empty, ret);
817 STRCAT_ONE_INODE_FLAG(flags, READONLY, empty, ret);
818 STRCAT_ONE_INODE_FLAG(flags, NOCOMPRESS, empty, ret);
819 STRCAT_ONE_INODE_FLAG(flags, PREALLOC, empty, ret);
820 STRCAT_ONE_INODE_FLAG(flags, SYNC, empty, ret);
821 STRCAT_ONE_INODE_FLAG(flags, IMMUTABLE, empty, ret);
822 STRCAT_ONE_INODE_FLAG(flags, APPEND, empty, ret);
823 STRCAT_ONE_INODE_FLAG(flags, NODUMP, empty, ret);
824 STRCAT_ONE_INODE_FLAG(flags, NOATIME, empty, ret);
825 STRCAT_ONE_INODE_FLAG(flags, DIRSYNC, empty, ret);
826 STRCAT_ONE_INODE_FLAG(flags, COMPRESS, empty, ret);
831 static void print_timespec(struct extent_buffer *eb,
832 struct btrfs_timespec *timespec, const char *prefix,
841 tmp_u64 = btrfs_timespec_sec(eb, timespec);
842 tmp_u32 = btrfs_timespec_nsec(eb, timespec);
844 localtime_r(&tmp_time, &tm);
845 strftime(timestamp, sizeof(timestamp),
846 "%Y-%m-%d %H:%M:%S", &tm);
847 printf("%s%llu.%u (%s)%s", prefix, (unsigned long long)tmp_u64, tmp_u32,
851 static void print_inode_item(struct extent_buffer *eb,
852 struct btrfs_inode_item *ii)
856 memset(flags_str, 0, sizeof(flags_str));
857 inode_flags_to_str(btrfs_inode_flags(eb, ii), flags_str);
858 printf("\t\tinode generation %llu transid %llu size %llu nbytes %llu\n"
859 "\t\tblock group %llu mode %o links %u uid %u gid %u rdev %llu\n"
860 "\t\tsequence %llu flags 0x%llx(%s)\n",
861 (unsigned long long)btrfs_inode_generation(eb, ii),
862 (unsigned long long)btrfs_inode_transid(eb, ii),
863 (unsigned long long)btrfs_inode_size(eb, ii),
864 (unsigned long long)btrfs_inode_nbytes(eb, ii),
865 (unsigned long long)btrfs_inode_block_group(eb,ii),
866 btrfs_inode_mode(eb, ii),
867 btrfs_inode_nlink(eb, ii),
868 btrfs_inode_uid(eb, ii),
869 btrfs_inode_gid(eb, ii),
870 (unsigned long long)btrfs_inode_rdev(eb,ii),
871 (unsigned long long)btrfs_inode_flags(eb,ii),
872 (unsigned long long)btrfs_inode_sequence(eb, ii),
874 print_timespec(eb, btrfs_inode_atime(ii), "\t\tatime ", "\n");
875 print_timespec(eb, btrfs_inode_ctime(ii), "\t\tctime ", "\n");
876 print_timespec(eb, btrfs_inode_mtime(ii), "\t\tmtime ", "\n");
877 print_timespec(eb, btrfs_inode_otime(ii), "\t\totime ", "\n");
880 static void print_disk_balance_args(struct btrfs_disk_balance_args *ba)
882 printf("\t\tprofiles %llu devid %llu target %llu flags %llu\n",
883 (unsigned long long)le64_to_cpu(ba->profiles),
884 (unsigned long long)le64_to_cpu(ba->devid),
885 (unsigned long long)le64_to_cpu(ba->target),
886 (unsigned long long)le64_to_cpu(ba->flags));
887 printf("\t\tusage_min %u usage_max %u pstart %llu pend %llu\n",
888 le32_to_cpu(ba->usage_min),
889 le32_to_cpu(ba->usage_max),
890 (unsigned long long)le64_to_cpu(ba->pstart),
891 (unsigned long long)le64_to_cpu(ba->pend));
892 printf("\t\tvstart %llu vend %llu limit_min %u limit_max %u\n",
893 (unsigned long long)le64_to_cpu(ba->vstart),
894 (unsigned long long)le64_to_cpu(ba->vend),
895 le32_to_cpu(ba->limit_min),
896 le32_to_cpu(ba->limit_max));
897 printf("\t\tstripes_min %u stripes_max %u\n",
898 le32_to_cpu(ba->stripes_min),
899 le32_to_cpu(ba->stripes_max));
902 static void print_balance_item(struct extent_buffer *eb,
903 struct btrfs_balance_item *bi)
905 printf("\t\tbalance status flags %llu\n",
906 btrfs_balance_item_flags(eb, bi));
908 printf("\t\tDATA\n");
909 print_disk_balance_args(btrfs_balance_item_data(eb, bi));
910 printf("\t\tMETADATA\n");
911 print_disk_balance_args(btrfs_balance_item_meta(eb, bi));
912 printf("\t\tSYSTEM\n");
913 print_disk_balance_args(btrfs_balance_item_sys(eb, bi));
916 static void print_dev_stats(struct extent_buffer *eb,
917 struct btrfs_dev_stats_item *stats, u32 size)
920 u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64);
921 __le64 *values = btrfs_dev_stats_values(eb, stats);
923 printf("\t\tdevice stats\n");
924 printf("\t\twrite_errs %llu read_errs %llu flush_errs %llu corruption_errs %llu generation %llu\n",
925 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_WRITE_ERRS]),
926 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_READ_ERRS]),
927 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_FLUSH_ERRS]),
928 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_CORRUPTION_ERRS]),
929 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_GENERATION_ERRS]));
932 printf("\t\tunknown stats item bytes %u", size - known);
933 for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
934 printf("\t\tunknown item %u offset %lu value %llu\n",
935 i, i * sizeof(__le64),
936 (unsigned long long)le64_to_cpu(values[i]));
941 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
943 struct btrfs_item *item;
944 struct btrfs_disk_key disk_key;
948 nr = btrfs_header_nritems(eb);
950 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
951 (unsigned long long)btrfs_header_bytenr(eb), nr,
952 btrfs_leaf_free_space(root, eb),
953 (unsigned long long)btrfs_header_generation(eb),
954 (unsigned long long)btrfs_header_owner(eb));
958 for (i = 0; i < nr; i++) {
965 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
966 u8 uuid[BTRFS_UUID_SIZE];
968 item = btrfs_item_nr(i);
969 item_size = btrfs_item_size(eb, item);
970 /* Untyped extraction of slot from btrfs_item_ptr */
971 ptr = btrfs_item_ptr(eb, i, void*);
973 btrfs_item_key(eb, &disk_key, i);
974 objectid = btrfs_disk_key_objectid(&disk_key);
975 type = btrfs_disk_key_type(&disk_key);
976 offset = btrfs_disk_key_offset(&disk_key);
978 printf("\titem %d ", i);
979 btrfs_print_key(&disk_key);
980 printf(" itemoff %d itemsize %d\n",
981 btrfs_item_offset(eb, item),
982 btrfs_item_size(eb, item));
984 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID)
985 print_free_space_header(eb, i);
988 case BTRFS_INODE_ITEM_KEY:
989 print_inode_item(eb, ptr);
991 case BTRFS_INODE_REF_KEY:
992 print_inode_ref_item(eb, item_size, ptr);
994 case BTRFS_INODE_EXTREF_KEY:
995 print_inode_extref_item(eb, item_size, ptr);
997 case BTRFS_DIR_ITEM_KEY:
998 case BTRFS_DIR_INDEX_KEY:
999 case BTRFS_XATTR_ITEM_KEY:
1000 print_dir_item(eb, item_size, ptr);
1002 case BTRFS_DIR_LOG_INDEX_KEY:
1003 case BTRFS_DIR_LOG_ITEM_KEY: {
1004 struct btrfs_dir_log_item *dlog;
1006 dlog = btrfs_item_ptr(eb, i, struct btrfs_dir_log_item);
1007 printf("\t\tdir log end %Lu\n",
1008 (unsigned long long)btrfs_dir_log_end(eb, dlog));
1011 case BTRFS_ORPHAN_ITEM_KEY:
1012 printf("\t\torphan item\n");
1014 case BTRFS_ROOT_ITEM_KEY:
1017 case BTRFS_ROOT_REF_KEY:
1018 print_root_ref(eb, i, "ref");
1020 case BTRFS_ROOT_BACKREF_KEY:
1021 print_root_ref(eb, i, "backref");
1023 case BTRFS_EXTENT_ITEM_KEY:
1024 print_extent_item(eb, i, 0);
1026 case BTRFS_METADATA_ITEM_KEY:
1027 print_extent_item(eb, i, 1);
1029 case BTRFS_TREE_BLOCK_REF_KEY:
1030 printf("\t\ttree block backref\n");
1032 case BTRFS_SHARED_BLOCK_REF_KEY:
1033 printf("\t\tshared block backref\n");
1035 case BTRFS_EXTENT_DATA_REF_KEY: {
1036 struct btrfs_extent_data_ref *dref;
1038 dref = btrfs_item_ptr(eb, i, struct btrfs_extent_data_ref);
1039 printf("\t\textent data backref root %llu "
1040 "objectid %llu offset %llu count %u\n",
1041 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
1042 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
1043 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
1044 btrfs_extent_data_ref_count(eb, dref));
1047 case BTRFS_SHARED_DATA_REF_KEY: {
1048 struct btrfs_shared_data_ref *sref;
1049 sref = btrfs_item_ptr(eb, i, struct btrfs_shared_data_ref);
1050 printf("\t\tshared data backref count %u\n",
1051 btrfs_shared_data_ref_count(eb, sref));
1054 case BTRFS_EXTENT_REF_V0_KEY:
1055 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1056 print_extent_ref_v0(eb, i);
1061 case BTRFS_CSUM_ITEM_KEY:
1062 printf("\t\tcsum item\n");
1064 case BTRFS_EXTENT_CSUM_KEY:
1065 printf("\t\textent csum item\n");
1067 case BTRFS_EXTENT_DATA_KEY:
1068 print_file_extent_item(eb, item, i, ptr);
1070 case BTRFS_BLOCK_GROUP_ITEM_KEY: {
1071 struct btrfs_block_group_item bg_item;
1073 read_extent_buffer(eb, &bg_item, (unsigned long)ptr,
1075 memset(flags_str, 0, sizeof(flags_str));
1076 bg_flags_to_str(btrfs_block_group_flags(&bg_item),
1078 printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
1079 (unsigned long long)btrfs_block_group_used(&bg_item),
1080 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
1084 case BTRFS_FREE_SPACE_INFO_KEY: {
1085 struct btrfs_free_space_info *free_info;
1087 free_info = btrfs_item_ptr(eb, i, struct btrfs_free_space_info);
1088 printf("\t\tfree space info extent count %u flags %u\n",
1089 (unsigned)btrfs_free_space_extent_count(eb, free_info),
1090 (unsigned)btrfs_free_space_flags(eb, free_info));
1093 case BTRFS_FREE_SPACE_EXTENT_KEY:
1094 printf("\t\tfree space extent\n");
1096 case BTRFS_FREE_SPACE_BITMAP_KEY:
1097 printf("\t\tfree space bitmap\n");
1099 case BTRFS_CHUNK_ITEM_KEY:
1100 print_chunk(eb, ptr);
1102 case BTRFS_DEV_ITEM_KEY:
1103 print_dev_item(eb, ptr);
1105 case BTRFS_DEV_EXTENT_KEY: {
1106 struct btrfs_dev_extent *dev_extent;
1108 dev_extent = btrfs_item_ptr(eb, i,
1109 struct btrfs_dev_extent);
1110 read_extent_buffer(eb, uuid,
1111 (unsigned long)btrfs_dev_extent_chunk_tree_uuid(dev_extent),
1113 uuid_unparse(uuid, uuid_str);
1114 printf("\t\tdev extent chunk_tree %llu\n"
1115 "\t\tchunk_objectid %llu chunk_offset %llu "
1117 "\t\tchunk_tree_uuid %s\n",
1118 (unsigned long long)
1119 btrfs_dev_extent_chunk_tree(eb, dev_extent),
1120 (unsigned long long)
1121 btrfs_dev_extent_chunk_objectid(eb, dev_extent),
1122 (unsigned long long)
1123 btrfs_dev_extent_chunk_offset(eb, dev_extent),
1124 (unsigned long long)
1125 btrfs_dev_extent_length(eb, dev_extent),
1129 case BTRFS_QGROUP_STATUS_KEY: {
1130 struct btrfs_qgroup_status_item *qg_status;
1132 qg_status = btrfs_item_ptr(eb, i,
1133 struct btrfs_qgroup_status_item);
1134 memset(flags_str, 0, sizeof(flags_str));
1135 qgroup_flags_to_str(btrfs_qgroup_status_flags(eb, qg_status),
1137 printf("\t\tversion %llu generation %llu flags %s "
1139 (unsigned long long)
1140 btrfs_qgroup_status_version(eb, qg_status),
1141 (unsigned long long)
1142 btrfs_qgroup_status_generation(eb, qg_status),
1144 (unsigned long long)
1145 btrfs_qgroup_status_rescan(eb, qg_status));
1148 case BTRFS_QGROUP_RELATION_KEY:
1150 case BTRFS_QGROUP_INFO_KEY: {
1151 struct btrfs_qgroup_info_item *qg_info;
1153 qg_info = btrfs_item_ptr(eb, i,
1154 struct btrfs_qgroup_info_item);
1155 printf("\t\tgeneration %llu\n"
1156 "\t\treferenced %llu referenced_compressed %llu\n"
1157 "\t\texclusive %llu exclusive_compressed %llu\n",
1158 (unsigned long long)
1159 btrfs_qgroup_info_generation(eb, qg_info),
1160 (unsigned long long)
1161 btrfs_qgroup_info_referenced(eb, qg_info),
1162 (unsigned long long)
1163 btrfs_qgroup_info_referenced_compressed(eb,
1165 (unsigned long long)
1166 btrfs_qgroup_info_exclusive(eb, qg_info),
1167 (unsigned long long)
1168 btrfs_qgroup_info_exclusive_compressed(eb,
1172 case BTRFS_QGROUP_LIMIT_KEY: {
1173 struct btrfs_qgroup_limit_item *qg_limit;
1175 qg_limit = btrfs_item_ptr(eb, i,
1176 struct btrfs_qgroup_limit_item);
1177 printf("\t\tflags %llx\n"
1178 "\t\tmax_referenced %lld max_exclusive %lld\n"
1179 "\t\trsv_referenced %lld rsv_exclusive %lld\n",
1180 (unsigned long long)
1181 btrfs_qgroup_limit_flags(eb, qg_limit),
1183 btrfs_qgroup_limit_max_referenced(eb, qg_limit),
1185 btrfs_qgroup_limit_max_exclusive(eb, qg_limit),
1187 btrfs_qgroup_limit_rsv_referenced(eb, qg_limit),
1189 btrfs_qgroup_limit_rsv_exclusive(eb, qg_limit));
1192 case BTRFS_UUID_KEY_SUBVOL:
1193 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
1194 print_uuid_item(eb, btrfs_item_ptr_offset(eb, i),
1195 btrfs_item_size_nr(eb, i));
1197 case BTRFS_STRING_ITEM_KEY: {
1198 const char *str = eb->data + btrfs_item_ptr_offset(eb, i);
1200 printf("\t\titem data %.*s\n", item_size, str);
1203 case BTRFS_PERSISTENT_ITEM_KEY:
1204 printf("\t\tpersistent item objectid ");
1205 print_objectid(stdout, objectid, BTRFS_PERSISTENT_ITEM_KEY);
1206 printf(" offset %llu\n", (unsigned long long)offset);
1208 case BTRFS_DEV_STATS_OBJECTID:
1209 print_dev_stats(eb, ptr, item_size);
1212 printf("\t\tunknown persistent item objectid %llu\n",
1216 case BTRFS_TEMPORARY_ITEM_KEY:
1217 printf("\t\ttemporary item objectid ");
1218 print_objectid(stdout, objectid, BTRFS_TEMPORARY_ITEM_KEY);
1219 printf(" offset %llu\n", (unsigned long long)offset);
1221 case BTRFS_BALANCE_OBJECTID:
1222 print_balance_item(eb, ptr);
1225 printf("\t\tunknown temporary item objectid %llu\n",
1234 void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
1239 struct btrfs_disk_key disk_key;
1240 struct btrfs_key key;
1241 struct extent_buffer *next;
1245 nr = btrfs_header_nritems(eb);
1246 if (btrfs_is_leaf(eb)) {
1247 btrfs_print_leaf(root, eb);
1250 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
1251 (unsigned long long)eb->start,
1252 btrfs_header_level(eb), nr,
1253 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
1254 (unsigned long long)btrfs_header_generation(eb),
1255 (unsigned long long)btrfs_header_owner(eb));
1258 size = root->nodesize;
1259 for (i = 0; i < nr; i++) {
1260 u64 blocknr = btrfs_node_blockptr(eb, i);
1261 btrfs_node_key(eb, &disk_key, i);
1262 btrfs_disk_key_to_cpu(&key, &disk_key);
1264 btrfs_print_key(&disk_key);
1265 printf(" block %llu (%llu) gen %llu\n",
1266 (unsigned long long)blocknr,
1267 (unsigned long long)blocknr / size,
1268 (unsigned long long)btrfs_node_ptr_generation(eb, i));
1274 for (i = 0; i < nr; i++) {
1275 next = read_tree_block(root, btrfs_node_blockptr(eb, i), size,
1276 btrfs_node_ptr_generation(eb, i));
1277 if (!extent_buffer_uptodate(next)) {
1278 fprintf(stderr, "failed to read %llu in tree %llu\n",
1279 (unsigned long long)btrfs_node_blockptr(eb, i),
1280 (unsigned long long)btrfs_header_owner(eb));
1283 if (btrfs_is_leaf(next) && btrfs_header_level(eb) != 1) {
1285 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1286 i, btrfs_header_level(next),
1287 btrfs_header_level(eb));
1290 if (btrfs_header_level(next) != btrfs_header_level(eb) - 1) {
1292 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1293 i, btrfs_header_level(next),
1294 btrfs_header_level(eb));
1297 btrfs_print_tree(root, next, 1);
1298 free_extent_buffer(next);
1304 free_extent_buffer(next);