btrfs-progs: convert: add missing types header
[platform/upstream/btrfs-progs.git] / print-tree.c
index c752ba2..cee30bf 100644 (file)
@@ -198,9 +198,17 @@ void print_chunk_item(struct extent_buffer *eb, struct btrfs_chunk *chunk)
 {
        u16 num_stripes = btrfs_chunk_num_stripes(eb, chunk);
        int i;
-       u32 chunk_item_size = btrfs_chunk_item_size(num_stripes);
+       u32 chunk_item_size;
        char chunk_flags_str[32] = {0};
 
+       /* The chunk must contain at least one stripe */
+       if (num_stripes < 1) {
+               printf("invalid num_stripes: %u\n", num_stripes);
+               return;
+       }
+
+       chunk_item_size = btrfs_chunk_item_size(num_stripes);
+
        if ((unsigned long)chunk + chunk_item_size > eb->len) {
                printf("\t\tchunk item invalid\n");
                return;
@@ -315,6 +323,9 @@ static void compress_type_to_str(u8 compress_type, char *ret)
        case BTRFS_COMPRESS_LZO:
                strcpy(ret, "lzo");
                break;
+       case BTRFS_COMPRESS_ZSTD:
+               strcpy(ret, "zstd");
+               break;
        default:
                sprintf(ret, "UNKNOWN.%d", compress_type);
        }
@@ -783,6 +794,17 @@ void btrfs_print_key(struct btrfs_disk_key *disk_key)
        case BTRFS_UUID_KEY_RECEIVED_SUBVOL:
                printf(" 0x%016llx)", (unsigned long long)offset);
                break;
+
+       /*
+        * Key offsets of ROOT_ITEM point to tree root, print them in human
+        * readable format.  Especially useful for trees like data/tree reloc
+        * tree, whose tree id can be negative.
+        */
+       case BTRFS_ROOT_ITEM_KEY:
+               printf(" ");
+               print_objectid(stdout, offset, type);
+               printf(")");
+               break;
        default:
                if (offset == (u64)-1)
                        printf(" -1)");
@@ -1247,7 +1269,7 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *eb)
                        break;
                case BTRFS_EXTENT_CSUM_KEY:
                        print_extent_csum(eb, root->fs_info, item_size,
-                                       disk_key.offset);
+                                       offset);
                        break;
                case BTRFS_EXTENT_DATA_KEY:
                        print_file_extent_item(eb, item, i, ptr);