iMinor refactoring - dedup - deduplicating backup program Err bitreich.org 70 hgit clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ URL:git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ bitreich.org 70 1Log /scm/dedup/log.gph bitreich.org 70 1Files /scm/dedup/files.gph bitreich.org 70 1Refs /scm/dedup/refs.gph bitreich.org 70 1Tags /scm/dedup/tag bitreich.org 70 1README /scm/dedup/file/README.gph bitreich.org 70 1LICENSE /scm/dedup/file/LICENSE.gph bitreich.org 70 i--- Err bitreich.org 70 1commit 44ce796d4a5c9a22d136f4f4c37596254d70bee3 /scm/dedup/commit/44ce796d4a5c9a22d136f4f4c37596254d70bee3.gph bitreich.org 70 1parent fe4061d87b77bf2789310758b799078da594f2bf /scm/dedup/commit/fe4061d87b77bf2789310758b799078da594f2bf.gph bitreich.org 70 hAuthor: sin URL:mailto:sin@2f30.org bitreich.org 70 iDate: Tue, 20 Mar 2018 18:03:17 +0000 Err bitreich.org 70 i Err bitreich.org 70 iMinor refactoring Err bitreich.org 70 i Err bitreich.org 70 iDiffstat: Err bitreich.org 70 i M dedup.c | 20 +++++++++++++------- Err bitreich.org 70 i Err bitreich.org 70 i1 file changed, 13 insertions(+), 7 deletions(-) Err bitreich.org 70 i--- Err bitreich.org 70 1diff --git a/dedup.c b/dedup.c /scm/dedup/file/dedup.c.gph bitreich.org 70 i@@ -19,7 +19,7 @@ struct enthdr { Err bitreich.org 70 i } __attribute__((packed)); Err bitreich.org 70 i Err bitreich.org 70 i struct ent { Err bitreich.org 70 i- uint64_t sz; Err bitreich.org 70 i+ uint64_t sz; /* size of entire entry structure */ Err bitreich.org 70 i unsigned char md[SHA256_DIGEST_LENGTH]; Err bitreich.org 70 i uint64_t nblks; Err bitreich.org 70 i uint64_t blks[]; Err bitreich.org 70 i@@ -90,10 +90,12 @@ dump_blk(struct blk *blk) Err bitreich.org 70 i void Err bitreich.org 70 i append_ent(struct ent *ent) Err bitreich.org 70 i { Err bitreich.org 70 i+ /* Update index header */ Err bitreich.org 70 i enthdr.nents++; Err bitreich.org 70 i lseek(ifd, 0, SEEK_SET); Err bitreich.org 70 i write(ifd, &enthdr, sizeof(enthdr)); Err bitreich.org 70 i Err bitreich.org 70 i+ /* Append entry */ Err bitreich.org 70 i lseek(ifd, 0, SEEK_END); Err bitreich.org 70 i ent->sz = sizeof(*ent); Err bitreich.org 70 i ent->sz += ent->nblks * sizeof(ent->blks[0]); Err bitreich.org 70 i@@ -117,6 +119,7 @@ grow_ent(struct ent *ent, uint64_t nblks) Err bitreich.org 70 i size_t sz; Err bitreich.org 70 i Err bitreich.org 70 i sz = sizeof(*ent); Err bitreich.org 70 i+ /* XXX: Smarter realloc strategy */ Err bitreich.org 70 i sz += nblks * sizeof(ent->blks[0]); Err bitreich.org 70 i ent = realloc(ent, sz); Err bitreich.org 70 i if (ent == NULL) Err bitreich.org 70 i@@ -185,7 +188,10 @@ dedup(int fd) Err bitreich.org 70 i hash_blk(&blk); Err bitreich.org 70 i if (verbose) Err bitreich.org 70 i dump_blk(&blk); Err bitreich.org 70 i+ Err bitreich.org 70 i+ /* Rolling hash of input stream */ Err bitreich.org 70 i SHA256_Update(&ctx, blk.data, blk.sz); Err bitreich.org 70 i+ /* Prepare for adding a new block index for this entry */ Err bitreich.org 70 i ent = grow_ent(ent, ent->nblks + 1); Err bitreich.org 70 i Err bitreich.org 70 i if (lookup_blk(&blk, &blkidx) == -1) { Err bitreich.org 70 i@@ -203,19 +209,19 @@ dedup(int fd) Err bitreich.org 70 i if (n < 0) Err bitreich.org 70 i err(1, "read"); Err bitreich.org 70 i Err bitreich.org 70 i+ /* Calculate hash and add this entry to the index */ Err bitreich.org 70 i SHA256_Final(ent->md, &ctx); Err bitreich.org 70 i append_ent(ent); Err bitreich.org 70 i free(ent); Err bitreich.org 70 i } Err bitreich.org 70 i Err bitreich.org 70 i void Err bitreich.org 70 i-str2id(unsigned char *idstr, uint8_t *id) Err bitreich.org 70 i+str2bin(unsigned char *s, uint8_t *d) Err bitreich.org 70 i { Err bitreich.org 70 i- size_t i, len = strlen(idstr) / 2; Err bitreich.org 70 i- char *p = idstr; Err bitreich.org 70 i+ size_t i, len = strlen(s) / 2; Err bitreich.org 70 i Err bitreich.org 70 i- for (i = 0; i < len; i++, p += 2) Err bitreich.org 70 i- sscanf(p, "%2hhx", &id[i]); Err bitreich.org 70 i+ for (i = 0; i < len; i++, s += 2) Err bitreich.org 70 i+ sscanf(s, "%2hhx", &d[i]); Err bitreich.org 70 i } Err bitreich.org 70 i Err bitreich.org 70 i void Err bitreich.org 70 i@@ -225,7 +231,7 @@ extract(unsigned char *id, int fd) Err bitreich.org 70 i struct ent *ent; Err bitreich.org 70 i uint64_t i; Err bitreich.org 70 i Err bitreich.org 70 i- str2id(id, md); Err bitreich.org 70 i+ str2bin(id, md); Err bitreich.org 70 i lseek(ifd, sizeof(enthdr), SEEK_SET); Err bitreich.org 70 i for (i = 0; i < enthdr.nents; i++) { Err bitreich.org 70 i ent = alloc_ent(); Err bitreich.org 70 .