dedup

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

commit 507fc4bcf4bbfe7d0fefa6c8cdd699322715da61
parent a7753b65b2b40ba265e30e8f2f0bda25da7baa53
Author: sin <sin@2f30.org>
Date:   Tue,  7 May 2019 16:57:40 +0100

Switch from singly linked list to a tail queue

This is needed to guarantee correct order of traversal for upcoming
streaming encryption/authentication support.

Diffstat:
Msnap.c | 30+++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/snap.c b/snap.c @@ -21,11 +21,11 @@ struct mdnode { unsigned char md[MDSIZE]; /* hash of block */ - SLIST_ENTRY(mdnode) e; /* mdhead link node */ + TAILQ_ENTRY(mdnode) e; /* mdhead link node */ }; struct sctx { - SLIST_HEAD(mdhead, mdnode) mdhead; /* list of hashes contained in snapshot */ + TAILQ_HEAD(mdhead, mdnode) mdhead; /* list of hashes contained in snapshot */ struct mdnode *mdnext; /* next hash to be returned via sget() */ int fd; /* underlying snapshot file descriptor */ int rdonly; /* when set to 1, the ssync() operation is a no-op */ @@ -48,7 +48,7 @@ loadmd(struct sctx *sctx) sseterr("failed to read block hash: %s", strerror(errno)); return -1; } - SLIST_INSERT_HEAD(&sctx->mdhead, mdnode, e); + TAILQ_INSERT_TAIL(&sctx->mdhead, mdnode, e); return 0; } @@ -68,11 +68,11 @@ initmdhead(struct sctx *sctx) continue; /* Cleanup */ - while (!SLIST_EMPTY(&sctx->mdhead)) { + while (!TAILQ_EMPTY(&sctx->mdhead)) { struct mdnode *mdnode; - mdnode = SLIST_FIRST(&sctx->mdhead); - SLIST_REMOVE(&sctx->mdhead, mdnode, mdnode, e); + mdnode = TAILQ_FIRST(&sctx->mdhead); + TAILQ_REMOVE(&sctx->mdhead, mdnode, e); free(mdnode); } return -1; @@ -103,7 +103,7 @@ screat(char *path, int mode, struct sctx **sctx) return -1; } - SLIST_INIT(&(*sctx)->mdhead); + TAILQ_INIT(&(*sctx)->mdhead); (*sctx)->mdnext = NULL; (*sctx)->fd = fd; return 0; @@ -138,7 +138,7 @@ sopen(char *path, int flags, int mode, struct sctx **sctx) return -1; } - SLIST_INIT(&(*sctx)->mdhead); + TAILQ_INIT(&(*sctx)->mdhead); (*sctx)->mdnext = NULL; (*sctx)->fd = fd; (*sctx)->rdonly = 1; @@ -167,7 +167,7 @@ sput(struct sctx *sctx, unsigned char *md) return -1; } memcpy(mdnode->md, md, MDSIZE); - SLIST_INSERT_HEAD(&sctx->mdhead, mdnode, e); + TAILQ_INSERT_TAIL(&sctx->mdhead, mdnode, e); return 0; } @@ -183,9 +183,9 @@ sget(struct sctx *sctx, unsigned char *md) mdnode = sctx->mdnext; if (mdnode == NULL) - mdnode = SLIST_FIRST(&sctx->mdhead); + mdnode = TAILQ_FIRST(&sctx->mdhead); else - mdnode = SLIST_NEXT(mdnode, e); + mdnode = TAILQ_NEXT(mdnode, e); sctx->mdnext = mdnode; if (mdnode != NULL) { memcpy(md, mdnode->md, MDSIZE); @@ -222,7 +222,7 @@ ssync(struct sctx *sctx) sseterr("lseek: %s", strerror(errno)); return -1; } - SLIST_FOREACH(mdnode, &sctx->mdhead, e) { + TAILQ_FOREACH(mdnode, &sctx->mdhead, e) { if (xwrite(sctx->fd, mdnode->md, MDSIZE) != MDSIZE) { sseterr("failed to write block hash: %s", strerror(errno)); @@ -245,11 +245,11 @@ sclose(struct sctx *sctx) return -1; /* Cleanup */ - while (!SLIST_EMPTY(&sctx->mdhead)) { + while (!TAILQ_EMPTY(&sctx->mdhead)) { struct mdnode *mdnode; - mdnode = SLIST_FIRST(&sctx->mdhead); - SLIST_REMOVE(&sctx->mdhead, mdnode, mdnode, e); + mdnode = TAILQ_FIRST(&sctx->mdhead); + TAILQ_REMOVE(&sctx->mdhead, mdnode, e); free(mdnode); }