Mercurial > flash_v2
comparison packages/fs/jffs2/current/src/compr.c @ 1443:cd7d2afbc7dd
Import latest JFFS2 code from David Woodhouse
| author | gthomas |
|---|---|
| date | Thu, 11 Dec 2003 23:33:54 +0000 |
| parents | 121121d3d18f |
| children | 8bafb5f8a697 |
comparison
equal
deleted
inserted
replaced
| 1442:b2f2e3f2a047 | 1443:cd7d2afbc7dd |
|---|---|
| 5 * | 5 * |
| 6 * Created by Arjan van de Ven <arjanv@redhat.com> | 6 * Created by Arjan van de Ven <arjanv@redhat.com> |
| 7 * | 7 * |
| 8 * For licensing information, see the file 'LICENCE' in this directory. | 8 * For licensing information, see the file 'LICENCE' in this directory. |
| 9 * | 9 * |
| 10 * $Id: compr.c,v 1.29 2003/11/20 16:40:35 dwmw2 Exp $ | 10 * $Id: compr.c,v 1.33 2003/11/28 17:22:54 dwmw2 Exp $ |
| 11 * | 11 * |
| 12 */ | 12 */ |
| 13 | 13 |
| 14 #include <linux/kernel.h> | 14 #include <linux/kernel.h> |
| 15 #include <linux/string.h> | 15 #include <linux/string.h> |
| 16 #include <linux/errno.h> | 16 #include <linux/errno.h> |
| 17 #include <linux/types.h> | 17 #include <linux/types.h> |
| 18 #include <linux/slab.h> | 18 #include <linux/slab.h> |
| 19 #include <linux/jffs2.h> | 19 #include <linux/jffs2.h> |
| 20 #include "nodelist.h" | |
| 20 | 21 |
| 21 int jffs2_zlib_compress(unsigned char *data_in, unsigned char *cpage_out, uint32_t *sourcelen, uint32_t *dstlen); | 22 int jffs2_zlib_compress(unsigned char *data_in, unsigned char *cpage_out, uint32_t *sourcelen, uint32_t *dstlen); |
| 22 void jffs2_zlib_decompress(unsigned char *data_in, unsigned char *cpage_out, uint32_t srclen, uint32_t destlen); | 23 void jffs2_zlib_decompress(unsigned char *data_in, unsigned char *cpage_out, uint32_t srclen, uint32_t destlen); |
| 23 int jffs2_rtime_compress(unsigned char *data_in, unsigned char *cpage_out, uint32_t *sourcelen, uint32_t *dstlen); | 24 int jffs2_rtime_compress(unsigned char *data_in, unsigned char *cpage_out, uint32_t *sourcelen, uint32_t *dstlen); |
| 24 void jffs2_rtime_decompress(unsigned char *data_in, unsigned char *cpage_out, uint32_t srclen, uint32_t destlen); | 25 void jffs2_rtime_decompress(unsigned char *data_in, unsigned char *cpage_out, uint32_t srclen, uint32_t destlen); |
| 52 int ret; | 53 int ret; |
| 53 | 54 |
| 54 *cpage_out = kmalloc(*cdatalen, GFP_KERNEL); | 55 *cpage_out = kmalloc(*cdatalen, GFP_KERNEL); |
| 55 if (!*cpage_out) { | 56 if (!*cpage_out) { |
| 56 printk(KERN_WARNING "No memory for compressor allocation. Compression failed\n"); | 57 printk(KERN_WARNING "No memory for compressor allocation. Compression failed\n"); |
| 57 return JFFS2_COMPR_NONE; | 58 goto out; |
| 58 } | 59 } |
| 59 | 60 |
| 60 #ifdef JFFS2_USE_ZLIB | 61 #ifdef JFFS2_USE_ZLIB |
| 61 ret = jffs2_zlib_compress(data_in, cpage_out, datalen, cdatalen); | 62 ret = jffs2_zlib_compress(data_in, *cpage_out, datalen, cdatalen); |
| 62 if (!ret) { | 63 if (!ret) { |
| 63 return JFFS2_COMPR_ZLIB; | 64 return JFFS2_COMPR_ZLIB; |
| 64 } | 65 } |
| 65 #endif | 66 #endif |
| 66 #ifdef JFFS2_USE_DYNRUBIN | 67 #ifdef JFFS2_USE_DYNRUBIN |
| 67 ret = jffs2_dynrubin_compress(data_in, cpage_out, datalen, cdatalen); | 68 ret = jffs2_dynrubin_compress(data_in, *cpage_out, datalen, cdatalen); |
| 68 if (!ret) { | 69 if (!ret) { |
| 69 return JFFS2_COMPR_DYNRUBIN; | 70 return JFFS2_COMPR_DYNRUBIN; |
| 70 } | 71 } |
| 71 #endif | 72 #endif |
| 72 #ifdef JFFS2_USE_RUBINMIPS | 73 #ifdef JFFS2_USE_RUBINMIPS |
| 73 ret = jffs2_rubinmips_compress(data_in, cpage_out, datalen, cdatalen); | 74 ret = jffs2_rubinmips_compress(data_in, *cpage_out, datalen, cdatalen); |
| 74 if (!ret) { | 75 if (!ret) { |
| 75 return JFFS2_COMPR_RUBINMIPS; | 76 return JFFS2_COMPR_RUBINMIPS; |
| 76 } | 77 } |
| 77 #endif | 78 #endif |
| 78 #ifdef JFFS2_USE_RTIME | 79 #ifdef JFFS2_USE_RTIME |
| 79 /* rtime does manage to recompress already-compressed data */ | 80 /* rtime does manage to recompress already-compressed data */ |
| 80 ret = jffs2_rtime_compress(data_in, cpage_out, datalen, cdatalen); | 81 ret = jffs2_rtime_compress(data_in, *cpage_out, datalen, cdatalen); |
| 81 if (!ret) { | 82 if (!ret) { |
| 82 return JFFS2_COMPR_RTIME; | 83 return JFFS2_COMPR_RTIME; |
| 83 } | 84 } |
| 84 #endif | 85 #endif |
| 85 kfree(*cpage_out); | 86 kfree(*cpage_out); |
| 86 #endif /* Compression */ | 87 #endif /* Compression */ |
| 88 out: | |
| 87 *cpage_out = data_in; | 89 *cpage_out = data_in; |
| 88 *datalen = *cdatalen; | 90 *datalen = *cdatalen; |
| 89 return JFFS2_COMPR_NONE; /* We failed to compress */ | 91 return JFFS2_COMPR_NONE; /* We failed to compress */ |
| 90 } | 92 } |
| 91 | 93 |
| 92 void jffs2_free_comprbuf(unsigned char *orig, unsigned char *comprbuf) | 94 void jffs2_free_comprbuf(unsigned char *comprbuf, unsigned char *orig) |
| 93 { | 95 { |
| 94 if (orig != comprbuf) | 96 if (orig != comprbuf) |
| 95 kfree(comprbuf); | 97 kfree(comprbuf); |
| 96 } | 98 } |
| 97 | 99 |
