1 --- a/fs/squashfs/Kconfig
2 +++ b/fs/squashfs/Kconfig
5 tristate "SquashFS 4.0 - Squashed file system support"
11 Saying Y here includes support for SquashFS 4.0 (a Compressed
12 Read-Only File System). Squashfs is a highly compressed read-only
13 --- a/fs/squashfs/block.c
14 +++ b/fs/squashfs/block.c
16 #include <linux/mutex.h>
17 #include <linux/string.h>
18 #include <linux/buffer_head.h>
19 -#include <linux/zlib.h>
21 +#include <crypto/compress.h>
23 #include "squashfs_fs.h"
24 #include "squashfs_fs_sb.h"
25 @@ -153,7 +154,8 @@ int squashfs_read_data(struct super_bloc
29 - int zlib_err = 0, zlib_init = 0;
30 + int res = 0, decomp_init = 0;
31 + struct comp_request req;
35 @@ -161,12 +163,13 @@ int squashfs_read_data(struct super_bloc
37 mutex_lock(&msblk->read_data_mutex);
39 - msblk->stream.avail_out = 0;
40 - msblk->stream.avail_in = 0;
47 - if (msblk->stream.avail_in == 0 && k < b) {
48 + if (req.avail_in == 0 && k < b) {
49 avail = min(bytes, msblk->devblksize - offset);
51 wait_on_buffer(bh[k]);
52 @@ -179,45 +182,47 @@ int squashfs_read_data(struct super_bloc
56 - msblk->stream.next_in = bh[k]->b_data + offset;
57 - msblk->stream.avail_in = avail;
58 + req.next_in = bh[k]->b_data + offset;
59 + req.avail_in = avail;
63 - if (msblk->stream.avail_out == 0 && page < pages) {
64 - msblk->stream.next_out = buffer[page++];
65 - msblk->stream.avail_out = PAGE_CACHE_SIZE;
66 + if (req.avail_out == 0 && page < pages) {
67 + req.next_out = buffer[page++];
68 + req.avail_out = PAGE_CACHE_SIZE;
72 - zlib_err = zlib_inflateInit(&msblk->stream);
73 - if (zlib_err != Z_OK) {
74 - ERROR("zlib_inflateInit returned"
75 - " unexpected result 0x%x,"
76 - " srclength %d\n", zlib_err,
79 + res = crypto_decompress_init(msblk->tfm);
81 + ERROR("crypto_decompress_init "
82 + "returned %d, srclength %d\n",
90 - zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
91 + res = crypto_decompress_update(msblk->tfm, &req);
93 + ERROR("crypto_decompress_update returned %d, "
94 + "data probably corrupt\n", res);
99 - if (msblk->stream.avail_in == 0 && k < b)
100 + if (req.avail_in == 0 && k < b)
102 - } while (zlib_err == Z_OK);
103 + } while (bytes || res);
105 - if (zlib_err != Z_STREAM_END) {
106 - ERROR("zlib_inflate error, data probably corrupt\n");
107 + res = crypto_decompress_final(msblk->tfm, &req);
109 + ERROR("crypto_decompress_final returned %d, data "
110 + "probably corrupt\n", res);
115 - zlib_err = zlib_inflateEnd(&msblk->stream);
116 - if (zlib_err != Z_OK) {
117 - ERROR("zlib_inflate error, data probably corrupt\n");
118 - goto release_mutex;
120 - length = msblk->stream.total_out;
121 mutex_unlock(&msblk->read_data_mutex);
124 --- a/fs/squashfs/squashfs_fs_sb.h
125 +++ b/fs/squashfs/squashfs_fs_sb.h
126 @@ -64,7 +64,7 @@ struct squashfs_sb_info {
127 struct mutex read_data_mutex;
128 struct mutex meta_index_mutex;
129 struct meta_index *meta_index;
131 + struct crypto_pcomp *tfm;
132 __le64 *inode_lookup_table;
135 --- a/fs/squashfs/super.c
136 +++ b/fs/squashfs/super.c
138 #include <linux/zlib.h>
139 #include <linux/magic.h>
141 +#include <crypto/compress.h>
143 +#include <net/netlink.h>
145 #include "squashfs_fs.h"
146 #include "squashfs_fs_sb.h"
147 #include "squashfs_fs_i.h"
148 #include "squashfs.h"
151 +#define SQUASHFS_CRYPTO_ALG "zlib"
154 static struct file_system_type squashfs_fs_type;
155 static struct super_operations squashfs_super_ops;
157 @@ -75,6 +83,16 @@ static int squashfs_fill_super(struct su
158 unsigned short flags;
159 unsigned int fragments;
160 u64 lookup_table_start;
166 + .nla_len = nla_attr_size(sizeof(int)),
167 + .nla_type = ZLIB_DECOMP_WINDOWBITS,
173 TRACE("Entered squashfs_fill_superblock\n");
174 @@ -86,16 +104,25 @@ static int squashfs_fill_super(struct su
176 msblk = sb->s_fs_info;
178 - msblk->stream.workspace = kmalloc(zlib_inflate_workspacesize(),
180 - if (msblk->stream.workspace == NULL) {
181 - ERROR("Failed to allocate zlib workspace\n");
182 + msblk->tfm = crypto_alloc_pcomp(SQUASHFS_CRYPTO_ALG, 0,
184 + if (IS_ERR(msblk->tfm)) {
185 + ERROR("Failed to load %s crypto module\n",
186 + SQUASHFS_CRYPTO_ALG);
187 + err = PTR_ERR(msblk->tfm);
191 + err = crypto_decompress_setup(msblk->tfm, ¶ms, sizeof(params));
193 + ERROR("Failed to set up decompression parameters\n");
197 sblk = kzalloc(sizeof(*sblk), GFP_KERNEL);
199 ERROR("Failed to allocate squashfs_super_block\n");
204 @@ -294,17 +321,18 @@ failed_mount:
205 kfree(msblk->inode_lookup_table);
206 kfree(msblk->fragment_index);
207 kfree(msblk->id_table);
208 - kfree(msblk->stream.workspace);
209 + crypto_free_pcomp(msblk->tfm);
210 kfree(sb->s_fs_info);
211 sb->s_fs_info = NULL;
216 - kfree(msblk->stream.workspace);
217 + crypto_free_pcomp(msblk->tfm);
219 kfree(sb->s_fs_info);
220 sb->s_fs_info = NULL;
226 @@ -346,7 +374,7 @@ static void squashfs_put_super(struct su
227 kfree(sbi->id_table);
228 kfree(sbi->fragment_index);
229 kfree(sbi->meta_index);
230 - kfree(sbi->stream.workspace);
231 + crypto_free_pcomp(sbi->tfm);
232 kfree(sb->s_fs_info);
233 sb->s_fs_info = NULL;