aboutsummaryrefslogtreecommitdiffstats
path: root/fs/squashfs/zlib_wrapper.c
diff options
context:
space:
mode:
authorPhillip Lougher <phillip@squashfs.org.uk>2013-11-17 21:59:12 -0500
committerPhillip Lougher <phillip@squashfs.org.uk>2013-11-19 22:59:01 -0500
commit846b730e99518a1c9945afcb2afbe4d08a02ed80 (patch)
treec70eb16cbec15e5bfa1db80c5f18e062673331a9 /fs/squashfs/zlib_wrapper.c
parentd208383d640727b70cd6689bc17e67e9b5ebf4ff (diff)
Squashfs: Generalise paging handling in the decompressors
Further generalise the decompressors by adding a page handler abstraction. This adds helpers to allow the decompressors to access and process the output buffers in an implementation independant manner. This allows different types of output buffer to be passed to the decompressors, with the implementation specific aspects handled at decompression time, but without the knowledge being held in the decompressor wrapper code. This will allow the decompressors to handle Squashfs cache buffers, and page cache pages. This patch adds the abstraction and an implementation for the caches. Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk> Reviewed-by: Minchan Kim <minchan@kernel.org>
Diffstat (limited to 'fs/squashfs/zlib_wrapper.c')
-rw-r--r--fs/squashfs/zlib_wrapper.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/fs/squashfs/zlib_wrapper.c b/fs/squashfs/zlib_wrapper.c
index bb049027d15c..8727caba6882 100644
--- a/fs/squashfs/zlib_wrapper.c
+++ b/fs/squashfs/zlib_wrapper.c
@@ -32,6 +32,7 @@
32#include "squashfs_fs_sb.h" 32#include "squashfs_fs_sb.h"
33#include "squashfs.h" 33#include "squashfs.h"
34#include "decompressor.h" 34#include "decompressor.h"
35#include "page_actor.h"
35 36
36static void *zlib_init(struct squashfs_sb_info *dummy, void *buff) 37static void *zlib_init(struct squashfs_sb_info *dummy, void *buff)
37{ 38{
@@ -62,14 +63,14 @@ static void zlib_free(void *strm)
62 63
63 64
64static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm, 65static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm,
65 void **buffer, struct buffer_head **bh, int b, int offset, int length, 66 struct buffer_head **bh, int b, int offset, int length,
66 int srclength, int pages) 67 struct squashfs_page_actor *output)
67{ 68{
68 int zlib_err, zlib_init = 0; 69 int zlib_err, zlib_init = 0, k = 0;
69 int k = 0, page = 0;
70 z_stream *stream = strm; 70 z_stream *stream = strm;
71 71
72 stream->avail_out = 0; 72 stream->avail_out = PAGE_CACHE_SIZE;
73 stream->next_out = squashfs_first_page(output);
73 stream->avail_in = 0; 74 stream->avail_in = 0;
74 75
75 do { 76 do {
@@ -81,15 +82,18 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm,
81 offset = 0; 82 offset = 0;
82 } 83 }
83 84
84 if (stream->avail_out == 0 && page < pages) { 85 if (stream->avail_out == 0) {
85 stream->next_out = buffer[page++]; 86 stream->next_out = squashfs_next_page(output);
86 stream->avail_out = PAGE_CACHE_SIZE; 87 if (stream->next_out != NULL)
88 stream->avail_out = PAGE_CACHE_SIZE;
87 } 89 }
88 90
89 if (!zlib_init) { 91 if (!zlib_init) {
90 zlib_err = zlib_inflateInit(stream); 92 zlib_err = zlib_inflateInit(stream);
91 if (zlib_err != Z_OK) 93 if (zlib_err != Z_OK) {
94 squashfs_finish_page(output);
92 goto out; 95 goto out;
96 }
93 zlib_init = 1; 97 zlib_init = 1;
94 } 98 }
95 99
@@ -99,6 +103,8 @@ static int zlib_uncompress(struct squashfs_sb_info *msblk, void *strm,
99 put_bh(bh[k++]); 103 put_bh(bh[k++]);
100 } while (zlib_err == Z_OK); 104 } while (zlib_err == Z_OK);
101 105
106 squashfs_finish_page(output);
107
102 if (zlib_err != Z_STREAM_END) 108 if (zlib_err != Z_STREAM_END)
103 goto out; 109 goto out;
104 110