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