diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-07-25 20:09:20 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2019-07-25 20:13:11 +0200 |
commit | 37bf7752c31d8fda8faad0cf5f89328215305c60 (patch) | |
tree | 2d005da012ae20c62f93b47b713c42aaa46fe589 /lib/sqfs/id_table_read.c | |
parent | f49fe3bbf0d52e2afcc1ace8c1f48dee9349d4f8 (diff) |
Add generic read_table function similar to write_table
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/sqfs/id_table_read.c')
-rw-r--r-- | lib/sqfs/id_table_read.c | 52 |
1 files changed, 5 insertions, 47 deletions
diff --git a/lib/sqfs/id_table_read.c b/lib/sqfs/id_table_read.c index 1e92f75..bed0cf4 100644 --- a/lib/sqfs/id_table_read.c +++ b/lib/sqfs/id_table_read.c @@ -1,21 +1,16 @@ /* SPDX-License-Identifier: GPL-3.0-or-later */ #include "config.h" -#include "meta_reader.h" #include "highlevel.h" #include "util.h" #include <stdlib.h> -#include <unistd.h> #include <stdio.h> int id_table_read(id_table_t *tbl, int fd, sqfs_super_t *super, compressor_t *cmp) { - size_t i, block_count, count, diff; - uint64_t blocks[32]; - meta_reader_t *m; - uint32_t *ptr; + size_t i; if (tbl->ids != NULL) { free(tbl->ids); @@ -29,54 +24,17 @@ int id_table_read(id_table_t *tbl, int fd, sqfs_super_t *super, return -1; } - tbl->ids = calloc(super->id_count, sizeof(uint32_t)); - if (tbl->ids == NULL) { - perror("reading ID table"); - return -1; - } - tbl->num_ids = super->id_count; tbl->max_ids = super->id_count; - - block_count = super->id_count / 2048; - if (super->id_count % 2048) - ++block_count; - - if (read_data_at("reading ID table", super->id_table_start, fd, - blocks, sizeof(blocks[0]) * block_count)) { - return -1; - } - - for (i = 0; i < block_count; ++i) - blocks[i] = le64toh(blocks[i]); - - m = meta_reader_create(fd, cmp); - if (m == NULL) + tbl->ids = sqfs_read_table(fd, cmp, tbl->num_ids * sizeof(uint32_t), + super->id_table_start); + if (tbl->ids == NULL) { + free(tbl); return -1; - - count = super->id_count; - ptr = tbl->ids; - - for (i = 0; i < block_count && count > 0; ++i) { - diff = count < 2048 ? count : 2048; - - if (meta_reader_seek(m, blocks[i], 0)) - goto fail_meta; - - if (meta_reader_read(m, ptr, diff * sizeof(tbl->ids[0]))) - goto fail_meta; - - count -= diff; - ptr += diff; } - meta_reader_destroy(m); - for (i = 0; i < tbl->num_ids; ++i) tbl->ids[i] = le32toh(tbl->ids[i]); return 0; -fail_meta: - meta_reader_destroy(m); - return -1; } |