* Generate and send a stream of signatures/checksums that describe a buffer * * Generate approximately one checksum every block_len bytes. */
| 773 | * Generate approximately one checksum every block_len bytes. |
| 774 | */ |
| 775 | static int generate_and_send_sums(int fd, OFF_T len, int f_out, int f_copy) |
| 776 | { |
| 777 | int32 i; |
| 778 | struct map_struct *mapbuf; |
| 779 | struct sum_struct sum; |
| 780 | OFF_T offset = 0; |
| 781 | |
| 782 | sum_sizes_sqroot(&sum, len); |
| 783 | if (sum.count < 0) |
| 784 | return -1; |
| 785 | write_sum_head(f_out, &sum); |
| 786 | |
| 787 | if (append_mode > 0 && f_copy < 0) |
| 788 | return 0; |
| 789 | |
| 790 | if (len > 0) |
| 791 | mapbuf = map_file(fd, len, MAX_MAP_SIZE, sum.blength); |
| 792 | else |
| 793 | mapbuf = NULL; |
| 794 | |
| 795 | for (i = 0; i < sum.count; i++) { |
| 796 | int32 n1 = (int32)MIN(len, (OFF_T)sum.blength); |
| 797 | char *map = map_ptr(mapbuf, offset, n1); |
| 798 | char sum2[MAX_DIGEST_LEN]; |
| 799 | uint32 sum1; |
| 800 | |
| 801 | len -= n1; |
| 802 | offset += n1; |
| 803 | |
| 804 | if (f_copy >= 0) { |
| 805 | full_write(f_copy, map, n1); |
| 806 | if (append_mode > 0) |
| 807 | continue; |
| 808 | } |
| 809 | |
| 810 | sum1 = get_checksum1(map, n1); |
| 811 | get_checksum2(map, n1, sum2); |
| 812 | |
| 813 | if (DEBUG_GTE(DELTASUM, 3)) { |
| 814 | rprintf(FINFO, |
| 815 | "chunk[%s] offset=%s len=%ld sum1=%08lx\n", |
| 816 | big_num(i), big_num(offset - n1), (long)n1, |
| 817 | (unsigned long)sum1); |
| 818 | } |
| 819 | write_int(f_out, sum1); |
| 820 | write_buf(f_out, sum2, sum.s2length); |
| 821 | } |
| 822 | |
| 823 | if (mapbuf) |
| 824 | unmap_file(mapbuf); |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | |
| 829 | |
| 830 | /* Try to find a filename in the same dir as "fname" with a similar name. */ |
no test coverage detected