diff options
-rw-r--r-- | include/sqfs/block_processor.h | 4 | ||||
-rw-r--r-- | include/sqfs/block_writer.h | 10 | ||||
-rw-r--r-- | lib/common/data_writer.c | 2 | ||||
-rw-r--r-- | lib/sqfs/block_processor/common.c | 5 | ||||
-rw-r--r-- | lib/sqfs/block_processor/frontend.c | 6 | ||||
-rw-r--r-- | lib/sqfs/block_processor/internal.h | 4 | ||||
-rw-r--r-- | lib/sqfs/block_writer.c | 5 |
7 files changed, 26 insertions, 10 deletions
diff --git a/include/sqfs/block_processor.h b/include/sqfs/block_processor.h index c88e3df..5c77155 100644 --- a/include/sqfs/block_processor.h +++ b/include/sqfs/block_processor.h @@ -168,6 +168,8 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size, * @param inode An optional pointer to a pointer to an inode. If not NULL, the * block processor creates a file inode and stores a pointer to * it here and keeps updating the inode as the file grows. + * @param user An optional user data pointer that is passed to the + * the @ref sqfs_block_writer_t for each file data block. * @param flags A combination of @ref SQFS_BLK_FLAGS that can be used to * micro manage how the data is processed. * @@ -175,7 +177,7 @@ sqfs_block_processor_t *sqfs_block_processor_create(size_t max_block_size, */ SQFS_API int sqfs_block_processor_begin_file(sqfs_block_processor_t *proc, sqfs_inode_generic_t **inode, - sqfs_u32 flags); + void *user, sqfs_u32 flags); /** * @brief Append data to the current file. diff --git a/include/sqfs/block_writer.h b/include/sqfs/block_writer.h index f8bc671..6352f4d 100644 --- a/include/sqfs/block_writer.h +++ b/include/sqfs/block_writer.h @@ -58,6 +58,9 @@ struct sqfs_block_writer_t { * @ref SQFS_BLK_LAST_BLOCK flag, the padding is added afterwards. * * @param wr A pointer to a block writer. + * @param user An optional user data pointer. + * The @ref sqfs_block_processor_t can be told to pass this + * on to the block writer for each block. * @param size The size of the block to write. * @param checksum A 32 bit checksum of the block data. * @param flags A combination of @ref SQFS_BLK_FLAGS flag bits @@ -70,9 +73,10 @@ struct sqfs_block_writer_t { * * @return Zero on success, an @ref SQFS_ERROR error on failure. */ - int (*write_data_block)(sqfs_block_writer_t *wr, sqfs_u32 size, - sqfs_u32 checksum, sqfs_u32 flags, - const sqfs_u8 *data, sqfs_u64 *location); + int (*write_data_block)(sqfs_block_writer_t *wr, void *user, + sqfs_u32 size, sqfs_u32 checksum, + sqfs_u32 flags, const sqfs_u8 *data, + sqfs_u64 *location); /** * @brief Get the number of blocks actually written to disk. diff --git a/lib/common/data_writer.c b/lib/common/data_writer.c index bc5a43b..ceccaac 100644 --- a/lib/common/data_writer.c +++ b/lib/common/data_writer.c @@ -16,7 +16,7 @@ int write_data_from_file(const char *filename, sqfs_block_processor_t *data, size_t diff; int ret; - ret = sqfs_block_processor_begin_file(data, inode, flags); + ret = sqfs_block_processor_begin_file(data, inode, NULL, flags); if (ret) { sqfs_perror(filename, "beginning file data blocks", ret); return -1; diff --git a/lib/sqfs/block_processor/common.c b/lib/sqfs/block_processor/common.c index 6a62d4f..bfcc3d5 100644 --- a/lib/sqfs/block_processor/common.c +++ b/lib/sqfs/block_processor/common.c @@ -69,8 +69,9 @@ static int process_completed_block(sqfs_block_processor_t *proc, sqfs_u32 size; int err; - err = proc->wr->write_data_block(proc->wr, blk->size, blk->checksum, - blk->flags, blk->data, &location); + err = proc->wr->write_data_block(proc->wr, blk->user, blk->size, + blk->checksum, blk->flags, + blk->data, &location); if (err) goto out; diff --git a/lib/sqfs/block_processor/frontend.c b/lib/sqfs/block_processor/frontend.c index 8381dd8..d6571ea 100644 --- a/lib/sqfs/block_processor/frontend.c +++ b/lib/sqfs/block_processor/frontend.c @@ -55,7 +55,8 @@ 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) + sqfs_inode_generic_t **inode, + void *user, sqfs_u32 flags) { if (proc->begin_called) return SQFS_ERROR_SEQUENCE; @@ -76,6 +77,7 @@ int sqfs_block_processor_begin_file(sqfs_block_processor_t *proc, proc->inode = inode; proc->blk_flags = flags | SQFS_BLK_FIRST_BLOCK; proc->blk_index = 0; + proc->user = user; return 0; } @@ -104,6 +106,7 @@ int sqfs_block_processor_append(sqfs_block_processor_t *proc, const void *data, proc->blk_current = new; proc->blk_current->flags = proc->blk_flags; proc->blk_current->inode = proc->inode; + proc->blk_current->user = proc->user; } diff = proc->max_block_size - proc->blk_current->size; @@ -162,6 +165,7 @@ int sqfs_block_processor_end_file(sqfs_block_processor_t *proc) proc->begin_called = false; proc->inode = NULL; + proc->user = NULL; proc->blk_flags = 0; return 0; } diff --git a/lib/sqfs/block_processor/internal.h b/lib/sqfs/block_processor/internal.h index 61e13d7..d28e023 100644 --- a/lib/sqfs/block_processor/internal.h +++ b/lib/sqfs/block_processor/internal.h @@ -42,6 +42,9 @@ typedef struct sqfs_block_t { consolidate in reverse order. */ struct sqfs_block_t *frag_list; + /* User data pointer */ + void *user; + sqfs_u8 data[]; } sqfs_block_t; @@ -59,6 +62,7 @@ struct sqfs_block_processor_t { sqfs_block_t *blk_current; sqfs_u32 blk_flags; sqfs_u32 blk_index; + void *user; sqfs_block_t *free_list; diff --git a/lib/sqfs/block_writer.c b/lib/sqfs/block_writer.c index a6ca4b3..07780d7 100644 --- a/lib/sqfs/block_writer.c +++ b/lib/sqfs/block_writer.c @@ -115,8 +115,8 @@ static void block_writer_destroy(sqfs_object_t *wr) free(wr); } -static int write_data_block(sqfs_block_writer_t *base, sqfs_u32 size, - sqfs_u32 checksum, sqfs_u32 flags, +static int write_data_block(sqfs_block_writer_t *base, void *user, + sqfs_u32 size, sqfs_u32 checksum, sqfs_u32 flags, const sqfs_u8 *data, sqfs_u64 *location) { block_writer_default_t *wr = (block_writer_default_t *)base; @@ -124,6 +124,7 @@ static int write_data_block(sqfs_block_writer_t *base, sqfs_u32 size, sqfs_u64 offset; sqfs_u32 out; int err; + (void)user; if (flags & SQFS_BLK_FIRST_BLOCK) { wr->start = wr->file->get_size(wr->file); |