dedup

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

commit 6cb387cea51dc694f225ec04bdf1c5d02caf9dcb
parent 067e9ecb71b543b24683fc32bf03dc2e2874a55d
Author: sin <sin@2f30.org>
Date:   Thu, 18 Apr 2019 00:35:29 +0100

Factor out init_{blk,snap}_hdr()

Diffstat:
Mdedup.h | 2++
Mdinit.c | 41++++++-----------------------------------
Mutils.c | 20++++++++++++++++++++
3 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/dedup.h b/dedup.h @@ -206,3 +206,5 @@ void str2bin(char *s, uint8_t *d); off_t xlseek(int fd, off_t offset, int whence); ssize_t xread(int fd, void *buf, size_t nbytes); ssize_t xwrite(int fd, const void *buf, size_t nbytes); +void init_blk_hdr(struct blk_hdr *hdr, int compr_algo, int hash_algo); +void init_snap_hdr(struct snap_hdr *hdr); diff --git a/dinit.c b/dinit.c @@ -28,37 +28,6 @@ int verbose; char *argv0; static void -init_blk_hdr(void) -{ - blk_hdr.flags = (VER_MAJ << VER_MAJ_SHIFT) | VER_MIN; - blk_hdr.flags |= compr_algo << COMPR_ALGO_SHIFT; - blk_hdr.flags |= hash_algo << HASH_ALGO_SHIFT; - blk_hdr.size = BLK_HDR_SIZE; -} - -static void -save_blk_hdr(void) -{ - xlseek(sfd, 0, SEEK_SET); - write_blk_hdr(sfd, &blk_hdr); -} - -static void -init_snap_hdr(void) -{ - snap_hdr.flags = (VER_MAJ << VER_MAJ_SHIFT) | VER_MIN; - snap_hdr.size = SNAP_HDR_SIZE; - snap_hdr.st.min_blk_size = UINT64_MAX; -} - -static void -save_snap_hdr(void) -{ - xlseek(ifd, 0, SEEK_SET); - write_snap_hdr(ifd, &snap_hdr); -} - -static void init(void) { int flags; @@ -76,15 +45,17 @@ init(void) flock(sfd, LOCK_NB | LOCK_EX) < 0) err(1, "flock"); - init_snap_hdr(); - init_blk_hdr(); + init_snap_hdr(&snap_hdr); + init_blk_hdr(&blk_hdr, compr_algo, hash_algo); } static void term(void) { - save_blk_hdr(); - save_snap_hdr(); + xlseek(ifd, 0, SEEK_SET); + write_snap_hdr(ifd, &snap_hdr); + xlseek(sfd, 0, SEEK_SET); + write_blk_hdr(sfd, &blk_hdr); fsync(sfd); fsync(ifd); diff --git a/utils.c b/utils.c @@ -6,6 +6,9 @@ #include <string.h> #include <unistd.h> +#include "blake2.h" +#include "dedup.h" + void str2bin(char *s, uint8_t *d) { @@ -65,3 +68,20 @@ xwrite(int fd, const void *buf, size_t nbytes) } return total; } + +void +init_blk_hdr(struct blk_hdr *hdr, int compr_algo, int hash_algo) +{ + hdr->flags = (VER_MAJ << VER_MAJ_SHIFT) | VER_MIN; + hdr->flags |= compr_algo << COMPR_ALGO_SHIFT; + hdr->flags |= hash_algo << HASH_ALGO_SHIFT; + hdr->size = BLK_HDR_SIZE; +} + +void +init_snap_hdr(struct snap_hdr *hdr) +{ + hdr->flags = (VER_MAJ << VER_MAJ_SHIFT) | VER_MIN; + hdr->size = SNAP_HDR_SIZE; + hdr->st.min_blk_size = UINT64_MAX; +}