dedup

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

commit c90df19c4abc00fea111be13b164216a33e5339d
parent 1f0640de77e4cf3d4227dd824d556f09e2bb4200
Author: sin <sin@2f30.org>
Date:   Tue, 26 Mar 2019 16:14:15 +0000

Rename struct snapshot to struct snap and related constants

Diffstat:
Mdedup.c | 51++++++++++++++++++++++++++-------------------------
Mdedup.h | 24++++++++++++------------
Mtypes.c | 16++++++++--------
3 files changed, 46 insertions(+), 45 deletions(-)

diff --git a/dedup.c b/dedup.c @@ -28,7 +28,7 @@ struct extract_args { int ret; }; -static struct snapshot_hdr snap_hdr; +static struct snap_hdr snap_hdr; static struct blk_hdr blk_hdr; static struct cache *cache; static int ifd; @@ -72,10 +72,10 @@ print_stats(struct stats *st) fprintf(stderr, "Cache misses: %llu\n", cache_misses); } -static struct snapshot * +static struct snap * alloc_snap(void) { - struct snapshot *snap; + struct snap *snap; snap = calloc(1, sizeof(*snap)); if (snap == NULL) @@ -84,7 +84,7 @@ alloc_snap(void) } static void -free_snap(struct snapshot *snap) +free_snap(struct snap *snap) { free(snap); } @@ -94,7 +94,7 @@ free_snap(struct snapshot *snap) * hash of its block descriptors. */ static void -hash_snap(struct snapshot *snap, uint8_t *md) +hash_snap(struct snap *snap, uint8_t *md) { blake2b_state ctx; uint64_t i; @@ -109,8 +109,8 @@ hash_snap(struct snapshot *snap, uint8_t *md) blake2b_final(&ctx, md, MDSIZE); } -static struct snapshot * -grow_snap(struct snapshot *snap, uint64_t nr_blk_descs) +static struct snap * +grow_snap(struct snap *snap, uint64_t nr_blk_descs) { size_t size; @@ -129,7 +129,7 @@ grow_snap(struct snapshot *snap, uint64_t nr_blk_descs) } static void -append_snap(struct snapshot *snap) +append_snap(struct snap *snap) { if (snap->nr_blk_descs > UINT64_MAX / BLK_DESC_SIZE) errx(1, "%s: overflow", __func__); @@ -140,16 +140,16 @@ append_snap(struct snapshot *snap) snap->size += SNAPSHOT_SIZE; xlseek(ifd, snap_hdr.size, SEEK_SET); - write_snapshot(ifd, snap); - write_snapshot_blk_descs(ifd, snap); + write_snap(ifd, snap); + write_snap_blk_descs(ifd, snap); if (snap_hdr.size > UINT64_MAX - snap->size) errx(1, "%s: overflow", __func__); snap_hdr.size += snap->size; - if (snap_hdr.nr_snapshots > UINT64_MAX - 1) + if (snap_hdr.nr_snaps > UINT64_MAX - 1) errx(1, "%s: overflow", __func__); - snap_hdr.nr_snapshots++; + snap_hdr.nr_snaps++; } static uint8_t * @@ -204,7 +204,7 @@ append_blk(uint8_t *buf, struct blk_desc *blk_desc) } static void -dedup_chunk(struct snapshot *snap, uint8_t *chunkp, size_t chunk_size) +dedup_chunk(struct snap *snap, uint8_t *chunkp, size_t chunk_size) { uint8_t md[MDSIZE]; struct blk_desc blk_desc; @@ -248,7 +248,7 @@ dedup_chunk(struct snapshot *snap, uint8_t *chunkp, size_t chunk_size) static void dedup(int fd, char *msg) { - struct snapshot *snap; + struct snap *snap; struct chunker *chunker; snap = alloc_snap(); @@ -284,7 +284,7 @@ dedup(int fd, char *msg) } static int -extract(struct snapshot *snap, void *arg) +extract(struct snap *snap, void *arg) { uint8_t *buf[2]; struct extract_args *args = arg; @@ -311,11 +311,12 @@ extract(struct snapshot *snap, void *arg) } /* - * For each snapshot, hash every block and check if the hash - * matches the one in the corresponding block descriptor. + * Hash every block referenced by the given snapshot + * and compare its hash with the one stored in the corresponding + * block descriptor. */ static int -check_snap(struct snapshot *snap, void *arg) +check_snap(struct snap *snap, void *arg) { uint8_t *buf; int *ret = arg; @@ -361,7 +362,7 @@ check_snap(struct snapshot *snap, void *arg) } static int -build_cache(struct snapshot *snap, void *arg) +build_cache(struct snap *snap, void *arg) { uint8_t *buf; uint64_t i; @@ -378,7 +379,7 @@ build_cache(struct snapshot *snap, void *arg) } static int -list(struct snapshot *snap, void *arg) +list(struct snap *snap, void *arg) { print_md(stdout, snap->md, sizeof(snap->md)); if (snap->msg[0] != '\0') @@ -390,19 +391,19 @@ list(struct snapshot *snap, void *arg) /* Walk through all snapshots and call fn() on each one */ static void -walk_snap(int (*fn)(struct snapshot *, void *), void *arg) +walk_snap(int (*fn)(struct snap *, void *), void *arg) { uint64_t i; xlseek(ifd, SNAP_HDR_SIZE, SEEK_SET); - for (i = 0; i < snap_hdr.nr_snapshots; i++) { - struct snapshot *snap; + for (i = 0; i < snap_hdr.nr_snaps; i++) { + struct snap *snap; int ret; snap = alloc_snap(); - read_snapshot(ifd, snap); + read_snap(ifd, snap); snap = grow_snap(snap, snap->nr_blk_descs); - read_snapshot_descs(ifd, snap); + read_snap_descs(ifd, snap); ret = (*fn)(snap, arg); free(snap); diff --git a/dedup.h b/dedup.h @@ -38,10 +38,10 @@ struct stats { uint64_t reserved[4]; }; -struct snapshot_hdr { +struct snap_hdr { uint64_t flags; /* bottom 16 bits are maj/min version */ uint64_t size; /* size of snapshots file */ - uint64_t nr_snapshots; + uint64_t nr_snaps; struct stats st; }; @@ -56,10 +56,10 @@ struct blk_desc { uint64_t size; /* size of block */ }; -struct snapshot { - uint64_t size; /* size of snapshot (including block descriptors) */ - uint8_t msg[MSGSIZE]; /* arbitrary message attached to snapshot */ - uint8_t md[MDSIZE]; /* hash of snapshot */ +struct snap { + uint64_t size; /* size of snap (including block descriptors) */ + uint8_t msg[MSGSIZE]; /* arbitrary message attached to snap */ + uint8_t md[MDSIZE]; /* hash of snap */ uint64_t nr_blk_descs; struct blk_desc blk_desc[]; }; @@ -97,16 +97,16 @@ int pack(unsigned char *dst, char *fmt, ...); int unpack(unsigned char *src, char *fmt, ...); /* types.c */ -void read_snap_hdr(int fd, struct snapshot_hdr *hdr); -void write_snap_hdr(int fd, struct snapshot_hdr *hdr); +void read_snap_hdr(int fd, struct snap_hdr *hdr); +void write_snap_hdr(int fd, struct snap_hdr *hdr); void read_blk_hdr(int fd, struct blk_hdr *hdr); void write_blk_hdr(int fd, struct blk_hdr *hdr); void read_blk_desc(int fd, struct blk_desc *desc); void write_blk_desc(int fd, struct blk_desc *desc); -void read_snapshot(int fd, struct snapshot *snap); -void read_snapshot_descs(int fd, struct snapshot *snap); -void write_snapshot(int fd, struct snapshot *snap); -void write_snapshot_blk_descs(int fd, struct snapshot *snap); +void read_snap(int fd, struct snap *snap); +void read_snap_descs(int fd, struct snap *snap); +void write_snap(int fd, struct snap *snap); +void write_snap_blk_descs(int fd, struct snap *snap); /* utils.c */ void str2bin(char *s, uint8_t *d); diff --git a/types.c b/types.c @@ -9,7 +9,7 @@ #include "dedup.h" void -read_snap_hdr(int fd, struct snapshot_hdr *hdr) +read_snap_hdr(int fd, struct snap_hdr *hdr) { uint8_t buf[SNAP_HDR_SIZE]; int n; @@ -20,7 +20,7 @@ read_snap_hdr(int fd, struct snapshot_hdr *hdr) n = unpack(buf, "qqq", &hdr->flags, &hdr->size, - &hdr->nr_snapshots); + &hdr->nr_snaps); n += unpack(&buf[n], "qqqqqq", &hdr->st.orig_size, @@ -40,7 +40,7 @@ read_snap_hdr(int fd, struct snapshot_hdr *hdr) } void -write_snap_hdr(int fd, struct snapshot_hdr *hdr) +write_snap_hdr(int fd, struct snap_hdr *hdr) { uint8_t buf[SNAP_HDR_SIZE]; int n; @@ -48,7 +48,7 @@ write_snap_hdr(int fd, struct snapshot_hdr *hdr) n = pack(buf, "qqq", hdr->flags, hdr->size, - hdr->nr_snapshots); + hdr->nr_snaps); n += pack(&buf[n], "qqqqqq", hdr->st.orig_size, @@ -135,7 +135,7 @@ write_blk_desc(int fd, struct blk_desc *desc) } void -read_snapshot(int fd, struct snapshot *snap) +read_snap(int fd, struct snap *snap) { uint8_t buf[SNAPSHOT_SIZE]; char fmt[BUFSIZ]; @@ -155,7 +155,7 @@ read_snapshot(int fd, struct snapshot *snap) }; void -read_snapshot_descs(int fd, struct snapshot *snap) +read_snap_descs(int fd, struct snap *snap) { uint64_t i; @@ -164,7 +164,7 @@ read_snapshot_descs(int fd, struct snapshot *snap) } void -write_snapshot(int fd, struct snapshot *snap) +write_snap(int fd, struct snap *snap) { uint8_t buf[SNAPSHOT_SIZE]; char fmt[BUFSIZ]; @@ -182,7 +182,7 @@ write_snapshot(int fd, struct snapshot *snap) } void -write_snapshot_blk_descs(int fd, struct snapshot *snap) +write_snap_blk_descs(int fd, struct snap *snap) { uint64_t i;