aboutsummaryrefslogtreecommitdiff
path: root/kernel-2.4/fs/squashfs
diff options
context:
space:
mode:
authorplougher <plougher>2006-08-01 23:49:43 +0000
committerMohamad Ayyash <mkayyash@google.com>2015-02-23 12:33:44 -0800
commit410dd958c15c73d91e877a0afe085bfaee37d9ff (patch)
treedca82549432b51d50fafae3396afad500eceb10a /kernel-2.4/fs/squashfs
parenta65704daf732cf4bb0ddb8061d2de36e0c1014d2 (diff)
downloadsquashfs-tools-410dd958c15c73d91e877a0afe085bfaee37d9ff.tar.gz
Fix for rare race condition that (mainly) occurs on SMP systems
Diffstat (limited to 'kernel-2.4/fs/squashfs')
-rwxr-xr-xkernel-2.4/fs/squashfs/inode.c39
-rwxr-xr-xkernel-2.4/fs/squashfs/squashfs2_0.c1
2 files changed, 23 insertions, 17 deletions
diff --git a/kernel-2.4/fs/squashfs/inode.c b/kernel-2.4/fs/squashfs/inode.c
index 22f3743..3466356 100755
--- a/kernel-2.4/fs/squashfs/inode.c
+++ b/kernel-2.4/fs/squashfs/inode.c
@@ -26,13 +26,13 @@
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/slab.h>
+#include <linux/zlib.h>
#include <linux/fs.h>
#include <linux/smp_lock.h>
#include <linux/locks.h>
#include <linux/init.h>
#include <linux/dcache.h>
#include <linux/wait.h>
-#include <linux/zlib.h>
#include <linux/blkdev.h>
#include <linux/vmalloc.h>
#include <asm/uaccess.h>
@@ -53,7 +53,7 @@ static long long read_blocklist(struct inode *inode, int index,
int readahead_blks, char *block_list,
unsigned short **block_p, unsigned int *bsize);
-static z_stream stream;
+/*static z_stream stream;*/
static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
@@ -229,20 +229,20 @@ SQSH_EXTERN unsigned int squashfs_read_data(struct super_block *s, char *buffer,
if (compressed) {
int zlib_err;
- stream.next_in = c_buffer;
- stream.avail_in = c_byte;
- stream.next_out = buffer;
- stream.avail_out = msblk->read_size;
+ msblk->stream.next_in = c_buffer;
+ msblk->stream.avail_in = c_byte;
+ msblk->stream.next_out = buffer;
+ msblk->stream.avail_out = msblk->read_size;
- if (((zlib_err = zlib_inflateInit(&stream)) != Z_OK) ||
- ((zlib_err = zlib_inflate(&stream, Z_FINISH))
+ if (((zlib_err = zlib_inflateInit(&msblk->stream)) != Z_OK) ||
+ ((zlib_err = zlib_inflate(&msblk->stream, Z_FINISH))
!= Z_STREAM_END) || ((zlib_err =
- zlib_inflateEnd(&stream)) != Z_OK)) {
+ zlib_inflateEnd(&msblk->stream)) != Z_OK)) {
ERROR("zlib_fs returned unexpected result 0x%x\n",
zlib_err);
bytes = 0;
} else
- bytes = stream.total_out;
+ bytes = msblk->stream.total_out;
up(&msblk->read_data_mutex);
}
@@ -936,7 +936,12 @@ static struct super_block *squashfs_read_super(struct super_block *s,
struct squashfs_super_block *sblk = &msblk->sblk;
int i;
struct inode *root;
-
+
+ if (!(msblk->stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
+ ERROR("Failed to allocate zlib workspace\n");
+ goto failed_mount;
+ }
+
msblk->devblksize = get_hardsect_size(dev);
if(msblk->devblksize < BLOCK_SIZE)
msblk->devblksize = BLOCK_SIZE;
@@ -1111,6 +1116,7 @@ failed_mount:
kfree(msblk->read_data);
kfree(msblk->block_cache);
kfree(msblk->fragment_index_2);
+ vfree(msblk->stream.workspace);
return NULL;
}
@@ -1988,6 +1994,8 @@ static void squashfs_put_super(struct super_block *s)
kfree(sbi->uid);
kfree(sbi->fragment_index);
kfree(sbi->fragment_index_2);
+ kfree(sbi->meta_index);
+ vfree(sbi->stream.workspace);
sbi->block_cache = NULL;
sbi->uid = NULL;
sbi->read_data = NULL;
@@ -1995,26 +2003,23 @@ static void squashfs_put_super(struct super_block *s)
sbi->fragment = NULL;
sbi->fragment_index = NULL;
sbi->fragment_index_2 = NULL;
+ sbi->meta_index = NULL;
+ sbi->stream.workspace = NULL;
}
static int __init init_squashfs_fs(void)
{
- printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
+ printk(KERN_INFO "squashfs: version 3.1-test (2006/07/31) "
"Phillip Lougher\n");
- if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
- ERROR("Failed to allocate zlib workspace\n");
- return -ENOMEM;
- }
return register_filesystem(&squashfs_fs_type);
}
static void __exit exit_squashfs_fs(void)
{
- vfree(stream.workspace);
unregister_filesystem(&squashfs_fs_type);
}
diff --git a/kernel-2.4/fs/squashfs/squashfs2_0.c b/kernel-2.4/fs/squashfs/squashfs2_0.c
index d4efd8a..4eabfa5 100755
--- a/kernel-2.4/fs/squashfs/squashfs2_0.c
+++ b/kernel-2.4/fs/squashfs/squashfs2_0.c
@@ -26,6 +26,7 @@
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/slab.h>
+#include <linux/zlib.h>
#include <linux/fs.h>
#include <linux/smp_lock.h>
#include <linux/locks.h>