diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-01-28 21:23:21 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-01-29 17:22:50 +0100 |
commit | 9d5b0c381a7961a14d2a94a6b31a4e25a2543eae (patch) | |
tree | 089a3cc96f54cd7b09762840d03e4dc2420c5ea9 /lib/sqfs/block_processor/fragment.c | |
parent | 60ff56b68ea0593782d7a2ef0ac4e667437418d2 (diff) |
Rename sqfs_data_writer_t back to sqfs_block_processor_t
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/block_processor/fragment.c')
-rw-r--r-- | lib/sqfs/block_processor/fragment.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/lib/sqfs/block_processor/fragment.c b/lib/sqfs/block_processor/fragment.c new file mode 100644 index 0000000..3701b3c --- /dev/null +++ b/lib/sqfs/block_processor/fragment.c @@ -0,0 +1,81 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * fragtbl.c + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#define SQFS_BUILDING_DLL +#include "internal.h" + +int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag, + sqfs_block_t **blk_out) +{ + sqfs_u32 index, offset; + size_t size; + int err; + + err = sqfs_frag_table_find_tail_end(proc->frag_tbl, + frag->checksum, frag->size, + &index, &offset); + if (err == 0) + goto out_duplicate; + + if (proc->frag_block != NULL) { + size = proc->frag_block->size + frag->size; + + if (size > proc->max_block_size) { + *blk_out = proc->frag_block; + proc->frag_block = NULL; + } + } + + if (proc->frag_block == NULL) { + size = sizeof(sqfs_block_t) + proc->max_block_size; + + err= sqfs_frag_table_append(proc->frag_tbl, 0, 0, &index); + if (err) + goto fail; + + proc->frag_block = calloc(1, size); + if (proc->frag_block == NULL) { + err = SQFS_ERROR_ALLOC; + goto fail; + } + + proc->frag_block->index = index; + proc->frag_block->flags = SQFS_BLK_FRAGMENT_BLOCK; + } + + err = sqfs_frag_table_add_tail_end(proc->frag_tbl, + proc->frag_block->index, + proc->frag_block->size, + frag->size, frag->checksum); + if (err) + goto fail; + + sqfs_inode_set_frag_location(frag->inode, proc->frag_block->index, + proc->frag_block->size); + + if (proc->hooks != NULL && proc->hooks->pre_fragment_store != NULL) { + proc->hooks->pre_fragment_store(proc->user_ptr, frag); + } + + memcpy(proc->frag_block->data + proc->frag_block->size, + frag->data, frag->size); + + proc->frag_block->flags |= (frag->flags & SQFS_BLK_DONT_COMPRESS); + proc->frag_block->size += frag->size; + return 0; +fail: + free(*blk_out); + *blk_out = NULL; + return err; +out_duplicate: + sqfs_inode_set_frag_location(frag->inode, index, offset); + + if (proc->hooks != NULL && + proc->hooks->notify_fragment_discard != NULL) { + proc->hooks->notify_fragment_discard(proc->user_ptr, frag); + } + return 0; +} |