dedup

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

commit 6dea955869804c893de2c0cd1d2b0700d72fe8ea
parent 9f38b53149dd3486e39b02d571fa5dda7ba11f83
Author: sin <sin@2f30.org>
Date:   Thu, 25 Apr 2019 14:40:58 +0100

Add magic field at the start of the storage header

Diffstat:
Mbstorage.c | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/bstorage.c b/bstorage.c @@ -37,9 +37,11 @@ #define CALGOSHIFT 16 #define CALGOMASK 0x7 +#define BHDRMAGIC "DEDUPDIDUPDIDUP" +#define NBHDRMAGIC sizeof(BHDRMAGIC) #define BDTYPE 0x100 -#define BHDRSIZE (8 + 8) +#define BHDRSIZE (NBHDRMAGIC + 8 + 8) #define BDSIZE (8 + 8 + 8 + (MDSIZE)) extern int pack(unsigned char *dst, char *fmt, ...); @@ -63,6 +65,7 @@ static struct bops bops = { /* Block header structure */ struct bhdr { + char magic[NBHDRMAGIC]; uint64_t flags; uint64_t nent; }; @@ -174,11 +177,14 @@ unpackbhdr(int fd, struct bhdr *bhdr) if (xread(fd, buf, sizeof(buf)) != sizeof(buf)) return -1; - n = unpack(buf, "qq", + n = unpack(buf, "'16qq", + bhdr->magic, &bhdr->flags, &bhdr->nent); assert(n == sizeof(buf)); + if (memcmp(bhdr->magic, BHDRMAGIC, NBHDRMAGIC) != 0) + return -1; return n; } @@ -189,7 +195,8 @@ packbhdr(int fd, struct bhdr *bhdr) unsigned char buf[BHDRSIZE]; int n; - n = pack(buf, "qq", + n = pack(buf, "'16qq", + bhdr->magic, bhdr->flags, bhdr->nent); @@ -318,6 +325,7 @@ bscreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) sctx = bctx->sctx; RB_INIT(&sctx->bdcache); bhdr = &sctx->bhdr; + memcpy(bhdr->magic, BHDRMAGIC, NBHDRMAGIC); bhdr->flags = (VMAJ << VMAJSHIFT) | VMIN; /* Set compression algorithm */