Now support dynamic per-file checksum2 size.

This pushes protocol version to 27
This commit is contained in:
J.W. Schultz committed 2003-04-10 01:13:30 +00:00
1 parent 91c4da3fda
commit fc0257c9fd
5 files changed
+66 -50

No files matched your search

+22 -15
View File
@@ -116,13 +116,21 @@ static int adapt_block_size(struct file_struct *file, int bsize)
/*
send a header that says "we have no checksums" down the f_out fd
* NULL sum_struct means we have no checksums
*/
static void send_null_sums(int f_out)
void write_sum_head(int f, struct sum_struct *sum)
{
write_int(f_out, 0);
write_int(f_out, block_size);
write_int(f_out, 0);
static struct sum_struct null_sum;
if (sum == (struct sum_struct *)NULL)
sum = &null_sum;
write_int(f, sum->count);
write_int(f, sum->blength);
if (remote_version >= 27)
write_int(f, sum->s2length);
write_int(f, sum->remainder);
}
@@ -164,19 +172,18 @@ static void generate_and_send_sums(struct map_struct *buf, OFF_T len,
sum.count = (len + (block_len - 1)) / block_len;
sum.remainder = (len % block_len);
sum.n = block_len;
sum.blength = block_len;
sum.flength = len;
sum.s2length = csum_length;
/* not needed here sum.sums = NULL; */
if (sum.count && verbose > 3) {
rprintf(FINFO, "count=%ld rem=%ld n=%ld flength=%.0f\n",
(long) sum.count, (long) sum.remainder,
(long) sum.n, (double) sum.flength);
(long) sum.blength, (double) sum.flength);
}
write_int(f_out, sum.count);
write_int(f_out, sum.n);
write_int(f_out, sum.remainder);
write_sum_head(f_out, &sum);
for (i = 0; i < sum.count; i++) {
int n1 = MIN(len, block_len);
@@ -192,7 +199,7 @@ static void generate_and_send_sums(struct map_struct *buf, OFF_T len,
i, (double) offset, n1, (unsigned long) sum1);
}
write_int(f_out, sum1);
write_buf(f_out, sum2, csum_length);
write_buf(f_out, sum2, sum.s2length);
len -= n1;
offset += n1;
}
@@ -384,7 +391,7 @@ void recv_generator(char *fname, struct file_list *flist, int i, int f_out)
if (statret == -1) {
if (errno == ENOENT) {
write_int(f_out,i);
if (!dry_run) send_null_sums(f_out);
if (!dry_run) write_sum_head(f_out, NULL);
} else {
if (verbose > 1)
rprintf(FERROR, RSYNC_NAME
@@ -401,7 +408,7 @@ void recv_generator(char *fname, struct file_list *flist, int i, int f_out)
/* now pretend the file didn't exist */
write_int(f_out,i);
if (!dry_run) send_null_sums(f_out);
if (!dry_run) write_sum_head(f_out, NULL);
return;
}
@@ -430,7 +437,7 @@ void recv_generator(char *fname, struct file_list *flist, int i, int f_out)
if (disable_deltas_p()) {
write_int(f_out,i);
send_null_sums(f_out);
write_sum_head(f_out, NULL);
return;
}
@@ -441,7 +448,7 @@ void recv_generator(char *fname, struct file_list *flist, int i, int f_out)
rprintf(FERROR,RSYNC_NAME": failed to open \"%s\", continuing : %s\n",fnamecmp,strerror(errno));
/* pretend the file didn't exist */
write_int(f_out,i);
send_null_sums(f_out);
write_sum_head(f_out, NULL);
return;
}
+11 -13
View File
@@ -19,8 +19,6 @@
#include "rsync.h"
extern int csum_length;
extern int verbose;
extern int am_server;
@@ -152,11 +150,11 @@ static void hash_search(int f,struct sum_struct *s,
if (verbose > 2)
rprintf(FINFO,"hash search b=%ld len=%.0f\n",
(long) s->n, (double)len);
(long) s->blength, (double)len);
/* cast is to make s->n signed; it should always be reasonably
/* cast is to make s->blength signed; it should always be reasonably
* small */
k = MIN(len, (OFF_T) s->n);
k = MIN(len, (OFF_T) s->blength);
map = (schar *)map_ptr(buf,0,k);
@@ -171,8 +169,8 @@ static void hash_search(int f,struct sum_struct *s,
end = len + 1 - s->sums[s->count-1].len;
if (verbose > 3)
rprintf(FINFO, "hash search s->n=%ld len=%.0f count=%ld\n",
(long) s->n, (double) len, (long) s->count);
rprintf(FINFO, "hash search s->blength=%ld len=%.0f count=%ld\n",
(long) s->blength, (double) len, (long) s->count);
do {
tag t = gettag2(s1,s2);
@@ -194,7 +192,7 @@ static void hash_search(int f,struct sum_struct *s,
if (sum != s->sums[i].sum1) continue;
/* also make sure the two blocks are the same length */
l = MIN(s->n,len-offset);
l = MIN(s->blength,len-offset);
if (l != s->sums[i].len) continue;
if (verbose > 3)
@@ -207,7 +205,7 @@ static void hash_search(int f,struct sum_struct *s,
done_csum2 = 1;
}
if (memcmp(sum2,s->sums[i].sum2,csum_length) != 0) {
if (memcmp(sum2,s->sums[i].sum2,s->s2length) != 0) {
false_alarms++;
continue;
}
@@ -218,7 +216,7 @@ static void hash_search(int f,struct sum_struct *s,
int i2 = targets[j].i;
if (i2 == last_i + 1) {
if (sum != s->sums[i2].sum1) break;
if (memcmp(sum2,s->sums[i2].sum2,csum_length) != 0) break;
if (memcmp(sum2,s->sums[i2].sum2,s->s2length) != 0) break;
/* we've found an adjacent match - the RLL coder
will be happy */
i = i2;
@@ -230,7 +228,7 @@ static void hash_search(int f,struct sum_struct *s,
matched(f,s,buf,offset,i);
offset += s->sums[i].len - 1;
k = MIN((len-offset), s->n);
k = MIN((len-offset), s->blength);
map = (schar *)map_ptr(buf,offset,k);
sum = get_checksum1((char *)map, k);
s1 = sum & 0xFFFF;
@@ -260,9 +258,9 @@ static void hash_search(int f,struct sum_struct *s,
running match, the checksum update and the
literal send. */
if (offset > last_match &&
offset-last_match >= CHUNK_SIZE+s->n &&
offset-last_match >= CHUNK_SIZE+s->blength &&
(end-offset > CHUNK_SIZE)) {
matched(f,s,buf,offset - s->n, -2);
matched(f,s,buf,offset - s->blength, -2);
}
} while (++offset < end);
+7 -8
View File
@@ -230,7 +230,8 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname,
OFF_T total_size)
{
int i;
unsigned int n,remainder,len,count;
struct sum_struct sum;
unsigned int len;
OFF_T offset = 0;
OFF_T offset2;
char *data;
@@ -238,9 +239,7 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname,
static char file_sum2[MD4_SUM_LENGTH];
char *map=NULL;
count = read_int(f_in);
n = read_int(f_in);
remainder = read_int(f_in);
read_sum_head(f_in, &sum);
sum_init();
@@ -270,10 +269,10 @@ static int receive_data(int f_in,struct map_struct *buf,int fd,char *fname,
}
i = -(i+1);
offset2 = i*(OFF_T)n;
len = n;
if (i == (int) count-1 && remainder != 0)
len = remainder;
offset2 = i*(OFF_T)sum.blength;
len = sum.blength;
if (i == (int) sum.count-1 && sum.remainder != 0)
len = sum.remainder;
stats.matched_data += len;
+3 -2
View File
@@ -50,7 +50,7 @@
#define SAME_TIME (1<<7)
/* update this if you make incompatible changes */
#define PROTOCOL_VERSION 26
#define PROTOCOL_VERSION 27
/* We refuse to interoperate with versions that are not in this range.
* Note that we assume we'll work with later versions: the onus is on
@@ -408,7 +408,8 @@ struct sum_struct {
OFF_T flength; /**< total file length */
size_t count; /**< how many chunks */
size_t remainder; /**< flength % block_length */
size_t n; /**< block_length */
size_t blength; /**< block_length */
size_t s2length; /**< sum2_length */
struct sum_buf *sums; /**< points to info for each chunk */
};
+23 -12
View File
@@ -36,6 +36,21 @@ extern int am_server;
**/
void read_sum_head(int f, struct sum_struct *sum)
{
extern int remote_version;
sum->count = read_int(f);
sum->blength = read_int(f);
if (remote_version < 27)
{
sum->s2length = csum_length;
} else {
sum->s2length = read_int(f);
}
sum->remainder = read_int(f);
}
/**
* Receive the checksums for a buffer
**/
@@ -48,14 +63,14 @@ static struct sum_struct *receive_sums(int f)
s = (struct sum_struct *)malloc(sizeof(*s));
if (!s) out_of_memory("receive_sums");
s->count = read_int(f);
s->n = read_int(f);
s->remainder = read_int(f);
read_sum_head(f, s);
s->sums = NULL;
if (verbose > 3)
rprintf(FINFO,"count=%ld n=%ld rem=%ld\n",
(long) s->count, (long) s->n, (long) s->remainder);
(long) s->count, (long) s->blength,
(long) s->remainder);
if (s->count == 0)
return(s);
@@ -65,7 +80,7 @@ static struct sum_struct *receive_sums(int f)
for (i=0; i < (int) s->count;i++) {
s->sums[i].sum1 = read_int(f);
read_buf(f,s->sums[i].sum2,csum_length);
read_buf(f,s->sums[i].sum2,s->s2length);
s->sums[i].offset = offset;
s->sums[i].i = i;
@@ -73,7 +88,7 @@ static struct sum_struct *receive_sums(int f)
if (i == (int) s->count-1 && s->remainder != 0) {
s->sums[i].len = s->remainder;
} else {
s->sums[i].len = s->n;
s->sums[i].len = s->blength;
}
offset += s->sums[i].len;
@@ -210,9 +225,7 @@ void send_files(struct file_list *flist,int f_out,int f_in)
if (write_batch)
write_batch_delta_file((char *)&i,sizeof(i));
write_int(f_out,s->count);
write_int(f_out,s->n);
write_int(f_out,s->remainder);
write_sum_head(f_out, s);
}
if (verbose > 2)
@@ -239,9 +252,7 @@ void send_files(struct file_list *flist,int f_out,int f_in)
}
else {
write_int(f_out,j);
write_int(f_out,s->count);
write_int(f_out,s->n);
write_int(f_out,s->remainder);
write_sum_head(f_out, s);
done=0;
while (!done) {
read_batch_delta_file( (char *) &buff_len, sizeof(int) );