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\tindex %llu parent %llu namelen %u name: %.*s\n",
108 (unsigned long long)index,
109 (unsigned long long)parent_objid,
110 name_len, len, namebuf);
112 len = sizeof(*extref) + name_len;
113 extref = (struct btrfs_inode_extref *)((char *)extref + len);
118 static void print_inode_ref_item(struct extent_buffer *eb, u32 size,
119 struct btrfs_inode_ref *ref)
125 char namebuf[BTRFS_NAME_LEN];
128 name_len = btrfs_inode_ref_name_len(eb, ref);
129 index = btrfs_inode_ref_index(eb, ref);
130 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
131 read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len);
132 printf("\t\tindex %llu namelen %u name: %.*s\n",
133 (unsigned long long)index, name_len, len, namebuf);
134 len = sizeof(*ref) + name_len;
135 ref = (struct btrfs_inode_ref *)((char *)ref + len);
140 /* Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10" */
141 static void bg_flags_to_str(u64 flags, char *ret)
145 if (flags & BTRFS_BLOCK_GROUP_DATA) {
149 if (flags & BTRFS_BLOCK_GROUP_METADATA) {
152 strcat(ret, "METADATA");
154 if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
157 strcat(ret, "SYSTEM");
159 switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
160 case BTRFS_BLOCK_GROUP_RAID0:
161 strcat(ret, "|RAID0");
163 case BTRFS_BLOCK_GROUP_RAID1:
164 strcat(ret, "|RAID1");
166 case BTRFS_BLOCK_GROUP_DUP:
169 case BTRFS_BLOCK_GROUP_RAID10:
170 strcat(ret, "|RAID10");
172 case BTRFS_BLOCK_GROUP_RAID5:
173 strcat(ret, "|RAID5");
175 case BTRFS_BLOCK_GROUP_RAID6:
176 strcat(ret, "|RAID6");
183 /* Caller should ensure sizeof(*ret)>= 26 "OFF|SCANNING|INCONSISTENT" */
184 static void qgroup_flags_to_str(u64 flags, char *ret)
186 if (flags & BTRFS_QGROUP_STATUS_FLAG_ON)
191 if (flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN)
192 strcat(ret, "|SCANNING");
193 if (flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
194 strcat(ret, "|INCONSISTENT");
197 void print_chunk_item(struct extent_buffer *eb, struct btrfs_chunk *chunk)
199 u16 num_stripes = btrfs_chunk_num_stripes(eb, chunk);
202 char chunk_flags_str[32] = {0};
204 /* The chunk must contain at least one stripe */
205 if (num_stripes < 1) {
206 printf("invalid num_stripes: %u\n", num_stripes);
210 chunk_item_size = btrfs_chunk_item_size(num_stripes);
212 if ((unsigned long)chunk + chunk_item_size > eb->len) {
213 printf("\t\tchunk item invalid\n");
217 bg_flags_to_str(btrfs_chunk_type(eb, chunk), chunk_flags_str);
218 printf("\t\tlength %llu owner %llu stripe_len %llu type %s\n",
219 (unsigned long long)btrfs_chunk_length(eb, chunk),
220 (unsigned long long)btrfs_chunk_owner(eb, chunk),
221 (unsigned long long)btrfs_chunk_stripe_len(eb, chunk),
223 printf("\t\tio_align %u io_width %u sector_size %u\n",
224 btrfs_chunk_io_align(eb, chunk),
225 btrfs_chunk_io_width(eb, chunk),
226 btrfs_chunk_sector_size(eb, chunk));
227 printf("\t\tnum_stripes %hu sub_stripes %hu\n", num_stripes,
228 btrfs_chunk_sub_stripes(eb, chunk));
229 for (i = 0 ; i < num_stripes ; i++) {
230 unsigned char dev_uuid[BTRFS_UUID_SIZE];
231 char str_dev_uuid[BTRFS_UUID_UNPARSED_SIZE];
235 uuid_offset = (unsigned long)btrfs_stripe_dev_uuid_nr(chunk, i);
236 stripe_offset = (unsigned long)btrfs_stripe_nr(chunk, i);
238 if (uuid_offset < stripe_offset ||
239 (uuid_offset + BTRFS_UUID_SIZE) >
240 (stripe_offset + sizeof(struct btrfs_stripe))) {
241 printf("\t\t\tstripe %d invalid\n", i);
245 read_extent_buffer(eb, dev_uuid,
248 uuid_unparse(dev_uuid, str_dev_uuid);
249 printf("\t\t\tstripe %d devid %llu offset %llu\n", i,
250 (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i),
251 (unsigned long long)btrfs_stripe_offset_nr(eb, chunk, i));
252 printf("\t\t\tdev_uuid %s\n", str_dev_uuid);
256 static void print_dev_item(struct extent_buffer *eb,
257 struct btrfs_dev_item *dev_item)
259 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
260 char fsid_str[BTRFS_UUID_UNPARSED_SIZE];
261 u8 uuid[BTRFS_UUID_SIZE];
262 u8 fsid[BTRFS_UUID_SIZE];
264 read_extent_buffer(eb, uuid,
265 (unsigned long)btrfs_device_uuid(dev_item),
267 uuid_unparse(uuid, uuid_str);
268 read_extent_buffer(eb, fsid,
269 (unsigned long)btrfs_device_fsid(dev_item),
271 uuid_unparse(fsid, fsid_str);
272 printf("\t\tdevid %llu total_bytes %llu bytes_used %Lu\n"
273 "\t\tio_align %u io_width %u sector_size %u type %llu\n"
274 "\t\tgeneration %llu start_offset %llu dev_group %u\n"
275 "\t\tseek_speed %hhu bandwidth %hhu\n"
278 (unsigned long long)btrfs_device_id(eb, dev_item),
279 (unsigned long long)btrfs_device_total_bytes(eb, dev_item),
280 (unsigned long long)btrfs_device_bytes_used(eb, dev_item),
281 btrfs_device_io_align(eb, dev_item),
282 btrfs_device_io_width(eb, dev_item),
283 btrfs_device_sector_size(eb, dev_item),
284 (unsigned long long)btrfs_device_type(eb, dev_item),
285 (unsigned long long)btrfs_device_generation(eb, dev_item),
286 (unsigned long long)btrfs_device_start_offset(eb, dev_item),
287 btrfs_device_group(eb, dev_item),
288 btrfs_device_seek_speed(eb, dev_item),
289 btrfs_device_bandwidth(eb, dev_item),
293 static void print_uuids(struct extent_buffer *eb)
295 char fs_uuid[BTRFS_UUID_UNPARSED_SIZE];
296 char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE];
297 u8 disk_uuid[BTRFS_UUID_SIZE];
299 read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(),
302 fs_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
303 uuid_unparse(disk_uuid, fs_uuid);
305 read_extent_buffer(eb, disk_uuid,
306 btrfs_header_chunk_tree_uuid(eb),
309 chunk_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
310 uuid_unparse(disk_uuid, chunk_uuid);
311 printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid);
314 static void compress_type_to_str(u8 compress_type, char *ret)
316 switch (compress_type) {
317 case BTRFS_COMPRESS_NONE:
320 case BTRFS_COMPRESS_ZLIB:
323 case BTRFS_COMPRESS_LZO:
327 sprintf(ret, "UNKNOWN.%d", compress_type);
331 static const char* file_extent_type_to_str(u8 type)
334 case BTRFS_FILE_EXTENT_INLINE: return "inline";
335 case BTRFS_FILE_EXTENT_PREALLOC: return "prealloc";
336 case BTRFS_FILE_EXTENT_REG: return "regular";
337 default: return "unknown";
341 static void print_file_extent_item(struct extent_buffer *eb,
342 struct btrfs_item *item,
344 struct btrfs_file_extent_item *fi)
346 unsigned char extent_type = btrfs_file_extent_type(eb, fi);
347 char compress_str[16];
349 compress_type_to_str(btrfs_file_extent_compression(eb, fi),
352 printf("\t\tgeneration %llu type %hhu (%s)\n",
353 btrfs_file_extent_generation(eb, fi),
354 extent_type, file_extent_type_to_str(extent_type));
356 if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
357 printf("\t\tinline extent data size %u ram_bytes %u compression %hhu (%s)\n",
358 btrfs_file_extent_inline_item_len(eb, item),
359 btrfs_file_extent_inline_len(eb, slot, fi),
360 btrfs_file_extent_compression(eb, fi),
364 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
365 printf("\t\tprealloc 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\tprealloc data offset %llu nr %llu\n",
369 (unsigned long long)btrfs_file_extent_offset(eb, fi),
370 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi));
373 printf("\t\textent data disk byte %llu nr %llu\n",
374 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
375 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
376 printf("\t\textent data offset %llu nr %llu ram %llu\n",
377 (unsigned long long)btrfs_file_extent_offset(eb, fi),
378 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi),
379 (unsigned long long)btrfs_file_extent_ram_bytes(eb, fi));
380 printf("\t\textent compression %hhu (%s)\n",
381 btrfs_file_extent_compression(eb, fi),
385 /* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
386 static void extent_flags_to_str(u64 flags, char *ret)
390 if (flags & BTRFS_EXTENT_FLAG_DATA) {
394 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
399 strcat(ret, "TREE_BLOCK");
401 if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
403 strcat(ret, "FULL_BACKREF");
407 void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
409 struct btrfs_extent_item *ei;
410 struct btrfs_extent_inline_ref *iref;
411 struct btrfs_extent_data_ref *dref;
412 struct btrfs_shared_data_ref *sref;
413 struct btrfs_disk_key key;
417 u32 item_size = btrfs_item_size_nr(eb, slot);
420 char flags_str[32] = {0};
422 if (item_size < sizeof(*ei)) {
423 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
424 struct btrfs_extent_item_v0 *ei0;
425 BUG_ON(item_size != sizeof(*ei0));
426 ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0);
427 printf("\t\trefs %u\n",
428 btrfs_extent_refs_v0(eb, ei0));
435 ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
436 flags = btrfs_extent_flags(eb, ei);
437 extent_flags_to_str(flags, flags_str);
439 printf("\t\trefs %llu gen %llu flags %s\n",
440 (unsigned long long)btrfs_extent_refs(eb, ei),
441 (unsigned long long)btrfs_extent_generation(eb, ei),
444 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !metadata) {
445 struct btrfs_tree_block_info *info;
446 info = (struct btrfs_tree_block_info *)(ei + 1);
447 btrfs_tree_block_key(eb, info, &key);
448 printf("\t\ttree block ");
449 btrfs_print_key(&key);
450 printf(" level %d\n", btrfs_tree_block_level(eb, info));
451 iref = (struct btrfs_extent_inline_ref *)(info + 1);
452 } else if (metadata) {
453 struct btrfs_key tmp;
455 btrfs_item_key_to_cpu(eb, &tmp, slot);
456 printf("\t\ttree block skinny level %d\n", (int)tmp.offset);
457 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
459 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
462 ptr = (unsigned long)iref;
463 end = (unsigned long)ei + item_size;
465 iref = (struct btrfs_extent_inline_ref *)ptr;
466 type = btrfs_extent_inline_ref_type(eb, iref);
467 offset = btrfs_extent_inline_ref_offset(eb, iref);
469 case BTRFS_TREE_BLOCK_REF_KEY:
470 printf("\t\ttree block backref root %llu\n",
471 (unsigned long long)offset);
473 case BTRFS_SHARED_BLOCK_REF_KEY:
474 printf("\t\tshared block backref parent %llu\n",
475 (unsigned long long)offset);
477 case BTRFS_EXTENT_DATA_REF_KEY:
478 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
479 printf("\t\textent data backref root %llu "
480 "objectid %llu offset %llu count %u\n",
481 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
482 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
483 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
484 btrfs_extent_data_ref_count(eb, dref));
486 case BTRFS_SHARED_DATA_REF_KEY:
487 sref = (struct btrfs_shared_data_ref *)(iref + 1);
488 printf("\t\tshared data backref parent %llu count %u\n",
489 (unsigned long long)offset,
490 btrfs_shared_data_ref_count(eb, sref));
495 ptr += btrfs_extent_inline_ref_size(type);
500 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
501 static void print_extent_ref_v0(struct extent_buffer *eb, int slot)
503 struct btrfs_extent_ref_v0 *ref0;
505 ref0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_ref_v0);
506 printf("\t\textent back ref root %llu gen %llu "
507 "owner %llu num_refs %lu\n",
508 (unsigned long long)btrfs_ref_root_v0(eb, ref0),
509 (unsigned long long)btrfs_ref_generation_v0(eb, ref0),
510 (unsigned long long)btrfs_ref_objectid_v0(eb, ref0),
511 (unsigned long)btrfs_ref_count_v0(eb, ref0));
515 static void print_root_ref(struct extent_buffer *leaf, int slot, const char *tag)
517 struct btrfs_root_ref *ref;
518 char namebuf[BTRFS_NAME_LEN];
521 ref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref);
522 namelen = btrfs_root_ref_name_len(leaf, ref);
523 read_extent_buffer(leaf, namebuf, (unsigned long)(ref + 1), namelen);
524 printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag,
525 (unsigned long long)btrfs_root_ref_dirid(leaf, ref),
526 (unsigned long long)btrfs_root_ref_sequence(leaf, ref),
530 static int empty_uuid(const u8 *uuid)
534 for (i = 0; i < BTRFS_UUID_SIZE; i++)
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_item(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 (!empty_uuid(root_item.parent_uuid)) {
584 uuid_unparse(root_item.parent_uuid, uuid_str);
585 printf("\t\tparent_uuid %s\n", uuid_str);
587 if (!empty_uuid(root_item.received_uuid)) {
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 static const char* key_to_str[256] = {
625 [BTRFS_INODE_ITEM_KEY] = "INODE_ITEM",
626 [BTRFS_INODE_REF_KEY] = "INODE_REF",
627 [BTRFS_INODE_EXTREF_KEY] = "INODE_EXTREF",
628 [BTRFS_DIR_ITEM_KEY] = "DIR_ITEM",
629 [BTRFS_DIR_INDEX_KEY] = "DIR_INDEX",
630 [BTRFS_DIR_LOG_ITEM_KEY] = "DIR_LOG_ITEM",
631 [BTRFS_DIR_LOG_INDEX_KEY] = "DIR_LOG_INDEX",
632 [BTRFS_XATTR_ITEM_KEY] = "XATTR_ITEM",
633 [BTRFS_ORPHAN_ITEM_KEY] = "ORPHAN_ITEM",
634 [BTRFS_ROOT_ITEM_KEY] = "ROOT_ITEM",
635 [BTRFS_ROOT_REF_KEY] = "ROOT_REF",
636 [BTRFS_ROOT_BACKREF_KEY] = "ROOT_BACKREF",
637 [BTRFS_EXTENT_ITEM_KEY] = "EXTENT_ITEM",
638 [BTRFS_METADATA_ITEM_KEY] = "METADATA_ITEM",
639 [BTRFS_TREE_BLOCK_REF_KEY] = "TREE_BLOCK_REF",
640 [BTRFS_SHARED_BLOCK_REF_KEY] = "SHARED_BLOCK_REF",
641 [BTRFS_EXTENT_DATA_REF_KEY] = "EXTENT_DATA_REF",
642 [BTRFS_SHARED_DATA_REF_KEY] = "SHARED_DATA_REF",
643 [BTRFS_EXTENT_REF_V0_KEY] = "EXTENT_REF_V0",
644 [BTRFS_CSUM_ITEM_KEY] = "CSUM_ITEM",
645 [BTRFS_EXTENT_CSUM_KEY] = "EXTENT_CSUM",
646 [BTRFS_EXTENT_DATA_KEY] = "EXTENT_DATA",
647 [BTRFS_BLOCK_GROUP_ITEM_KEY] = "BLOCK_GROUP_ITEM",
648 [BTRFS_FREE_SPACE_INFO_KEY] = "FREE_SPACE_INFO",
649 [BTRFS_FREE_SPACE_EXTENT_KEY] = "FREE_SPACE_EXTENT",
650 [BTRFS_FREE_SPACE_BITMAP_KEY] = "FREE_SPACE_BITMAP",
651 [BTRFS_CHUNK_ITEM_KEY] = "CHUNK_ITEM",
652 [BTRFS_DEV_ITEM_KEY] = "DEV_ITEM",
653 [BTRFS_DEV_EXTENT_KEY] = "DEV_EXTENT",
654 [BTRFS_TEMPORARY_ITEM_KEY] = "TEMPORARY_ITEM",
655 [BTRFS_DEV_REPLACE_KEY] = "DEV_REPLACE",
656 [BTRFS_STRING_ITEM_KEY] = "STRING_ITEM",
657 [BTRFS_QGROUP_STATUS_KEY] = "QGROUP_STATUS",
658 [BTRFS_QGROUP_RELATION_KEY] = "QGROUP_RELATION",
659 [BTRFS_QGROUP_INFO_KEY] = "QGROUP_INFO",
660 [BTRFS_QGROUP_LIMIT_KEY] = "QGROUP_LIMIT",
661 [BTRFS_PERSISTENT_ITEM_KEY] = "PERSISTENT_ITEM",
662 [BTRFS_UUID_KEY_SUBVOL] = "UUID_KEY_SUBVOL",
663 [BTRFS_UUID_KEY_RECEIVED_SUBVOL] = "UUID_KEY_RECEIVED_SUBVOL",
666 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
667 fprintf(stream, "UNTYPED");
672 if (key_to_str[type])
673 fputs(key_to_str[type], stream);
675 fprintf(stream, "UNKNOWN.%d", type);
678 void print_objectid(FILE *stream, u64 objectid, u8 type)
681 case BTRFS_DEV_EXTENT_KEY:
683 fprintf(stream, "%llu", (unsigned long long)objectid);
685 case BTRFS_QGROUP_RELATION_KEY:
686 fprintf(stream, "%llu/%llu", btrfs_qgroup_level(objectid),
687 btrfs_qgroup_subvid(objectid));
689 case BTRFS_UUID_KEY_SUBVOL:
690 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
691 fprintf(stream, "0x%016llx", (unsigned long long)objectid);
696 case BTRFS_ROOT_TREE_OBJECTID:
697 if (type == BTRFS_DEV_ITEM_KEY)
698 fprintf(stream, "DEV_ITEMS");
700 fprintf(stream, "ROOT_TREE");
702 case BTRFS_EXTENT_TREE_OBJECTID:
703 fprintf(stream, "EXTENT_TREE");
705 case BTRFS_CHUNK_TREE_OBJECTID:
706 fprintf(stream, "CHUNK_TREE");
708 case BTRFS_DEV_TREE_OBJECTID:
709 fprintf(stream, "DEV_TREE");
711 case BTRFS_FS_TREE_OBJECTID:
712 fprintf(stream, "FS_TREE");
714 case BTRFS_ROOT_TREE_DIR_OBJECTID:
715 fprintf(stream, "ROOT_TREE_DIR");
717 case BTRFS_CSUM_TREE_OBJECTID:
718 fprintf(stream, "CSUM_TREE");
720 case BTRFS_BALANCE_OBJECTID:
721 fprintf(stream, "BALANCE");
723 case BTRFS_ORPHAN_OBJECTID:
724 fprintf(stream, "ORPHAN");
726 case BTRFS_TREE_LOG_OBJECTID:
727 fprintf(stream, "TREE_LOG");
729 case BTRFS_TREE_LOG_FIXUP_OBJECTID:
730 fprintf(stream, "LOG_FIXUP");
732 case BTRFS_TREE_RELOC_OBJECTID:
733 fprintf(stream, "TREE_RELOC");
735 case BTRFS_DATA_RELOC_TREE_OBJECTID:
736 fprintf(stream, "DATA_RELOC_TREE");
738 case BTRFS_EXTENT_CSUM_OBJECTID:
739 fprintf(stream, "EXTENT_CSUM");
741 case BTRFS_FREE_SPACE_OBJECTID:
742 fprintf(stream, "FREE_SPACE");
744 case BTRFS_FREE_INO_OBJECTID:
745 fprintf(stream, "FREE_INO");
747 case BTRFS_QUOTA_TREE_OBJECTID:
748 fprintf(stream, "QUOTA_TREE");
750 case BTRFS_UUID_TREE_OBJECTID:
751 fprintf(stream, "UUID_TREE");
753 case BTRFS_FREE_SPACE_TREE_OBJECTID:
754 fprintf(stream, "FREE_SPACE_TREE");
756 case BTRFS_MULTIPLE_OBJECTIDS:
757 fprintf(stream, "MULTIPLE");
760 fprintf(stream, "-1");
762 case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
763 if (type == BTRFS_CHUNK_ITEM_KEY) {
764 fprintf(stream, "FIRST_CHUNK_TREE");
769 fprintf(stream, "%llu", (unsigned long long)objectid);
773 void btrfs_print_key(struct btrfs_disk_key *disk_key)
775 u64 objectid = btrfs_disk_key_objectid(disk_key);
776 u8 type = btrfs_disk_key_type(disk_key);
777 u64 offset = btrfs_disk_key_offset(disk_key);
780 print_objectid(stdout, objectid, type);
782 print_key_type(stdout, objectid, type);
784 case BTRFS_QGROUP_RELATION_KEY:
785 case BTRFS_QGROUP_INFO_KEY:
786 case BTRFS_QGROUP_LIMIT_KEY:
787 printf(" %llu/%llu)", btrfs_qgroup_level(offset),
788 btrfs_qgroup_subvid(offset));
790 case BTRFS_UUID_KEY_SUBVOL:
791 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
792 printf(" 0x%016llx)", (unsigned long long)offset);
795 if (offset == (u64)-1)
798 printf(" %llu)", (unsigned long long)offset);
803 static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
806 if (item_size & (sizeof(u64) - 1)) {
807 printf("btrfs: uuid item with illegal size %lu!\n",
808 (unsigned long)item_size);
814 read_extent_buffer(l, &subvol_id, offset, sizeof(u64));
815 printf("\t\tsubvol_id %llu\n",
816 (unsigned long long)le64_to_cpu(subvol_id));
817 item_size -= sizeof(u64);
818 offset += sizeof(u64);
822 /* Btrfs inode flag stringification helper */
823 #define STRCAT_ONE_INODE_FLAG(flags, name, empty, dst) ({ \
824 if (flags & BTRFS_INODE_##name) { \
827 strcat(dst, #name); \
833 * Caller should ensure sizeof(*ret) >= 102: all charactors plus '|' of
834 * BTRFS_INODE_* flags
836 static void inode_flags_to_str(u64 flags, char *ret)
840 STRCAT_ONE_INODE_FLAG(flags, NODATASUM, empty, ret);
841 STRCAT_ONE_INODE_FLAG(flags, NODATACOW, empty, ret);
842 STRCAT_ONE_INODE_FLAG(flags, READONLY, empty, ret);
843 STRCAT_ONE_INODE_FLAG(flags, NOCOMPRESS, empty, ret);
844 STRCAT_ONE_INODE_FLAG(flags, PREALLOC, empty, ret);
845 STRCAT_ONE_INODE_FLAG(flags, SYNC, empty, ret);
846 STRCAT_ONE_INODE_FLAG(flags, IMMUTABLE, empty, ret);
847 STRCAT_ONE_INODE_FLAG(flags, APPEND, empty, ret);
848 STRCAT_ONE_INODE_FLAG(flags, NODUMP, empty, ret);
849 STRCAT_ONE_INODE_FLAG(flags, NOATIME, empty, ret);
850 STRCAT_ONE_INODE_FLAG(flags, DIRSYNC, empty, ret);
851 STRCAT_ONE_INODE_FLAG(flags, COMPRESS, empty, ret);
856 static void print_timespec(struct extent_buffer *eb,
857 struct btrfs_timespec *timespec, const char *prefix,
866 tmp_u64 = btrfs_timespec_sec(eb, timespec);
867 tmp_u32 = btrfs_timespec_nsec(eb, timespec);
869 localtime_r(&tmp_time, &tm);
870 strftime(timestamp, sizeof(timestamp),
871 "%Y-%m-%d %H:%M:%S", &tm);
872 printf("%s%llu.%u (%s)%s", prefix, (unsigned long long)tmp_u64, tmp_u32,
876 static void print_inode_item(struct extent_buffer *eb,
877 struct btrfs_inode_item *ii)
881 memset(flags_str, 0, sizeof(flags_str));
882 inode_flags_to_str(btrfs_inode_flags(eb, ii), flags_str);
883 printf("\t\tgeneration %llu transid %llu size %llu nbytes %llu\n"
884 "\t\tblock group %llu mode %o links %u uid %u gid %u rdev %llu\n"
885 "\t\tsequence %llu flags 0x%llx(%s)\n",
886 (unsigned long long)btrfs_inode_generation(eb, ii),
887 (unsigned long long)btrfs_inode_transid(eb, ii),
888 (unsigned long long)btrfs_inode_size(eb, ii),
889 (unsigned long long)btrfs_inode_nbytes(eb, ii),
890 (unsigned long long)btrfs_inode_block_group(eb,ii),
891 btrfs_inode_mode(eb, ii),
892 btrfs_inode_nlink(eb, ii),
893 btrfs_inode_uid(eb, ii),
894 btrfs_inode_gid(eb, ii),
895 (unsigned long long)btrfs_inode_rdev(eb,ii),
896 (unsigned long long)btrfs_inode_flags(eb,ii),
897 (unsigned long long)btrfs_inode_sequence(eb, ii),
899 print_timespec(eb, btrfs_inode_atime(ii), "\t\tatime ", "\n");
900 print_timespec(eb, btrfs_inode_ctime(ii), "\t\tctime ", "\n");
901 print_timespec(eb, btrfs_inode_mtime(ii), "\t\tmtime ", "\n");
902 print_timespec(eb, btrfs_inode_otime(ii), "\t\totime ", "\n");
905 static void print_disk_balance_args(struct btrfs_disk_balance_args *ba)
907 printf("\t\tprofiles %llu devid %llu target %llu flags %llu\n",
908 (unsigned long long)le64_to_cpu(ba->profiles),
909 (unsigned long long)le64_to_cpu(ba->devid),
910 (unsigned long long)le64_to_cpu(ba->target),
911 (unsigned long long)le64_to_cpu(ba->flags));
912 printf("\t\tusage_min %u usage_max %u pstart %llu pend %llu\n",
913 le32_to_cpu(ba->usage_min),
914 le32_to_cpu(ba->usage_max),
915 (unsigned long long)le64_to_cpu(ba->pstart),
916 (unsigned long long)le64_to_cpu(ba->pend));
917 printf("\t\tvstart %llu vend %llu limit_min %u limit_max %u\n",
918 (unsigned long long)le64_to_cpu(ba->vstart),
919 (unsigned long long)le64_to_cpu(ba->vend),
920 le32_to_cpu(ba->limit_min),
921 le32_to_cpu(ba->limit_max));
922 printf("\t\tstripes_min %u stripes_max %u\n",
923 le32_to_cpu(ba->stripes_min),
924 le32_to_cpu(ba->stripes_max));
927 static void print_balance_item(struct extent_buffer *eb,
928 struct btrfs_balance_item *bi)
930 printf("\t\tbalance status flags %llu\n",
931 btrfs_balance_item_flags(eb, bi));
933 printf("\t\tDATA\n");
934 print_disk_balance_args(btrfs_balance_item_data(eb, bi));
935 printf("\t\tMETADATA\n");
936 print_disk_balance_args(btrfs_balance_item_meta(eb, bi));
937 printf("\t\tSYSTEM\n");
938 print_disk_balance_args(btrfs_balance_item_sys(eb, bi));
941 static void print_dev_stats(struct extent_buffer *eb,
942 struct btrfs_dev_stats_item *stats, u32 size)
945 u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64);
946 __le64 *values = btrfs_dev_stats_values(eb, stats);
948 printf("\t\tdevice stats\n");
949 printf("\t\twrite_errs %llu read_errs %llu flush_errs %llu corruption_errs %llu generation %llu\n",
950 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_WRITE_ERRS]),
951 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_READ_ERRS]),
952 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_FLUSH_ERRS]),
953 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_CORRUPTION_ERRS]),
954 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_GENERATION_ERRS]));
957 printf("\t\tunknown stats item bytes %u", size - known);
958 for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
959 printf("\t\tunknown item %u offset %zu value %llu\n",
960 i, i * sizeof(__le64),
961 (unsigned long long)le64_to_cpu(values[i]));
966 static void print_block_group_item(struct extent_buffer *eb,
967 struct btrfs_block_group_item *bgi)
969 struct btrfs_block_group_item bg_item;
972 read_extent_buffer(eb, &bg_item, (unsigned long)bgi, sizeof(bg_item));
973 memset(flags_str, 0, sizeof(flags_str));
974 bg_flags_to_str(btrfs_block_group_flags(&bg_item), flags_str);
975 printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
976 (unsigned long long)btrfs_block_group_used(&bg_item),
977 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
981 static void print_extent_data_ref(struct extent_buffer *eb, int slot)
983 struct btrfs_extent_data_ref *dref;
985 dref = btrfs_item_ptr(eb, slot, struct btrfs_extent_data_ref);
986 printf("\t\textent data backref root %llu "
987 "objectid %llu offset %llu count %u\n",
988 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
989 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
990 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
991 btrfs_extent_data_ref_count(eb, dref));
994 static void print_shared_data_ref(struct extent_buffer *eb, int slot)
996 struct btrfs_shared_data_ref *sref;
998 sref = btrfs_item_ptr(eb, slot, struct btrfs_shared_data_ref);
999 printf("\t\tshared data backref count %u\n",
1000 btrfs_shared_data_ref_count(eb, sref));
1003 static void print_free_space_info(struct extent_buffer *eb, int slot)
1005 struct btrfs_free_space_info *free_info;
1007 free_info = btrfs_item_ptr(eb, slot, struct btrfs_free_space_info);
1008 printf("\t\tfree space info extent count %u flags %u\n",
1009 (unsigned)btrfs_free_space_extent_count(eb, free_info),
1010 (unsigned)btrfs_free_space_flags(eb, free_info));
1013 static void print_dev_extent(struct extent_buffer *eb, int slot)
1015 struct btrfs_dev_extent *dev_extent;
1016 u8 uuid[BTRFS_UUID_SIZE];
1017 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
1019 dev_extent = btrfs_item_ptr(eb, slot, struct btrfs_dev_extent);
1020 read_extent_buffer(eb, uuid,
1021 (unsigned long)btrfs_dev_extent_chunk_tree_uuid(dev_extent),
1023 uuid_unparse(uuid, uuid_str);
1024 printf("\t\tdev extent chunk_tree %llu\n"
1025 "\t\tchunk_objectid %llu chunk_offset %llu "
1027 "\t\tchunk_tree_uuid %s\n",
1028 (unsigned long long)btrfs_dev_extent_chunk_tree(eb, dev_extent),
1029 (unsigned long long)btrfs_dev_extent_chunk_objectid(eb, dev_extent),
1030 (unsigned long long)btrfs_dev_extent_chunk_offset(eb, dev_extent),
1031 (unsigned long long)btrfs_dev_extent_length(eb, dev_extent),
1035 static void print_qgroup_status(struct extent_buffer *eb, int slot)
1037 struct btrfs_qgroup_status_item *qg_status;
1038 char flags_str[256];
1040 qg_status = btrfs_item_ptr(eb, slot, struct btrfs_qgroup_status_item);
1041 memset(flags_str, 0, sizeof(flags_str));
1042 qgroup_flags_to_str(btrfs_qgroup_status_flags(eb, qg_status),
1044 printf("\t\tversion %llu generation %llu flags %s scan %lld\n",
1045 (unsigned long long)btrfs_qgroup_status_version(eb, qg_status),
1046 (unsigned long long)btrfs_qgroup_status_generation(eb, qg_status),
1048 (unsigned long long)btrfs_qgroup_status_rescan(eb, qg_status));
1051 static void print_qgroup_info(struct extent_buffer *eb, int slot)
1053 struct btrfs_qgroup_info_item *qg_info;
1055 qg_info = btrfs_item_ptr(eb, slot, struct btrfs_qgroup_info_item);
1056 printf("\t\tgeneration %llu\n"
1057 "\t\treferenced %llu referenced_compressed %llu\n"
1058 "\t\texclusive %llu exclusive_compressed %llu\n",
1059 (unsigned long long)btrfs_qgroup_info_generation(eb, qg_info),
1060 (unsigned long long)btrfs_qgroup_info_referenced(eb, qg_info),
1061 (unsigned long long)btrfs_qgroup_info_referenced_compressed(eb,
1063 (unsigned long long)btrfs_qgroup_info_exclusive(eb, qg_info),
1064 (unsigned long long)btrfs_qgroup_info_exclusive_compressed(eb,
1068 static void print_qgroup_limit(struct extent_buffer *eb, int slot)
1070 struct btrfs_qgroup_limit_item *qg_limit;
1072 qg_limit = btrfs_item_ptr(eb, slot, struct btrfs_qgroup_limit_item);
1073 printf("\t\tflags %llx\n"
1074 "\t\tmax_referenced %lld max_exclusive %lld\n"
1075 "\t\trsv_referenced %lld rsv_exclusive %lld\n",
1076 (unsigned long long)btrfs_qgroup_limit_flags(eb, qg_limit),
1077 (long long)btrfs_qgroup_limit_max_referenced(eb, qg_limit),
1078 (long long)btrfs_qgroup_limit_max_exclusive(eb, qg_limit),
1079 (long long)btrfs_qgroup_limit_rsv_referenced(eb, qg_limit),
1080 (long long)btrfs_qgroup_limit_rsv_exclusive(eb, qg_limit));
1083 static void print_persistent_item(struct extent_buffer *eb, void *ptr,
1084 u32 item_size, u64 objectid, u64 offset)
1086 printf("\t\tpersistent item objectid ");
1087 print_objectid(stdout, objectid, BTRFS_PERSISTENT_ITEM_KEY);
1088 printf(" offset %llu\n", (unsigned long long)offset);
1090 case BTRFS_DEV_STATS_OBJECTID:
1091 print_dev_stats(eb, ptr, item_size);
1094 printf("\t\tunknown persistent item objectid %llu\n", objectid);
1098 static void print_temporary_item(struct extent_buffer *eb, void *ptr,
1099 u64 objectid, u64 offset)
1101 printf("\t\ttemporary item objectid ");
1102 print_objectid(stdout, objectid, BTRFS_TEMPORARY_ITEM_KEY);
1103 printf(" offset %llu\n", (unsigned long long)offset);
1105 case BTRFS_BALANCE_OBJECTID:
1106 print_balance_item(eb, ptr);
1109 printf("\t\tunknown temporary item objectid %llu\n", objectid);
1113 static void print_extent_csum(struct extent_buffer *eb,
1114 struct btrfs_fs_info *fs_info, u32 item_size, u64 start)
1118 size = (item_size / btrfs_super_csum_size(fs_info->super_copy)) *
1119 fs_info->sectorsize;
1120 printf("\t\trange start %llu end %llu length %u\n",
1121 (unsigned long long)start,
1122 (unsigned long long)start + size, size);
1125 /* Caller must ensure sizeof(*ret) >= 14 "WRITTEN|RELOC" */
1126 static void header_flags_to_str(u64 flags, char *ret)
1130 if (flags & BTRFS_HEADER_FLAG_WRITTEN) {
1132 strcpy(ret, "WRITTEN");
1134 if (flags & BTRFS_HEADER_FLAG_RELOC) {
1137 strcat(ret, "RELOC");
1141 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
1143 struct btrfs_item *item;
1144 struct btrfs_disk_key disk_key;
1145 char flags_str[128];
1151 flags = btrfs_header_flags(eb) & ~BTRFS_BACKREF_REV_MASK;
1152 backref_rev = btrfs_header_flags(eb) >> BTRFS_BACKREF_REV_SHIFT;
1153 header_flags_to_str(flags, flags_str);
1154 nr = btrfs_header_nritems(eb);
1156 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
1157 (unsigned long long)btrfs_header_bytenr(eb), nr,
1158 btrfs_leaf_free_space(root, eb),
1159 (unsigned long long)btrfs_header_generation(eb),
1160 (unsigned long long)btrfs_header_owner(eb));
1161 printf("leaf %llu flags 0x%llx(%s) backref revision %d\n",
1162 btrfs_header_bytenr(eb), flags, flags_str, backref_rev);
1166 for (i = 0; i < nr; i++) {
1173 item = btrfs_item_nr(i);
1174 item_size = btrfs_item_size(eb, item);
1175 /* Untyped extraction of slot from btrfs_item_ptr */
1176 ptr = btrfs_item_ptr(eb, i, void*);
1178 btrfs_item_key(eb, &disk_key, i);
1179 objectid = btrfs_disk_key_objectid(&disk_key);
1180 type = btrfs_disk_key_type(&disk_key);
1181 offset = btrfs_disk_key_offset(&disk_key);
1183 printf("\titem %d ", i);
1184 btrfs_print_key(&disk_key);
1185 printf(" itemoff %d itemsize %d\n",
1186 btrfs_item_offset(eb, item),
1187 btrfs_item_size(eb, item));
1189 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID)
1190 print_free_space_header(eb, i);
1193 case BTRFS_INODE_ITEM_KEY:
1194 print_inode_item(eb, ptr);
1196 case BTRFS_INODE_REF_KEY:
1197 print_inode_ref_item(eb, item_size, ptr);
1199 case BTRFS_INODE_EXTREF_KEY:
1200 print_inode_extref_item(eb, item_size, ptr);
1202 case BTRFS_DIR_ITEM_KEY:
1203 case BTRFS_DIR_INDEX_KEY:
1204 case BTRFS_XATTR_ITEM_KEY:
1205 print_dir_item(eb, item_size, ptr);
1207 case BTRFS_DIR_LOG_INDEX_KEY:
1208 case BTRFS_DIR_LOG_ITEM_KEY: {
1209 struct btrfs_dir_log_item *dlog;
1211 dlog = btrfs_item_ptr(eb, i, struct btrfs_dir_log_item);
1212 printf("\t\tdir log end %Lu\n",
1213 (unsigned long long)btrfs_dir_log_end(eb, dlog));
1216 case BTRFS_ORPHAN_ITEM_KEY:
1217 printf("\t\torphan item\n");
1219 case BTRFS_ROOT_ITEM_KEY:
1220 print_root_item(eb, i);
1222 case BTRFS_ROOT_REF_KEY:
1223 print_root_ref(eb, i, "ref");
1225 case BTRFS_ROOT_BACKREF_KEY:
1226 print_root_ref(eb, i, "backref");
1228 case BTRFS_EXTENT_ITEM_KEY:
1229 print_extent_item(eb, i, 0);
1231 case BTRFS_METADATA_ITEM_KEY:
1232 print_extent_item(eb, i, 1);
1234 case BTRFS_TREE_BLOCK_REF_KEY:
1235 printf("\t\ttree block backref\n");
1237 case BTRFS_SHARED_BLOCK_REF_KEY:
1238 printf("\t\tshared block backref\n");
1240 case BTRFS_EXTENT_DATA_REF_KEY:
1241 print_extent_data_ref(eb, i);
1243 case BTRFS_SHARED_DATA_REF_KEY:
1244 print_shared_data_ref(eb, i);
1246 case BTRFS_EXTENT_REF_V0_KEY:
1247 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1248 print_extent_ref_v0(eb, i);
1253 case BTRFS_CSUM_ITEM_KEY:
1254 printf("\t\tcsum item\n");
1256 case BTRFS_EXTENT_CSUM_KEY:
1257 print_extent_csum(eb, root->fs_info, item_size,
1260 case BTRFS_EXTENT_DATA_KEY:
1261 print_file_extent_item(eb, item, i, ptr);
1263 case BTRFS_BLOCK_GROUP_ITEM_KEY:
1264 print_block_group_item(eb, ptr);
1266 case BTRFS_FREE_SPACE_INFO_KEY:
1267 print_free_space_info(eb, i);
1269 case BTRFS_FREE_SPACE_EXTENT_KEY:
1270 printf("\t\tfree space extent\n");
1272 case BTRFS_FREE_SPACE_BITMAP_KEY:
1273 printf("\t\tfree space bitmap\n");
1275 case BTRFS_CHUNK_ITEM_KEY:
1276 print_chunk_item(eb, ptr);
1278 case BTRFS_DEV_ITEM_KEY:
1279 print_dev_item(eb, ptr);
1281 case BTRFS_DEV_EXTENT_KEY:
1282 print_dev_extent(eb, i);
1284 case BTRFS_QGROUP_STATUS_KEY:
1285 print_qgroup_status(eb, i);
1287 case BTRFS_QGROUP_RELATION_KEY:
1289 case BTRFS_QGROUP_INFO_KEY:
1290 print_qgroup_info(eb, i);
1292 case BTRFS_QGROUP_LIMIT_KEY:
1293 print_qgroup_limit(eb, i);
1295 case BTRFS_UUID_KEY_SUBVOL:
1296 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
1297 print_uuid_item(eb, btrfs_item_ptr_offset(eb, i),
1298 btrfs_item_size_nr(eb, i));
1300 case BTRFS_STRING_ITEM_KEY: {
1301 const char *str = eb->data + btrfs_item_ptr_offset(eb, i);
1303 printf("\t\titem data %.*s\n", item_size, str);
1306 case BTRFS_PERSISTENT_ITEM_KEY:
1307 print_persistent_item(eb, ptr, item_size, objectid,
1310 case BTRFS_TEMPORARY_ITEM_KEY:
1311 print_temporary_item(eb, ptr, objectid, offset);
1318 void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
1322 struct btrfs_disk_key disk_key;
1323 struct btrfs_key key;
1324 struct extent_buffer *next;
1328 nr = btrfs_header_nritems(eb);
1329 if (btrfs_is_leaf(eb)) {
1330 btrfs_print_leaf(root, eb);
1333 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
1334 (unsigned long long)eb->start,
1335 btrfs_header_level(eb), nr,
1336 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
1337 (unsigned long long)btrfs_header_generation(eb),
1338 (unsigned long long)btrfs_header_owner(eb));
1341 for (i = 0; i < nr; i++) {
1342 u64 blocknr = btrfs_node_blockptr(eb, i);
1343 btrfs_node_key(eb, &disk_key, i);
1344 btrfs_disk_key_to_cpu(&key, &disk_key);
1346 btrfs_print_key(&disk_key);
1347 printf(" block %llu (%llu) gen %llu\n",
1348 (unsigned long long)blocknr,
1349 (unsigned long long)blocknr / root->fs_info->nodesize,
1350 (unsigned long long)btrfs_node_ptr_generation(eb, i));
1356 for (i = 0; i < nr; i++) {
1357 next = read_tree_block(root->fs_info,
1358 btrfs_node_blockptr(eb, i),
1359 btrfs_node_ptr_generation(eb, i));
1360 if (!extent_buffer_uptodate(next)) {
1361 fprintf(stderr, "failed to read %llu in tree %llu\n",
1362 (unsigned long long)btrfs_node_blockptr(eb, i),
1363 (unsigned long long)btrfs_header_owner(eb));
1366 if (btrfs_is_leaf(next) && btrfs_header_level(eb) != 1) {
1368 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1369 i, btrfs_header_level(next),
1370 btrfs_header_level(eb));
1373 if (btrfs_header_level(next) != btrfs_header_level(eb) - 1) {
1375 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1376 i, btrfs_header_level(next),
1377 btrfs_header_level(eb));
1380 btrfs_print_tree(root, next, 1);
1381 free_extent_buffer(next);
1387 free_extent_buffer(next);