Apply EINSUFFFRAGS to reconstruct

This commit is contained in:
Kota Tsuyuzaki
2015-03-06 14:58:06 +09:00
parent de94bbad63
commit 1667acb87c
2 changed files with 22 additions and 1 deletions

View File

@@ -248,7 +248,7 @@ int get_fragment_partition(
}
// TODO: In general, it is possible to reconstruct one or more fragments
// when more than m fragments are missing (e.g. flat XOR codes)
return (num_missing > m) ? -1 : 0;
return (num_missing > m) ? -EINSUFFFRAGS : 0;
}
int fragments_to_string(int k, int m,

View File

@@ -429,6 +429,10 @@ static void test_reconstruct_fragment_invalid_args()
int frag_len = 10;
char **avail_frags = malloc(sizeof(char *) * 2);
char *out_frag = malloc(frag_len);
int orig_data_size = 1024 * 1024;
char *orig_data = create_buffer(orig_data_size, 'x');
char **encoded_data = NULL, **encoded_parity = NULL;
uint64_t encoded_fragment_len = 0;
assert(avail_frags);
assert(out_frag);
@@ -444,6 +448,23 @@ static void test_reconstruct_fragment_invalid_args()
rc = liberasurecode_reconstruct_fragment(desc, avail_frags, 1, frag_len, 1, NULL);
assert(rc < 0);
free(out_frag);
free(avail_frags);
// Test for EINSUFFFRAGS
// we have to call encode to get fragments which have valid header.
rc = liberasurecode_encode(desc, orig_data, orig_data_size,
&encoded_data, &encoded_parity, &encoded_fragment_len);
assert(rc == 0);
out_frag = malloc(encoded_fragment_len);
assert(out_frag != NULL);
rc = liberasurecode_reconstruct_fragment(desc, avail_frags, 1, encoded_fragment_len, 1, out_frag);
assert(rc == -EINSUFFFRAGS);
free(out_frag);
free(avail_frags);
}