diff options
author | Phillip Lougher <phillip@lougher.demon.co.uk> | 2009-09-23 14:04:49 -0400 |
---|---|---|
committer | Phillip Lougher <phillip@lougher.demon.co.uk> | 2010-01-20 16:47:47 -0500 |
commit | f1a40359f8d8ba073257ed31a513e492621bcbc5 (patch) | |
tree | 313f81085e0e3e3606cecf4cc6ed4ead59cea3ee | |
parent | e6a6d3795565b8ccb957afc6ca0e50db40b2d899 (diff) |
Squashfs: factor out remaining zlib dependencies into separate wrapper file
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>
-rw-r--r-- | fs/squashfs/block.c | 1 | ||||
-rw-r--r-- | fs/squashfs/cache.c | 1 | ||||
-rw-r--r-- | fs/squashfs/dir.c | 1 | ||||
-rw-r--r-- | fs/squashfs/export.c | 1 | ||||
-rw-r--r-- | fs/squashfs/file.c | 1 | ||||
-rw-r--r-- | fs/squashfs/fragment.c | 1 | ||||
-rw-r--r-- | fs/squashfs/id.c | 1 | ||||
-rw-r--r-- | fs/squashfs/inode.c | 1 | ||||
-rw-r--r-- | fs/squashfs/namei.c | 1 | ||||
-rw-r--r-- | fs/squashfs/squashfs.h | 2 | ||||
-rw-r--r-- | fs/squashfs/squashfs_fs_sb.h | 2 | ||||
-rw-r--r-- | fs/squashfs/super.c | 14 | ||||
-rw-r--r-- | fs/squashfs/symlink.c | 1 | ||||
-rw-r--r-- | fs/squashfs/zlib_wrapper.c | 56 |
14 files changed, 51 insertions, 33 deletions
diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c index b8addfdc6094..3f836e181eb8 100644 --- a/fs/squashfs/block.c +++ b/fs/squashfs/block.c | |||
@@ -31,7 +31,6 @@ | |||
31 | #include <linux/slab.h> | 31 | #include <linux/slab.h> |
32 | #include <linux/string.h> | 32 | #include <linux/string.h> |
33 | #include <linux/buffer_head.h> | 33 | #include <linux/buffer_head.h> |
34 | #include <linux/zlib.h> | ||
35 | 34 | ||
36 | #include "squashfs_fs.h" | 35 | #include "squashfs_fs.h" |
37 | #include "squashfs_fs_sb.h" | 36 | #include "squashfs_fs_sb.h" |
diff --git a/fs/squashfs/cache.c b/fs/squashfs/cache.c index 40c98fa6b5d6..57314bee9059 100644 --- a/fs/squashfs/cache.c +++ b/fs/squashfs/cache.c | |||
@@ -51,7 +51,6 @@ | |||
51 | #include <linux/sched.h> | 51 | #include <linux/sched.h> |
52 | #include <linux/spinlock.h> | 52 | #include <linux/spinlock.h> |
53 | #include <linux/wait.h> | 53 | #include <linux/wait.h> |
54 | #include <linux/zlib.h> | ||
55 | #include <linux/pagemap.h> | 54 | #include <linux/pagemap.h> |
56 | 55 | ||
57 | #include "squashfs_fs.h" | 56 | #include "squashfs_fs.h" |
diff --git a/fs/squashfs/dir.c b/fs/squashfs/dir.c index 566b0eaed868..12b933ac6585 100644 --- a/fs/squashfs/dir.c +++ b/fs/squashfs/dir.c | |||
@@ -30,7 +30,6 @@ | |||
30 | #include <linux/fs.h> | 30 | #include <linux/fs.h> |
31 | #include <linux/vfs.h> | 31 | #include <linux/vfs.h> |
32 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
33 | #include <linux/zlib.h> | ||
34 | 33 | ||
35 | #include "squashfs_fs.h" | 34 | #include "squashfs_fs.h" |
36 | #include "squashfs_fs_sb.h" | 35 | #include "squashfs_fs_sb.h" |
diff --git a/fs/squashfs/export.c b/fs/squashfs/export.c index 2b1b8fe5e037..7f93d5a9ee05 100644 --- a/fs/squashfs/export.c +++ b/fs/squashfs/export.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include <linux/vfs.h> | 39 | #include <linux/vfs.h> |
40 | #include <linux/dcache.h> | 40 | #include <linux/dcache.h> |
41 | #include <linux/exportfs.h> | 41 | #include <linux/exportfs.h> |
42 | #include <linux/zlib.h> | ||
43 | #include <linux/slab.h> | 42 | #include <linux/slab.h> |
44 | 43 | ||
45 | #include "squashfs_fs.h" | 44 | #include "squashfs_fs.h" |
diff --git a/fs/squashfs/file.c b/fs/squashfs/file.c index 717767d831df..a25c5060bdcb 100644 --- a/fs/squashfs/file.c +++ b/fs/squashfs/file.c | |||
@@ -47,7 +47,6 @@ | |||
47 | #include <linux/string.h> | 47 | #include <linux/string.h> |
48 | #include <linux/pagemap.h> | 48 | #include <linux/pagemap.h> |
49 | #include <linux/mutex.h> | 49 | #include <linux/mutex.h> |
50 | #include <linux/zlib.h> | ||
51 | 50 | ||
52 | #include "squashfs_fs.h" | 51 | #include "squashfs_fs.h" |
53 | #include "squashfs_fs_sb.h" | 52 | #include "squashfs_fs_sb.h" |
diff --git a/fs/squashfs/fragment.c b/fs/squashfs/fragment.c index b5a2c15bbbc7..7c90bbd6879d 100644 --- a/fs/squashfs/fragment.c +++ b/fs/squashfs/fragment.c | |||
@@ -36,7 +36,6 @@ | |||
36 | #include <linux/fs.h> | 36 | #include <linux/fs.h> |
37 | #include <linux/vfs.h> | 37 | #include <linux/vfs.h> |
38 | #include <linux/slab.h> | 38 | #include <linux/slab.h> |
39 | #include <linux/zlib.h> | ||
40 | 39 | ||
41 | #include "squashfs_fs.h" | 40 | #include "squashfs_fs.h" |
42 | #include "squashfs_fs_sb.h" | 41 | #include "squashfs_fs_sb.h" |
diff --git a/fs/squashfs/id.c b/fs/squashfs/id.c index 3795b837ba28..b7f64bcd2b70 100644 --- a/fs/squashfs/id.c +++ b/fs/squashfs/id.c | |||
@@ -34,7 +34,6 @@ | |||
34 | #include <linux/fs.h> | 34 | #include <linux/fs.h> |
35 | #include <linux/vfs.h> | 35 | #include <linux/vfs.h> |
36 | #include <linux/slab.h> | 36 | #include <linux/slab.h> |
37 | #include <linux/zlib.h> | ||
38 | 37 | ||
39 | #include "squashfs_fs.h" | 38 | #include "squashfs_fs.h" |
40 | #include "squashfs_fs_sb.h" | 39 | #include "squashfs_fs_sb.h" |
diff --git a/fs/squashfs/inode.c b/fs/squashfs/inode.c index 9101dbde39ec..49daaf669e41 100644 --- a/fs/squashfs/inode.c +++ b/fs/squashfs/inode.c | |||
@@ -40,7 +40,6 @@ | |||
40 | 40 | ||
41 | #include <linux/fs.h> | 41 | #include <linux/fs.h> |
42 | #include <linux/vfs.h> | 42 | #include <linux/vfs.h> |
43 | #include <linux/zlib.h> | ||
44 | 43 | ||
45 | #include "squashfs_fs.h" | 44 | #include "squashfs_fs.h" |
46 | #include "squashfs_fs_sb.h" | 45 | #include "squashfs_fs_sb.h" |
diff --git a/fs/squashfs/namei.c b/fs/squashfs/namei.c index 9e398653b22b..5266bd8ad932 100644 --- a/fs/squashfs/namei.c +++ b/fs/squashfs/namei.c | |||
@@ -57,7 +57,6 @@ | |||
57 | #include <linux/slab.h> | 57 | #include <linux/slab.h> |
58 | #include <linux/string.h> | 58 | #include <linux/string.h> |
59 | #include <linux/dcache.h> | 59 | #include <linux/dcache.h> |
60 | #include <linux/zlib.h> | ||
61 | 60 | ||
62 | #include "squashfs_fs.h" | 61 | #include "squashfs_fs.h" |
63 | #include "squashfs_fs_sb.h" | 62 | #include "squashfs_fs_sb.h" |
diff --git a/fs/squashfs/squashfs.h b/fs/squashfs/squashfs.h index ba87db693651..9c2f76a1c50b 100644 --- a/fs/squashfs/squashfs.h +++ b/fs/squashfs/squashfs.h | |||
@@ -71,6 +71,8 @@ extern struct inode *squashfs_iget(struct super_block *, long long, | |||
71 | extern int squashfs_read_inode(struct inode *, long long); | 71 | extern int squashfs_read_inode(struct inode *, long long); |
72 | 72 | ||
73 | /* zlib_wrapper.c */ | 73 | /* zlib_wrapper.c */ |
74 | extern void *squashfs_zlib_init(void); | ||
75 | extern void squashfs_zlib_free(void *); | ||
74 | extern int squashfs_zlib_uncompress(struct squashfs_sb_info *, void **, | 76 | extern int squashfs_zlib_uncompress(struct squashfs_sb_info *, void **, |
75 | struct buffer_head **, int, int, int, int, int); | 77 | struct buffer_head **, int, int, int, int, int); |
76 | 78 | ||
diff --git a/fs/squashfs/squashfs_fs_sb.h b/fs/squashfs/squashfs_fs_sb.h index c8c65614dd1c..23a67fa40b03 100644 --- a/fs/squashfs/squashfs_fs_sb.h +++ b/fs/squashfs/squashfs_fs_sb.h | |||
@@ -64,7 +64,7 @@ struct squashfs_sb_info { | |||
64 | struct mutex read_data_mutex; | 64 | struct mutex read_data_mutex; |
65 | struct mutex meta_index_mutex; | 65 | struct mutex meta_index_mutex; |
66 | struct meta_index *meta_index; | 66 | struct meta_index *meta_index; |
67 | z_stream stream; | 67 | void *stream; |
68 | __le64 *inode_lookup_table; | 68 | __le64 *inode_lookup_table; |
69 | u64 inode_table; | 69 | u64 inode_table; |
70 | u64 directory_table; | 70 | u64 directory_table; |
diff --git a/fs/squashfs/super.c b/fs/squashfs/super.c index 6c197ef53add..b9f8c6a92d6a 100644 --- a/fs/squashfs/super.c +++ b/fs/squashfs/super.c | |||
@@ -35,7 +35,6 @@ | |||
35 | #include <linux/pagemap.h> | 35 | #include <linux/pagemap.h> |
36 | #include <linux/init.h> | 36 | #include <linux/init.h> |
37 | #include <linux/module.h> | 37 | #include <linux/module.h> |
38 | #include <linux/zlib.h> | ||
39 | #include <linux/magic.h> | 38 | #include <linux/magic.h> |
40 | 39 | ||
41 | #include "squashfs_fs.h" | 40 | #include "squashfs_fs.h" |
@@ -87,12 +86,9 @@ static int squashfs_fill_super(struct super_block *sb, void *data, int silent) | |||
87 | } | 86 | } |
88 | msblk = sb->s_fs_info; | 87 | msblk = sb->s_fs_info; |
89 | 88 | ||
90 | msblk->stream.workspace = kmalloc(zlib_inflate_workspacesize(), | 89 | msblk->stream = squashfs_zlib_init(); |
91 | GFP_KERNEL); | 90 | if (msblk->stream == NULL) |
92 | if (msblk->stream.workspace == NULL) { | ||
93 | ERROR("Failed to allocate zlib workspace\n"); | ||
94 | goto failure; | 91 | goto failure; |
95 | } | ||
96 | 92 | ||
97 | sblk = kzalloc(sizeof(*sblk), GFP_KERNEL); | 93 | sblk = kzalloc(sizeof(*sblk), GFP_KERNEL); |
98 | if (sblk == NULL) { | 94 | if (sblk == NULL) { |
@@ -292,17 +288,17 @@ failed_mount: | |||
292 | squashfs_cache_delete(msblk->block_cache); | 288 | squashfs_cache_delete(msblk->block_cache); |
293 | squashfs_cache_delete(msblk->fragment_cache); | 289 | squashfs_cache_delete(msblk->fragment_cache); |
294 | squashfs_cache_delete(msblk->read_page); | 290 | squashfs_cache_delete(msblk->read_page); |
291 | squashfs_zlib_free(msblk->stream); | ||
295 | kfree(msblk->inode_lookup_table); | 292 | kfree(msblk->inode_lookup_table); |
296 | kfree(msblk->fragment_index); | 293 | kfree(msblk->fragment_index); |
297 | kfree(msblk->id_table); | 294 | kfree(msblk->id_table); |
298 | kfree(msblk->stream.workspace); | ||
299 | kfree(sb->s_fs_info); | 295 | kfree(sb->s_fs_info); |
300 | sb->s_fs_info = NULL; | 296 | sb->s_fs_info = NULL; |
301 | kfree(sblk); | 297 | kfree(sblk); |
302 | return err; | 298 | return err; |
303 | 299 | ||
304 | failure: | 300 | failure: |
305 | kfree(msblk->stream.workspace); | 301 | squashfs_zlib_free(msblk->stream); |
306 | kfree(sb->s_fs_info); | 302 | kfree(sb->s_fs_info); |
307 | sb->s_fs_info = NULL; | 303 | sb->s_fs_info = NULL; |
308 | return -ENOMEM; | 304 | return -ENOMEM; |
@@ -346,10 +342,10 @@ static void squashfs_put_super(struct super_block *sb) | |||
346 | squashfs_cache_delete(sbi->block_cache); | 342 | squashfs_cache_delete(sbi->block_cache); |
347 | squashfs_cache_delete(sbi->fragment_cache); | 343 | squashfs_cache_delete(sbi->fragment_cache); |
348 | squashfs_cache_delete(sbi->read_page); | 344 | squashfs_cache_delete(sbi->read_page); |
345 | squashfs_zlib_free(sbi->stream); | ||
349 | kfree(sbi->id_table); | 346 | kfree(sbi->id_table); |
350 | kfree(sbi->fragment_index); | 347 | kfree(sbi->fragment_index); |
351 | kfree(sbi->meta_index); | 348 | kfree(sbi->meta_index); |
352 | kfree(sbi->stream.workspace); | ||
353 | kfree(sb->s_fs_info); | 349 | kfree(sb->s_fs_info); |
354 | sb->s_fs_info = NULL; | 350 | sb->s_fs_info = NULL; |
355 | } | 351 | } |
diff --git a/fs/squashfs/symlink.c b/fs/squashfs/symlink.c index 83d87880aac8..e80be2022a7f 100644 --- a/fs/squashfs/symlink.c +++ b/fs/squashfs/symlink.c | |||
@@ -36,7 +36,6 @@ | |||
36 | #include <linux/slab.h> | 36 | #include <linux/slab.h> |
37 | #include <linux/string.h> | 37 | #include <linux/string.h> |
38 | #include <linux/pagemap.h> | 38 | #include <linux/pagemap.h> |
39 | #include <linux/zlib.h> | ||
40 | 39 | ||
41 | #include "squashfs_fs.h" | 40 | #include "squashfs_fs.h" |
42 | #include "squashfs_fs_sb.h" | 41 | #include "squashfs_fs_sb.h" |
diff --git a/fs/squashfs/zlib_wrapper.c b/fs/squashfs/zlib_wrapper.c index 3be99642d6af..c814594d522e 100644 --- a/fs/squashfs/zlib_wrapper.c +++ b/fs/squashfs/zlib_wrapper.c | |||
@@ -31,21 +31,51 @@ | |||
31 | #include "squashfs_fs_i.h" | 31 | #include "squashfs_fs_i.h" |
32 | #include "squashfs.h" | 32 | #include "squashfs.h" |
33 | 33 | ||
34 | void *squashfs_zlib_init() | ||
35 | { | ||
36 | z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL); | ||
37 | if (stream == NULL) | ||
38 | goto failed; | ||
39 | stream->workspace = kmalloc(zlib_inflate_workspacesize(), | ||
40 | GFP_KERNEL); | ||
41 | if (stream->workspace == NULL) | ||
42 | goto failed; | ||
43 | |||
44 | return stream; | ||
45 | |||
46 | failed: | ||
47 | ERROR("Failed to allocate zlib workspace\n"); | ||
48 | kfree(stream); | ||
49 | return NULL; | ||
50 | } | ||
51 | |||
52 | |||
53 | void squashfs_zlib_free(void *strm) | ||
54 | { | ||
55 | z_stream *stream = strm; | ||
56 | |||
57 | if (stream) | ||
58 | kfree(stream->workspace); | ||
59 | kfree(stream); | ||
60 | } | ||
61 | |||
62 | |||
34 | int squashfs_zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, | 63 | int squashfs_zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, |
35 | struct buffer_head **bh, int b, int offset, int length, int srclength, | 64 | struct buffer_head **bh, int b, int offset, int length, int srclength, |
36 | int pages) | 65 | int pages) |
37 | { | 66 | { |
38 | int zlib_err = 0, zlib_init = 0; | 67 | int zlib_err = 0, zlib_init = 0; |
39 | int avail, bytes, k = 0, page = 0; | 68 | int avail, bytes, k = 0, page = 0; |
69 | z_stream *stream = msblk->stream; | ||
40 | 70 | ||
41 | mutex_lock(&msblk->read_data_mutex); | 71 | mutex_lock(&msblk->read_data_mutex); |
42 | 72 | ||
43 | msblk->stream.avail_out = 0; | 73 | stream->avail_out = 0; |
44 | msblk->stream.avail_in = 0; | 74 | stream->avail_in = 0; |
45 | 75 | ||
46 | bytes = length; | 76 | bytes = length; |
47 | do { | 77 | do { |
48 | if (msblk->stream.avail_in == 0 && k < b) { | 78 | if (stream->avail_in == 0 && k < b) { |
49 | avail = min(bytes, msblk->devblksize - offset); | 79 | avail = min(bytes, msblk->devblksize - offset); |
50 | bytes -= avail; | 80 | bytes -= avail; |
51 | wait_on_buffer(bh[k]); | 81 | wait_on_buffer(bh[k]); |
@@ -58,18 +88,18 @@ int squashfs_zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, | |||
58 | continue; | 88 | continue; |
59 | } | 89 | } |
60 | 90 | ||
61 | msblk->stream.next_in = bh[k]->b_data + offset; | 91 | stream->next_in = bh[k]->b_data + offset; |
62 | msblk->stream.avail_in = avail; | 92 | stream->avail_in = avail; |
63 | offset = 0; | 93 | offset = 0; |
64 | } | 94 | } |
65 | 95 | ||
66 | if (msblk->stream.avail_out == 0 && page < pages) { | 96 | if (stream->avail_out == 0 && page < pages) { |
67 | msblk->stream.next_out = buffer[page++]; | 97 | stream->next_out = buffer[page++]; |
68 | msblk->stream.avail_out = PAGE_CACHE_SIZE; | 98 | stream->avail_out = PAGE_CACHE_SIZE; |
69 | } | 99 | } |
70 | 100 | ||
71 | if (!zlib_init) { | 101 | if (!zlib_init) { |
72 | zlib_err = zlib_inflateInit(&msblk->stream); | 102 | zlib_err = zlib_inflateInit(stream); |
73 | if (zlib_err != Z_OK) { | 103 | if (zlib_err != Z_OK) { |
74 | ERROR("zlib_inflateInit returned unexpected " | 104 | ERROR("zlib_inflateInit returned unexpected " |
75 | "result 0x%x, srclength %d\n", | 105 | "result 0x%x, srclength %d\n", |
@@ -79,9 +109,9 @@ int squashfs_zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, | |||
79 | zlib_init = 1; | 109 | zlib_init = 1; |
80 | } | 110 | } |
81 | 111 | ||
82 | zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH); | 112 | zlib_err = zlib_inflate(stream, Z_SYNC_FLUSH); |
83 | 113 | ||
84 | if (msblk->stream.avail_in == 0 && k < b) | 114 | if (stream->avail_in == 0 && k < b) |
85 | put_bh(bh[k++]); | 115 | put_bh(bh[k++]); |
86 | } while (zlib_err == Z_OK); | 116 | } while (zlib_err == Z_OK); |
87 | 117 | ||
@@ -90,14 +120,14 @@ int squashfs_zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer, | |||
90 | goto release_mutex; | 120 | goto release_mutex; |
91 | } | 121 | } |
92 | 122 | ||
93 | zlib_err = zlib_inflateEnd(&msblk->stream); | 123 | zlib_err = zlib_inflateEnd(stream); |
94 | if (zlib_err != Z_OK) { | 124 | if (zlib_err != Z_OK) { |
95 | ERROR("zlib_inflate error, data probably corrupt\n"); | 125 | ERROR("zlib_inflate error, data probably corrupt\n"); |
96 | goto release_mutex; | 126 | goto release_mutex; |
97 | } | 127 | } |
98 | 128 | ||
99 | mutex_unlock(&msblk->read_data_mutex); | 129 | mutex_unlock(&msblk->read_data_mutex); |
100 | return msblk->stream.total_out; | 130 | return stream->total_out; |
101 | 131 | ||
102 | release_mutex: | 132 | release_mutex: |
103 | mutex_unlock(&msblk->read_data_mutex); | 133 | mutex_unlock(&msblk->read_data_mutex); |