liberasurecode
1.8.0
Erasure Code API library
Toggle main menu visibility
Loading...
Searching...
No Matches
construction
devel
liberasurecode
liberasurecode-1.8.0
src
erasurecode_postprocessing.c
Go to the documentation of this file.
1
/*
2
* Copyright 2014 Tushar Gohad, Kevin M Greenan, Eric Lambert
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
6
*
7
* Redistributions of source code must retain the above copyright notice, this
8
* list of conditions and the following disclaimer.
9
*
10
* Redistributions in binary form must reproduce the above copyright notice, this
11
* list of conditions and the following disclaimer in the documentation and/or
12
* other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY
13
* THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
14
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16
* EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
17
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
20
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
21
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
*
24
* liberasurecode postprocessing helpers implementation
25
*
26
* vi: set noai tw=79 ts=4 sw=4:
27
*/
28
29
#include <zlib.h>
30
#include "erasurecode_backend.h"
31
#include "erasurecode_helpers.h"
32
#include "erasurecode_helpers_ext.h"
33
#include "erasurecode_log.h"
34
#include "erasurecode_stdinc.h"
35
#include "alg_sig.h"
36
37
__attribute__
((visibility (
"internal"
)))
38
void add_fragment_metadata(ec_backend_t be,
char
*fragment,
39
int
idx, uint64_t orig_data_size,
int
blocksize,
40
ec_checksum_type_t ct,
int
add_chksum)
41
{
42
//TODO EDL we are ignoring the return codes here, fix that
43
set_libec_version(fragment);
44
set_fragment_idx(fragment, idx);
45
set_orig_data_size(fragment, orig_data_size);
46
set_fragment_payload_size(fragment, blocksize);
47
set_backend_id(fragment, be->common.id);
48
set_backend_version(fragment, be->common.ec_backend_version);
49
set_fragment_backend_metadata_size(fragment, be->common.ops->get_backend_metadata_size(
50
be->desc.backend_desc,
51
blocksize));
52
53
if
(add_chksum) {
54
set_checksum(ct, fragment, blocksize);
55
}
56
57
fragment_header_t* header = (fragment_header_t*) fragment;
58
59
if
(header->magic != LIBERASURECODE_FRAG_HEADER_MAGIC) {
60
log_error(
"Invalid fragment header (add fragment metadata)!\n"
);
61
return
;
62
}
63
64
char
*flag = getenv(
"LIBERASURECODE_WRITE_LEGACY_CRC"
);
65
if
(flag && !(flag[0] ==
'\0'
|| (flag[0] ==
'0'
&& flag[1] ==
'\0'
))) {
66
header->metadata_chksum =
liberasurecode_crc32_alt
(
67
0, &header->meta,
sizeof
(fragment_metadata_t));
68
}
else
{
69
header->metadata_chksum = crc32(0, (
unsigned
char
*) &header->meta,
70
sizeof
(fragment_metadata_t));
71
}
72
}
73
74
__attribute__
((visibility (
"internal"
)))
75
int finalize_fragments_after_encode(ec_backend_t instance,
76
int
k,
int
m,
int
blocksize, uint64_t orig_data_size,
77
char
**encoded_data,
char
**encoded_parity)
78
{
79
int
i, set_chksum = 1;
80
ec_checksum_type_t ct = instance->args.uargs.ct;
81
82
/* finalize data fragments */
83
for
(i = 0; i < k; i++) {
84
char
*fragment = get_fragment_ptr_from_data(encoded_data[i]);
85
add_fragment_metadata(instance, fragment, i, orig_data_size,
86
blocksize, ct, set_chksum);
87
encoded_data[i] = fragment;
88
}
89
90
/* finalize parity fragments */
91
for
(i = 0; i < m; i++) {
92
char
*fragment = get_fragment_ptr_from_data(encoded_parity[i]);
93
add_fragment_metadata(instance, fragment, i + k, orig_data_size,
94
blocksize, ct, set_chksum);
95
encoded_parity[i] = fragment;
96
}
97
98
return
0;
99
}
liberasurecode_crc32_alt
int liberasurecode_crc32_alt(int crc, const void *buf, size_t size)
Definition
crc32.c:92
__attribute__
__attribute__((visibility("internal")))
Return the element-size, which is the number of bits stored on a given device, per codeword.
Definition
isa_l_common.c:39
Generated on
for liberasurecode by
1.18.0