dedup

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

commit ba61c65bb274657b7ea643de789db2a24ea836f8
parent 1b1447f899bb2dc4b78ec0b915c71343009ca9c5
Author: sin <sin@2f30.org>
Date:   Sat,  9 Mar 2019 22:15:26 +0000

Pass chunker params from caller

Diffstat:
Mchunker.c | 18+++++++++---------
Mdedup.c | 3++-
Mdedup.h | 4+++-
3 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/chunker.c b/chunker.c @@ -12,7 +12,6 @@ struct chunker { uint8_t *buf; int fd; - size_t cap; size_t rpos; size_t wpos; size_t min_size; @@ -131,7 +130,8 @@ get_chunk_size(struct chunker *chunker) } struct chunker * -alloc_chunker(int fd, size_t cap) +alloc_chunker(int fd, size_t min_size, size_t max_size, + size_t mask, size_t win_size) { struct chunker *chunker; @@ -139,15 +139,15 @@ alloc_chunker(int fd, size_t cap) if (chunker == NULL) err(1, "calloc"); - chunker->buf = calloc(1, cap); + chunker->buf = calloc(1, max_size); if (chunker->buf == NULL) err(1, "calloc"); + chunker->fd = fd; - chunker->cap = cap; - chunker->min_size = BLKSIZE_MIN; - chunker->max_size = BLKSIZE_MAX; - chunker->mask = HASHMASK_BITS; - chunker->win_size = WINSIZE; + chunker->min_size = min_size; + chunker->max_size = max_size; + chunker->mask = mask; + chunker->win_size = win_size; return chunker; } @@ -166,7 +166,7 @@ fill_chunker(struct chunker *chunker) ssize_t n; bp = &chunker->buf[chunker->wpos]; - n = xread(chunker->fd, bp, chunker->cap - chunker->wpos); + n = xread(chunker->fd, bp, chunker->max_size - chunker->wpos); chunker->wpos += n; return chunker->wpos; } diff --git a/dedup.c b/dedup.c @@ -233,7 +233,8 @@ dedup(int fd, char *msg) ssize_t n; snap = alloc_snap(); - chunker = alloc_chunker(fd, BLKSIZE_MAX); + chunker = alloc_chunker(fd, BLKSIZE_MIN, BLKSIZE_MAX, + HASHMASK_BITS, WINSIZE); SHA256_Init(&ctx); while ((n = fill_chunker(chunker)) > 0) { diff --git a/dedup.h b/dedup.h @@ -77,7 +77,9 @@ void add_cache_entry(struct cache *cache, struct blk_desc *desc); int lookup_cache_entry(struct cache *cache, struct blk_desc *desc); /* chunker.c */ -struct chunker *alloc_chunker(int fd, size_t cap); +struct chunker * +alloc_chunker(int fd, size_t min_size, size_t max_size, + size_t mask, size_t win_size); void free_chunker(struct chunker *chunker); ssize_t fill_chunker(struct chunker *chunker); uint8_t *get_chunk(struct chunker *chunker, size_t *chunk_size);