diff options
Diffstat (limited to 'lib/sqfs/read_table.c')
-rw-r--r-- | lib/sqfs/read_table.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/sqfs/read_table.c b/lib/sqfs/read_table.c index d2664d4..843247e 100644 --- a/lib/sqfs/read_table.c +++ b/lib/sqfs/read_table.c @@ -8,27 +8,27 @@ #include "config.h" #include "sqfs/meta_reader.h" -#include "highlevel.h" +#include "sqfs/error.h" +#include "sqfs/table.h" +#include "sqfs/data.h" #include "util.h" #include <endian.h> #include <stdlib.h> -#include <stdio.h> -void *sqfs_read_table(int fd, sqfs_compressor_t *cmp, size_t table_size, - uint64_t location, uint64_t lower_limit, - uint64_t upper_limit) +int sqfs_read_table(int fd, sqfs_compressor_t *cmp, size_t table_size, + uint64_t location, uint64_t lower_limit, + uint64_t upper_limit, void **out) { size_t diff, block_count, blk_idx = 0; uint64_t start, *locations; sqfs_meta_reader_t *m; void *data, *ptr; + int err; data = malloc(table_size); - if (data == NULL) { - perror("reading table"); - return NULL; - } + if (data == NULL) + return SQFS_ERROR_ALLOC; /* restore list from image */ block_count = table_size / SQFS_META_BLOCK_SIZE; @@ -39,33 +39,38 @@ void *sqfs_read_table(int fd, sqfs_compressor_t *cmp, size_t table_size, locations = alloc_array(sizeof(uint64_t), block_count); if (locations == NULL) { - perror("allocation table location list"); + err = SQFS_ERROR_ALLOC; goto fail_data; } if (read_data_at("reading table locations", location, fd, locations, sizeof(uint64_t) * block_count)) { + err = SQFS_ERROR_IO; goto fail_idx; } /* Read the actual data */ m = sqfs_meta_reader_create(fd, cmp, lower_limit, upper_limit); - if (m == NULL) + if (m == NULL) { + err = SQFS_ERROR_ALLOC; goto fail_idx; + } ptr = data; while (table_size > 0) { start = le64toh(locations[blk_idx++]); - if (sqfs_meta_reader_seek(m, start, 0)) + err = sqfs_meta_reader_seek(m, start, 0); + if (err) goto fail; diff = SQFS_META_BLOCK_SIZE; if (diff > table_size) diff = table_size; - if (sqfs_meta_reader_read(m, ptr, diff)) + err = sqfs_meta_reader_read(m, ptr, diff); + if (err) goto fail; ptr = (char *)ptr + diff; @@ -74,12 +79,14 @@ void *sqfs_read_table(int fd, sqfs_compressor_t *cmp, size_t table_size, sqfs_meta_reader_destroy(m); free(locations); - return data; + *out = data; + return 0; fail: sqfs_meta_reader_destroy(m); fail_idx: free(locations); fail_data: free(data); - return NULL; + *out = NULL; + return err; } |