diff --git a/include/sparse.h b/include/sparse.h index 635f05d438e1284e42a21dc7ea99815174c1bd1a..3d2d8f6d7a89346325076d4bec4f081752e5d4f7 100644 --- a/include/sparse.h +++ b/include/sparse.h @@ -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 ==============================================================================*/ diff --git a/src/sparse.c b/src/sparse.c index 0450a87be13ae53a248e4963e19565d7fe0023ae..abef8ee5cee470297dc49eae069e2c9a7fdc23d3 100644 --- a/src/sparse.c +++ b/src/sparse.c @@ -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; +}