dedup

deduplicating backup program
git clone git://git.2f30.org/dedup
Log | Files | Refs | README | LICENSE

commit 4122001dbfb14b263965c955e865a6c04151fbbc
parent 4106dd721d10db6f7ba0fe25009a85be8c5bee61
Author: sin <sin@2f30.org>
Date:   Sun, 10 Mar 2019 10:25:26 +0000

Factor out snapshot hash calculation to a function

Diffstat:
Mdedup.c | 37+++++++++++++++++++++----------------
1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -88,6 +88,26 @@ free_snap(struct snapshot *snap) free(snap); } +/* + * The snapshot hash is calculated over the + * hash of its block descriptors. + */ +static void +hash_snap(struct snapshot *snap, uint8_t *md) +{ + SHA256_CTX ctx; + uint64_t i; + + SHA256_Init(&ctx); + for (i = 0; i < snap->nr_blk_descs; i++) { + struct blk_desc *blk_desc; + + blk_desc = &snap->blk_desc[i]; + SHA256_Update(&ctx, blk_desc->md, sizeof(blk_desc->md)); + } + SHA256_Final(md, &ctx); +} + static struct snapshot * grow_snap(struct snapshot *snap, uint64_t nr_blk_descs) { @@ -245,22 +265,7 @@ dedup(int fd, char *msg) } if (snap->nr_blk_descs > 0) { - SHA256_CTX ctx; - uint64_t i; - - /* - * The snapshot hash is calculated over the - * hash of its block descriptors. - */ - SHA256_Init(&ctx); - for (i = 0; i < snap->nr_blk_descs; i++) { - struct blk_desc *blk_desc; - - blk_desc = &snap->blk_desc[i]; - SHA256_Update(&ctx, blk_desc->md, - sizeof(blk_desc->md)); - } - SHA256_Final(snap->md, &ctx); + hash_snap(snap, snap->md); if (msg != NULL) { size_t size;