Skip to content

Commit

Permalink
Squashfs: extend decompressor framework to handle compression options
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Phillip Lougher committed Feb 28, 2011
1 parent 100b33c commit b7fc0ff
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 16 deletions.
34 changes: 34 additions & 0 deletions fs/squashfs/decompressor.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <linux/types.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/buffer_head.h>

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

return decompressor[i];
}


void *squashfs_decompressor_init(struct super_block *sb, unsigned short flags)
{
struct squashfs_sb_info *msblk = sb->s_fs_info;
void *strm, *buffer = NULL;
int length = 0;

/*
* Read decompressor specific options from file system if present
*/
if (SQUASHFS_COMP_OPTS(flags)) {
buffer = kmalloc(PAGE_CACHE_SIZE, GFP_KERNEL);
if (buffer == NULL)
return ERR_PTR(-ENOMEM);

length = squashfs_read_data(sb, &buffer,
sizeof(struct squashfs_super_block), 0, NULL,
PAGE_CACHE_SIZE, 1);

if (length < 0) {
strm = ERR_PTR(length);
goto finished;
}
}

strm = msblk->decompressor->init(msblk, buffer, length);

finished:
kfree(buffer);

return strm;
}
7 changes: 1 addition & 6 deletions fs/squashfs/decompressor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/

struct squashfs_decompressor {
void *(*init)(struct squashfs_sb_info *);
void *(*init)(struct squashfs_sb_info *, void *, int);
void (*free)(void *);
int (*decompress)(struct squashfs_sb_info *, void **,
struct buffer_head **, int, int, int, int, int);
Expand All @@ -33,11 +33,6 @@ struct squashfs_decompressor {
int supported;
};

static inline void *squashfs_decompressor_init(struct squashfs_sb_info *msblk)
{
return msblk->decompressor->init(msblk);
}

static inline void squashfs_decompressor_free(struct squashfs_sb_info *msblk,
void *s)
{
Expand Down
4 changes: 2 additions & 2 deletions fs/squashfs/lzo_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct squashfs_lzo {
void *output;
};

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

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


Expand Down
1 change: 1 addition & 0 deletions fs/squashfs/squashfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extern int squashfs_read_table(struct super_block *, void *, u64, int);

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

/* export.c */
extern __le64 *squashfs_read_inode_lookup_table(struct super_block *, u64,
Expand Down
4 changes: 4 additions & 0 deletions fs/squashfs/squashfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#define SQUASHFS_ALWAYS_FRAG 5
#define SQUASHFS_DUPLICATE 6
#define SQUASHFS_EXPORT 7
#define SQUASHFS_COMP_OPT 10

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

Expand All @@ -81,6 +82,9 @@
#define SQUASHFS_EXPORTABLE(flags) SQUASHFS_BIT(flags, \
SQUASHFS_EXPORT)

#define SQUASHFS_COMP_OPTS(flags) SQUASHFS_BIT(flags, \
SQUASHFS_COMP_OPT)

/* Max number of types and file types */
#define SQUASHFS_DIR_TYPE 1
#define SQUASHFS_REG_TYPE 2
Expand Down
11 changes: 7 additions & 4 deletions fs/squashfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)

err = -ENOMEM;

msblk->stream = squashfs_decompressor_init(msblk);
if (msblk->stream == NULL)
goto failed_mount;

msblk->block_cache = squashfs_cache_init("metadata",
SQUASHFS_CACHED_BLKS, SQUASHFS_METADATA_SIZE);
if (msblk->block_cache == NULL)
Expand All @@ -215,6 +211,13 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
goto failed_mount;
}

msblk->stream = squashfs_decompressor_init(sb, flags);
if (IS_ERR(msblk->stream)) {
err = PTR_ERR(msblk->stream);
msblk->stream = NULL;
goto failed_mount;
}

/* Allocate and read id index table */
msblk->id_table = squashfs_read_id_index_table(sb,
le64_to_cpu(sblk->id_table_start), le16_to_cpu(sblk->no_ids));
Expand Down
5 changes: 3 additions & 2 deletions fs/squashfs/xz_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ struct squashfs_xz {
struct xz_buf buf;
};

static void *squashfs_xz_init(struct squashfs_sb_info *msblk)
static void *squashfs_xz_init(struct squashfs_sb_info *msblk, void *buff,
int len)
{
int block_size = max_t(int, msblk->block_size, SQUASHFS_METADATA_SIZE);

Expand All @@ -55,7 +56,7 @@ static void *squashfs_xz_init(struct squashfs_sb_info *msblk)
failed:
ERROR("Failed to allocate xz workspace\n");
kfree(stream);
return NULL;
return ERR_PTR(-ENOMEM);
}


Expand Down
4 changes: 2 additions & 2 deletions fs/squashfs/zlib_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "squashfs.h"
#include "decompressor.h"

static void *zlib_init(struct squashfs_sb_info *dummy)
static void *zlib_init(struct squashfs_sb_info *dummy, void *buff, int len)
{
z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL);
if (stream == NULL)
Expand All @@ -47,7 +47,7 @@ static void *zlib_init(struct squashfs_sb_info *dummy)
failed:
ERROR("Failed to allocate zlib workspace\n");
kfree(stream);
return NULL;
return ERR_PTR(-ENOMEM);
}


Expand Down

0 comments on commit b7fc0ff

Please sign in to comment.