From bde917c8e90b7c98264172c1c0b3f210f44e7fc4 Mon Sep 17 00:00:00 2001 From: Moinak Ghosh Date: Fri, 10 Aug 2012 10:47:11 +0530 Subject: [PATCH] Fix handling of compression flags in adaptive mode Fix error handling when chunk size is too small for dedupe Bump version to 0.6 --- adaptive_compress.c | 10 +++++----- main.c | 16 ++++++++++++---- pcompress.h | 11 ++++++++--- rabin/rabin_polynomial.c | 2 +- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/adaptive_compress.c b/adaptive_compress.c index afe2c9a..20c6672 100644 --- a/adaptive_compress.c +++ b/adaptive_compress.c @@ -197,17 +197,17 @@ adapt_decompress(void *src, size_t srclen, void *dst, size_t *dstlen, int level, uchar_t chdr, void *data) { struct adapt_data *adat = (struct adapt_data *)(data); - uchar_t HDR; + uchar_t cmp_flags; - HDR = chdr; + cmp_flags = (chdr>>4) & CHDR_ALGO_MASK; - if (HDR & (COMPRESS_LZMA << 4)) { + if (cmp_flags == COMPRESS_LZMA) { return (lzma_decompress(src, srclen, dst, dstlen, level, chdr, adat->lzma_data)); - } else if (HDR & (COMPRESS_BZIP2 << 4)) { + } else if (cmp_flags == COMPRESS_BZIP2) { return (bzip2_decompress(src, srclen, dst, dstlen, level, chdr, NULL)); - } else if (HDR & (COMPRESS_PPMD << 4)) { + } else if (cmp_flags == COMPRESS_PPMD) { return (ppmd_decompress(src, srclen, dst, dstlen, level, chdr, adat->ppmd_data)); } else { diff --git a/main.c b/main.c index c1298a6..f64c70c 100644 --- a/main.c +++ b/main.c @@ -467,11 +467,15 @@ start_decompress(const char *filename, const char *to_filename) UNCOMP_BAIL; } } - if (enable_rabin_scan) + if (enable_rabin_scan) { tdat->rctx = create_rabin_context(chunksize, compressed_chunksize, algo, enable_delta_encode); - else + if (tdat->rctx == NULL) { + UNCOMP_BAIL; + } + } else { tdat->rctx = NULL; + } if (pthread_create(&(tdat->thr), NULL, perform_decompress, (void *)tdat) != 0) { perror("Error in thread creation: "); @@ -981,11 +985,15 @@ start_compress(const char *filename, uint64_t chunksize, int level) COMP_BAIL; } } - if (enable_rabin_scan) + if (enable_rabin_scan) { tdat->rctx = create_rabin_context(chunksize, compressed_chunksize, algo, enable_delta_encode); - else + if (tdat->rctx == NULL) { + COMP_BAIL; + } + } else { tdat->rctx = NULL; + } if (pthread_create(&(tdat->thr), NULL, perform_compress, (void *)tdat) != 0) { diff --git a/pcompress.h b/pcompress.h index b1bfc0f..0e55b30 100644 --- a/pcompress.h +++ b/pcompress.h @@ -39,18 +39,23 @@ extern "C" { #define MIN_CHUNK 2048 #define VERSION 2 #define FLAG_DEDUP 1 -#define UTILITY_VERSION 0.5 +#define UTILITY_VERSION 0.6 #define COMPRESSED 1 #define UNCOMPRESSED 0 #define CHSIZE_MASK 0x80 #define BZIP2_A_NUM 16 #define LZMA_A_NUM 32 +#define CHUNK_FLAG_DEDUP 2 +#define COMP_EXTN ".pz" + +/* + * lower 3 bits in higher nibble indicate compression algorithm. + */ #define COMPRESS_LZMA 1 #define COMPRESS_BZIP2 2 #define COMPRESS_PPMD 3 -#define CHUNK_FLAG_DEDUP 2 -#define COMP_EXTN ".pz" +#define CHDR_ALGO_MASK 7 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, diff --git a/rabin/rabin_polynomial.c b/rabin/rabin_polynomial.c index 2d3b6ce..23b1c79 100755 --- a/rabin/rabin_polynomial.c +++ b/rabin/rabin_polynomial.c @@ -105,7 +105,7 @@ create_rabin_context(uint64_t chunksize, uint64_t real_chunksize, const char *al } if (chunksize < RAB_MIN_CHUNK_SIZE) { - fprintf(stderr, "Minimum chunk size for Dedup must be %l bytes\n", + fprintf(stderr, "Minimum chunk size for Dedup must be %llu bytes\n", RAB_MIN_CHUNK_SIZE); return (NULL); }