summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-22 23:38:23 +0100
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-02-22 23:38:23 +0100
commit7350bebc4ceee0bf065e73f392edb725f8d0cd14 (patch)
tree002dcaf28f184e473bd33117ff59a3626701c241
parentaecc6dc5a9971eb4f1309f0754b0f213347c4d11 (diff)
libcommon: stdin file: Fix size accounting for sparse files
The file has to report the "apparent size" for sparse files, but internally work with the actual size in the tar ball. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/common/io_stdin.c17
-rw-r--r--tar/tar2sqfs.c21
2 files changed, 17 insertions, 21 deletions
diff --git a/lib/common/io_stdin.c b/lib/common/io_stdin.c
index 469e300..4694989 100644
--- a/lib/common/io_stdin.c
+++ b/lib/common/io_stdin.c
@@ -16,7 +16,8 @@ typedef struct {
const sparse_map_t *map;
sqfs_u64 offset;
- sqfs_u64 size;
+ sqfs_u64 real_size;
+ sqfs_u64 apparent_size;
FILE *fp;
} sqfs_file_stdinout_t;
@@ -28,7 +29,7 @@ static void stdinout_destroy(sqfs_object_t *base)
static sqfs_u64 stdinout_get_size(const sqfs_file_t *base)
{
- return ((const sqfs_file_stdinout_t *)base)->size;
+ return ((const sqfs_file_stdinout_t *)base)->apparent_size;
}
static int stdinout_truncate(sqfs_file_t *base, sqfs_u64 size)
@@ -54,7 +55,7 @@ static int stdin_read_at(sqfs_file_t *base, sqfs_u64 offset,
temp = alloca(temp_size);
}
- if (offset >= file->size || (offset + size) > file->size)
+ if (offset >= file->real_size || (offset + size) > file->real_size)
return SQFS_ERROR_OUT_OF_BOUNDS;
while (size > 0) {
@@ -151,14 +152,22 @@ sqfs_file_t *sqfs_get_stdin_file(FILE *fp, const sparse_map_t *map,
{
sqfs_file_stdinout_t *file = calloc(1, sizeof(*file));
sqfs_file_t *base = (sqfs_file_t *)file;
+ const sparse_map_t *it;
if (file == NULL)
return NULL;
- file->size = size;
+ file->apparent_size = size;
file->map = map;
file->fp = fp;
+ if (map != NULL) {
+ for (it = map; it != NULL; it = it->next)
+ file->real_size += map->count;
+ } else {
+ file->real_size = size;
+ }
+
((sqfs_object_t *)base)->destroy = stdinout_destroy;
base->write_at = stdin_write_at;
base->get_size = stdinout_get_size;
diff --git a/tar/tar2sqfs.c b/tar/tar2sqfs.c
index f505f6b..69d445e 100644
--- a/tar/tar2sqfs.c
+++ b/tar/tar2sqfs.c
@@ -250,11 +250,9 @@ fail_arg:
static int write_file(tar_header_decoded_t *hdr, file_info_t *fi,
sqfs_u64 filesize)
{
- const sparse_map_t *it;
sqfs_inode_generic_t *inode;
size_t size, max_blk_count;
sqfs_file_t *file;
- sqfs_u64 sum;
int flags;
int ret;
@@ -278,21 +276,10 @@ static int write_file(tar_header_decoded_t *hdr, file_info_t *fi,
inode->base.type = SQFS_INODE_FILE;
fi->user_ptr = inode;
- if (hdr->sparse != NULL) {
- for (sum = 0, it = hdr->sparse; it != NULL; it = it->next)
- sum += it->count;
-
- file = sqfs_get_stdin_file(input_file, hdr->sparse, sum);
- if (file == NULL) {
- perror("packing files");
- return -1;
- }
- } else {
- file = sqfs_get_stdin_file(input_file, NULL, filesize);
- if (file == NULL) {
- perror("packing files");
- return -1;
- }
+ file = sqfs_get_stdin_file(input_file, hdr->sparse, filesize);
+ if (file == NULL) {
+ perror("packing files");
+ return -1;
}
flags = 0;