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 static void print_chunk(struct extent_buffer
*eb
, struct btrfs_chunk
*chunk
)
165 int num_stripes
= btrfs_chunk_num_stripes(eb
, chunk
);
167 printf("\t\tchunk length %llu owner %llu type %llu num_stripes %d\n",
168 (unsigned long long)btrfs_chunk_length(eb
, chunk
),
169 (unsigned long long)btrfs_chunk_owner(eb
, chunk
),
170 (unsigned long long)btrfs_chunk_type(eb
, chunk
),
172 for (i
= 0 ; i
< num_stripes
; i
++) {
173 printf("\t\t\tstripe %d devid %llu offset %llu\n", i
,
174 (unsigned long long)btrfs_stripe_devid_nr(eb
, chunk
, i
),
175 (unsigned long long)btrfs_stripe_offset_nr(eb
, chunk
, i
));
179 static void print_dev_item(struct extent_buffer
*eb
,
180 struct btrfs_dev_item
*dev_item
)
182 printf("\t\tdev item devid %llu "
183 "total_bytes %llu bytes used %Lu\n",
184 (unsigned long long)btrfs_device_id(eb
, dev_item
),
185 (unsigned long long)btrfs_device_total_bytes(eb
, dev_item
),
186 (unsigned long long)btrfs_device_bytes_used(eb
, dev_item
));
189 static void print_uuids(struct extent_buffer
*eb
)
191 char fs_uuid
[BTRFS_UUID_UNPARSED_SIZE
];
192 char chunk_uuid
[BTRFS_UUID_UNPARSED_SIZE
];
193 u8 disk_uuid
[BTRFS_UUID_SIZE
];
195 read_extent_buffer(eb
, disk_uuid
, btrfs_header_fsid(),
198 fs_uuid
[BTRFS_UUID_UNPARSED_SIZE
- 1] = '\0';
199 uuid_unparse(disk_uuid
, fs_uuid
);
201 read_extent_buffer(eb
, disk_uuid
,
202 btrfs_header_chunk_tree_uuid(eb
),
205 chunk_uuid
[BTRFS_UUID_UNPARSED_SIZE
- 1] = '\0';
206 uuid_unparse(disk_uuid
, chunk_uuid
);
207 printf("fs uuid %s\nchunk uuid %s\n", fs_uuid
, chunk_uuid
);
210 static void print_file_extent_item(struct extent_buffer
*eb
,
211 struct btrfs_item
*item
,
213 struct btrfs_file_extent_item
*fi
)
215 int extent_type
= btrfs_file_extent_type(eb
, fi
);
217 if (extent_type
== BTRFS_FILE_EXTENT_INLINE
) {
218 printf("\t\tinline extent data size %u "
219 "ram %u compress %d\n",
220 btrfs_file_extent_inline_item_len(eb
, item
),
221 btrfs_file_extent_inline_len(eb
, slot
, fi
),
222 btrfs_file_extent_compression(eb
, fi
));
225 if (extent_type
== BTRFS_FILE_EXTENT_PREALLOC
) {
226 printf("\t\tprealloc data disk byte %llu nr %llu\n",
227 (unsigned long long)btrfs_file_extent_disk_bytenr(eb
, fi
),
228 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb
, fi
));
229 printf("\t\tprealloc data offset %llu nr %llu\n",
230 (unsigned long long)btrfs_file_extent_offset(eb
, fi
),
231 (unsigned long long)btrfs_file_extent_num_bytes(eb
, fi
));
234 printf("\t\textent data disk byte %llu nr %llu\n",
235 (unsigned long long)btrfs_file_extent_disk_bytenr(eb
, fi
),
236 (unsigned long long)btrfs_file_extent_disk_num_bytes(eb
, fi
));
237 printf("\t\textent data offset %llu nr %llu ram %llu\n",
238 (unsigned long long)btrfs_file_extent_offset(eb
, fi
),
239 (unsigned long long)btrfs_file_extent_num_bytes(eb
, fi
),
240 (unsigned long long)btrfs_file_extent_ram_bytes(eb
, fi
));
241 printf("\t\textent compression %d\n",
242 btrfs_file_extent_compression(eb
, fi
));
245 static void print_extent_item(struct extent_buffer
*eb
, int slot
, int metadata
)
247 struct btrfs_extent_item
*ei
;
248 struct btrfs_extent_inline_ref
*iref
;
249 struct btrfs_extent_data_ref
*dref
;
250 struct btrfs_shared_data_ref
*sref
;
251 struct btrfs_disk_key key
;
255 u32 item_size
= btrfs_item_size_nr(eb
, slot
);
259 if (item_size
< sizeof(*ei
)) {
260 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
261 struct btrfs_extent_item_v0
*ei0
;
262 BUG_ON(item_size
!= sizeof(*ei0
));
263 ei0
= btrfs_item_ptr(eb
, slot
, struct btrfs_extent_item_v0
);
264 printf("\t\textent refs %u\n",
265 btrfs_extent_refs_v0(eb
, ei0
));
272 ei
= btrfs_item_ptr(eb
, slot
, struct btrfs_extent_item
);
273 flags
= btrfs_extent_flags(eb
, ei
);
275 printf("\t\textent refs %llu gen %llu flags %llu\n",
276 (unsigned long long)btrfs_extent_refs(eb
, ei
),
277 (unsigned long long)btrfs_extent_generation(eb
, ei
),
278 (unsigned long long)flags
);
280 if (flags
& BTRFS_EXTENT_FLAG_TREE_BLOCK
&& !metadata
) {
281 struct btrfs_tree_block_info
*info
;
282 info
= (struct btrfs_tree_block_info
*)(ei
+ 1);
283 btrfs_tree_block_key(eb
, info
, &key
);
284 printf("\t\ttree block ");
285 btrfs_print_key(&key
);
286 printf(" level %d\n", btrfs_tree_block_level(eb
, info
));
287 iref
= (struct btrfs_extent_inline_ref
*)(info
+ 1);
288 } else if (metadata
) {
289 struct btrfs_key tmp
;
291 btrfs_item_key_to_cpu(eb
, &tmp
, slot
);
292 printf("\t\ttree block skinny level %d\n", (int)tmp
.offset
);
293 iref
= (struct btrfs_extent_inline_ref
*)(ei
+ 1);
295 iref
= (struct btrfs_extent_inline_ref
*)(ei
+ 1);
298 ptr
= (unsigned long)iref
;
299 end
= (unsigned long)ei
+ item_size
;
301 iref
= (struct btrfs_extent_inline_ref
*)ptr
;
302 type
= btrfs_extent_inline_ref_type(eb
, iref
);
303 offset
= btrfs_extent_inline_ref_offset(eb
, iref
);
305 case BTRFS_TREE_BLOCK_REF_KEY
:
306 printf("\t\ttree block backref root %llu\n",
307 (unsigned long long)offset
);
309 case BTRFS_SHARED_BLOCK_REF_KEY
:
310 printf("\t\tshared block backref parent %llu\n",
311 (unsigned long long)offset
);
313 case BTRFS_EXTENT_DATA_REF_KEY
:
314 dref
= (struct btrfs_extent_data_ref
*)(&iref
->offset
);
315 printf("\t\textent data backref root %llu "
316 "objectid %llu offset %llu count %u\n",
317 (unsigned long long)btrfs_extent_data_ref_root(eb
, dref
),
318 (unsigned long long)btrfs_extent_data_ref_objectid(eb
, dref
),
319 (unsigned long long)btrfs_extent_data_ref_offset(eb
, dref
),
320 btrfs_extent_data_ref_count(eb
, dref
));
322 case BTRFS_SHARED_DATA_REF_KEY
:
323 sref
= (struct btrfs_shared_data_ref
*)(iref
+ 1);
324 printf("\t\tshared data backref parent %llu count %u\n",
325 (unsigned long long)offset
,
326 btrfs_shared_data_ref_count(eb
, sref
));
331 ptr
+= btrfs_extent_inline_ref_size(type
);
336 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
337 static void print_extent_ref_v0(struct extent_buffer
*eb
, int slot
)
339 struct btrfs_extent_ref_v0
*ref0
;
341 ref0
= btrfs_item_ptr(eb
, slot
, struct btrfs_extent_ref_v0
);
342 printf("\t\textent back ref root %llu gen %llu "
343 "owner %llu num_refs %lu\n",
344 (unsigned long long)btrfs_ref_root_v0(eb
, ref0
),
345 (unsigned long long)btrfs_ref_generation_v0(eb
, ref0
),
346 (unsigned long long)btrfs_ref_objectid_v0(eb
, ref0
),
347 (unsigned long)btrfs_ref_count_v0(eb
, ref0
));
351 static void print_root_ref(struct extent_buffer
*leaf
, int slot
, char *tag
)
353 struct btrfs_root_ref
*ref
;
354 char namebuf
[BTRFS_NAME_LEN
];
357 ref
= btrfs_item_ptr(leaf
, slot
, struct btrfs_root_ref
);
358 namelen
= btrfs_root_ref_name_len(leaf
, ref
);
359 read_extent_buffer(leaf
, namebuf
, (unsigned long)(ref
+ 1), namelen
);
360 printf("\t\troot %s key dirid %llu sequence %llu name %.*s\n", tag
,
361 (unsigned long long)btrfs_root_ref_dirid(leaf
, ref
),
362 (unsigned long long)btrfs_root_ref_sequence(leaf
, ref
),
366 static int count_bytes(void *buf
, int len
, char b
)
370 for (i
= 0; i
< len
; i
++) {
371 if (((char*)buf
)[i
] == b
)
377 static void print_root(struct extent_buffer
*leaf
, int slot
)
379 struct btrfs_root_item
*ri
;
380 struct btrfs_root_item root_item
;
382 char uuid_str
[BTRFS_UUID_UNPARSED_SIZE
];
384 ri
= btrfs_item_ptr(leaf
, slot
, struct btrfs_root_item
);
385 len
= btrfs_item_size_nr(leaf
, slot
);
387 memset(&root_item
, 0, sizeof(root_item
));
388 read_extent_buffer(leaf
, &root_item
, (unsigned long)ri
, len
);
390 printf("\t\troot data bytenr %llu level %d dirid %llu refs %u gen %llu\n",
391 (unsigned long long)btrfs_root_bytenr(&root_item
),
392 btrfs_root_level(&root_item
),
393 (unsigned long long)btrfs_root_dirid(&root_item
),
394 btrfs_root_refs(&root_item
),
395 (unsigned long long)btrfs_root_generation(&root_item
));
397 if (root_item
.generation
== root_item
.generation_v2
) {
398 uuid_unparse(root_item
.uuid
, uuid_str
);
399 printf("\t\tuuid %s\n", uuid_str
);
400 if (count_bytes(root_item
.parent_uuid
, BTRFS_UUID_SIZE
, 0) != BTRFS_UUID_SIZE
) {
401 uuid_unparse(root_item
.parent_uuid
, uuid_str
);
402 printf("\t\tparent_uuid %s\n", uuid_str
);
404 if (count_bytes(root_item
.received_uuid
, BTRFS_UUID_SIZE
, 0) != BTRFS_UUID_SIZE
) {
405 uuid_unparse(root_item
.received_uuid
, uuid_str
);
406 printf("\t\treceived_uuid %s\n", uuid_str
);
408 if (root_item
.ctransid
) {
409 printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
410 btrfs_root_ctransid(&root_item
),
411 btrfs_root_otransid(&root_item
),
412 btrfs_root_stransid(&root_item
),
413 btrfs_root_rtransid(&root_item
));
416 if (btrfs_root_refs(&root_item
) == 0) {
417 struct btrfs_key drop_key
;
418 btrfs_disk_key_to_cpu(&drop_key
,
419 &root_item
.drop_progress
);
421 btrfs_print_key(&root_item
.drop_progress
);
422 printf(" level %d\n", root_item
.drop_level
);
426 static void print_free_space_header(struct extent_buffer
*leaf
, int slot
)
428 struct btrfs_free_space_header
*header
;
429 struct btrfs_disk_key location
;
431 header
= btrfs_item_ptr(leaf
, slot
, struct btrfs_free_space_header
);
432 btrfs_free_space_key(leaf
, header
, &location
);
433 printf("\t\tlocation ");
434 btrfs_print_key(&location
);
436 printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
437 (unsigned long long)btrfs_free_space_generation(leaf
, header
),
438 (unsigned long long)btrfs_free_space_entries(leaf
, header
),
439 (unsigned long long)btrfs_free_space_bitmaps(leaf
, header
));
442 static void print_key_type(u64 objectid
, u8 type
)
444 if (type
== 0 && objectid
== BTRFS_FREE_SPACE_OBJECTID
) {
450 case BTRFS_INODE_ITEM_KEY
:
451 printf("INODE_ITEM");
453 case BTRFS_INODE_REF_KEY
:
456 case BTRFS_INODE_EXTREF_KEY
:
457 printf("INODE_EXTREF");
459 case BTRFS_DIR_ITEM_KEY
:
462 case BTRFS_DIR_INDEX_KEY
:
465 case BTRFS_DIR_LOG_ITEM_KEY
:
466 printf("DIR_LOG_ITEM");
468 case BTRFS_DIR_LOG_INDEX_KEY
:
469 printf("DIR_LOG_INDEX");
471 case BTRFS_XATTR_ITEM_KEY
:
472 printf("XATTR_ITEM");
474 case BTRFS_ORPHAN_ITEM_KEY
:
475 printf("ORPHAN_ITEM");
477 case BTRFS_ROOT_ITEM_KEY
:
480 case BTRFS_ROOT_REF_KEY
:
483 case BTRFS_ROOT_BACKREF_KEY
:
484 printf("ROOT_BACKREF");
486 case BTRFS_EXTENT_ITEM_KEY
:
487 printf("EXTENT_ITEM");
489 case BTRFS_METADATA_ITEM_KEY
:
490 printf("METADATA_ITEM");
492 case BTRFS_TREE_BLOCK_REF_KEY
:
493 printf("TREE_BLOCK_REF");
495 case BTRFS_SHARED_BLOCK_REF_KEY
:
496 printf("SHARED_BLOCK_REF");
498 case BTRFS_EXTENT_DATA_REF_KEY
:
499 printf("EXTENT_DATA_REF");
501 case BTRFS_SHARED_DATA_REF_KEY
:
502 printf("SHARED_DATA_REF");
504 case BTRFS_EXTENT_REF_V0_KEY
:
505 printf("EXTENT_REF_V0");
507 case BTRFS_CSUM_ITEM_KEY
:
510 case BTRFS_EXTENT_CSUM_KEY
:
511 printf("EXTENT_CSUM");
513 case BTRFS_EXTENT_DATA_KEY
:
514 printf("EXTENT_DATA");
516 case BTRFS_BLOCK_GROUP_ITEM_KEY
:
517 printf("BLOCK_GROUP_ITEM");
519 case BTRFS_CHUNK_ITEM_KEY
:
520 printf("CHUNK_ITEM");
522 case BTRFS_DEV_ITEM_KEY
:
525 case BTRFS_DEV_EXTENT_KEY
:
526 printf("DEV_EXTENT");
528 case BTRFS_BALANCE_ITEM_KEY
:
529 printf("BALANCE_ITEM");
531 case BTRFS_DEV_REPLACE_KEY
:
532 printf("DEV_REPLACE_ITEM");
534 case BTRFS_STRING_ITEM_KEY
:
535 printf("STRING_ITEM");
537 case BTRFS_QGROUP_STATUS_KEY
:
538 printf("BTRFS_STATUS_KEY");
540 case BTRFS_QGROUP_RELATION_KEY
:
541 printf("BTRFS_QGROUP_RELATION_KEY");
543 case BTRFS_QGROUP_INFO_KEY
:
544 printf("BTRFS_QGROUP_INFO_KEY");
546 case BTRFS_QGROUP_LIMIT_KEY
:
547 printf("BTRFS_QGROUP_LIMIT_KEY");
549 case BTRFS_DEV_STATS_KEY
:
550 printf("DEV_STATS_ITEM");
552 case BTRFS_UUID_KEY_SUBVOL
:
553 printf("BTRFS_UUID_KEY_SUBVOL");
555 case BTRFS_UUID_KEY_RECEIVED_SUBVOL
:
556 printf("BTRFS_UUID_KEY_RECEIVED_SUBVOL");
559 printf("UNKNOWN.%d", type
);
563 static void print_objectid(u64 objectid
, u8 type
)
566 case BTRFS_DEV_EXTENT_KEY
:
567 printf("%llu", (unsigned long long)objectid
); /* device id */
569 case BTRFS_QGROUP_RELATION_KEY
:
570 printf("%llu/%llu", objectid
>> 48,
571 objectid
& ((1ll << 48) - 1));
573 case BTRFS_UUID_KEY_SUBVOL
:
574 case BTRFS_UUID_KEY_RECEIVED_SUBVOL
:
575 printf("0x%016llx", (unsigned long long)objectid
);
580 case BTRFS_ROOT_TREE_OBJECTID
:
581 if (type
== BTRFS_DEV_ITEM_KEY
)
586 case BTRFS_EXTENT_TREE_OBJECTID
:
587 printf("EXTENT_TREE");
589 case BTRFS_CHUNK_TREE_OBJECTID
:
590 printf("CHUNK_TREE");
592 case BTRFS_DEV_TREE_OBJECTID
:
595 case BTRFS_FS_TREE_OBJECTID
:
598 case BTRFS_ROOT_TREE_DIR_OBJECTID
:
599 printf("ROOT_TREE_DIR");
601 case BTRFS_CSUM_TREE_OBJECTID
:
604 case BTRFS_BALANCE_OBJECTID
:
607 case BTRFS_ORPHAN_OBJECTID
:
610 case BTRFS_TREE_LOG_OBJECTID
:
613 case BTRFS_TREE_LOG_FIXUP_OBJECTID
:
616 case BTRFS_TREE_RELOC_OBJECTID
:
617 printf("TREE_RELOC");
619 case BTRFS_DATA_RELOC_TREE_OBJECTID
:
620 printf("DATA_RELOC_TREE");
622 case BTRFS_EXTENT_CSUM_OBJECTID
:
623 printf("EXTENT_CSUM");
625 case BTRFS_FREE_SPACE_OBJECTID
:
626 printf("FREE_SPACE");
628 case BTRFS_FREE_INO_OBJECTID
:
631 case BTRFS_QUOTA_TREE_OBJECTID
:
632 printf("QUOTA_TREE");
634 case BTRFS_UUID_TREE_OBJECTID
:
637 case BTRFS_MULTIPLE_OBJECTIDS
:
643 case BTRFS_FIRST_CHUNK_TREE_OBJECTID
:
644 if (type
== BTRFS_CHUNK_ITEM_KEY
) {
645 printf("FIRST_CHUNK_TREE");
650 printf("%llu", (unsigned long long)objectid
);
654 void btrfs_print_key(struct btrfs_disk_key
*disk_key
)
656 u64 objectid
= btrfs_disk_key_objectid(disk_key
);
657 u8 type
= btrfs_disk_key_type(disk_key
);
658 u64 offset
= btrfs_disk_key_offset(disk_key
);
661 print_objectid(objectid
, type
);
663 print_key_type(objectid
, type
);
665 case BTRFS_QGROUP_RELATION_KEY
:
666 case BTRFS_QGROUP_INFO_KEY
:
667 case BTRFS_QGROUP_LIMIT_KEY
:
668 printf(" %llu/%llu)", (unsigned long long)(offset
>> 48),
669 (unsigned long long)(offset
& ((1ll << 48) - 1)));
671 case BTRFS_UUID_KEY_SUBVOL
:
672 case BTRFS_UUID_KEY_RECEIVED_SUBVOL
:
673 printf(" 0x%016llx)", (unsigned long long)offset
);
676 if (offset
== (u64
)-1)
679 printf(" %llu)", (unsigned long long)offset
);
684 static void print_uuid_item(struct extent_buffer
*l
, unsigned long offset
,
687 if (item_size
& (sizeof(u64
) - 1)) {
688 printf("btrfs: uuid item with illegal size %lu!\n",
689 (unsigned long)item_size
);
695 read_extent_buffer(l
, &subvol_id
, offset
, sizeof(u64
));
696 printf("\t\tsubvol_id %llu\n",
697 (unsigned long long)le64_to_cpu(subvol_id
));
698 item_size
-= sizeof(u64
);
699 offset
+= sizeof(u64
);
703 void btrfs_print_leaf(struct btrfs_root
*root
, struct extent_buffer
*l
)
707 struct btrfs_item
*item
;
708 struct btrfs_dir_item
*di
;
709 struct btrfs_inode_item
*ii
;
710 struct btrfs_file_extent_item
*fi
;
711 struct btrfs_block_group_item
*bi
;
712 struct btrfs_extent_data_ref
*dref
;
713 struct btrfs_shared_data_ref
*sref
;
714 struct btrfs_inode_ref
*iref
;
715 struct btrfs_inode_extref
*iref2
;
716 struct btrfs_dev_extent
*dev_extent
;
717 struct btrfs_disk_key disk_key
;
718 struct btrfs_block_group_item bg_item
;
719 struct btrfs_dir_log_item
*dlog
;
720 struct btrfs_qgroup_info_item
*qg_info
;
721 struct btrfs_qgroup_limit_item
*qg_limit
;
722 struct btrfs_qgroup_status_item
*qg_status
;
723 u32 nr
= btrfs_header_nritems(l
);
727 printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
728 (unsigned long long)btrfs_header_bytenr(l
), nr
,
729 btrfs_leaf_free_space(root
, l
),
730 (unsigned long long)btrfs_header_generation(l
),
731 (unsigned long long)btrfs_header_owner(l
));
734 for (i
= 0 ; i
< nr
; i
++) {
735 item
= btrfs_item_nr(i
);
736 btrfs_item_key(l
, &disk_key
, i
);
737 objectid
= btrfs_disk_key_objectid(&disk_key
);
738 type
= btrfs_disk_key_type(&disk_key
);
739 printf("\titem %d ", i
);
740 btrfs_print_key(&disk_key
);
741 printf(" itemoff %d itemsize %d\n",
742 btrfs_item_offset(l
, item
),
743 btrfs_item_size(l
, item
));
745 if (type
== 0 && objectid
== BTRFS_FREE_SPACE_OBJECTID
)
746 print_free_space_header(l
, i
);
749 case BTRFS_INODE_ITEM_KEY
:
750 ii
= btrfs_item_ptr(l
, i
, struct btrfs_inode_item
);
751 printf("\t\tinode generation %llu transid %llu size %llu block group %llu mode %o links %u\n",
752 (unsigned long long)btrfs_inode_generation(l
, ii
),
753 (unsigned long long)btrfs_inode_transid(l
, ii
),
754 (unsigned long long)btrfs_inode_size(l
, ii
),
755 (unsigned long long)btrfs_inode_block_group(l
,ii
),
756 btrfs_inode_mode(l
, ii
),
757 btrfs_inode_nlink(l
, ii
));
759 case BTRFS_INODE_REF_KEY
:
760 iref
= btrfs_item_ptr(l
, i
, struct btrfs_inode_ref
);
761 print_inode_ref_item(l
, item
, iref
);
763 case BTRFS_INODE_EXTREF_KEY
:
764 iref2
= btrfs_item_ptr(l
, i
, struct btrfs_inode_extref
);
765 print_inode_extref_item(l
, item
, iref2
);
767 case BTRFS_DIR_ITEM_KEY
:
768 case BTRFS_DIR_INDEX_KEY
:
769 case BTRFS_XATTR_ITEM_KEY
:
770 di
= btrfs_item_ptr(l
, i
, struct btrfs_dir_item
);
771 print_dir_item(l
, item
, di
);
773 case BTRFS_DIR_LOG_INDEX_KEY
:
774 case BTRFS_DIR_LOG_ITEM_KEY
:
775 dlog
= btrfs_item_ptr(l
, i
, struct btrfs_dir_log_item
);
776 printf("\t\tdir log end %Lu\n",
777 (unsigned long long)btrfs_dir_log_end(l
, dlog
));
779 case BTRFS_ORPHAN_ITEM_KEY
:
780 printf("\t\torphan item\n");
782 case BTRFS_ROOT_ITEM_KEY
:
785 case BTRFS_ROOT_REF_KEY
:
786 print_root_ref(l
, i
, "ref");
788 case BTRFS_ROOT_BACKREF_KEY
:
789 print_root_ref(l
, i
, "backref");
791 case BTRFS_EXTENT_ITEM_KEY
:
792 print_extent_item(l
, i
, 0);
794 case BTRFS_METADATA_ITEM_KEY
:
795 print_extent_item(l
, i
, 1);
797 case BTRFS_TREE_BLOCK_REF_KEY
:
798 printf("\t\ttree block backref\n");
800 case BTRFS_SHARED_BLOCK_REF_KEY
:
801 printf("\t\tshared block backref\n");
803 case BTRFS_EXTENT_DATA_REF_KEY
:
804 dref
= btrfs_item_ptr(l
, i
, struct btrfs_extent_data_ref
);
805 printf("\t\textent data backref root %llu "
806 "objectid %llu offset %llu count %u\n",
807 (unsigned long long)btrfs_extent_data_ref_root(l
, dref
),
808 (unsigned long long)btrfs_extent_data_ref_objectid(l
, dref
),
809 (unsigned long long)btrfs_extent_data_ref_offset(l
, dref
),
810 btrfs_extent_data_ref_count(l
, dref
));
812 case BTRFS_SHARED_DATA_REF_KEY
:
813 sref
= btrfs_item_ptr(l
, i
, struct btrfs_shared_data_ref
);
814 printf("\t\tshared data backref count %u\n",
815 btrfs_shared_data_ref_count(l
, sref
));
817 case BTRFS_EXTENT_REF_V0_KEY
:
818 #ifdef BTRFS_COMPAT_EXTENT_TREE_V0
819 print_extent_ref_v0(l
, i
);
824 case BTRFS_CSUM_ITEM_KEY
:
825 printf("\t\tcsum item\n");
827 case BTRFS_EXTENT_CSUM_KEY
:
828 printf("\t\textent csum item\n");
830 case BTRFS_EXTENT_DATA_KEY
:
831 fi
= btrfs_item_ptr(l
, i
,
832 struct btrfs_file_extent_item
);
833 print_file_extent_item(l
, item
, i
, fi
);
835 case BTRFS_BLOCK_GROUP_ITEM_KEY
:
836 bi
= btrfs_item_ptr(l
, i
,
837 struct btrfs_block_group_item
);
838 read_extent_buffer(l
, &bg_item
, (unsigned long)bi
,
840 printf("\t\tblock group used %llu chunk_objectid %llu flags %llu\n",
841 (unsigned long long)btrfs_block_group_used(&bg_item
),
842 (unsigned long long)btrfs_block_group_chunk_objectid(&bg_item
),
843 (unsigned long long)btrfs_block_group_flags(&bg_item
));
845 case BTRFS_CHUNK_ITEM_KEY
:
846 print_chunk(l
, btrfs_item_ptr(l
, i
, struct btrfs_chunk
));
848 case BTRFS_DEV_ITEM_KEY
:
849 print_dev_item(l
, btrfs_item_ptr(l
, i
,
850 struct btrfs_dev_item
));
852 case BTRFS_DEV_EXTENT_KEY
:
853 dev_extent
= btrfs_item_ptr(l
, i
,
854 struct btrfs_dev_extent
);
855 printf("\t\tdev extent chunk_tree %llu\n"
856 "\t\tchunk objectid %llu chunk offset %llu "
859 btrfs_dev_extent_chunk_tree(l
, dev_extent
),
861 btrfs_dev_extent_chunk_objectid(l
, dev_extent
),
863 btrfs_dev_extent_chunk_offset(l
, dev_extent
),
865 btrfs_dev_extent_length(l
, dev_extent
));
867 case BTRFS_QGROUP_STATUS_KEY
:
868 qg_status
= btrfs_item_ptr(l
, i
,
869 struct btrfs_qgroup_status_item
);
870 printf("\t\tversion %llu generation %llu flags %#llx "
873 btrfs_qgroup_status_version(l
, qg_status
),
875 btrfs_qgroup_status_generation(l
, qg_status
),
877 btrfs_qgroup_status_flags(l
, qg_status
),
879 btrfs_qgroup_status_scan(l
, qg_status
));
881 case BTRFS_QGROUP_RELATION_KEY
:
883 case BTRFS_QGROUP_INFO_KEY
:
884 qg_info
= btrfs_item_ptr(l
, i
,
885 struct btrfs_qgroup_info_item
);
886 printf("\t\tgeneration %llu\n"
887 "\t\treferenced %lld referenced compressed %lld\n"
888 "\t\texclusive %lld exclusive compressed %lld\n",
890 btrfs_qgroup_info_generation(l
, qg_info
),
892 btrfs_qgroup_info_referenced(l
, qg_info
),
894 btrfs_qgroup_info_referenced_compressed(l
,
897 btrfs_qgroup_info_exclusive(l
, qg_info
),
899 btrfs_qgroup_info_exclusive_compressed(l
,
902 case BTRFS_QGROUP_LIMIT_KEY
:
903 qg_limit
= btrfs_item_ptr(l
, i
,
904 struct btrfs_qgroup_limit_item
);
905 printf("\t\tflags %llx\n"
906 "\t\tmax referenced %lld max exclusive %lld\n"
907 "\t\trsv referenced %lld rsv exclusive %lld\n",
909 btrfs_qgroup_limit_flags(l
, qg_limit
),
911 btrfs_qgroup_limit_max_referenced(l
, qg_limit
),
913 btrfs_qgroup_limit_max_exclusive(l
, qg_limit
),
915 btrfs_qgroup_limit_rsv_referenced(l
, qg_limit
),
917 btrfs_qgroup_limit_rsv_exclusive(l
, qg_limit
));
919 case BTRFS_UUID_KEY_SUBVOL
:
920 case BTRFS_UUID_KEY_RECEIVED_SUBVOL
:
921 print_uuid_item(l
, btrfs_item_ptr_offset(l
, i
),
922 btrfs_item_size_nr(l
, i
));
924 case BTRFS_STRING_ITEM_KEY
:
925 /* dirty, but it's simple */
926 str
= l
->data
+ btrfs_item_ptr_offset(l
, i
);
927 printf("\t\titem data %.*s\n", btrfs_item_size(l
, item
), str
);
929 case BTRFS_DEV_STATS_KEY
:
930 printf("\t\tdevice stats\n");
937 void btrfs_print_tree(struct btrfs_root
*root
, struct extent_buffer
*eb
, int follow
)
942 struct btrfs_disk_key disk_key
;
943 struct btrfs_key key
;
947 nr
= btrfs_header_nritems(eb
);
948 if (btrfs_is_leaf(eb
)) {
949 btrfs_print_leaf(root
, eb
);
952 printf("node %llu level %d items %d free %u generation %llu owner %llu\n",
953 (unsigned long long)eb
->start
,
954 btrfs_header_level(eb
), nr
,
955 (u32
)BTRFS_NODEPTRS_PER_BLOCK(root
) - nr
,
956 (unsigned long long)btrfs_header_generation(eb
),
957 (unsigned long long)btrfs_header_owner(eb
));
960 size
= btrfs_level_size(root
, btrfs_header_level(eb
) - 1);
961 for (i
= 0; i
< nr
; i
++) {
962 u64 blocknr
= btrfs_node_blockptr(eb
, i
);
963 btrfs_node_key(eb
, &disk_key
, i
);
964 btrfs_disk_key_to_cpu(&key
, &disk_key
);
966 btrfs_print_key(&disk_key
);
967 printf(" block %llu (%llu) gen %llu\n",
968 (unsigned long long)blocknr
,
969 (unsigned long long)blocknr
/ size
,
970 (unsigned long long)btrfs_node_ptr_generation(eb
, i
));
976 for (i
= 0; i
< nr
; i
++) {
977 struct extent_buffer
*next
= read_tree_block(root
,
978 btrfs_node_blockptr(eb
, i
),
980 btrfs_node_ptr_generation(eb
, i
));
982 fprintf(stderr
, "failed to read %llu in tree %llu\n",
983 (unsigned long long)btrfs_node_blockptr(eb
, i
),
984 (unsigned long long)btrfs_header_owner(eb
));
987 if (btrfs_is_leaf(next
) &&
988 btrfs_header_level(eb
) != 1)
990 if (btrfs_header_level(next
) !=
991 btrfs_header_level(eb
) - 1)
993 btrfs_print_tree(root
, next
, 1);
994 free_extent_buffer(next
);