From 2555e503aad5dc892ac97cc9769d9b20ac4280b4 Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Mon, 15 Dec 2025 10:57:37 +0100 Subject: [PATCH] Force version 3 when saving content This avoid saving the content file when it was not strictly necessary because we keep the partity size. --- HISTORY | 1 + cmdline/state.c | 48 +++++++++++++----------------------------------- 2 files changed, 14 insertions(+), 35 deletions(-) diff --git a/HISTORY b/HISTORY index b5495fe8..71e9a597 100644 --- a/HISTORY +++ b/HISTORY @@ -3,6 +3,7 @@ SnapRAID HISTORY 13.1 WIP ======== + * Avoided saving the content file when it was not strictly necessary. * More log tags for the `status` command [Tristan Teufel] * Added documentation of the tags used in the log file in the new snapraid_log manpage. diff --git a/cmdline/state.c b/cmdline/state.c index 1a0de1ec..d666e439 100644 --- a/cmdline/state.c +++ b/cmdline/state.c @@ -3057,27 +3057,15 @@ 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; - + /* force version 3 a we want to always store the parity size */ /* write header */ - if (version == 3) - swrite("SNAPCNT3\n\3\0\0", 12, f); - else - swrite("SNAPCNT2\n\3\0\0", 12, f); + swrite("SNAPCNT3\n\3\0\0", 12, f); /* write block size and block max */ sputc('z', f); @@ -3086,10 +3074,8 @@ static void* state_write_thread(void* arg) sputb32(blockmax, f); /* hash size */ - if (version == 3) { - sputc('y', f); - sputb32(BLOCK_HASH_SIZE, f); - } + sputc('y', f); + sputb32(BLOCK_HASH_SIZE, f); if (serror(f)) { /* LCOV_EXCL_START */ @@ -3179,23 +3165,15 @@ static void* state_write_thread(void* arg) /* for each parity */ for (l = 0; l < state->level; ++l) { - 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); + 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 (serror(f)) { /* LCOV_EXCL_START */