dedup

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

commit bf294b1ffe58f2412d592f2e099b73ce0c7daa83
parent 0dc1d8bf1eb6a00c244c2b18c8ba62bb4e9ff005
Author: sin <sin@2f30.org>
Date:   Wed, 21 Mar 2018 13:58:04 +0000

Small stylistic changes

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

diff --git a/dedup.c b/dedup.c @@ -202,7 +202,6 @@ grow_ent(struct ent *ent, uint64_t nblks) size_t sz; sz = sizeof(*ent); - /* XXX: Smarter realloc strategy */ sz += nblks * sizeof(ent->blks[0]); ent = realloc(ent, sz); if (ent == NULL) @@ -284,14 +283,15 @@ dedup(int fd) if (lookup_blk(&blk, &blkidx) == -1) { struct cache_ent *cache_ent; - uint64_t nblks = storefile_nblks(); + + blkidx = storefile_nblks(); /* Create a cache entry for this block */ - cache_ent = alloc_cache_ent(blk.md, nblks); + cache_ent = alloc_cache_ent(blk.md, blkidx); add_cache_ent(cache_ent); cache_ent->dirty = 1; - ent->blks[ent->nblks++] = nblks; + ent->blks[ent->nblks++] = blkidx; append_blk(&blk); } else { ent->blks[ent->nblks++] = blkidx; @@ -302,6 +302,7 @@ dedup(int fd) SHA256_Final(ent->md, &ctx); append_ent(ent); free(ent); + flush_cache(); } @@ -318,14 +319,14 @@ void extract(char *id, int fd) { unsigned char md[SHA256_DIGEST_LENGTH]; - struct ent *ent; - uint64_t nblks; - uint64_t i; + uint64_t nblks, i; str2bin(id, md); nblks = storefile_nblks(); lseek(ifd, sizeof(enthdr), SEEK_SET); for (i = 0; i < enthdr.nents; i++) { + struct ent *ent; + ent = alloc_ent(); if (xread(ifd, ent, sizeof(*ent)) == 0) errx(1, "unexpected EOF"); @@ -353,8 +354,7 @@ extract(char *id, int fd) void rebuild_cache(void) { - uint64_t nblks; - uint64_t i; + uint64_t nblks, i; if (verbose) fprintf(stderr, "rebuilding cache..."); @@ -377,8 +377,7 @@ rebuild_cache(void) void init_cache(void) { - uint64_t nblks; - uint64_t i; + uint64_t nblks, i; if (verbose) fprintf(stderr, "initializing cache..."); @@ -440,8 +439,7 @@ term(void) void check(void) { - uint64_t nblks; - uint64_t i, j; + uint64_t nblks, i, j; nblks = storefile_nblks(); lseek(ifd, sizeof(enthdr), SEEK_SET); @@ -485,9 +483,8 @@ list(void) for (i = 0; i < enthdr.nents; i++) { struct ent ent; - if (xread(ifd, &ent, sizeof(ent)) == 0) { + if (xread(ifd, &ent, sizeof(ent)) == 0) errx(1, "unexpected EOF"); - } dump_md(ent.md, sizeof(ent.md)); putchar('\n'); lseek(ifd, ent.nblks * sizeof(ent.blks[0]), SEEK_CUR);