move cluster size functions and pipeline stage finders to pipeline system

This commit is contained in:
2025-02-02 20:56:29 +00:00
parent c5d8b4e881
commit 0a2919a424
3 changed files with 45 additions and 35 deletions

View File

@@ -1,4 +1,5 @@
#include "pipeline.h"
#include "bin.h"
#include <stdlib.h>
#include <string.h>
@@ -14,6 +15,14 @@ static const struct ec3_pipeline_stage_type *stage_types[] = {
};
static const size_t nr_stage_types = sizeof stage_types / sizeof stage_types[0];
static const size_t cluster_sizes[] = {
[EC3_CLUSTER_4K] = 0x1000,
[EC3_CLUSTER_8K] = 0x2000,
[EC3_CLUSTER_16K] = 0x4000,
[EC3_CLUSTER_32K] = 0x8000,
[EC3_CLUSTER_64K] = 0x10000,
};
static enum ec3_status create_pipeline_stage(
const struct ec3_pipeline_stage_type *type,
size_t cluster_size,
@@ -154,3 +163,30 @@ enum ec3_status ec3_pipeline_data_in(
{
return EC3_ERR_NOT_SUPPORTED;
}
size_t ec3_get_cluster_size(unsigned int v)
{
return cluster_sizes[v];
}
enum ec3_pipeline_stage_type_id ec3_get_pipeline_stage_for_compression_func(
unsigned int func)
{
switch (func) {
case EC3_COMPRESSION_ZSTD:
return EC3_PIPELINE_ZSTD;
default:
return EC3_PIPELINE_NONE;
}
}
enum ec3_pipeline_stage_type_id ec3_get_pipeline_stage_for_encryption_func(
unsigned int func)
{
switch (func) {
case EC3_ENCRYPTION_AES256:
return EC3_PIPELINE_AES256;
default:
return EC3_PIPELINE_NONE;
}
}

View File

@@ -71,4 +71,8 @@ extern enum ec3_status ec3_pipeline_data_in(
size_t max,
size_t *nr_read);
extern size_t ec3_get_cluster_size(unsigned int v);
extern enum ec3_pipeline_stage_id ec3_get_pipeline_stage_for_encryption_func(unsigned int func);
extern enum ec3_pipeline_stage_id ec3_get_pipeline_stage_for_compression_func(unsigned int func);
#endif

View File

@@ -41,36 +41,6 @@ struct ec3_tag_writer {
b_queue_entry w_entry;
};
static const size_t cluster_sizes[] = {
[EC3_CLUSTER_4K] = 0x1000,
[EC3_CLUSTER_8K] = 0x2000,
[EC3_CLUSTER_16K] = 0x4000,
[EC3_CLUSTER_32K] = 0x8000,
[EC3_CLUSTER_64K] = 0x10000,
};
static enum ec3_pipeline_stage_type_id pipeline_stage_for_compression_func(
unsigned int func)
{
switch (func) {
case EC3_COMPRESSION_ZSTD:
return EC3_PIPELINE_ZSTD;
default:
return EC3_PIPELINE_NONE;
}
}
static enum ec3_pipeline_stage_type_id pipeline_stage_for_encryption_func(
unsigned int func)
{
switch (func) {
case EC3_ENCRYPTION_AES256:
return EC3_PIPELINE_AES256;
default:
return EC3_PIPELINE_NONE;
}
}
enum ec3_status ec3_writer_create(
const struct ec3_parameters *param,
struct ec3_writer **out)
@@ -83,7 +53,7 @@ enum ec3_status ec3_writer_create(
memset(writer, 0x0, sizeof *writer);
memcpy(&writer->w_param, param, sizeof *param);
size_t cluster_size = cluster_sizes[param->p_cluster_size];
size_t cluster_size = ec3_get_cluster_size(param->p_cluster_size);
FILE *cluster_table = tmpfile();
@@ -95,12 +65,12 @@ enum ec3_status ec3_writer_create(
struct ec3_pipeline_stage_args stages[3] = {0};
if (param->p_compression_func != EC3_COMPRESSION_NONE) {
stages[0].type = pipeline_stage_for_compression_func(
stages[0].type = ec3_get_pipeline_stage_for_compression_func(
param->p_compression_func);
}
if (param->p_encryption_func != EC3_ENCRYPTION_NONE) {
stages[1].type = pipeline_stage_for_encryption_func(
stages[1].type = ec3_get_pipeline_stage_for_encryption_func(
param->p_encryption_func);
}
@@ -249,7 +219,7 @@ enum ec3_status ec3_writer_create_tag(
memset(tag, 0x0, sizeof *tag);
size_t cluster_size = cluster_sizes[w->w_param.p_cluster_size];
size_t cluster_size = ec3_get_cluster_size(w->w_param.p_cluster_size);
tag->w_parent = w;
tag->w_flags = flags;
@@ -336,7 +306,7 @@ enum ec3_status ec3_tag_writer_write(
size_t len)
{
size_t cluster_size
= cluster_sizes[w->w_parent->w_param.p_cluster_size];
= ec3_get_cluster_size(w->w_parent->w_param.p_cluster_size);
enum ec3_status status = EC3_SUCCESS;
unsigned char *buf = w->w_buf;