2012-07-22 18:45:08 +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-07-22 18:45:08 +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
|
|
|
|
* version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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-07-22 18:45:08 +00:00
|
|
|
* moinakg@belenix.org, http://moinakg.wordpress.com/
|
2014-07-26 09:58:40 +00:00
|
|
|
*
|
2012-07-22 18:45:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <strings.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <utils.h>
|
|
|
|
#include <pcompress.h>
|
|
|
|
#include <lzfx.h>
|
2012-07-23 16:13:12 +00:00
|
|
|
#include <allocator.h>
|
|
|
|
|
|
|
|
struct lzfx_params {
|
|
|
|
uint32_t htab_bits;
|
|
|
|
};
|
2012-07-22 18:45:08 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
lz_fx_stats(int show)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-04 18:39:47 +00:00
|
|
|
void
|
2012-12-27 17:36:48 +00:00
|
|
|
lz_fx_props(algo_props_t *data, int level, uint64_t chunksize) {
|
2012-12-13 15:48:16 +00:00
|
|
|
data->delta2_span = 50;
|
2013-01-14 07:50:07 +00:00
|
|
|
data->deltac_min_distance = FOURM;
|
2012-12-04 18:39:47 +00:00
|
|
|
}
|
|
|
|
|
2012-07-22 18:45:08 +00:00
|
|
|
int
|
2012-12-27 17:36:48 +00:00
|
|
|
lz_fx_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-07-22 18:45:08 +00:00
|
|
|
{
|
2012-07-23 16:13:12 +00:00
|
|
|
struct lzfx_params *lzdat;
|
|
|
|
int lev;
|
|
|
|
|
2012-07-22 18:45:08 +00:00
|
|
|
if (chunksize > UINT_MAX) {
|
2013-10-02 15:15:33 +00:00
|
|
|
log_msg(LOG_ERR, 0, "Chunk size too big for LZFX.\n");
|
2012-07-22 18:45:08 +00:00
|
|
|
return (1);
|
|
|
|
}
|
2012-12-27 17:36:48 +00:00
|
|
|
lzdat = (struct lzfx_params *)slab_alloc(NULL, sizeof (struct lzfx_params));
|
2012-07-23 16:13:12 +00:00
|
|
|
|
|
|
|
lev = *level;
|
|
|
|
if (lev > 5) lev = 5;
|
|
|
|
lzdat->htab_bits = 16 + (lev-1);
|
|
|
|
*data = lzdat;
|
|
|
|
|
|
|
|
if (*level > 9) *level = 9;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lz_fx_deinit(void **data)
|
|
|
|
{
|
|
|
|
struct lzfx_params *lzdat = (struct lzfx_params *)(*data);
|
|
|
|
|
|
|
|
if (lzdat) {
|
|
|
|
slab_free(NULL, lzdat);
|
|
|
|
}
|
|
|
|
*data = NULL;
|
2012-07-22 18:45:08 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-07-25 15:37:36 +00:00
|
|
|
static void
|
2012-07-22 18:45:08 +00:00
|
|
|
lz_fx_err(int err)
|
|
|
|
{
|
|
|
|
switch (err) {
|
|
|
|
case LZFX_ESIZE:
|
2013-10-02 15:15:33 +00:00
|
|
|
log_msg(LOG_ERR, 0, "LZFX: Output buffer too small.\n");
|
2012-07-22 18:45:08 +00:00
|
|
|
break;
|
|
|
|
case LZFX_ECORRUPT:
|
2013-10-02 15:15:33 +00:00
|
|
|
log_msg(LOG_ERR, 0, "LZFX: Corrupt data for decompression.\n");
|
2012-07-22 18:45:08 +00:00
|
|
|
break;
|
|
|
|
case LZFX_EARGS:
|
2013-10-02 15:15:33 +00:00
|
|
|
log_msg(LOG_ERR, 0, "LZFX: Invalid arguments.\n");
|
2012-07-22 18:45:08 +00:00
|
|
|
break;
|
2012-07-23 16:13:12 +00:00
|
|
|
case LZFX_ENOMEM:
|
2013-10-02 15:15:33 +00:00
|
|
|
log_msg(LOG_ERR, 0, "LZFX: Out of memory when allocating hashtable.\n");
|
2012-07-23 16:13:12 +00:00
|
|
|
break;
|
2012-07-22 18:45:08 +00:00
|
|
|
default:
|
2013-10-02 15:15:33 +00:00
|
|
|
log_msg(LOG_ERR, 0, "LZFX: Unknown error code: %d\n", err);
|
2012-07-22 18:45:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-12-09 04:45:06 +00:00
|
|
|
lz_fx_compress(void *src, uint64_t srclen, void *dst, uint64_t *dstlen,
|
2013-11-08 18:20:28 +00:00
|
|
|
int level, uchar_t chdr, int btype, void *data)
|
2012-07-22 18:45:08 +00:00
|
|
|
{
|
|
|
|
int rv;
|
2012-07-23 16:13:12 +00:00
|
|
|
struct lzfx_params *lzdat = (struct lzfx_params *)data;
|
2012-07-22 18:45:08 +00:00
|
|
|
unsigned int _srclen = srclen;
|
|
|
|
unsigned int _dstlen = *dstlen;
|
|
|
|
|
2013-11-09 11:16:19 +00:00
|
|
|
/*
|
|
|
|
* Ignore compressed data in fast modes.
|
|
|
|
*/
|
|
|
|
if (level < 7 && PC_TYPE(btype) == TYPE_COMPRESSED)
|
|
|
|
return (-1);
|
|
|
|
|
2012-07-23 16:13:12 +00:00
|
|
|
rv = lzfx_compress(src, _srclen, dst, &_dstlen, lzdat->htab_bits);
|
2012-07-31 15:37:35 +00:00
|
|
|
if (rv != 0) {
|
|
|
|
if (rv != LZFX_ESIZE)
|
|
|
|
lz_fx_err(rv);
|
2012-07-22 18:45:08 +00:00
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
*dstlen = _dstlen;
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-12-09 04:45:06 +00:00
|
|
|
lz_fx_decompress(void *src, uint64_t srclen, void *dst, uint64_t *dstlen,
|
2013-11-08 18:20:28 +00:00
|
|
|
int level, uchar_t chdr, int btype, void *data)
|
2012-07-22 18:45:08 +00:00
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
unsigned int _srclen = srclen;
|
|
|
|
unsigned int _dstlen = *dstlen;
|
|
|
|
|
|
|
|
rv = lzfx_decompress(src, _srclen, dst, &_dstlen);
|
2012-07-31 15:37:35 +00:00
|
|
|
if (rv != 0) {
|
2012-07-22 18:45:08 +00:00
|
|
|
lz_fx_err(rv);
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
*dstlen = _dstlen;
|
|
|
|
return (0);
|
|
|
|
}
|