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 /fs/squashfs/zlib_wrapper.c | |
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>
Diffstat (limited to 'fs/squashfs/zlib_wrapper.c')
-rw-r--r-- | fs/squashfs/zlib_wrapper.c | 56 |
1 files changed, 43 insertions, 13 deletions
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); |