summaryrefslogtreecommitdiff
path: root/lib/sqfs/blk_proc/serial.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfs/blk_proc/serial.c')
-rw-r--r--lib/sqfs/blk_proc/serial.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/sqfs/blk_proc/serial.c b/lib/sqfs/blk_proc/serial.c
index 06c811e..c7ec366 100644
--- a/lib/sqfs/blk_proc/serial.c
+++ b/lib/sqfs/blk_proc/serial.c
@@ -28,6 +28,7 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
proc->devblksz = devblksz;
proc->file = file;
proc->max_blocks = INIT_BLOCK_COUNT;
+ proc->frag_list_max = INIT_BLOCK_COUNT;
proc->blocks = alloc_array(sizeof(proc->blocks[0]), proc->max_blocks);
if (proc->blocks == NULL) {
@@ -35,11 +36,21 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size,
return NULL;
}
+ proc->frag_list = alloc_array(sizeof(proc->frag_list[0]),
+ proc->frag_list_max);
+ if (proc->frag_list == NULL) {
+ free(proc->blocks);
+ free(proc);
+ return NULL;
+ }
+
return proc;
}
void sqfs_block_processor_destroy(sqfs_block_processor_t *proc)
{
+ free(proc->frag_block);
+ free(proc->frag_list);
free(proc->fragments);
free(proc->blocks);
free(proc);
@@ -48,6 +59,8 @@ void sqfs_block_processor_destroy(sqfs_block_processor_t *proc)
int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc,
sqfs_block_t *block)
{
+ sqfs_block_t *fragblk = NULL;
+
if (proc->status != 0) {
free(block);
return proc->status;
@@ -59,6 +72,23 @@ int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc,
return proc->status;
}
+ if (block->flags & SQFS_BLK_IS_FRAGMENT) {
+ block->checksum = crc32(0, block->data, block->size);
+
+ proc->status = handle_fragment(proc, block, &fragblk);
+ free(block);
+
+ if (proc->status != 0) {
+ free(fragblk);
+ return proc->status;
+ }
+
+ if (fragblk == NULL)
+ return 0;
+
+ block = fragblk;
+ }
+
proc->status = sqfs_block_process(block, proc->cmp, proc->scratch,
proc->max_block_size);
@@ -71,5 +101,16 @@ int sqfs_block_processor_enqueue(sqfs_block_processor_t *proc,
int sqfs_block_processor_finish(sqfs_block_processor_t *proc)
{
+ if (proc->status != 0 || proc->frag_block == NULL)
+ return proc->status;
+
+ proc->status = sqfs_block_process(proc->frag_block, proc->cmp,
+ proc->scratch, proc->max_block_size);
+
+ if (proc->status == 0)
+ proc->status = process_completed_block(proc, proc->frag_block);
+
+ free(proc->frag_block);
+ proc->frag_block = NULL;
return proc->status;
}