c07239bb2da90cc3440b29fd9dbc8d968345b082
[openwrt/svn-archive/archive.git] / target / linux / generic-2.6 / patches-2.6.31 / 053-squashfs_lzma.patch
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"
5 depends on BLOCK
6 select CRYPTO
7 - select CRYPTO_ZLIB
8 help
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
12
13 If unsure, say N.
14
15 +config SQUASHFS_SUPPORT_ZLIB
16 + bool
17 + prompt "Support ZLIB compression" if SQUASHFS_SUPPORT_LZMA
18 + depends on SQUASHFS
19 + select CRYPTO_ZLIB
20 + default y
21 + help
22 + ZLIB is the default compression used in squashfs. If you are
23 + using LZMA compression instead, you can remove support for ZLIB
24 + entirely.
25 +
26 +config SQUASHFS_SUPPORT_LZMA
27 + bool "Support LZMA compression"
28 + depends on SQUASHFS
29 + select CRYPTO_UNLZMA
30 + help
31 + By default SquashFS uses ZLIB compression, however (if your tools
32 + support it, you can use LZMA instead, which saves space.
33 +
34 +
35 config SQUASHFS_FRAGMENT_CACHE_SIZE
36 int "Number of fragments cached" if SQUASHFS_EMBEDDED
37 depends on SQUASHFS
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
42 */
43 #define ZLIB_COMPRESSION 1
44 +#define LZMA_COMPRESSION 2
45
46 struct squashfs_super_block {
47 __le32 s_magic;
48 --- a/fs/squashfs/super.c
49 +++ b/fs/squashfs/super.c
50 @@ -48,13 +48,65 @@
51 #include "squashfs.h"
52
53
54 -#define SQUASHFS_CRYPTO_ALG "zlib"
55 +static int squashfs_setup_zlib(struct squashfs_sb_info *msblk)
56 +{
57 + int err = -EOPNOTSUPP;
58 +
59 +#ifdef CONFIG_SQUASHFS_SUPPORT_ZLIB
60 + struct {
61 + struct nlattr nla;
62 + int val;
63 + } params = {
64 + .nla = {
65 + .nla_len = nla_attr_size(sizeof(int)),
66 + .nla_type = ZLIB_DECOMP_WINDOWBITS,
67 + },
68 + .val = DEF_WBITS,
69 + };
70 +
71 + msblk->tfm = crypto_alloc_pcomp("zlib", 0,
72 + CRYPTO_ALG_ASYNC);
73 + if (IS_ERR(msblk->tfm)) {
74 + ERROR("Failed to load zlib crypto module\n");
75 + return PTR_ERR(msblk->tfm);
76 + }
77 +
78 + err = crypto_decompress_setup(msblk->tfm, &params, sizeof(params));
79 + if (err) {
80 + ERROR("Failed to set up decompression parameters\n");
81 + crypto_free_pcomp(msblk->tfm);
82 + }
83 +#endif
84
85 + return err;
86 +}
87 +
88 +static int squashfs_setup_lzma(struct squashfs_sb_info *msblk)
89 +{
90 + int err = -EOPNOTSUPP;
91 +
92 +#ifdef CONFIG_SQUASHFS_SUPPORT_LZMA
93 + msblk->tfm = crypto_alloc_pcomp("lzma", 0,
94 + CRYPTO_ALG_ASYNC);
95 + if (IS_ERR(msblk->tfm)) {
96 + ERROR("Failed to load lzma crypto module\n");
97 + return PTR_ERR(msblk->tfm);
98 + }
99 +
100 + err = crypto_decompress_setup(msblk->tfm, NULL, 0);
101 + if (err) {
102 + ERROR("Failed to set up decompression parameters\n");
103 + crypto_free_pcomp(msblk->tfm);
104 + }
105 +#endif
106 +
107 + return err;
108 +}
109
110 static struct file_system_type squashfs_fs_type;
111 static struct super_operations squashfs_super_ops;
112
113 -static int supported_squashfs_filesystem(short major, short minor, short comp)
114 +static int supported_squashfs_filesystem(short major, short minor)
115 {
116 if (major < SQUASHFS_MAJOR) {
117 ERROR("Major/Minor mismatch, older Squashfs %d.%d "
118 @@ -67,9 +119,6 @@ static int supported_squashfs_filesystem
119 return -EINVAL;
120 }
121
122 - if (comp != ZLIB_COMPRESSION)
123 - return -EINVAL;
124 -
125 return 0;
126 }
127
128 @@ -84,16 +133,6 @@ static int squashfs_fill_super(struct su
129 unsigned short flags;
130 unsigned int fragments;
131 u64 lookup_table_start;
132 - struct {
133 - struct nlattr nla;
134 - int val;
135 - } params = {
136 - .nla = {
137 - .nla_len = nla_attr_size(sizeof(int)),
138 - .nla_type = ZLIB_DECOMP_WINDOWBITS,
139 - },
140 - .val = DEF_WBITS,
141 - };
142 int err;
143
144 TRACE("Entered squashfs_fill_superblock\n");
145 @@ -105,21 +144,6 @@ static int squashfs_fill_super(struct su
146 }
147 msblk = sb->s_fs_info;
148
149 - msblk->tfm = crypto_alloc_pcomp(SQUASHFS_CRYPTO_ALG, 0,
150 - CRYPTO_ALG_ASYNC);
151 - if (IS_ERR(msblk->tfm)) {
152 - ERROR("Failed to load %s crypto module\n",
153 - SQUASHFS_CRYPTO_ALG);
154 - err = PTR_ERR(msblk->tfm);
155 - goto failed_pcomp;
156 - }
157 -
158 - err = crypto_decompress_setup(msblk->tfm, &params, sizeof(params));
159 - if (err) {
160 - ERROR("Failed to set up decompression parameters\n");
161 - goto failure;
162 - }
163 -
164 sblk = kzalloc(sizeof(*sblk), GFP_KERNEL);
165 if (sblk == NULL) {
166 ERROR("Failed to allocate squashfs_super_block\n");
167 @@ -159,8 +183,21 @@ static int squashfs_fill_super(struct su
168
169 /* Check the MAJOR & MINOR versions and compression type */
170 err = supported_squashfs_filesystem(le16_to_cpu(sblk->s_major),
171 - le16_to_cpu(sblk->s_minor),
172 - le16_to_cpu(sblk->compression));
173 + le16_to_cpu(sblk->s_minor));
174 + if (err < 0)
175 + goto failed_mount;
176 +
177 + switch(le16_to_cpu(sblk->compression)) {
178 + case ZLIB_COMPRESSION:
179 + err = squashfs_setup_zlib(msblk);
180 + break;
181 + case LZMA_COMPRESSION:
182 + err = squashfs_setup_lzma(msblk);
183 + break;
184 + default:
185 + err = -EINVAL;
186 + break;
187 + }
188 if (err < 0)
189 goto failed_mount;
190
191 @@ -316,21 +353,16 @@ allocate_root:
192 return 0;
193
194 failed_mount:
195 + if (msblk->tfm)
196 + crypto_free_pcomp(msblk->tfm);
197 squashfs_cache_delete(msblk->block_cache);
198 squashfs_cache_delete(msblk->fragment_cache);
199 squashfs_cache_delete(msblk->read_page);
200 kfree(msblk->inode_lookup_table);
201 kfree(msblk->fragment_index);
202 kfree(msblk->id_table);
203 - crypto_free_pcomp(msblk->tfm);
204 - kfree(sb->s_fs_info);
205 - sb->s_fs_info = NULL;
206 kfree(sblk);
207 - return err;
208 -
209 failure:
210 - crypto_free_pcomp(msblk->tfm);
211 -failed_pcomp:
212 kfree(sb->s_fs_info);
213 sb->s_fs_info = NULL;
214 return err;