iSeparate pack/unpack from write/read - dedup - deduplicating backup program Err bitreich.org 70 hgit clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ URL:git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/ bitreich.org 70 1Log /scm/dedup/log.gph bitreich.org 70 1Files /scm/dedup/files.gph bitreich.org 70 1Refs /scm/dedup/refs.gph bitreich.org 70 1Tags /scm/dedup/tag bitreich.org 70 1README /scm/dedup/file/README.gph bitreich.org 70 1LICENSE /scm/dedup/file/LICENSE.gph bitreich.org 70 i--- Err bitreich.org 70 1commit c14172d9472f2d53300a19b3fa27ddcbaba185d6 /scm/dedup/commit/c14172d9472f2d53300a19b3fa27ddcbaba185d6.gph bitreich.org 70 1parent 7c3a4a21592d3c11e418e00964caadaec81613a5 /scm/dedup/commit/7c3a4a21592d3c11e418e00964caadaec81613a5.gph bitreich.org 70 hAuthor: sin URL:mailto:sin@2f30.org bitreich.org 70 iDate: Sun, 12 May 2019 19:36:07 +0100 Err bitreich.org 70 i Err bitreich.org 70 iSeparate pack/unpack from write/read Err bitreich.org 70 i Err bitreich.org 70 iDiffstat: Err bitreich.org 70 i M bstorage.c | 36 ++++++++++++++++---------------- Err bitreich.org 70 i Err bitreich.org 70 i1 file changed, 18 insertions(+), 18 deletions(-) Err bitreich.org 70 i--- Err bitreich.org 70 1diff --git a/bstorage.c b/bstorage.c /scm/dedup/file/bstorage.c.gph bitreich.org 70 i@@ -122,18 +122,12 @@ bhash(void *buf, size_t n, unsigned char *md) Err bitreich.org 70 i return crypto_generichash(md, MDSIZE, buf, n, NULL, 0); Err bitreich.org 70 i } Err bitreich.org 70 i Err bitreich.org 70 i-/* Read block header */ Err bitreich.org 70 i+/* Unpack block header */ Err bitreich.org 70 i static int Err bitreich.org 70 i-unpackbhdr(int fd, struct bhdr *bhdr) Err bitreich.org 70 i+unpackbhdr(unsigned char *buf, struct bhdr *bhdr) Err bitreich.org 70 i { Err bitreich.org 70 i- unsigned char buf[BHDRSIZE]; Err bitreich.org 70 i int n; Err bitreich.org 70 i Err bitreich.org 70 i- if (xread(fd, buf, BHDRSIZE) != BHDRSIZE) { Err bitreich.org 70 i- seterr("failed to read block header: %s", strerror(errno)); Err bitreich.org 70 i- return -1; Err bitreich.org 70 i- } Err bitreich.org 70 i- Err bitreich.org 70 i n = unpack(buf, "'16qq", Err bitreich.org 70 i bhdr->magic, Err bitreich.org 70 i &bhdr->flags, Err bitreich.org 70 i@@ -145,9 +139,8 @@ unpackbhdr(int fd, struct bhdr *bhdr) Err bitreich.org 70 i Err bitreich.org 70 i /* Write block header */ Err bitreich.org 70 i static int Err bitreich.org 70 i-packbhdr(int fd, struct bhdr *bhdr) Err bitreich.org 70 i+packbhdr(unsigned char *buf, struct bhdr *bhdr) Err bitreich.org 70 i { Err bitreich.org 70 i- unsigned char buf[BHDRSIZE]; Err bitreich.org 70 i int n; Err bitreich.org 70 i Err bitreich.org 70 i n = pack(buf, "'16qq", Err bitreich.org 70 i@@ -156,14 +149,10 @@ packbhdr(int fd, struct bhdr *bhdr) Err bitreich.org 70 i bhdr->nbd); Err bitreich.org 70 i Err bitreich.org 70 i assert(n == BHDRSIZE); Err bitreich.org 70 i- if (xwrite(fd, buf, n) != n) { Err bitreich.org 70 i- seterr("failed to write block header: %s", strerror(errno)); Err bitreich.org 70 i- return -1; Err bitreich.org 70 i- } Err bitreich.org 70 i return n; Err bitreich.org 70 i } Err bitreich.org 70 i Err bitreich.org 70 i-/* Read block descriptor */ Err bitreich.org 70 i+/* Unpack block descriptor */ Err bitreich.org 70 i static int Err bitreich.org 70 i unpackbd(int fd, struct bd *bd) Err bitreich.org 70 i { Err bitreich.org 70 i@@ -298,6 +287,7 @@ initbdcache(struct sctx *sctx) Err bitreich.org 70 i static int Err bitreich.org 70 i bscreat(struct bctx *bctx, char *path, int mode) Err bitreich.org 70 i { Err bitreich.org 70 i+ unsigned char buf[BHDRSIZE]; Err bitreich.org 70 i struct sctx *sctx; Err bitreich.org 70 i struct bhdr *bhdr; Err bitreich.org 70 i int fd; Err bitreich.org 70 i@@ -330,9 +320,11 @@ bscreat(struct bctx *bctx, char *path, int mode) Err bitreich.org 70 i bhdr->flags = (VMAJ << VMAJSHIFT) | VMIN; Err bitreich.org 70 i bhdr->nbd = 0; Err bitreich.org 70 i Err bitreich.org 70 i- if (packbhdr(fd, bhdr) < 0) { Err bitreich.org 70 i+ packbhdr(buf, bhdr); Err bitreich.org 70 i+ if (xwrite(fd, buf, BHDRSIZE) != BHDRSIZE) { Err bitreich.org 70 i free(sctx); Err bitreich.org 70 i close(fd); Err bitreich.org 70 i+ seterr("failed to write block header: %s", strerror(errno)); Err bitreich.org 70 i return -1; Err bitreich.org 70 i } Err bitreich.org 70 i return 0; Err bitreich.org 70 i@@ -342,6 +334,7 @@ bscreat(struct bctx *bctx, char *path, int mode) Err bitreich.org 70 i static int Err bitreich.org 70 i bsopen(struct bctx *bctx, char *path, int flags, int mode) Err bitreich.org 70 i { Err bitreich.org 70 i+ unsigned char buf[BHDRSIZE]; Err bitreich.org 70 i struct sctx *sctx; Err bitreich.org 70 i struct bhdr *bhdr; Err bitreich.org 70 i int fd, algo; Err bitreich.org 70 i@@ -381,11 +374,13 @@ bsopen(struct bctx *bctx, char *path, int flags, int mode) Err bitreich.org 70 i SLIST_INIT(&sctx->gchead); Err bitreich.org 70 i bhdr = &sctx->bhdr; Err bitreich.org 70 i Err bitreich.org 70 i- if (unpackbhdr(fd, bhdr) < 0) { Err bitreich.org 70 i+ if (xread(fd, buf, BHDRSIZE) != BHDRSIZE) { Err bitreich.org 70 i free(sctx); Err bitreich.org 70 i close(fd); Err bitreich.org 70 i+ seterr("failed to read block header: %s", strerror(errno)); Err bitreich.org 70 i return -1; Err bitreich.org 70 i } Err bitreich.org 70 i+ unpackbhdr(buf, bhdr); Err bitreich.org 70 i Err bitreich.org 70 i if (memcmp(bhdr->magic, BHDRMAGIC, NBHDRMAGIC) != 0) { Err bitreich.org 70 i free(sctx); Err bitreich.org 70 i@@ -662,6 +657,7 @@ bscheck(struct bctx *bctx, unsigned char *md) Err bitreich.org 70 i static int Err bitreich.org 70 i bssync(struct bctx *bctx) Err bitreich.org 70 i { Err bitreich.org 70 i+ unsigned char buf[BHDRSIZE]; Err bitreich.org 70 i struct sctx *sctx; Err bitreich.org 70 i struct bhdr *bhdr; Err bitreich.org 70 i Err bitreich.org 70 i@@ -673,9 +669,13 @@ bssync(struct bctx *bctx) Err bitreich.org 70 i seterr("lseek: %s", strerror(errno)); Err bitreich.org 70 i return -1; Err bitreich.org 70 i } Err bitreich.org 70 i+ Err bitreich.org 70 i bhdr = &sctx->bhdr; Err bitreich.org 70 i- if (packbhdr(sctx->fd, bhdr) < 0) Err bitreich.org 70 i+ packbhdr(buf, bhdr); Err bitreich.org 70 i+ if (xwrite(sctx->fd, buf, BHDRSIZE) != BHDRSIZE) { Err bitreich.org 70 i+ seterr("failed to write block header: %s", strerror(errno)); Err bitreich.org 70 i return -1; Err bitreich.org 70 i+ } Err bitreich.org 70 i fsync(sctx->fd); Err bitreich.org 70 i return 0; Err bitreich.org 70 i } Err bitreich.org 70 .