+ static char file_sum1[MAX_DIGEST_LEN];
+ struct map_struct *mapbuf;
+ struct sum_struct sum;
+ int32 len;
+ OFF_T offset = 0;
+ OFF_T offset2;
+ char *data;
+ int32 i;
+ char *map = NULL;
+#ifdef SUPPORT_PREALLOCATION
+#ifdef PREALLOCATE_NEEDS_TRUNCATE
+ OFF_T preallocated_len = 0;
+#endif
+
+ if (preallocate_files && fd != -1 && total_size > 0) {
+ /* Try to preallocate enough space for file's eventual length. Can
+ * reduce fragmentation on filesystems like ext4, xfs, and NTFS. */
+ if (do_fallocate(fd, 0, total_size) == 0) {
+#ifdef PREALLOCATE_NEEDS_TRUNCATE
+ preallocated_len = total_size;
+#endif
+ } else
+ rsyserr(FWARNING, errno, "do_fallocate %s", full_fname(fname));
+ }
+#endif
+
+ read_sum_head(f_in, &sum);
+
+ if (fd_r >= 0 && size_r > 0) {
+ int32 read_size = MAX(sum.blength * 2, 16*1024);
+ mapbuf = map_file(fd_r, size_r, read_size, sum.blength);
+ if (DEBUG_GTE(DELTASUM, 2)) {
+ rprintf(FINFO, "recv mapped %s of size %s\n",
+ fname_r, big_num(size_r));
+ }
+ } else
+ mapbuf = NULL;
+
+ sum_init(checksum_seed);
+
+ if (append_mode > 0) {
+ OFF_T j;
+ sum.flength = (OFF_T)sum.count * sum.blength;
+ if (sum.remainder)
+ sum.flength -= sum.blength - sum.remainder;
+ if (append_mode == 2 && mapbuf) {
+ for (j = CHUNK_SIZE; j < sum.flength; j += CHUNK_SIZE) {
+ if (INFO_GTE(PROGRESS, 1))
+ show_progress(offset, total_size);
+ sum_update(map_ptr(mapbuf, offset, CHUNK_SIZE),
+ CHUNK_SIZE);
+ offset = j;
+ }
+ if (offset < sum.flength) {
+ int32 len = (int32)(sum.flength - offset);
+ if (INFO_GTE(PROGRESS, 1))
+ show_progress(offset, total_size);
+ sum_update(map_ptr(mapbuf, offset, len), len);
+ }