diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-15 20:40:01 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-09-15 20:44:41 +0200 |
commit | 428aa363dd2b44756a5b16aa17e8c2030de801a0 (patch) | |
tree | 8bc507fdcc795a5c75ef7a148e66e940d4df91b9 /lib/sqfshelper | |
parent | 129e1758a5e2cf851f042e139fdd808a9be9ce94 (diff) |
Move condensed-sparse-file handling to libsquashfs
Add another helper function for getting a blocks from a condensed sparse
file, then rewrite the data writer to use that instead, using an
sqfs_file_t pointer instead of direct file i/o.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfshelper')
-rw-r--r-- | lib/sqfshelper/data_writer.c | 80 |
1 files changed, 7 insertions, 73 deletions
diff --git a/lib/sqfshelper/data_writer.c b/lib/sqfshelper/data_writer.c index a6d0297..92592c9 100644 --- a/lib/sqfshelper/data_writer.c +++ b/lib/sqfshelper/data_writer.c @@ -390,77 +390,15 @@ int write_data_from_file(data_writer_t *data, file_info_t *fi, return 0; } -static int check_map_valid(const sqfs_sparse_map_t *map, file_info_t *fi) -{ - const sqfs_sparse_map_t *m; - uint64_t offset; - - if (map != NULL) { - offset = map->offset; - - for (m = map; m != NULL; m = m->next) { - if (m->offset < offset) - goto fail_map; - offset = m->offset + m->count; - } - - if (offset > fi->size) - goto fail_map_size; - } - - return 0; -fail_map_size: - fprintf(stderr, "%s: sparse file map spans beyond file size\n", - fi->input_file); - return -1; -fail_map: - fprintf(stderr, - "%s: sparse file map is unordered or self overlapping\n", - fi->input_file); - return -1; -} - -static int get_sparse_block(sqfs_block_t *blk, file_info_t *fi, int infd, - sqfs_sparse_map_t **sparse_map, uint64_t offset, - size_t diff) -{ - sqfs_sparse_map_t *map = *sparse_map; - size_t start, count; - - while (map != NULL && map->offset < offset + diff) { - start = 0; - count = map->count; - - if (map->offset < offset) - count -= offset - map->offset; - - if (map->offset > offset) - start = map->offset - offset; - - if (start + count > diff) - count = diff - start; - - if (read_data(fi->input_file, infd, blk->data + start, count)) - return -1; - - map = map->next; - } - - *sparse_map = map; - return 0; -} - -int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi, - int infd, sqfs_sparse_map_t *map, int flags) +int write_data_from_file_condensed(data_writer_t *data, sqfs_file_t *file, + file_info_t *fi, + const sqfs_sparse_map_t *map, int flags) { uint32_t blk_flags = BLK_FIRST_BLOCK; size_t diff, i = 0; sqfs_block_t *blk; uint64_t offset; - if (check_map_valid(map, fi)) - return -1; - if (flags & DW_DONT_COMPRESS) blk_flags |= SQFS_BLK_DONT_COMPRESS; @@ -474,17 +412,13 @@ int write_data_from_fd_condensed(data_writer_t *data, file_info_t *fi, diff = fi->size - offset; } - blk = alloc_flex(sizeof(*blk), 1, diff); - blk->size = diff; - blk->index = i++; - blk->user = fi; - blk->flags = blk_flags; - - if (get_sparse_block(blk, fi, infd, &map, offset, diff)) { - free(blk); + if (sqfs_file_create_block_dense(file, offset, diff, fi, + blk_flags, map, &blk)) { return -1; } + blk->index = i++; + if (is_zero_block(blk->data, blk->size)) { data->stats.sparse_blocks += 1; |