dedup

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

commit bfeed4a4f620d817f12f6f3d11043c06f1c53b80
parent d6d133da1f296f09aa158c4e7ab40824e2dbfc19
Author: sin <sin@2f30.org>
Date:   Wed,  1 May 2019 13:45:54 +0100

Reflect hash type in the block descriptor type

Diffstat:
Mbstorage.c | 21++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/bstorage.c b/bstorage.c @@ -40,7 +40,8 @@ #define BHDRMAGIC "DEDUPDIDUPDIDUP" #define NBHDRMAGIC sizeof(BHDRMAGIC) -#define BDTYPE 0x100 +#define BD2BTYPE 0x100 +#define BD2STYPE 0x101 #define BHDRSIZE (NBHDRMAGIC + 8 + 8) #define BDSIZE (8 + 8 + 8 + 8 + (MDSIZE)) @@ -242,7 +243,7 @@ loadbd(struct sctx *sctx) return -1; } - if (bd->type != BDTYPE) { + if (bd->type != BD2BTYPE && bd->type != BD2STYPE) { free(bd); return -1; } @@ -330,8 +331,10 @@ bscreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) /* Set hash type */ if (strcmp(bpar->halgo, "blake2b") == 0) { bhdr->flags |= HBLAKE2BTYPE << HALGOSHIFT; + sctx->type = BD2BTYPE; } else if (strcmp(bpar->halgo, "blake2s") == 0) { bhdr->flags |= HBLAKE2STYPE << HALGOSHIFT; + sctx->type = BD2STYPE; } else { free(sctx); close(fd); @@ -339,7 +342,6 @@ bscreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) } bhdr->nbd = 0; sctx->fd = fd; - sctx->type = (bhdr->flags >> HALGOSHIFT) & HALGOMASK; if (packbhdr(fd, bhdr) < 0) { free(sctx); @@ -422,9 +424,11 @@ bsopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) switch (halgo) { case HBLAKE2BTYPE: bpar->halgo = "blake2b"; + sctx->type = BD2BTYPE; break; case HBLAKE2STYPE: bpar->halgo = "blake2s"; + sctx->type = BD2STYPE; break; default: free(sctx); @@ -434,7 +438,6 @@ bsopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) sctx->fd = fd; sctx->rdonly = flags == O_RDONLY; - sctx->type = halgo; if (initbdcache(sctx) < 0) { free(sctx); @@ -456,11 +459,11 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) sctx = bctx->sctx; switch (sctx->type) { - case HBLAKE2BTYPE: + case BD2BTYPE: if (b2bhash(buf, n, key.md) < 0) return -1; break; - case HBLAKE2STYPE: + case BD2STYPE: if (b2shash(buf, n, key.md) < 0) return -1; break; @@ -494,7 +497,7 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) bd = calloc(1, sizeof(*bd)); if (bd == NULL) return -1; - bd->type = BDTYPE; + bd->type = sctx->type; bd->offset = offs + BDSIZE; bd->size = n; bd->refcnt = 1; @@ -640,13 +643,13 @@ bscheck(struct bctx *bctx, unsigned char *md) } switch (sctx->type) { - case HBLAKE2BTYPE: + case BD2BTYPE: if (b2bhash(buf, bd->size, key.md) < 0) { free(buf); return -1; } break; - case HBLAKE2STYPE: + case BD2STYPE: if (b2shash(buf, bd->size, key.md) < 0) { free(buf); return -1;