compr.c (2227c0ba4bc177a014d95b380b4d888454a127a9) compr.c (182ec4eee397543101a6db8906ed88727d3f7e53)
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 * Created by Arjan van de Ven <arjanv@redhat.com>
6 *
7 * Copyright (C) 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>,
8 * University of Szeged, Hungary
9 *
10 * For licensing information, see the file 'LICENCE' in this directory.
11 *
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001-2003 Red Hat, Inc.
5 * Created by Arjan van de Ven <arjanv@redhat.com>
6 *
7 * Copyright (C) 2004 Ferenc Havasi <havasi@inf.u-szeged.hu>,
8 * University of Szeged, Hungary
9 *
10 * For licensing information, see the file 'LICENCE' in this directory.
11 *
12 * $Id: compr.c,v 1.45 2005/07/26 13:24:40 havasi Exp $
12 * $Id: compr.c,v 1.46 2005/11/07 11:14:38 gleixner Exp $
13 *
14 */
15
16#include "compr.h"
17
18static DEFINE_SPINLOCK(jffs2_compressor_list_lock);
19
20/* Available compressors are on this list */

--- 10 unchanged lines hidden (view full) ---

31 * @cdata: Pointer to returned pointer to buffer for compressed data
32 * @datalen: On entry, holds the amount of data available for compression.
33 * On exit, expected to hold the amount of data actually compressed.
34 * @cdatalen: On entry, holds the amount of space available for compressed
35 * data. On exit, expected to hold the actual size of the compressed
36 * data.
37 *
38 * Returns: Lower byte to be stored with data indicating compression type used.
13 *
14 */
15
16#include "compr.h"
17
18static DEFINE_SPINLOCK(jffs2_compressor_list_lock);
19
20/* Available compressors are on this list */

--- 10 unchanged lines hidden (view full) ---

