From 43a481dc5586a16af249fbae611b36442bed6a8c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 27 Jun 1996 05:16:15 +0000 Subject: [PATCH] added csum-length option --- checksum.c | 6 +++++- compat.c | 6 ++++-- flist.c | 6 ++++-- main.c | 16 +++++++++++++++- match.c | 4 +++- rsync.c | 8 +++++--- 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/checksum.c b/checksum.c index cdd554fd..b656ef90 100644 --- a/checksum.c +++ b/checksum.c @@ -19,6 +19,7 @@ #include "rsync.h" +extern int csum_length; /* a simple 32 bit checksum that can be upadted from either end @@ -52,8 +53,11 @@ void get_checksum2(char *buf,int len,char *sum) bcopy(buf+i,buf2,len-i); MDupdate(&MD, buf2, (len-i)*8); SIVAL(sum,0,MD.buffer[0]); + if (csum_length <= 4) return; SIVAL(sum,4,MD.buffer[1]); + if (csum_length <= 8) return; SIVAL(sum,8,MD.buffer[2]); + if (csum_length <= 12) return; SIVAL(sum,12,MD.buffer[3]); } @@ -61,7 +65,7 @@ void file_checksum(char *fname,char *sum,off_t size) { char *buf; int fd; - bzero(sum,SUM_LENGTH); + bzero(sum,csum_length); fd = open(fname,O_RDONLY); if (fd == -1) return; diff --git a/compat.c b/compat.c index 2b72f9ba..64808a04 100644 --- a/compat.c +++ b/compat.c @@ -21,6 +21,8 @@ #include "rsync.h" +extern int csum_length; + extern int preserve_links; extern int preserve_perms; extern int preserve_devices; @@ -93,7 +95,7 @@ void send_file_entry_v10(struct file_struct *file,int f) #endif if (always_checksum) { - write_buf(f,file->sum,SUM_LENGTH); + write_buf(f,file->sum,csum_length); } last_mode = file->mode; @@ -159,7 +161,7 @@ void receive_file_entry_v10(struct file_struct *file, #endif if (always_checksum) - read_buf(f,file->sum,SUM_LENGTH); + read_buf(f,file->sum,csum_length); last_mode = file->mode; last_dev = file->dev; diff --git a/flist.c b/flist.c index 43d5533e..a89f6f5b 100644 --- a/flist.c +++ b/flist.c @@ -21,6 +21,8 @@ #include "rsync.h" +extern int csum_length; + extern int verbose; extern int am_server; extern int always_checksum; @@ -137,7 +139,7 @@ void send_file_entry_v11(struct file_struct *file,int f) #endif if (always_checksum) { - write_buf(f,file->sum,SUM_LENGTH); + write_buf(f,file->sum,csum_length); } last_mode = file->mode; @@ -199,7 +201,7 @@ void receive_file_entry_v11(struct file_struct *file, #endif if (always_checksum) - read_buf(f,file->sum,SUM_LENGTH); + read_buf(f,file->sum,csum_length); last_mode = file->mode; last_dev = file->dev; diff --git a/main.c b/main.c index 0af90e58..95c6fdeb 100644 --- a/main.c +++ b/main.c @@ -44,6 +44,7 @@ int ignore_times=0; int delete_mode=0; int one_file_system=0; int remote_version=0; +int csum_length=SUM_LENGTH; int am_server = 0; static int sender = 0; @@ -88,6 +89,7 @@ static void server_options(char **args,int *argc) int ac = *argc; static char argstr[50]; static char bsize[30]; + static char slength[30]; int i, x; args[ac++] = "--server"; @@ -135,6 +137,11 @@ static void server_options(char **args,int *argc) sprintf(bsize,"-B%d",block_size); args[ac++] = bsize; } + + if (csum_length != SUM_LENGTH) { + sprintf(slength,"--csum-length=%d",csum_length); + args[ac++] = slength; + } if (delete_mode) args[ac++] = "--delete"; @@ -369,6 +376,7 @@ static void usage(FILE *f) fprintf(f," --exclude FILE exclude file FILE\n"); fprintf(f," --exclude-from FILE exclude files listed in FILE\n"); fprintf(f," --suffix SUFFIX override backup suffix\n"); + fprintf(f," --csum-length LENGTH set the checksum length\n"); fprintf(f," --version print version number\n"); fprintf(f,"\n"); @@ -377,7 +385,7 @@ static void usage(FILE *f) } enum {OPT_VERSION,OPT_SUFFIX,OPT_SENDER,OPT_SERVER,OPT_EXCLUDE, - OPT_EXCLUDE_FROM,OPT_DELETE,OPT_RSYNC_PATH}; + OPT_EXCLUDE_FROM,OPT_DELETE,OPT_RSYNC_PATH,OPT_CSUM_LENGTH}; static char *short_options = "oblpguDCtcahvrIxne:B:"; @@ -389,6 +397,7 @@ static struct option long_options[] = { {"exclude", 1, 0, OPT_EXCLUDE}, {"exclude-from",1, 0, OPT_EXCLUDE_FROM}, {"rsync-path", 1, 0, OPT_RSYNC_PATH}, + {"csum-length", 1, 0, OPT_CSUM_LENGTH}, {"one-file-system",0, 0, 'x'}, {"ignore-times",0, 0, 'I'}, {"help", 0, 0, 'h'}, @@ -445,6 +454,11 @@ int main(int argc,char *argv[]) rsync_path = optarg; break; + case OPT_CSUM_LENGTH: + csum_length = atoi(optarg); + csum_length = MIN(csum_length,SUM_LENGTH); + break; + case 'I': ignore_times = 1; break; diff --git a/match.c b/match.c index ee22ca3e..a2121a17 100644 --- a/match.c +++ b/match.c @@ -19,6 +19,8 @@ #include "rsync.h" +extern int csum_length; + extern int verbose; extern int am_server; @@ -170,7 +172,7 @@ static void hash_search(int f,struct sum_struct *s,char *buf,off_t len) get_checksum2(map,l,sum2); done_csum2 = 1; } - if (memcmp(sum2,s->sums[i].sum2,SUM_LENGTH) == 0) { + if (memcmp(sum2,s->sums[i].sum2,csum_length) == 0) { matched(f,s,buf,len,offset,i); offset += s->sums[i].len - 1; k = MIN((len-offset), s->n); diff --git a/rsync.c b/rsync.c index 570dfef0..c9ffa784 100644 --- a/rsync.c +++ b/rsync.c @@ -19,6 +19,8 @@ #include "rsync.h" +extern int csum_length; + extern int verbose; extern int am_server; extern int always_checksum; @@ -67,7 +69,7 @@ static void send_sums(struct sum_struct *s,int f_out) if (s) for (i=0;icount;i++) { write_int(f_out,s->sums[i].sum1); - write_buf(f_out,s->sums[i].sum2,SUM_LENGTH); + write_buf(f_out,s->sums[i].sum2,csum_length); } write_flush(f_out); } @@ -164,7 +166,7 @@ static struct sum_struct *receive_sums(int f) for (i=0;icount;i++) { s->sums[i].sum1 = read_int(f); - read_buf(f,s->sums[i].sum2,SUM_LENGTH); + read_buf(f,s->sums[i].sum2,csum_length); s->sums[i].offset = offset; s->sums[i].i = i; @@ -343,7 +345,7 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out) if (st.st_size == flist->files[i].length && ((!ignore_times && st.st_mtime == flist->files[i].modtime) || (always_checksum && S_ISREG(st.st_mode) && - memcmp(sum,flist->files[i].sum,SUM_LENGTH) == 0))) { + memcmp(sum,flist->files[i].sum,csum_length) == 0))) { set_perms(fname,&flist->files[i],&st,1); return; } -- 2.34.1