summaryrefslogtreecommitdiff
path: root/src/erasurecode_helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/erasurecode_helpers.c')
-rw-r--r--src/erasurecode_helpers.c32
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;
+}
+
+/* ==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~==~=*=~== */
+