2 Copyright (C) Andrew Tridgell 1996
3 Copyright (C) Paul Mackerras 1996
5 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.
10 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.
15 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.
23 extern int remote_version
;
24 extern int csum_length
;
25 extern struct stats stats
;
32 receive the checksums for a buffer
34 static struct sum_struct
*receive_sums(int f
)
40 s
= (struct sum_struct
*)malloc(sizeof(*s
));
41 if (!s
) out_of_memory("receive_sums");
43 s
->count
= read_int(f
);
45 s
->remainder
= read_int(f
);
49 rprintf(FINFO
,"count=%d n=%d rem=%d\n",
50 s
->count
,s
->n
,s
->remainder
);
55 s
->sums
= (struct sum_buf
*)malloc(sizeof(s
->sums
[0])*s
->count
);
56 if (!s
->sums
) out_of_memory("receive_sums");
58 for (i
=0;i
<s
->count
;i
++) {
59 s
->sums
[i
].sum1
= read_int(f
);
60 read_buf(f
,s
->sums
[i
].sum2
,csum_length
);
62 s
->sums
[i
].offset
= offset
;
65 if (i
== s
->count
-1 && s
->remainder
!= 0) {
66 s
->sums
[i
].len
= s
->remainder
;
68 s
->sums
[i
].len
= s
->n
;
70 offset
+= s
->sums
[i
].len
;
73 rprintf(FINFO
,"chunk[%d] len=%d offset=%d sum1=%08x\n",
74 i
,s
->sums
[i
].len
,(int)s
->sums
[i
].offset
,s
->sums
[i
].sum1
);
84 void send_files(struct file_list
*flist
,int f_out
,int f_in
)
88 struct map_struct
*buf
;
90 char fname
[MAXPATHLEN
];
92 struct file_struct
*file
;
94 extern struct stats stats
;
95 struct stats initial_stats
;
98 rprintf(FINFO
,"send_files starting\n");
100 setup_readbuffer(f_in
);
107 if (phase
==0 && remote_version
>= 13) {
109 csum_length
= SUM_LENGTH
;
112 rprintf(FINFO
,"send_files phase=%d\n",phase
);
118 if (i
< 0 || i
>= flist
->count
) {
119 rprintf(FERROR
,"Invalid file index %d (count=%d)\n",
121 exit_cleanup(RERR_PROTOCOL
);
124 file
= flist
->files
[i
];
126 stats
.num_transferred_files
++;
127 stats
.total_transferred_size
+= file
->length
;
131 strlcpy(fname
,file
->basedir
,MAXPATHLEN
);
132 if (strlen(fname
) == MAXPATHLEN
-1) {
134 rprintf(FERROR
, "send_files failed on long-named directory %s\n",
138 strlcat(fname
,"/",MAXPATHLEN
);
139 offset
= strlen(file
->basedir
)+1;
141 strlcat(fname
,f_name(file
),MAXPATHLEN
);
144 rprintf(FINFO
,"send_files(%d,%s)\n",i
,fname
);
148 log_transfer(file
, fname
+offset
);
154 initial_stats
= stats
;
156 s
= receive_sums(f_in
);
159 rprintf(FERROR
,"receive_sums failed\n");
163 fd
= do_open(fname
, O_RDONLY
, 0);
166 rprintf(FERROR
,"send_files failed to open %s: %s\n",
167 fname
,strerror(errno
));
172 /* map the local file */
173 if (do_fstat(fd
,&st
) != 0) {
175 rprintf(FERROR
,"fstat failed : %s\n",strerror(errno
));
181 if (st
.st_size
> 0) {
182 buf
= map_file(fd
,st
.st_size
);
188 rprintf(FINFO
,"send_files mapped %s of size %d\n",
189 fname
,(int)st
.st_size
);
193 write_int(f_out
,s
->count
);
194 write_int(f_out
,s
->n
);
195 write_int(f_out
,s
->remainder
);
198 rprintf(FINFO
,"calling match_sums %s\n",fname
);
201 log_transfer(file
, fname
+offset
);
204 set_compression(fname
);
206 match_sums(f_out
,s
,buf
,st
.st_size
);
208 log_send(file
, &initial_stats
);
210 if (buf
) unmap_file(buf
);
216 rprintf(FINFO
,"sender finished %s\n",fname
);
220 rprintf(FINFO
,"send files finished\n");