qcow2: Add subcluster support to qcow2_get_host_offset()
The logic of this function remains pretty much the same, except that
it uses count_contiguous_subclusters(), which combines the logic of
count_contiguous_clusters() / count_contiguous_clusters_unallocated()
and checks individual subclusters.
qcow2_cluster_to_subcluster_type() is not necessary as a separate
function anymore so it's inlined into its caller.
Signed-off-by: Alberto Garcia <berto@igalia.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Message-Id: <d2193fd48653a350d80f0eca1c67b1d9053fb2f3.1594396418.git.berto@igalia.com>
[mreitz: Initialize expected_type to anything]
Signed-off-by: Max Reitz <mreitz@redhat.com>
diff --git a/block/qcow2.h b/block/qcow2.h
index 5df761e..4fad40b 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -711,29 +711,6 @@
}
/*
- * For an image without extended L2 entries, return the
- * QCow2SubclusterType equivalent of a given QCow2ClusterType.
- */
-static inline
-QCow2SubclusterType qcow2_cluster_to_subcluster_type(QCow2ClusterType type)
-{
- switch (type) {
- case QCOW2_CLUSTER_COMPRESSED:
- return QCOW2_SUBCLUSTER_COMPRESSED;
- case QCOW2_CLUSTER_ZERO_PLAIN:
- return QCOW2_SUBCLUSTER_ZERO_PLAIN;
- case QCOW2_CLUSTER_ZERO_ALLOC:
- return QCOW2_SUBCLUSTER_ZERO_ALLOC;
- case QCOW2_CLUSTER_NORMAL:
- return QCOW2_SUBCLUSTER_NORMAL;
- case QCOW2_CLUSTER_UNALLOCATED:
- return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN;
- default:
- g_assert_not_reached();
- }
-}
-
-/*
* In an image without subsclusters @l2_bitmap is ignored and
* @sc_index must be 0.
* Return QCOW2_SUBCLUSTER_INVALID if an invalid l2 entry is detected
@@ -776,7 +753,20 @@
g_assert_not_reached();
}
} else {
- return qcow2_cluster_to_subcluster_type(type);
+ switch (type) {
+ case QCOW2_CLUSTER_COMPRESSED:
+ return QCOW2_SUBCLUSTER_COMPRESSED;
+ case QCOW2_CLUSTER_ZERO_PLAIN:
+ return QCOW2_SUBCLUSTER_ZERO_PLAIN;
+ case QCOW2_CLUSTER_ZERO_ALLOC:
+ return QCOW2_SUBCLUSTER_ZERO_ALLOC;
+ case QCOW2_CLUSTER_NORMAL:
+ return QCOW2_SUBCLUSTER_NORMAL;
+ case QCOW2_CLUSTER_UNALLOCATED:
+ return QCOW2_SUBCLUSTER_UNALLOCATED_PLAIN;
+ default:
+ g_assert_not_reached();
+ }
}
}