summaryrefslogtreecommitdiff
path: root/lib/comp/process_block.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-13 14:11:25 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-18 22:44:39 +0200
commit7ca19d23cb4913b5dabfdf3469852ec9f2c0f8d7 (patch)
treeacfff19efd250a37e9eec15be80aa1e743b78bc9 /lib/comp/process_block.c
parent2f22a35e843a24f0ad5f31644133d64648fe4efc (diff)
Add block processor data structure
The interface is designed for parallel, asynchronuous processing of data blocks with an I/O callback that handles the serialized result. The underlying implementation is currently still synchronuous. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/comp/process_block.c')
-rw-r--r--lib/comp/process_block.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/comp/process_block.c b/lib/comp/process_block.c
new file mode 100644
index 0000000..76cd07d
--- /dev/null
+++ b/lib/comp/process_block.c
@@ -0,0 +1,37 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * process_block.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "config.h"
+
+#include "block_processor.h"
+#include "util.h"
+
+#include <string.h>
+
+int process_block(block_t *block, compressor_t *cmp,
+ uint8_t *scratch, size_t scratch_size)
+{
+ ssize_t ret;
+
+ if (!(block->flags & BLK_DONT_CHECKSUM))
+ block->checksum = update_crc32(0, block->data, block->size);
+
+ if (!(block->flags & BLK_DONT_COMPRESS)) {
+ ret = cmp->do_block(cmp, block->data, block->size,
+ scratch, scratch_size);
+
+ if (ret < 0)
+ return -1;
+
+ if (ret > 0) {
+ memcpy(block->data, scratch, ret);
+ block->size = ret;
+ block->flags |= BLK_IS_COMPRESSED;
+ }
+ }
+
+ return 0;
+}