Skip to content
Snippets Groups Projects
Commit 53329b73 authored by raphael.bach's avatar raphael.bach
Browse files

Add Sparse_GuessBlockSize()

parent 99f6df76
No related branches found
No related tags found
No related merge requests found
Pipeline #
......@@ -157,6 +157,10 @@ void Sparse_PrintChunkHeader(const struct Sparse_Chunk * const header);
Sparse_DumpInfo()
------------------------------------------------------------------------------*/
void Sparse_DumpInfo(const struct Sparse * const sparse);
/*------------------------------------------------------------------------------
Sparse_GuessBlockSize()
------------------------------------------------------------------------------*/
size_t Sparse_GuessBlockSize(size_t img_size);
/*==============================================================================
GUARD
==============================================================================*/
......
......@@ -58,6 +58,9 @@ static struct Logger s_logger = {
.level_flag = LOG_LEVEL_ALL,
.output = LOG_OUTPUT_STDERR
};
static const size_t s_block_size_list[] = {
4096, 2048, 1024
};
/*==============================================================================
PUBLIC FUNCTION DEFINITION
==============================================================================*/
......@@ -333,3 +336,18 @@ void Sparse_DumpInfo(const struct Sparse * const sparse)
printf("%zu\n" , (sparse->chunks + i)->size + CHUNK_HEADER_SIZE);
}
}
/*------------------------------------------------------------------------------
Sparse_GuessBlockSize()
------------------------------------------------------------------------------*/
size_t Sparse_GuessBlockSize(size_t img_size)
{
size_t block_size = 0;
size_t array_size = sizeof(s_block_size_list) / sizeof(size_t);
for(size_t i = 0; i < array_size; i++) {
if((img_size % s_block_size_list[i]) == 0) {
block_size = s_block_size_list[i];
break;
}
}
return block_size;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment