10 char rsync_flist_file[27] = "rsync_flist.";
11 char rsync_csums_file[27] = "rsync_csums.";
12 char rsync_delta_file[27] = "rsync_delta.";
13 char rsync_argvs_file[27] = "rsync_argvs.";
15 char batch_file_ext[15];
22 struct file_list *batch_flist;
24 void create_batch_file_ext()
27 time_t elapsed_seconds;
29 /* Save run date and time to use for batch file extensions */
30 time(&elapsed_seconds);
31 timeptr = localtime(&elapsed_seconds);
33 sprintf(batch_file_ext, "%4d%02d%02d%02d%02d%02d",
34 timeptr->tm_year+1900, timeptr->tm_mon+1, timeptr->tm_mday,
35 timeptr->tm_hour, timeptr->tm_min, timeptr->tm_sec);
38 void set_batch_file_ext(char *ext)
40 strcpy(batch_file_ext, ext);
43 void write_batch_flist_file(char *buff, int bytes_to_write)
47 /* Set up file extension */
48 strcat(rsync_flist_file, batch_file_ext);
50 /* Open batch flist file for writing; create it if it doesn't exist */
51 fdb = do_open(rsync_flist_file, O_WRONLY|O_CREAT|O_TRUNC,
54 rprintf(FERROR, "Batch file %s open error: %s\n",
55 rsync_flist_file, strerror(errno));
62 /* Write buffer to batch flist file */
64 if ( write(fdb, buff, bytes_to_write) == -1 ) {
65 rprintf(FERROR, "Batch file %s write error: %s\n",
66 rsync_flist_file, strerror(errno));
77 void write_batch_flist_info(int flist_count, struct file_struct **fptr)
82 /* Write flist info to batch file */
84 bytes_to_write = sizeof(unsigned) +
96 for (i=0; i<flist_count; i++) {
97 write_batch_flist_file( (char *) fptr[i], bytes_to_write);
98 write_char_bufs(fptr[i]->basename);
99 write_char_bufs(fptr[i]->dirname);
100 write_char_bufs(fptr[i]->basedir);
101 write_char_bufs(fptr[i]->link);
102 if (i==flist_count - 1) {
105 write_char_bufs(fptr[i]->sum);
110 void write_char_bufs(char *buf)
112 /* Write the size of the string which will follow */
116 SIVAL(b,0,strlen(buf));
121 write_batch_flist_file(b, sizeof(int));
123 /* Write the string if there is one */
126 write_batch_flist_file(buf, strlen(buf));
130 void write_batch_argvs_file(int orig_argc, int argc, char **argv)
136 strcat(rsync_argvs_file, batch_file_ext);
139 /* Open batch argvs file for writing; create it if it doesn't exist */
140 fdb = do_open(rsync_argvs_file, O_WRONLY|O_CREAT|O_TRUNC,
141 S_IREAD|S_IWRITE|S_IEXEC);
143 rprintf(FERROR, "Batch file %s open error: %s\n", rsync_argvs_file,
149 /* Write argvs info to batch file */
151 for (i=argc - orig_argc;i<argc;i++) {
152 if ( !strcmp(argv[i],"-F") ){ /* safer to change it here than script*/
153 strncat(buff,"-f ",3); /* chg to -f + ext to get ready for remote */
154 strncat(buff,batch_file_ext,strlen(batch_file_ext));
157 strncat(buff,argv[i],strlen(argv[i]));
160 if (i < (argc - 1)) {
164 if (!write(fdb, buff, strlen(buff))) {
165 rprintf(FERROR, "Batch file %s write error: %s\n",
166 rsync_argvs_file, strerror(errno));
173 struct file_list *create_flist_from_batch()
180 batch_flist = (struct file_list *)malloc(sizeof(batch_flist[0]));
182 out_of_memory("create_flist_from_batch");
184 batch_flist->count=0;
185 batch_flist->malloced=1000;
186 batch_flist->files = (struct file_struct **)malloc(sizeof(batch_flist->files[0])* batch_flist->malloced);
187 if (!batch_flist->files) {
188 out_of_memory("create_flist_from_batch"); /* dw -- will exit */
191 for ( flags=read_batch_flags() ; flags; flags=read_batch_flags() ) {
193 int i = batch_flist->count;
195 if (i >= batch_flist->malloced) {
196 if (batch_flist->malloced < 1000)
197 batch_flist->malloced += 1000;
199 batch_flist->malloced *= 2;
200 batch_flist->files =(struct file_struct **)realloc(batch_flist->files,
201 sizeof(batch_flist->files[0])*
202 batch_flist->malloced);
203 if (!batch_flist->files)
204 out_of_memory("create_flist_from_batch");
206 read_batch_flist_info(&batch_flist->files[i]);
207 batch_flist->files[i]->flags = flags;
209 batch_flist->count++;
216 int read_batch_flist_file(char *buff, int len)
222 /* Set up file extension */
223 strcat(rsync_flist_file, batch_file_ext);
225 /* Open batch flist file for reading */
226 fdb = do_open(rsync_flist_file, O_RDONLY, 0);
228 rprintf(FERROR, "Batch file %s open error: %s\n", rsync_flist_file,
236 /* Read flist batch file */
238 bytes_read = read(fdb, buff, len);
240 if (bytes_read == -1) {
241 rprintf(FERROR, "Batch file %s read error: %s\n",
242 rsync_flist_file, strerror(errno));
246 if (bytes_read == 0) { /* EOF */
252 unsigned char read_batch_flags()
256 if (read_batch_flist_file((char *)&flags, 4) ) {
264 void read_batch_flist_info(struct file_struct **fptr)
267 char char_str_len[4];
269 struct file_struct *file;
271 file = (struct file_struct *)malloc(sizeof(*file));
272 if (!file) out_of_memory("read_batch_flist_info");
273 memset((char *)file, 0, sizeof(*file));
277 read_batch_flist_file((char *)&file->modtime, sizeof(time_t));
278 read_batch_flist_file((char *)&file->length, sizeof(OFF_T));
279 read_batch_flist_file((char *)&file->mode, sizeof(mode_t));
280 read_batch_flist_file((char *)&file->inode, sizeof(INO_T));
281 read_batch_flist_file((char *)&file->dev, sizeof(dev_t));
282 read_batch_flist_file((char *)&file->rdev, sizeof(dev_t));
283 read_batch_flist_file((char *)&file->uid, sizeof(uid_t));
284 read_batch_flist_file((char *)&file->gid, sizeof(gid_t));
285 read_batch_flist_file(char_str_len, sizeof(char_str_len));
286 int_str_len = IVAL(char_str_len,0);
287 if (int_str_len > 0) {
288 read_batch_flist_file(buff, int_str_len);
289 buff[int_str_len] = '\0';
290 file->basename = strdup(buff);
293 file->basename = NULL;
296 read_batch_flist_file(char_str_len, sizeof(char_str_len));
297 int_str_len = IVAL(char_str_len,0);
298 if (int_str_len > 0) {
299 read_batch_flist_file(buff, int_str_len);
300 buff[int_str_len] = '\0';
301 file[0].dirname = strdup(buff);
304 file[0].dirname = NULL;
307 read_batch_flist_file(char_str_len, sizeof(char_str_len));
308 int_str_len = IVAL(char_str_len,0);
309 if (int_str_len > 0) {
310 read_batch_flist_file(buff, int_str_len);
311 buff[int_str_len] = '\0';
312 file[0].basedir = strdup(buff);
315 file[0].basedir = NULL;
318 read_batch_flist_file(char_str_len, sizeof(char_str_len));
319 int_str_len = IVAL(char_str_len,0);
320 if (int_str_len > 0) {
321 read_batch_flist_file(buff, int_str_len);
322 buff[int_str_len] = '\0';
323 file[0].link = strdup(buff);
329 read_batch_flist_file(char_str_len, sizeof(char_str_len));
330 int_str_len = IVAL(char_str_len,0);
331 if (int_str_len > 0) {
332 read_batch_flist_file(buff, int_str_len);
333 buff[int_str_len] = '\0';
334 file[0].sum = strdup(buff);
341 void write_batch_csums_file(char *buff, int bytes_to_write)
344 static int fdb_open = 1;
347 /* Set up file extension */
348 strcat(rsync_csums_file, batch_file_ext);
350 /* Open batch csums file for writing; create it if it doesn't exist */
351 fdb = do_open(rsync_csums_file, O_WRONLY|O_CREAT|O_TRUNC,
354 rprintf(FERROR, "Batch file %s open error: %s\n",
355 rsync_csums_file, strerror(errno));
362 /* Write buffer to batch csums file */
364 if ( write(fdb, buff, bytes_to_write) == -1 ) {
365 rprintf(FERROR, "Batch file %s write error: %s\n",
366 rsync_csums_file, strerror(errno));
372 void close_batch_csums_file()
378 void write_batch_csum_info(int *flist_entry, int flist_count, struct sum_struct *s)
382 extern int block_size;
383 extern int csum_length;
387 /* Write csum info to batch file */
389 write_batch_csums_file ( (char *) flist_entry, sizeof(int) );
390 write_batch_csums_file ( (char *) (s?&s->count:&int_zero), sizeof(int) );
392 for (i=0; i < s->count; i++) {
393 write_batch_csums_file( (char *) &s->sums[i].sum1, sizeof(uint32));
394 if ( (*flist_entry == flist_count - 1) && (i == s->count - 1) ) {
397 write_batch_csums_file( s->sums[i].sum2, csum_length);
402 int read_batch_csums_file(char *buff, int len)
404 static int fdb_open = 1;
409 /* Set up file extension */
410 strcat(rsync_csums_file, batch_file_ext);
412 /* Open batch flist file for reading */
413 fdb = do_open(rsync_csums_file, O_RDONLY, 0);
415 rprintf(FERROR, "Batch file %s open error: %s\n", rsync_csums_file,
423 /* Read csums batch file */
425 bytes_read = read(fdb, buff, len);
427 if (bytes_read == -1) {
428 rprintf(FERROR, "Batch file %s read error: %s\n",
429 rsync_csums_file, strerror(errno));
437 void read_batch_csum_info(int flist_entry, struct sum_struct *s, int *checksums_match)
440 int file_flist_entry;
443 char file_sum2[SUM_LENGTH];
444 extern int csum_length;
447 read_batch_csums_file((char *)&file_flist_entry, sizeof(int));
448 if (file_flist_entry != flist_entry) {
449 rprintf(FINFO,"file_list_entry NE flist_entry\n");
450 rprintf(FINFO,"file_flist_entry = %d flist_entry = %d\n", file_flist_entry, flist_entry);
456 read_batch_csums_file((char *)&file_chunk_ct, sizeof(int));
457 *checksums_match = 1;
458 for (i = 0;i < file_chunk_ct;i++) {
460 read_batch_csums_file((char *)&file_sum1, sizeof(uint32));
461 read_batch_csums_file(file_sum2, csum_length);
463 if ( (s->sums[i].sum1 != file_sum1) ||
464 ( memcmp(s->sums[i].sum2,file_sum2, csum_length)!=0) ) {
465 *checksums_match = 0;
472 void write_batch_delta_file(char *buff, int bytes_to_write)
474 static int fdb_delta_open = 1;
476 if (fdb_delta_open) {
477 /* Set up file extension */
478 strcat(rsync_delta_file, batch_file_ext);
480 /* Open batch delta file for writing; create it if it doesn't exist */
481 fdb_delta = do_open(rsync_delta_file, O_WRONLY|O_CREAT|O_TRUNC,
483 if (fdb_delta == -1) {
484 rprintf(FERROR, "Batch file %s open error: %s\n",
485 rsync_delta_file, strerror(errno));
492 /* Write buffer to batch delta file */
494 if ( write(fdb_delta, buff, bytes_to_write) == -1 ) {
495 rprintf(FERROR, "Batch file %s write error: %s\n",
496 rsync_delta_file, strerror(errno));
501 void close_batch_delta_file()
507 int read_batch_delta_file(char *buff, int len)
509 static int fdb_delta_open = 1;
512 if (fdb_delta_open) {
514 /* Set up file extension */
515 strcat(rsync_delta_file, batch_file_ext);
517 /* Open batch flist file for reading */
518 fdb_delta = do_open(rsync_delta_file, O_RDONLY, 0);
519 if (fdb_delta == -1) {
520 rprintf(FERROR, "Batch file %s open error: %s\n", rsync_delta_file,
528 /* Read delta batch file */
530 bytes_read = read(fdb_delta, buff, len);
532 if (bytes_read == -1) {
533 rprintf(FERROR, "Batch file %s read error: %s\n",
534 rsync_delta_file, strerror(errno));
542 void show_flist(int index, struct file_struct **fptr)
544 /* for debugging show_flist(flist->count, flist->files **/
547 for (i=0;i<index;i++) {
548 rprintf(FINFO,"flist->flags=%x\n",fptr[i]->flags);
549 rprintf(FINFO,"flist->modtime=%x\n",fptr[i]->modtime);
550 rprintf(FINFO,"flist->length=%x\n",fptr[i]->length);
551 rprintf(FINFO,"flist->mode=%x\n",fptr[i]->mode);
552 rprintf(FINFO,"flist->basename=%s\n",fptr[i]->basename);
553 if (fptr[i]->dirname)
554 rprintf(FINFO,"flist->dirname=%s\n",fptr[i]->dirname);
555 if (fptr[i]->basedir)
556 rprintf(FINFO,"flist->basedir=%s\n",fptr[i]->basedir);
560 void show_argvs(int argc, char *argv[])
565 rprintf(FINFO,"BATCH.C:show_argvs,argc=%d\n",argc);
566 for (i=0;i<argc;i++) {
568 rprintf(FINFO,"i=%d,argv[i]=%s\n",i,argv[i]);