Skip to content

Commit b7fc0ff

Browse files
author
Phillip Lougher
committed
Squashfs: extend decompressor framework to handle compression options
Extend decompressor framework to handle compression options stored in the filesystem. These options can be used by the relevant decompressor at initialisation time to over-ride defaults. The presence of compression options in the filesystem is indicated by the COMP_OPT filesystem flag. If present the data is read from the filesystem and passed to the decompressor init function. The decompressor init function signature has been extended to take this data. Also update the init function signature in the glib, lzo and xz decompressor wrappers. Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
1 parent 100b33c commit b7fc0ff

8 files changed

Lines changed: 54 additions & 16 deletions

File tree

‎fs/squashfs/decompressor.c‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include <linux/types.h>
2525
#include <linux/mutex.h>
26+
#include <linux/slab.h>
2627
#include <linux/buffer_head.h>
2728

2829
#include "squashfs_fs.h"
@@ -74,3 +75,36 @@ const struct squashfs_decompressor *squashfs_lookup_decompressor(int id)
7475

7576
return decompressor[i];
7677
}
78+
79+
80+
void *squashfs_decompressor_init(struct super_block *sb, unsigned short flags)
81+
{
82+
struct squashfs_sb_info *msblk = sb->s_fs_info;
83+
void *strm, *buffer = NULL;
84+
int length = 0;
85+
86+
/*
87+
* Read decompressor specific options from file system if present
88+
*/
89+
if (SQUASHFS_COMP_OPTS(flags)) {
90+
buffer = kmalloc(PAGE_CACHE_SIZE, GFP_KERNEL);
91+
if (buffer == NULL)
92+
return ERR_PTR(-ENOMEM);
93+
94+
length = squashfs_read_data(sb, &buffer,
95+
sizeof(struct squashfs_super_block), 0, NULL,
96+
PAGE_CACHE_SIZE, 1);
97+
98+
if (length < 0) {
99+
strm = ERR_PTR(length);
100+
goto finished;
101+
}
102+
}
103+
104+
strm = msblk->decompressor->init(msblk, buffer, length);
105+
106+
finished:
107+
kfree(buffer);
108+
109+
return strm;
110+
}

‎fs/squashfs/decompressor.h‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525

2626
struct squashfs_decompressor {
27-
void *(*init)(struct squashfs_sb_info *);
27+
void *(*init)(struct squashfs_sb_info *, void *, int);
2828
void (*free)(void *);
2929
int (*decompress)(struct squashfs_sb_info *, void **,
3030
struct buffer_head **, int, int, int, int, int);
@@ -33,11 +33,6 @@ struct squashfs_decompressor {
3333
int supported;
3434
};
3535

36-
static inline void *squashfs_decompressor_init(struct squashfs_sb_info *msblk)
37-
{
38-
return msblk->decompressor->init(msblk);
39-
}
40-
4136
static inline void squashfs_decompressor_free(struct squashfs_sb_info *msblk,
4237
void *s)
4338
{

‎fs/squashfs/lzo_wrapper.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct squashfs_lzo {
3737
void *output;
3838
};
3939

40-
static void *lzo_init(struct squashfs_sb_info *msblk)
40+
static void *lzo_init(struct squashfs_sb_info *msblk, void *buff, int len)
4141
{
4242
int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
4343

@@ -58,7 +58,7 @@ static void *lzo_init(struct squashfs_sb_info *msblk)
5858
failed:
5959
ERROR("Failed to allocate lzo workspace\n");
6060
kfree(stream);
61-
return NULL;
61+
return ERR_PTR(-ENOMEM);
6262
}
6363

6464

‎fs/squashfs/squashfs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ extern int squashfs_read_table(struct super_block *, void *, u64, int);
4848

4949
/* decompressor.c */
5050
extern const struct squashfs_decompressor *squashfs_lookup_decompressor(int);
51+
extern void *squashfs_decompressor_init(struct super_block *, unsigned short);
5152

5253
/* export.c */
5354
extern __le64 *squashfs_read_inode_lookup_table(struct super_block *, u64,

‎fs/squashfs/squashfs_fs.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#define SQUASHFS_ALWAYS_FRAG 5
5858
#define SQUASHFS_DUPLICATE 6
5959
#define SQUASHFS_EXPORT 7
60+
#define SQUASHFS_COMP_OPT 10
6061

6162
#define SQUASHFS_BIT(flag, bit) ((flag >> bit) & 1)
6263

@@ -81,6 +82,9 @@
8182
#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
8283
SQUASHFS_EXPORT)
8384

85+
#define SQUASHFS_COMP_OPTS(flags) SQUASHFS_BIT(flags, \
86+
SQUASHFS_COMP_OPT)
87+
8488
/* Max number of types and file types */
8589
#define SQUASHFS_DIR_TYPE 1
8690
#define SQUASHFS_REG_TYPE 2

‎fs/squashfs/super.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,6 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
199199

200200
err = -ENOMEM;
201201

202-
msblk->stream = squashfs_decompressor_init(msblk);
203-
if (msblk->stream == NULL)
204-
goto failed_mount;
205-
206202
msblk->block_cache = squashfs_cache_init("metadata",
207203
SQUASHFS_CACHED_BLKS, SQUASHFS_METADATA_SIZE);
208204
if (msblk->block_cache == NULL)
@@ -215,6 +211,13 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
215211
goto failed_mount;
216212
}
217213

214+
msblk->stream = squashfs_decompressor_init(sb, flags);
215+
if (IS_ERR(msblk->stream)) {
216+
err = PTR_ERR(msblk->stream);
217+
msblk->stream = NULL;
218+
goto failed_mount;
219+
}
220+
218221
/* Allocate and read id index table */
219222
msblk->id_table = squashfs_read_id_index_table(sb,
220223
le64_to_cpu(sblk->id_table_start), le16_to_cpu(sblk->no_ids));

‎fs/squashfs/xz_wrapper.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ struct squashfs_xz {
3838
struct xz_buf buf;
3939
};
4040

41-
static void *squashfs_xz_init(struct squashfs_sb_info *msblk)
41+
static void *squashfs_xz_init(struct squashfs_sb_info *msblk, void *buff,
42+
int len)
4243
{
4344
int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);
4445

@@ -55,7 +56,7 @@ static void *squashfs_xz_init(struct squashfs_sb_info *msblk)
5556
failed:
5657
ERROR("Failed to allocate xz workspace\n");
5758
kfree(stream);
58-
return NULL;
59+
return ERR_PTR(-ENOMEM);
5960
}
6061

6162

‎fs/squashfs/zlib_wrapper.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include "squashfs.h"
3333
#include "decompressor.h"
3434

35-
static void *zlib_init(struct squashfs_sb_info *dummy)
35+
static void *zlib_init(struct squashfs_sb_info *dummy, void *buff, int len)
3636
{
3737
z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL);
3838
if (stream == NULL)
@@ -47,7 +47,7 @@ static void *zlib_init(struct squashfs_sb_info *dummy)
4747
failed:
4848
ERROR("Failed to allocate zlib workspace\n");
4949
kfree(stream);
50-
return NULL;
50+
return ERR_PTR(-ENOMEM);
5151
}
5252

5353

0 commit comments

Comments
 (0)