mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Centralize canonical SnapRAID block hashing semantics
This commit is contained in:
parent
0ab885d8e5
commit
1a5b5728d2
7 changed files with 87 additions and 33 deletions
|
|
@ -109,21 +109,21 @@ int search_file_compare(const void* void_arg, const void* void_data)
|
|||
/* LCOV_EXCL_STOP */
|
||||
}
|
||||
|
||||
/* compute the hash */
|
||||
if (arg->prevhash)
|
||||
memhash(state->prevhash, state->prevhashseed, buffer_hash, arg->buffer, arg->read_size);
|
||||
else
|
||||
memhash(state->hash, state->hashseed, buffer_hash, arg->buffer, arg->read_size);
|
||||
|
||||
/* check if the hash is matching */
|
||||
if (memcmp(buffer_hash, arg->block->hash, BLOCK_HASH_SIZE) != 0)
|
||||
return -1;
|
||||
|
||||
if (arg->read_size != state->block_size) {
|
||||
/* fill the remaining with 0 */
|
||||
memset(arg->buffer + arg->read_size, 0, state->block_size - arg->read_size);
|
||||
}
|
||||
|
||||
/* compute the block hash from the canonical buffer */
|
||||
if (arg->prevhash)
|
||||
memhash_block(state->prevhash, state->prevhashseed, buffer_hash, arg->buffer, arg->read_size, state->block_size);
|
||||
else
|
||||
memhash_block(state->hash, state->hashseed, buffer_hash, arg->buffer, arg->read_size, state->block_size);
|
||||
|
||||
/* check if the hash is matching */
|
||||
if (memcmp(buffer_hash, arg->block->hash, BLOCK_HASH_SIZE) != 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue