liberasurecode  1.4.0
Erasure Code API library
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 "erasurecode_backend.h"
30 #include "erasurecode_helpers.h"
31 #include "erasurecode_helpers_ext.h"
32 #include "erasurecode_stdinc.h"
33 
34 void add_fragment_metadata(ec_backend_t be, char *fragment,
35  int idx, uint64_t orig_data_size, int blocksize,
36  ec_checksum_type_t ct, int add_chksum)
37 {
38  //TODO EDL we are ignoring the return codes here, fix that
39  set_libec_version(fragment);
40  set_fragment_idx(fragment, idx);
41  set_orig_data_size(fragment, orig_data_size);
42  set_fragment_payload_size(fragment, blocksize);
43  set_backend_id(fragment, be->common.id);
44  set_backend_version(fragment, be->common.ec_backend_version);
45  set_fragment_backend_metadata_size(fragment, be->common.backend_metadata_size);
46 
47  if (add_chksum) {
48  set_checksum(ct, fragment, blocksize);
49  }
50  set_metadata_chksum(fragment);
51 }
52 
53 int finalize_fragments_after_encode(ec_backend_t instance,
54  int k, int m, int blocksize, uint64_t orig_data_size,
55  char **encoded_data, char **encoded_parity)
56 {
57  int i, set_chksum = 1;
58  ec_checksum_type_t ct = instance->args.uargs.ct;
59 
60  /* finalize data fragments */
61  for (i = 0; i < k; i++) {
62  char *fragment = get_fragment_ptr_from_data(encoded_data[i]);
63  add_fragment_metadata(instance, fragment, i, orig_data_size,
64  blocksize, ct, set_chksum);
65  encoded_data[i] = fragment;
66  }
67 
68  /* finalize parity fragments */
69  for (i = 0; i < m; i++) {
70  char *fragment = get_fragment_ptr_from_data(encoded_parity[i]);
71  add_fragment_metadata(instance, fragment, i + k, orig_data_size,
72  blocksize, ct, set_chksum);
73  encoded_parity[i] = fragment;
74  }
75 
76  return 0;
77 }
char * get_fragment_ptr_from_data(char *buf)
int set_backend_version(char *buf, uint32_t version)
int finalize_fragments_after_encode(ec_backend_t instance, int k, int m, int blocksize, uint64_t orig_data_size, char **encoded_data, char **encoded_parity)
void add_fragment_metadata(ec_backend_t be, char *fragment, int idx, uint64_t orig_data_size, int blocksize, ec_checksum_type_t ct, int add_chksum)
int set_metadata_chksum(char *buf)
int set_checksum(ec_checksum_type_t ct, char *buf, int blocksize)
int set_backend_id(char *buf, ec_backend_id_t id)
int set_orig_data_size(char *buf, int orig_data_size)
int set_fragment_payload_size(char *buf, int size)
int set_fragment_idx(char *buf, int idx)
int set_fragment_backend_metadata_size(char *buf, int size)
int set_libec_version(char *buf)