aboutsummaryrefslogtreecommitdiffstats
path: root/package/utils
diff options
context:
space:
mode:
authorAndre Heider <a.heider@gmail.com>2021-12-15 12:48:26 +0100
committerDavid Bauer <mail@david-bauer.net>2022-12-07 12:30:23 +0100
commit8138d66fccd1131eb18f47ed1d16a24c7ce89b99 (patch)
tree65ae715b90dae3fa2ac587c5abcff57a51a83cfc /package/utils
parent902378dc87a88ad3242a8bc4812f8ee6dbf08a90 (diff)
downloadupstream-8138d66fccd1131eb18f47ed1d16a24c7ce89b99.tar.gz
upstream-8138d66fccd1131eb18f47ed1d16a24c7ce89b99.tar.bz2
upstream-8138d66fccd1131eb18f47ed1d16a24c7ce89b99.zip
fritz-tools: fritz_tffs_nand: cache already read sector ids
This speeds up the tool significantly, especially when using the "-a" argument. Signed-off-by: Andre Heider <a.heider@gmail.com>
Diffstat (limited to 'package/utils')
-rw-r--r--package/utils/fritz-tools/src/fritz_tffs_nand_read.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/package/utils/fritz-tools/src/fritz_tffs_nand_read.c b/package/utils/fritz-tools/src/fritz_tffs_nand_read.c
index 29b4a5d2e5..05179bb423 100644
--- a/package/utils/fritz-tools/src/fritz_tffs_nand_read.c
+++ b/package/utils/fritz-tools/src/fritz_tffs_nand_read.c
@@ -75,6 +75,7 @@ static uint32_t blocksize;
static int mtdfd;
static uint32_t num_sectors;
static uint8_t *sectors;
+static uint32_t *sector_ids;
static inline void sector_mark_bad(int num)
{
@@ -135,6 +136,8 @@ static int read_sector(off_t pos)
return -1;
}
+ sector_ids[pos / TFFS_SECTOR_SIZE] = read_uint32(readbuf, 0x00);
+
return 0;
}
@@ -178,6 +181,17 @@ static int find_entry(uint32_t id, struct tffs_entry *entry)
block_end = 0;
}
} else if (sector_get_good(sector)) {
+ if (sector_ids[sector]) {
+ if (sector_ids[sector] == TFFS_ID_END) {
+ /* no more entries in this block */
+ block_end = 1;
+ continue;
+ }
+
+ if (sector_ids[sector] != id)
+ continue;
+ }
+
if (read_sectoroob(pos) || read_sector(pos)) {
fprintf(stderr, "ERROR: sector isn't readable, but has been previously!\n");
exit(EXIT_FAILURE);
@@ -415,7 +429,8 @@ static int scan_mtd(void)
num_sectors = info.size / TFFS_SECTOR_SIZE;
sectors = malloc((num_sectors + 7) / 8);
- if (sectors == NULL) {
+ sector_ids = calloc(num_sectors, sizeof(uint32_t));
+ if (!sectors || !sector_ids) {
fprintf(stderr, "ERROR: memory allocation failed!\n");
exit(EXIT_FAILURE);
}
@@ -563,6 +578,7 @@ int main(int argc, char *argv[])
out_free_entry:
free(name_table.val);
out_free_sectors:
+ free(sector_ids);
free(sectors);
out_close:
close(mtdfd);