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"
29 static void print_dir_item_type(struct extent_buffer *eb,
30 struct btrfs_dir_item *di)
32 u8 type = btrfs_dir_type(eb, di);
35 case BTRFS_FT_REG_FILE:
53 case BTRFS_FT_SYMLINK:
64 static int print_dir_item(struct extent_buffer *eb, struct btrfs_item *item,
65 struct btrfs_dir_item *di)
72 char namebuf[BTRFS_NAME_LEN];
73 struct btrfs_disk_key location;
75 total = btrfs_item_size(eb, item);
77 btrfs_dir_item_key(eb, di, &location);
78 printf("\t\tlocation ");
79 btrfs_print_key(&location);
81 print_dir_item_type(eb, di);
83 name_len = btrfs_dir_name_len(eb, di);
84 data_len = btrfs_dir_data_len(eb, di);
85 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
86 read_extent_buffer(eb, namebuf, (unsigned long)(di + 1), len);
87 printf("\t\tnamelen %u datalen %u name: %.*s\n",
88 name_len, data_len, len, namebuf);
90 len = (data_len <= sizeof(namebuf))? data_len: sizeof(namebuf);
91 read_extent_buffer(eb, namebuf,
92 (unsigned long)(di + 1) + name_len, len);
93 printf("\t\tdata %.*s\n", len, namebuf);
95 len = sizeof(*di) + name_len + data_len;
96 di = (struct btrfs_dir_item *)((char *)di + len);
102 static int print_inode_extref_item(struct extent_buffer *eb,
103 struct btrfs_item *item,
104 struct btrfs_inode_extref *extref)
112 char namebuf[BTRFS_NAME_LEN];
114 total = btrfs_item_size(eb, item);
116 while (cur < total) {
117 index = btrfs_inode_extref_index(eb, extref);
118 name_len = btrfs_inode_extref_name_len(eb, extref);
119 parent_objid = btrfs_inode_extref_parent(eb, extref);
121 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
123 read_extent_buffer(eb, namebuf, (unsigned long)(extref->name), len);
125 printf("\t\tinode extref index %llu parent %llu namelen %u "
127 (unsigned long long)index,
128 (unsigned long long)parent_objid,
129 name_len, len, namebuf);
131 len = sizeof(*extref) + name_len;
132 extref = (struct btrfs_inode_extref *)((char *)extref + len);
138 static int print_inode_ref_item(struct extent_buffer *eb, struct btrfs_item *item,
139 struct btrfs_inode_ref *ref)
146 char namebuf[BTRFS_NAME_LEN];
147 total = btrfs_item_size(eb, item);
149 name_len = btrfs_inode_ref_name_len(eb, ref);
150 index = btrfs_inode_ref_index(eb, ref);
151 len = (name_len <= sizeof(namebuf))? name_len: sizeof(namebuf);
152 read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len);
153 printf("\t\tinode ref index %llu namelen %u name: %.*s\n",
154 (unsigned long long)index, name_len, len, namebuf);
155 len = sizeof(*ref) + name_len;
156 ref = (struct btrfs_inode_ref *)((char *)ref + len);
162 static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
164 int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
166 printf("\t\tchunk length %llu owner %llu type %llu num_stripes %d\n",
167 (unsigned long long)btrfs_chunk_length(eb, chunk),
168 (unsigned long long)btrfs_chunk_owner(eb, chunk),
169 (unsigned long long)btrfs_chunk_type(eb, chunk),
171 for (i = 0 ; i < num_stripes ; i++) {
172 printf("\t\t\tstripe %d devid %llu offset %llu\n", i,
173 (unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i),
174 (unsigned long long)btrfs_stripe_offset_nr(eb, chunk, i));
178 static void print_dev_item(struct extent_buffer *eb,
179 struct btrfs_dev_item *dev_item)
181 printf("\t\tdev item devid %llu "
182 "total_bytes %llu bytes used %Lu\n",
183 (unsigned long long)btrfs_device_id(eb, dev_item),
184 (unsigned long long)btrfs_device_total_bytes(eb, dev_item),
185 (unsigned long long)btrfs_device_bytes_used(eb, dev_item));
188 static void print_uuids(struct extent_buffer *eb)
192 u8 disk_uuid[BTRFS_UUID_SIZE];
194 read_extent_buffer(eb, disk_uuid, (unsigned long)btrfs_header_fsid(eb),
198 uuid_unparse(disk_uuid, fs_uuid);
200 read_extent_buffer(eb, disk_uuid,
201 (unsigned long)btrfs_header_chunk_tree_uuid(eb),
204 chunk_uuid[36] = '\0';
205 uuid_unparse(disk_uuid, chunk_uuid);
206 printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid);
209 static void print_file_extent_item(struct extent_buffer *eb,
210 struct btrfs_item *item,
211 struct btrfs_file_extent_item *fi)
213 int extent_type = btrfs_file_extent_type(eb, fi);
215 if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
216 printf("\t\tinline extent data size %u "
217 "ram %u compress %d\n",
218 btrfs_file_extent_inline_item_len(eb, item),
219 btrfs_file_extent_inline_len(eb, fi),
220 btrfs_file_extent_compression(eb, fi));
223 if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
224 printf("\t\tprealloc data disk byte %llu nr %llu\n",
225 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
226 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
227 printf("\t\tprealloc data offset %llu nr %llu\n",
228 (unsigned long long)btrfs_file_extent_offset(eb, fi),
229 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi));
232 printf("\t\textent data disk byte %llu nr %llu\n",
233 (unsigned long long)btrfs_file_extent_disk_bytenr(eb, fi),
234 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb, fi));
235 printf("\t\textent data offset %llu nr %llu ram %llu\n",
236 (unsigned long long)btrfs_file_extent_offset(eb, fi),
237 (unsigned long long)btrfs_file_extent_num_bytes(eb, fi),
238 (unsigned long long)btrfs_file_extent_ram_bytes(eb, fi));
239 printf("\t\textent compression %d\n",
240 btrfs_file_extent_compression(eb, fi));
243 static void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
245 struct btrfs_extent_item *ei;
246 struct btrfs_extent_inline_ref *iref;
247 struct btrfs_extent_data_ref *dref;
248 struct btrfs_shared_data_ref *sref;
249 struct btrfs_disk_key key;
253 u32 item_size = btrfs_item_size_nr(eb, slot);
257 if (item_size < sizeof(*ei)) {
258 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
259 struct btrfs_extent_item_v0 *ei0;
260 BUG_ON(item_size != sizeof(*ei0));
261 ei0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_item_v0);
262 printf("\t\textent refs %u\n",
263 btrfs_extent_refs_v0(eb, ei0));
270 ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
271 flags = btrfs_extent_flags(eb, ei);
273 printf("\t\textent refs %llu gen %llu flags %llu\n",
274 (unsigned long long)btrfs_extent_refs(eb, ei),
275 (unsigned long long)btrfs_extent_generation(eb, ei),
276 (unsigned long long)flags);
278 if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !metadata) {
279 struct btrfs_tree_block_info *info;
280 info = (struct btrfs_tree_block_info *)(ei + 1);
281 btrfs_tree_block_key(eb, info, &key);
282 printf("\t\ttree block ");
283 btrfs_print_key(&key);
284 printf(" level %d\n", btrfs_tree_block_level(eb, info));
285 iref = (struct btrfs_extent_inline_ref *)(info + 1);
286 } else if (metadata) {
287 struct btrfs_key tmp;
289 btrfs_item_key_to_cpu(eb, &tmp, slot);
290 printf("\t\ttree block skinny level %d\n", (int)tmp.offset);
291 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
293 iref = (struct btrfs_extent_inline_ref *)(ei + 1);
296 ptr = (unsigned long)iref;
297 end = (unsigned long)ei + item_size;
299 iref = (struct btrfs_extent_inline_ref *)ptr;
300 type = btrfs_extent_inline_ref_type(eb, iref);
301 offset = btrfs_extent_inline_ref_offset(eb, iref);
303 case BTRFS_TREE_BLOCK_REF_KEY:
304 printf("\t\ttree block backref root %llu\n",
305 (unsigned long long)offset);
307 case BTRFS_SHARED_BLOCK_REF_KEY:
308 printf("\t\tshared block backref parent %llu\n",
309 (unsigned long long)offset);
311 case BTRFS_EXTENT_DATA_REF_KEY:
312 dref = (struct btrfs_extent_data_ref *)(&iref->offset);
313 printf("\t\textent data backref root %llu "
314 "objectid %llu offset %llu count %u\n",
315 (unsigned long long)btrfs_extent_data_ref_root(eb, dref),
316 (unsigned long long)btrfs_extent_data_ref_objectid(eb, dref),
317 (unsigned long long)btrfs_extent_data_ref_offset(eb, dref),
318 btrfs_extent_data_ref_count(eb, dref));
320 case BTRFS_SHARED_DATA_REF_KEY:
321 sref = (struct btrfs_shared_data_ref *)(iref + 1);
322 printf("\t\tshared data backref parent %llu count %u\n",
323 (unsigned long long)offset,
324 btrfs_shared_data_ref_count(eb, sref));
329 ptr += btrfs_extent_inline_ref_size(type);
334 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
335 static void print_extent_ref_v0(struct extent_buffer *eb, int slot)
337 struct btrfs_extent_ref_v0 *ref0;
339 ref0 = btrfs_item_ptr(eb, slot, struct btrfs_extent_ref_v0);
340 printf("\t\textent back ref root %llu gen %llu "
341 "owner %llu num_refs %lu\n",
342 (unsigned long long)btrfs_ref_root_v0(eb, ref0),
343 (unsigned long long)btrfs_ref_generation_v0(eb, ref0),
344 (unsigned long long)btrfs_ref_objectid_v0(eb, ref0),
345 (unsigned long)btrfs_ref_count_v0(eb, ref0));
349 static void print_root_ref(struct extent_buffer *leaf, int slot, char *tag)
351 struct btrfs_root_ref *ref;
352 char namebuf[BTRFS_NAME_LEN];
355 ref = btrfs_item_ptr(leaf, slot, struct btrfs_root_ref);
356 namelen = btrfs_root_ref_name_len(leaf, ref);
357 read_extent_buffer(leaf, namebuf, (unsigned long)(ref + 1), namelen);
358 printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag,
359 (unsigned long long)btrfs_root_ref_dirid(leaf, ref),
360 (unsigned long long)btrfs_root_ref_sequence(leaf, ref),
364 static int count_bytes(void *buf, int len, char b)
368 for (i = 0; i < len; i++) {
369 if (((char*)buf)[i] == b)
375 static void print_root(struct extent_buffer *leaf, int slot)
377 struct btrfs_root_item *ri;
378 struct btrfs_root_item root_item;
382 ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
383 len = btrfs_item_size_nr(leaf, slot);
385 memset(&root_item, 0, sizeof(root_item));
386 read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);
388 printf("\t\troot data bytenr %llu level %d dirid %llu refs %u gen %llu\n",
389 (unsigned long long)btrfs_root_bytenr(&root_item),
390 btrfs_root_level(&root_item),
391 (unsigned long long)btrfs_root_dirid(&root_item),
392 btrfs_root_refs(&root_item),
393 (unsigned long long)btrfs_root_generation(&root_item));
395 if (root_item.generation == root_item.generation_v2) {
396 uuid_unparse(root_item.uuid, uuid_str);
397 printf("\t\tuuid %s\n", uuid_str);
398 if (count_bytes(root_item.parent_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
399 uuid_unparse(root_item.parent_uuid, uuid_str);
400 printf("\t\tparent_uuid %s\n", uuid_str);
402 if (count_bytes(root_item.received_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
403 uuid_unparse(root_item.received_uuid, uuid_str);
404 printf("\t\treceived_uuid %s\n", uuid_str);
406 if (root_item.ctransid) {
407 printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
408 btrfs_root_ctransid(&root_item),
409 btrfs_root_otransid(&root_item),
410 btrfs_root_stransid(&root_item),
411 btrfs_root_rtransid(&root_item));
414 if (btrfs_root_refs(&root_item) == 0) {
415 struct btrfs_key drop_key;
416 btrfs_disk_key_to_cpu(&drop_key,
417 &root_item.drop_progress);
419 btrfs_print_key(&root_item.drop_progress);
420 printf(" level %d\n", root_item.drop_level);
424 static void print_free_space_header(struct extent_buffer *leaf, int slot)
426 struct btrfs_free_space_header *header;
427 struct btrfs_disk_key location;
429 header = btrfs_item_ptr(leaf, slot, struct btrfs_free_space_header);
430 btrfs_free_space_key(leaf, header, &location);
431 printf("\t\tlocation ");
432 btrfs_print_key(&location);
434 printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
435 (unsigned long long)btrfs_free_space_generation(leaf, header),
436 (unsigned long long)btrfs_free_space_entries(leaf, header),
437 (unsigned long long)btrfs_free_space_bitmaps(leaf, header));
440 static void print_key_type(u64 objectid, u8 type)
442 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
448 case BTRFS_INODE_ITEM_KEY:
449 printf("INODE_ITEM");
451 case BTRFS_INODE_REF_KEY:
454 case BTRFS_INODE_EXTREF_KEY:
455 printf("INODE_EXTREF");
457 case BTRFS_DIR_ITEM_KEY:
460 case BTRFS_DIR_INDEX_KEY:
463 case BTRFS_DIR_LOG_ITEM_KEY:
464 printf("DIR_LOG_ITEM");
466 case BTRFS_DIR_LOG_INDEX_KEY:
467 printf("DIR_LOG_INDEX");
469 case BTRFS_XATTR_ITEM_KEY:
470 printf("XATTR_ITEM");
472 case BTRFS_ORPHAN_ITEM_KEY:
473 printf("ORPHAN_ITEM");
475 case BTRFS_ROOT_ITEM_KEY:
478 case BTRFS_ROOT_REF_KEY:
481 case BTRFS_ROOT_BACKREF_KEY:
482 printf("ROOT_BACKREF");
484 case BTRFS_EXTENT_ITEM_KEY:
485 printf("EXTENT_ITEM");
487 case BTRFS_METADATA_ITEM_KEY:
488 printf("METADATA_ITEM");
490 case BTRFS_TREE_BLOCK_REF_KEY:
491 printf("TREE_BLOCK_REF");
493 case BTRFS_SHARED_BLOCK_REF_KEY:
494 printf("SHARED_BLOCK_REF");
496 case BTRFS_EXTENT_DATA_REF_KEY:
497 printf("EXTENT_DATA_REF");
499 case BTRFS_SHARED_DATA_REF_KEY:
500 printf("SHARED_DATA_REF");
502 case BTRFS_EXTENT_REF_V0_KEY:
503 printf("EXTENT_REF_V0");
505 case BTRFS_CSUM_ITEM_KEY:
508 case BTRFS_EXTENT_CSUM_KEY:
509 printf("EXTENT_CSUM");
511 case BTRFS_EXTENT_DATA_KEY:
512 printf("EXTENT_DATA");
514 case BTRFS_BLOCK_GROUP_ITEM_KEY:
515 printf("BLOCK_GROUP_ITEM");
517 case BTRFS_CHUNK_ITEM_KEY:
518 printf("CHUNK_ITEM");
520 case BTRFS_DEV_ITEM_KEY:
523 case BTRFS_DEV_EXTENT_KEY:
524 printf("DEV_EXTENT");
526 case BTRFS_BALANCE_ITEM_KEY:
527 printf("BALANCE_ITEM");
529 case BTRFS_DEV_REPLACE_KEY:
530 printf("DEV_REPLACE_ITEM");
532 case BTRFS_STRING_ITEM_KEY:
533 printf("STRING_ITEM");
535 case BTRFS_QGROUP_STATUS_KEY:
536 printf("BTRFS_STATUS_KEY");
538 case BTRFS_QGROUP_RELATION_KEY:
539 printf("BTRFS_QGROUP_RELATION_KEY");
541 case BTRFS_QGROUP_INFO_KEY:
542 printf("BTRFS_QGROUP_INFO_KEY");
544 case BTRFS_QGROUP_LIMIT_KEY:
545 printf("BTRFS_QGROUP_LIMIT_KEY");
547 case BTRFS_DEV_STATS_KEY:
548 printf("DEV_STATS_ITEM");
550 case BTRFS_UUID_KEY_SUBVOL:
551 printf("BTRFS_UUID_KEY_SUBVOL");
553 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
554 printf("BTRFS_UUID_KEY_RECEIVED_SUBVOL");
557 printf("UNKNOWN.%d", type);
561 static void print_objectid(u64 objectid, u8 type)
564 case BTRFS_DEV_EXTENT_KEY:
565 printf("%llu", (unsigned long long)objectid); /* device id */
567 case BTRFS_QGROUP_RELATION_KEY:
568 printf("%llu/%llu", objectid >> 48,
569 objectid & ((1ll << 48) - 1));
571 case BTRFS_UUID_KEY_SUBVOL:
572 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
573 printf("0x%016llx", (unsigned long long)objectid);
578 case BTRFS_ROOT_TREE_OBJECTID:
579 if (type == BTRFS_DEV_ITEM_KEY)
584 case BTRFS_EXTENT_TREE_OBJECTID:
585 printf("EXTENT_TREE");
587 case BTRFS_CHUNK_TREE_OBJECTID:
588 printf("CHUNK_TREE");
590 case BTRFS_DEV_TREE_OBJECTID:
593 case BTRFS_FS_TREE_OBJECTID:
596 case BTRFS_ROOT_TREE_DIR_OBJECTID:
597 printf("ROOT_TREE_DIR");
599 case BTRFS_CSUM_TREE_OBJECTID:
602 case BTRFS_BALANCE_OBJECTID:
605 case BTRFS_ORPHAN_OBJECTID:
608 case BTRFS_TREE_LOG_OBJECTID:
611 case BTRFS_TREE_LOG_FIXUP_OBJECTID:
614 case BTRFS_TREE_RELOC_OBJECTID:
615 printf("TREE_RELOC");
617 case BTRFS_DATA_RELOC_TREE_OBJECTID:
618 printf("DATA_RELOC_TREE");
620 case BTRFS_EXTENT_CSUM_OBJECTID:
621 printf("EXTENT_CSUM");
623 case BTRFS_FREE_SPACE_OBJECTID:
624 printf("FREE_SPACE");
626 case BTRFS_FREE_INO_OBJECTID:
629 case BTRFS_QUOTA_TREE_OBJECTID:
630 printf("QUOTA_TREE");
632 case BTRFS_UUID_TREE_OBJECTID:
635 case BTRFS_MULTIPLE_OBJECTIDS:
641 case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
642 if (type == BTRFS_CHUNK_ITEM_KEY) {
643 printf("FIRST_CHUNK_TREE");
648 printf("%llu", (unsigned long long)objectid);
652 void btrfs_print_key(struct btrfs_disk_key *disk_key)
654 u64 objectid = btrfs_disk_key_objectid(disk_key);
655 u8 type = btrfs_disk_key_type(disk_key);
656 u64 offset = btrfs_disk_key_offset(disk_key);
659 print_objectid(objectid, type);
661 print_key_type(objectid, type);
663 case BTRFS_QGROUP_RELATION_KEY:
664 case BTRFS_QGROUP_INFO_KEY:
665 case BTRFS_QGROUP_LIMIT_KEY:
666 printf(" %llu/%llu)", (unsigned long long)(offset >> 48),
667 (unsigned long long)(offset & ((1ll << 48) - 1)));
669 case BTRFS_UUID_KEY_SUBVOL:
670 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
671 printf(" 0x%016llx)", (unsigned long long)offset);
674 if (offset == (u64)-1)
677 printf(" %llu)", (unsigned long long)offset);
682 static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
685 if (item_size & (sizeof(u64) - 1)) {
686 printf("btrfs: uuid item with illegal size %lu!\n",
687 (unsigned long)item_size);
693 read_extent_buffer(l, &subvol_id, offset, sizeof(u64));
694 printf("\t\tsubvol_id %llu\n",
695 (unsigned long long)le64_to_cpu(subvol_id));
696 item_size -= sizeof(u64);
697 offset += sizeof(u64);
701 void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
705 struct btrfs_item *item;
706 struct btrfs_dir_item *di;
707 struct btrfs_inode_item *ii;
708 struct btrfs_file_extent_item *fi;
709 struct btrfs_block_group_item *bi;
710 struct btrfs_extent_data_ref *dref;
711 struct btrfs_shared_data_ref *sref;
712 struct btrfs_inode_ref *iref;
713 struct btrfs_inode_extref *iref2;
714 struct btrfs_dev_extent *dev_extent;
715 struct btrfs_disk_key disk_key;
716 struct btrfs_block_group_item bg_item;
717 struct btrfs_dir_log_item *dlog;
718 struct btrfs_qgroup_info_item *qg_info;
719 struct btrfs_qgroup_limit_item *qg_limit;
720 struct btrfs_qgroup_status_item *qg_status;
721 u32 nr = btrfs_header_nritems(l);
725 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
726 (unsigned long long)btrfs_header_bytenr(l), nr,
727 btrfs_leaf_free_space(root, l),
728 (unsigned long long)btrfs_header_generation(l),
729 (unsigned long long)btrfs_header_owner(l));
732 for (i = 0 ; i < nr ; i++) {
733 item = btrfs_item_nr(l, i);
734 btrfs_item_key(l, &disk_key, i);
735 objectid = btrfs_disk_key_objectid(&disk_key);
736 type = btrfs_disk_key_type(&disk_key);
737 printf("\titem %d ", i);
738 btrfs_print_key(&disk_key);
739 printf(" itemoff %d itemsize %d\n",
740 btrfs_item_offset(l, item),
741 btrfs_item_size(l, item));
743 if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID)
744 print_free_space_header(l, i);
747 case BTRFS_INODE_ITEM_KEY:
748 ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
749 printf("\t\tinode generation %llu transid %llu size %llu block group %llu mode %o links %u\n",
750 (unsigned long long)btrfs_inode_generation(l, ii),
751 (unsigned long long)btrfs_inode_transid(l, ii),
752 (unsigned long long)btrfs_inode_size(l, ii),
753 (unsigned long long)btrfs_inode_block_group(l,ii),
754 btrfs_inode_mode(l, ii),
755 btrfs_inode_nlink(l, ii));
757 case BTRFS_INODE_REF_KEY:
758 iref = btrfs_item_ptr(l, i, struct btrfs_inode_ref);
759 print_inode_ref_item(l, item, iref);
761 case BTRFS_INODE_EXTREF_KEY:
762 iref2 = btrfs_item_ptr(l, i, struct btrfs_inode_extref);
763 print_inode_extref_item(l, item, iref2);
765 case BTRFS_DIR_ITEM_KEY:
766 case BTRFS_DIR_INDEX_KEY:
767 case BTRFS_XATTR_ITEM_KEY:
768 di = btrfs_item_ptr(l, i, struct btrfs_dir_item);
769 print_dir_item(l, item, di);
771 case BTRFS_DIR_LOG_INDEX_KEY:
772 case BTRFS_DIR_LOG_ITEM_KEY:
773 dlog = btrfs_item_ptr(l, i, struct btrfs_dir_log_item);
774 printf("\t\tdir log end %Lu\n",
775 (unsigned long long)btrfs_dir_log_end(l, dlog));
777 case BTRFS_ORPHAN_ITEM_KEY:
778 printf("\t\torphan item\n");
780 case BTRFS_ROOT_ITEM_KEY:
783 case BTRFS_ROOT_REF_KEY:
784 print_root_ref(l, i, "ref");
786 case BTRFS_ROOT_BACKREF_KEY:
787 print_root_ref(l, i, "backref");
789 case BTRFS_EXTENT_ITEM_KEY:
790 print_extent_item(l, i, 0);
792 case BTRFS_METADATA_ITEM_KEY:
793 print_extent_item(l, i, 1);
795 case BTRFS_TREE_BLOCK_REF_KEY:
796 printf("\t\ttree block backref\n");
798 case BTRFS_SHARED_BLOCK_REF_KEY:
799 printf("\t\tshared block backref\n");
801 case BTRFS_EXTENT_DATA_REF_KEY:
802 dref = btrfs_item_ptr(l, i, struct btrfs_extent_data_ref);
803 printf("\t\textent data backref root %llu "
804 "objectid %llu offset %llu count %u\n",
805 (unsigned long long)btrfs_extent_data_ref_root(l, dref),
806 (unsigned long long)btrfs_extent_data_ref_objectid(l, dref),
807 (unsigned long long)btrfs_extent_data_ref_offset(l, dref),
808 btrfs_extent_data_ref_count(l, dref));
810 case BTRFS_SHARED_DATA_REF_KEY:
811 sref = btrfs_item_ptr(l, i, struct btrfs_shared_data_ref);
812 printf("\t\tshared data backref count %u\n",
813 btrfs_shared_data_ref_count(l, sref));
815 case BTRFS_EXTENT_REF_V0_KEY:
816 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
817 print_extent_ref_v0(l, i);
822 case BTRFS_CSUM_ITEM_KEY:
823 printf("\t\tcsum item\n");
825 case BTRFS_EXTENT_CSUM_KEY:
826 printf("\t\textent csum item\n");
828 case BTRFS_EXTENT_DATA_KEY:
829 fi = btrfs_item_ptr(l, i,
830 struct btrfs_file_extent_item);
831 print_file_extent_item(l, item, fi);
833 case BTRFS_BLOCK_GROUP_ITEM_KEY:
834 bi = btrfs_item_ptr(l, i,
835 struct btrfs_block_group_item);
836 read_extent_buffer(l, &bg_item, (unsigned long)bi,
838 printf("\t\tblock group used %llu chunk_objectid %llu flags %llu\n",
839 (unsigned long long)btrfs_block_group_used(&bg_item),
840 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
841 (unsigned long long)btrfs_block_group_flags(&bg_item));
843 case BTRFS_CHUNK_ITEM_KEY:
844 print_chunk(l, btrfs_item_ptr(l, i, struct btrfs_chunk));
846 case BTRFS_DEV_ITEM_KEY:
847 print_dev_item(l, btrfs_item_ptr(l, i,
848 struct btrfs_dev_item));
850 case BTRFS_DEV_EXTENT_KEY:
851 dev_extent = btrfs_item_ptr(l, i,
852 struct btrfs_dev_extent);
853 printf("\t\tdev extent chunk_tree %llu\n"
854 "\t\tchunk objectid %llu chunk offset %llu "
857 btrfs_dev_extent_chunk_tree(l, dev_extent),
859 btrfs_dev_extent_chunk_objectid(l, dev_extent),
861 btrfs_dev_extent_chunk_offset(l, dev_extent),
863 btrfs_dev_extent_length(l, dev_extent));
865 case BTRFS_QGROUP_STATUS_KEY:
866 qg_status = btrfs_item_ptr(l, i,
867 struct btrfs_qgroup_status_item);
868 printf("\t\tversion %llu generation %llu flags %#llx "
871 btrfs_qgroup_status_version(l, qg_status),
873 btrfs_qgroup_status_generation(l, qg_status),
875 btrfs_qgroup_status_flags(l, qg_status),
877 btrfs_qgroup_status_scan(l, qg_status));
879 case BTRFS_QGROUP_RELATION_KEY:
881 case BTRFS_QGROUP_INFO_KEY:
882 qg_info = btrfs_item_ptr(l, i,
883 struct btrfs_qgroup_info_item);
884 printf("\t\tgeneration %llu\n"
885 "\t\treferenced %lld referenced compressed %lld\n"
886 "\t\texclusive %lld exclusive compressed %lld\n",
888 btrfs_qgroup_info_generation(l, qg_info),
890 btrfs_qgroup_info_referenced(l, qg_info),
892 btrfs_qgroup_info_referenced_compressed(l,
895 btrfs_qgroup_info_exclusive(l, qg_info),
897 btrfs_qgroup_info_exclusive_compressed(l,
900 case BTRFS_QGROUP_LIMIT_KEY:
901 qg_limit = btrfs_item_ptr(l, i,
902 struct btrfs_qgroup_limit_item);
903 printf("\t\tflags %llx\n"
904 "\t\tmax referenced %lld max exclusive %lld\n"
905 "\t\trsv referenced %lld rsv exclusive %lld\n",
907 btrfs_qgroup_limit_flags(l, qg_limit),
909 btrfs_qgroup_limit_max_referenced(l, qg_limit),
911 btrfs_qgroup_limit_max_exclusive(l, qg_limit),
913 btrfs_qgroup_limit_rsv_referenced(l, qg_limit),
915 btrfs_qgroup_limit_rsv_exclusive(l, qg_limit));
917 case BTRFS_UUID_KEY_SUBVOL:
918 case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
919 print_uuid_item(l, btrfs_item_ptr_offset(l, i),
920 btrfs_item_size_nr(l, i));
922 case BTRFS_STRING_ITEM_KEY:
923 /* dirty, but it's simple */
924 str = l->data + btrfs_item_ptr_offset(l, i);
925 printf("\t\titem data %.*s\n", btrfs_item_size(l, item), str);
927 case BTRFS_DEV_STATS_KEY:
928 printf("\t\tdevice stats\n");
935 void btrfs_print_tree(struct btrfs_root *root, struct extent_buffer *eb, int follow)
940 struct btrfs_disk_key disk_key;
941 struct btrfs_key key;
945 nr = btrfs_header_nritems(eb);
946 if (btrfs_is_leaf(eb)) {
947 btrfs_print_leaf(root, eb);
950 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
951 (unsigned long long)eb->start,
952 btrfs_header_level(eb), nr,
953 (u32)BTRFS_NODEPTRS_PER_BLOCK(root) - nr,
954 (unsigned long long)btrfs_header_generation(eb),
955 (unsigned long long)btrfs_header_owner(eb));
958 size = btrfs_level_size(root, btrfs_header_level(eb) - 1);
959 for (i = 0; i < nr; i++) {
960 u64 blocknr = btrfs_node_blockptr(eb, i);
961 btrfs_node_key(eb, &disk_key, i);
962 btrfs_disk_key_to_cpu(&key, &disk_key);
964 btrfs_print_key(&disk_key);
965 printf(" block %llu (%llu) gen %llu\n",
966 (unsigned long long)blocknr,
967 (unsigned long long)blocknr / size,
968 (unsigned long long)btrfs_node_ptr_generation(eb, i));
974 for (i = 0; i < nr; i++) {
975 struct extent_buffer *next = read_tree_block(root,
976 btrfs_node_blockptr(eb, i),
978 btrfs_node_ptr_generation(eb, i));
980 fprintf(stderr, "failed to read %llu in tree %llu\n",
981 (unsigned long long)btrfs_node_blockptr(eb, i),
982 (unsigned long long)btrfs_header_owner(eb));
985 if (btrfs_is_leaf(next) &&
986 btrfs_header_level(eb) != 1)
988 if (btrfs_header_level(next) !=
989 btrfs_header_level(eb) - 1)
991 btrfs_print_tree(root, next, 1);
992 free_extent_buffer(next);