dedup

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

commit 9eb852d729dd0e58a51d453beb76b3fb3d420084
parent e45da8785b9e8436fb747f023743c910b06f36b5
Author: sin <sin@2f30.org>
Date:   Mon, 18 Feb 2019 19:24:24 +0000

Encode file format version in the bottom 16 bits of flags

Diffstat:
MTODO | 1-
Mdedup.c | 19++++++++++++++++++-
2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/TODO b/TODO @@ -1,4 +1,3 @@ endianness agnostic -version field in entry header file locking overflow checks diff --git a/dedup.c b/dedup.c @@ -23,6 +23,10 @@ #define MSGSIZE 256 #define MDSIZE SHA256_DIGEST_LENGTH +/* file format version */ +#define VER_MIN 0 +#define VER_MAJ 0 + #define ROTL(x, y) (((x) << (y)) | ((x) >> (32 - (y)))) enum { @@ -676,8 +680,21 @@ init(void) if (fstat(ifd, &sb) < 0) err(1, "fstat %s", INDEXF); - if (sb.st_size != 0) + if (sb.st_size != 0) { + uint8_t maj, min; + xread(ifd, &enthdr, sizeof(enthdr)); + min = enthdr.flags & 0xff; + maj = (enthdr.flags >> 8) & 0xff; + + if (maj != VER_MAJ || min != VER_MIN) + errx(1, "expected index format version %u.%u but got %u.%u", + VER_MAJ, VER_MIN, maj, min); + } else { + enthdr.flags = (VER_MAJ << 8) | VER_MIN; + xwrite(ifd, &enthdr, sizeof(enthdr)); + } + if (verbose) { fprintf(stderr, "original size: %llu bytes\n", (unsigned long long)enthdr.st.orig_size);