From 4a091b656c0861e3f9335c38af25040cb3ff03c8 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 19 Jan 2020 20:05:13 +0100 Subject: Cleanup: remove the payload pointers from sqfs_inode_generic_t There are 3 types of extra payload: - Directory index - File block sizes - Symlink target This commit removes the type specific pointers and modifies the code to use the payload area directly. To simplify the file block case and mitigate alignment issues, the type of the extra field is changed to sqfs_u32. For symlink target, the extra field can simply be cast to a character pointer (it had to be cast anyway for most uses). For block sizes, probably the most common usecase, it can be used as is. For directory indices, there is a helper function anyway. Signed-off-by: David Oberhollenzer --- lib/sqfs/data_reader.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'lib/sqfs/data_reader.c') diff --git a/lib/sqfs/data_reader.c b/lib/sqfs/data_reader.c index 6a0db35..af15b9b 100644 --- a/lib/sqfs/data_reader.c +++ b/lib/sqfs/data_reader.c @@ -219,14 +219,13 @@ int sqfs_data_reader_get_block(sqfs_data_reader_t *data, return SQFS_ERROR_OUT_OF_BOUNDS; for (i = 0; i < index; ++i) { - off += SQFS_ON_DISK_BLOCK_SIZE(inode->block_sizes[i]); + off += SQFS_ON_DISK_BLOCK_SIZE(inode->extra[i]); filesz -= data->block_size; } unpacked_size = filesz < data->block_size ? filesz : data->block_size; - return get_block(data, off, inode->block_sizes[index], - unpacked_size, out); + return get_block(data, off, inode->extra[index], unpacked_size, out); } int sqfs_data_reader_get_fragment(sqfs_data_reader_t *data, @@ -285,7 +284,7 @@ sqfs_s32 sqfs_data_reader_read(sqfs_data_reader_t *data, i = 0; while (offset > data->block_size && i < inode->num_file_blocks) { - off += SQFS_ON_DISK_BLOCK_SIZE(inode->block_sizes[i++]); + off += SQFS_ON_DISK_BLOCK_SIZE(inode->extra[i++]); offset -= data->block_size; if (filesz >= data->block_size) { @@ -301,17 +300,15 @@ sqfs_s32 sqfs_data_reader_read(sqfs_data_reader_t *data, if (size < diff) diff = size; - if (SQFS_IS_SPARSE_BLOCK(inode->block_sizes[i])) { + if (SQFS_IS_SPARSE_BLOCK(inode->extra[i])) { memset(buffer, 0, diff); } else { - if (precache_data_block(data, off, - inode->block_sizes[i])) { + if (precache_data_block(data, off, inode->extra[i])) return -1; - } memcpy(buffer, (char *)data->data_block->data + offset, diff); - off += SQFS_ON_DISK_BLOCK_SIZE(inode->block_sizes[i]); + off += SQFS_ON_DISK_BLOCK_SIZE(inode->extra[i]); } if (filesz >= data->block_size) { -- cgit v1.2.3