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-06-29 12:53:55 +00:00
|
|
|
#include <rabin_polynomial.h>
|
|
|
|
|
2012-05-28 14:49:29 +00:00
|
|
|
#define CHDR_SZ 1
|
|
|
|
#define ALGO_SZ 8
|
|
|
|
#define MIN_CHUNK 2048
|
2012-06-29 12:53:55 +00:00
|
|
|
#define VERSION 2
|
|
|
|
#define FLAG_DEDUP 1
|
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
|
|
|
|
#define COMPRESS_LZMA 1
|
|
|
|
#define COMPRESS_BZIP2 2
|
|
|
|
#define COMPRESS_PPMD 3
|
2012-06-29 12:53:55 +00:00
|
|
|
#define CHUNK_FLAG_DEDUP 2
|
2012-05-28 14:49:29 +00:00
|
|
|
#define COMP_EXTN ".pz"
|
|
|
|
|
|
|
|
extern uint64_t lzma_crc64(const uint8_t *buf, size_t size, uint64_t crc);
|
|
|
|
extern uint64_t lzma_crc64_8bchk(const uint8_t *buf, size_t size,
|
|
|
|
uint64_t crc, uint64_t *cnt);
|
|
|
|
|
|
|
|
extern int zlib_compress(void *src, size_t srclen, void *dst,
|
2012-07-01 16:14:02 +00:00
|
|
|
size_t *destlen, int level, uchar_t chdr, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int lzma_compress(void *src, size_t srclen, void *dst,
|
2012-07-01 16:14:02 +00:00
|
|
|
size_t *destlen, int level, uchar_t chdr, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int bzip2_compress(void *src, size_t srclen, void *dst,
|
2012-07-01 16:14:02 +00:00
|
|
|
size_t *destlen, int level, uchar_t chdr, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int adapt_compress(void *src, size_t srclen, void *dst,
|
2012-07-01 16:14:02 +00:00
|
|
|
size_t *dstlen, int level, uchar_t chdr, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int ppmd_compress(void *src, size_t srclen, void *dst,
|
2012-07-01 16:14:02 +00:00
|
|
|
size_t *dstlen, int level, uchar_t chdr, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
|
|
|
|
extern int zlib_decompress(void *src, size_t srclen, void *dst,
|
2012-07-01 16:14:02 +00:00
|
|
|
size_t *dstlen, int level, uchar_t chdr, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int lzma_decompress(void *src, size_t srclen, void *dst,
|
2012-07-01 16:14:02 +00:00
|
|
|
size_t *dstlen, int level, uchar_t chdr, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int bzip2_decompress(void *src, size_t srclen, void *dst,
|
2012-07-01 16:14:02 +00:00
|
|
|
size_t *dstlen, int level, uchar_t chdr, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int adapt_decompress(void *src, size_t srclen, void *dst,
|
2012-07-01 16:14:02 +00:00
|
|
|
size_t *dstlen, int level, uchar_t chdr, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
extern int ppmd_decompress(void *src, size_t srclen, void *dst,
|
2012-07-01 16:14:02 +00:00
|
|
|
size_t *dstlen, int level, uchar_t chdr, void *data);
|
2012-05-28 14:49:29 +00:00
|
|
|
|
|
|
|
extern int adapt_init(void **data, int *level, ssize_t chunksize);
|
|
|
|
extern int adapt2_init(void **data, int *level, ssize_t chunksize);
|
|
|
|
extern int lzma_init(void **data, int *level, ssize_t chunksize);
|
|
|
|
extern int ppmd_init(void **data, int *level, ssize_t chunksize);
|
|
|
|
extern int bzip2_init(void **data, int *level, ssize_t chunksize);
|
|
|
|
extern int zlib_init(void **data, int *level, ssize_t chunksize);
|
2012-05-31 16:06:33 +00:00
|
|
|
|
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-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-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-06-29 12:53:55 +00:00
|
|
|
rabin_context_t *rctx;
|
2012-05-28 14:49:29 +00:00
|
|
|
ssize_t rbytes;
|
|
|
|
ssize_t chunksize;
|
|
|
|
ssize_t len_cmp;
|
|
|
|
uint64_t crc64;
|
|
|
|
int level;
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|