From 811bfef2a02aa302b718263a27ef8df76f745b30 Mon Sep 17 00:00:00 2001 From: Stefano Babic Date: Fri, 17 Sep 2021 13:15:45 +0200 Subject: [PATCH] Add accessor to return associated SRC chunk If a chunk with the same hash is already present on device, it is recorded in the src pointer. Add accessor to return this chunk. Signed-off-by: Stefano Babic --- include/zck.h.in | 4 +++- src/lib/index/index_read.c | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/zck.h.in b/include/zck.h.in index ed646b7..3be82ff 100644 --- a/include/zck.h.in +++ b/include/zck.h.in @@ -280,7 +280,9 @@ ssize_t zck_get_chunk_comp_data(zckChunk *idx, char *dst, size_t dst_size) /* Find out if two chunk digests are the same */ bool zck_compare_chunk_digest(zckChunk *a, zckChunk *b) __attribute__ ((warn_unused_result)); - +/* Get associate src chunk if any */ +zckChunk *zck_get_src_chunk(zckChunk *idx) + __attribute__ ((warn_unused_result)); /******************************************************************* * Advanced hash functions diff --git a/src/lib/index/index_read.c b/src/lib/index/index_read.c index 8c90137..9b2c435 100644 --- a/src/lib/index/index_read.c +++ b/src/lib/index/index_read.c @@ -183,6 +183,17 @@ zckChunk PUBLIC *zck_get_next_chunk(zckChunk *idx) { return idx->next; } +zckChunk PUBLIC *zck_get_src_chunk(zckChunk *idx) { + if(idx && idx->zck) { + VALIDATE_PTR(idx->zck); + ALLOCD_PTR(idx->zck, idx); + } else { + ALLOCD_PTR(NULL, idx); + } + + return idx->src; +} + ssize_t PUBLIC zck_get_chunk_start(zckChunk *idx) { if(idx && idx->zck) { VALIDATE_INT(idx->zck); -- 2.30.2