Add some comments - dedup - deduplicating backup program HTML git clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit 53b588c7899ecf4f4c969259e2c80f18192893ba DIR parent ff783e2a9af6d97d55697d654d759ca48d6a28a1 HTML Author: sin <sin@2f30.org> Date: Sat, 27 Apr 2019 18:31:05 +0100 Add some comments Diffstat: M bstorage.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) --- DIR diff --git a/bstorage.c b/bstorage.c @@ -84,8 +84,8 @@ struct bhdr { /* Block descriptor */ struct bd { uint64_t type; - uint64_t offset; - uint64_t size; + uint64_t offset; /* offset of block */ + uint64_t size; /* size of block */ uint64_t refcnt; unsigned char md[MDSIZE]; RB_ENTRY(bd) rbe; @@ -359,7 +359,6 @@ bscreat(struct bctx *bctx, char *path, int mode, struct bparam *bpar) close(fd); return -1; } - bhdr->nbd = 0; sctx->fd = fd; @@ -484,6 +483,7 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md) if (lseek(sctx->fd, bdoffs, SEEK_SET) < 0) return -1; + /* Block already present, increment the reference count */ bd->refcnt++; if (packbd(sctx->fd, bd) < 0) { bd->refcnt--; @@ -583,8 +583,7 @@ bsrm(struct bctx *bctx, unsigned char *md) 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 - * lose track of the block. + * Restore reference count. */ lseek(sctx->fd, bdoffs, SEEK_SET); bd->refcnt++; @@ -592,6 +591,11 @@ bsrm(struct bctx *bctx, unsigned char *md) return -1; } + /* + * Remove block from block descriptor cache as this is no + * longer a valid block. Insert it into the garbage collector + * list instead. + */ RB_REMOVE(bdcache, &sctx->bdcache, bd); SLIST_INSERT_HEAD(&sctx->gchead, bd, sle); return 0; @@ -685,6 +689,7 @@ bsclose(struct bctx *bctx) return -1; sctx = bctx->sctx; + /* Free block descriptor cache */ RB_FOREACH_SAFE(bd, bdcache, &sctx->bdcache, tmp) { RB_REMOVE(bdcache, &sctx->bdcache, bd);