SMOLNET PORTAL home about changes
iSplit some more 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 0b71c907f1b957781c5850a7445e3fd6abbdfb43	/scm/dedup/commit/0b71c907f1b957781c5850a7445e3fd6abbdfb43.gph	bitreich.org	70
1parent 51940c0f0f8def58517f3ef932b9b657cf556f18	/scm/dedup/commit/51940c0f0f8def58517f3ef932b9b657cf556f18.gph	bitreich.org	70
hAuthor: sin <sin@2f30.org>	URL:mailto:sin@2f30.org	bitreich.org	70
iDate:   Sun, 12 May 2019 20:14:09 +0100	Err	bitreich.org	70
i	Err	bitreich.org	70
iSplit some more pack/unpack from write/read	Err	bitreich.org	70
i	Err	bitreich.org	70
iDiffstat:	Err	bitreich.org	70
i  M bstorage.c                          |      63 +++++++++++++++++--------------	Err	bitreich.org	70
i	Err	bitreich.org	70
i1 file changed, 34 insertions(+), 29 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@@ -154,18 +154,11 @@ packbhdr(unsigned char *buf, struct bhdr *bhdr)	Err	bitreich.org	70
i 	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+unpackbd(unsigned char *buf, struct bd *bd)	Err	bitreich.org	70
i {	Err	bitreich.org	70
i-        unsigned char buf[BDSIZE];	Err	bitreich.org	70
i         char fmt[BUFSIZ];	Err	bitreich.org	70
i         int n;	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-        if (xread(fd, buf, BDSIZE) != BDSIZE) {	Err	bitreich.org	70
i-                seterr("failed to read block descriptor: %s",	Err	bitreich.org	70
i-                        strerror(errno));	Err	bitreich.org	70
i-                return -1;	Err	bitreich.org	70
i-        }	Err	bitreich.org	70
i-	Err	bitreich.org	70
i         snprintf(fmt, sizeof(fmt), "s'6qqq'%d", MDSIZE);	Err	bitreich.org	70
i         n = unpack(buf, fmt,	Err	bitreich.org	70
i                    &bd->type,	Err	bitreich.org	70
i@@ -181,9 +174,8 @@ unpackbd(int fd, struct bd *bd)	Err	bitreich.org	70
i 	Err	bitreich.org	70
i /* Write block descriptor */	Err	bitreich.org	70
i static int	Err	bitreich.org	70
i-packbd(int fd, struct bd *bd)	Err	bitreich.org	70
i+packbd(unsigned char *buf, struct bd *bd)	Err	bitreich.org	70
i {	Err	bitreich.org	70
i-        unsigned char buf[BDSIZE];	Err	bitreich.org	70
i         char fmt[BUFSIZ];	Err	bitreich.org	70
i         int n;	Err	bitreich.org	70
i 	Err	bitreich.org	70
i@@ -197,11 +189,6 @@ packbd(int fd, struct bd *bd)	Err	bitreich.org	70
i                  bd->md);	Err	bitreich.org	70
i 	Err	bitreich.org	70
i         assert(n == BDSIZE);	Err	bitreich.org	70
i-        if (xwrite(fd, buf, n) != n) {	Err	bitreich.org	70
i-                seterr("failed to write block descriptor: %s",	Err	bitreich.org	70
i-                        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@@ -209,6 +196,7 @@ packbd(int fd, struct bd *bd)	Err	bitreich.org	70
i static int	Err	bitreich.org	70
i loadbd(struct sctx *sctx)	Err	bitreich.org	70
i {	Err	bitreich.org	70
i+        unsigned char bdbuf[BDSIZE];	Err	bitreich.org	70
i         struct bd *bd;	Err	bitreich.org	70
i 	Err	bitreich.org	70
i         bd = calloc(1, sizeof(*bd));	Err	bitreich.org	70
i@@ -217,10 +205,13 @@ loadbd(struct sctx *sctx)	Err	bitreich.org	70
i                 return -1;	Err	bitreich.org	70
i         }	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-        if (unpackbd(sctx->fd, bd) < 0) {	Err	bitreich.org	70
i+        if (xread(sctx->fd, bdbuf, BDSIZE) != BDSIZE) {	Err	bitreich.org	70
i                 free(bd);	Err	bitreich.org	70
i+                seterr("failed to read block descriptor: %s",	Err	bitreich.org	70
i+                        strerror(errno));	Err	bitreich.org	70
i                 return -1;	Err	bitreich.org	70
i         }	Err	bitreich.org	70
i+        unpackbd(bdbuf, bd);	Err	bitreich.org	70
i 	Err	bitreich.org	70
i         if (bd->type != BDTYPE) {	Err	bitreich.org	70
i                 free(bd);	Err	bitreich.org	70
i@@ -287,7 +278,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+        unsigned char bhdrbuf[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@@ -320,8 +311,8 @@ 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-        packbhdr(buf, bhdr);	Err	bitreich.org	70
i-        if (xwrite(fd, buf, BHDRSIZE) != BHDRSIZE) {	Err	bitreich.org	70
i+        packbhdr(bhdrbuf, bhdr);	Err	bitreich.org	70
i+        if (xwrite(fd, bhdrbuf, 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@@ -334,7 +325,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+        unsigned char bhdrbuf[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@@ -374,13 +365,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 (xread(fd, buf, BHDRSIZE) != BHDRSIZE) {	Err	bitreich.org	70
i+        if (xread(fd, bhdrbuf, 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+        unpackbhdr(bhdrbuf, 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@@ -412,6 +403,7 @@ bsopen(struct bctx *bctx, char *path, int flags, int mode)	Err	bitreich.org	70
i static int	Err	bitreich.org	70
i bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md)	Err	bitreich.org	70
i {	Err	bitreich.org	70
i+        unsigned char bdbuf[BDSIZE];	Err	bitreich.org	70
i         struct sctx *sctx;	Err	bitreich.org	70
i         struct bhdr *bhdr;	Err	bitreich.org	70
i         struct bd key, *bd;	Err	bitreich.org	70
i@@ -439,8 +431,11 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md)	Err	bitreich.org	70
i                 }	Err	bitreich.org	70
i 	Err	bitreich.org	70
i                 bd->refcnt++;	Err	bitreich.org	70
i-                if (packbd(sctx->fd, bd) < 0) {	Err	bitreich.org	70
i+                packbd(bdbuf, bd);	Err	bitreich.org	70
i+                if (xwrite(sctx->fd, bdbuf, BDSIZE) != BDSIZE) {	Err	bitreich.org	70
i                         bd->refcnt--;	Err	bitreich.org	70
i+                        seterr("failed to write block descriptor: %s",	Err	bitreich.org	70
i+                                strerror(errno));	Err	bitreich.org	70
i                         return -1;	Err	bitreich.org	70
i                 }	Err	bitreich.org	70
i 	Err	bitreich.org	70
i@@ -466,8 +461,13 @@ bsput(struct bctx *bctx, void *buf, size_t n, unsigned char *md)	Err	bitreich.org	70
i         bd->refcnt = 1;	Err	bitreich.org	70
i         memcpy(bd->md, key.md, MDSIZE);	Err	bitreich.org	70
i 	Err	bitreich.org	70
i-        if (packbd(sctx->fd, bd) < 0) {	Err	bitreich.org	70
i+        packbd(bdbuf, bd);	Err	bitreich.org	70
i+        if (xwrite(sctx->fd, bdbuf, BDSIZE) != BDSIZE) {	Err	bitreich.org	70
i+                /* Shouldn't fail but if it does rewind storage file state */	Err	bitreich.org	70
i+                ftruncate(sctx->fd, offs);	Err	bitreich.org	70
i                 free(bd);	Err	bitreich.org	70
i+                seterr("failed to write block descriptor: %s",	Err	bitreich.org	70
i+                        strerror(errno));	Err	bitreich.org	70
i                 return -1;	Err	bitreich.org	70
i         }	Err	bitreich.org	70
i 	Err	bitreich.org	70
i@@ -528,6 +528,7 @@ bsget(struct bctx *bctx, unsigned char *md, void *buf, size_t *n)	Err	bitreich.org	70
i static int	Err	bitreich.org	70
i bsrm(struct bctx *bctx, unsigned char *md)	Err	bitreich.org	70
i {	Err	bitreich.org	70
i+        unsigned char bdbuf[BDSIZE];	Err	bitreich.org	70
i         struct sctx *sctx;	Err	bitreich.org	70
i         struct bd key, *bd;	Err	bitreich.org	70
i         off_t bdoffs;	Err	bitreich.org	70
i@@ -547,8 +548,11 @@ bsrm(struct bctx *bctx, unsigned char *md)	Err	bitreich.org	70
i         }	Err	bitreich.org	70
i 	Err	bitreich.org	70
i         bd->refcnt--;	Err	bitreich.org	70
i-        if (packbd(sctx->fd, bd) < 0) {	Err	bitreich.org	70
i+        packbd(bdbuf, bd);	Err	bitreich.org	70
i+        if (xwrite(sctx->fd, bdbuf, BDSIZE) != BDSIZE) {	Err	bitreich.org	70
i                 bd->refcnt++;	Err	bitreich.org	70
i+                seterr("failed to write block descriptor: %s",	Err	bitreich.org	70
i+                        strerror(errno));	Err	bitreich.org	70
i                 return -1;	Err	bitreich.org	70
i         }	Err	bitreich.org	70
i 	Err	bitreich.org	70
i@@ -563,7 +567,8 @@ bsrm(struct bctx *bctx, unsigned char *md)	Err	bitreich.org	70
i                  */	Err	bitreich.org	70
i                 lseek(sctx->fd, bdoffs, SEEK_SET);	Err	bitreich.org	70
i                 bd->refcnt++;	Err	bitreich.org	70
i-                packbd(sctx->fd, bd);	Err	bitreich.org	70
i+                packbd(bdbuf, bd);	Err	bitreich.org	70
i+                xwrite(sctx->fd, bdbuf, BDSIZE);	Err	bitreich.org	70
i                 seterr("operation not supported");	Err	bitreich.org	70
i                 return -1;	Err	bitreich.org	70
i         }	Err	bitreich.org	70
i@@ -657,7 +662,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+        unsigned char bhdrbuf[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@@ -671,8 +676,8 @@ bssync(struct bctx *bctx)	Err	bitreich.org	70
i         }	Err	bitreich.org	70
i 	Err	bitreich.org	70
i         bhdr = &sctx->bhdr;	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+        packbhdr(bhdrbuf, bhdr);	Err	bitreich.org	70
i+        if (xwrite(sctx->fd, bhdrbuf, 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
.
Response: text/plain
Original URLgopher://bitreich.org/0/scm/dedup/commit/0b71c907f1b95778...
Content-Typetext/plain; charset=utf-8