Squashfs: factor out remaining zlib dependencies into separate wrapper file
authorPhillip Lougher <phillip@lougher.demon.co.uk>
Wed, 23 Sep 2009 18:04:49 +0000 (19:04 +0100)
committerPhillip Lougher <phillip@lougher.demon.co.uk>
Wed, 20 Jan 2010 21:47:47 +0000 (21:47 +0000)
Move zlib buffer init/destroy code into separate wrapper file.  Also
make zlib z_stream field a void * removing the need to include zlib.h
for most files.

Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
14 files changed:
fs/squashfs/block.c
fs/squashfs/cache.c
fs/squashfs/dir.c
fs/squashfs/export.c
fs/squashfs/file.c
fs/squashfs/fragment.c
fs/squashfs/id.c
fs/squashfs/inode.c
fs/squashfs/namei.c
fs/squashfs/squashfs.h
fs/squashfs/squashfs_fs_sb.h
fs/squashfs/super.c
fs/squashfs/symlink.c
fs/squashfs/zlib_wrapper.c

index b8addfdc60945f881373ede13394eaa88194dee5..3f836e181eb863b87f893a5306ab4b4719c34d26 100644 (file)
@@ -31,7 +31,6 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/buffer_head.h>
-#include <linux/zlib.h>
 
 #include "squashfs_fs.h"
 #include "squashfs_fs_sb.h"
index 40c98fa6b5d6a779d94bbb6b937a67a8c053d8c7..57314bee9059709d9230c80dff70210729236c07 100644 (file)
@@ -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"
index 566b0eaed868df557a7e05061cd31b0f160a2b54..12b933ac6585d7d0291608cf3253754223a07fd4 100644 (file)
@@ -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"
index 2b1b8fe5e03765cdb91cc6311176d31a8ea3d054..7f93d5a9ee056648a865ae2e2dbf45a3783ce9bb 100644 (file)
@@ -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"
index 717767d831dfb455c9ff2f4d3695c49b1b857c19..a25c5060bdcb5437726497e8bf43d621f09af599 100644 (file)
@@ -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"
index b5a2c15bbbc78b75f8bd2871bb9bdc0c95cdcb87..7c90bbd6879d533a9dc021c8add961ed252d2e84 100644 (file)
@@ -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"
index 3795b837ba284d15055388f692d7077fe9597b2b..b7f64bcd2b707df4e5385c15efe8f553cc70fa1d 100644 (file)
@@ -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"
index 9101dbde39ece6a9ca5d8b47d3344c1f3bdc6879..49daaf669e41809d33b377c40c2f39e0f2e462c7 100644 (file)
@@ -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"
index 9e398653b22b79a6d7ab26724ab0ab291a98fa91..5266bd8ad932edb3a288217d8992693d649b7112 100644 (file)
@@ -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"
index ba87db6936515010b364d81425a9163d78a8a2e4..9c2f76a1c50bb721c1cc2c836d78d302ad1c589f 100644 (file)
@@ -71,6 +71,8 @@ extern struct inode *squashfs_iget(struct super_block *, long long,
 extern int squashfs_read_inode(struct inode *, long long);
 
 /* zlib_wrapper.c */
+extern void *squashfs_zlib_init(void);
+extern void squashfs_zlib_free(void *);
 extern int squashfs_zlib_uncompress(struct squashfs_sb_info *, void **,
                                struct buffer_head **, int, int, int, int, int);
 
index c8c65614dd1c2d4c6eefe4d36a6ab2b4985874ab..23a67fa40b03b3b254c7de272c3fd077af163ac6 100644 (file)
@@ -64,7 +64,7 @@ struct squashfs_sb_info {
        struct mutex            read_data_mutex;
        struct mutex            meta_index_mutex;
        struct meta_index       *meta_index;
-       z_stream                stream;
+       void                    *stream;
        __le64                  *inode_lookup_table;
        u64                     inode_table;
        u64                     directory_table;
index 6c197ef53adda0e8300e416d1a13008fbfe4004a..b9f8c6a92d6abcf524fb4b55c8c28d8bc4591f71 100644 (file)
@@ -35,7 +35,6 @@
 #include <linux/pagemap.h>
 #include <linux/init.h>
 #include <linux/module.h>
-#include <linux/zlib.h>
 #include <linux/magic.h>
 
 #include "squashfs_fs.h"
@@ -87,12 +86,9 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent)
        }
        msblk = sb->s_fs_info;
 
