diff options
author | Tushar Gohad <tushar.gohad@intel.com> | 2014-07-21 01:19:36 -0700 |
---|---|---|
committer | Tushar Gohad <tushar.gohad@intel.com> | 2014-07-21 01:19:36 -0700 |
commit | 8a07d41e850694a3c60904119b899cf476c2b05e (patch) | |
tree | 306336fc4597c9e6255495ea8ccc32516b7dae94 /src/erasurecode_helpers.c | |
parent | 4de83981d33ec120e4ba1fcd7190256f353c12a3 (diff) | |
download | liberasurecode-8a07d41e850694a3c60904119b899cf476c2b05e.tar.gz |
Add encode postprocessing, checksum helpers
Signed-off-by: Tushar Gohad <tushar.gohad@intel.com>
Diffstat (limited to 'src/erasurecode_helpers.c')
-rw-r--r-- | src/erasurecode_helpers.c | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/src/erasurecode_helpers.c b/src/erasurecode_helpers.c index 839d101..6c0d158 100644 --- a/src/erasurecode_helpers.c +++ b/src/erasurecode_helpers.c @@ -57,9 +57,7 @@ void *get_aligned_buffer16(int size) } /** - * Allocate a zero-ed buffer of a specific size. This method allocates from - * the Python stack in order to comply with the recommendations of the - * Python\C API. On error, return NULL and call PyErr_NoMemory. + * Allocate a zero-ed buffer of a specific size. * * @param size integer size in bytes of buffer to allocate * @return pointer to start of allocated buffer or NULL on error @@ -307,3 +305,31 @@ int validate_fragment(char *buf) /* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */ +inline int set_chksum(char *buf, int chksum) +{ + fragment_header_t* header = (fragment_header_t*) buf; + + if (header->magic != LIBERASURECODE_FRAG_HEADER_MAGIC) { + log_error("Invalid fragment header (set chksum)!\n"); + return -1; + } + + header->chksum = chksum; + + return 0; +} + +inline int get_chksum(char *buf) +{ + fragment_header_t* header = (fragment_header_t*) buf; + + if (header->magic != LIBERASURECODE_FRAG_HEADER_MAGIC) { + log_error("Invalid fragment header (get chksum)!"); + return -1; + } + + return header->chksum; +} + +/* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */ + |