dedup

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

commit 873f8140b3c1861e5baa5c2dd93f83dfb1d1bc2a
parent 119f4b9531960ed842f475fe4b3e91444ce92b59
Author: sin <sin@2f30.org>
Date:   Fri, 26 Apr 2019 14:50:26 +0100

Introduce S_READ/B_READ/B_RDWR

Diffstat:
Mblock.h | 5+++++
Mbstorage.c | 11+++++++++++
Mdup-check.c | 5++---
Mdup-gc.c | 3+--
Mdup-init.c | 1-
Mdup-pack.c | 3+--
Mdup-rm.c | 5++---
Mdup-unpack.c | 5++---
Msnap.c | 4++--
Msnap.h | 4++++
10 files changed, 30 insertions(+), 16 deletions(-)

diff --git a/block.h b/block.h @@ -1,3 +1,8 @@ +enum { + B_READ = 1 << 0, + B_RDWR = 1 << 1, +}; + struct bctx { void *gctx; /* generic layer context (unused) */ void *cctx; /* compression layer context */ diff --git a/bstorage.c b/bstorage.c @@ -379,6 +379,17 @@ bsopen(struct bctx *bctx, char *path, int flags, int mode, struct bparam *bpar) struct bhdr *bhdr; int fd, calgo, halgo; + switch (flags) { + case B_READ: + flags = O_RDONLY; + break; + case B_RDWR: + flags = O_RDWR; + break; + default: + return -1; + } + fd = open(path, flags, mode); if (fd < 0) return -1; diff --git a/dup-check.c b/dup-check.c @@ -2,7 +2,6 @@ #include <sys/stat.h> #include <err.h> -#include <fcntl.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -61,11 +60,11 @@ main(int argc, char *argv[]) usage(); snprintf(path, sizeof(path), "%s/archive/%s", repo, argv[0]); - if (sopen(path, O_RDONLY, 0600, &sctx) < 0) + if (sopen(path, S_READ, 0600, &sctx) < 0) errx(1, "sopen: %s: failed", path); snprintf(path, sizeof(path), "%s/storage", repo); - if (bopen(path, O_RDONLY, 0600, &bparam, &bctx) <0) + if (bopen(path, B_READ, 0600, &bparam, &bctx) <0) errx(1, "bopen: %s: failed", path); if (check(sctx, bctx) < 0) diff --git a/dup-gc.c b/dup-gc.c @@ -2,7 +2,6 @@ #include <sys/stat.h> #include <err.h> -#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -51,7 +50,7 @@ main(int argc, char *argv[]) if (chdir(repo) < 0) err(1, "chdir: %s", repo); - if (bopen(STORAGEPATH, O_RDWR, 0600, &bpar, &bctx) < 0) + if (bopen(STORAGEPATH, B_RDWR, 0600, &bpar, &bctx) < 0) errx(1, "bopen: failed"); if (bgc(bctx) < 0) errx(1, "bgc: failed"); diff --git a/dup-init.c b/dup-init.c @@ -2,7 +2,6 @@ #include <sys/stat.h> #include <err.h> -#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> diff --git a/dup-pack.c b/dup-pack.c @@ -2,7 +2,6 @@ #include <sys/stat.h> #include <err.h> -#include <fcntl.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -83,7 +82,7 @@ main(int argc, char *argv[]) errx(1, "screat: %s: failed", path); snprintf(path, sizeof(path), "%s/storage", repo); - if (bopen(path, O_RDWR, 0600, &bpar, &bctx) <0) + if (bopen(path, B_RDWR, 0600, &bpar, &bctx) <0) errx(1, "bopen: %s: failed", path); if (pack(sctx, bctx) < 0) diff --git a/dup-rm.c b/dup-rm.c @@ -2,7 +2,6 @@ #include <sys/stat.h> #include <err.h> -#include <fcntl.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -63,11 +62,11 @@ main(int argc, char *argv[]) usage(); snprintf(spath, sizeof(spath), "%s/archive/%s", repo, argv[0]); - if (sopen(spath, O_RDONLY, 0600, &sctx) < 0) + if (sopen(spath, S_READ, 0600, &sctx) < 0) errx(1, "sopen: %s: failed", spath); snprintf(bpath, sizeof(bpath), "%s/storage", repo); - if (bopen(bpath, O_RDWR, 0600, &bparam, &bctx) <0) + if (bopen(bpath, B_RDWR, 0600, &bparam, &bctx) <0) errx(1, "bopen: %s: failed", bpath); if (rm(sctx, bctx) < 0) diff --git a/dup-unpack.c b/dup-unpack.c @@ -2,7 +2,6 @@ #include <sys/stat.h> #include <err.h> -#include <fcntl.h> #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -95,11 +94,11 @@ main(int argc, char *argv[]) usage(); snprintf(path, sizeof(path), "%s/archive/%s", repo, argv[0]); - if (sopen(path, O_RDONLY, 0600, &sctx) < 0) + if (sopen(path, S_READ, 0600, &sctx) < 0) errx(1, "sopen: %s: failed", path); snprintf(path, sizeof(path), "%s/storage", repo); - if (bopen(path, O_RDONLY, 0600, &bpar, &bctx) <0) + if (bopen(path, B_READ, 0600, &bpar, &bctx) <0) errx(1, "bopen: %s: failed", path); if (unpack(sctx, bctx) < 0) diff --git a/snap.c b/snap.c @@ -141,10 +141,10 @@ sopen(char *path, int flags, int mode, struct sctx **sctx) return -1; /* Existing snapshots are immutable */ - if (flags != O_RDONLY) + if (flags != S_READ) return -1; - fd = open(path, flags, mode); + fd = open(path, O_RDONLY, mode); if (fd < 0) return -1; diff --git a/snap.h b/snap.h @@ -1,3 +1,7 @@ +enum { + S_READ = 1 << 0, +}; + struct sctx; extern int screat(char *path, int mode, struct sctx **sctx);