Rechecks the hash of imported files before using them.

This commit is contained in:
Andrea Mazzoleni 2013-03-19 21:59:13 +01:00
parent 0ab9066a4f
commit 8c7332cfda
3 changed files with 16 additions and 2 deletions

4
TODO
View file

@ -5,6 +5,10 @@ This is the list of TODO items for SnapRAID.
- v3.1
* In the import list, uses also all the blocks in the array.
But we must cover the case of bad blocks. Likely we can just check the
hash after reading, and in case, skip it, and retry with another copy.
* If a content file is missing, sync should rewrite it, even if no change was done at the content.
* A new 'init' command to differentiate the first 'sync' operation.

View file

@ -275,11 +275,11 @@ static int repair(struct snapraid_state* state, unsigned pos, unsigned diskmax,
}
} else {
assert(block_state == BLOCK_STATE_CHG || block_state == BLOCK_STATE_NEW);
/* otherwise it's CHG or NEW and we try to recover it */
failed_map[n] = j;
++n;
/* we have something to try to recover */
something_to_recover = 1;
}

View file

@ -125,6 +125,7 @@ int state_import_fetch(struct snapraid_state* state, const unsigned char* hash,
int f;
unsigned block_size = state->block_size;
unsigned read_size;
unsigned char buffer_hash[HASH_SIZE];
const char* path;
block = tommy_hashdyn_search(&state->importset, import_block_compare, hash, import_block_hash(hash));
@ -162,6 +163,15 @@ int state_import_fetch(struct snapraid_state* state, const unsigned char* hash,
memset(buffer + read_size, 0, block_size - read_size);
}
/* recheck the hash */
memhash(state->hash, buffer_hash, buffer, read_size);
if (memcmp(buffer_hash, hash, HASH_SIZE) != 0) {
fprintf(stderr, "Error in data reading file '%s'.\n", path);
fprintf(stderr, "Please don't change imported files while running.\n");
exit(EXIT_FAILURE);
}
return 0;
}