-       msblk->stream.workspace = kmalloc(zlib_inflate_workspacesize(),
-               GFP_KERNEL);
-       if (msblk->stream.workspace == NULL) {
-               ERROR("Failed to allocate zlib workspace\n");
+       msblk->stream = squashfs_zlib_init();
+       if (msblk->stream == NULL)
                goto failure;
-       }
 
        sblk = kzalloc(sizeof(*sblk), GFP_KERNEL);
        if (sblk == NULL) {
@@ -292,17 +288,17 @@ failed_mount:
        squashfs_cache_delete(msblk->block_cache);
        squashfs_cache_delete(msblk->fragment_cache);
        squashfs_cache_delete(msblk->read_page);
+       squashfs_zlib_free(msblk->stream);
        kfree(msblk->inode_lookup_table);
        kfree(msblk->fragment_index);
        kfree(msblk->id_table);
-       kfree(msblk->stream.workspace);
        kfree(sb->s_fs_info);
        sb->s_fs_info = NULL;
        kfree(sblk);
        return err;
 
 failure:
-       kfree(msblk->stream.workspace);
+       squashfs_zlib_free(msblk->stream);
        kfree(sb->s_fs_info);
        sb->s_fs_info = NULL;
        return -ENOMEM;
@@ -346,10 +342,10 @@ static void squashfs_put_super(struct super_block *sb)
                squashfs_cache_delete(sbi->block_cache);
                squashfs_cache_delete(sbi->fragment_cache);
                squashfs_cache_delete(sbi->read_page);
+               squashfs_zlib_free(sbi->stream);
                kfree(sbi->id_table);
                kfree(sbi->fragment_index);
                kfree(sbi->meta_index);
-               kfree(sbi->stream.workspace);
                kfree(sb->s_fs_info);
                sb->s_fs_info = NULL;
        }
index 83d87880aac837640cbc44cf64252c063cdcad47..e80be2022a7fceebfbd37383c65f3b032b45ed00 100644 (file)
@@ -36,7 +36,6 @@
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/pagemap.h>
-#include <linux/zlib.h>
 
 #include "squashfs_fs.h"
 #include "squashfs_fs_sb.h"
index 3be99642d6afd7281e1485e42b72dc59ff376e81..c814594d522eebb180a9c38500cb818899df709c 100644 (file)
 #include "squashfs_fs_i.h"
 #include "squashfs.h"
 
+void *squashfs_zlib_init()
+{
+       z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL);
+       if (stream == NULL)
+               goto failed;
+       stream->workspace = kmalloc(zlib_inflate_workspacesize(),
+               GFP_KERNEL);
+       if (stream->workspace == NULL)
+               goto failed;
+
+       return stream;
+
+failed:
+       ERROR("Failed to allocate zlib workspace\n");
+       kfree(stream);
+       return NULL;
+}
+
+
+void squashfs_zlib_free(void *strm)
+{
+       z_stream *stream = strm;
+
+       if (stream)
+               kfree(stream->workspace);
+       kfree(stream);
+}
+
+
 int squashfs_zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,
        struct buffer_head **bh, int b, int offset, int length, int srclength,
        int pages)
 {
        int zlib_err = 0, zlib_init = 0;
        int avail, bytes, k = 0, page = 0;
+       z_stream *stream = msblk->stream;
 
        mutex_lock(&msblk->read_data_mutex);
 
-       msblk->stream.avail_out = 0;
-       msblk->stream.avail_in = 0;
+       stream->avail_out = 0;
+       stream->avail_in = 0;
 
        bytes = length;
        do {
-               if (msblk->stream.avail_in == 0 && k < b) {
+               if (stream->avail_in == 0 && k < b) {
                        avail = min(bytes, msblk->devblksize - offset);
                        bytes -= avail;
                        wait_on_buffer(bh[k]);
@@ -58,18 +88,18 @@ int squashfs_zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,
                                continue;
                        }
 
-                       msblk->stream.next_in = bh[k]->b_data + offset;
-                       msblk->stream.avail_in = avail;
+                       stream->next_in = bh[k]->b_data + offset;
+                       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 (stream->avail_out == 0 && page < pages) {
+                       stream->next_out = buffer[page++];
+                       stream->avail_out = PAGE_CACHE_SIZE;
                }
 
                if (!zlib_init) {
-                       zlib_err = zlib_inflateInit(&msblk->stream);
+                       zlib_err = zlib_inflateInit(stream);
                        if (zlib_err != Z_OK) {
                                ERROR("zlib_inflateInit returned unexpected "
                                        "result 0x%x, srclength %d\n",
@@ -79,9 +109,9 @@ int squashfs_zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,
                        zlib_init = 1;
                }
 
-               zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
+               zlib_err = zlib_inflate(stream, Z_SYNC_FLUSH);
 
-               if (msblk->stream.avail_in == 0 && k < b)
+               if (stream->avail_in == 0 && k < b)
                        put_bh(bh[k++]);
        } while (zlib_err == Z_OK);
 
@@ -90,14 +120,14 @@ int squashfs_zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,
                goto release_mutex;
        }
 
-       zlib_err = zlib_inflateEnd(&msblk->stream);
+       zlib_err = zlib_inflateEnd(stream);
        if (zlib_err != Z_OK) {
                ERROR("zlib_inflate error, data probably corrupt\n");
                goto release_mutex;
        }
 
        mutex_unlock(&msblk->read_data_mutex);
-       return msblk->stream.total_out;
+       return stream->total_out;
 
 release_mutex:
        mutex_unlock(&msblk->read_data_mutex);