dedup

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

commit 8c2f8215f75e4570f9971d1bd637ff80114cd096
parent 46584d2ff6fd9566d99fc0298d1037e540afc77c
Author: sin <sin@2f30.org>
Date:   Sat, 30 Mar 2019 16:15:47 +0000

Rename some defines for consistency

Diffstat:
Mdedup.c | 18+++++++++---------
Mdedup.h | 14+++++++-------
Mtypes.c | 8++++----
3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -99,14 +99,14 @@ hash_snap(struct snap *snap, uint8_t *md) blake2b_state ctx; uint64_t i; - blake2b_init(&ctx, MDSIZE); + blake2b_init(&ctx, MD_SIZE); for (i = 0; i < snap->nr_blk_descs; i++) { struct blk_desc *blk_desc; blk_desc = &snap->blk_desc[i]; blake2b_update(&ctx, blk_desc->md, sizeof(blk_desc->md)); } - blake2b_final(&ctx, md, MDSIZE); + blake2b_final(&ctx, md, MD_SIZE); } static struct snap * @@ -174,9 +174,9 @@ hash_blk(uint8_t *buf, size_t size, uint8_t *md) { blake2b_state ctx; - blake2b_init(&ctx, MDSIZE); + blake2b_init(&ctx, MD_SIZE); blake2b_update(&ctx, buf, size); - blake2b_final(&ctx, md, MDSIZE); + blake2b_final(&ctx, md, MD_SIZE); } static void @@ -206,7 +206,7 @@ append_blk(uint8_t *buf, struct blk_desc *blk_desc) static void dedup_chunk(struct snap *snap, uint8_t *chunkp, size_t chunk_size) { - uint8_t md[MDSIZE]; + uint8_t md[MD_SIZE]; struct blk_desc blk_desc; uint8_t *compr_buf; size_t n; @@ -330,16 +330,16 @@ check_snap(struct snap *snap, void *arg) buf = alloc_buf(compr_size(BLKSIZE_MAX)); for (i = 0; i < snap->nr_blk_descs; i++) { - uint8_t md[MDSIZE]; + uint8_t md[MD_SIZE]; blake2b_state ctx; struct blk_desc *blk_desc; blk_desc = &snap->blk_desc[i]; read_blk(buf, blk_desc); - blake2b_init(&ctx, MDSIZE); + blake2b_init(&ctx, MD_SIZE); blake2b_update(&ctx, buf, blk_desc->size); - blake2b_final(&ctx, md, MDSIZE); + blake2b_final(&ctx, md, MD_SIZE); if (memcmp(blk_desc->md, md, sizeof(blk_desc->md)) == 0) continue; @@ -538,7 +538,7 @@ usage(void) int main(int argc, char *argv[]) { - uint8_t md[MDSIZE]; + uint8_t md[MD_SIZE]; char *id = NULL, *root = NULL, *msg = NULL; int iflag = 0, lflag = 0, cflag = 0; int fd = -1; diff --git a/dedup.h b/dedup.h @@ -6,13 +6,13 @@ * using the helpers from types.c. Any modification made to * the structs below will need to be reflected here and in types.c. */ -#define MSGSIZE 256 -#define MDSIZE 32 +#define MSG_SIZE 256 +#define MD_SIZE 32 #define SNAP_HDR_SIZE 104 #define BLK_HDR_SIZE 16 -#define BLK_DESC_SIZE (MDSIZE + 16) -#define SNAPSHOT_SIZE (8 + MSGSIZE + MDSIZE + 8) +#define BLK_DESC_SIZE (MD_SIZE + 16) +#define SNAPSHOT_SIZE (8 + MSG_SIZE + MD_SIZE + 8) /* file format version */ #define VER_MIN 2 @@ -51,15 +51,15 @@ struct blk_hdr { }; struct blk_desc { - uint8_t md[MDSIZE]; /* hash of block */ + uint8_t md[MD_SIZE]; /* hash of block */ uint64_t offset; /* offset into store file */ uint64_t size; /* size of block */ }; struct snap { uint64_t size; /* size of snapshot (including block descriptors) */ - uint8_t msg[MSGSIZE]; /* arbitrary message attached to snapshot */ - uint8_t md[MDSIZE]; /* hash of snapshot (hash of all block descriptor hashes) */ + uint8_t msg[MSG_SIZE]; /* arbitrary message attached to snapshot */ + uint8_t md[MD_SIZE]; /* hash of snapshot (hash of all block descriptor hashes) */ uint64_t nr_blk_descs; struct blk_desc blk_desc[]; }; diff --git a/types.c b/types.c @@ -108,7 +108,7 @@ read_blk_desc(int fd, struct blk_desc *desc) if (xread(fd, buf, sizeof(buf)) == 0) errx(1, "%s: unexpected EOF", __func__); - snprintf(fmt, sizeof(fmt), "'%dqq", MDSIZE); + snprintf(fmt, sizeof(fmt), "'%dqq", MD_SIZE); n = unpack(buf, fmt, desc->md, &desc->offset, @@ -124,7 +124,7 @@ write_blk_desc(int fd, struct blk_desc *desc) char fmt[BUFSIZ]; int n; - snprintf(fmt, sizeof(fmt), "'%dqq", MDSIZE); + snprintf(fmt, sizeof(fmt), "'%dqq", MD_SIZE); n = pack(buf, fmt, desc->md, desc->offset, @@ -144,7 +144,7 @@ read_snap(int fd, struct snap *snap) if (xread(fd, buf, sizeof(buf)) == 0) errx(1, "%s: unexpected EOF", __func__); - snprintf(fmt, sizeof(fmt), "q'%d'%dq", MSGSIZE, MDSIZE); + snprintf(fmt, sizeof(fmt), "q'%d'%dq", MSG_SIZE, MD_SIZE); n = unpack(buf, fmt, &snap->size, snap->msg, @@ -170,7 +170,7 @@ write_snap(int fd, struct snap *snap) char fmt[BUFSIZ]; int n; - snprintf(fmt, sizeof(fmt), "q'%d'%dq", MSGSIZE, MDSIZE); + snprintf(fmt, sizeof(fmt), "q'%d'%dq", MSG_SIZE, MD_SIZE); n = pack(buf, fmt, snap->size, snap->msg,