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