Skip to content

Commit

Permalink
Merge git://git.kernel.org/pub/scm/linux/kernel/git/pkl/squashfs-linus
Browse files Browse the repository at this point in the history
* git://git.kernel.org/pub/scm/linux/kernel/git/pkl/squashfs-linus:
  Squashfs: get rid of obsolete definition in header file
  Squashfs: get rid of obsolete variable in struct squashfs_sb_info
  Squashfs: add decompressor entries for lzma and lzo
  Squashfs: add a decompressor framework
  Squashfs: factor out remaining zlib dependencies into separate wrapper file
  Squashfs: move zlib decompression wrapper code into a separate file
  • Loading branch information
Linus Torvalds committed Mar 5, 2010
2 parents 64ba992 + 06862f8 commit b24bc1e
Show file tree
Hide file tree
Showing 18 changed files with 335 additions and 128 deletions.
2 changes: 1 addition & 1 deletion fs/squashfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

obj-$(CONFIG_SQUASHFS) += squashfs.o
squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o
squashfs-y += namei.o super.o symlink.o
squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o
76 changes: 5 additions & 71 deletions fs/squashfs/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
#include <linux/fs.h>
#include <linux/vfs.h>
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/string.h>
#include <linux/buffer_head.h>
#include <linux/zlib.h>

#include "squashfs_fs.h"
#include "squashfs_fs_sb.h"
#include "squashfs_fs_i.h"
#include "squashfs.h"
#include "decompressor.h"

/*
* Read the metadata block length, this is stored in the first two
Expand Down Expand Up @@ -153,72 +152,10 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
}

if (compressed) {
int zlib_err = 0, zlib_init = 0;

/*
* Uncompress block.
*/

mutex_lock(&msblk->read_data_mutex);

msblk->stream.avail_out = 0;
msblk->stream.avail_in = 0;

bytes = length;
do {
if (msblk->stream.avail_in == 0 && k < b) {
avail = min(bytes, msblk->devblksize - offset);
bytes -= avail;
wait_on_buffer(bh[k]);
if (!buffer_uptodate(bh[k]))
goto release_mutex;

if (avail == 0) {
offset = 0;
put_bh(bh[k++]);
continue;
}

msblk->stream.next_in = bh[k]->b_data + offset;
msblk->stream.avail_in = avail;
offset = 0;
}

if (msblk->stream.avail_out == 0 && page < pages) {
msblk->stream.next_out = buffer[page++];
msblk->stream.avail_out = PAGE_CACHE_SIZE;
}

if (!zlib_init) {
zlib_err = zlib_inflateInit(&msblk->stream);
if (zlib_err != Z_OK) {
ERROR("zlib_inflateInit returned"
" unexpected result 0x%x,"
" srclength %d\n", zlib_err,
srclength);
goto release_mutex;
}
zlib_init = 1;
}

zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);

if (msblk->stream.avail_in == 0 && k < b)
put_bh(bh[k++]);
} while (zlib_err == Z_OK);

if (zlib_err != Z_STREAM_END) {
ERROR("zlib_inflate error, data probably corrupt\n");
goto release_mutex;
}

