dedup

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

commit a7876bfd884b201019ba7d498347257d1869f340
parent b32c5c5b3c6b92b0a10ddc694e7df2d233c43c52
Author: sin <sin@2f30.org>
Date:   Sun, 17 Feb 2019 10:08:01 +0000

Rework lookup

Diffstat:
Mdedup.c | 25+++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -351,16 +351,14 @@ store_size(void) } int -lookup_blk(uint8_t *md, struct bdescr *bdescr) +lookup_blk(uint8_t *md) { struct cent *ent, key; memcpy(key.bdescr.md, md, sizeof(key.bdescr.md)); ent = RB_FIND(cache, &cache_head, &key); - if (ent != NULL) { - *bdescr = ent->bdescr; + if (ent != NULL) return 0; - } return -1; } @@ -389,26 +387,25 @@ dedup(int fd) else blksiz = n; - hash_blk(bp, blksiz, md); + memcpy(bdescr.md, md, sizeof(bdescr)); + bdescr.offset = store_size(); + bdescr.size = blksiz; + + hash_blk(bp, bdescr.size, bdescr.md); /* Calculate file hash one block at a time */ - SHA256_Update(&ctx, bp, blksiz); + SHA256_Update(&ctx, bp, bdescr.size); ent = grow_ent(ent, ent->nblks + 1); - if (lookup_blk(md, &bdescr) < 0) { - struct bdescr bdescr; - struct cent *cent; - /* Block not found, create new block descriptor */ - memcpy(bdescr.md, md, sizeof(bdescr)); - bdescr.offset = store_size(); - bdescr.size = blksiz; + if (lookup_blk(bdescr.md) < 0) { + struct cent *cent; /* Update index entry */ ent->bdescr[ent->nblks++] = bdescr; /* Store block */ - append_blk(bp, blksiz); + append_blk(bp, bdescr.size); /* Create a cache entry for this block */ cent = alloc_cent();