diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-12 14:04:06 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-12 14:05:36 +0200 |
commit | 31ae9e5cc5337558ddb456c379949e23af43fd9f (patch) | |
tree | 9281c7a14449efd6300fa012310a5151657ea4a5 /lib/sqfs/blk_proc/process_block.c | |
parent | 9879cd8393b0d5ec26885de9f9dce2d34997db42 (diff) |
Cleanup: move block processor code to sub directory
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/blk_proc/process_block.c')
-rw-r--r-- | lib/sqfs/blk_proc/process_block.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/lib/sqfs/blk_proc/process_block.c b/lib/sqfs/blk_proc/process_block.c new file mode 100644 index 0000000..3289767 --- /dev/null +++ b/lib/sqfs/blk_proc/process_block.c @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * process_block.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#define SQFS_BUILDING_DLL +#include "config.h" + +#include "sqfs/block_processor.h" +#include "sqfs/compress.h" +#include "util.h" + +#include <string.h> +#include <zlib.h> + +int sqfs_block_process(sqfs_block_t *block, sqfs_compressor_t *cmp, + uint8_t *scratch, size_t scratch_size) +{ + ssize_t ret; + + if (!(block->flags & SQFS_BLK_DONT_CHECKSUM)) + block->checksum = crc32(0, block->data, block->size); + + if (!(block->flags & SQFS_BLK_DONT_COMPRESS)) { + ret = cmp->do_block(cmp, block->data, block->size, + scratch, scratch_size); + + if (ret < 0) { + block->flags |= SQFS_BLK_COMPRESS_ERROR; + return ret; + } + + if (ret > 0) { + memcpy(block->data, scratch, ret); + block->size = ret; + block->flags |= SQFS_BLK_IS_COMPRESSED; + } + } + + return 0; +} |