Line data Source code
1 : #include "../../burp.h"
2 : #include "../backup_phase1.h"
3 :
4 : #include <math.h>
5 :
6 : // Use the same MAX_BLOCK_SIZE as rsync.
7 : #define MAX_BLOCK_SIZE ((uint32_t)1 << 17)
8 :
9 : /* Need to base librsync block length on the size of the old file, otherwise
10 : the risk of librsync collisions and silent corruption increases as the
11 : size of the new file gets bigger. */
12 14 : size_t get_librsync_block_len(const char *endfile)
13 : {
14 14 : size_t ret=0;
15 14 : uint64_t oldlen=0;
16 14 : oldlen=strtoull(endfile, NULL, 10);
17 14 : ret=(size_t)(ceil(sqrt(oldlen)/16)*16); // round to a multiple of 16.
18 14 : if(ret<64) return 64; // minimum of 64 bytes.
19 11 : if(ret>MAX_BLOCK_SIZE) return MAX_BLOCK_SIZE;
20 9 : return ret;
21 : }
|