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.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Moinak Ghosh. All rights reserved.
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* moinakg@belenix.org, http://moinakg.wordpress.com/
|
|
|
|
*
|
|
|
|
* This program includes partly-modified public domain source
|
|
|
|
* code from the LZMA SDK: http://www.7-zip.org/sdk.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _PCOMPRESS_H
|
|
|
|
#define _PCOMPRESS_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <semaphore.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-09-02 15:10:32 +00:00
|
|
|
#include <rabin_dedup.h>
|
2012-10-17 18:02:35 +00:00
|
|
|
#include <crypto_utils.h>
|
2012-06-29 12:53:55 +00:00
|
|
|
|
2012-08-31 17:06:06 +00:00
|
|
|
#define CHUNK_FLAG_SZ 1
|
2012-05-28 14:49:29 +00:00
|
|
|
#define ALGO_SZ 8
|
|
|
|
#define MIN_CHUNK 2048
|
2013-02-24 14:35:16 +00:00
|
|
|
#define VERSION 7
|
2012-06-29 12:53:55 +00:00
|
|
|
#define FLAG_DEDUP 1
|
2012-10-15 06:40:00 +00:00
|
|
|
#define FLAG_DEDUP_FIXED 2
|
|
|
|
#define FLAG_SINGLE_CHUNK 4
|
2013-01-29 16:12:54 +00:00
|
|
|
#define UTILITY_VERSION "1.3.0"
|
2012-10-15 06:40:00 +00:00
|
|
|
#define MASK_CRYPTO_ALG 0x30
|
2012-10-17 18:02:35 +00:00
|
|
|
#define MAX_LEVEL 14
|
2012-05-28 14:49:29 +00:00
|
|
|
|
|
|
|
#define COMPRESSED 1
|
|
|
|
#define UNCOMPRESSED 0
|
|
|
|
#define CHSIZE_MASK 0x80
|
|
|
|
#define BZIP2_A_NUM 16
|
|
|
|
#define LZMA_A_NUM 32
|
2012-08-10 05:17:11 +00:00
|
|
|
#define CHUNK_FLAG_DEDUP 2
|
2012-08-23 17:28:44 +00:00
|
|
|
#define CHUNK_FLAG_PREPROC 4
|
2012-08-10 05:17:11 +00:00
|
|
|
#define COMP_EXTN ".pz"
|
|
|
|
|
2012-08-23 17:28:44 +00:00
|
|
|
#define PREPROC_TYPE_LZP 1
|
2012-12-04 18:39:47 +00:00
|
|
|
#define PREPROC_TYPE_DELTA2 2
|
2012-08-23 17:28:44 +00:00
|
|
|
#define PREPROC_COMPRESSED 128
|
|
|
|
|
2012-08-10 05:17:11 +00:00
|
|
|
/*
|
2012-08-31 17:06:06 +00:00
|
|
|
* Sizes of chunk header components.
|
|
|
|
*/
|
|
|
|
#define COMPRESSED_CHUNKSZ (sizeof (uint64_t))
|
|
|
|
#define ORIGINAL_CHUNKSZ (sizeof (uint64_t))
|
|
|
|
#define CHUNK_HDR_SZ (COMPRESSED_CHUNKSZ + cksum_bytes + ORIGINAL_CHUNKSZ + CHUNK_FLAG_SZ)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* lower 3 bits in higher nibble indicate chunk compression algorithm
|
|
|
|
* in adaptive modes.
|
2012-08-10 05:17:11 +00:00
|
|
|
*/
|
2013-02-17 15:35:40 +00:00
|
|
|
#define ADAPT_COMPRESS_NONE 0
|
|
|
|
#define ADAPT_COMPRESS_LZMA 1
|
|
|
|
#define ADAPT_COMPRESS_BZIP2 2
|
|
|
|
#define ADAPT_COMPRESS_PPMD 3
|
|
|
|
#define ADAPT_COMPRESS_BSC 4
|
2012-08-10 05:17:11 +00:00
|
|
|
#define CHDR_ALGO_MASK 7
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2012-12-27 17:36:48 +00:00
|
|
|
extern uint32_t zlib_buf_extra(uint64_t buflen);
|
|
|
|
extern int lz4_buf_extra(uint64_t buflen);
|
2012-12-09 04:45:06 +00:00
|
|
|
|
|
|
|
extern int zlib_compress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *destlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int lzma_compress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *destlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int bzip2_compress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *destlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int adapt_compress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int ppmd_compress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int lz_fx_compress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int lz4_compress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int none_compress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
|
|
|
|
extern int zlib_decompress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int lzma_decompress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int bzip2_decompress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int adapt_decompress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int ppmd_decompress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int lz_fx_decompress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int lz4_decompress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int none_decompress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
|
2012-12-27 17:36:48 +00:00
|
|
|
extern int 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-12-27 17:36:48 +00:00
|
|
|
extern int 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-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-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-12-27 17:36:48 +00:00
|
|
|
extern int bzip2_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-12-27 17:36:48 +00:00
|
|
|
extern int zlib_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-12-27 17:36:48 +00:00
|
|
|
extern int 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-12-27 17:36:48 +00:00
|
|
|
extern int lz4_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-12-27 17:36:48 +00:00
|
|
|
extern int none_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-08-18 04:50:52 +00:00
|
|
|
|
2012-12-27 17:36:48 +00:00
|
|
|
extern void lzma_props(algo_props_t *data, int level, uint64_t chunksize);
|
|
|
|
extern void lzma_mt_props(algo_props_t *data, int level, uint64_t chunksize);
|
|
|
|
extern void lz4_props(algo_props_t *data, int level, uint64_t chunksize);
|
|
|
|
extern void zlib_props(algo_props_t *data, int level, uint64_t chunksize);
|
|
|
|
extern void ppmd_props(algo_props_t *data, int level, uint64_t chunksize);
|
|
|
|
extern void lz_fx_props(algo_props_t *data, int level, uint64_t chunksize);
|
|
|
|
extern void bzip2_props(algo_props_t *data, int level, uint64_t chunksize);
|
|
|
|
extern void adapt_props(algo_props_t *data, int level, uint64_t chunksize);
|
|
|
|
extern void none_props(algo_props_t *data, int level, uint64_t chunksize);
|
2012-05-31 16:06:33 +00:00
|
|
|
|
2012-08-08 17:10:58 +00:00
|
|
|
extern int zlib_deinit(void **data);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int adapt_deinit(void **data);
|
|
|
|
extern int lzma_deinit(void **data);
|
|
|
|
extern int ppmd_deinit(void **data);
|
2012-07-23 16:13:12 +00:00
|
|
|
extern int lz_fx_deinit(void **data);
|
2012-07-25 15:37:36 +00:00
|
|
|
extern int lz4_deinit(void **data);
|
2012-08-05 17:05:51 +00:00
|
|
|
extern int none_deinit(void **data);
|
2012-05-28 14:49:29 +00:00
|
|
|
|
2012-05-31 16:06:33 +00:00
|
|
|
extern void adapt_stats(int show);
|
|
|
|
extern void ppmd_stats(int show);
|
|
|
|
extern void lzma_stats(int show);
|
|
|
|
extern void bzip2_stats(int show);
|
|
|
|
extern void zlib_stats(int show);
|
2012-07-22 18:45:08 +00:00
|
|
|
extern void lz_fx_stats(int show);
|
2012-07-25 15:37:36 +00:00
|
|
|
extern void lz4_stats(int show);
|
2012-08-05 17:05:51 +00:00
|
|
|
extern void none_stats(int show);
|
2012-05-31 16:06:33 +00:00
|
|
|
|
2012-08-27 16:21:55 +00:00
|
|
|
#ifdef ENABLE_PC_LIBBSC
|
2012-12-09 04:45:06 +00:00
|
|
|
extern int libbsc_compress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, void *data);
|
|
|
|
extern int libbsc_decompress(void *src, uint64_t srclen, void *dst,
|
|
|
|
uint64_t *dstlen, int level, uchar_t chdr, 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-12-27 17:36:48 +00:00
|
|
|
extern void libbsc_props(algo_props_t *data, int level, uint64_t chunksize);
|
2012-08-27 16:21:55 +00:00
|
|
|
extern int libbsc_deinit(void **data);
|
|
|
|
extern void libbsc_stats(int show);
|
|
|
|
#endif
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
/*
|
|
|
|
* Per-thread data structure for compression and decompression threads.
|
|
|
|
*/
|
|
|
|
struct cmp_data {
|
|
|
|
uchar_t *cmp_seg;
|
|
|
|
uchar_t *compressed_chunk;
|
|
|
|
uchar_t *uncompressed_chunk;
|
2012-09-16 05:42:58 +00:00
|
|
|
dedupe_context_t *rctx;
|
2012-12-27 17:36:48 +00:00
|
|
|
uint64_t rbytes;
|
|
|
|
uint64_t chunksize;
|
|
|
|
uint64_t len_cmp, len_cmp_be;
|
2012-08-31 17:06:06 +00:00
|
|
|
uchar_t checksum[CKSUM_MAX_BYTES];
|
2013-01-26 12:58:13 +00:00
|
|
|
int level, cksum_mt;
|
2012-05-28 14:49:29 +00:00
|
|
|
unsigned int id;
|
|
|
|
compress_func_ptr compress;
|
|
|
|
compress_func_ptr decompress;
|
|
|
|
int cancel;
|
|
|
|
sem_t start_sem;
|
|
|
|
sem_t cmp_done_sem;
|
|
|
|
sem_t write_done_sem;
|
|
|
|
void *data;
|
|
|
|
pthread_t thr;
|
2012-10-18 17:25:41 +00:00
|
|
|
mac_ctx_t chunk_hmac;
|
2012-12-04 18:39:47 +00:00
|
|
|
algo_props_t *props;
|
2012-05-28 14:49:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|