summaryrefslogtreecommitdiff
path: root/lib/sqfs/frag_reader.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-16 21:02:58 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-07-16 22:48:00 +0200
commite3ef871d6a80d72db02c9ab1ef492e8f58c2ddeb (patch)
treeec28b205b651e83c795e1e264aacfe5bcb307bc4 /lib/sqfs/frag_reader.c
parentbfd876dbf151df164b4d87de20aec39b24f205f9 (diff)
cleanup: move error handling into read_retry
If read_retry fails to read the expected amount of data (EOF or otherwise), it is almost always an error. This commit renames read_retry to read_data and moves error handling into the function, making a lot of error handling code redundant. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/frag_reader.c')
-rw-r--r--lib/sqfs/frag_reader.c27
1 files changed, 7 insertions, 20 deletions
diff --git a/lib/sqfs/frag_reader.c b/lib/sqfs/frag_reader.c
index 0d13bcd..6fa160b 100644
--- a/lib/sqfs/frag_reader.c
+++ b/lib/sqfs/frag_reader.c
@@ -42,16 +42,8 @@ static int precache_block(frag_reader_t *f, size_t i)
return -1;
}
- ret = read_retry(f->fd, f->buffer, size);
- if (ret < 0) {
- perror("reading fragment");
+ if (read_data("reading fragment", f->fd, f->buffer, size))
return -1;
- }
-
- if ((size_t)ret < size) {
- fputs("reading fragment: unexpected end of file\n", stderr);
- return -1;
- }
if (compressed) {
ret = f->cmp->do_block(f->cmp, f->buffer, size,
@@ -62,11 +54,12 @@ static int precache_block(frag_reader_t *f, size_t i)
return -1;
}
+ size = ret;
memmove(f->buffer, f->buffer + f->block_size, ret);
}
f->current_index = i;
- f->used = ret;
+ f->used = size;
return 0;
}
@@ -79,7 +72,6 @@ frag_reader_t *frag_reader_create(sqfs_super_t *super, int fd,
uint64_t *locations = NULL;
meta_reader_t *m = NULL;
frag_reader_t *f = NULL;
- ssize_t ret;
count = super->fragment_entry_count;
blockcount = count / (SQFS_META_BLOCK_SIZE / sizeof(tbl[0]));
@@ -104,12 +96,10 @@ frag_reader_t *frag_reader_create(sqfs_super_t *super, int fd,
if (lseek(fd, super->fragment_table_start, SEEK_SET) == (off_t)-1)
goto fail_seek;
- ret = read_retry(fd, locations, blockcount * sizeof(locations[0]));
- if (ret < 0)
- goto fail_rd;
-
- if ((size_t)ret < (blockcount * sizeof(locations[0])))
- goto fail_trunc;
+ if (read_data("reading fragment table", fd, locations,
+ blockcount * sizeof(locations[0]))) {
+ goto fail;
+ }
for (i = 0; i < blockcount; ++i)
locations[i] = le64toh(locations[i]);
@@ -150,9 +140,6 @@ frag_reader_t *frag_reader_create(sqfs_super_t *super, int fd,
fail_seek:
perror("seek to fragment table");
goto fail;
-fail_trunc:
- fputs("reading fragment table: unexpected end of file\n", stderr);
- goto fail;
fail_rd:
perror("reading fragment table");
goto fail;