From 3834b43878ac0fe1cfd255cd2cdd32023994bb2f Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Tue, 10 Jan 2023 09:21:44 +0100 Subject: [PATCH] qcow: Fix number of refcount table entries The number of entries in the refcount table was incorrectly calculated given there was no need for dividing the number of refblock clusters. The number of refblock clusters is the number of entries in the refcount table. Suggested-by: lv_mz Signed-off-by: Sebastien Boeuf (cherry picked from commit 0e7d5d27611631306f2df2d9e55d0610f441e3eb) --- qcow/src/qcow.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/qcow/src/qcow.rs b/qcow/src/qcow.rs index c22e32dcb..47e22fd71 100644 --- a/qcow/src/qcow.rs +++ b/qcow/src/qcow.rs @@ -777,10 +777,8 @@ impl QcowFile { refcounts: &mut [u16], cluster_size: u64, refblock_clusters: u64, - pointers_per_cluster: u64, ) -> Result> { - let refcount_table_entries = div_round_up_u64(refblock_clusters, pointers_per_cluster); - let mut ref_table = vec![0; refcount_table_entries as usize]; + let mut ref_table = vec![0; refblock_clusters as usize]; let mut first_free_cluster: u64 = 0; for refblock_addr in &mut ref_table { loop { @@ -907,12 +905,7 @@ impl QcowFile { set_refcount_table_refcounts(&mut refcounts, header, cluster_size)?; // Allocate clusters to store the new reference count blocks. - let ref_table = alloc_refblocks( - &mut refcounts, - cluster_size, - refblock_clusters, - pointers_per_cluster, - )?; + let ref_table = alloc_refblocks(&mut refcounts, cluster_size, refblock_clusters)?; // Write updated reference counts and point the reftable at them. write_refblocks(