diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-02-16 01:05:40 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2020-02-16 01:05:40 +0100 |
commit | d6143ce54787f70eda9ad2492823e6142e8c5652 (patch) | |
tree | 361dfa80d0ecdc3ac9e0bb2bcc850705fb032e53 /lib/sqfs/block_processor | |
parent | 8e52ed282e16cc0cc984d077377cd79d0f10308d (diff) |
Minor cleanup
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/block_processor')
-rw-r--r-- | lib/sqfs/block_processor/common.c | 42 | ||||
-rw-r--r-- | lib/sqfs/block_processor/fileapi.c | 28 |
2 files changed, 30 insertions, 40 deletions
diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c index 3859916..a1e8b6e 100644 --- a/lib/sqfs/block_processor/common.c +++ b/lib/sqfs/block_processor/common.c @@ -57,37 +57,31 @@ static bool is_zero_block(unsigned char *ptr, size_t size) int block_processor_do_block(sqfs_block_t *block, sqfs_compressor_t *cmp, sqfs_u8 *scratch, size_t scratch_size) { - ssize_t ret; + sqfs_s32 ret; - if (block->size == 0) { - block->checksum = 0; + if (block->size == 0) return 0; - } if (is_zero_block(block->data, block->size)) { block->flags |= SQFS_BLK_IS_SPARSE; - block->checksum = 0; return 0; } block->checksum = crc32(0, block->data, block->size); - if (block->flags & SQFS_BLK_IS_FRAGMENT) + if (block->flags & (SQFS_BLK_IS_FRAGMENT | SQFS_BLK_DONT_COMPRESS)) return 0; - if (!(block->flags & SQFS_BLK_DONT_COMPRESS)) { - ret = cmp->do_block(cmp, block->data, block->size, - scratch, scratch_size); - if (ret < 0) - return ret; + ret = cmp->do_block(cmp, block->data, block->size, + scratch, scratch_size); + if (ret < 0) + return ret; - if (ret > 0) { - memcpy(block->data, scratch, ret); - block->size = ret; - block->flags |= SQFS_BLK_IS_COMPRESSED; - } + if (ret > 0) { + memcpy(block->data, scratch, ret); + block->size = ret; + block->flags |= SQFS_BLK_IS_COMPRESSED; } - return 0; } @@ -110,11 +104,12 @@ int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag, proc->stats.total_frag_count += 1; - err = sqfs_frag_table_find_tail_end(proc->frag_tbl, - frag->checksum, frag->size, - &index, &offset); - if (err == 0) - goto out_duplicate; + err = sqfs_frag_table_find_tail_end(proc->frag_tbl, frag->checksum, + frag->size, &index, &offset); + if (err == 0) { + sqfs_inode_set_frag_location(frag->inode, index, offset); + return 0; + } if (proc->frag_block != NULL) { size = proc->frag_block->size + frag->size; @@ -164,9 +159,6 @@ fail: free(*blk_out); *blk_out = NULL; return err; -out_duplicate: - sqfs_inode_set_frag_location(frag->inode, index, offset); - return 0; } const sqfs_block_processor_stats_t diff --git a/lib/sqfs/block_processor/fileapi.c b/lib/sqfs/block_processor/fileapi.c index abaf3d2..098f724 100644 --- a/lib/sqfs/block_processor/fileapi.c +++ b/lib/sqfs/block_processor/fileapi.c @@ -44,14 +44,14 @@ int sqfs_block_processor_begin_file(sqfs_block_processor_t *proc, proc->inode = inode; proc->blk_flags = flags | SQFS_BLK_FIRST_BLOCK; - proc->blk_current = NULL; return 0; } -static int flush_block(sqfs_block_processor_t *proc, sqfs_block_t *block) +static int flush_block(sqfs_block_processor_t *proc) { - block->flags = proc->blk_flags; - block->inode = proc->inode; + sqfs_block_t *block = proc->blk_current; + + proc->blk_current = NULL; if (block->size < proc->max_block_size && !(block->flags & SQFS_BLK_DONT_FRAGMENT)) { @@ -66,26 +66,25 @@ static int flush_block(sqfs_block_processor_t *proc, sqfs_block_t *block) int sqfs_block_processor_append(sqfs_block_processor_t *proc, const void *data, size_t size) { + sqfs_block_t *new; size_t diff; - void *new; int err; while (size > 0) { if (proc->blk_current == NULL) { - new = alloc_flex(sizeof(*proc->blk_current), 1, - proc->max_block_size); - + new = alloc_flex(sizeof(*new), 1, proc->max_block_size); if (new == NULL) return SQFS_ERROR_ALLOC; proc->blk_current = new; + proc->blk_current->flags = proc->blk_flags; + proc->blk_current->inode = proc->inode; } diff = proc->max_block_size - proc->blk_current->size; if (diff == 0) { - err = flush_block(proc, proc->blk_current); - proc->blk_current = NULL; + err = flush_block(proc); if (err) return err; continue; @@ -106,9 +105,7 @@ int sqfs_block_processor_append(sqfs_block_processor_t *proc, const void *data, if (proc->blk_current != NULL && proc->blk_current->size == proc->max_block_size) { - err = flush_block(proc, proc->blk_current); - proc->blk_current = NULL; - return err; + return flush_block(proc); } return 0; @@ -133,8 +130,9 @@ int sqfs_block_processor_end_file(sqfs_block_processor_t *proc) } if (proc->blk_current != NULL) { - err = flush_block(proc, proc->blk_current); - proc->blk_current = NULL; + err = flush_block(proc); + if (err) + return err; } proc->inode = NULL; |