From fdbddd580039f0266fe1b962df36d8151e94c3b1 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 24 Feb 2025 15:51:05 +0000 Subject: [PATCH] fix slightly incorrect cluster boundaries written by shadow_image --- src/shadow-image.c | 14 ++++++++------ src/shadow-image.h | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/shadow-image.c b/src/shadow-image.c index 7aef0c9..a09a63d 100644 --- a/src/shadow-image.c +++ b/src/shadow-image.c @@ -106,6 +106,7 @@ enum ec3_status shadow_image_init( cluster_table_init_empty_table(&out->img_cluster_table); out->img_nr_bytes = sizeof header; + out->img_cluster_data_offset = out->img_nr_bytes; out->img_extent_table = b_buffer_create(sizeof(struct ec3_extent_info)); out->img_tag_table = b_buffer_create(sizeof(struct ec3_tag_info)); @@ -434,7 +435,7 @@ static enum ec3_status put_empty_cluster( struct cluster cluster = {0}; cluster.c_id = image->img_nr_clusters; - cluster.c_base = image->img_nr_bytes; + cluster.c_base = image->img_nr_bytes - image->img_cluster_data_offset; cluster.c_len = encoded_size; image->img_nr_clusters++; @@ -493,7 +494,7 @@ static enum ec3_status copy_cached_cluster( struct cluster cluster = {0}; cluster.c_id = image->img_nr_clusters; - cluster.c_base = image->img_nr_bytes; + cluster.c_base = image->img_nr_bytes - image->img_cluster_data_offset; cluster.c_len = encoded_size; image->img_nr_clusters++; @@ -577,7 +578,8 @@ static enum ec3_status copy_cluster_range( } cluster.c_id = dest->img_nr_clusters; - cluster.c_base = dest->img_nr_bytes; + cluster.c_base + = dest->img_nr_bytes - dest->img_cluster_data_offset; size_t nr_written = 0; status2 = b_file_write( @@ -611,7 +613,7 @@ static enum ec3_status write_wseq_tag( { size_t cluster_id_offset = dest->img_nr_clusters; size_t cluster_id_limit = cluster_id_offset; - size_t data_offset = dest->img_nr_bytes; + size_t data_offset = dest->img_nr_bytes - dest->img_cluster_data_offset; size_t first_logical_cluster = 0; struct cluster_table *clusters = &ioctx->io_cluster_table; @@ -785,7 +787,7 @@ enum ec3_status shadow_image_write_tag( return status; } - size_t last_cluster = dest->img_nr_clusters; + size_t nr_clusters = dest->img_nr_clusters - first_cluster; struct ec3_extent_info *extent = NULL; b_buffer_push_back(dest->img_extent_table, 1, (void **)&extent); @@ -793,7 +795,7 @@ enum ec3_status shadow_image_write_tag( extent->ex_owner = tag->tag_ident; extent->ex_logical_cluster = 0; extent->ex_physical_cluster = first_cluster; - extent->ex_count = last_cluster - first_cluster; + extent->ex_count = nr_clusters; b_buffer_append(dest->img_tag_table, tag, 1); diff --git a/src/shadow-image.h b/src/shadow-image.h index 98a040d..2ac71ca 100644 --- a/src/shadow-image.h +++ b/src/shadow-image.h @@ -15,6 +15,7 @@ struct ec3_tag_info; struct shadow_image { size_t img_nr_clusters; size_t img_nr_bytes; + size_t img_cluster_data_offset; struct b_file *img_f_data; struct b_file *img_f_cluster_table; struct cluster_table img_cluster_table;