summaryrefslogtreecommitdiff
path: root/lib/sqfs/id_table_read.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sqfs/id_table_read.c')
-rw-r--r--lib/sqfs/id_table_read.c52
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;
}