aboutsummaryrefslogtreecommitdiff
path: root/lib/sqfshelper
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-15 17:56:07 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-09-15 17:59:00 +0200
commit8ee3ee9c71418dbdb73d4350c17056024fb7ec41 (patch)
tree28416eda2893ed28750c29b41b64d783a1aaa35d /lib/sqfshelper
parentab2d7fd8bfb1eafc61953e74757e84ed407b1f21 (diff)
Replace file descriptor IO in data_writer with sqfs_file_t
First, this commit moves the create-blocks-from-fd function over to libsquashfs and ports it to work on an sqfs_file_t instead. Second, the function in the data_writer that reads from a file descriptor is adjusted to use an sqfs_file_t instead. Finally, the tools that use it have to be adjusted accordingly. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfshelper')
-rw-r--r--lib/sqfshelper/data_writer.c44
1 files changed, 12 insertions, 32 deletions
diff --git a/lib/sqfshelper/data_writer.c b/lib/sqfshelper/data_writer.c
index 43d5851..edd1770 100644
--- a/lib/sqfshelper/data_writer.c
+++ b/lib/sqfshelper/data_writer.c
@@ -319,34 +319,11 @@ static int add_sentinel_block(data_writer_t *data, file_info_t *fi,
return sqfs_block_processor_enqueue(data->proc, blk);
}
-static sqfs_block_t *create_block(file_info_t *fi, int fd, size_t size,
- uint32_t flags)
-{
- sqfs_block_t *blk = alloc_flex(sizeof(*blk), 1, size);
-
- if (blk == NULL) {
- perror(fi->input_file);
- return NULL;
- }
-
- if (fd >= 0) {
- if (read_data(fi->input_file, fd, blk->data, size)) {
- free(blk);
- return NULL;
- }
- }
-
- blk->size = size;
- blk->user = fi;
- blk->flags = flags;
- return blk;
-}
-
-int write_data_from_fd(data_writer_t *data, file_info_t *fi,
- int infd, int flags)
+int write_data_from_file(data_writer_t *data, file_info_t *fi,
+ sqfs_file_t *file, int flags)
{
uint32_t blk_flags = BLK_FIRST_BLOCK;
- uint64_t file_size = fi->size;
+ uint64_t offset, file_size;
size_t diff, i = 0;
sqfs_block_t *blk;
@@ -356,16 +333,19 @@ int write_data_from_fd(data_writer_t *data, file_info_t *fi,
if (flags & DW_ALLIGN_DEVBLK)
blk_flags |= BLK_ALLIGN;
- for (; file_size > 0; file_size -= diff) {
- if (file_size > data->super->block_size) {
+ file_size = file->get_size(file);
+
+ for (offset = 0; offset < file_size; offset += diff) {
+ if (file_size - offset > data->super->block_size) {
diff = data->super->block_size;
} else {
- diff = file_size;
+ diff = file_size - offset;
}
- blk = create_block(fi, infd, diff, blk_flags);
- if (blk == NULL)
+ if (sqfs_file_create_block(file, offset, diff, fi,
+ blk_flags, &blk)) {
return -1;
+ }
blk->index = i++;
@@ -405,7 +385,7 @@ int write_data_from_fd(data_writer_t *data, file_info_t *fi,
return -1;
}
- data->stats.bytes_read += fi->size;
+ data->stats.bytes_read += file_size;
data->stats.file_count += 1;
return 0;
}