diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-26 18:55:04 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-26 18:55:04 +0200 |
commit | 9ed84dac57944149e05646960a715d8f98dabcc5 (patch) | |
tree | 1be14b86b10b96d0549b1839078c0c19c588f77e /lib/sqfshelper/data_writer.c | |
parent | ff4a9235feb4237854ff102c4dc7cf4645d6a116 (diff) |
Replace the data writer enqueue with "append buffer to current file"
This commit turns the file interface into an actual, generic file
interface and does away with having to move around blocks outside
the data writer. Instead the data writer takes over full control
and responsibility of dividing the input data up into blocks
propperly.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfshelper/data_writer.c')
-rw-r--r-- | lib/sqfshelper/data_writer.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/sqfshelper/data_writer.c b/lib/sqfshelper/data_writer.c index ca47447..71dd4be 100644 --- a/lib/sqfshelper/data_writer.c +++ b/lib/sqfshelper/data_writer.c @@ -9,13 +9,15 @@ #include "highlevel.h" #include "util.h" +static uint8_t buffer[4096]; + int write_data_from_file(sqfs_data_writer_t *data, sqfs_inode_generic_t *inode, sqfs_file_t *file, size_t block_size, int flags) { uint64_t filesz, offset; - sqfs_block_t *blk; size_t diff; int ret; + (void)block_size; (void)flags; if (sqfs_data_writer_begin_file(data, inode, 0)) @@ -24,20 +26,19 @@ int write_data_from_file(sqfs_data_writer_t *data, sqfs_inode_generic_t *inode, sqfs_inode_get_file_size(inode, &filesz); for (offset = 0; offset < filesz; offset += diff) { - if (filesz - offset > (uint64_t)block_size) { - diff = block_size; + if (filesz - offset > sizeof(buffer)) { + diff = sizeof(buffer); } else { diff = filesz - offset; } - ret = sqfs_file_create_block(file, offset, diff, - NULL, 0, &blk); - + ret = file->read_at(file, offset, buffer, diff); if (ret) - return -1; + return ret; - if (sqfs_data_writer_enqueue(data, blk)) - return -1; + ret = sqfs_data_writer_append(data, buffer, diff); + if (ret) + return ret; } return sqfs_data_writer_end_file(data); |