tPass chunker params from caller - dedup - deduplicating backup program
(HTM) git clone git://git.z3bra.org/dedup.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit ba61c65bb274657b7ea643de789db2a24ea836f8
(DIR) parent 1b1447f899bb2dc4b78ec0b915c71343009ca9c5
(HTM) Author: sin <sin@2f30.org>
Date: Sat, 9 Mar 2019 22:15:26 +0000
Pass chunker params from caller
Diffstat:
M chunker.c | 18 +++++++++---------
M dedup.c | 3 ++-
M dedup.h | 4 +++-
3 files changed, 14 insertions(+), 11 deletions(-)
---
(DIR) diff --git a/chunker.c b/chunker.c
t@@ -12,7 +12,6 @@
struct chunker {
uint8_t *buf;
int fd;
- size_t cap;
size_t rpos;
size_t wpos;
size_t min_size;
t@@ -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;
t@@ -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;
}
t@@ -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;
}
(DIR) diff --git a/dedup.c b/dedup.c
t@@ -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) {
(DIR) diff --git a/dedup.h b/dedup.h
t@@ -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);