31 * @cdata: Pointer to returned pointer to buffer for compressed data
32 * @datalen: On entry, holds the amount of data available for compression.
33 * On exit, expected to hold the amount of data actually compressed.
34 * @cdatalen: On entry, holds the amount of space available for compressed
35 * data. On exit, expected to hold the actual size of the compressed
36 * data.
37 *
38 * Returns: Lower byte to be stored with data indicating compression type used.
39 * Zero is used to show that the data could not be compressed - the
39 * Zero is used to show that the data could not be compressed - the
40 * compressed version was actually larger than the original.
41 * Upper byte will be used later. (soon)
42 *
43 * If the cdata buffer isn't large enough to hold all the uncompressed data,
40 * compressed version was actually larger than the original.
41 * Upper byte will be used later. (soon)
42 *
43 * If the cdata buffer isn't large enough to hold all the uncompressed data,
44 * jffs2_compress should compress as much as will fit, and should set
44 * jffs2_compress should compress as much as will fit, and should set
45 * *datalen accordingly to show the amount of data which were compressed.
46 */
47uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
45 * *datalen accordingly to show the amount of data which were compressed.
46 */
47uint16_t jffs2_compress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
48 unsigned char *data_in, unsigned char **cpage_out,
48 unsigned char *data_in, unsigned char **cpage_out,
49 uint32_t *datalen, uint32_t *cdatalen)
50{
51 int ret = JFFS2_COMPR_NONE;
52 int compr_ret;
53 struct jffs2_compressor *this, *best=NULL;
54 unsigned char *output_buf = NULL, *tmp_buf;
55 uint32_t orig_slen, orig_dlen;
56 uint32_t best_slen=0, best_dlen=0;

--- 102 unchanged lines hidden (view full) ---

159 }
160 else {
161 *cpage_out = output_buf;
162 }
163 return ret;
164}
165
166int jffs2_decompress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
49 uint32_t *datalen, uint32_t *cdatalen)
50{
51 int ret = JFFS2_COMPR_NONE;
52 int compr_ret;
53 struct jffs2_compressor *this, *best=NULL;
54 unsigned char *output_buf = NULL, *tmp_buf;
55 uint32_t orig_slen, orig_dlen;
56 uint32_t best_slen=0, best_dlen=0;

--- 102 unchanged lines hidden (view full) ---

159 }
160 else {
161 *cpage_out = output_buf;
162 }
163 return ret;
164}
165
166int jffs2_decompress(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
167 uint16_t comprtype, unsigned char *cdata_in,
167 uint16_t comprtype, unsigned char *cdata_in,
168 unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)
169{
170 struct jffs2_compressor *this;
171 int ret;
172
173 /* Older code had a bug where it would write non-zero 'usercompr'
174 fields. Deal with it. */
175 if ((comprtype & 0xff) <= JFFS2_COMPR_ZLIB)

--- 117 unchanged lines hidden (view full) ---

293{
294 struct jffs2_compressor *this;
295 char *buf, *act_buf;
296
297 act_buf = buf = kmalloc(JFFS2_STAT_BUF_SIZE,GFP_KERNEL);
298
299 act_buf += sprintf(act_buf,"JFFS2 compressor statistics:\n");
300 act_buf += sprintf(act_buf,"%10s ","none");
168 unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)
169{
170 struct jffs2_compressor *this;
171 int ret;
172
173 /* Older code had a bug where it would write non-zero 'usercompr'
174 fields. Deal with it. */
175 if ((comprtype & 0xff) <= JFFS2_COMPR_ZLIB)

--- 117 unchanged lines hidden (view full) ---

293{
294 struct jffs2_compressor *this;
295 char *buf, *act_buf;
296
297 act_buf = buf = kmalloc(JFFS2_STAT_BUF_SIZE,GFP_KERNEL);
298
299 act_buf += sprintf(act_buf,"JFFS2 compressor statistics:\n");
300 act_buf += sprintf(act_buf,"%10s ","none");
301 act_buf += sprintf(act_buf,"compr: %d blocks (%d) decompr: %d blocks\n", none_stat_compr_blocks,
301 act_buf += sprintf(act_buf,"compr: %d blocks (%d) decompr: %d blocks\n", none_stat_compr_blocks,
302 none_stat_compr_size, none_stat_decompr_blocks);
303 spin_lock(&jffs2_compressor_list_lock);
304 list_for_each_entry(this, &jffs2_compressor_list, list) {
305 act_buf += sprintf(act_buf,"%10s ",this->name);
306 if ((this->disabled)||(!this->compress))
307 act_buf += sprintf(act_buf,"- ");
308 else
309 act_buf += sprintf(act_buf,"+ ");
302 none_stat_compr_size, none_stat_decompr_blocks);
303 spin_lock(&jffs2_compressor_list_lock);
304 list_for_each_entry(this, &jffs2_compressor_list, list) {
305 act_buf += sprintf(act_buf,"%10s ",this->name);
306 if ((this->disabled)||(!this->compress))
307 act_buf += sprintf(act_buf,"- ");
308 else
309 act_buf += sprintf(act_buf,"+ ");
310 act_buf += sprintf(act_buf,"compr: %d blocks (%d/%d) decompr: %d blocks ", this->stat_compr_blocks,
311 this->stat_compr_new_size, this->stat_compr_orig_size,
310 act_buf += sprintf(act_buf,"compr: %d blocks (%d/%d) decompr: %d blocks ", this->stat_compr_blocks,
311 this->stat_compr_new_size, this->stat_compr_orig_size,
312 this->stat_decompr_blocks);
313 act_buf += sprintf(act_buf,"\n");
314 }
315 spin_unlock(&jffs2_compressor_list_lock);
316
317 return buf;
318}
319
312 this->stat_decompr_blocks);
313 act_buf += sprintf(act_buf,"\n");
314 }
315 spin_unlock(&jffs2_compressor_list_lock);
316
317 return buf;
318}
319
320char *jffs2_get_compression_mode_name(void)
320char *jffs2_get_compression_mode_name(void)
321{
322 switch (jffs2_compression_mode) {
323 case JFFS2_COMPR_MODE_NONE:
324 return "none";
325 case JFFS2_COMPR_MODE_PRIORITY:
326 return "priority";
327 case JFFS2_COMPR_MODE_SIZE:
328 return "size";
329 }
330 return "unkown";
331}
332
321{
322 switch (jffs2_compression_mode) {
323 case JFFS2_COMPR_MODE_NONE:
324 return "none";
325 case JFFS2_COMPR_MODE_PRIORITY:
326 return "priority";
327 case JFFS2_COMPR_MODE_SIZE:
328 return "size";
329 }
330 return "unkown";
331}
332
333int jffs2_set_compression_mode_name(const char *name)
333int jffs2_set_compression_mode_name(const char *name)
334{
335 if (!strcmp("none",name)) {
336 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
337 return 0;
338 }
339 if (!strcmp("priority",name)) {
340 jffs2_compression_mode = JFFS2_COMPR_MODE_PRIORITY;
341 return 0;

--- 8 unchanged lines hidden (view full) ---

350static int jffs2_compressor_Xable(const char *name, int disabled)
351{
352 struct jffs2_compressor *this;
353 spin_lock(&jffs2_compressor_list_lock);
354 list_for_each_entry(this, &jffs2_compressor_list, list) {
355 if (!strcmp(this->name, name)) {
356 this->disabled = disabled;
357 spin_unlock(&jffs2_compressor_list_lock);
334{
335 if (!strcmp("none",name)) {
336 jffs2_compression_mode = JFFS2_COMPR_MODE_NONE;
337 return 0;
338 }
339 if (!strcmp("priority",name)) {
340 jffs2_compression_mode = JFFS2_COMPR_MODE_PRIORITY;
341 return 0;

--- 8 unchanged lines hidden (view full) ---

350static int jffs2_compressor_Xable(const char *name, int disabled)
351{
352 struct jffs2_compressor *this;
353 spin_lock(&jffs2_compressor_list_lock);
354 list_for_each_entry(this, &jffs2_compressor_list, list) {
355 if (!strcmp(this->name, name)) {
356 this->disabled = disabled;
357 spin_unlock(&jffs2_compressor_list_lock);
358 return 0;
358 return 0;
359 }
360 }
361 spin_unlock(&jffs2_compressor_list_lock);
362 printk(KERN_WARNING "JFFS2: compressor %s not found.\n",name);
363 return 1;
364}
365
366int jffs2_enable_compressor_name(const char *name)

--- 13 unchanged lines hidden (view full) ---

380 list_for_each_entry(this, &jffs2_compressor_list, list) {
381 if (!strcmp(this->name, name)) {
382 this->priority = priority;
383 comp = this;
384 goto reinsert;
385 }
386 }
387 spin_unlock(&jffs2_compressor_list_lock);
359 }
360 }
361 spin_unlock(&jffs2_compressor_list_lock);
362 printk(KERN_WARNING "JFFS2: compressor %s not found.\n",name);
363 return 1;
364}
365
366int jffs2_enable_compressor_name(const char *name)

--- 13 unchanged lines hidden (view full) ---

380 list_for_each_entry(this, &jffs2_compressor_list, list) {
381 if (!strcmp(this->name, name)) {
382 this->priority = priority;
383 comp = this;
384 goto reinsert;
385 }
386 }
387 spin_unlock(&jffs2_compressor_list_lock);
388 printk(KERN_WARNING "JFFS2: compressor %s not found.\n",name);
388 printk(KERN_WARNING "JFFS2: compressor %s not found.\n",name);
389 return 1;
390reinsert:
391 /* list is sorted in the order of priority, so if
392 we change it we have to reinsert it into the
393 good place */
394 list_del(&comp->list);
395 list_for_each_entry(this, &jffs2_compressor_list, list) {
396 if (this->priority < comp->priority) {

--- 10 unchanged lines hidden (view full) ---

407#endif
408
409void jffs2_free_comprbuf(unsigned char *comprbuf, unsigned char *orig)
410{
411 if (orig != comprbuf)
412 kfree(comprbuf);
413}
414
389 return 1;
390reinsert:
391 /* list is sorted in the order of priority, so if
392 we change it we have to reinsert it into the
393 good place */
394 list_del(&comp->list);
395 list_for_each_entry(this, &jffs2_compressor_list, list) {
396 if (this->priority < comp->priority) {

--- 10 unchanged lines hidden (view full) ---

407#endif
408
409void jffs2_free_comprbuf(unsigned char *comprbuf, unsigned char *orig)
410{
411 if (orig != comprbuf)
412 kfree(comprbuf);
413}
414
415int jffs2_compressors_init(void)
415int jffs2_compressors_init(void)
416{
417/* Registering compressors */
418#ifdef CONFIG_JFFS2_ZLIB
419 jffs2_zlib_init();
420#endif
421#ifdef CONFIG_JFFS2_RTIME
422 jffs2_rtime_init();
423#endif

--- 11 unchanged lines hidden (view full) ---

435 D1(printk(KERN_INFO "JFFS2: default compression mode: size\n");)
436#else
437 D1(printk(KERN_INFO "JFFS2: default compression mode: priority\n");)
438#endif
439#endif
440 return 0;
441}
442
416{
417/* Registering compressors */
418#ifdef CONFIG_JFFS2_ZLIB
419 jffs2_zlib_init();
420#endif
421#ifdef CONFIG_JFFS2_RTIME
422 jffs2_rtime_init();
423#endif

--- 11 unchanged lines hidden (view full) ---

435 D1(printk(KERN_INFO "JFFS2: default compression mode: size\n");)
436#else
437 D1(printk(KERN_INFO "JFFS2: default compression mode: priority\n");)
438#endif
439#endif
440 return 0;
441}
442
443int jffs2_compressors_exit(void)
443int jffs2_compressors_exit(void)
444{
445/* Unregistering compressors */
446#ifdef CONFIG_JFFS2_RUBIN
447 jffs2_dynrubin_exit();
448 jffs2_rubinmips_exit();
449#endif
450#ifdef CONFIG_JFFS2_RTIME
451 jffs2_rtime_exit();
452#endif
453#ifdef CONFIG_JFFS2_ZLIB
454 jffs2_zlib_exit();
455#endif
456 return 0;
457}
444{
445/* Unregistering compressors */
446#ifdef CONFIG_JFFS2_RUBIN
447 jffs2_dynrubin_exit();
448 jffs2_rubinmips_exit();
449#endif
450#ifdef CONFIG_JFFS2_RTIME
451 jffs2_rtime_exit();
452#endif
453#ifdef CONFIG_JFFS2_ZLIB
454 jffs2_zlib_exit();
455#endif
456 return 0;
457}