Add support for snappy compressor/decompressor - dedup - deduplicating backup program
 (HTM) git clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 573a013a9738a43524c0e5994245353b8bd4b564
 (DIR) parent 2c9dc65a8287e67d92b8ce1aa87d205243aa9eeb
 (HTM) Author: sin <sin@2f30.org>
       Date:   Wed, 10 Apr 2019 13:16:48 +0100
       
       Add support for snappy compressor/decompressor
       
       Diffstat:
         M CHANGELOG                           |       1 +
         M Makefile                            |       2 +-
         M README                              |       1 +
         M compress.c                          |      61 +++++++++++++++++++++++++++++++
         M dedup.1                             |       4 ++--
         M dedup.h                             |       1 +
       
       6 files changed, 67 insertions(+), 3 deletions(-)
       ---
 (DIR) diff --git a/CHANGELOG b/CHANGELOG
       @@ -4,6 +4,7 @@
        ### Added
        - Support for blake2bp, which is parallel variant of blake2b.
        - Support for blake2s and blake2sp.
       +- Support for snappy compressor/decompressor.
        
        ## [0.9] - 2019-03-26
        ### Added
 (DIR) diff --git a/Makefile b/Makefile
       @@ -55,7 +55,7 @@ DISTFILES = \
        CFLAGS = -g -O2 -Wall $(OPENMPCFLAGS)
        CPPFLAGS = -I/usr/local/include -D_FILE_OFFSET_BITS=64
        LDFLAGS = -L/usr/local/lib
       -LDLIBS = -llz4 $(OPENMPLDLIBS)
       +LDLIBS = -llz4 -lsnappy $(OPENMPLDLIBS)
        
        all: $(BIN)
        
 (DIR) diff --git a/README b/README
       @@ -41,6 +41,7 @@ Dependencies
        ============
        
          - liblz4
       +  - snappy
          - libomp (optional, see config.mk)
        
        Contact
 (DIR) diff --git a/compress.c b/compress.c
       @@ -6,6 +6,7 @@
        #include <strings.h>
        
        #include <lz4.h>
       +#include <snappy-c.h>
        
        #include "blake2.h"
        #include "dedup.h"
       @@ -26,6 +27,14 @@ static size_t lz4_decompr(struct compr_ctx *ctx, const void *in, void *out,
                                  size_t insize, size_t outsize);
        static int lz4_final(struct compr_ctx *ctx);
        
       +static int snappy_init(struct compr_ctx *ctx);
       +static size_t snappy_size(struct compr_ctx *ctx, size_t n);
       +static size_t snappy_compr(struct compr_ctx *ctx, const void *in, void *out,
       +                        size_t insize, size_t outsize);
       +static size_t snappy_decompr(struct compr_ctx *ctx, const void *in, void *out,
       +                          size_t insize, size_t outsize);
       +static int snappy_final(struct compr_ctx *ctx);
       +
        static struct compr_ops {
                int (*init)(struct compr_ctx *ctx);
                size_t (*size)(struct compr_ctx *ctx, size_t n);
       @@ -49,6 +58,13 @@ static struct compr_ops {
                        .decompr = lz4_decompr,
                        .final = lz4_final,
                },
       +        {
       +                .init = snappy_init,
       +                .size = snappy_size,
       +                .compr = snappy_compr,
       +                .decompr = snappy_decompr,
       +                .final = snappy_final,
       +        },
        };
        
        static struct algomap {
       @@ -57,6 +73,7 @@ static struct algomap {
        } algomap[] = {
                { .name = "none", .type = COMPR_NONE },
                { .name = "lz4", .type = COMPR_LZ4 },
       +        { .name = "snappy", .type = COMPR_SNAPPY },
                { .name = NULL, },
        };
        
       @@ -138,6 +155,50 @@ lz4_final(struct compr_ctx *ctx)
                return 0;
        }
        
       +static int
       +snappy_init(struct compr_ctx *ctx)
       +{
       +        return 0;
       +}
       +
       +static size_t
       +snappy_size(struct compr_ctx *ctx, size_t n)
       +{
       +        return snappy_max_compressed_length(n);
       +}
       +
       +static size_t
       +snappy_compr(struct compr_ctx *ctx, const void *in, void *out,
       +          size_t insize, size_t outsize)
       +{
       +        size_t n = outsize;
       +        snappy_status ret;
       +
       +        ret = snappy_compress((char *)in, insize, (char *)out, &n);
       +        if (ret != SNAPPY_OK)
       +                errx(1, "snappy_compress failed: %d", ret);
       +        return n;
       +}
       +
       +static size_t
       +snappy_decompr(struct compr_ctx *ctx, const void *in, void *out,
       +            size_t insize, size_t outsize)
       +{
       +        size_t n = outsize;
       +        snappy_status ret;
       +
       +        ret = snappy_uncompress((char *)in, insize, (char *)out, &n);
       +        if (ret != SNAPPY_OK)
       +                errx(1, "snappy_uncompress failed: %d", ret);
       +        return n;
       +}
       +
       +static int
       +snappy_final(struct compr_ctx *ctx)
       +{
       +        return 0;
       +}
       +
        int
        compr_init(struct compr_ctx *ctx, int type)
        {
 (DIR) diff --git a/dedup.1 b/dedup.1
       @@ -1,4 +1,4 @@
       -.Dd April 7, 2019
       +.Dd April 10, 2019
        .Dt DEDUP 1
        .Os
        .Sh NAME
       @@ -38,7 +38,7 @@ By default blake2b is used.
        .It Fl Z Ar compressor
        The compressor function used to compress the blocks
        in the store.
       -The supported compressor functions are none and lz4.
       +The supported compressor functions are none, lz4 and snappy.
        This flag only has an effect when initializing the repository.
        By default lz4 is used.
        .It Fl c
 (DIR) diff --git a/dedup.h b/dedup.h
       @@ -30,6 +30,7 @@
        enum compr_algo {
                COMPR_NONE,
                COMPR_LZ4,
       +        COMPR_SNAPPY,
                NR_COMPRS,
        };