dedup

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

commit a2ee78a3a3866e2ef605ca45263c14079c808d56
parent b30db499a59ec215edb9a96f4b0d7fd517dab34b
Author: sin <sin@2f30.org>
Date:   Fri,  3 May 2019 15:29:26 +0100

Set error closer to where it happened

Diffstat:
Mbstorage.c | 28++++++++++++++--------------
1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/bstorage.c b/bstorage.c @@ -135,8 +135,10 @@ unpackbhdr(int fd, struct bhdr *bhdr) unsigned char buf[BHDRSIZE]; int n; - if (xread(fd, buf, sizeof(buf)) != sizeof(buf)) - return -1; + if (xread(fd, buf, sizeof(buf)) != sizeof(buf)) { + bseterr("failed to read block header"); + return -1; + } n = unpack(buf, "'16qq", bhdr->magic, @@ -160,8 +162,10 @@ packbhdr(int fd, struct bhdr *bhdr) bhdr->nbd); assert(n == BHDRSIZE); - if (xwrite(fd, buf, n) != n) + if (xwrite(fd, buf, n) != n) { + bseterr("failed to write block header"); return -1; + } return n; } @@ -173,8 +177,10 @@ unpackbd(int fd, struct bd *bd) char fmt[BUFSIZ]; int n; - if (xread(fd, buf, sizeof(buf)) != sizeof(buf)) + if (xread(fd, buf, sizeof(buf)) != sizeof(buf)) { + bseterr("failed to read block descriptor"); return -1; + } snprintf(fmt, sizeof(fmt), "s'6qqq'%d", MDSIZE); n = unpack(buf, fmt, @@ -207,8 +213,10 @@ packbd(int fd, struct bd *bd) bd->md); assert(n == BDSIZE); - if (xwrite(fd, buf, n) != n) + if (xwrite(fd, buf, n) != n) { + bseterr("failed to write block descriptor"); return -1; + } return n; } @@ -226,7 +234,6 @@ loadbd(struct sctx *sctx) if (unpackbd(sctx->fd, bd) < 0) { free(bd); - bseterr("failed to unpack block descriptor"); return -1; } @@ -355,7 +362,6 @@ bscreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) if (packbhdr(fd, bhdr) < 0) { free(sctx); close(fd); - bseterr("failed to write block header entry"); return -1; } return 0; @@ -408,7 +414,6 @@ bsopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) if (unpackbhdr(fd, bhdr) < 0) { free(sctx); close(fd); - bseterr("failed to read block header entry"); return -1; } @@ -508,7 +513,6 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) bd->refcnt++; if (packbd(sctx->fd, bd) < 0) { bd->refcnt--; - bseterr("failed to write block descriptor"); return -1; } @@ -538,7 +542,6 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) /* Write block descriptor to storage file */ if (packbd(sctx->fd, bd) < 0) { free(bd); - bseterr("failed to write block descriptor"); return -1; } @@ -625,7 +628,6 @@ bsrm(struct bctx *bctx, unsigned char *md) bd->refcnt--; if (packbd(sctx->fd, bd) < 0) { bd->refcnt++; - bseterr("failed to write block descriptor"); return -1; } @@ -744,10 +746,8 @@ bssync(struct bctx *bctx) return -1; } bhdr = &sctx->bhdr; - if (packbhdr(sctx->fd, bhdr) < 0) { - bseterr("failed to write block header"); + if (packbhdr(sctx->fd, bhdr) < 0) return -1; - } fsync(sctx->fd); return 0; }