dedup

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

commit bdab7844c3c3299f59eadea85b6e709ab0acad86
parent 312b8de3f21fe167b82d288362442364c51a0431
Author: sin <sin@2f30.org>
Date:   Wed, 20 Feb 2019 12:53:53 +0000

Unbreak block descriptor configuration

In case of a cache hit, the block descriptor was totally wrong.

Diffstat:
Mdedup.c | 22++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -448,14 +448,16 @@ append_blk(uint8_t *buf, struct bdescr *bdescr) } int -lookup_blk(uint8_t *md) +lookup_bdescr(uint8_t *md, struct bdescr *bdescr) { struct cent *ent, key; memcpy(key.bdescr.md, md, sizeof(key.bdescr.md)); ent = RB_FIND(cache, &cache_head, &key); - if (ent != NULL) + if (ent != NULL) { + *bdescr = ent->bdescr; return 0; + } return -1; } @@ -488,22 +490,22 @@ dedup(int fd, char *msg) blksize = chunk_blk(inp, bufsize); csize = comp(inp, outp, blksize, comp_size(BLKSIZE)); - memcpy(bdescr.md, md, sizeof(bdescr)); - bdescr.offset = enthdr.store_size; - bdescr.size = csize; - - enthdr.st.comp_size += bdescr.size; + enthdr.st.comp_size += csize; - hash_blk(outp, bdescr.size, bdescr.md); + hash_blk(outp, csize, md); /* Calculate file hash one block at a time */ - SHA256_Update(&ctx, outp, bdescr.size); + SHA256_Update(&ctx, outp, csize); ent = grow_ent(ent, ent->nblks + 1); - if (lookup_blk(bdescr.md) < 0) { + if (lookup_bdescr(md, &bdescr) < 0) { struct cent *cent; + memcpy(bdescr.md, md, sizeof(bdescr.md)); + bdescr.offset = enthdr.store_size; + bdescr.size = csize; + /* Update index entry */ ent->bdescr[ent->nblks++] = bdescr;