dedup

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

commit 5cc2cb4d8ed4f3866cc99a3c2e50e4f244f6f836
parent 3cb8c88abd3f830a2637a8b666402d063df0e7e4
Author: sin <sin@2f30.org>
Date:   Sun, 17 Feb 2019 11:23:29 +0000

Add support for attaching descriptive messages to snapshots

Diffstat:
Mdedup.1 | 9++++++---
Mdedup.c | 29++++++++++++++++++++++++-----
2 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/dedup.1 b/dedup.1 @@ -1,4 +1,4 @@ -.Dd March 21, 2018 +.Dd Feb 17, 2019 .Dt DEDUP 1 .Os .Sh NAME @@ -9,6 +9,7 @@ .Op Fl clv .Op Fl e Ar id .Op Fl r Ar root +.Op Fl m Ar message .Op file .Sh DESCRIPTION .Nm @@ -20,14 +21,16 @@ only handles a single file at a time, so using tar is advised. .It Fl c Perform a consistency check on the deduplication storage. .It Fl l -List revisions by hash. +List snapshots by hash. .It Fl v Enable verbose mode. .It Fl e Ar id -Extract revision with the specified id. +Extract snapshot with the specified id. .It Fl r Ar root Set the root directory where the .cache, .index and .store files will be created. +.It Fl m Ar message +Attach a descriptive message to the snapshot. .El .Sh AUTHORS .An Dimitris Papastamos Aq Mt sin@2f30.org , diff --git a/dedup.c b/dedup.c @@ -19,6 +19,7 @@ #define BLKSIZ (1024 * 512) #define WINSIZ 1024 #define HASHMSK ((1ul << 21) - 1) +#define MSGSIZ 256 #define MDSIZ SHA256_DIGEST_LENGTH #define ROTL(x, y) (((x) << (y)) | ((x) >> (32 - (y)))) @@ -44,6 +45,7 @@ struct bdescr { /* index file entry */ struct ent { uint64_t size; + uint8_t msg[MSGSIZ]; uint8_t md[MDSIZ]; /* hash of file */ uint64_t nblks; struct bdescr bdescr[]; @@ -363,7 +365,7 @@ lookup_blk(uint8_t *md) } void -dedup(int fd) +dedup(int fd, char *msg) { uint8_t *buf; struct ent *ent; @@ -421,8 +423,19 @@ dedup(int fd) } if (ent->nblks > 0) { + size_t size; + /* Calculate hash and add this entry to the index */ SHA256_Final(ent->md, &ctx); + + if (msg != NULL && msg[0] != '\0') { + size = strlen(msg) + 1; + if (size > sizeof(ent->msg)) + size = sizeof(ent->msg); + memcpy(ent->msg, msg, size); + ent->msg[size - 1] = '\0'; + } + append_ent(ent); } @@ -493,7 +506,10 @@ int list(struct ent *ent, void *arg) { print_md(ent->md, sizeof(ent->md)); - putchar('\n'); + if (ent->msg) + printf("\t%s\n", ent->msg); + else + putchar('\n'); return WALK_CONTINUE; } @@ -630,7 +646,7 @@ term(void) void usage(void) { - fprintf(stderr, "usage: %s [-clv] [-e id] [-r root] [file]\n", argv0); + fprintf(stderr, "usage: %s [-clv] [-e id] [-r root] [-m message] [file]\n", argv0); exit(1); } @@ -638,7 +654,7 @@ int main(int argc, char *argv[]) { uint8_t md[MDSIZ]; - char *id = NULL, *root = NULL; + char *id = NULL, *root = NULL, *msg = NULL; int fd = -1, lflag = 0, cflag = 0; ARGBEGIN { @@ -654,6 +670,9 @@ main(int argc, char *argv[]) case 'r': root = EARGF(usage()); break; + case 'm': + msg = EARGF(usage()); + break; case 'v': verbose = 1; break; @@ -704,7 +723,7 @@ main(int argc, char *argv[]) str2bin(id, md); walk(extract, &(struct extract_args){ .md = md, .fd = fd }); } else { - dedup(fd); + dedup(fd, msg); } term();