/* jffs2_compress: * @data: Pointer to uncompressed data * @cdata: Pointer to returned pointer to buffer for compressed data * @datalen: On entry, holds the amount of data available for compression. * On exit, expected to hold the amount of data actually compressed. * @cdatalen: On entry, holds the amount of space available for compressed * data. On exit, expected to hold the actual size of the compressed * data. * * Returns: Byte to be stored with data indicating compression type used. * Zero is used to show that the data could not be compressed - the * compressed version was actually larger than the original. * * If the cdata buffer isn't large enough to hold all the uncompressed data, * jffs2_compress should compress as much as will fit, and should set * *datalen accordingly to show the amount of data which were compressed. */ unsigned char jffs2_compress(unsigned char *data_in, unsigned char **cpage_out, uint32_t *datalen, uint32_t *cdatalen) { #ifdef JFFS2_COMPRESSION int ret; *cpage_out = kmalloc(*cdatalen, GFP_KERNEL); if (!*cpage_out) { printk(KERN_WARNING "No memory for compressor allocation. Compression failed\n"); goto out; } #ifdef JFFS2_USE_ZLIB ret = jffs2_zlib_compress(data_in, *cpage_out, datalen, cdatalen); if (!ret) { return JFFS2_COMPR_ZLIB; } #endif #ifdef JFFS2_USE_DYNRUBIN ret = jffs2_dynrubin_compress(data_in, *cpage_out, datalen, cdatalen); if (!ret) { return JFFS2_COMPR_DYNRUBIN; } #endif #ifdef JFFS2_USE_RUBINMIPS ret = jffs2_rubinmips_compress(data_in, *cpage_out, datalen, cdatalen); if (!ret) { return JFFS2_COMPR_RUBINMIPS; } #endif #ifdef JFFS2_USE_RTIME /* rtime does manage to recompress already-compressed data */ ret = jffs2_rtime_compress(data_in, *cpage_out, datalen, cdatalen); if (!ret) { return JFFS2_COMPR_RTIME; } #endif kfree(*cpage_out); #endif /* Compression */ out: *cpage_out = data_in; *datalen = *cdatalen; return JFFS2_COMPR_NONE; /* We failed to compress */ }
/* jffs2_compress: * @data: Pointer to uncompressed data * @cdata: Pointer to buffer for compressed data * @datalen: On entry, holds the amount of data available for compression. * On exit, expected to hold the amount of data actually compressed. * @cdatalen: On entry, holds the amount of space available for compressed * data. On exit, expected to hold the actual size of the compressed * data. * * Returns: Byte to be stored with data indicating compression type used. * Zero is used to show that the data could not be compressed - the * compressed version was actually larger than the original. * * If the cdata buffer isn't large enough to hold all the uncompressed data, * jffs2_compress should compress as much as will fit, and should set * *datalen accordingly to show the amount of data which were compressed. */ unsigned char jffs2_compress(unsigned char *data_in, unsigned char *cpage_out, uint32_t *datalen, uint32_t *cdatalen) { int ret; ret = jffs2_zlib_compress(data_in, cpage_out, datalen, cdatalen); if (!ret) { return JFFS2_COMPR_ZLIB; } #if 0 /* Disabled 23/9/1. With zlib it hardly ever gets a look in */ ret = jffs2_dynrubin_compress(data_in, cpage_out, datalen, cdatalen); if (!ret) { return JFFS2_COMPR_DYNRUBIN; } #endif #if 0 /* Disabled 26/2/1. Obsoleted by dynrubin */ ret = jffs2_rubinmips_compress(data_in, cpage_out, datalen, cdatalen); if (!ret) { return JFFS2_COMPR_RUBINMIPS; } #endif /* rtime does manage to recompress already-compressed data */ ret = jffs2_rtime_compress(data_in, cpage_out, datalen, cdatalen); if (!ret) { return JFFS2_COMPR_RTIME; } #if 0 /* We don't need to copy. Let the caller special-case the COMPR_NONE case. */ /* If we get here, no compression is going to work */ /* But we might want to use the fragmentation part -- Arjan */ memcpy(cpage_out,data_in,min(*datalen,*cdatalen)); if (*datalen > *cdatalen) *datalen = *cdatalen; #endif return JFFS2_COMPR_NONE; /* We failed to compress */ }