dedup

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

commit 41ef1e9be6c16c307def27c5f9712be313735cac
parent 6650bc506d13a91f409788e350a48b38aaf5f98e
Author: sin <sin@2f30.org>
Date:   Fri,  3 May 2019 15:08:18 +0100

Set error message in snap.c

Diffstat:
Msnap.c | 54++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 42 insertions(+), 12 deletions(-)

diff --git a/snap.c b/snap.c @@ -16,6 +16,7 @@ #include "snap.h" #define NERRBUF 128 + extern ssize_t xread(int, void *, size_t); extern ssize_t xwrite(int, void *, size_t); @@ -39,10 +40,13 @@ loadmd(struct sctx *sctx) struct mdnode *mdnode; mdnode = calloc(1, sizeof(*mdnode)); - if (mdnode == NULL) + if (mdnode == NULL) { + sseterr("out of memory"); return -1; + } if (xread(sctx->fd, mdnode->md, MDSIZE) != MDSIZE) { free(mdnode); + sseterr("failed to read message digest"); return -1; } SLIST_INSERT_HEAD(&sctx->mdhead, mdnode, e); @@ -80,16 +84,21 @@ screat(char *path, int mode, struct sctx **sctx) { int fd; - if (path == NULL || sctx == NULL) + if (path == NULL || sctx == NULL) { + sseterr("invalid params"); return -1; + } fd = open(path, O_RDWR | O_CREAT | O_EXCL, mode); - if (fd < 0) + if (fd < 0) { + sseterr("failed to open"); return -1; + } *sctx = calloc(1, sizeof(**sctx)); if (*sctx == NULL) { close(fd); + sseterr("out of memory"); return -1; } @@ -104,20 +113,27 @@ sopen(char *path, int flags, int mode, struct sctx **sctx) { int fd; - if (path == NULL || sctx == NULL) + if (path == NULL || sctx == NULL) { + sseterr("invalid params"); return -1; + } /* Existing snapshots are immutable */ - if (flags != S_READ) + if (flags != S_READ) { + sseterr("invalid params"); return -1; + } fd = open(path, O_RDONLY, mode); - if (fd < 0) + if (fd < 0) { + sseterr("failed to open"); return -1; + } *sctx = calloc(1, sizeof(**sctx)); if (*sctx == NULL) { close(fd); + sseterr("out of memory"); return -1; } @@ -139,12 +155,16 @@ sput(struct sctx *sctx, unsigned char *md) { struct mdnode *mdnode; - if (sctx == NULL || md == NULL) + if (sctx == NULL || md == NULL) { + sseterr("invalid params"); return -1; + } mdnode = calloc(1, sizeof(*mdnode)); - if (mdnode == NULL) + if (mdnode == NULL) { + sseterr("out of memory"); return -1; + } memcpy(mdnode->md, md, MDSIZE); SLIST_INSERT_HEAD(&sctx->mdhead, mdnode, e); return 0; @@ -155,8 +175,10 @@ sget(struct sctx *sctx, unsigned char *md) { struct mdnode *mdnode; - if (sctx == NULL || md == NULL) + if (sctx == NULL || md == NULL) { + sseterr("invalid params"); return -1; + } mdnode = sctx->mdnext; if (mdnode == NULL) @@ -174,8 +196,10 @@ sget(struct sctx *sctx, unsigned char *md) int srewind(struct sctx *sctx) { - if (sctx == NULL) + if (sctx == NULL) { + sseterr("invalid params"); return -1; + } sctx->mdnext = NULL; return 0; } @@ -185,14 +209,18 @@ ssync(struct sctx *sctx) { struct mdnode *mdnode; - if (sctx == NULL) + if (sctx == NULL) { + sseterr("invalid params"); return -1; + } if (sctx->rdonly) return 0; - if (lseek(sctx->fd, 0, SEEK_SET) < 0) + if (lseek(sctx->fd, 0, SEEK_SET) < 0) { + sseterr("failed to seek on snapshot descriptor"); return -1; + } SLIST_FOREACH(mdnode, &sctx->mdhead, e) { if (xwrite(sctx->fd, mdnode->md, MDSIZE) != MDSIZE) return -1; @@ -223,6 +251,8 @@ sclose(struct sctx *sctx) r = close(sctx->fd); free(sctx); + if (r < 0) + sseterr("failed to close snapshot descriptor"); return r; }