dedup

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

commit 0dbd594d0b2c51df4b6cfe6f837322b002ccfee2
parent 9817f61535da145c316a4bb5861ed913bc16b4cf
Author: sin <sin@2f30.org>
Date:   Tue, 26 Feb 2019 11:16:14 +0000

Break out snaphdr loading

Diffstat:
Mdedup.c | 41+++++++++++++++++++++++------------------
1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -456,10 +456,31 @@ load_cache(void) } static void -init(void) +load_snaphdr(void) { + uint8_t maj, min; struct stat sb; + if (fstat(ifd, &sb) < 0) + err(1, "fstat %s", SNAPSF); + if (sb.st_size == 0) { + snaphdr.flags = (VER_MAJ << 8) | VER_MIN; + snaphdr.st.min_blk_size = comp_size(BLKSIZE_MAX); + write_snaphdr(ifd, &snaphdr); + return; + } + + read_snaphdr(ifd, &snaphdr); + min = snaphdr.flags & 0xff; + maj = (snaphdr.flags >> 8) & 0xff; + if (maj != VER_MAJ || min != VER_MIN) + errx(1, "format version mismatch: expected %u.%u but got %u.%u", + VER_MAJ, VER_MIN, maj, min); +} + +static void +init(void) +{ ifd = open(SNAPSF, O_RDWR | O_CREAT, 0600); if (ifd < 0) err(1, "open %s", SNAPSF); @@ -477,23 +498,7 @@ init(void) flock(cfd, LOCK_NB | LOCK_EX) < 0) errx(1, "busy lock"); - if (fstat(ifd, &sb) < 0) - err(1, "fstat %s", SNAPSF); - if (sb.st_size != 0) { - uint8_t maj, min; - - read_snaphdr(ifd, &snaphdr); - min = snaphdr.flags & 0xff; - maj = (snaphdr.flags >> 8) & 0xff; - - if (maj != VER_MAJ || min != VER_MIN) - errx(1, "expected snapshot format version %u.%u but got %u.%u", - VER_MAJ, VER_MIN, maj, min); - } else { - snaphdr.flags = (VER_MAJ << 8) | VER_MIN; - snaphdr.st.min_blk_size = comp_size(BLKSIZE_MAX); - write_snaphdr(ifd, &snaphdr); - } + load_snaphdr(); cache = alloc_cache(); if (cache_nr_entries() != 0)