Add block compat interface - 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 dd4146c8d47e62b50f3806ee6e16588bf0d83e02
 (DIR) parent 42901e4da4f38681c9cb7defdcce92d5f63b38a6
 (HTM) Author: sin <sin@2f30.org>
       Date:   Fri, 26 Apr 2019 10:44:04 +0100
       
       Add block compat interface
       
       fallocate(2) is not available on non-linux systems.
       
       Diffstat:
         M Makefile                            |       1 +
         A bcompat.c                           |      19 +++++++++++++++++++
         M block.h                             |       3 +++
         M bstorage.c                          |       5 +----
         M config.mk                           |       2 +-
       
       5 files changed, 25 insertions(+), 5 deletions(-)
       ---
 (DIR) diff --git a/Makefile b/Makefile
       @@ -15,6 +15,7 @@ HDR = \
                tree.h \
        
        COMMOBJ = \
       +        bcompat.o \
                bcompress.o \
                blake2b-ref.o \
                block.o \
 (DIR) diff --git a/bcompat.c b/bcompat.c
       @@ -0,0 +1,19 @@
       +#ifdef __linux__
       +#define _GNU_SOURCE
       +#include <fcntl.h>
       +
       +int
       +punchhole(int fd, off_t offset, off_t len)
       +{
       +        int mode;
       +
       +        mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
       +        return fallocate(fd, mode, offset, len);
       +}
       +#else
       +int
       +punchhole(int fd, off_t offset, off_t len)
       +{
       +        return -1;
       +}
       +#endif
 (DIR) diff --git a/block.h b/block.h
       @@ -34,6 +34,9 @@ extern int bsync(struct bctx *bctx);
        extern int bclose(struct bctx *bctx);
        struct bparam *bparamdef(void);
        
       +/* bcompat.c */
       +extern int punchhole(int fd, off_t offset, off_t len);
       +
        /* bcompress.c */
        extern struct bops *bcompressops(void);
        
 (DIR) diff --git a/bstorage.c b/bstorage.c
       @@ -552,10 +552,7 @@ bsrm(struct bctx *bctx, unsigned char *md)
                }
        
                if (bd->refcnt == 0) {
       -                int mode;
       -
       -                mode = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
       -                if (fallocate(sctx->fd, mode, bd->offset, bd->size) < 0) {
       +                if (punchhole(sctx->fd, bd->offset, bd->size) < 0) {
                                /*
                                 * Filesystem does not support hole punching.
                                 * Try to recover the block descriptor so we don't
 (DIR) diff --git a/config.mk b/config.mk
       @@ -2,5 +2,5 @@ VERSION = 1.0
        PREFIX = /usr/local
        MANPREFIX = $(PREFIX)/man
        
       -CPPFLAGS = -I/usr/local/include -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
       +CPPFLAGS = -I/usr/local/include -D_FILE_OFFSET_BITS=64
        LDFLAGS = -L/usr/local/lib