zlib_err = zlib_inflateEnd(&msblk->stream);
if (zlib_err != Z_OK) {
ERROR("zlib_inflate error, data probably corrupt\n");
goto release_mutex;
}
length = msblk->stream.total_out;
mutex_unlock(&msblk->read_data_mutex);
length = squashfs_decompress(msblk, buffer, bh, b, offset,
length, srclength, pages);
if (length < 0)
goto read_failure;
} else {
/*
* Block is uncompressed.
Expand Down Expand Up @@ -255,9 +192,6 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
kfree(bh);
return length;

release_mutex:
mutex_unlock(&msblk->read_data_mutex);

block_release:
for (; k < b; k++)
put_bh(bh[k]);
Expand Down
1 change: 0 additions & 1 deletion fs/squashfs/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#include <linux/sched.h>
#include <linux/spinlock.h>
#include <linux/wait.h>
#include <linux/zlib.h>
#include <linux/pagemap.h>

#include "squashfs_fs.h"
Expand Down
68 changes: 68 additions & 0 deletions fs/squashfs/decompressor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Squashfs - a compressed read only filesystem for Linux
*
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
* Phillip Lougher <phillip@lougher.demon.co.uk>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* decompressor.c
*/

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

#include "squashfs_fs.h"
#include "squashfs_fs_sb.h"
#include "squashfs_fs_i.h"
#include "decompressor.h"
#include "squashfs.h"

/*
* This file (and decompressor.h) implements a decompressor framework for
* Squashfs, allowing multiple decompressors to be easily supported
*/

static const struct squashfs_decompressor squashfs_lzma_unsupported_comp_ops = {
NULL, NULL, NULL, LZMA_COMPRESSION, "lzma", 0
};

static const struct squashfs_decompressor squashfs_lzo_unsupported_comp_ops = {
NULL, NULL, NULL, LZO_COMPRESSION, "lzo", 0
};

static const struct squashfs_decompressor squashfs_unknown_comp_ops = {
NULL, NULL, NULL, 0, "unknown", 0
};

static const struct squashfs_decompressor *decompressor[] = {
&squashfs_zlib_comp_ops,
&squashfs_lzma_unsupported_comp_ops,
&squashfs_lzo_unsupported_comp_ops,
&squashfs_unknown_comp_ops
};


const struct squashfs_decompressor *squashfs_lookup_decompressor(int id)
{
int i;

for (i = 0; decompressor[i]->id; i++)
if (id == decompressor[i]->id)
break;

return decompressor[i];
}
55 changes: 55 additions & 0 deletions fs/squashfs/decompressor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef DECOMPRESSOR_H
#define DECOMPRESSOR_H
/*
* Squashfs - a compressed read only filesystem for Linux
*
* Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
* Phillip Lougher <phillip@lougher.demon.co.uk>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* decompressor.h
*/

struct squashfs_decompressor {
void *(*init)(struct squashfs_sb_info *);
void (*free)(void *);
int (*decompress)(struct squashfs_sb_info *, void **,
struct buffer_head **, int, int, int, int, int);
int id;
char *name;
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)
{
if (msblk->decompressor)
msblk->decompressor->free(s);
}

static inline int squashfs_decompress(struct squashfs_sb_info *msblk,
void **buffer, struct buffer_head **bh, int b, int offset, int length,
int srclength, int pages)
{
return msblk->decompressor->decompress(msblk, buffer, bh, b, offset,
length, srclength, pages);
}
#endif
1 change: 0 additions & 1 deletion fs/squashfs/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <linux/fs.h>
#include <linux/vfs.h>
#include <linux/slab.h>
#include <linux/zlib.h>

#include "squashfs_fs.h"
#include "squashfs_fs_sb.h"
Expand Down
1 change: 0 additions & 1 deletion fs/squashfs/export.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <linux/vfs.h>
#include <linux/dcache.h>
#include <linux/exportfs.h>
#include <linux/zlib.h>
#include <linux/slab.h>

#include "squashfs_fs.h"
Expand Down
1 change: 0 additions & 1 deletion fs/squashfs/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include <linux/string.h>
#include <linux/pagemap.h>
#include <linux/mutex.h>
#include <linux/zlib.h>

#include "squashfs_fs.h"
#include "squashfs_fs_sb.h"
Expand Down
1 change: 0 additions & 1 deletion fs/squashfs/fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
#include <linux/fs.h>
#include <linux/vfs.h>
#include <linux/slab.h>
#include <linux/zlib.h>

#include "squashfs_fs.h"
#include "squashfs_fs_sb.h"
Expand Down
1 change: 0 additions & 1 deletion fs/squashfs/id.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include <linux/fs.h>
#include <linux/vfs.h>
#include <linux/slab.h>
#include <linux/zlib.h>

#include "squashfs_fs.h"
#include "squashfs_fs_sb.h"
Expand Down
1 change: 0 additions & 1 deletion fs/squashfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

#include <linux/fs.h>
#include <linux/vfs.h>
#include <linux/zlib.h>

#include "squashfs_fs.h"
#include "squashfs_fs_sb.h"
Expand Down
1 change: 0 additions & 1 deletion fs/squashfs/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/dcache.h>
#include <linux/zlib.h>

#include "squashfs_fs.h"
#include "squashfs_fs_sb.h"
Expand Down
8 changes: 7 additions & 1 deletion fs/squashfs/squashfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ extern struct squashfs_cache_entry *squashfs_get_datablock(struct super_block *,
u64, int);
extern int squashfs_read_table(struct super_block *, void *, u64, int);

/* decompressor.c */
extern const struct squashfs_decompressor *squashfs_lookup_decompressor(int);

/* export.c */
extern __le64 *squashfs_read_inode_lookup_table(struct super_block *, u64,
unsigned int);
Expand All @@ -71,7 +74,7 @@ extern struct inode *squashfs_iget(struct super_block *, long long,
extern int squashfs_read_inode(struct inode *, long long);

/*
* Inodes and files operations
* Inodes, files and decompressor operations
*/

/* dir.c */
Expand All @@ -88,3 +91,6 @@ extern const struct inode_operations squashfs_dir_inode_ops;

/* symlink.c */
extern const struct address_space_operations squashfs_symlink_aops;

/* zlib_wrapper.c */
extern const struct squashfs_decompressor squashfs_zlib_comp_ops;
6 changes: 3 additions & 3 deletions fs/squashfs/squashfs_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@
#define SQUASHFS_MAX_FILE_SIZE (1LL << \
(SQUASHFS_MAX_FILE_SIZE_LOG - 2))

#define SQUASHFS_MARKER_BYTE 0xff

/* meta index cache */
#define SQUASHFS_META_INDEXES (SQUASHFS_METADATA_SIZE / sizeof(unsigned int))
#define SQUASHFS_META_ENTRIES 127
Expand All @@ -211,7 +209,9 @@ struct meta_index {
/*
* definitions for structures on disk
*/
#define ZLIB_COMPRESSION 1
#define ZLIB_COMPRESSION 1
#define LZMA_COMPRESSION 2
#define LZO_COMPRESSION 3

struct squashfs_super_block {
__le32 s_magic;
Expand Down
40 changes: 20 additions & 20 deletions fs/squashfs/squashfs_fs_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,25 @@ struct squashfs_cache_entry {
};

struct squashfs_sb_info {
int devblksize;
int devblksize_log2;
struct squashfs_cache *block_cache;
struct squashfs_cache *fragment_cache;
struct squashfs_cache *read_page;
int next_meta_index;
__le64 *id_table;
__le64 *fragment_index;
unsigned int *fragment_index_2;
struct mutex read_data_mutex;
struct mutex meta_index_mutex;
struct meta_index *meta_index;
z_stream stream;
__le64 *inode_lookup_table;
u64 inode_table;
u64 directory_table;
unsigned int block_size;
unsigned short block_log;
long long bytes_used;
unsigned int inodes;
const struct squashfs_decompressor *decompressor;
int devblksize;
int devblksize_log2;
struct squashfs_cache *block_cache;
struct squashfs_cache *fragment_cache;
struct squashfs_cache *read_page;
int next_meta_index;
__le64 *id_table;
__le64 *fragment_index;
struct mutex read_data_mutex;
struct mutex meta_index_mutex;
struct meta_index *meta_index;
void *stream;
__le64 *inode_lookup_table;
u64 inode_table;
u64 directory_table;
unsigned int block_size;
unsigned short block_log;
long long bytes_used;
unsigned int inodes;
};
#endif
Loading

0 comments on commit b24bc1e

Please sign in to comment.