#include "ctree.h"
#include "disk-io.h"
#include "print-tree.h"
+#include "utils.h"
static void print_dir_item_type(struct extent_buffer *eb,
return 0;
}
-static void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
+/* Caller should ensure sizeof(*ret)>=21 "DATA|METADATA|RAID10" */
+static void bg_flags_to_str(u64 flags, char *ret)
+{
+ int empty = 1;
+
+ if (flags & BTRFS_BLOCK_GROUP_DATA) {
+ empty = 0;
+ strcpy(ret, "DATA");
+ }
+ if (flags & BTRFS_BLOCK_GROUP_METADATA) {
+ if (!empty)
+ strcat(ret, "|");
+ strcat(ret, "METADATA");
+ }
+ if (flags & BTRFS_BLOCK_GROUP_SYSTEM) {
+ if (!empty)
+ strcat(ret, "|");
+ strcat(ret, "SYSTEM");
+ }
+ switch (flags & BTRFS_BLOCK_GROUP_PROFILE_MASK) {
+ case BTRFS_BLOCK_GROUP_RAID0:
+ strcat(ret, "|RAID0");
+ break;
+ case BTRFS_BLOCK_GROUP_RAID1:
+ strcat(ret, "|RAID1");
+ break;
+ case BTRFS_BLOCK_GROUP_DUP:
+ strcat(ret, "|DUP");
+ break;
+ case BTRFS_BLOCK_GROUP_RAID10:
+ strcat(ret, "|RAID10");
+ break;
+ case BTRFS_BLOCK_GROUP_RAID5:
+ strcat(ret, "|RAID5");
+ break;
+ case BTRFS_BLOCK_GROUP_RAID6:
+ strcat(ret, "|RAID6");
+ break;
+ default:
+ break;
+ }
+}
+
+/* Caller should ensure sizeof(*ret)>= 26 "OFF|SCANNING|INCONSISTENT" */
+static void qgroup_flags_to_str(u64 flags, char *ret)
+{
+ if (flags & BTRFS_QGROUP_STATUS_FLAG_ON)
+ strcpy(ret, "ON");
+ else
+ strcpy(ret, "OFF");
+
+ if (flags & BTRFS_QGROUP_STATUS_FLAG_RESCAN)
+ strcat(ret, "|SCANNING");
+ if (flags & BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT)
+ strcat(ret, "|INCONSISTENT");
+}
+
+void print_chunk(struct extent_buffer *eb, struct btrfs_chunk *chunk)
{
int num_stripes = btrfs_chunk_num_stripes(eb, chunk);
int i;
- printf("\t\tchunk length %llu owner %llu type %llu num_stripes %d\n",
+ char chunk_flags_str[32] = {0};
+
+ bg_flags_to_str(btrfs_chunk_type(eb, chunk), chunk_flags_str);
+ printf("\t\tchunk length %llu owner %llu stripe_len %llu\n",
(unsigned long long)btrfs_chunk_length(eb, chunk),
(unsigned long long)btrfs_chunk_owner(eb, chunk),
- (unsigned long long)btrfs_chunk_type(eb, chunk),
- num_stripes);
+ (unsigned long long)btrfs_chunk_stripe_len(eb, chunk));
+ printf("\t\ttype %s num_stripes %d\n",
+ chunk_flags_str, num_stripes);
for (i = 0 ; i < num_stripes ; i++) {
+ unsigned char dev_uuid[BTRFS_UUID_SIZE];
+ char str_dev_uuid[BTRFS_UUID_UNPARSED_SIZE];
+
+ read_extent_buffer(eb, dev_uuid,
+ (unsigned long)btrfs_stripe_dev_uuid_nr(chunk, i),
+ BTRFS_UUID_SIZE);
+ uuid_unparse(dev_uuid, str_dev_uuid);
printf("\t\t\tstripe %d devid %llu offset %llu\n", i,
(unsigned long long)btrfs_stripe_devid_nr(eb, chunk, i),
(unsigned long long)btrfs_stripe_offset_nr(eb, chunk, i));
+ printf("\t\t\tdev uuid: %s\n", str_dev_uuid);
}
}
static void print_dev_item(struct extent_buffer *eb,
struct btrfs_dev_item *dev_item)
{
+ char disk_uuid_c[BTRFS_UUID_UNPARSED_SIZE];
+ u8 disk_uuid[BTRFS_UUID_SIZE];
+
+ read_extent_buffer(eb, disk_uuid,
+ (unsigned long)btrfs_device_uuid(dev_item),
+ BTRFS_UUID_SIZE);
+ uuid_unparse(disk_uuid, disk_uuid_c);
printf("\t\tdev item devid %llu "
- "total_bytes %llu bytes used %Lu\n",
+ "total_bytes %llu bytes used %Lu\n"
+ "\t\tdev uuid %s\n",
(unsigned long long)btrfs_device_id(eb, dev_item),
(unsigned long long)btrfs_device_total_bytes(eb, dev_item),
- (unsigned long long)btrfs_device_bytes_used(eb, dev_item));
+ (unsigned long long)btrfs_device_bytes_used(eb, dev_item),
+ disk_uuid_c);
}
static void print_uuids(struct extent_buffer *eb)
{
- char fs_uuid[37];
- char chunk_uuid[37];
+ char fs_uuid[BTRFS_UUID_UNPARSED_SIZE];
+ char chunk_uuid[BTRFS_UUID_UNPARSED_SIZE];
u8 disk_uuid[BTRFS_UUID_SIZE];
- read_extent_buffer(eb, disk_uuid, (unsigned long)btrfs_header_fsid(),
+ read_extent_buffer(eb, disk_uuid, btrfs_header_fsid(),
BTRFS_FSID_SIZE);
- fs_uuid[36] = '\0';
+ fs_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
uuid_unparse(disk_uuid, fs_uuid);
read_extent_buffer(eb, disk_uuid,
- (unsigned long)btrfs_header_chunk_tree_uuid(eb),
+ btrfs_header_chunk_tree_uuid(eb),
BTRFS_UUID_SIZE);
- chunk_uuid[36] = '\0';
+ chunk_uuid[BTRFS_UUID_UNPARSED_SIZE - 1] = '\0';
uuid_unparse(disk_uuid, chunk_uuid);
printf("fs uuid %s\nchunk uuid %s\n", fs_uuid, chunk_uuid);
}
+static void compress_type_to_str(u8 compress_type, char *ret)
+{
+ switch (compress_type) {
+ case BTRFS_COMPRESS_NONE:
+ strcpy(ret, "none");
+ break;
+ case BTRFS_COMPRESS_ZLIB:
+ strcpy(ret, "zlib");
+ break;
+ case BTRFS_COMPRESS_LZO:
+ strcpy(ret, "lzo");
+ break;
+ default:
+ sprintf(ret, "UNKNOWN.%d", compress_type);
+ }
+}
+
static void print_file_extent_item(struct extent_buffer *eb,
struct btrfs_item *item,
+ int slot,
struct btrfs_file_extent_item *fi)
{
int extent_type = btrfs_file_extent_type(eb, fi);
+ char compress_str[16];
+
+ compress_type_to_str(btrfs_file_extent_compression(eb, fi),
+ compress_str);
if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
printf("\t\tinline extent data size %u "
- "ram %u compress %d\n",
+ "ram %u compress(%s)\n",
btrfs_file_extent_inline_item_len(eb, item),
- btrfs_file_extent_inline_len(eb, fi),
- btrfs_file_extent_compression(eb, fi));
+ btrfs_file_extent_inline_len(eb, slot, fi),
+ compress_str);
return;
}
if (extent_type == BTRFS_FILE_EXTENT_PREALLOC) {
(unsigned long long)btrfs_file_extent_offset(eb, fi),
(unsigned long long)btrfs_file_extent_num_bytes(eb, fi),
(unsigned long long)btrfs_file_extent_ram_bytes(eb, fi));
- printf("\t\textent compression %d\n",
- btrfs_file_extent_compression(eb, fi));
+ printf("\t\textent compression(%s)\n", compress_str);
}
-static void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
+/* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */
+static void extent_flags_to_str(u64 flags, char *ret)
+{
+ int empty = 1;
+
+ if (flags & BTRFS_EXTENT_FLAG_DATA) {
+ empty = 0;
+ strcpy(ret, "DATA");
+ }
+ if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
+ if (!empty) {
+ empty = 0;
+ strcat(ret, "|");
+ }
+ strcat(ret, "TREE_BLOCK");
+ }
+ if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
+ strcat(ret, "|");
+ strcat(ret, "FULL_BACKREF");
+ }
+}
+
+void print_extent_item(struct extent_buffer *eb, int slot, int metadata)
{
struct btrfs_extent_item *ei;
struct btrfs_extent_inline_ref *iref;
u32 item_size = btrfs_item_size_nr(eb, slot);
u64 flags;
u64 offset;
+ char flags_str[32] = {0};
if (item_size < sizeof(*ei)) {
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
ei = btrfs_item_ptr(eb, slot, struct btrfs_extent_item);
flags = btrfs_extent_flags(eb, ei);
+ extent_flags_to_str(flags, flags_str);
- printf("\t\textent refs %llu gen %llu flags %llu\n",
+ printf("\t\textent refs %llu gen %llu flags %s\n",
(unsigned long long)btrfs_extent_refs(eb, ei),
(unsigned long long)btrfs_extent_generation(eb, ei),
- (unsigned long long)flags);
+ flags_str);
if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK && !metadata) {
struct btrfs_tree_block_info *info;
struct btrfs_root_item *ri;
struct btrfs_root_item root_item;
int len;
- char uuid_str[128];
+ 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",
+ printf("\t\troot data bytenr %llu level %d dirid %llu refs %u gen %llu lastsnap %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));
+ (unsigned long long)btrfs_root_generation(&root_item),
+ (unsigned long long)btrfs_root_last_snapshot(&root_item));
if (root_item.generation == root_item.generation_v2) {
uuid_unparse(root_item.uuid, uuid_str);
case BTRFS_BLOCK_GROUP_ITEM_KEY:
printf("BLOCK_GROUP_ITEM");
break;
+ case BTRFS_FREE_SPACE_INFO_KEY:
+ printf("FREE_SPACE_INFO");
+ break;
+ case BTRFS_FREE_SPACE_EXTENT_KEY:
+ printf("FREE_SPACE_EXTENT");
+ break;
+ case BTRFS_FREE_SPACE_BITMAP_KEY:
+ printf("FREE_SPACE_BITMAP");
+ break;
case BTRFS_CHUNK_ITEM_KEY:
printf("CHUNK_ITEM");
break;
printf("BALANCE_ITEM");
break;
case BTRFS_DEV_REPLACE_KEY:
- printf("DEV_REPLACE_ITEM");
+ printf("DEV_REPLACE");
break;
case BTRFS_STRING_ITEM_KEY:
printf("STRING_ITEM");
break;
case BTRFS_QGROUP_STATUS_KEY:
- printf("BTRFS_STATUS_KEY");
+ printf("QGROUP_STATUS");
break;
case BTRFS_QGROUP_RELATION_KEY:
- printf("BTRFS_QGROUP_RELATION_KEY");
+ printf("QGROUP_RELATION");
break;
case BTRFS_QGROUP_INFO_KEY:
- printf("BTRFS_QGROUP_INFO_KEY");
+ printf("QGROUP_INFO");
break;
case BTRFS_QGROUP_LIMIT_KEY:
- printf("BTRFS_QGROUP_LIMIT_KEY");
+ printf("QGROUP_LIMIT");
break;
case BTRFS_DEV_STATS_KEY:
- printf("DEV_STATS_ITEM");
+ printf("DEV_STATS");
break;
case BTRFS_UUID_KEY_SUBVOL:
- printf("BTRFS_UUID_KEY_SUBVOL");
+ printf("UUID_KEY_SUBVOL");
break;
case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
- printf("BTRFS_UUID_KEY_RECEIVED_SUBVOL");
+ printf("UUID_KEY_RECEIVED_SUBVOL");
break;
default:
printf("UNKNOWN.%d", type);
printf("%llu", (unsigned long long)objectid); /* device id */
return;
case BTRFS_QGROUP_RELATION_KEY:
- printf("%llu/%llu", objectid >> 48,
- objectid & ((1ll << 48) - 1));
+ printf("%llu/%llu", btrfs_qgroup_level(objectid),
+ btrfs_qgroup_subvid(objectid));
return;
case BTRFS_UUID_KEY_SUBVOL:
case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
case BTRFS_UUID_TREE_OBJECTID:
printf("UUID_TREE");
break;
+ case BTRFS_FREE_SPACE_TREE_OBJECTID:
+ printf("FREE_SPACE_TREE");
+ break;
case BTRFS_MULTIPLE_OBJECTIDS:
printf("MULTIPLE");
break;
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)));
+ printf(" %llu/%llu)", btrfs_qgroup_level(offset),
+ btrfs_qgroup_subvid(offset));
break;
case BTRFS_UUID_KEY_SUBVOL:
case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
struct btrfs_dev_extent *dev_extent;
struct btrfs_disk_key disk_key;
struct btrfs_block_group_item bg_item;
+ struct btrfs_free_space_info *free_info;
struct btrfs_dir_log_item *dlog;
struct btrfs_qgroup_info_item *qg_info;
struct btrfs_qgroup_limit_item *qg_limit;
u32 nr = btrfs_header_nritems(l);
u64 objectid;
u32 type;
+ char flags_str[32];
printf("leaf %llu items %d free space %d generation %llu owner %llu\n",
(unsigned long long)btrfs_header_bytenr(l), nr,
switch (type) {
case BTRFS_INODE_ITEM_KEY:
ii = btrfs_item_ptr(l, i, struct btrfs_inode_item);
- printf("\t\tinode generation %llu transid %llu size %llu block group %llu mode %o links %u\n",
+ printf("\t\tinode generation %llu transid %llu size %llu nbytes %llu\n"
+ "\t\tblock group %llu mode %o links %u uid %u gid %u\n"
+ "\t\trdev %llu flags 0x%llx\n",
(unsigned long long)btrfs_inode_generation(l, ii),
(unsigned long long)btrfs_inode_transid(l, ii),
(unsigned long long)btrfs_inode_size(l, ii),
+ (unsigned long long)btrfs_inode_nbytes(l, ii),
(unsigned long long)btrfs_inode_block_group(l,ii),
btrfs_inode_mode(l, ii),
- btrfs_inode_nlink(l, ii));
+ btrfs_inode_nlink(l, ii),
+ btrfs_inode_uid(l, ii),
+ btrfs_inode_gid(l, ii),
+ (unsigned long long)btrfs_inode_rdev(l,ii),
+ (unsigned long long)btrfs_inode_flags(l,ii));
break;
case BTRFS_INODE_REF_KEY:
iref = btrfs_item_ptr(l, i, struct btrfs_inode_ref);
case BTRFS_EXTENT_DATA_KEY:
fi = btrfs_item_ptr(l, i,
struct btrfs_file_extent_item);
- print_file_extent_item(l, item, fi);
+ print_file_extent_item(l, item, i, fi);
break;
case BTRFS_BLOCK_GROUP_ITEM_KEY:
bi = btrfs_item_ptr(l, i,
struct btrfs_block_group_item);
read_extent_buffer(l, &bg_item, (unsigned long)bi,
sizeof(bg_item));
- printf("\t\tblock group used %llu chunk_objectid %llu flags %llu\n",
+ memset(flags_str, 0, sizeof(flags_str));
+ bg_flags_to_str(btrfs_block_group_flags(&bg_item),
+ flags_str);
+ printf("\t\tblock group used %llu chunk_objectid %llu flags %s\n",
(unsigned long long)btrfs_block_group_used(&bg_item),
(unsigned long long)btrfs_block_group_chunk_objectid(&bg_item),
- (unsigned long long)btrfs_block_group_flags(&bg_item));
+ flags_str);
+ break;
+ case BTRFS_FREE_SPACE_INFO_KEY:
+ free_info = btrfs_item_ptr(l, i, struct btrfs_free_space_info);
+ printf("\t\tfree space info extent count %u flags %u\n",
+ (unsigned)btrfs_free_space_extent_count(l, free_info),
+ (unsigned)btrfs_free_space_flags(l, free_info));
+ break;
+ case BTRFS_FREE_SPACE_EXTENT_KEY:
+ printf("\t\tfree space extent\n");
+ break;
+ case BTRFS_FREE_SPACE_BITMAP_KEY:
+ printf("\t\tfree space bitmap\n");
break;
case BTRFS_CHUNK_ITEM_KEY:
print_chunk(l, btrfs_item_ptr(l, i, struct btrfs_chunk));
case BTRFS_QGROUP_STATUS_KEY:
qg_status = btrfs_item_ptr(l, i,
struct btrfs_qgroup_status_item);
- printf("\t\tversion %llu generation %llu flags %#llx "
+ memset(flags_str, 0, sizeof(flags_str));
+ qgroup_flags_to_str(btrfs_qgroup_status_flags(l, qg_status),
+ flags_str);
+ printf("\t\tversion %llu generation %llu flags %s "
"scan %lld\n",
(unsigned long long)
btrfs_qgroup_status_version(l, qg_status),
(unsigned long long)
btrfs_qgroup_status_generation(l, qg_status),
+ flags_str,
(unsigned long long)
- btrfs_qgroup_status_flags(l, qg_status),
- (unsigned long long)
- btrfs_qgroup_status_scan(l, qg_status));
+ btrfs_qgroup_status_rescan(l, qg_status));
break;
case BTRFS_QGROUP_RELATION_KEY:
break;
qg_info = btrfs_item_ptr(l, i,
struct btrfs_qgroup_info_item);
printf("\t\tgeneration %llu\n"
- "\t\treferenced %lld referenced compressed %lld\n"
- "\t\texclusive %lld exclusive compressed %lld\n",
+ "\t\treferenced %llu referenced compressed %llu\n"
+ "\t\texclusive %llu exclusive compressed %llu\n",
(unsigned long long)
btrfs_qgroup_info_generation(l, qg_info),
- (long long)
+ (unsigned long long)
btrfs_qgroup_info_referenced(l, qg_info),
- (long long)
+ (unsigned long long)
btrfs_qgroup_info_referenced_compressed(l,
qg_info),
- (long long)
+ (unsigned long long)
btrfs_qgroup_info_exclusive(l, qg_info),
- (long long)
+ (unsigned long long)
btrfs_qgroup_info_exclusive_compressed(l,
qg_info));
break;
(unsigned long long)btrfs_header_owner(eb));
print_uuids(eb);
fflush(stdout);
- size = btrfs_level_size(root, btrfs_header_level(eb) - 1);
+ size = root->nodesize;
for (i = 0; i < nr; i++) {
u64 blocknr = btrfs_node_blockptr(eb, i);
btrfs_node_key(eb, &disk_key, i);
btrfs_node_blockptr(eb, i),
size,
btrfs_node_ptr_generation(eb, i));
- if (!next) {
+ if (!extent_buffer_uptodate(next)) {
fprintf(stderr, "failed to read %llu in tree %llu\n",
(unsigned long long)btrfs_node_blockptr(eb, i),
(unsigned long long)btrfs_header_owner(eb));