mirror of
https://github.com/amadvance/snapraid.git
synced 2026-11-22 07:56:33 -05:00
Assumes also CHG blocks with a NULL hash without needing an info block.
Some refactoring and renaming of other hash functions to avoid misunderstanding.
This commit is contained in:
parent
9ad388724e
commit
e0afd0edf7
6 changed files with 50 additions and 34 deletions
25
state.c
25
state.c
|
|
@ -826,30 +826,17 @@ static void state_content_check(struct snapraid_state* state, const char* path)
|
|||
* and has a hash value.
|
||||
* Note that we include DELETED blocks, but only if they have a not NULL hash.
|
||||
*/
|
||||
static int position_has_hash(struct snapraid_state* state, block_off_t pos)
|
||||
static int position_has_any_hash(struct snapraid_state* state, block_off_t pos)
|
||||
{
|
||||
tommy_node* i;
|
||||
unsigned j;
|
||||
|
||||
/* check for each disk if block is really used */
|
||||
for(i=state->disklist;i!=0;i=i->next) {
|
||||
struct snapraid_disk* disk = i->data;
|
||||
struct snapraid_block* block = disk_block_get(disk, pos);
|
||||
|
||||
unsigned block_state = block_state_get(block);
|
||||
|
||||
switch (block_state) {
|
||||
case BLOCK_STATE_BLK :
|
||||
case BLOCK_STATE_CHG :
|
||||
if (block_has_any_hash(block))
|
||||
return 1;
|
||||
case BLOCK_STATE_DELETED :
|
||||
for(j=0;j<HASH_SIZE;++j)
|
||||
if (block->hash[j] != 0)
|
||||
break;
|
||||
if (j != HASH_SIZE)
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -1660,7 +1647,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f)
|
|||
info_has_rehash = 0; /* if there is a rehash info */
|
||||
for(b=0;b<blockmax;++b) {
|
||||
/* if the position is used */
|
||||
if (position_has_hash(state, b)) {
|
||||
if (position_has_any_hash(state, b)) {
|
||||
snapraid_info info = info_get(&state->infoarr, b);
|
||||
|
||||
/* only if there is some info to store */
|
||||
|
|
@ -1898,7 +1885,7 @@ static void state_write_text(struct snapraid_state* state, STREAM* f)
|
|||
/* write the info for each block */
|
||||
for(b=0;b<blockmax;++b) {
|
||||
/* if the position is used */
|
||||
if (position_has_hash(state, b)) {
|
||||
if (position_has_any_hash(state, b)) {
|
||||
snapraid_info info = info_get(&state->infoarr, b);
|
||||
|
||||
/* save only stuffs different than 0 */
|
||||
|
|
@ -2280,7 +2267,7 @@ static void state_read_binary(struct snapraid_state* state, const char* path, ST
|
|||
info_set(&state->infoarr, v_pos, info);
|
||||
|
||||
/* ensure that an info is present only for used positions */
|
||||
if (position_has_hash(state, v_pos)) {
|
||||
if (position_has_any_hash(state, v_pos)) {
|
||||
if (!info) {
|
||||
decoding_error(path, f);
|
||||
fprintf(stderr, "Internal incosistency for missing info!\n");
|
||||
|
|
@ -2701,7 +2688,7 @@ static void state_write_binary(struct snapraid_state* state, STREAM* f)
|
|||
info_has_rehash = 0; /* if there is a rehash info */
|
||||
for(b=0;b<blockmax;++b) {
|
||||
/* if the position is used */
|
||||
if (position_has_hash(state, b)) {
|
||||
if (position_has_any_hash(state, b)) {
|
||||
snapraid_info info = info_get(&state->infoarr, b);
|
||||
|
||||
/* only if there is some info to store */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue