From 45aba42fba7ae2a768606e08cece87a4aed987a6 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 28 May 2009 16:07:05 +0200 Subject: qcow2: Split out guest cluster functions qcow2-cluster.c contains all functions related to the management of guest clusters, i.e. what the guest sees on its virtual disk. This code is about mapping these guest clusters to host clusters in the image file using the two-level lookup tables. Signed-off-by: Kevin Wolf Signed-off-by: Anthony Liguori --- block/qcow2-refcount.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'block/qcow2-refcount.c') diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index b70afe9639..3f461c6890 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -389,6 +389,34 @@ void free_clusters(BlockDriverState *bs, update_refcount(bs, offset, size, -1); } +/* + * free_any_clusters + * + * free clusters according to its type: compressed or not + * + */ + +void free_any_clusters(BlockDriverState *bs, + uint64_t cluster_offset, int nb_clusters) +{ + BDRVQcowState *s = bs->opaque; + + /* free the cluster */ + + if (cluster_offset & QCOW_OFLAG_COMPRESSED) { + int nb_csectors; + nb_csectors = ((cluster_offset >> s->csize_shift) & + s->csize_mask) + 1; + free_clusters(bs, (cluster_offset & s->cluster_offset_mask) & ~511, + nb_csectors * 512); + return; + } + + free_clusters(bs, cluster_offset, nb_clusters << s->cluster_bits); + + return; +} + /*********************************************************/ -- cgit v1.2.1