15 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 static uint32_t none_stat_compr_blocks=0,none_stat_decompr_blocks=0,none_stat_compr_size=0;
37 switch (jffs2_compression_mode) {
74 static int jffs2_selected_compress(
u8 compr,
unsigned char *data_in,
84 pr_warn(
"No memory for compressor allocation. Compression failed.\n");
88 orig_dlen = *cdatalen;
89 spin_lock(&jffs2_compressor_list_lock);
96 if (compr && (compr != this->compr))
104 spin_unlock(&jffs2_compressor_list_lock);
106 *datalen = orig_slen;
107 *cdatalen = orig_dlen;
108 err = this->
compress(data_in, output_buf, datalen, cdatalen);
110 spin_lock(&jffs2_compressor_list_lock);
121 spin_unlock(&jffs2_compressor_list_lock);
125 *cpage_out = output_buf;
149 unsigned char *data_in,
unsigned char **cpage_out,
155 unsigned char *output_buf =
NULL, *tmp_buf;
162 mode = jffs2_compression_mode;
168 ret = jffs2_selected_compress(0, data_in, cpage_out, datalen,
174 orig_dlen = *cdatalen;
175 spin_lock(&jffs2_compressor_list_lock);
182 spin_unlock(&jffs2_compressor_list_lock);
184 spin_lock(&jffs2_compressor_list_lock);
189 spin_unlock(&jffs2_compressor_list_lock);
191 spin_lock(&jffs2_compressor_list_lock);
193 pr_warn(
"No memory for compressor allocation. (%d bytes)\n",
203 spin_unlock(&jffs2_compressor_list_lock);
204 *datalen = orig_slen;
205 *cdatalen = orig_dlen;
207 spin_lock(&jffs2_compressor_list_lock);
210 if (((!best_dlen) || jffs2_is_best_compression(
this, best, *cdatalen, best_dlen))
211 && (*cdatalen < *datalen)) {
212 best_dlen = *cdatalen;
219 *cdatalen = best_dlen;
220 *datalen = best_slen;
228 *cpage_out = output_buf;
230 spin_unlock(&jffs2_compressor_list_lock);
234 cpage_out, datalen, cdatalen);
238 cpage_out, datalen, cdatalen);
241 pr_err(
"unknown compression mode\n");
245 *cpage_out = data_in;
246 *datalen = *cdatalen;
247 none_stat_compr_blocks++;
248 none_stat_compr_size += *
datalen;
254 uint16_t comprtype,
unsigned char *cdata_in,
265 switch (comprtype & 0xff) {
268 memcpy(data_out, cdata_in, datalen);
269 none_stat_decompr_blocks++;
272 memset(data_out, 0, datalen);
275 spin_lock(&jffs2_compressor_list_lock);
277 if (comprtype == this->compr) {
279 spin_unlock(&jffs2_compressor_list_lock);
280 ret = this->
decompress(cdata_in, data_out, cdatalen, datalen);
281 spin_lock(&jffs2_compressor_list_lock);
283 pr_warn(
"Decompressor \"%s\" returned %d\n",
290 spin_unlock(&jffs2_compressor_list_lock);
294 pr_warn(
"compression type 0x%02x not available\n", comprtype);
295 spin_unlock(&jffs2_compressor_list_lock);
306 pr_warn(
"NULL compressor name at registering JFFS2 compressor. Failed.\n");
316 jffs2_dbg(1,
"Registering JFFS2 compressor \"%s\"\n", comp->
name);
318 spin_lock(&jffs2_compressor_list_lock);
321 if (this->priority < comp->
priority) {
322 list_add(&comp->
list, this->list.prev);
332 spin_unlock(&jffs2_compressor_list_lock);
341 jffs2_dbg(1,
"Unregistering JFFS2 compressor \"%s\"\n", comp->
name);
343 spin_lock(&jffs2_compressor_list_lock);
346 spin_unlock(&jffs2_compressor_list_lock);
347 pr_warn(
"Compressor module is in use. Unregister failed.\n");
355 spin_unlock(&jffs2_compressor_list_lock);
361 if (orig != comprbuf)
368 #ifdef CONFIG_JFFS2_ZLIB
371 #ifdef CONFIG_JFFS2_RTIME
374 #ifdef CONFIG_JFFS2_RUBIN
378 #ifdef CONFIG_JFFS2_LZO
382 #ifdef CONFIG_JFFS2_CMODE_NONE
384 jffs2_dbg(1,
"default compression mode: none\n");
386 #ifdef CONFIG_JFFS2_CMODE_SIZE
388 jffs2_dbg(1,
"default compression mode: size\n");
390 #ifdef CONFIG_JFFS2_CMODE_FAVOURLZO
392 jffs2_dbg(1,
"default compression mode: favourlzo\n");
394 jffs2_dbg(1,
"default compression mode: priority\n");
404 #ifdef CONFIG_JFFS2_LZO
407 #ifdef CONFIG_JFFS2_RUBIN
411 #ifdef CONFIG_JFFS2_RTIME
414 #ifdef CONFIG_JFFS2_ZLIB