fix incorrect extent bounds

This commit is contained in:
2025-02-04 12:53:45 +00:00
parent 5c79b8140c
commit 02258f6403

View File

@@ -21,6 +21,8 @@ struct ec3_writer {
size_t w_data_offset;
size_t w_next_cluster_id;
size_t w_nr_extents;
size_t w_nr_tags;
FILE *w_data;
struct cluster_table w_cluster_table;
@@ -148,6 +150,7 @@ static enum ec3_status flush_extent_entry(struct ec3_writer *w)
return EC3_ERR_IO_FAILURE;
}
w->w_nr_extents++;
return EC3_SUCCESS;
}
@@ -181,6 +184,11 @@ void ec3_writer_finish(struct ec3_writer *w)
header.h_tag_table_offset = b_i64_htob(tag_table_offset);
header.h_extent_table_offset = b_i64_htob(extent_table_offset);
header.h_cluster_table_offset = b_i64_htob(cluster_table_offset);
header.h_tag_count = b_i32_htob(w->w_nr_tags);
header.h_extent_count = b_i32_htob(w->w_nr_extents);
header.h_app_magic = b_i64_htob(w->w_param.p_ident);
header.h_cluster_group_count
= b_i32_htob(w->w_cluster_table.t_nr_groups);
fwrite(&header, sizeof header, 1, w->w_data);
}
@@ -244,12 +252,16 @@ enum ec3_status ec3_writer_create_tag(
return EC3_ERR_IO_FAILURE;
}
w->w_nr_tags++;
*out_writer = tag;
return EC3_SUCCESS;
}
static enum ec3_status flush_tag_buffer(struct ec3_tag_writer *w)
{
printf("writing cluster %ld for 0x%llx\n",
w->w_nr_clusters,
w->w_ident);
struct ec3_writer *container = w->w_parent;
unsigned char *buf = w->w_buf;
enum ec3_status status = EC3_SUCCESS;
@@ -285,6 +297,7 @@ static enum ec3_status flush_tag_buffer(struct ec3_tag_writer *w)
}
if (container->w_extent_nr_clusters) {
// w->w_nr_clusters += container->w_extent_nr_clusters;
status = flush_extent_entry(container);
}
@@ -294,8 +307,8 @@ static enum ec3_status flush_tag_buffer(struct ec3_tag_writer *w)
container->w_extent_tag = w->w_ident;
container->w_extent_physical_start += container->w_extent_nr_clusters;
container->w_extent_logical_start = w->w_nr_clusters;
container->w_extent_nr_clusters = 0;
container->w_extent_logical_start = w->w_nr_clusters - 1;
container->w_extent_nr_clusters = 1;
return EC3_SUCCESS;
}