+ struct btrfs_root_item root_item;
+ int len;
+ char uuid_str[BTRFS_UUID_UNPARSED_SIZE];
+
+ ri = btrfs_item_ptr(leaf, slot, struct btrfs_root_item);
+ len = btrfs_item_size_nr(leaf, slot);
+
+ memset(&root_item, 0, sizeof(root_item));
+ read_extent_buffer(leaf, &root_item, (unsigned long)ri, len);
+
+ printf("\t\troot data bytenr %llu level %d dirid %llu refs %u gen %llu\n",
+ (unsigned long long)btrfs_root_bytenr(&root_item),
+ btrfs_root_level(&root_item),
+ (unsigned long long)btrfs_root_dirid(&root_item),
+ btrfs_root_refs(&root_item),
+ (unsigned long long)btrfs_root_generation(&root_item));
+
+ if (root_item.generation == root_item.generation_v2) {
+ uuid_unparse(root_item.uuid, uuid_str);
+ printf("\t\tuuid %s\n", uuid_str);
+ if (count_bytes(root_item.parent_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
+ uuid_unparse(root_item.parent_uuid, uuid_str);
+ printf("\t\tparent_uuid %s\n", uuid_str);
+ }
+ if (count_bytes(root_item.received_uuid, BTRFS_UUID_SIZE, 0) != BTRFS_UUID_SIZE) {
+ uuid_unparse(root_item.received_uuid, uuid_str);
+ printf("\t\treceived_uuid %s\n", uuid_str);
+ }
+ if (root_item.ctransid) {
+ printf("\t\tctransid %llu otransid %llu stransid %llu rtransid %llu\n",
+ btrfs_root_ctransid(&root_item),
+ btrfs_root_otransid(&root_item),
+ btrfs_root_stransid(&root_item),
+ btrfs_root_rtransid(&root_item));
+ }
+ }
+ if (btrfs_root_refs(&root_item) == 0) {
+ struct btrfs_key drop_key;
+ btrfs_disk_key_to_cpu(&drop_key,
+ &root_item.drop_progress);
+ printf("\t\tdrop ");
+ btrfs_print_key(&root_item.drop_progress);
+ printf(" level %d\n", root_item.drop_level);
+ }
+}
+
+static void print_free_space_header(struct extent_buffer *leaf, int slot)
+{
+ struct btrfs_free_space_header *header;
+ struct btrfs_disk_key location;
+
+ header = btrfs_item_ptr(leaf, slot, struct btrfs_free_space_header);
+ btrfs_free_space_key(leaf, header, &location);
+ printf("\t\tlocation ");
+ btrfs_print_key(&location);
+ printf("\n");
+ printf("\t\tcache generation %llu entries %llu bitmaps %llu\n",
+ (unsigned long long)btrfs_free_space_generation(leaf, header),
+ (unsigned long long)btrfs_free_space_entries(leaf, header),
+ (unsigned long long)btrfs_free_space_bitmaps(leaf, header));
+}
+
+static void print_key_type(u64 objectid, u8 type)
+{
+ if (type == 0 && objectid == BTRFS_FREE_SPACE_OBJECTID) {
+ printf("UNTYPED");
+ return;
+ }
+
+ switch (type) {
+ case BTRFS_INODE_ITEM_KEY:
+ printf("INODE_ITEM");
+ break;
+ case BTRFS_INODE_REF_KEY:
+ printf("INODE_REF");
+ break;
+ case BTRFS_INODE_EXTREF_KEY:
+ printf("INODE_EXTREF");
+ break;
+ case BTRFS_DIR_ITEM_KEY:
+ printf("DIR_ITEM");
+ break;
+ case BTRFS_DIR_INDEX_KEY:
+ printf("DIR_INDEX");
+ break;
+ case BTRFS_DIR_LOG_ITEM_KEY:
+ printf("DIR_LOG_ITEM");
+ break;
+ case BTRFS_DIR_LOG_INDEX_KEY:
+ printf("DIR_LOG_INDEX");
+ break;
+ case BTRFS_XATTR_ITEM_KEY:
+ printf("XATTR_ITEM");
+ break;
+ case BTRFS_ORPHAN_ITEM_KEY:
+ printf("ORPHAN_ITEM");
+ break;
+ case BTRFS_ROOT_ITEM_KEY:
+ printf("ROOT_ITEM");
+ break;
+ case BTRFS_ROOT_REF_KEY:
+ printf("ROOT_REF");
+ break;
+ case BTRFS_ROOT_BACKREF_KEY:
+ printf("ROOT_BACKREF");
+ break;
+ case BTRFS_EXTENT_ITEM_KEY:
+ printf("EXTENT_ITEM");
+ break;
+ case BTRFS_METADATA_ITEM_KEY:
+ printf("METADATA_ITEM");
+ break;
+ case BTRFS_TREE_BLOCK_REF_KEY:
+ printf("TREE_BLOCK_REF");
+ break;
+ case BTRFS_SHARED_BLOCK_REF_KEY:
+ printf("SHARED_BLOCK_REF");
+ break;
+ case BTRFS_EXTENT_DATA_REF_KEY:
+ printf("EXTENT_DATA_REF");
+ break;
+ case BTRFS_SHARED_DATA_REF_KEY:
+ printf("SHARED_DATA_REF");
+ break;
+ case BTRFS_EXTENT_REF_V0_KEY:
+ printf("EXTENT_REF_V0");
+ break;
+ case BTRFS_CSUM_ITEM_KEY:
+ printf("CSUM_ITEM");
+ break;
+ case BTRFS_EXTENT_CSUM_KEY:
+ printf("EXTENT_CSUM");
+ break;
+ case BTRFS_EXTENT_DATA_KEY:
+ printf("EXTENT_DATA");
+ break;
+ case BTRFS_BLOCK_GROUP_ITEM_KEY:
+ printf("BLOCK_GROUP_ITEM");
+ break;
+ case BTRFS_CHUNK_ITEM_KEY:
+ printf("CHUNK_ITEM");
+ break;
+ case BTRFS_DEV_ITEM_KEY:
+ printf("DEV_ITEM");
+ break;
+ case BTRFS_DEV_EXTENT_KEY:
+ printf("DEV_EXTENT");
+ break;
+ case BTRFS_BALANCE_ITEM_KEY:
+ printf("BALANCE_ITEM");
+ break;
+ case BTRFS_DEV_REPLACE_KEY:
+ printf("DEV_REPLACE_ITEM");
+ break;
+ case BTRFS_STRING_ITEM_KEY:
+ printf("STRING_ITEM");
+ break;
+ case BTRFS_QGROUP_STATUS_KEY:
+ printf("BTRFS_STATUS_KEY");
+ break;
+ case BTRFS_QGROUP_RELATION_KEY:
+ printf("BTRFS_QGROUP_RELATION_KEY");
+ break;
+ case BTRFS_QGROUP_INFO_KEY:
+ printf("BTRFS_QGROUP_INFO_KEY");
+ break;
+ case BTRFS_QGROUP_LIMIT_KEY:
+ printf("BTRFS_QGROUP_LIMIT_KEY");
+ break;
+ case BTRFS_DEV_STATS_KEY:
+ printf("DEV_STATS_ITEM");
+ break;
+ case BTRFS_UUID_KEY_SUBVOL:
+ printf("BTRFS_UUID_KEY_SUBVOL");
+ break;
+ case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
+ printf("BTRFS_UUID_KEY_RECEIVED_SUBVOL");
+ break;
+ default:
+ printf("UNKNOWN.%d", type);
+ };
+}
+
+static void print_objectid(u64 objectid, u8 type)
+{
+ switch (type) {
+ case BTRFS_DEV_EXTENT_KEY:
+ printf("%llu", (unsigned long long)objectid); /* device id */
+ return;
+ case BTRFS_QGROUP_RELATION_KEY:
+ printf("%llu/%llu", objectid >> 48,
+ objectid & ((1ll << 48) - 1));
+ return;
+ case BTRFS_UUID_KEY_SUBVOL:
+ case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
+ printf("0x%016llx", (unsigned long long)objectid);
+ return;
+ }
+
+ switch (objectid) {
+ case BTRFS_ROOT_TREE_OBJECTID:
+ if (type == BTRFS_DEV_ITEM_KEY)
+ printf("DEV_ITEMS");
+ else
+ printf("ROOT_TREE");
+ break;
+ case BTRFS_EXTENT_TREE_OBJECTID:
+ printf("EXTENT_TREE");
+ break;
+ case BTRFS_CHUNK_TREE_OBJECTID:
+ printf("CHUNK_TREE");
+ break;
+ case BTRFS_DEV_TREE_OBJECTID:
+ printf("DEV_TREE");
+ break;
+ case BTRFS_FS_TREE_OBJECTID:
+ printf("FS_TREE");
+ break;
+ case BTRFS_ROOT_TREE_DIR_OBJECTID:
+ printf("ROOT_TREE_DIR");
+ break;
+ case BTRFS_CSUM_TREE_OBJECTID:
+ printf("CSUM_TREE");
+ break;
+ case BTRFS_BALANCE_OBJECTID:
+ printf("BALANCE");
+ break;
+ case BTRFS_ORPHAN_OBJECTID:
+ printf("ORPHAN");
+ break;
+ case BTRFS_TREE_LOG_OBJECTID:
+ printf("TREE_LOG");
+ break;
+ case BTRFS_TREE_LOG_FIXUP_OBJECTID:
+ printf("LOG_FIXUP");
+ break;
+ case BTRFS_TREE_RELOC_OBJECTID:
+ printf("TREE_RELOC");
+ break;
+ case BTRFS_DATA_RELOC_TREE_OBJECTID:
+ printf("DATA_RELOC_TREE");
+ break;
+ case BTRFS_EXTENT_CSUM_OBJECTID:
+ printf("EXTENT_CSUM");
+ break;
+ case BTRFS_FREE_SPACE_OBJECTID:
+ printf("FREE_SPACE");
+ break;
+ case BTRFS_FREE_INO_OBJECTID:
+ printf("FREE_INO");
+ break;
+ case BTRFS_QUOTA_TREE_OBJECTID:
+ printf("QUOTA_TREE");
+ break;
+ case BTRFS_UUID_TREE_OBJECTID:
+ printf("UUID_TREE");
+ break;
+ case BTRFS_MULTIPLE_OBJECTIDS:
+ printf("MULTIPLE");
+ break;
+ case (u64)-1:
+ printf("-1");
+ break;
+ case BTRFS_FIRST_CHUNK_TREE_OBJECTID:
+ if (type == BTRFS_CHUNK_ITEM_KEY) {
+ printf("FIRST_CHUNK_TREE");
+ break;
+ }
+ /* fall-thru */
+ default:
+ printf("%llu", (unsigned long long)objectid);
+ }
+}
+
+void btrfs_print_key(struct btrfs_disk_key *disk_key)
+{
+ u64 objectid = btrfs_disk_key_objectid(disk_key);
+ u8 type = btrfs_disk_key_type(disk_key);
+ u64 offset = btrfs_disk_key_offset(disk_key);
+
+ printf("key (");
+ print_objectid(objectid, type);
+ printf(" ");
+ print_key_type(objectid, type);
+ switch (type) {
+ case BTRFS_QGROUP_RELATION_KEY:
+ case BTRFS_QGROUP_INFO_KEY:
+ case BTRFS_QGROUP_LIMIT_KEY:
+ printf(" %llu/%llu)", (unsigned long long)(offset >> 48),
+ (unsigned long long)(offset & ((1ll << 48) - 1)));
+ break;
+ case BTRFS_UUID_KEY_SUBVOL:
+ case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
+ printf(" 0x%016llx)", (unsigned long long)offset);
+ break;
+ default:
+ if (offset == (u64)-1)
+ printf(" -1)");
+ else
+ printf(" %llu)", (unsigned long long)offset);
+ break;
+ }
+}
+
+static void print_uuid_item(struct extent_buffer *l, unsigned long offset,
+ u32 item_size)
+{
+ if (item_size & (sizeof(u64) - 1)) {
+ printf("btrfs: uuid item with illegal size %lu!\n",
+ (unsigned long)item_size);
+ return;
+ }
+ while (item_size) {
+ __le64 subvol_id;
+
+ read_extent_buffer(l, &subvol_id, offset, sizeof(u64));
+ printf("\t\tsubvol_id %llu\n",
+ (unsigned long long)le64_to_cpu(subvol_id));
+ item_size -= sizeof(u64);
+ offset += sizeof(u64);
+ }
+}
+
+void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
+{
+ int i;
+ char *str;
+ struct btrfs_item *item;