From 715a4be2a0b5624e60928f12adf6d51c56ad282b Mon Sep 17 00:00:00 2001 From: Andrea Mazzoleni Date: Sat, 22 Feb 2014 07:47:34 +0100 Subject: [PATCH] New option to relax the content file checks. --- snapraid.c | 7 +++++++ state.c | 45 ++++++++++++++++++++++++++++++++++----------- state.h | 1 + 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/snapraid.c b/snapraid.c index b1b23568..ccb4c85e 100644 --- a/snapraid.c +++ b/snapraid.c @@ -104,6 +104,7 @@ void memory(void) #define OPT_TEST_FORCE_SCRUB_EVEN 272 #define OPT_TEST_FORCE_CONTENT_WRITE 273 #define OPT_TEST_FORCE_CONTENT_TEXT 274 +#define OPT_TEST_SKIP_CONTENT_CHECK 275 #if HAVE_GETOPT_LONG struct option long_options[] = { @@ -185,6 +186,9 @@ struct option long_options[] = { /* Force the use of text content file . */ { "test-force-content-text", 0, 0, OPT_TEST_FORCE_CONTENT_TEXT }, + /* Relax the checks done at the content file */ + { "test-skip-content-check", 0, 0, OPT_TEST_SKIP_CONTENT_CHECK }, + { 0, 0, 0, 0 } }; #endif @@ -399,6 +403,9 @@ int main(int argc, char* argv[]) case OPT_TEST_SKIP_DEVICE : opt.skip_device = 1; break; + case OPT_TEST_SKIP_CONTENT_CHECK : + opt.skip_content_check = 1; + break; case OPT_TEST_FORCE_MURMUR3 : opt.force_murmur3 = 1; break; diff --git a/state.c b/state.c index 560607d2..b03932ce 100644 --- a/state.c +++ b/state.c @@ -2242,7 +2242,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* check for impossible file size to avoid to crash for a too big allocation */ if (v_size / state->block_size > blockmax) { decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in file size!\n"); + fprintf(stderr, "Internal inconsistency in file size too big!\n"); exit(EXIT_FAILURE); } @@ -2316,9 +2316,15 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST } if (v_pos + v_count > blockmax) { - decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in block size!\n"); - exit(EXIT_FAILURE); + if (state->opt.skip_content_check) { + fprintf(stderr, "Internal inconsistency in block size!\n"); + fprintf(stderr, "Overriding from %u to %u...\n", blockmax, v_pos + v_count); + blockmax = v_pos + v_count; + } else { + fprintf(stderr, "Internal inconsistency in block size!\n"); + decoding_error(path, f); + exit(EXIT_FAILURE); + } } /* grow the array */ @@ -2419,9 +2425,15 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST } if (v_pos + v_count > blockmax) { - decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in info size!\n"); - exit(EXIT_FAILURE); + if (state->opt.skip_content_check) { + fprintf(stderr, "Internal inconsistency in info size!\n"); + fprintf(stderr, "Overriding from %u to %u...\n", blockmax, v_pos + v_count); + blockmax = v_pos + v_count; + } else { + decoding_error(path, f); + fprintf(stderr, "Internal inconsistency in info size!\n"); + exit(EXIT_FAILURE); + } } ret = sgetb32(f, &flag); @@ -2507,9 +2519,15 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST } if (v_pos + v_count > blockmax) { - decoding_error(path, f); - fprintf(stderr, "Internal inconsistency in hole size!\n"); - exit(EXIT_FAILURE); + if (state->opt.skip_content_check) { + fprintf(stderr, "Internal inconsistency in hole size!\n"); + fprintf(stderr, "Overriding from %u to %u...\n", blockmax, v_pos + v_count); + blockmax = v_pos + v_count; + } else { + decoding_error(path, f); + fprintf(stderr, "Internal inconsistency in hole size!\n"); + exit(EXIT_FAILURE); + } } /* get the subcommand */ @@ -2849,7 +2867,12 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST /* check that the stored parity size matches the loaded state */ if (blockmax != parity_size(state)) { fprintf(stderr, "Internal inconsistency in parity size in '%s' at offset %"PRIi64"\n", path, stell(f)); - exit(EXIT_FAILURE); + if (state->opt.skip_content_check) { + fprintf(stderr, "Overriding from %u to %u...\n", blockmax, parity_size(state)); + blockmax = parity_size(state); + } else { + exit(EXIT_FAILURE); + } } /* set the required parity size */ diff --git a/state.h b/state.h index d68e201e..35930624 100644 --- a/state.h +++ b/state.h @@ -71,6 +71,7 @@ struct snapraid_option { int skip_sequential; /**< Skip sequential hint. */ int skip_lock; /**< Skip the lock file protection. */ int skip_self; /**< Skip the self-test. */ + int skip_content_check; /**< Relax some content file checks. */ int kill_after_sync; /**< Kill the process after sync without saving the final state. */ int force_murmur3; /**< Force Murmur3 choice. */ int force_spooky2; /**< Force Spooky2 choice. */