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 u32 chunk_item_size = btrfs_chunk_item_size(num_stripes);
203 char chunk_flags_str[32] = {0};
205 if ((unsigned long)chunk + chunk_item_size > eb->len) {
206 printf("\t\tchunk item invalid\n");
210 bg_flags_to_str(btrfs_chunk_type(eb, chunk), chunk_flags_str);
211 printf("\t\tlength %llu owner %llu stripe_len %llu type %s\n",
212 (unsigned long long)btrfs_chunk_length(eb, chunk),
213 (unsigned long long)btrfs_chunk_owner(eb, chunk),
214 (unsigned long long)btrfs_chunk_stripe_len(eb, chunk),
216 printf("\t\tio_align %u io_width %u sector_size %u\n",
217 btrfs_chunk_io_align(eb, chunk),
218 btrfs_chunk_io_width(eb, chunk),
219 btrfs_chunk_sector_size(eb, chunk));
220 printf("\t\tnum_stripes %hu sub_stripes %hu\n", num_stripes,
221 btrfs_chunk_sub_stripes(eb, chunk));
222 for (i = 0 ; i < num_stripes ; i++) {
223 unsigned char dev_uuid[BTRFS_UUID_SIZE];
224 char str_dev_uuid[BTRFS_UUID_UNPARSED_SIZE];
228 uuid_offset = (unsigned long)btrfs_stripe_dev_uuid_nr(chunk, i);
229 stripe_offset = (unsigned long)btrfs_stripe_nr(chunk, i);
231 if (uuid_offset < stripe_offset ||
232 (uuid_offset + BTRFS_UUID_SIZE) >
233 (stripe_offset + sizeof(struct btrfs_stripe))) {
234 printf("\t\t\tstripe %d invalid\n", i);
238 read_extent_buffer(eb, dev_uuid,
241 uuid_unparse(dev_uuid, str_dev_uuid);
242 printf("\t\t\tstripe %d devid %llu offset %llu\n", i,
243 (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i),
244 (unsigned long long)btrfs_stripe_offset_nr(eb, chunk, i));
245 printf("\t\t\tdev_uuid %s\n", str_dev_uuid);
249 static void print_dev_item(struct extent_buffer *eb,
250 struct btrfs_dev_item *dev_item)
252 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
253 char fsid_str[BTRFS_UUID_UNPARSED_SIZE];
254 u8 uuid[BTRFS_UUID_SIZE];
255 u8 fsid[BTRFS_UUID_SIZE];
257 read_extent_buffer(eb, uuid,
258 (unsigned long)btrfs_device_uuid(dev_item),
260 uuid_unparse(uuid, uuid_str);
261 read_extent_buffer(eb, fsid,
262 (unsigned long)btrfs_device_fsid(dev_item),
264 uuid_unparse(fsid, fsid_str);
265 printf("\t\tdevid %llu total_bytes %llu bytes_used %Lu\n"
266 "\t\tio_align %u io_width %u sector_size %u type %llu\n"
267 "\t\tgeneration %llu start_offset %llu dev_group %u\n"
268 "\t\tseek_speed %hhu bandwidth %hhu\n"
271 (unsigned long long)btrfs_device_id(eb, dev_item),
272 (unsigned long long)btrfs_device_total_bytes(eb, dev_item),
273 (unsigned long long)btrfs_device_bytes_used(eb, dev_item),
274 btrfs_device_io_align(eb, dev_item),
275 btrfs_device_io_width(eb, dev_item),
276 btrfs_device_sector_size(eb, dev_item),
277 (unsigned long long)btrfs_device_type(eb, dev_item),
278 (unsigned long long)btrfs_device_generation(eb, dev_item),
279 (unsigned long long)btrfs_device_start_offset(eb, dev_item),
280 btrfs_device_group(eb, dev_item),
281 btrfs_device_seek_speed(eb, dev_item),
282 btrfs_device_bandwidth(eb, dev_item),
286 static void print_uuids(struct extent_buffer *eb)
288 char fs_uuid[BTRFS_UUID_UNPARSED_SIZE];
289 char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE];
290 u8 disk_uuid[BTRFS_UUID_SIZE];
292 read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(),
295 fs_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
296 uuid_unparse(disk_uuid, fs_uuid);
298 read_extent_buffer(eb, disk_uuid,
299 btrfs_header_chunk_tree_uuid(eb),
302 chunk_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
303 uuid_unparse(disk_uuid, chunk_uuid);
304 printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid);
307 static void compress_type_to_str(u8 compress_type, char *ret)
309 switch (compress_type) {
310 case BTRFS_COMPRESS_NONE:
313 case BTRFS_COMPRESS_ZLIB:
316 case BTRFS_COMPRESS_LZO:
320 sprintf(ret, "UNKNOWN.%d", compress_type);
324 static const char* file_extent_type_to_str(u8 type)
327 case BTRFS_FILE_EXTENT_INLINE: return "inline";
328 case BTRFS_FILE_EXTENT_PREALLOC: return "prealloc";
329 case BTRFS_FILE_EXTENT_REG: return "regular";
330 default: return "unknown";
334 static void print_file_extent_item(struct extent_buffer *eb,
335 struct btrfs_item *item,
337 struct btrfs_file_extent_item *fi)
339 int extent_type = btrfs_file_extent_type(eb, fi);
340 char compress_str[16];
342 compress_type_to_str(btrfs_file_extent_compression(eb, fi),
345 printf("\t\tgeneration %llu type %hhu (%s)\n",
346 btrfs_file_extent_generation(eb, fi),
347 extent_type, file_extent_type_to_str(extent_type));
349 if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
350 printf("\t\tinline extent data size %u ram_bytes %u compression %hhu (%s)\n",
351 btrfs_file_extent_inline_item_len(eb, item),
352 btrfs_file_extent_inline_len(eb, slot, fi),
353 btrfs_file_extent_compression(eb, fi),
357 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
358 printf("\t\tprealloc data disk byte %llu nr %llu\n",
359 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
360 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
361 printf("\t\tprealloc data offset %llu nr %llu\n",
362 (unsigned long long)btrfs_file_extent_offset(eb, fi),
363 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi));
366 printf("\t\textent data disk byte %llu nr %llu\n",
367 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
368 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
369 printf("\t\textent data offset %llu nr %llu ram %llu\n",
370 (unsigned long long)btrfs_file_extent_offset(eb, fi),
371 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi),
372 (unsigned long long)btrfs_file_extent_ram_bytes(eb, fi));
373 printf("\t\textent compression %hhu (%s)\n",
374 btrfs_file_extent_compression(eb, fi),
378 /* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
379 static void extent_flags_to_str(u64 flags, char *ret)
383 if (flags & BTRFS_EXTENT_FLAG_DATA) {
387 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
392 strcat(ret, "TREE_BLOCK");
394 if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
396 strcat(ret, "FULL_BACKREF");
400 void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
402 struct btrfs_extent_item *ei;
403 struct btrfs_extent_inline_ref *iref;
404 struct btrfs_extent_data_ref *dref;
405 struct btrfs_shared_data_ref *sref;
406 struct btrfs_disk_key key;
410 u32 item_size = btrfs_item_size_nr(eb, slot);
413 char flags_str[32] = {0};
415 if (item_size < sizeof(*ei)) {
416 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
417 struct btrfs_extent_item_v0 *ei0;
418 BUG_ON(item_size != sizeof(*ei0));
419 ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0);
420 printf("\t\textent refs %u\n",
421 btrfs_extent_refs_v0(eb, ei0));
428 ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
429 flags = btrfs_extent_flags(eb, ei);
430 extent_flags_to_str(flags, flags_str);
432 printf("\t\textent refs %llu gen %llu flags %s\n",
433 (unsigned long long)btrfs_extent_refs(eb, ei),
434 (unsigned long long)btrfs_extent_generation(eb, ei),
437 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !metadata) {
438 struct btrfs_tree_block_info *info;
439 info = (struct btrfs_tree_block_info *)(ei + 1);
440 btrfs_tree_block_key(eb, info, &key);
441 printf("\t\ttree block ");
442 btrfs_print_key(&key);
443 printf(" level %d\n", btrfs_tree_block_level(eb, info));
444 iref = (struct btrfs_extent_inline_ref *)(info + 1);
445 } else if (metadata) {
446 struct btrfs_key tmp;
448 btrfs_item_key_to_cpu(eb, &tmp, slot);
449 printf("\t\ttree block skinny level %d\n", (int)tmp.offset);
450 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
452 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
455 ptr = (unsigned long)iref;
456 end = (unsigned long)ei + item_size;
458 iref = (struct btrfs_extent_inline_ref *)ptr;
459 type = btrfs_extent_inline_ref_type(eb, iref);
460 offset = btrfs_extent_inline_ref_offset(eb, iref);
462 case BTRFS_TREE_BLOCK_REF_KEY:
463 printf("\t\ttree block backref root %llu\n",
464 (unsigned long long)offset);
466 case BTRFS_SHARED_BLOCK_REF_KEY:
467 printf("\t\tshared block backref parent %llu\n",
468 (unsigned long long)offset);
470 case BTRFS_EXTENT_DATA_REF_KEY:
471 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
472 printf("\t\textent data backref root %llu "
473 "objectid %llu offset %llu count %u\n",
474 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
475 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
476 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
477 btrfs_extent_data_ref_count(eb, dref));
479 case BTRFS_SHARED_DATA_REF_KEY:
480 sref = (struct btrfs_shared_data_ref *)(iref + 1);
481 printf("\t\tshared data backref parent %llu count %u\n",
482 (unsigned long long)offset,
483 btrfs_shared_data_ref_count(eb, sref));
488 ptr += btrfs_extent_inline_ref_size(type);
493 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
494 static void print_extent_ref_v0(struct extent_buffer *eb, int slot)
496 struct btrfs_extent_ref_v0 *ref0;
498 ref0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_ref_v0);
499 printf("\t\textent back ref root %llu gen %llu "
500 "owner %llu num_refs %lu\n",
501 (unsigned long long)btrfs_ref_root_v0(eb, ref0),
502 (unsigned long long)btrfs_ref_generation_v0(eb, ref0),
503 (unsigned long long)btrfs_ref_objectid_v0(eb, ref0),
504 (unsigned long)btrfs_ref_count_v0(eb, ref0));
508 static void print_root_ref(struct extent_buffer *leaf, int slot, const char *tag)
510 struct btrfs_root_ref *ref;
511 char namebuf[BTRFS_NAME_LEN];
514 ref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref);
515 namelen = btrfs_root_ref_name_len(leaf, ref);
516 read_extent_buffer(leaf, namebuf, (unsigned long)(ref + 1), namelen);
517 printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag,
518 (unsigned long long)btrfs_root_ref_dirid(leaf, ref),
519 (unsigned long long)btrfs_root_ref_sequence(leaf, ref),
523 static int empty_uuid(const u8 *uuid)
527 for (i = 0; i < BTRFS_UUID_SIZE; i++)
534 * Caller must ensure sizeof(*ret) >= 7 "RDONLY"
536 static void root_flags_to_str(u64 flags, char *ret)
538 if (flags & BTRFS_ROOT_SUBVOL_RDONLY)
539 strcat(ret, "RDONLY");
544 static void print_root(struct extent_buffer *leaf, int slot)
546 struct btrfs_root_item *ri;
547 struct btrfs_root_item root_item;
549 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
550 char flags_str[32] = {0};
551 struct btrfs_key drop_key;
553 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
554 len = btrfs_item_size_nr(leaf, slot);
556 memset(&root_item, 0, sizeof(root_item));
557 read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);
558 root_flags_to_str(btrfs_root_flags(&root_item), flags_str);
560 printf("\t\tgeneration %llu root_dirid %llu bytenr %llu level %hhu refs %u\n",
561 (unsigned long long)btrfs_root_generation(&root_item),
562 (unsigned long long)btrfs_root_dirid(&root_item),
563 (unsigned long long)btrfs_root_bytenr(&root_item),
564 btrfs_root_level(&root_item),
565 btrfs_root_refs(&root_item));
566 printf("\t\tlastsnap %llu byte_limit %llu bytes_used %llu flags 0x%llx(%s)\n",
567 (unsigned long long)btrfs_root_last_snapshot(&root_item),
568 (unsigned long long)btrfs_root_limit(&root_item),
569 (unsigned long long)btrfs_root_used(&root_item),
570 (unsigned long long)btrfs_root_flags(&root_item),
573 if (root_item.generation == root_item.generation_v2) {
574 uuid_unparse(root_item.uuid, uuid_str);
575 printf("\t\tuuid %s\n", uuid_str);
576 if (!empty_uuid(root_item.parent_uuid)) {
577 uuid_unparse(root_item.parent_uuid, uuid_str);
578 printf("\t\tparent_uuid %s\n", uuid_str);
580 if (!empty_uuid(root_item.received_uuid)) {
581 uuid_unparse(root_item.received_uuid, uuid_str);
582 printf("\t\treceived_uuid %s\n", uuid_str);
584 if (root_item.ctransid) {
585 printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
586 btrfs_root_ctransid(&root_item),
587 btrfs_root_otransid(&root_item),
588 btrfs_root_stransid(&root_item),
589 btrfs_root_rtransid(&root_item));
593 btrfs_disk_key_to_cpu(&drop_key, &root_item.drop_progress);
595 btrfs_print_key(&root_item.drop_progress);
596 printf(" level %hhu\n", root_item.drop_level);
599 static void print_free_space_header(struct extent_buffer *leaf, int slot)
601 struct btrfs_free_space_header *header;
602 struct btrfs_disk_key location;
604 header = btrfs_item_ptr(leaf, slot, struct btrfs_free_space_header);
605 btrfs_free_space_key(leaf, header, &location);
606 printf("\t\tlocation ");
607 btrfs_print_key(&location);
609 printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
610 (unsigned long long)btrfs_free_space_generation(leaf, header),
611 (unsigned long long)btrfs_free_space_entries(leaf, header),
612 (unsigned long long)btrfs_free_space_bitmaps(leaf, header));
615 void print_key_type(FILE *stream, u64 objectid, u8 type)
617 static const char* key_to_str[256] = {
618 [BTRFS_INODE_ITEM_KEY] = "INODE_ITEM",
619 [BTRFS_INODE_REF_KEY] = "INODE_REF",
620 [BTRFS_INODE_EXTREF_KEY] = "INODE_EXTREF",
621 [BTRFS_DIR_ITEM_KEY] = "DIR_ITEM",
622 [BTRFS_DIR_INDEX_KEY] = "DIR_INDEX",
623 [BTRFS_DIR_LOG_ITEM_KEY] = "DIR_LOG_ITEM",
624 [BTRFS_DIR_LOG_INDEX_KEY] = "DIR_LOG_INDEX",
625 [BTRFS_XATTR_ITEM_KEY] = "XATTR_ITEM",
626 [BTRFS_ORPHAN_ITEM_KEY] = "ORPHAN_ITEM",
627 [BTRFS_ROOT_ITEM_KEY] = "ROOT_ITEM",
628 [BTRFS_ROOT_REF_KEY] = "ROOT_REF",
629 [BTRFS_ROOT_BACKREF_KEY] = "ROOT_BACKREF",
630 [BTRFS_EXTENT_ITEM_KEY] = "EXTENT_ITEM",
631 [BTRFS_METADATA_ITEM_KEY] = "METADATA_ITEM",
632 [BTRFS_TREE_BLOCK_REF_KEY] = "TREE_BLOCK_REF",
633 [BTRFS_SHARED_BLOCK_REF_KEY] = "SHARED_BLOCK_REF",
634 [BTRFS_EXTENT_DATA_REF_KEY] = "EXTENT_DATA_REF",
635 [BTRFS_SHARED_DATA_REF_KEY] = "SHARED_DATA_REF",
636 [BTRFS_EXTENT_REF_V0_KEY] = "EXTENT_REF_V0",
637 [BTRFS_CSUM_ITEM_KEY] = "CSUM_ITEM",
638 [BTRFS_EXTENT_CSUM_KEY] = "EXTENT_CSUM",
639 [BTRFS_EXTENT_DATA_KEY] = "EXTENT_DATA",
640 [BTRFS_BLOCK_GROUP_ITEM_KEY] = "BLOCK_GROUP_ITEM",
641 [BTRFS_FREE_SPACE_INFO_KEY] = "FREE_SPACE_INFO",
642 [BTRFS_FREE_SPACE_EXTENT_KEY] = "FREE_SPACE_EXTENT",
643 [BTRFS_FREE_SPACE_BITMAP_KEY] = "FREE_SPACE_BITMAP",
644 [BTRFS_CHUNK_ITEM_KEY] = "CHUNK_ITEM",
645 [BTRFS_DEV_ITEM_KEY] = "DEV_ITEM",
646 [BTRFS_DEV_EXTENT_KEY] = "DEV_EXTENT",
647 [BTRFS_TEMPORARY_ITEM_KEY] = "TEMPORARY_ITEM",
648 [BTRFS_DEV_REPLACE_KEY] = "DEV_REPLACE",
649 [BTRFS_STRING_ITEM_KEY] = "STRING_ITEM",
650 [BTRFS_QGROUP_STATUS_KEY] = "QGROUP_STATUS",
651 [BTRFS_QGROUP_RELATION_KEY] = "QGROUP_RELATION",
652 [BTRFS_QGROUP_INFO_KEY] = "QGROUP_INFO",
653 [BTRFS_QGROUP_LIMIT_KEY] = "QGROUP_LIMIT",
654 [BTRFS_PERSISTENT_ITEM_KEY] = "PERSISTENT_ITEM",
655 [BTRFS_UUID_KEY_SUBVOL] = "UUID_KEY_SUBVOL",
656 [BTRFS_UUID_KEY_RECEIVED_SUBVOL] = "UUID_KEY_RECEIVED_SUBVOL",
659 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
660 fprintf(stream, "UNTYPED");
665 if (key_to_str[type])
666 fputs(key_to_str[type], stream);
668 fprintf(stream, "UNKNOWN.%d", type);
671 void print_objectid(FILE *stream, u64 objectid, u8 type)
674 case BTRFS_DEV_EXTENT_KEY:
676 fprintf(stream, "%llu", (unsigned long long)objectid);
678 case BTRFS_QGROUP_RELATION_KEY:
679 fprintf(stream, "%llu/%llu", btrfs_qgroup_level(objectid),
680 btrfs_qgroup_subvid(objectid));
682 case BTRFS_UUID_KEY_SUBVOL:
683 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
684 fprintf(stream, "0x%016llx", (unsigned long long)objectid);
689 case BTRFS_ROOT_TREE_OBJECTID:
690 if (type == BTRFS_DEV_ITEM_KEY)
691 fprintf(stream, "DEV_ITEMS");
693 fprintf(stream, "ROOT_TREE");
695 case BTRFS_EXTENT_TREE_OBJECTID:
696 fprintf(stream, "EXTENT_TREE");
698 case BTRFS_CHUNK_TREE_OBJECTID:
699 fprintf(stream, "CHUNK_TREE");
701 case BTRFS_DEV_TREE_OBJECTID:
702 fprintf(stream, "DEV_TREE");
704 case BTRFS_FS_TREE_OBJECTID:
705 fprintf(stream, "FS_TREE");
707 case BTRFS_ROOT_TREE_DIR_OBJECTID:
708 fprintf(stream, "ROOT_TREE_DIR");
710 case BTRFS_CSUM_TREE_OBJECTID:
711 fprintf(stream, "CSUM_TREE");
713 case BTRFS_BALANCE_OBJECTID:
714 fprintf(stream, "BALANCE");
716 case BTRFS_ORPHAN_OBJECTID:
717 fprintf(stream, "ORPHAN");
719 case BTRFS_TREE_LOG_OBJECTID:
720 fprintf(stream, "TREE_LOG");
722 case BTRFS_TREE_LOG_FIXUP_OBJECTID:
723 fprintf(stream, "LOG_FIXUP");
725 case BTRFS_TREE_RELOC_OBJECTID:
726 fprintf(stream, "TREE_RELOC");
728 case BTRFS_DATA_RELOC_TREE_OBJECTID:
729 fprintf(stream, "DATA_RELOC_TREE");
731 case BTRFS_EXTENT_CSUM_OBJECTID:
732 fprintf(stream, "EXTENT_CSUM");
734 case BTRFS_FREE_SPACE_OBJECTID:
735 fprintf(stream, "FREE_SPACE");
737 case BTRFS_FREE_INO_OBJECTID:
738 fprintf(stream, "FREE_INO");
740 case BTRFS_QUOTA_TREE_OBJECTID:
741 fprintf(stream, "QUOTA_TREE");
743 case BTRFS_UUID_TREE_OBJECTID:
744 fprintf(stream, "UUID_TREE");
746 case BTRFS_FREE_SPACE_TREE_OBJECTID:
747 fprintf(stream, "FREE_SPACE_TREE");
749 case BTRFS_MULTIPLE_OBJECTIDS:
750 fprintf(stream, "MULTIPLE");
753 fprintf(stream, "-1");
755 case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
756 if (type == BTRFS_CHUNK_ITEM_KEY) {
757 fprintf(stream, "FIRST_CHUNK_TREE");
762 fprintf(stream, "%llu", (unsigned long long)objectid);
766 void btrfs_print_key(struct btrfs_disk_key *disk_key)
768 u64 objectid = btrfs_disk_key_objectid(disk_key);
769 u8 type = btrfs_disk_key_type(disk_key);
770 u64 offset = btrfs_disk_key_offset(disk_key);
773 print_objectid(stdout, objectid, type);
775 print_key_type(stdout, objectid, type);
777 case BTRFS_QGROUP_RELATION_KEY:
778 case BTRFS_QGROUP_INFO_KEY:
779 case BTRFS_QGROUP_LIMIT_KEY:
780 printf(" %llu/%llu)", btrfs_qgroup_level(offset),
781 btrfs_qgroup_subvid(offset));
783 case BTRFS_UUID_KEY_SUBVOL:
784 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
785 printf(" 0x%016llx)", (unsigned long long)offset);
788 if (offset == (u64)-1)
791 printf(" %llu)", (unsigned long long)offset);
796 static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
799 if (item_size & (sizeof(u64) - 1)) {
800 printf("btrfs: uuid item with illegal size %lu!\n",
801 (unsigned long)item_size);
807 read_extent_buffer(l, &subvol_id, offset, sizeof(u64));
808 printf("\t\tsubvol_id %llu\n",
809 (unsigned long long)le64_to_cpu(subvol_id));
810 item_size -= sizeof(u64);
811 offset += sizeof(u64);
815 /* Btrfs inode flag stringification helper */
816 #define STRCAT_ONE_INODE_FLAG(flags, name, empty, dst) ({ \
817 if (flags & BTRFS_INODE_##name) { \
820 strcat(dst, #name); \
826 * Caller should ensure sizeof(*ret) >= 102: all charactors plus '|' of
827 * BTRFS_INODE_* flags
829 static void inode_flags_to_str(u64 flags, char *ret)
833 STRCAT_ONE_INODE_FLAG(flags, NODATASUM, empty, ret);
834 STRCAT_ONE_INODE_FLAG(flags, NODATACOW, empty, ret);
835 STRCAT_ONE_INODE_FLAG(flags, READONLY, empty, ret);
836 STRCAT_ONE_INODE_FLAG(flags, NOCOMPRESS, empty, ret);
837 STRCAT_ONE_INODE_FLAG(flags, PREALLOC, empty, ret);
838 STRCAT_ONE_INODE_FLAG(flags, SYNC, empty, ret);
839 STRCAT_ONE_INODE_FLAG(flags, IMMUTABLE, empty, ret);
840 STRCAT_ONE_INODE_FLAG(flags, APPEND, empty, ret);
841 STRCAT_ONE_INODE_FLAG(flags, NODUMP, empty, ret);
842 STRCAT_ONE_INODE_FLAG(flags, NOATIME, empty, ret);
843 STRCAT_ONE_INODE_FLAG(flags, DIRSYNC, empty, ret);
844 STRCAT_ONE_INODE_FLAG(flags, COMPRESS, empty, ret);
849 static void print_timespec(struct extent_buffer *eb,
850 struct btrfs_timespec *timespec, const char *prefix,
859 tmp_u64 = btrfs_timespec_sec(eb, timespec);
860 tmp_u32 = btrfs_timespec_nsec(eb, timespec);
862 localtime_r(&tmp_time, &tm);
863 strftime(timestamp, sizeof(timestamp),
864 "%Y-%m-%d %H:%M:%S", &tm);
865 printf("%s%llu.%u (%s)%s", prefix, (unsigned long long)tmp_u64, tmp_u32,
869 static void print_inode_item(struct extent_buffer *eb,
870 struct btrfs_inode_item *ii)
874 memset(flags_str, 0, sizeof(flags_str));
875 inode_flags_to_str(btrfs_inode_flags(eb, ii), flags_str);
876 printf("\t\tinode generation %llu transid %llu size %llu nbytes %llu\n"
877 "\t\tblock group %llu mode %o links %u uid %u gid %u rdev %llu\n"
878 "\t\tsequence %llu flags 0x%llx(%s)\n",
879 (unsigned long long)btrfs_inode_generation(eb, ii),
880 (unsigned long long)btrfs_inode_transid(eb, ii),
881 (unsigned long long)btrfs_inode_size(eb, ii),
882 (unsigned long long)btrfs_inode_nbytes(eb, ii),
883 (unsigned long long)btrfs_inode_block_group(eb,ii),
884 btrfs_inode_mode(eb, ii),
885 btrfs_inode_nlink(eb, ii),
886 btrfs_inode_uid(eb, ii),
887 btrfs_inode_gid(eb, ii),
888 (unsigned long long)btrfs_inode_rdev(eb,ii),
889 (unsigned long long)btrfs_inode_flags(eb,ii),
890 (unsigned long long)btrfs_inode_sequence(eb, ii),
892 print_timespec(eb, btrfs_inode_atime(ii), "\t\tatime ", "\n");
893 print_timespec(eb, btrfs_inode_ctime(ii), "\t\tctime ", "\n");
894 print_timespec(eb, btrfs_inode_mtime(ii), "\t\tmtime ", "\n");
895 print_timespec(eb, btrfs_inode_otime(ii), "\t\totime ", "\n");
898 static void print_disk_balance_args(struct btrfs_disk_balance_args *ba)
900 printf("\t\tprofiles %llu devid %llu target %llu flags %llu\n",
901 (unsigned long long)le64_to_cpu(ba->profiles),
902 (unsigned long long)le64_to_cpu(ba->devid),
903 (unsigned long long)le64_to_cpu(ba->target),
904 (unsigned long long)le64_to_cpu(ba->flags));
905 printf("\t\tusage_min %u usage_max %u pstart %llu pend %llu\n",
906 le32_to_cpu(ba->usage_min),
907 le32_to_cpu(ba->usage_max),
908 (unsigned long long)le64_to_cpu(ba->pstart),
909 (unsigned long long)le64_to_cpu(ba->pend));
910 printf("\t\tvstart %llu vend %llu limit_min %u limit_max %u\n",
911 (unsigned long long)le64_to_cpu(ba->vstart),
912 (unsigned long long)le64_to_cpu(ba->vend),
913 le32_to_cpu(ba->limit_min),
914 le32_to_cpu(ba->limit_max));
915 printf("\t\tstripes_min %u stripes_max %u\n",
916 le32_to_cpu(ba->stripes_min),
917 le32_to_cpu(ba->stripes_max));
920 static void print_balance_item(struct extent_buffer *eb,
921 struct btrfs_balance_item *bi)
923 printf("\t\tbalance status flags %llu\n",
924 btrfs_balance_item_flags(eb, bi));
926 printf("\t\tDATA\n");
927 print_disk_balance_args(btrfs_balance_item_data(eb, bi));
928 printf("\t\tMETADATA\n");
929 print_disk_balance_args(btrfs_balance_item_meta(eb, bi));
930 printf("\t\tSYSTEM\n");
931 print_disk_balance_args(btrfs_balance_item_sys(eb, bi));
934 static void print_dev_stats(struct extent_buffer *eb,
935 struct btrfs_dev_stats_item *stats, u32 size)
938 u32 known = BTRFS_DEV_STAT_VALUES_MAX * sizeof(__le64);
939 __le64 *values = btrfs_dev_stats_values(eb, stats);
941 printf("\t\tdevice stats\n");
942 printf("\t\twrite_errs %llu read_errs %llu flush_errs %llu corruption_errs %llu generation %llu\n",
943 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_WRITE_ERRS]),
944 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_READ_ERRS]),
945 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_FLUSH_ERRS]),
946 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_CORRUPTION_ERRS]),
947 (unsigned long long)le64_to_cpu(values[BTRFS_DEV_STAT_GENERATION_ERRS]));
950 printf("\t\tunknown stats item bytes %u", size - known);
951 for (i = BTRFS_DEV_STAT_VALUES_MAX; i * sizeof(__le64) < size; i++) {
952 printf("\t\tunknown item %u offset %zu value %llu\n",
953 i, i * sizeof(__le64),
954 (unsigned long long)le64_to_cpu(values[i]));
959 /* Caller must ensure sizeof(*ret) >= 14 "WRITTEN|RELOC" */
960 static void header_flags_to_str(u64 flags, char *ret)
964 if (flags & BTRFS_HEADER_FLAG_WRITTEN) {
966 strcpy(ret, "WRITTEN");
968 if (flags & BTRFS_HEADER_FLAG_RELOC) {
971 strcat(ret, "RELOC");
975 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
977 struct btrfs_item *item;
978 struct btrfs_disk_key disk_key;
985 flags = btrfs_header_flags(eb) & ~BTRFS_BACKREF_REV_MASK;
986 backref_rev = btrfs_header_flags(eb) >> BTRFS_BACKREF_REV_SHIFT;
987 header_flags_to_str(flags, flags_str);
988 nr = btrfs_header_nritems(eb);
990 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
991 (unsigned long long)btrfs_header_bytenr(eb), nr,
992 btrfs_leaf_free_space(root, eb),
993 (unsigned long long)btrfs_header_generation(eb),
994 (unsigned long long)btrfs_header_owner(eb));
995 printf("leaf %llu flags 0x%llx(%s) backref revision %d\n",
996 btrfs_header_bytenr(eb), flags, flags_str, backref_rev);
1000 for (i = 0; i < nr; i++) {
1006 char flags_str[256];
1007 char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
1008 u8 uuid[BTRFS_UUID_SIZE];
1010 item = btrfs_item_nr(i);
1011 item_size = btrfs_item_size(eb, item);
1012 /* Untyped extraction of slot from btrfs_item_ptr */
1013 ptr = btrfs_item_ptr(eb, i, void*);
1015 btrfs_item_key(eb, &disk_key, i);
1016 objectid = btrfs_disk_key_objectid(&disk_key);
1017 type = btrfs_disk_key_type(&disk_key);
1018 offset = btrfs_disk_key_offset(&disk_key);
1020 printf("\titem %d ", i);
1021 btrfs_print_key(&disk_key);
1022 printf(" itemoff %d itemsize %d\n",
1023 btrfs_item_offset(eb, item),
1024 btrfs_item_size(eb, item));
1026 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID)
1027 print_free_space_header(eb, i);
1030 case BTRFS_INODE_ITEM_KEY:
1031 print_inode_item(eb, ptr);
1033 case BTRFS_INODE_REF_KEY:
1034 print_inode_ref_item(eb, item_size, ptr);
1036 case BTRFS_INODE_EXTREF_KEY:
1037 print_inode_extref_item(eb, item_size, ptr);
1039 case BTRFS_DIR_ITEM_KEY:
1040 case BTRFS_DIR_INDEX_KEY:
1041 case BTRFS_XATTR_ITEM_KEY:
1042 print_dir_item(eb, item_size, ptr);
1044 case BTRFS_DIR_LOG_INDEX_KEY:
1045 case BTRFS_DIR_LOG_ITEM_KEY: {
1046 struct btrfs_dir_log_item *dlog;
1048 dlog = btrfs_item_ptr(eb, i, struct btrfs_dir_log_item);
1049 printf("\t\tdir log end %Lu\n",
1050 (unsigned long long)btrfs_dir_log_end(eb, dlog));
1053 case BTRFS_ORPHAN_ITEM_KEY:
1054 printf("\t\torphan item\n");
1056 case BTRFS_ROOT_ITEM_KEY:
1059 case BTRFS_ROOT_REF_KEY:
1060 print_root_ref(eb, i, "ref");
1062 case BTRFS_ROOT_BACKREF_KEY:
1063 print_root_ref(eb, i, "backref");
1065 case BTRFS_EXTENT_ITEM_KEY:
1066 print_extent_item(eb, i, 0);
1068 case BTRFS_METADATA_ITEM_KEY:
1069 print_extent_item(eb, i, 1);
1071 case BTRFS_TREE_BLOCK_REF_KEY:
1072 printf("\t\ttree block backref\n");
1074 case BTRFS_SHARED_BLOCK_REF_KEY:
1075 printf("\t\tshared block backref\n");
1077 case BTRFS_EXTENT_DATA_REF_KEY: {
1078 struct btrfs_extent_data_ref *dref;
1080 dref = btrfs_item_ptr(eb, i, struct btrfs_extent_data_ref);
1081 printf("\t\textent data backref root %llu "
1082 "objectid %llu offset %llu count %u\n",
1083 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
1084 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
1085 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
1086 btrfs_extent_data_ref_count(eb, dref));
1089 case BTRFS_SHARED_DATA_REF_KEY: {
1090 struct btrfs_shared_data_ref *sref;
1091 sref = btrfs_item_ptr(eb, i, struct btrfs_shared_data_ref);
1092 printf("\t\tshared data backref count %u\n",
1093 btrfs_shared_data_ref_count(eb, sref));
1096 case BTRFS_EXTENT_REF_V0_KEY:
1097 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
1098 print_extent_ref_v0(eb, i);
1103 case BTRFS_CSUM_ITEM_KEY:
1104 printf("\t\tcsum item\n");
1106 case BTRFS_EXTENT_CSUM_KEY:
1107 printf("\t\textent csum item\n");
1109 case BTRFS_EXTENT_DATA_KEY:
1110 print_file_extent_item(eb, item, i, ptr);
1112 case BTRFS_BLOCK_GROUP_ITEM_KEY: {
1113 struct btrfs_block_group_item bg_item;
1115 read_extent_buffer(eb, &bg_item, (unsigned long)ptr,
1117 memset(flags_str, 0, sizeof(flags_str));
1118 bg_flags_to_str(btrfs_block_group_flags(&bg_item),
1120 printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
1121 (unsigned long long)btrfs_block_group_used(&bg_item),
1122 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
1126 case BTRFS_FREE_SPACE_INFO_KEY: {
1127 struct btrfs_free_space_info *free_info;
1129 free_info = btrfs_item_ptr(eb, i, struct btrfs_free_space_info);
1130 printf("\t\tfree space info extent count %u flags %u\n",
1131 (unsigned)btrfs_free_space_extent_count(eb, free_info),
1132 (unsigned)btrfs_free_space_flags(eb, free_info));
1135 case BTRFS_FREE_SPACE_EXTENT_KEY:
1136 printf("\t\tfree space extent\n");
1138 case BTRFS_FREE_SPACE_BITMAP_KEY:
1139 printf("\t\tfree space bitmap\n");
1141 case BTRFS_CHUNK_ITEM_KEY:
1142 print_chunk(eb, ptr);
1144 case BTRFS_DEV_ITEM_KEY:
1145 print_dev_item(eb, ptr);
1147 case BTRFS_DEV_EXTENT_KEY: {
1148 struct btrfs_dev_extent *dev_extent;
1150 dev_extent = btrfs_item_ptr(eb, i,
1151 struct btrfs_dev_extent);
1152 read_extent_buffer(eb, uuid,
1153 (unsigned long)btrfs_dev_extent_chunk_tree_uuid(dev_extent),
1155 uuid_unparse(uuid, uuid_str);
1156 printf("\t\tdev extent chunk_tree %llu\n"
1157 "\t\tchunk_objectid %llu chunk_offset %llu "
1159 "\t\tchunk_tree_uuid %s\n",
1160 (unsigned long long)
1161 btrfs_dev_extent_chunk_tree(eb, dev_extent),
1162 (unsigned long long)
1163 btrfs_dev_extent_chunk_objectid(eb, dev_extent),
1164 (unsigned long long)
1165 btrfs_dev_extent_chunk_offset(eb, dev_extent),
1166 (unsigned long long)
1167 btrfs_dev_extent_length(eb, dev_extent),
1171 case BTRFS_QGROUP_STATUS_KEY: {
1172 struct btrfs_qgroup_status_item *qg_status;
1174 qg_status = btrfs_item_ptr(eb, i,
1175 struct btrfs_qgroup_status_item);
1176 memset(flags_str, 0, sizeof(flags_str));
1177 qgroup_flags_to_str(btrfs_qgroup_status_flags(eb, qg_status),
1179 printf("\t\tversion %llu generation %llu flags %s "
1181 (unsigned long long)
1182 btrfs_qgroup_status_version(eb, qg_status),
1183 (unsigned long long)
1184 btrfs_qgroup_status_generation(eb, qg_status),
1186 (unsigned long long)
1187 btrfs_qgroup_status_rescan(eb, qg_status));
1190 case BTRFS_QGROUP_RELATION_KEY:
1192 case BTRFS_QGROUP_INFO_KEY: {
1193 struct btrfs_qgroup_info_item *qg_info;
1195 qg_info = btrfs_item_ptr(eb, i,
1196 struct btrfs_qgroup_info_item);
1197 printf("\t\tgeneration %llu\n"
1198 "\t\treferenced %llu referenced_compressed %llu\n"
1199 "\t\texclusive %llu exclusive_compressed %llu\n",
1200 (unsigned long long)
1201 btrfs_qgroup_info_generation(eb, qg_info),
1202 (unsigned long long)
1203 btrfs_qgroup_info_referenced(eb, qg_info),
1204 (unsigned long long)
1205 btrfs_qgroup_info_referenced_compressed(eb,
1207 (unsigned long long)
1208 btrfs_qgroup_info_exclusive(eb, qg_info),
1209 (unsigned long long)
1210 btrfs_qgroup_info_exclusive_compressed(eb,
1214 case BTRFS_QGROUP_LIMIT_KEY: {
1215 struct btrfs_qgroup_limit_item *qg_limit;
1217 qg_limit = btrfs_item_ptr(eb, i,
1218 struct btrfs_qgroup_limit_item);
1219 printf("\t\tflags %llx\n"
1220 "\t\tmax_referenced %lld max_exclusive %lld\n"
1221 "\t\trsv_referenced %lld rsv_exclusive %lld\n",
1222 (unsigned long long)
1223 btrfs_qgroup_limit_flags(eb, qg_limit),
1225 btrfs_qgroup_limit_max_referenced(eb, qg_limit),
1227 btrfs_qgroup_limit_max_exclusive(eb, qg_limit),
1229 btrfs_qgroup_limit_rsv_referenced(eb, qg_limit),
1231 btrfs_qgroup_limit_rsv_exclusive(eb, qg_limit));
1234 case BTRFS_UUID_KEY_SUBVOL:
1235 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
1236 print_uuid_item(eb, btrfs_item_ptr_offset(eb, i),
1237 btrfs_item_size_nr(eb, i));
1239 case BTRFS_STRING_ITEM_KEY: {
1240 const char *str = eb->data + btrfs_item_ptr_offset(eb, i);
1242 printf("\t\titem data %.*s\n", item_size, str);
1245 case BTRFS_PERSISTENT_ITEM_KEY:
1246 printf("\t\tpersistent item objectid ");
1247 print_objectid(stdout, objectid, BTRFS_PERSISTENT_ITEM_KEY);
1248 printf(" offset %llu\n", (unsigned long long)offset);
1250 case BTRFS_DEV_STATS_OBJECTID:
1251 print_dev_stats(eb, ptr, item_size);
1254 printf("\t\tunknown persistent item objectid %llu\n",
1258 case BTRFS_TEMPORARY_ITEM_KEY:
1259 printf("\t\ttemporary item objectid ");
1260 print_objectid(stdout, objectid, BTRFS_TEMPORARY_ITEM_KEY);
1261 printf(" offset %llu\n", (unsigned long long)offset);
1263 case BTRFS_BALANCE_OBJECTID:
1264 print_balance_item(eb, ptr);
1267 printf("\t\tunknown temporary item objectid %llu\n",
1276 void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
1281 struct btrfs_disk_key disk_key;
1282 struct btrfs_key key;
1283 struct extent_buffer *next;
1287 nr = btrfs_header_nritems(eb);
1288 if (btrfs_is_leaf(eb)) {
1289 btrfs_print_leaf(root, eb);
1292 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
1293 (unsigned long long)eb->start,
1294 btrfs_header_level(eb), nr,
1295 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
1296 (unsigned long long)btrfs_header_generation(eb),
1297 (unsigned long long)btrfs_header_owner(eb));
1300 size = root->fs_info->nodesize;
1301 for (i = 0; i < nr; i++) {
1302 u64 blocknr = btrfs_node_blockptr(eb, i);
1303 btrfs_node_key(eb, &disk_key, i);
1304 btrfs_disk_key_to_cpu(&key, &disk_key);
1306 btrfs_print_key(&disk_key);
1307 printf(" block %llu (%llu) gen %llu\n",
1308 (unsigned long long)blocknr,
1309 (unsigned long long)blocknr / size,
1310 (unsigned long long)btrfs_node_ptr_generation(eb, i));
1316 for (i = 0; i < nr; i++) {
1317 next = read_tree_block(root, btrfs_node_blockptr(eb, i), size,
1318 btrfs_node_ptr_generation(eb, i));
1319 if (!extent_buffer_uptodate(next)) {
1320 fprintf(stderr, "failed to read %llu in tree %llu\n",
1321 (unsigned long long)btrfs_node_blockptr(eb, i),
1322 (unsigned long long)btrfs_header_owner(eb));
1325 if (btrfs_is_leaf(next) && btrfs_header_level(eb) != 1) {
1327 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1328 i, btrfs_header_level(next),
1329 btrfs_header_level(eb));
1332 if (btrfs_header_level(next) != btrfs_header_level(eb) - 1) {
1334 "eb corrupted: item %d eb level %d next level %d, skipping the rest",
1335 i, btrfs_header_level(next),
1336 btrfs_header_level(eb));
1339 btrfs_print_tree(root, next, 1);
1340 free_extent_buffer(next);
1346 free_extent_buffer(next);