[PATCH v4 2/5] fs/squashfs: replace sqfs_decompress() parameter
Joao Marcos Costa
joaomarcos.costa at bootlin.com
Tue Aug 18 17:17:22 CEST 2020
Replace 'u16 comp_type' by a reference to squashfs_ctxt structure.
Signed-off-by: Joao Marcos Costa <joaomarcos.costa at bootlin.com>
---
Changes in v4:
- This patch was not present in the previous version.
fs/squashfs/sqfs.c | 25 +++++++++----------------
fs/squashfs/sqfs_decompressor.c | 5 +++--
fs/squashfs/sqfs_decompressor.h | 4 ++--
3 files changed, 14 insertions(+), 20 deletions(-)
diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c
index 598b42cd34..9bd7b98d88 100644
--- a/fs/squashfs/sqfs.c
+++ b/fs/squashfs/sqfs.c
@@ -104,9 +104,7 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
struct squashfs_super_block *sblk = ctxt.sblk;
unsigned long dest_len;
int block, offset, ret;
- u16 header, comp_type;
-
- comp_type = get_unaligned_le16(&sblk->compression);
+ u16 header;
if (inode_fragment_index >= get_unaligned_le32(&sblk->fragments))
return -EINVAL;
@@ -165,7 +163,7 @@ static int sqfs_frag_lookup(u32 inode_fragment_index,
if (SQFS_COMPRESSED_METADATA(header)) {
src_len = SQFS_METADATA_SIZE(header);
dest_len = SQFS_METADATA_BLOCK_SIZE;
- ret = sqfs_decompress(comp_type, entries, &dest_len, metadata,
+ ret = sqfs_decompress(&ctxt, entries, &dest_len, metadata,
src_len);
if (ret) {
ret = -EINVAL;
@@ -629,13 +627,12 @@ static int sqfs_read_inode_table(unsigned char **inode_table)
{
struct squashfs_super_block *sblk = ctxt.sblk;
u64 start, n_blks, table_offset, table_size;
- int j, ret = 0, metablks_count, comp_type;
+ int j, ret = 0, metablks_count;
unsigned char *src_table, *itb;
u32 src_len, dest_offset = 0;
unsigned long dest_len;
bool compressed;
- comp_type = get_unaligned_le16(&sblk->compression);
table_size = get_unaligned_le64(&sblk->directory_table_start) -
get_unaligned_le64(&sblk->inode_table_start);
start = get_unaligned_le64(&sblk->inode_table_start) /
@@ -680,7 +677,7 @@ static int sqfs_read_inode_table(unsigned char **inode_table)
sqfs_read_metablock(itb, table_offset, &compressed, &src_len);
if (compressed) {
dest_len = SQFS_METADATA_BLOCK_SIZE;
- ret = sqfs_decompress(comp_type, *inode_table +
+ ret = sqfs_decompress(&ctxt, *inode_table +
dest_offset, &dest_len,
src_table, src_len);
if (ret) {
@@ -711,15 +708,13 @@ free_itb:
static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list)
{
u64 start, n_blks, table_offset, table_size;
- int j, ret = 0, metablks_count = -1, comp_type;
struct squashfs_super_block *sblk = ctxt.sblk;
+ int j, ret = 0, metablks_count = -1;
unsigned char *src_table, *dtb;
u32 src_len, dest_offset = 0;
unsigned long dest_len;
bool compressed;
- comp_type = get_unaligned_le16(&sblk->compression);
-
/* DIRECTORY TABLE */
table_size = get_unaligned_le64(&sblk->fragment_table_start) -
get_unaligned_le64(&sblk->directory_table_start);
@@ -773,7 +768,7 @@ static int sqfs_read_directory_table(unsigned char **dir_table, u32 **pos_list)
sqfs_read_metablock(dtb, table_offset, &compressed, &src_len);
if (compressed) {
dest_len = SQFS_METADATA_BLOCK_SIZE;
- ret = sqfs_decompress(comp_type, *dir_table +
+ ret = sqfs_decompress(&ctxt, *dir_table +
(j * SQFS_METADATA_BLOCK_SIZE),
&dest_len, src_table, src_len);
if (ret) {
@@ -1197,7 +1192,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
char *dir, *fragment_block, *datablock = NULL, *data_buffer = NULL;
char *fragment, *file, *resolved, *data;
u64 start, n_blks, table_size, data_offset, table_offset;
- int ret, j, i_number, comp_type, datablk_count = 0;
+ int ret, j, i_number, datablk_count = 0;
struct squashfs_super_block *sblk = ctxt.sblk;
struct squashfs_fragment_block_entry frag_entry;
struct squashfs_file_info finfo = {0};
@@ -1213,8 +1208,6 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
*actread = 0;
- comp_type = get_unaligned_le16(&sblk->compression);
-
/*
* sqfs_opendir will uncompress inode and directory tables, and will
* return a pointer to the directory that contains the requested file.
@@ -1346,7 +1339,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
/* Load the data */
if (SQFS_COMPRESSED_BLOCK(finfo.blk_sizes[j])) {
dest_len = get_unaligned_le32(&sblk->block_size);
- ret = sqfs_decompress(comp_type, datablock, &dest_len,
+ ret = sqfs_decompress(&ctxt, datablock, &dest_len,
data, table_size);
if (ret)
goto free_buffer;
@@ -1396,7 +1389,7 @@ int sqfs_read(const char *filename, void *buf, loff_t offset, loff_t len,
goto free_fragment;
}
- ret = sqfs_decompress(comp_type, fragment_block, &dest_len,
+ ret = sqfs_decompress(&ctxt, fragment_block, &dest_len,
(void *)fragment + table_offset,
frag_entry.size);
if (ret) {
diff --git a/fs/squashfs/sqfs_decompressor.c b/fs/squashfs/sqfs_decompressor.c
index 633a8a1818..cf388ace58 100644
--- a/fs/squashfs/sqfs_decompressor.c
+++ b/fs/squashfs/sqfs_decompressor.c
@@ -62,9 +62,10 @@ static void zlib_decompression_status(int ret)
}
#endif
-int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len,
- void *source, u32 src_len)
+int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest,
+ unsigned long *dest_len, void *source, u32 src_len)
{
+ u16 comp_type = get_unaligned_le16(&ctxt->sblk->compression);
int ret = 0;
switch (comp_type) {
diff --git a/fs/squashfs/sqfs_decompressor.h b/fs/squashfs/sqfs_decompressor.h
index 450257e5ce..892cfb6974 100644
--- a/fs/squashfs/sqfs_decompressor.h
+++ b/fs/squashfs/sqfs_decompressor.h
@@ -53,8 +53,8 @@ union squashfs_compression_opts {
struct squashfs_lzo_opts *lzo;
};
-int sqfs_decompress(u16 comp_type, void *dest, unsigned long *dest_len,
- void *source, u32 lenp);
+int sqfs_decompress(struct squashfs_ctxt *ctxt, void *dest,
+ unsigned long *dest_len, void *source, u32 src_len);
int sqfs_decompressor_init(struct squashfs_ctxt *ctxt);
void sqfs_decompressor_cleanup(struct squashfs_ctxt *ctxt);
--
2.17.1
More information about the U-Boot
mailing list