summaryrefslogtreecommitdiff
path: root/lib/sqfs/block_processor
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfs/block_processor')
-rw-r--r--lib/sqfs/block_processor/common.c42
-rw-r--r--lib/sqfs/block_processor/frontend.c27
-rw-r--r--lib/sqfs/block_processor/internal.h2
3 files changed, 45 insertions, 26 deletions
diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c
index e3d5486..6fb8f6f 100644
--- a/lib/sqfs/block_processor/common.c
+++ b/lib/sqfs/block_processor/common.c
@@ -76,13 +76,14 @@ int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk)
proc->stats.output_bytes_generated += blk->size;
if (blk->flags & SQFS_BLK_IS_SPARSE) {
- sqfs_inode_make_extended(*(blk->inode));
- (*(blk->inode))->data.file_ext.sparse += blk->size;
-
- err = set_block_size(blk->inode, blk->index, 0);
- if (err)
- goto out;
+ if (blk->inode != NULL) {
+ sqfs_inode_make_extended(*(blk->inode));
+ (*(blk->inode))->data.file_ext.sparse += blk->size;
+ err = set_block_size(blk->inode, blk->index, 0);
+ if (err)
+ goto out;
+ }
proc->stats.sparse_block_count += 1;
} else if (blk->size != 0) {
size = blk->size;
@@ -96,14 +97,17 @@ int process_completed_block(sqfs_block_processor_t *proc, sqfs_block_t *blk)
goto out;
proc->stats.frag_block_count += 1;
} else {
- err = set_block_size(blk->inode, blk->index, size);
- if (err)
- goto out;
+ if (blk->inode != NULL) {
+ err = set_block_size(blk->inode, blk->index,
+ size);
+ if (err)
+ goto out;
+ }
proc->stats.data_block_count += 1;
}
}
- if (blk->flags & SQFS_BLK_LAST_BLOCK)
+ if (blk->flags & SQFS_BLK_LAST_BLOCK && blk->inode != NULL)
sqfs_inode_set_file_block_start(*(blk->inode), location);
out:
release_old_block(proc, blk);
@@ -169,10 +173,11 @@ int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
int err;
if (frag->flags & SQFS_BLK_IS_SPARSE) {
- sqfs_inode_make_extended(*(frag->inode));
- set_block_size(frag->inode, frag->index, 0);
- (*(frag->inode))->data.file_ext.sparse += frag->size;
-
+ if (frag->inode != NULL) {
+ sqfs_inode_make_extended(*(frag->inode));
+ set_block_size(frag->inode, frag->index, 0);
+ (*(frag->inode))->data.file_ext.sparse += frag->size;
+ }
proc->stats.sparse_block_count += 1;
release_old_block(proc, frag);
return 0;
@@ -185,8 +190,10 @@ int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
frag->checksum, frag->size,
&index, &offset);
if (err == 0) {
- sqfs_inode_set_frag_location(*(frag->inode),
- index, offset);
+ if (frag->inode != NULL) {
+ sqfs_inode_set_frag_location(*(frag->inode),
+ index, offset);
+ }
release_old_block(proc, frag);
return 0;
}
@@ -227,7 +234,8 @@ int process_completed_fragment(sqfs_block_processor_t *proc, sqfs_block_t *frag,
if (err)
goto fail_outblk;
- sqfs_inode_set_frag_location(*(frag->inode), index, offset);
+ if (frag->inode != NULL)
+ sqfs_inode_set_frag_location(*(frag->inode), index, offset);
proc->stats.actual_frag_count += 1;
return 0;
fail:
diff --git a/lib/sqfs/block_processor/frontend.c b/lib/sqfs/block_processor/frontend.c
index cfa6581..0865df8 100644
--- a/lib/sqfs/block_processor/frontend.c
+++ b/lib/sqfs/block_processor/frontend.c
@@ -57,19 +57,22 @@ static int flush_block(sqfs_block_processor_t *proc)
int sqfs_block_processor_begin_file(sqfs_block_processor_t *proc,
sqfs_inode_generic_t **inode, sqfs_u32 flags)
{
- if (proc->inode != NULL)
+ if (proc->begin_called)
return SQFS_ERROR_SEQUENCE;
if (flags & ~SQFS_BLK_USER_SETTABLE_FLAGS)
return SQFS_ERROR_UNSUPPORTED;
- (*inode) = calloc(1, sizeof(sqfs_inode_generic_t));
- if ((*inode) == NULL)
- return SQFS_ERROR_ALLOC;
+ if (inode != NULL) {
+ (*inode) = calloc(1, sizeof(sqfs_inode_generic_t));
+ if ((*inode) == NULL)
+ return SQFS_ERROR_ALLOC;
- (*inode)->base.type = SQFS_INODE_FILE;
- sqfs_inode_set_frag_location(*inode, 0xFFFFFFFF, 0xFFFFFFFF);
+ (*inode)->base.type = SQFS_INODE_FILE;
+ sqfs_inode_set_frag_location(*inode, 0xFFFFFFFF, 0xFFFFFFFF);
+ }
+ proc->begin_called = true;
proc->inode = inode;
proc->blk_flags = flags | SQFS_BLK_FIRST_BLOCK;
proc->blk_index = 0;
@@ -84,8 +87,13 @@ int sqfs_block_processor_append(sqfs_block_processor_t *proc, const void *data,
size_t diff;
int err;
- sqfs_inode_get_file_size(*(proc->inode), &filesize);
- sqfs_inode_set_file_size(*(proc->inode), filesize + size);
+ if (!proc->begin_called)
+ return SQFS_ERROR_SEQUENCE;
+
+ if (proc->inode != NULL) {
+ sqfs_inode_get_file_size(*(proc->inode), &filesize);
+ sqfs_inode_set_file_size(*(proc->inode), filesize + size);
+ }
while (size > 0) {
if (proc->blk_current == NULL) {
@@ -132,7 +140,7 @@ int sqfs_block_processor_end_file(sqfs_block_processor_t *proc)
{
int err;
- if (proc->inode == NULL)
+ if (!proc->begin_called)
return SQFS_ERROR_SEQUENCE;
if (!(proc->blk_flags & SQFS_BLK_FIRST_BLOCK)) {
@@ -152,6 +160,7 @@ int sqfs_block_processor_end_file(sqfs_block_processor_t *proc)
return err;
}
+ proc->begin_called = false;
proc->inode = NULL;
proc->blk_flags = 0;
return 0;
diff --git a/lib/sqfs/block_processor/internal.h b/lib/sqfs/block_processor/internal.h
index 775671c..a71e6d7 100644
--- a/lib/sqfs/block_processor/internal.h
+++ b/lib/sqfs/block_processor/internal.h
@@ -63,6 +63,8 @@ struct sqfs_block_processor_t {
sqfs_block_t *free_list;
size_t max_block_size;
+
+ bool begin_called;
};
SQFS_INTERNAL int process_completed_block(sqfs_block_processor_t *proc,