dedup

deduplicating backup program
git clone git://git.2f30.org/dedup
Log | Files | Refs | README | LICENSE

commit dd4146c8d47e62b50f3806ee6e16588bf0d83e02
parent 42901e4da4f38681c9cb7defdcce92d5f63b38a6
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:
MMakefile | 1+
Abcompat.c | 19+++++++++++++++++++
Mblock.h | 3+++
Mbstorage.c | 5+----
Mconfig.mk | 2+-
5 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile @@ -15,6 +15,7 @@ HDR = \ tree.h \ COMMOBJ = \ + bcompat.o \ bcompress.o \ blake2b-ref.o \ block.o \ 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 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); 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 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