From 10a308396ee20f89e292a05edfeb153eee841e35 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sun, 15 May 2016 14:49:41 +0200 Subject: [PATCH] Don't upgrade the content file to version 3 if possible This avoids to make it incompatible with old versions. --- cmdline/state.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/cmdline/state.c b/cmdline/state.c index 743905a8..102cc31d 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -2848,14 +2848,27 @@ static void* state_write_thread(void* arg) block_off_t idx; block_off_t begin; unsigned l, s; + int version; count_file = 0; count_hardlink = 0; count_symlink = 0; count_dir = 0; + /* check what version to use */ + version = 2; + for (l = 0; l < state->level; ++l) { + if (state->parity[l].split_mac > 1) + version = 3; + } + if (BLOCK_HASH_SIZE != 16) + version = 3; + /* write header */ - swrite("SNAPCNT3\n\3\0\0", 12, f); + if (version == 3) + swrite("SNAPCNT3\n\3\0\0", 12, f); + else + swrite("SNAPCNT2\n\3\0\0", 12, f); /* write block size and block max */ sputc('z', f); @@ -2864,8 +2877,10 @@ static void* state_write_thread(void* arg) sputb32(blockmax, f); /* hash size */ - sputc('y', f); - sputb32(BLOCK_HASH_SIZE, f); + if (version == 3) { + sputc('y', f); + sputb32(BLOCK_HASH_SIZE, f); + } if (serror(f)) { /* LCOV_EXCL_START */ @@ -2951,15 +2966,23 @@ static void* state_write_thread(void* arg) /* for each parity */ for (l = 0; l < state->level; ++l) { - sputc('Q', f); - sputb32(l, f); - sputb32(state->parity[l].total_blocks, f); - sputb32(state->parity[l].free_blocks, f); - sputb32(state->parity[l].split_mac, f); - for (s = 0; s < state->parity[l].split_mac; ++s) { - sputbs(state->parity[l].split_map[s].path, f); - sputbs(state->parity[l].split_map[s].uuid, f); - sputb64(state->parity[l].split_map[s].size, f); + if (version == 3) { + sputc('Q', f); + sputb32(l, f); + sputb32(state->parity[l].total_blocks, f); + sputb32(state->parity[l].free_blocks, f); + sputb32(state->parity[l].split_mac, f); + for (s = 0; s < state->parity[l].split_mac; ++s) { + sputbs(state->parity[l].split_map[s].path, f); + sputbs(state->parity[l].split_map[s].uuid, f); + sputb64(state->parity[l].split_map[s].size, f); + } + } else { + sputc('P', f); + sputb32(l, f); + sputb32(state->parity[l].total_blocks, f); + sputb32(state->parity[l].free_blocks, f); + sputbs(state->parity[l].split_map[0].uuid, f); } if (serror(f)) { /* LCOV_EXCL_START */