diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-25 13:21:07 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-25 13:32:42 +0200 |
commit | e0e98b7b747f63c1b8fccd035592e3684fdb2691 (patch) | |
tree | 31e75a68d40f6947cf09e06928df8f4f013d5a89 /lib/sqfs/data_writer/block.c | |
parent | f64986ac1d95ffb2604cfef0efa8e7d2e0b7f8ce (diff) |
Add the ability to hook into the data writer block writing
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/data_writer/block.c')
-rw-r--r-- | lib/sqfs/data_writer/block.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/lib/sqfs/data_writer/block.c b/lib/sqfs/data_writer/block.c index 9461737..9c40793 100644 --- a/lib/sqfs/data_writer/block.c +++ b/lib/sqfs/data_writer/block.c @@ -61,11 +61,15 @@ static int allign_file(sqfs_data_writer_t *proc, sqfs_block_t *blk) int process_completed_block(sqfs_data_writer_t *proc, sqfs_block_t *blk) { + uint64_t offset, bytes; size_t start, count; - uint64_t offset; uint32_t out; int err; + if (proc->hooks != NULL && proc->hooks->pre_block_write != NULL) { + proc->hooks->pre_block_write(proc->user_ptr, blk, proc->file); + } + if (blk->flags & SQFS_BLK_FIRST_BLOCK) { proc->start = proc->file->get_size(proc->file); proc->file_start = proc->num_blocks; @@ -101,6 +105,10 @@ int process_completed_block(sqfs_data_writer_t *proc, sqfs_block_t *blk) return err; } + if (proc->hooks != NULL && proc->hooks->post_block_write != NULL) { + proc->hooks->post_block_write(proc->user_ptr, blk, proc->file); + } + if (blk->flags & SQFS_BLK_LAST_BLOCK) { err = allign_file(proc, blk); if (err) @@ -112,19 +120,28 @@ int process_completed_block(sqfs_data_writer_t *proc, sqfs_block_t *blk) sqfs_inode_set_file_block_start(blk->inode, offset); - if (start < proc->file_start) { - offset = start + count; + if (start >= proc->file_start) + return 0; + + offset = start + count; + if (offset >= proc->file_start) { + count = proc->num_blocks - offset; + proc->num_blocks = offset; + } else { + proc->num_blocks = proc->file_start; + } - if (offset >= proc->file_start) { - proc->num_blocks = offset; - } else { - proc->num_blocks = proc->file_start; - } + if (proc->hooks != NULL && + proc->hooks->notify_blocks_erased != NULL) { + bytes = proc->file->get_size(proc->file) - proc->start; - err = proc->file->truncate(proc->file, proc->start); - if (err) - return err; + proc->hooks->notify_blocks_erased(proc->user_ptr, + count, bytes); } + + err = proc->file->truncate(proc->file, proc->start); + if (err) + return err; } return 0; |