36 const int RS_MD4_SUM_LENGTH = 16;
37 const int RS_BLAKE2_SUM_LENGTH = 32;
39 static void rs_block_sig_init(
rs_block_sig_t *sig, rs_weak_sum_t weak_sum,
40 rs_strong_sum_t *strong_sum,
int strong_len)
44 memcpy(sig->
strong_sum, strong_sum, strong_len);
47 static inline unsigned rs_block_sig_hash(
const rs_block_sig_t *sig)
60 rs_weak_sum_t weak_sum,
61 rs_strong_sum_t *strong_sum,
const void *buf,
64 rs_block_sig_init(&match->block_sig, weak_sum, strong_sum,
66 match->signature = sig;
76 #ifndef HASHTABLE_NSTATS 79 rs_signature_calc_strong_sum(match->signature, match->buf, match->len,
88 #define ENTRY rs_block_sig 89 #define MATCH rs_block_match 90 #define NAME hashtable 100 sizeof(rs_weak_sum_t)-
101 1) /
sizeof(rs_weak_sum_t)) *
102 sizeof(rs_weak_sum_t);
110 block_idx * rs_block_sig_size(sig));
117 return ((
char *)block_sig -
118 (
char *)sig->
block_sigs) / rs_block_sig_size(sig);
122 int strong_len, rs_long_t sig_fsize)
130 max_strong_len = RS_BLAKE2_SUM_LENGTH;
133 max_strong_len = RS_MD4_SUM_LENGTH;
136 rs_error(
"invalid magic %#x", magic);
139 strong_len = strong_len ? strong_len : max_strong_len;
140 if (strong_len < 1 || max_strong_len < strong_len) {
141 rs_error(
"invalid strong_sum_len %d for magic %#x", strong_len, magic);
152 sig->
size = (int)(sig_fsize ? (sig_fsize - 12) / (4 + strong_len) : 0);
155 rs_alloc(sig->
size * rs_block_sig_size(sig),
156 "signature->block_sigs");
160 #ifndef HASHTABLE_NSTATS 163 rs_signature_check(sig);
170 rs_bzero(sig,
sizeof(*sig));
174 rs_weak_sum_t weak_sum,
175 rs_strong_sum_t *strong_sum)
177 rs_signature_check(sig);
183 "signature->block_sigs");
190 rs_long_t rs_signature_find_match(
rs_signature_t *sig, rs_weak_sum_t weak_sum,
191 void const *buf,
size_t len)
196 rs_signature_check(sig);
197 rs_block_match_init(&m, sig, weak_sum, NULL, buf, len);
198 if ((b = hashtable_find(sig->
hashtable, &m))) {
199 return (rs_long_t)rs_block_sig_idx(sig, b) * sig->
block_len;
206 #ifndef HASHTABLE_NSTATS 210 "match statistics: signature[%ld searches, %ld (%.3f%%) matches, " 211 "%ld (%.3fx) weak sum compares, %ld (%.3f%%) strong sum compares, " 227 rs_signature_check(sig);
231 for (i = 0; i < sig->
count; i++) {
232 b = rs_block_sig_ptr(sig, i);
243 rs_signature_done(psums);
251 char strong_hex[RS_MAX_STRONG_SUM_LENGTH * 3];
254 "sumset info: magic=%#x, block_len=%d, block_num=%d", sums->
magic,
257 for (i = 0; i < sums->
count; i++) {
258 b = rs_block_sig_ptr(sums, i);
261 "sum %6d: weak=" FMT_WEAKSUM
", strong=%s", i, b->
weak_sum,
int size
Total number of blocks allocated.
hashtable_t * hashtable
The hashtable for finding matches.
rs_result rs_build_hash_table(rs_signature_t *sums)
Call this after loading a signature to index it.
int count
Total number of blocks.
long hashcmp_count
The count of hash compares done.
int block_len
The block length.
A signature file using the BLAKE2 hash.
Bad value passed in to library, probably an application bug.
long match_count
The count of matches found.
Bad magic number at start of stream.
void rs_hexify(char *to_buf, void const *from_buf, int from_len)
Convert from_len bytes at from_buf into a hex representation in to_buf, which must be twice as long p...
rs_weak_sum_t weak_sum
Block's weak checksum.
int strong_sum_len
The block strong sum length.
void rs_free_sumset(rs_signature_t *)
Deep deallocation of checksums.
Don't show function name in message.
A signature file with MD4 signatures.
long entrycmp_count
The count of entry compares done.
void * block_sigs
The packed block_sigs for all blocks.
Public header for librsync.
Signature of a whole file.
rs_result
Return codes from nonblocking rsync operations.
int magic
The signature magic value.
long calc_strong_count
The count of strongsum calcs done.
void rs_sumset_dump(rs_signature_t const *)
Dump signatures to the log.
Signature of a single block.
long find_count
The count of finds tried.
A generic open addressing hashtable.
rs_strong_sum_t strong_sum
Block's strong checksum.