New option to relax the content file checks.

This commit is contained in:
Andrea Mazzoleni 2014-02-22 07:47:34 +01:00
parent 624212d7d4
commit 715a4be2a0
3 changed files with 42 additions and 11 deletions

View file

@ -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;

45
state.c
View file

@ -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 */

View file

@ -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. */