2012-05-28 14:49:29 +00:00
|
|
|
/*
|
|
|
|
* This file is a part of Pcompress, a chunked parallel multi-
|
|
|
|
* algorithm lossless compression and decompression program.
|
|
|
|
*
|
2013-03-07 14:56:48 +00:00
|
|
|
* Copyright (C) 2012-2013 Moinak Ghosh. All rights reserved.
|
2012-05-28 14:49:29 +00:00
|
|
|
* Use is subject to license terms.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2012-07-07 16:48:29 +00:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2012-05-28 14:49:29 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
2013-03-07 14:56:48 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2012-05-28 14:49:29 +00:00
|
|
|
*
|
2013-03-07 14:56:48 +00:00
|
|
|
* moinakg@belenix.org, http://moinakg.wordpress.com/
|
2012-05-28 14:49:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <strings.h>
|
2014-04-27 18:42:51 +00:00
|
|
|
/*
|
2012-05-31 12:31:34 +00:00
|
|
|
#if defined(sun) || defined(__sun)
|
|
|
|
#include <sys/byteorder.h>
|
|
|
|
#else
|
2012-05-28 14:49:29 +00:00
|
|
|
#include <byteswap.h>
|
2012-05-31 12:31:34 +00:00
|
|
|
#endif
|
2014-04-27 18:42:51 +00:00
|
|
|
*/
|
2012-05-28 14:49:29 +00:00
|
|
|
#include <utils.h>
|
|
|
|
#include <pcompress.h>
|
|
|
|
#include <allocator.h>
|
2013-11-08 18:20:28 +00:00
|
|
|
#include <pc_archive.h>
|
2014-11-06 16:53:33 +00:00
|
|
|
#include "filters/analyzer/analyzer.h"
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2012-05-31 16:06:33 +00:00
|
|
|
static unsigned int lzma_count = 0;
|
|
|
|
static unsigned int bzip2_count = 0;
|
2012-11-04 15:43:26 +00:00
|
|
|
static unsigned int bsc_count = 0;
|
2012-05-31 16:06:33 +00:00
|
|
|
static unsigned int ppmd_count = 0;
|
2013-11-15 15:36:23 +00:00
|
|
|
static unsigned int lz4_count = 0;
|
2012-05-31 16:06:33 +00:00
|
|
|
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int lzma_compress(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *destlen, int level, uchar_t chdr, int btype, void *data);
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int bzip2_compress(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *destlen, int level, uchar_t chdr, int btype, void *data);
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int ppmd_compress(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, int btype, void *data);
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int libbsc_compress(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, int btype, void *data);
|
2013-11-15 15:36:23 +00:00
|
|
|
extern int lz4_compress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, int btype, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int lzma_decompress(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, int btype, void *data);
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int bzip2_decompress(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, int btype, void *data);
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int ppmd_decompress(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, int btype, void *data);
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int libbsc_decompress(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, int btype, void *data);
|
2013-11-15 15:36:23 +00:00
|
|
|
extern int lz4_decompress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, int btype, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2012-12-27 17:36:48 +00:00
|
|
|
extern int lzma_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
2012-11-22 15:32:50 +00:00
|
|
|
int file_version, compress_op_t op);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int lzma_deinit(void **data);
|
2012-12-27 17:36:48 +00:00
|
|
|
extern int ppmd_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
2012-11-22 15:32:50 +00:00
|
|
|
int file_version, compress_op_t op);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int ppmd_deinit(void **data);
|
2012-12-27 17:36:48 +00:00
|
|
|
extern int libbsc_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
2012-11-22 15:32:50 +00:00
|
|
|
int file_version, compress_op_t op);
|
2012-11-04 15:43:26 +00:00
|
|
|
extern int libbsc_deinit(void **data);
|
2013-11-15 15:36:23 +00:00
|
|
|
extern int lz4_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
|
|
|
int file_version, compress_op_t op);
|
|
|
|
extern int lz4_deinit(void **data);
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2013-12-21 18:02:27 +00:00
|
|
|
extern int ppmd_alloc(void *data);
|
|
|
|
extern void ppmd_free(void *data);
|
|
|
|
extern int ppmd_state_init(void **data, int *level, int alloc);
|
|
|
|
|
2014-01-28 18:42:04 +00:00
|
|
|
extern int lz4_buf_extra(uint64_t buflen);
|
|
|
|
extern int libbsc_buf_extra(uint64_t buflen);
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
struct adapt_data {
|
|
|
|
void *lzma_data;
|
|
|
|
void *ppmd_data;
|
2012-11-04 15:43:26 +00:00
|
|
|
void *bsc_data;
|
2013-11-15 15:36:23 +00:00
|
|
|
void *lz4_data;
|
2012-05-28 14:49:29 +00:00
|
|
|
int adapt_mode;
|
2014-11-06 16:53:33 +00:00
|
|
|
analyzer_ctx_t *actx;
|
2012-05-28 14:49:29 +00:00
|
|
|
};
|
|
|
|
|
2014-11-06 16:53:33 +00:00
|
|
|
void
|
|
|
|
adapt_set_analyzer_ctx(void *data, analyzer_ctx_t *actx)
|
|
|
|
{
|
|
|
|
struct adapt_data *adat = (struct adapt_data *)data;
|
|
|
|
adat->actx = actx;
|
|
|
|
}
|
|
|
|
|
2012-05-31 16:06:33 +00:00
|
|
|
void
|
|
|
|
adapt_stats(int show)
|
|
|
|
{
|
|
|
|
if (show) {
|
2013-05-12 06:24:40 +00:00
|
|
|
if (bzip2_count > 0 || bsc_count > 0 || ppmd_count > 0 || lzma_count > 0) {
|
2013-11-15 15:36:23 +00:00
|
|
|
log_msg(LOG_INFO, 0, "Adaptive mode stats:");
|
|
|
|
log_msg(LOG_INFO, 0, " BZIP2 chunk count: %u", bzip2_count);
|
|
|
|
log_msg(LOG_INFO, 0, " LIBBSC chunk count: %u", bsc_count);
|
|
|
|
log_msg(LOG_INFO, 0, " PPMd chunk count: %u", ppmd_count);
|
|
|
|
log_msg(LOG_INFO, 0, " LZMA chunk count: %u", lzma_count);
|
|
|
|
log_msg(LOG_INFO, 0, " LZ4 chunk count: %u", lz4_count);
|
2013-05-12 06:24:40 +00:00
|
|
|
} else {
|
2013-10-02 15:15:33 +00:00
|
|
|
log_msg(LOG_INFO, 0, "\n");
|
2013-05-12 06:24:40 +00:00
|
|
|
}
|
2012-05-31 16:06:33 +00:00
|
|
|
}
|
|
|
|
lzma_count = 0;
|
|
|
|
bzip2_count = 0;
|
2012-11-04 15:43:26 +00:00
|
|
|
bsc_count = 0;
|
2012-05-31 16:06:33 +00:00
|
|
|
ppmd_count = 0;
|
2013-11-15 15:36:23 +00:00
|
|
|
lz4_count = 0;
|
2012-05-31 16:06:33 +00:00
|
|
|
}
|
|
|
|
|
2012-12-04 18:39:47 +00:00
|
|
|
void
|
2012-12-27 17:36:48 +00:00
|
|
|
adapt_props(algo_props_t *data, int level, uint64_t chunksize)
|
2012-12-04 18:39:47 +00:00
|
|
|
{
|
2014-01-28 18:42:04 +00:00
|
|
|
int ext1, ext2;
|
|
|
|
|
2012-12-13 15:48:16 +00:00
|
|
|
data->delta2_span = 200;
|
2013-01-14 07:50:07 +00:00
|
|
|
data->deltac_min_distance = EIGHTM;
|
2014-01-28 18:42:04 +00:00
|
|
|
ext1 = lz4_buf_extra(chunksize);
|
2014-07-24 18:18:42 +00:00
|
|
|
|
|
|
|
#ifdef ENABLE_PC_LIBBSC
|
2014-01-28 18:42:04 +00:00
|
|
|
ext2 = libbsc_buf_extra(chunksize);
|
|
|
|
if (ext2 > ext1) ext1 = ext2;
|
2014-07-24 18:18:42 +00:00
|
|
|
#endif
|
|
|
|
|
2014-01-28 18:42:04 +00:00
|
|
|
data->buf_extra = ext1;
|
2012-12-04 18:39:47 +00:00
|
|
|
}
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
int
|
2012-12-27 17:36:48 +00:00
|
|
|
adapt_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
2012-11-22 15:32:50 +00:00
|
|
|
int file_version, compress_op_t op)
|
2012-05-28 14:49:29 +00:00
|
|
|
{
|
|
|
|
struct adapt_data *adat = (struct adapt_data *)(*data);
|
2013-11-24 14:15:58 +00:00
|
|
|
int rv = 0, lv = 1;
|
2012-05-28 14:49:29 +00:00
|
|
|
|
|
|
|
if (!adat) {
|
|
|
|
adat = (struct adapt_data *)slab_alloc(NULL, sizeof (struct adapt_data));
|
|
|
|
adat->adapt_mode = 1;
|
2013-12-21 18:02:27 +00:00
|
|
|
rv = ppmd_state_init(&(adat->ppmd_data), level, 0);
|
2013-11-22 15:14:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* LZ4 is used to tackle some embedded archive headers and/or zero paddings in
|
|
|
|
* otherwise incompressible data. So we always use it at the lowest and fastest
|
|
|
|
* compression level.
|
|
|
|
*/
|
2013-11-15 15:36:23 +00:00
|
|
|
if (rv == 0)
|
2013-11-24 14:15:58 +00:00
|
|
|
rv = lz4_init(&(adat->lz4_data), &lv, nthreads, chunksize, file_version, op);
|
2012-08-10 04:45:20 +00:00
|
|
|
adat->lzma_data = NULL;
|
2012-11-04 15:43:26 +00:00
|
|
|
adat->bsc_data = NULL;
|
2012-05-28 14:49:29 +00:00
|
|
|
*data = adat;
|
|
|
|
if (*level > 9) *level = 9;
|
|
|
|
}
|
2012-05-31 16:06:33 +00:00
|
|
|
lzma_count = 0;
|
|
|
|
bzip2_count = 0;
|
|
|
|
ppmd_count = 0;
|
2012-11-04 15:43:26 +00:00
|
|
|
bsc_count = 0;
|
2013-11-15 15:36:23 +00:00
|
|
|
lz4_count = 0;
|
2012-05-28 14:49:29 +00:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-12-27 17:36:48 +00:00
|
|
|
adapt2_init(void **data, int *level, int nthreads, uint64_t chunksize,
|
2012-11-22 15:32:50 +00:00
|
|
|
int file_version, compress_op_t op)
|
2012-05-28 14:49:29 +00:00
|
|
|
{
|
|
|
|
struct adapt_data *adat = (struct adapt_data *)(*data);
|
2012-12-27 17:36:48 +00:00
|
|
|
int rv = 0, lv;
|
2012-05-28 14:49:29 +00:00
|
|
|
|
|
|
|
if (!adat) {
|
|
|
|
adat = (struct adapt_data *)slab_alloc(NULL, sizeof (struct adapt_data));
|
|
|
|
adat->adapt_mode = 2;
|
|
|
|
adat->ppmd_data = NULL;
|
2012-11-26 14:51:03 +00:00
|
|
|
adat->bsc_data = NULL;
|
2012-05-28 14:49:29 +00:00
|
|
|
lv = *level;
|
2013-12-21 15:12:38 +00:00
|
|
|
if (lv > 10) lv = 10;
|
2013-12-21 18:02:27 +00:00
|
|
|
rv = ppmd_state_init(&(adat->ppmd_data), level, 0);
|
2012-05-28 14:49:29 +00:00
|
|
|
lv = *level;
|
|
|
|
if (rv == 0)
|
2012-11-22 15:32:50 +00:00
|
|
|
rv = lzma_init(&(adat->lzma_data), &lv, nthreads, chunksize, file_version, op);
|
2012-11-04 15:43:26 +00:00
|
|
|
lv = *level;
|
2012-11-26 14:51:03 +00:00
|
|
|
#ifdef ENABLE_PC_LIBBSC
|
2012-11-04 15:43:26 +00:00
|
|
|
if (rv == 0)
|
2012-11-22 15:32:50 +00:00
|
|
|
rv = libbsc_init(&(adat->bsc_data), &lv, nthreads, chunksize, file_version, op);
|
2012-11-26 14:51:03 +00:00
|
|
|
#endif
|
2013-11-22 15:14:26 +00:00
|
|
|
/*
|
|
|
|
* LZ4 is used to tackle some embedded archive headers and/or zero paddings in
|
|
|
|
* otherwise incompressible data. So we always use it at the lowest and fastest
|
|
|
|
* compression level.
|
|
|
|
*/
|
2013-11-24 14:15:58 +00:00
|
|
|
lv = 1;
|
2013-11-15 15:36:23 +00:00
|
|
|
if (rv == 0)
|
2013-11-24 14:15:58 +00:00
|
|
|
rv = lz4_init(&(adat->lz4_data), &lv, nthreads, chunksize, file_version, op);
|
2012-05-28 14:49:29 +00:00
|
|
|
*data = adat;
|
|
|
|
if (*level > 9) *level = 9;
|
|
|
|
}
|
2012-11-04 15:43:26 +00:00
|
|
|
lzma_count = 0;
|
|
|
|
bzip2_count = 0;
|
|
|
|
ppmd_count = 0;
|
|
|
|
bsc_count = 0;
|
2013-11-15 15:36:23 +00:00
|
|
|
lz4_count = 0;
|
2012-05-28 14:49:29 +00:00
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
adapt_deinit(void **data)
|
|
|
|
{
|
|
|
|
struct adapt_data *adat = (struct adapt_data *)(*data);
|
2012-12-27 17:36:48 +00:00
|
|
|
int rv = 0;
|
2012-05-28 14:49:29 +00:00
|
|
|
|
|
|
|
if (adat) {
|
2012-08-10 04:45:20 +00:00
|
|
|
rv = ppmd_deinit(&(adat->ppmd_data));
|
|
|
|
if (adat->lzma_data)
|
|
|
|
rv += lzma_deinit(&(adat->lzma_data));
|
2013-11-15 15:36:23 +00:00
|
|
|
if (adat->lz4_data)
|
|
|
|
rv += lz4_deinit(&(adat->lz4_data));
|
2012-05-28 14:49:29 +00:00
|
|
|
slab_free(NULL, adat);
|
|
|
|
*data = NULL;
|
|
|
|
}
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
2014-01-01 14:14:58 +00:00
|
|
|
/*
|
|
|
|
* Identify the types that BSC can compress better than others.
|
|
|
|
*/
|
2013-12-03 16:26:07 +00:00
|
|
|
int
|
|
|
|
is_bsc_type(int btype)
|
|
|
|
{
|
|
|
|
int stype = PC_SUBTYPE(btype);
|
2015-01-11 12:06:46 +00:00
|
|
|
int mtype = PC_TYPE(btype);
|
|
|
|
|
|
|
|
return ((stype == TYPE_BMP) | (stype == TYPE_DNA_SEQ) |
|
2014-11-19 14:49:16 +00:00
|
|
|
(stype == TYPE_MP4) | (stype == TYPE_FLAC) | (stype == TYPE_AVI) |
|
2015-01-11 12:06:46 +00:00
|
|
|
(stype == TYPE_DICOM) | (stype == TYPE_MEDIA_BSC) |
|
2015-01-13 14:29:09 +00:00
|
|
|
(mtype & TYPE_TEXT && stype != TYPE_MARKUP));
|
2013-12-03 16:26:07 +00:00
|
|
|
}
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
int
|
2012-12-09 04:45:06 +00:00
|
|
|
adapt_compress(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, int btype, void *data)
|
2012-05-28 14:49:29 +00:00
|
|
|
{
|
|
|
|
struct adapt_data *adat = (struct adapt_data *)(data);
|
2013-12-03 16:26:07 +00:00
|
|
|
int rv = 0, bsc_type = 0;
|
2013-12-30 17:54:37 +00:00
|
|
|
int stype = PC_SUBTYPE(btype);
|
2014-11-06 16:53:33 +00:00
|
|
|
analyzer_ctx_t actx;
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2015-01-13 14:29:09 +00:00
|
|
|
if (btype == TYPE_UNKNOWN || PC_TYPE(btype) & TYPE_TEXT ||
|
2015-01-11 12:06:46 +00:00
|
|
|
stype == TYPE_ARCHIVE_TAR || stype == TYPE_PDF) {
|
2014-11-06 16:53:33 +00:00
|
|
|
if (adat->actx == NULL) {
|
|
|
|
analyze_buffer(src, srclen, &actx);
|
|
|
|
adat->actx = &actx;
|
2013-12-30 17:54:37 +00:00
|
|
|
}
|
2014-11-06 16:53:33 +00:00
|
|
|
if (adat->adapt_mode == 2) {
|
|
|
|
btype = adat->actx->forty_pct.btype;
|
2013-12-30 17:54:37 +00:00
|
|
|
|
2014-11-06 16:53:33 +00:00
|
|
|
} else if (adat->adapt_mode == 1) {
|
|
|
|
btype = adat->actx->fifty_pct.btype;
|
2013-12-30 17:54:37 +00:00
|
|
|
}
|
2013-11-08 18:20:28 +00:00
|
|
|
}
|
2013-02-17 16:06:20 +00:00
|
|
|
|
2014-11-06 16:53:33 +00:00
|
|
|
/* Reset analyzer context for subsequent calls. */
|
|
|
|
adat->actx = NULL;
|
|
|
|
|
2012-09-26 14:17:32 +00:00
|
|
|
/*
|
2012-09-27 16:59:08 +00:00
|
|
|
* Use PPMd if some percentage of source is 7-bit textual bytes, otherwise
|
2013-11-15 15:36:23 +00:00
|
|
|
* use Bzip2 or LZMA. For totally incompressible data we always use LZ4. There
|
|
|
|
* is no point trying to compress such data, like Jpegs. However some archive headers
|
|
|
|
* and zero paddings can exist which LZ4 can easily take care of very fast.
|
2012-09-26 14:17:32 +00:00
|
|
|
*/
|
2013-12-03 16:26:07 +00:00
|
|
|
#ifdef ENABLE_PC_LIBBSC
|
|
|
|
bsc_type = is_bsc_type(btype);
|
|
|
|
#endif
|
2014-11-19 14:49:16 +00:00
|
|
|
if (is_incompressible(btype) && !bsc_type) {
|
2013-11-15 15:36:23 +00:00
|
|
|
rv = lz4_compress(src, srclen, dst, dstlen, level, chdr, btype, adat->lz4_data);
|
|
|
|
if (rv < 0)
|
|
|
|
return (rv);
|
|
|
|
rv = ADAPT_COMPRESS_LZ4;
|
|
|
|
lz4_count++;
|
|
|
|
|
2015-01-13 14:29:09 +00:00
|
|
|
} else if (adat->adapt_mode == 2 && PC_TYPE(btype) & TYPE_BINARY && !bsc_type) {
|
2013-11-08 18:20:28 +00:00
|
|
|
rv = lzma_compress(src, srclen, dst, dstlen, level, chdr, btype, adat->lzma_data);
|
2012-09-27 16:59:08 +00:00
|
|
|
if (rv < 0)
|
|
|
|
return (rv);
|
2013-02-17 15:35:40 +00:00
|
|
|
rv = ADAPT_COMPRESS_LZMA;
|
2012-09-27 16:59:08 +00:00
|
|
|
lzma_count++;
|
|
|
|
|
2015-01-13 14:29:09 +00:00
|
|
|
} else if (adat->adapt_mode == 1 && PC_TYPE(btype) & TYPE_BINARY && !bsc_type) {
|
2013-11-08 18:20:28 +00:00
|
|
|
rv = bzip2_compress(src, srclen, dst, dstlen, level, chdr, btype, NULL);
|
2012-09-27 16:59:08 +00:00
|
|
|
if (rv < 0)
|
|
|
|
return (rv);
|
2013-02-17 15:35:40 +00:00
|
|
|
rv = ADAPT_COMPRESS_BZIP2;
|
2012-09-27 16:59:08 +00:00
|
|
|
bzip2_count++;
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
} else {
|
2013-02-17 16:31:29 +00:00
|
|
|
#ifdef ENABLE_PC_LIBBSC
|
2013-12-03 16:26:07 +00:00
|
|
|
if (adat->bsc_data && bsc_type) {
|
2013-11-08 18:20:28 +00:00
|
|
|
rv = libbsc_compress(src, srclen, dst, dstlen, level, chdr, btype, adat->bsc_data);
|
2012-11-04 15:43:26 +00:00
|
|
|
if (rv < 0)
|
|
|
|
return (rv);
|
2013-02-17 15:35:40 +00:00
|
|
|
rv = ADAPT_COMPRESS_BSC;
|
2012-11-04 15:43:26 +00:00
|
|
|
bsc_count++;
|
|
|
|
} else {
|
2013-02-17 16:31:29 +00:00
|
|
|
#endif
|
2013-12-21 18:02:27 +00:00
|
|
|
rv = ppmd_alloc(adat->ppmd_data);
|
|
|
|
if (rv < 0)
|
|
|
|
return (rv);
|
2013-11-08 18:20:28 +00:00
|
|
|
rv = ppmd_compress(src, srclen, dst, dstlen, level, chdr, btype, adat->ppmd_data);
|
2013-12-21 18:02:27 +00:00
|
|
|
ppmd_free(adat->ppmd_data);
|
2012-11-04 15:43:26 +00:00
|
|
|
if (rv < 0)
|
|
|
|
return (rv);
|
2013-02-17 15:35:40 +00:00
|
|
|
rv = ADAPT_COMPRESS_PPMD;
|
2012-11-04 15:43:26 +00:00
|
|
|
ppmd_count++;
|
2013-02-17 16:31:29 +00:00
|
|
|
#ifdef ENABLE_PC_LIBBSC
|
2012-11-04 15:43:26 +00:00
|
|
|
}
|
2013-02-17 16:31:29 +00:00
|
|
|
#endif
|
2012-05-28 14:49:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-12-09 04:45:06 +00:00
|
|
|
adapt_decompress(void *src, uint64_t srclen, void *dst,
|
2013-11-08 18:20:28 +00:00
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, int btype, void *data)
|
2012-05-28 14:49:29 +00:00
|
|
|
{
|
|
|
|
struct adapt_data *adat = (struct adapt_data *)(data);
|
2012-08-10 05:17:11 +00:00
|
|
|
uchar_t cmp_flags;
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2013-11-15 15:36:23 +00:00
|
|
|
cmp_flags = CHDR_ALGO(chdr);
|
|
|
|
|
|
|
|
if (cmp_flags == ADAPT_COMPRESS_LZ4) {
|
2013-11-22 15:14:26 +00:00
|
|
|
return (lz4_decompress(src, srclen, dst, dstlen, 1, chdr, btype, adat->lz4_data));
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2013-11-15 15:36:23 +00:00
|
|
|
} else if (cmp_flags == ADAPT_COMPRESS_LZMA) {
|
2013-11-08 18:20:28 +00:00
|
|
|
return (lzma_decompress(src, srclen, dst, dstlen, level, chdr, btype, adat->lzma_data));
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2013-02-17 15:35:40 +00:00
|
|
|
} else if (cmp_flags == ADAPT_COMPRESS_BZIP2) {
|
2013-11-08 18:20:28 +00:00
|
|
|
return (bzip2_decompress(src, srclen, dst, dstlen, level, chdr, btype, NULL));
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2013-02-17 15:35:40 +00:00
|
|
|
} else if (cmp_flags == ADAPT_COMPRESS_PPMD) {
|
2013-12-27 18:19:47 +00:00
|
|
|
int rv;
|
|
|
|
rv = ppmd_alloc(adat->ppmd_data);
|
|
|
|
if (rv < 0)
|
|
|
|
return (rv);
|
|
|
|
rv = ppmd_decompress(src, srclen, dst, dstlen, level, chdr, btype, adat->ppmd_data);
|
|
|
|
ppmd_free(adat->ppmd_data);
|
|
|
|
return (rv);
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2013-02-17 15:35:40 +00:00
|
|
|
} else if (cmp_flags == ADAPT_COMPRESS_BSC) {
|
2012-11-26 14:51:03 +00:00
|
|
|
#ifdef ENABLE_PC_LIBBSC
|
2013-11-08 18:20:28 +00:00
|
|
|
return (libbsc_decompress(src, srclen, dst, dstlen, level, chdr, btype, adat->bsc_data));
|
2012-11-26 14:51:03 +00:00
|
|
|
#else
|
2013-10-02 15:15:33 +00:00
|
|
|
log_msg(LOG_ERR, 0, "Cannot decompress chunk. Libbsc support not present.\n");
|
2012-11-26 14:51:03 +00:00
|
|
|
return (-1);
|
|
|
|
#endif
|
2012-11-04 15:43:26 +00:00
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
} else {
|
2013-10-02 15:15:33 +00:00
|
|
|
log_msg(LOG_ERR, 0, "Unrecognized compression mode: %d, file corrupt.\n", cmp_flags);
|
2012-05-28 14:49:29 +00:00
|
|
|
}
|
|
|
|
return (-1);
|
|
|
|
}
|