1 --- a/fs/squashfs/Kconfig
2 +++ b/fs/squashfs/Kconfig
3 @@ -2,7 +2,6 @@ config SQUASHFS
4 tristate "SquashFS 4.0 - Squashed file system support"
9 Saying Y here includes support for SquashFS 4.0 (a Compressed
10 Read-Only File System). Squashfs is a highly compressed read-only
11 @@ -37,6 +36,26 @@ config SQUASHFS_EMBEDDED
15 +config SQUASHFS_SUPPORT_ZLIB
17 + prompt "Support ZLIB compression" if SQUASHFS_SUPPORT_LZMA
22 + ZLIB is the default compression used in squashfs. If you are
23 + using LZMA compression instead, you can remove support for ZLIB
26 +config SQUASHFS_SUPPORT_LZMA
27 + bool "Support LZMA compression"
29 + select CRYPTO_UNLZMA
31 + By default SquashFS uses ZLIB compression, however (if your tools
32 + support it, you can use LZMA instead, which saves space.
35 config SQUASHFS_FRAGMENT_CACHE_SIZE
36 int "Number of fragments cached" if SQUASHFS_EMBEDDED
38 --- a/fs/squashfs/squashfs_fs.h
39 +++ b/fs/squashfs/squashfs_fs.h
40 @@ -212,6 +212,7 @@ struct meta_index {
41 * definitions for structures on disk
43 #define ZLIB_COMPRESSION 1
44 +#define LZMA_COMPRESSION 2
46 struct squashfs_super_block {
48 --- a/fs/squashfs/super.c
49 +++ b/fs/squashfs/super.c
54 -#define SQUASHFS_CRYPTO_ALG "zlib"
55 +static int squashfs_setup_zlib(struct squashfs_sb_info *msblk)
57 + int err = -EOPNOTSUPP;
59 +#ifdef CONFIG_SQUASHFS_SUPPORT_ZLIB
65 + .nla_len = nla_attr_size(sizeof(int)),
66 + .nla_type = ZLIB_DECOMP_WINDOWBITS,
71 + msblk->tfm = crypto_alloc_pcomp("zlib", 0,
73 + if (IS_ERR(msblk->tfm)) {
74 + ERROR("Failed to load zlib crypto module\n");
75 + return PTR_ERR(msblk->tfm);
78 + err = crypto_decompress_setup(msblk->tfm, ¶ms, sizeof(params));
80 + ERROR("Failed to set up decompression parameters\n");
81 + crypto_free_pcomp(msblk->tfm);
88 +static int squashfs_setup_lzma(struct squashfs_sb_info *msblk)
90 + int err = -EOPNOTSUPP;
92 +#ifdef CONFIG_SQUASHFS_SUPPORT_LZMA
98 + .nla_len = nla_attr_size(sizeof(int)),
99 + .nla_type = UNLZMA_DECOMP_OUT_BUFFERS,
101 + .val = (msblk->block_size / PAGE_CACHE_SIZE) + 1
104 + msblk->tfm = crypto_alloc_pcomp("lzma", 0,
106 + if (IS_ERR(msblk->tfm)) {
107 + ERROR("Failed to load lzma crypto module\n");
108 + return PTR_ERR(msblk->tfm);
111 + err = crypto_decompress_setup(msblk->tfm, ¶ms, sizeof(params));
113 + ERROR("Failed to set up decompression parameters\n");
114 + crypto_free_pcomp(msblk->tfm);
121 static struct file_system_type squashfs_fs_type;
122 static struct super_operations squashfs_super_ops;
124 -static int supported_squashfs_filesystem(short major, short minor, short comp)
125 +static int supported_squashfs_filesystem(short major, short minor)
127 if (major < SQUASHFS_MAJOR) {
128 ERROR("Major/Minor mismatch, older Squashfs %d.%d "
129 @@ -66,9 +129,6 @@ static int supported_squashfs_filesystem
133 - if (comp != ZLIB_COMPRESSION)
139 @@ -83,16 +143,6 @@ static int squashfs_fill_super(struct su
140 unsigned short flags;
141 unsigned int fragments;
142 u64 lookup_table_start;
148 - .nla_len = nla_attr_size(sizeof(int)),
149 - .nla_type = ZLIB_DECOMP_WINDOWBITS,
155 TRACE("Entered squashfs_fill_superblock\n");
156 @@ -104,21 +154,6 @@ static int squashfs_fill_super(struct su
158 msblk = sb->s_fs_info;
160 - msblk->tfm = crypto_alloc_pcomp(SQUASHFS_CRYPTO_ALG, 0,
162 - if (IS_ERR(msblk->tfm)) {
163 - ERROR("Failed to load %s crypto module\n",
164 - SQUASHFS_CRYPTO_ALG);
165 - err = PTR_ERR(msblk->tfm);
169 - err = crypto_decompress_setup(msblk->tfm, ¶ms, sizeof(params));
171 - ERROR("Failed to set up decompression parameters\n");
175 sblk = kzalloc(sizeof(*sblk), GFP_KERNEL);
177 ERROR("Failed to allocate squashfs_super_block\n");
178 @@ -156,10 +191,28 @@ static int squashfs_fill_super(struct su
182 + /* Check block size for sanity */
183 + msblk->block_size = le32_to_cpu(sblk->block_size);
184 + if (msblk->block_size > SQUASHFS_FILE_MAX_SIZE)
187 /* Check the MAJOR & MINOR versions and compression type */
188 err = supported_squashfs_filesystem(le16_to_cpu(sblk->s_major),
189 - le16_to_cpu(sblk->s_minor),
190 - le16_to_cpu(sblk->compression));
191 + le16_to_cpu(sblk->s_minor));
195 + switch(le16_to_cpu(sblk->compression)) {
196 + case ZLIB_COMPRESSION:
197 + err = squashfs_setup_zlib(msblk);
199 + case LZMA_COMPRESSION:
200 + err = squashfs_setup_lzma(msblk);
209 @@ -179,11 +232,6 @@ static int squashfs_fill_super(struct su
210 i_size_read(sb->s_bdev->bd_inode))
213 - /* Check block size for sanity */
214 - msblk->block_size = le32_to_cpu(sblk->block_size);
215 - if (msblk->block_size > SQUASHFS_FILE_MAX_SIZE)
219 * Check the system page size is not larger than the filesystem
220 * block size (by default 128K). This is currently not supported.
221 @@ -315,21 +363,16 @@ allocate_root:
226 + crypto_free_pcomp(msblk->tfm);
227 squashfs_cache_delete(msblk->block_cache);
228 squashfs_cache_delete(msblk->fragment_cache);
229 squashfs_cache_delete(msblk->read_page);
230 kfree(msblk->inode_lookup_table);
231 kfree(msblk->fragment_index);
232 kfree(msblk->id_table);
233 - crypto_free_pcomp(msblk->tfm);
234 - kfree(sb->s_fs_info);
235 - sb->s_fs_info = NULL;
240 - crypto_free_pcomp(msblk->tfm);
242 kfree(sb->s_fs_info);
243 sb->s_fs_info = NULL;