2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
21 #include <uuid/uuid.h>
22 #include "kerncompat.h"
23 #include "radix-tree.h"
26 #include "print-tree.h"
30 static void print_dir_item_type(struct extent_buffer
*eb
,
31 struct btrfs_dir_item
*di
)
33 u8 type
= btrfs_dir_type(eb
, di
);
36 case BTRFS_FT_REG_FILE
:
54 case BTRFS_FT_SYMLINK
:
65 static int print_dir_item(struct extent_buffer
*eb
, struct btrfs_item
*item
,
66 struct btrfs_dir_item
*di
)
73 char namebuf
[BTRFS_NAME_LEN
];
74 struct btrfs_disk_key location
;
76 total
= btrfs_item_size(eb
, item
);
78 btrfs_dir_item_key(eb
, di
, &location
);
79 printf("\t\tlocation ");
80 btrfs_print_key(&location
);
82 print_dir_item_type(eb
, di
);
84 name_len
= btrfs_dir_name_len(eb
, di
);
85 data_len
= btrfs_dir_data_len(eb
, di
);
86 len
= (name_len
<= sizeof(namebuf
))? name_len
: sizeof(namebuf
);
87 read_extent_buffer(eb
, namebuf
, (unsigned long)(di
+ 1), len
);
88 printf("\t\tnamelen %u datalen %u name: %.*s\n",
89 name_len
, data_len
, len
, namebuf
);
91 len
= (data_len
<= sizeof(namebuf
))? data_len
: sizeof(namebuf
);
92 read_extent_buffer(eb
, namebuf
,
93 (unsigned long)(di
+ 1) + name_len
, len
);
94 printf("\t\tdata %.*s\n", len
, namebuf
);
96 len
= sizeof(*di
) + name_len
+ data_len
;
97 di
= (struct btrfs_dir_item
*)((char *)di
+ len
);
103 static int print_inode_extref_item(struct extent_buffer
*eb
,
104 struct btrfs_item
*item
,
105 struct btrfs_inode_extref
*extref
)
113 char namebuf
[BTRFS_NAME_LEN
];
115 total
= btrfs_item_size(eb
, item
);
117 while (cur
< total
) {
118 index
= btrfs_inode_extref_index(eb
, extref
);
119 name_len
= btrfs_inode_extref_name_len(eb
, extref
);
120 parent_objid
= btrfs_inode_extref_parent(eb
, extref
);
122 len
= (name_len
<= sizeof(namebuf
))? name_len
: sizeof(namebuf
);
124 read_extent_buffer(eb
, namebuf
, (unsigned long)(extref
->name
), len
);
126 printf("\t\tinode extref index %llu parent %llu namelen %u "
128 (unsigned long long)index
,
129 (unsigned long long)parent_objid
,
130 name_len
, len
, namebuf
);
132 len
= sizeof(*extref
) + name_len
;
133 extref
= (struct btrfs_inode_extref
*)((char *)extref
+ len
);
139 static int print_inode_ref_item(struct extent_buffer
*eb
, struct btrfs_item
*item
,
140 struct btrfs_inode_ref
*ref
)
147 char namebuf
[BTRFS_NAME_LEN
];
148 total
= btrfs_item_size(eb
, item
);
150 name_len
= btrfs_inode_ref_name_len(eb
, ref
);
151 index
= btrfs_inode_ref_index(eb
, ref
);
152 len
= (name_len
<= sizeof(namebuf
))? name_len
: sizeof(namebuf
);
153 read_extent_buffer(eb
, namebuf
, (unsigned long)(ref
+ 1), len
);
154 printf("\t\tinode ref index %llu namelen %u name: %.*s\n",
155 (unsigned long long)index
, name_len
, len
, namebuf
);
156 len
= sizeof(*ref
) + name_len
;
157 ref
= (struct btrfs_inode_ref
*)((char *)ref
+ len
);
163 /* Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10" */
164 static void bg_flags_to_str(u64 flags
, char *ret
)
168 if (flags
& BTRFS_BLOCK_GROUP_DATA
) {
172 if (flags
& BTRFS_BLOCK_GROUP_METADATA
) {
175 strcat(ret
, "METADATA");
177 if (flags
& BTRFS_BLOCK_GROUP_SYSTEM
) {
180 strcat(ret
, "SYSTEM");
182 switch (flags
& BTRFS_BLOCK_GROUP_PROFILE_MASK
) {
183 case BTRFS_BLOCK_GROUP_RAID0
:
184 strcat(ret
, "|RAID0");
186 case BTRFS_BLOCK_GROUP_RAID1
:
187 strcat(ret
, "|RAID1");
189 case BTRFS_BLOCK_GROUP_DUP
:
192 case BTRFS_BLOCK_GROUP_RAID10
:
193 strcat(ret
, "|RAID10");
195 case BTRFS_BLOCK_GROUP_RAID5
:
196 strcat(ret
, "|RAID5");
198 case BTRFS_BLOCK_GROUP_RAID6
:
199 strcat(ret
, "|RAID6");
206 /* Caller should ensure sizeof(*ret)>= 26 "OFF|SCANNING|INCONSISTENT" */
207 static void qgroup_flags_to_str(u64 flags
, char *ret
)
209 if (flags
& BTRFS_QGROUP_STATUS_FLAG_ON
)
214 if (flags
& BTRFS_QGROUP_STATUS_FLAG_RESCAN
)
215 strcat(ret
, "|SCANNING");
216 if (flags
& BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT
)
217 strcat(ret
, "|INCONSISTENT");
220 void print_chunk(struct extent_buffer
*eb
, struct btrfs_chunk
*chunk
)
222 int num_stripes
= btrfs_chunk_num_stripes(eb
, chunk
);
224 char chunk_flags_str
[32] = {0};
226 bg_flags_to_str(btrfs_chunk_type(eb
, chunk
), chunk_flags_str
);
227 printf("\t\tchunk length %llu owner %llu stripe_len %llu\n",
228 (unsigned long long)btrfs_chunk_length(eb
, chunk
),
229 (unsigned long long)btrfs_chunk_owner(eb
, chunk
),
230 (unsigned long long)btrfs_chunk_stripe_len(eb
, chunk
));
231 printf("\t\ttype %s num_stripes %d\n",
232 chunk_flags_str
, num_stripes
);
233 for (i
= 0 ; i
< num_stripes
; i
++) {
234 printf("\t\t\tstripe %d devid %llu offset %llu\n", i
,
235 (unsigned long long)btrfs_stripe_devid_nr(eb
, chunk
, i
),
236 (unsigned long long)btrfs_stripe_offset_nr(eb
, chunk
, i
));
240 static void print_dev_item(struct extent_buffer
*eb
,
241 struct btrfs_dev_item
*dev_item
)
243 char disk_uuid_c
[BTRFS_UUID_UNPARSED_SIZE
];
244 u8 disk_uuid
[BTRFS_UUID_SIZE
];
246 read_extent_buffer(eb
, disk_uuid
,
247 (unsigned long)btrfs_device_uuid(dev_item
),
249 uuid_unparse(disk_uuid
, disk_uuid_c
);
250 printf("\t\tdev item devid %llu "
251 "total_bytes %llu bytes used %Lu\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
),
259 static void print_uuids(struct extent_buffer
*eb
)
261 char fs_uuid
[BTRFS_UUID_UNPARSED_SIZE
];
262 char chunk_uuid
[BTRFS_UUID_UNPARSED_SIZE
];
263 u8 disk_uuid
[BTRFS_UUID_SIZE
];
265 read_extent_buffer(eb
, disk_uuid
, btrfs_header_fsid(),
268 fs_uuid
[BTRFS_UUID_UNPARSED_SIZE
- 1] = '\0';
269 uuid_unparse(disk_uuid
, fs_uuid
);
271 read_extent_buffer(eb
, disk_uuid
,
272 btrfs_header_chunk_tree_uuid(eb
),
275 chunk_uuid
[BTRFS_UUID_UNPARSED_SIZE
- 1] = '\0';
276 uuid_unparse(disk_uuid
, chunk_uuid
);
277 printf("fs uuid %s\nchunk uuid %s\n", fs_uuid
, chunk_uuid
);
280 static void print_file_extent_item(struct extent_buffer
*eb
,
281 struct btrfs_item
*item
,
283 struct btrfs_file_extent_item
*fi
)
285 int extent_type
= btrfs_file_extent_type(eb
, fi
);
287 if (extent_type
== BTRFS_FILE_EXTENT_INLINE
) {
288 printf("\t\tinline extent data size %u "
289 "ram %u compress %d\n",
290 btrfs_file_extent_inline_item_len(eb
, item
),
291 btrfs_file_extent_inline_len(eb
, slot
, fi
),
292 btrfs_file_extent_compression(eb
, fi
));
295 if (extent_type
== BTRFS_FILE_EXTENT_PREALLOC
) {
296 printf("\t\tprealloc data disk byte %llu nr %llu\n",
297 (unsigned long long)btrfs_file_extent_disk_bytenr(eb
, fi
),
298 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb
, fi
));
299 printf("\t\tprealloc data offset %llu nr %llu\n",
300 (unsigned long long)btrfs_file_extent_offset(eb
, fi
),
301 (unsigned long long)btrfs_file_extent_num_bytes(eb
, fi
));
304 printf("\t\textent data disk byte %llu nr %llu\n",
305 (unsigned long long)btrfs_file_extent_disk_bytenr(eb
, fi
),
306 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb
, fi
));
307 printf("\t\textent data offset %llu nr %llu ram %llu\n",
308 (unsigned long long)btrfs_file_extent_offset(eb
, fi
),
309 (unsigned long long)btrfs_file_extent_num_bytes(eb
, fi
),
310 (unsigned long long)btrfs_file_extent_ram_bytes(eb
, fi
));
311 printf("\t\textent compression %d\n",
312 btrfs_file_extent_compression(eb
, fi
));
315 /* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
316 static void extent_flags_to_str(u64 flags
, char *ret
)
320 if (flags
& BTRFS_EXTENT_FLAG_DATA
) {
324 if (flags
& BTRFS_EXTENT_FLAG_TREE_BLOCK
) {
329 strcat(ret
, "TREE_BLOCK");
331 if (flags
& BTRFS_BLOCK_FLAG_FULL_BACKREF
) {
333 strcat(ret
, "FULL_BACKREF");
337 void print_extent_item(struct extent_buffer
*eb
, int slot
, int metadata
)
339 struct btrfs_extent_item
*ei
;
340 struct btrfs_extent_inline_ref
*iref
;
341 struct btrfs_extent_data_ref
*dref
;
342 struct btrfs_shared_data_ref
*sref
;
343 struct btrfs_disk_key key
;
347 u32 item_size
= btrfs_item_size_nr(eb
, slot
);
350 char flags_str
[32] = {0};
352 if (item_size
< sizeof(*ei
)) {
353 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
354 struct btrfs_extent_item_v0
*ei0
;
355 BUG_ON(item_size
!= sizeof(*ei0
));
356 ei0
= btrfs_item_ptr(eb
, slot
, struct btrfs_extent_item_v0
);
357 printf("\t\textent refs %u\n",
358 btrfs_extent_refs_v0(eb
, ei0
));
365 ei
= btrfs_item_ptr(eb
, slot
, struct btrfs_extent_item
);
366 flags
= btrfs_extent_flags(eb
, ei
);
367 extent_flags_to_str(flags
, flags_str
);
369 printf("\t\textent refs %llu gen %llu flags %s\n",
370 (unsigned long long)btrfs_extent_refs(eb
, ei
),
371 (unsigned long long)btrfs_extent_generation(eb
, ei
),
374 if (flags
& BTRFS_EXTENT_FLAG_TREE_BLOCK
&& !metadata
) {
375 struct btrfs_tree_block_info
*info
;
376 info
= (struct btrfs_tree_block_info
*)(ei
+ 1);
377 btrfs_tree_block_key(eb
, info
, &key
);
378 printf("\t\ttree block ");
379 btrfs_print_key(&key
);
380 printf(" level %d\n", btrfs_tree_block_level(eb
, info
));
381 iref
= (struct btrfs_extent_inline_ref
*)(info
+ 1);
382 } else if (metadata
) {
383 struct btrfs_key tmp
;
385 btrfs_item_key_to_cpu(eb
, &tmp
, slot
);
386 printf("\t\ttree block skinny level %d\n", (int)tmp
.offset
);
387 iref
= (struct btrfs_extent_inline_ref
*)(ei
+ 1);
389 iref
= (struct btrfs_extent_inline_ref
*)(ei
+ 1);
392 ptr
= (unsigned long)iref
;
393 end
= (unsigned long)ei
+ item_size
;
395 iref
= (struct btrfs_extent_inline_ref
*)ptr
;
396 type
= btrfs_extent_inline_ref_type(eb
, iref
);
397 offset
= btrfs_extent_inline_ref_offset(eb
, iref
);
399 case BTRFS_TREE_BLOCK_REF_KEY
:
400 printf("\t\ttree block backref root %llu\n",
401 (unsigned long long)offset
);
403 case BTRFS_SHARED_BLOCK_REF_KEY
:
404 printf("\t\tshared block backref parent %llu\n",
405 (unsigned long long)offset
);
407 case BTRFS_EXTENT_DATA_REF_KEY
:
408 dref
= (struct btrfs_extent_data_ref
*)(&iref
->offset
);
409 printf("\t\textent data backref root %llu "
410 "objectid %llu offset %llu count %u\n",
411 (unsigned long long)btrfs_extent_data_ref_root(eb
, dref
),
412 (unsigned long long)btrfs_extent_data_ref_objectid(eb
, dref
),
413 (unsigned long long)btrfs_extent_data_ref_offset(eb
, dref
),
414 btrfs_extent_data_ref_count(eb
, dref
));
416 case BTRFS_SHARED_DATA_REF_KEY
:
417 sref
= (struct btrfs_shared_data_ref
*)(iref
+ 1);
418 printf("\t\tshared data backref parent %llu count %u\n",
419 (unsigned long long)offset
,
420 btrfs_shared_data_ref_count(eb
, sref
));
425 ptr
+= btrfs_extent_inline_ref_size(type
);
430 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
431 static void print_extent_ref_v0(struct extent_buffer
*eb
, int slot
)
433 struct btrfs_extent_ref_v0
*ref0
;
435 ref0
= btrfs_item_ptr(eb
, slot
, struct btrfs_extent_ref_v0
);
436 printf("\t\textent back ref root %llu gen %llu "
437 "owner %llu num_refs %lu\n",
438 (unsigned long long)btrfs_ref_root_v0(eb
, ref0
),
439 (unsigned long long)btrfs_ref_generation_v0(eb
, ref0
),
440 (unsigned long long)btrfs_ref_objectid_v0(eb
, ref0
),
441 (unsigned long)btrfs_ref_count_v0(eb
, ref0
));
445 static void print_root_ref(struct extent_buffer
*leaf
, int slot
, char *tag
)
447 struct btrfs_root_ref
*ref
;
448 char namebuf
[BTRFS_NAME_LEN
];
451 ref
= btrfs_item_ptr(leaf
, slot
, struct btrfs_root_ref
);
452 namelen
= btrfs_root_ref_name_len(leaf
, ref
);
453 read_extent_buffer(leaf
, namebuf
, (unsigned long)(ref
+ 1), namelen
);
454 printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag
,
455 (unsigned long long)btrfs_root_ref_dirid(leaf
, ref
),
456 (unsigned long long)btrfs_root_ref_sequence(leaf
, ref
),
460 static int count_bytes(void *buf
, int len
, char b
)
464 for (i
= 0; i
< len
; i
++) {
465 if (((char*)buf
)[i
] == b
)
471 static void print_root(struct extent_buffer
*leaf
, int slot
)
473 struct btrfs_root_item
*ri
;
474 struct btrfs_root_item root_item
;
476 char uuid_str
[BTRFS_UUID_UNPARSED_SIZE
];
478 ri
= btrfs_item_ptr(leaf
, slot
, struct btrfs_root_item
);
479 len
= btrfs_item_size_nr(leaf
, slot
);
481 memset(&root_item
, 0, sizeof(root_item
));
482 read_extent_buffer(leaf
, &root_item
, (unsigned long)ri
, len
);
484 printf("\t\troot data bytenr %llu level %d dirid %llu refs %u gen %llu lastsnap %llu\n",
485 (unsigned long long)btrfs_root_bytenr(&root_item
),
486 btrfs_root_level(&root_item
),
487 (unsigned long long)btrfs_root_dirid(&root_item
),
488 btrfs_root_refs(&root_item
),
489 (unsigned long long)btrfs_root_generation(&root_item
),
490 (unsigned long long)btrfs_root_last_snapshot(&root_item
));
492 if (root_item
.generation
== root_item
.generation_v2
) {
493 uuid_unparse(root_item
.uuid
, uuid_str
);
494 printf("\t\tuuid %s\n", uuid_str
);
495 if (count_bytes(root_item
.parent_uuid
, BTRFS_UUID_SIZE
, 0) != BTRFS_UUID_SIZE
) {
496 uuid_unparse(root_item
.parent_uuid
, uuid_str
);
497 printf("\t\tparent_uuid %s\n", uuid_str
);
499 if (count_bytes(root_item
.received_uuid
, BTRFS_UUID_SIZE
, 0) != BTRFS_UUID_SIZE
) {
500 uuid_unparse(root_item
.received_uuid
, uuid_str
);
501 printf("\t\treceived_uuid %s\n", uuid_str
);
503 if (root_item
.ctransid
) {
504 printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
505 btrfs_root_ctransid(&root_item
),
506 btrfs_root_otransid(&root_item
),
507 btrfs_root_stransid(&root_item
),
508 btrfs_root_rtransid(&root_item
));
511 if (btrfs_root_refs(&root_item
) == 0) {
512 struct btrfs_key drop_key
;
513 btrfs_disk_key_to_cpu(&drop_key
,
514 &root_item
.drop_progress
);
516 btrfs_print_key(&root_item
.drop_progress
);
517 printf(" level %d\n", root_item
.drop_level
);
521 static void print_free_space_header(struct extent_buffer
*leaf
, int slot
)
523 struct btrfs_free_space_header
*header
;
524 struct btrfs_disk_key location
;
526 header
= btrfs_item_ptr(leaf
, slot
, struct btrfs_free_space_header
);
527 btrfs_free_space_key(leaf
, header
, &location
);
528 printf("\t\tlocation ");
529 btrfs_print_key(&location
);
531 printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
532 (unsigned long long)btrfs_free_space_generation(leaf
, header
),
533 (unsigned long long)btrfs_free_space_entries(leaf
, header
),
534 (unsigned long long)btrfs_free_space_bitmaps(leaf
, header
));
537 static void print_key_type(u64 objectid
, u8 type
)
539 if (type
== 0 && objectid
== BTRFS_FREE_SPACE_OBJECTID
) {
545 case BTRFS_INODE_ITEM_KEY
:
546 printf("INODE_ITEM");
548 case BTRFS_INODE_REF_KEY
:
551 case BTRFS_INODE_EXTREF_KEY
:
552 printf("INODE_EXTREF");
554 case BTRFS_DIR_ITEM_KEY
:
557 case BTRFS_DIR_INDEX_KEY
:
560 case BTRFS_DIR_LOG_ITEM_KEY
:
561 printf("DIR_LOG_ITEM");
563 case BTRFS_DIR_LOG_INDEX_KEY
:
564 printf("DIR_LOG_INDEX");
566 case BTRFS_XATTR_ITEM_KEY
:
567 printf("XATTR_ITEM");
569 case BTRFS_ORPHAN_ITEM_KEY
:
570 printf("ORPHAN_ITEM");
572 case BTRFS_ROOT_ITEM_KEY
:
575 case BTRFS_ROOT_REF_KEY
:
578 case BTRFS_ROOT_BACKREF_KEY
:
579 printf("ROOT_BACKREF");
581 case BTRFS_EXTENT_ITEM_KEY
:
582 printf("EXTENT_ITEM");
584 case BTRFS_METADATA_ITEM_KEY
:
585 printf("METADATA_ITEM");
587 case BTRFS_TREE_BLOCK_REF_KEY
:
588 printf("TREE_BLOCK_REF");
590 case BTRFS_SHARED_BLOCK_REF_KEY
:
591 printf("SHARED_BLOCK_REF");
593 case BTRFS_EXTENT_DATA_REF_KEY
:
594 printf("EXTENT_DATA_REF");
596 case BTRFS_SHARED_DATA_REF_KEY
:
597 printf("SHARED_DATA_REF");
599 case BTRFS_EXTENT_REF_V0_KEY
:
600 printf("EXTENT_REF_V0");
602 case BTRFS_CSUM_ITEM_KEY
:
605 case BTRFS_EXTENT_CSUM_KEY
:
606 printf("EXTENT_CSUM");
608 case BTRFS_EXTENT_DATA_KEY
:
609 printf("EXTENT_DATA");
611 case BTRFS_BLOCK_GROUP_ITEM_KEY
:
612 printf("BLOCK_GROUP_ITEM");
614 case BTRFS_CHUNK_ITEM_KEY
:
615 printf("CHUNK_ITEM");
617 case BTRFS_DEV_ITEM_KEY
:
620 case BTRFS_DEV_EXTENT_KEY
:
621 printf("DEV_EXTENT");
623 case BTRFS_BALANCE_ITEM_KEY
:
624 printf("BALANCE_ITEM");
626 case BTRFS_DEV_REPLACE_KEY
:
627 printf("DEV_REPLACE");
629 case BTRFS_STRING_ITEM_KEY
:
630 printf("STRING_ITEM");
632 case BTRFS_QGROUP_STATUS_KEY
:
633 printf("QGROUP_STATUS");
635 case BTRFS_QGROUP_RELATION_KEY
:
636 printf("QGROUP_RELATION");
638 case BTRFS_QGROUP_INFO_KEY
:
639 printf("QGROUP_INFO");
641 case BTRFS_QGROUP_LIMIT_KEY
:
642 printf("QGROUP_LIMIT");
644 case BTRFS_DEV_STATS_KEY
:
647 case BTRFS_UUID_KEY_SUBVOL
:
648 printf("UUID_KEY_SUBVOL");
650 case BTRFS_UUID_KEY_RECEIVED_SUBVOL
:
651 printf("UUID_KEY_RECEIVED_SUBVOL");
654 printf("UNKNOWN.%d", type
);
658 static void print_objectid(u64 objectid
, u8 type
)
661 case BTRFS_DEV_EXTENT_KEY
:
662 printf("%llu", (unsigned long long)objectid
); /* device id */
664 case BTRFS_QGROUP_RELATION_KEY
:
665 printf("%llu/%llu", btrfs_qgroup_level(objectid
),
666 btrfs_qgroup_subvid(objectid
));
668 case BTRFS_UUID_KEY_SUBVOL
:
669 case BTRFS_UUID_KEY_RECEIVED_SUBVOL
:
670 printf("0x%016llx", (unsigned long long)objectid
);
675 case BTRFS_ROOT_TREE_OBJECTID
:
676 if (type
== BTRFS_DEV_ITEM_KEY
)
681 case BTRFS_EXTENT_TREE_OBJECTID
:
682 printf("EXTENT_TREE");
684 case BTRFS_CHUNK_TREE_OBJECTID
:
685 printf("CHUNK_TREE");
687 case BTRFS_DEV_TREE_OBJECTID
:
690 case BTRFS_FS_TREE_OBJECTID
:
693 case BTRFS_ROOT_TREE_DIR_OBJECTID
:
694 printf("ROOT_TREE_DIR");
696 case BTRFS_CSUM_TREE_OBJECTID
:
699 case BTRFS_BALANCE_OBJECTID
:
702 case BTRFS_ORPHAN_OBJECTID
:
705 case BTRFS_TREE_LOG_OBJECTID
:
708 case BTRFS_TREE_LOG_FIXUP_OBJECTID
:
711 case BTRFS_TREE_RELOC_OBJECTID
:
712 printf("TREE_RELOC");
714 case BTRFS_DATA_RELOC_TREE_OBJECTID
:
715 printf("DATA_RELOC_TREE");
717 case BTRFS_EXTENT_CSUM_OBJECTID
:
718 printf("EXTENT_CSUM");
720 case BTRFS_FREE_SPACE_OBJECTID
:
721 printf("FREE_SPACE");
723 case BTRFS_FREE_INO_OBJECTID
:
726 case BTRFS_QUOTA_TREE_OBJECTID
:
727 printf("QUOTA_TREE");
729 case BTRFS_UUID_TREE_OBJECTID
:
732 case BTRFS_MULTIPLE_OBJECTIDS
:
738 case BTRFS_FIRST_CHUNK_TREE_OBJECTID
:
739 if (type
== BTRFS_CHUNK_ITEM_KEY
) {
740 printf("FIRST_CHUNK_TREE");
745 printf("%llu", (unsigned long long)objectid
);
749 void btrfs_print_key(struct btrfs_disk_key
*disk_key
)
751 u64 objectid
= btrfs_disk_key_objectid(disk_key
);
752 u8 type
= btrfs_disk_key_type(disk_key
);
753 u64 offset
= btrfs_disk_key_offset(disk_key
);
756 print_objectid(objectid
, type
);
758 print_key_type(objectid
, type
);
760 case BTRFS_QGROUP_RELATION_KEY
:
761 case BTRFS_QGROUP_INFO_KEY
:
762 case BTRFS_QGROUP_LIMIT_KEY
:
763 printf(" %llu/%llu)", btrfs_qgroup_level(offset
),
764 btrfs_qgroup_subvid(offset
));
766 case BTRFS_UUID_KEY_SUBVOL
:
767 case BTRFS_UUID_KEY_RECEIVED_SUBVOL
:
768 printf(" 0x%016llx)", (unsigned long long)offset
);
771 if (offset
== (u64
)-1)
774 printf(" %llu)", (unsigned long long)offset
);
779 static void print_uuid_item(struct extent_buffer
*l
, unsigned long offset
,
782 if (item_size
& (sizeof(u64
) - 1)) {
783 printf("btrfs: uuid item with illegal size %lu!\n",
784 (unsigned long)item_size
);
790 read_extent_buffer(l
, &subvol_id
, offset
, sizeof(u64
));
791 printf("\t\tsubvol_id %llu\n",
792 (unsigned long long)le64_to_cpu(subvol_id
));
793 item_size
-= sizeof(u64
);
794 offset
+= sizeof(u64
);
798 void btrfs_print_leaf(struct btrfs_root
*root
, struct extent_buffer
*l
)
802 struct btrfs_item
*item
;
803 struct btrfs_dir_item
*di
;
804 struct btrfs_inode_item
*ii
;
805 struct btrfs_file_extent_item
*fi
;
806 struct btrfs_block_group_item
*bi
;
807 struct btrfs_extent_data_ref
*dref
;
808 struct btrfs_shared_data_ref
*sref
;
809 struct btrfs_inode_ref
*iref
;
810 struct btrfs_inode_extref
*iref2
;
811 struct btrfs_dev_extent
*dev_extent
;
812 struct btrfs_disk_key disk_key
;
813 struct btrfs_block_group_item bg_item
;
814 struct btrfs_dir_log_item
*dlog
;
815 struct btrfs_qgroup_info_item
*qg_info
;
816 struct btrfs_qgroup_limit_item
*qg_limit
;
817 struct btrfs_qgroup_status_item
*qg_status
;
818 u32 nr
= btrfs_header_nritems(l
);
823 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
824 (unsigned long long)btrfs_header_bytenr(l
), nr
,
825 btrfs_leaf_free_space(root
, l
),
826 (unsigned long long)btrfs_header_generation(l
),
827 (unsigned long long)btrfs_header_owner(l
));
830 for (i
= 0 ; i
< nr
; i
++) {
831 item
= btrfs_item_nr(i
);
832 btrfs_item_key(l
, &disk_key
, i
);
833 objectid
= btrfs_disk_key_objectid(&disk_key
);
834 type
= btrfs_disk_key_type(&disk_key
);
835 printf("\titem %d ", i
);
836 btrfs_print_key(&disk_key
);
837 printf(" itemoff %d itemsize %d\n",
838 btrfs_item_offset(l
, item
),
839 btrfs_item_size(l
, item
));
841 if (type
== 0 && objectid
== BTRFS_FREE_SPACE_OBJECTID
)
842 print_free_space_header(l
, i
);
845 case BTRFS_INODE_ITEM_KEY
:
846 ii
= btrfs_item_ptr(l
, i
, struct btrfs_inode_item
);
847 printf("\t\tinode generation %llu transid %llu size %llu nbytes %llu\n"
848 "\t\tblock group %llu mode %o links %u uid %u gid %u\n"
849 "\t\trdev %llu flags 0x%llx\n",
850 (unsigned long long)btrfs_inode_generation(l
, ii
),
851 (unsigned long long)btrfs_inode_transid(l
, ii
),
852 (unsigned long long)btrfs_inode_size(l
, ii
),
853 (unsigned long long)btrfs_inode_nbytes(l
, ii
),
854 (unsigned long long)btrfs_inode_block_group(l
,ii
),
855 btrfs_inode_mode(l
, ii
),
856 btrfs_inode_nlink(l
, ii
),
857 btrfs_inode_uid(l
, ii
),
858 btrfs_inode_gid(l
, ii
),
859 (unsigned long long)btrfs_inode_rdev(l
,ii
),
860 (unsigned long long)btrfs_inode_flags(l
,ii
));
862 case BTRFS_INODE_REF_KEY
:
863 iref
= btrfs_item_ptr(l
, i
, struct btrfs_inode_ref
);
864 print_inode_ref_item(l
, item
, iref
);
866 case BTRFS_INODE_EXTREF_KEY
:
867 iref2
= btrfs_item_ptr(l
, i
, struct btrfs_inode_extref
);
868 print_inode_extref_item(l
, item
, iref2
);
870 case BTRFS_DIR_ITEM_KEY
:
871 case BTRFS_DIR_INDEX_KEY
:
872 case BTRFS_XATTR_ITEM_KEY
:
873 di
= btrfs_item_ptr(l
, i
, struct btrfs_dir_item
);
874 print_dir_item(l
, item
, di
);
876 case BTRFS_DIR_LOG_INDEX_KEY
:
877 case BTRFS_DIR_LOG_ITEM_KEY
:
878 dlog
= btrfs_item_ptr(l
, i
, struct btrfs_dir_log_item
);
879 printf("\t\tdir log end %Lu\n",
880 (unsigned long long)btrfs_dir_log_end(l
, dlog
));
882 case BTRFS_ORPHAN_ITEM_KEY
:
883 printf("\t\torphan item\n");
885 case BTRFS_ROOT_ITEM_KEY
:
888 case BTRFS_ROOT_REF_KEY
:
889 print_root_ref(l
, i
, "ref");
891 case BTRFS_ROOT_BACKREF_KEY
:
892 print_root_ref(l
, i
, "backref");
894 case BTRFS_EXTENT_ITEM_KEY
:
895 print_extent_item(l
, i
, 0);
897 case BTRFS_METADATA_ITEM_KEY
:
898 print_extent_item(l
, i
, 1);
900 case BTRFS_TREE_BLOCK_REF_KEY
:
901 printf("\t\ttree block backref\n");
903 case BTRFS_SHARED_BLOCK_REF_KEY
:
904 printf("\t\tshared block backref\n");
906 case BTRFS_EXTENT_DATA_REF_KEY
:
907 dref
= btrfs_item_ptr(l
, i
, struct btrfs_extent_data_ref
);
908 printf("\t\textent data backref root %llu "
909 "objectid %llu offset %llu count %u\n",
910 (unsigned long long)btrfs_extent_data_ref_root(l
, dref
),
911 (unsigned long long)btrfs_extent_data_ref_objectid(l
, dref
),
912 (unsigned long long)btrfs_extent_data_ref_offset(l
, dref
),
913 btrfs_extent_data_ref_count(l
, dref
));
915 case BTRFS_SHARED_DATA_REF_KEY
:
916 sref
= btrfs_item_ptr(l
, i
, struct btrfs_shared_data_ref
);
917 printf("\t\tshared data backref count %u\n",
918 btrfs_shared_data_ref_count(l
, sref
));
920 case BTRFS_EXTENT_REF_V0_KEY
:
921 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
922 print_extent_ref_v0(l
, i
);
927 case BTRFS_CSUM_ITEM_KEY
:
928 printf("\t\tcsum item\n");
930 case BTRFS_EXTENT_CSUM_KEY
:
931 printf("\t\textent csum item\n");
933 case BTRFS_EXTENT_DATA_KEY
:
934 fi
= btrfs_item_ptr(l
, i
,
935 struct btrfs_file_extent_item
);
936 print_file_extent_item(l
, item
, i
, fi
);
938 case BTRFS_BLOCK_GROUP_ITEM_KEY
:
939 bi
= btrfs_item_ptr(l
, i
,
940 struct btrfs_block_group_item
);
941 read_extent_buffer(l
, &bg_item
, (unsigned long)bi
,
943 memset(flags_str
, 0, sizeof(flags_str
));
944 bg_flags_to_str(btrfs_block_group_flags(&bg_item
),
946 printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
947 (unsigned long long)btrfs_block_group_used(&bg_item
),
948 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item
),
951 case BTRFS_CHUNK_ITEM_KEY
:
952 print_chunk(l
, btrfs_item_ptr(l
, i
, struct btrfs_chunk
));
954 case BTRFS_DEV_ITEM_KEY
:
955 print_dev_item(l
, btrfs_item_ptr(l
, i
,
956 struct btrfs_dev_item
));
958 case BTRFS_DEV_EXTENT_KEY
:
959 dev_extent
= btrfs_item_ptr(l
, i
,
960 struct btrfs_dev_extent
);
961 printf("\t\tdev extent chunk_tree %llu\n"
962 "\t\tchunk objectid %llu chunk offset %llu "
965 btrfs_dev_extent_chunk_tree(l
, dev_extent
),
967 btrfs_dev_extent_chunk_objectid(l
, dev_extent
),
969 btrfs_dev_extent_chunk_offset(l
, dev_extent
),
971 btrfs_dev_extent_length(l
, dev_extent
));
973 case BTRFS_QGROUP_STATUS_KEY
:
974 qg_status
= btrfs_item_ptr(l
, i
,
975 struct btrfs_qgroup_status_item
);
976 memset(flags_str
, 0, sizeof(flags_str
));
977 qgroup_flags_to_str(btrfs_qgroup_status_flags(l
, qg_status
),
979 printf("\t\tversion %llu generation %llu flags %s "
982 btrfs_qgroup_status_version(l
, qg_status
),
984 btrfs_qgroup_status_generation(l
, qg_status
),
987 btrfs_qgroup_status_scan(l
, qg_status
));
989 case BTRFS_QGROUP_RELATION_KEY
:
991 case BTRFS_QGROUP_INFO_KEY
:
992 qg_info
= btrfs_item_ptr(l
, i
,
993 struct btrfs_qgroup_info_item
);
994 printf("\t\tgeneration %llu\n"
995 "\t\treferenced %llu referenced compressed %llu\n"
996 "\t\texclusive %llu exclusive compressed %llu\n",
998 btrfs_qgroup_info_generation(l
, qg_info
),
1000 btrfs_qgroup_info_referenced(l
, qg_info
),
1001 (unsigned long long)
1002 btrfs_qgroup_info_referenced_compressed(l
,
1004 (unsigned long long)
1005 btrfs_qgroup_info_exclusive(l
, qg_info
),
1006 (unsigned long long)
1007 btrfs_qgroup_info_exclusive_compressed(l
,
1010 case BTRFS_QGROUP_LIMIT_KEY
:
1011 qg_limit
= btrfs_item_ptr(l
, i
,
1012 struct btrfs_qgroup_limit_item
);
1013 printf("\t\tflags %llx\n"
1014 "\t\tmax referenced %lld max exclusive %lld\n"
1015 "\t\trsv referenced %lld rsv exclusive %lld\n",
1016 (unsigned long long)
1017 btrfs_qgroup_limit_flags(l
, qg_limit
),
1019 btrfs_qgroup_limit_max_referenced(l
, qg_limit
),
1021 btrfs_qgroup_limit_max_exclusive(l
, qg_limit
),
1023 btrfs_qgroup_limit_rsv_referenced(l
, qg_limit
),
1025 btrfs_qgroup_limit_rsv_exclusive(l
, qg_limit
));
1027 case BTRFS_UUID_KEY_SUBVOL
:
1028 case BTRFS_UUID_KEY_RECEIVED_SUBVOL
:
1029 print_uuid_item(l
, btrfs_item_ptr_offset(l
, i
),
1030 btrfs_item_size_nr(l
, i
));
1032 case BTRFS_STRING_ITEM_KEY
:
1033 /* dirty, but it's simple */
1034 str
= l
->data
+ btrfs_item_ptr_offset(l
, i
);
1035 printf("\t\titem data %.*s\n", btrfs_item_size(l
, item
), str
);
1037 case BTRFS_DEV_STATS_KEY
:
1038 printf("\t\tdevice stats\n");
1045 void btrfs_print_tree(struct btrfs_root
*root
, struct extent_buffer
*eb
, int follow
)
1050 struct btrfs_disk_key disk_key
;
1051 struct btrfs_key key
;
1055 nr
= btrfs_header_nritems(eb
);
1056 if (btrfs_is_leaf(eb
)) {
1057 btrfs_print_leaf(root
, eb
);
1060 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
1061 (unsigned long long)eb
->start
,
1062 btrfs_header_level(eb
), nr
,
1063 (u32
)BTRFS_NODEPTRS_PER_BLOCK(root
) - nr
,
1064 (unsigned long long)btrfs_header_generation(eb
),
1065 (unsigned long long)btrfs_header_owner(eb
));
1068 size
= btrfs_level_size(root
, btrfs_header_level(eb
) - 1);
1069 for (i
= 0; i
< nr
; i
++) {
1070 u64 blocknr
= btrfs_node_blockptr(eb
, i
);
1071 btrfs_node_key(eb
, &disk_key
, i
);
1072 btrfs_disk_key_to_cpu(&key
, &disk_key
);
1074 btrfs_print_key(&disk_key
);
1075 printf(" block %llu (%llu) gen %llu\n",
1076 (unsigned long long)blocknr
,
1077 (unsigned long long)blocknr
/ size
,
1078 (unsigned long long)btrfs_node_ptr_generation(eb
, i
));
1084 for (i
= 0; i
< nr
; i
++) {
1085 struct extent_buffer
*next
= read_tree_block(root
,
1086 btrfs_node_blockptr(eb
, i
),
1088 btrfs_node_ptr_generation(eb
, i
));
1089 if (!extent_buffer_uptodate(next
)) {
1090 fprintf(stderr
, "failed to read %llu in tree %llu\n",
1091 (unsigned long long)btrfs_node_blockptr(eb
, i
),
1092 (unsigned long long)btrfs_header_owner(eb
));
1095 if (btrfs_is_leaf(next
) &&
1096 btrfs_header_level(eb
) != 1)
1098 if (btrfs_header_level(next
) !=
1099 btrfs_header_level(eb
) - 1)
1101 btrfs_print_tree(root
, next
, 1);
1102 free_extent_buffer(next
);