blob: 00a38aa45abb8a310bc2d5157979d1358433e8a4 [file] [log] [blame]
Wayne Davison1e4f48d2003-08-22 05:51:42 +00001/*
Andrew Tridgellc627d611996-06-22 05:04:20 +00002 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
Wayne Davison1e4f48d2003-08-22 05:51:42 +00004
Andrew Tridgellc627d611996-06-22 05:04:20 +00005 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
Wayne Davison1e4f48d2003-08-22 05:51:42 +00009
Andrew Tridgellc627d611996-06-22 05:04:20 +000010 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
Wayne Davison1e4f48d2003-08-22 05:51:42 +000014
Andrew Tridgellc627d611996-06-22 05:04:20 +000015 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18*/
19
20#include "rsync.h"
21
22extern int verbose;
23extern int am_server;
Wayne Davison16417f82003-07-08 16:49:10 +000024extern int do_progress;
Wayne Davisonba582f72004-05-21 08:27:04 +000025extern int checksum_seed;
Wayne Davisona36ffd32005-01-17 23:11:13 +000026
27int updating_basis_file;
Andrew Tridgellc627d611996-06-22 05:04:20 +000028
29typedef unsigned short tag;
30
31#define TABLESIZE (1<<16)
Wayne Davison7cacd472005-02-14 08:12:22 +000032#define NULL_TAG (-1)
Andrew Tridgellc627d611996-06-22 05:04:20 +000033
34static int false_alarms;
35static int tag_hits;
36static int matches;
Andrew Tridgella8004341998-06-01 03:42:14 +000037static int64 data_transfer;
Andrew Tridgellc627d611996-06-22 05:04:20 +000038
Andrew Tridgell3a6a3661998-03-23 12:52:57 +000039static int total_false_alarms;
40static int total_tag_hits;
41static int total_matches;
Andrew Tridgellc627d611996-06-22 05:04:20 +000042
Andrew Tridgella8004341998-06-01 03:42:14 +000043extern struct stats stats;
Andrew Tridgellc627d611996-06-22 05:04:20 +000044
45struct target {
Wayne Davison1e4f48d2003-08-22 05:51:42 +000046 tag t;
Wayne Davison7cacd472005-02-14 08:12:22 +000047 int32 i;
Andrew Tridgellc627d611996-06-22 05:04:20 +000048};
49
Andrew Tridgell3a6a3661998-03-23 12:52:57 +000050static struct target *targets;
Andrew Tridgellc627d611996-06-22 05:04:20 +000051
Wayne Davison7cacd472005-02-14 08:12:22 +000052static int32 *tag_table;
Andrew Tridgellc627d611996-06-22 05:04:20 +000053
54#define gettag2(s1,s2) (((s1) + (s2)) & 0xFFFF)
55#define gettag(sum) gettag2((sum)&0xFFFF,(sum)>>16)
56
57static int compare_targets(struct target *t1,struct target *t2)
58{
Wayne Davison1e4f48d2003-08-22 05:51:42 +000059 return (int)t1->t - (int)t2->t;
Andrew Tridgellc627d611996-06-22 05:04:20 +000060}
61
62
63static void build_hash_table(struct sum_struct *s)
64{
Wayne Davison7cacd472005-02-14 08:12:22 +000065 int32 i;
Andrew Tridgellc627d611996-06-22 05:04:20 +000066
Wayne Davison1e4f48d2003-08-22 05:51:42 +000067 if (!tag_table)
Wayne Davison7cacd472005-02-14 08:12:22 +000068 tag_table = new_array(int32, TABLESIZE);
Andrew Tridgellc627d611996-06-22 05:04:20 +000069
Wayne Davison58cadc82003-12-06 21:07:27 +000070 targets = new_array(struct target, s->count);
Wayne Davison1e4f48d2003-08-22 05:51:42 +000071 if (!tag_table || !targets)
72 out_of_memory("build_hash_table");
Andrew Tridgellc627d611996-06-22 05:04:20 +000073
Wayne Davison0e36d9d2004-01-03 19:28:03 +000074 for (i = 0; i < s->count; i++) {
Wayne Davison1e4f48d2003-08-22 05:51:42 +000075 targets[i].i = i;
76 targets[i].t = gettag(s->sums[i].sum1);
77 }
Andrew Tridgellc627d611996-06-22 05:04:20 +000078
Wayne Davison1e4f48d2003-08-22 05:51:42 +000079 qsort(targets,s->count,sizeof(targets[0]),(int (*)())compare_targets);
Andrew Tridgellc627d611996-06-22 05:04:20 +000080
Wayne Davison1e4f48d2003-08-22 05:51:42 +000081 for (i = 0; i < TABLESIZE; i++)
82 tag_table[i] = NULL_TAG;
Andrew Tridgellc627d611996-06-22 05:04:20 +000083
Wayne Davison0e36d9d2004-01-03 19:28:03 +000084 for (i = s->count; i-- > 0; )
Wayne Davison1e4f48d2003-08-22 05:51:42 +000085 tag_table[targets[i].t] = i;
Andrew Tridgellc627d611996-06-22 05:04:20 +000086}
87
88
Andrew Tridgellbcacc181998-05-06 05:43:36 +000089static OFF_T last_match;
Andrew Tridgellc627d611996-06-22 05:04:20 +000090
91
Martin Poolf5f95a32002-04-08 08:23:50 +000092/**
93 * Transmit a literal and/or match token.
94 *
95 * This delightfully-named function is called either when we find a
96 * match and need to transmit all the unmatched data leading up to it,
97 * or when we get bored of accumulating literal data and just need to
98 * transmit it. As a result of this second case, it is called even if
99 * we have not matched at all!
100 *
101 * @param i If >0, the number of a matched token. If 0, indicates we
102 * have only literal data.
103 **/
Wayne Davisona06b4192005-01-01 21:08:14 +0000104static void matched(int f, struct sum_struct *s, struct map_struct *buf,
Wayne Davison37a56442005-02-14 22:48:28 +0000105 OFF_T offset, int32 i)
Andrew Tridgellc627d611996-06-22 05:04:20 +0000106{
Wayne Davisona06b4192005-01-01 21:08:14 +0000107 int32 n = offset - last_match; /* max value: block_size (int32) */
108 int32 j;
Andrew Tridgell9e31c481996-07-02 03:19:58 +0000109
Wayne Davisona06b4192005-01-01 21:08:14 +0000110 if (verbose > 2 && i >= 0) {
111 rprintf(FINFO,
112 "match at %.0f last_match=%.0f j=%d len=%ld n=%ld\n",
113 (double)offset, (double)last_match, i,
114 (long)s->sums[i].len, (long)n);
115 }
Andrew Tridgellc627d611996-06-22 05:04:20 +0000116
Wayne Davisona06b4192005-01-01 21:08:14 +0000117 send_token(f, i, buf, last_match, n, i < 0 ? 0 : s->sums[i].len);
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000118 data_transfer += n;
Andrew Tridgell70d794d1996-07-01 05:55:05 +0000119
Andrew Tridgella8004341998-06-01 03:42:14 +0000120 if (i >= 0) {
121 stats.matched_data += s->sums[i].len;
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000122 n += s->sums[i].len;
Andrew Tridgella8004341998-06-01 03:42:14 +0000123 }
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000124
125 for (j = 0; j < n; j += CHUNK_SIZE) {
Wayne Davisona06b4192005-01-01 21:08:14 +0000126 int32 n1 = MIN(CHUNK_SIZE, n - j);
127 sum_update(map_ptr(buf, last_match + j, n1), n1);
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000128 }
Andrew Tridgell9e31c481996-07-02 03:19:58 +0000129
130
Andrew Tridgell0d0e2e91998-03-23 14:46:03 +0000131 if (i >= 0)
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000132 last_match = offset + s->sums[i].len;
Andrew Tridgell0d0e2e91998-03-23 14:46:03 +0000133 else
134 last_match = offset;
Andrew Tridgelleb86d661998-07-02 00:47:13 +0000135
Wayne Davison0394e342005-03-05 17:51:23 +0000136 if (buf && do_progress)
Andrew Tridgell4440b8a1998-12-30 14:48:45 +0000137 show_progress(last_match, buf->file_size);
Andrew Tridgell9e31c481996-07-02 03:19:58 +0000138}
139
140
Andrew Tridgellc6e7fcb1996-07-01 23:27:19 +0000141static void hash_search(int f,struct sum_struct *s,
Wayne Davisonda9d12f2004-01-03 18:37:41 +0000142 struct map_struct *buf, OFF_T len)
Andrew Tridgellc627d611996-06-22 05:04:20 +0000143{
Wayne Davison7560c172004-08-03 08:05:23 +0000144 OFF_T offset, end, backup;
Wayne Davison7cacd472005-02-14 08:12:22 +0000145 int32 k, want_i;
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000146 char sum2[SUM_LENGTH];
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000147 uint32 s1, s2, sum;
Wayne Davison7560c172004-08-03 08:05:23 +0000148 int more;
Andrew Tridgelldebb4501998-05-06 06:21:35 +0000149 schar *map;
Andrew Tridgellc627d611996-06-22 05:04:20 +0000150
Wayne Davisona04d77b2004-07-07 08:38:40 +0000151 /* want_i is used to encourage adjacent matches, allowing the RLL
152 * coding of the output to work more efficiently. */
153 want_i = 0;
Andrew Tridgell923fa971999-01-05 01:15:32 +0000154
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000155 if (verbose > 2) {
Wayne Davisona06b4192005-01-01 21:08:14 +0000156 rprintf(FINFO, "hash search b=%ld len=%.0f\n",
157 (long)s->blength, (double)len);
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000158 }
Andrew Tridgellc627d611996-06-22 05:04:20 +0000159
Wayne Davisona06b4192005-01-01 21:08:14 +0000160 k = (int32)MIN(len, (OFF_T)s->blength);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000161
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000162 map = (schar *)map_ptr(buf, 0, k);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000163
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000164 sum = get_checksum1((char *)map, k);
165 s1 = sum & 0xFFFF;
166 s2 = sum >> 16;
167 if (verbose > 3)
Wayne Davisona06b4192005-01-01 21:08:14 +0000168 rprintf(FINFO, "sum=%.8x k=%ld\n", sum, (long)k);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000169
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000170 offset = 0;
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000171
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000172 end = len + 1 - s->sums[s->count-1].len;
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000173
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000174 if (verbose > 3) {
Wayne Davisona06b4192005-01-01 21:08:14 +0000175 rprintf(FINFO, "hash search s->blength=%ld len=%.0f count=%.0f\n",
176 (long)s->blength, (double)len, (double)s->count);
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000177 }
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000178
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000179 do {
180 tag t = gettag2(s1,s2);
181 int done_csum2 = 0;
Wayne Davison7cacd472005-02-14 08:12:22 +0000182 int32 j = tag_table[t];
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000183
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000184 if (verbose > 4)
Andrew Tridgell5f808df2000-01-23 12:30:34 +0000185 rprintf(FINFO,"offset=%.0f sum=%08x\n",(double)offset,sum);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000186
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000187 if (j == NULL_TAG)
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000188 goto null_tag;
Andrew Tridgelld9bea2d1996-06-26 15:57:54 +0000189
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000190 sum = (s1 & 0xffff) | (s2 << 16);
191 tag_hits++;
Wayne Davison066a8442004-07-04 08:07:23 +0000192 do {
Wayne Davison7cacd472005-02-14 08:12:22 +0000193 int32 l, i = targets[j].i;
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000194
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000195 if (sum != s->sums[i].sum1)
196 continue;
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000197
Andrew Tridgell536541d1999-01-05 06:43:59 +0000198 /* also make sure the two blocks are the same length */
Wayne Davisona06b4192005-01-01 21:08:14 +0000199 l = (int32)MIN((OFF_T)s->blength, len-offset);
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000200 if (l != s->sums[i].len)
201 continue;
Andrew Tridgell536541d1999-01-05 06:43:59 +0000202
Wayne Davisona36ffd32005-01-17 23:11:13 +0000203 /* in-place: ensure chunk's offset is either >= our
Wayne Davisona3221d22004-07-16 20:06:24 +0000204 * offset or that the data didn't move. */
Wayne Davisona36ffd32005-01-17 23:11:13 +0000205 if (updating_basis_file && s->sums[i].offset < offset
Wayne Davisona3221d22004-07-16 20:06:24 +0000206 && !(s->sums[i].flags & SUMFLG_SAME_OFFSET))
207 continue;
208
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000209 if (verbose > 3)
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000210 rprintf(FINFO,"potential match at %.0f target=%.0f %.0f sum=%08x\n",
211 (double)offset,(double)j,(double)i,sum);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000212
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000213 if (!done_csum2) {
Andrew Tridgelldebb4501998-05-06 06:21:35 +0000214 map = (schar *)map_ptr(buf,offset,l);
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000215 get_checksum2((char *)map,l,sum2);
216 done_csum2 = 1;
217 }
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000218
J.W. Schultzfc0257c2003-04-10 01:13:30 +0000219 if (memcmp(sum2,s->sums[i].sum2,s->s2length) != 0) {
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000220 false_alarms++;
221 continue;
222 }
Andrew Tridgell923fa971999-01-05 01:15:32 +0000223
Wayne Davisona36ffd32005-01-17 23:11:13 +0000224 /* When updating in-place, the best possible match is
Wayne Davisona3221d22004-07-16 20:06:24 +0000225 * one with an identical offset, so we prefer that over
226 * the following want_i optimization. */
Wayne Davisona36ffd32005-01-17 23:11:13 +0000227 if (updating_basis_file) {
Wayne Davisona3221d22004-07-16 20:06:24 +0000228 do {
Wayne Davison7cacd472005-02-14 08:12:22 +0000229 int32 i2 = targets[j].i;
Wayne Davisona3221d22004-07-16 20:06:24 +0000230 if (s->sums[i2].offset != offset)
231 continue;
232 if (i2 != i) {
233 if (sum != s->sums[i2].sum1)
234 break;
235 if (memcmp(sum2, s->sums[i2].sum2,
236 s->s2length) != 0)
237 break;
238 i = i2;
239 }
240 /* This chunk was at the same offset on
241 * both the sender and the receiver. */
242 s->sums[i].flags |= SUMFLG_SAME_OFFSET;
243 goto set_want_i;
244 } while (++j < s->count && targets[j].t == t);
245 }
246
Andrew Tridgell923fa971999-01-05 01:15:32 +0000247 /* we've found a match, but now check to see
Wayne Davisona04d77b2004-07-07 08:38:40 +0000248 * if want_i can hint at a better match. */
249 if (i != want_i && want_i < s->count
Wayne Davisona36ffd32005-01-17 23:11:13 +0000250 && (!updating_basis_file || s->sums[want_i].offset >= offset
Wayne Davisona3221d22004-07-16 20:06:24 +0000251 || s->sums[want_i].flags & SUMFLG_SAME_OFFSET)
Wayne Davisona04d77b2004-07-07 08:38:40 +0000252 && sum == s->sums[want_i].sum1
253 && memcmp(sum2, s->sums[want_i].sum2, s->s2length) == 0) {
Wayne Davison5e252de2004-07-02 23:35:30 +0000254 /* we've found an adjacent match - the RLL coder
255 * will be happy */
Wayne Davisona04d77b2004-07-07 08:38:40 +0000256 i = want_i;
Andrew Tridgell923fa971999-01-05 01:15:32 +0000257 }
Wayne Davisona3221d22004-07-16 20:06:24 +0000258 set_want_i:
Wayne Davisona04d77b2004-07-07 08:38:40 +0000259 want_i = i + 1;
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000260
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000261 matched(f,s,buf,offset,i);
262 offset += s->sums[i].len - 1;
Wayne Davisona06b4192005-01-01 21:08:14 +0000263 k = (int32)MIN((OFF_T)s->blength, len-offset);
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000264 map = (schar *)map_ptr(buf, offset, k);
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000265 sum = get_checksum1((char *)map, k);
266 s1 = sum & 0xFFFF;
267 s2 = sum >> 16;
268 matches++;
269 break;
Wayne Davison066a8442004-07-04 08:07:23 +0000270 } while (++j < s->count && targets[j].t == t);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000271
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000272 null_tag:
Wayne Davison7560c172004-08-03 08:05:23 +0000273 backup = offset - last_match;
274 /* We sometimes read 1 byte prior to last_match... */
275 if (backup < 0)
276 backup = 0;
277
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000278 /* Trim off the first byte from the checksum */
Wayne Davison7560c172004-08-03 08:05:23 +0000279 more = offset + k < len;
280 map = (schar *)map_ptr(buf, offset - backup, k + more + backup)
281 + backup;
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000282 s1 -= map[0] + CHAR_OFFSET;
283 s2 -= k * (map[0]+CHAR_OFFSET);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000284
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000285 /* Add on the next byte (if there is one) to the checksum */
Wayne Davison7560c172004-08-03 08:05:23 +0000286 if (more) {
287 s1 += map[k] + CHAR_OFFSET;
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000288 s2 += s1;
Wayne Davison0e36d9d2004-01-03 19:28:03 +0000289 } else
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000290 --k;
Andrew Tridgell45f133b1998-05-22 01:53:02 +0000291
Paul Mackerras5914bf11998-05-22 06:58:52 +0000292 /* By matching early we avoid re-reading the
293 data 3 times in the case where a token
294 match comes a long way after last
295 match. The 3 reads are caused by the
296 running match, the checksum update and the
297 literal send. */
Wayne Davisona06b4192005-01-01 21:08:14 +0000298 if (backup >= s->blength+CHUNK_SIZE && end-offset > CHUNK_SIZE)
299 matched(f, s, buf, offset - s->blength, -2);
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000300 } while (++offset < end);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000301
Wayne Davisona06b4192005-01-01 21:08:14 +0000302 matched(f, s, buf, len, -1);
303 map_ptr(buf, len-1, 1);
Andrew Tridgellc627d611996-06-22 05:04:20 +0000304}
305
306
Martin Poolf5f95a32002-04-08 08:23:50 +0000307/**
308 * Scan through a origin file, looking for sections that match
309 * checksums from the generator, and transmit either literal or token
310 * data.
311 *
Martin Pool538ba242002-04-08 08:33:13 +0000312 * Also calculates the MD4 checksum of the whole file, using the md
313 * accumulator. This is transmitted with the file as protection
314 * against corruption on the wire.
315 *
Martin Poolf5f95a32002-04-08 08:23:50 +0000316 * @param s Checksums received from the generator. If <tt>s->count ==
317 * 0</tt>, then there are actually no checksums for this file.
318 *
319 * @param len Length of the file to send.
320 **/
321void match_sums(int f, struct sum_struct *s, struct map_struct *buf, OFF_T len)
Andrew Tridgellc627d611996-06-22 05:04:20 +0000322{
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000323 char file_sum[MD4_SUM_LENGTH];
Andrew Tridgell9e31c481996-07-02 03:19:58 +0000324
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000325 last_match = 0;
326 false_alarms = 0;
327 tag_hits = 0;
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000328 matches = 0;
329 data_transfer = 0;
Andrew Tridgellc627d611996-06-22 05:04:20 +0000330
Wayne Davisonba582f72004-05-21 08:27:04 +0000331 sum_init(checksum_seed);
Andrew Tridgell9e31c481996-07-02 03:19:58 +0000332
Wayne Davisona06b4192005-01-01 21:08:14 +0000333 if (len > 0 && s->count > 0) {
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000334 build_hash_table(s);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000335
336 if (verbose > 2)
Andrew Tridgell94862891998-05-07 14:50:22 +0000337 rprintf(FINFO,"built hash table\n");
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000338
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000339 hash_search(f,s,buf,len);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000340
341 if (verbose > 2)
Andrew Tridgell94862891998-05-07 14:50:22 +0000342 rprintf(FINFO,"done hash search\n");
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000343 } else {
Andrew Tridgelleb86d661998-07-02 00:47:13 +0000344 OFF_T j;
345 /* by doing this in pieces we avoid too many seeks */
Wayne Davisona06b4192005-01-01 21:08:14 +0000346 for (j = CHUNK_SIZE; j < len; j += CHUNK_SIZE)
347 matched(f, s, buf, j, -2);
348 matched(f, s, buf, len, -1);
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000349 }
Andrew Tridgellc627d611996-06-22 05:04:20 +0000350
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000351 sum_end(file_sum);
Wayne Davisonedecdad2004-05-13 06:46:20 +0000352 /* If we had a read error, send a bad checksum. */
353 if (buf && buf->status != 0)
354 file_sum[0]++;
Andrew Tridgellc627d611996-06-22 05:04:20 +0000355
J.W. Schultzbc63ae32003-03-31 17:28:34 +0000356 if (verbose > 2)
357 rprintf(FINFO,"sending file_sum\n");
358 write_buf(f,file_sum,MD4_SUM_LENGTH);
Andrew Tridgellc627d611996-06-22 05:04:20 +0000359
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000360 if (targets) {
361 free(targets);
362 targets=NULL;
363 }
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000364
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000365 if (verbose > 2)
Andrew Tridgell94862891998-05-07 14:50:22 +0000366 rprintf(FINFO, "false_alarms=%d tag_hits=%d matches=%d\n",
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000367 false_alarms, tag_hits, matches);
Wayne Davison1e4f48d2003-08-22 05:51:42 +0000368
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000369 total_tag_hits += tag_hits;
370 total_false_alarms += false_alarms;
371 total_matches += matches;
Andrew Tridgella8004341998-06-01 03:42:14 +0000372 stats.literal_data += data_transfer;
Andrew Tridgellc627d611996-06-22 05:04:20 +0000373}
374
375void match_report(void)
376{
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000377 if (verbose <= 1)
378 return;
Andrew Tridgellc627d611996-06-22 05:04:20 +0000379
Andrew Tridgell94862891998-05-07 14:50:22 +0000380 rprintf(FINFO,
Andrew Tridgella8004341998-06-01 03:42:14 +0000381 "total: matches=%d tag_hits=%d false_alarms=%d data=%.0f\n",
Andrew Tridgelle7ebc361998-03-23 07:11:51 +0000382 total_matches,total_tag_hits,
Andrew Tridgella8004341998-06-01 03:42:14 +0000383 total_false_alarms,
384 (double)stats.literal_data);
Andrew Tridgellc627d611996-06-22 05:04:20 +0000385}