1 /* Cumulus: Efficient Filesystem Backup to the Cloud
2 * Copyright (C) 2013 The Cumulus Developers
3 * See the AUTHORS file for a list of contributors.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 /* Small utility program for computing chunk breakpoints for subfile
21 * signatures. This can be used by the Python database rebuilder; while the
22 * Python code can compute chunk breakpoints the C++ version runs much more
25 * Protocol: The input is binary, consisting of a 4-byte record, giving the
26 * length of a data buffer in network byte order, followed by the raw data.
27 * The output is line-oriented: each line consists of whitespace-separated
28 * integers giving the computed breakpoints. An input with a specified length
29 * of zero ends the computation. */
31 #include <arpa/inet.h>
36 #include "third_party/chunk.h"
38 #define MAX_BUFSIZE (1 << 24)
40 int main(int, char **)
42 char *buf = new char[MAX_BUFSIZE];
43 size_t *breakpoints = new size_t[chunk_compute_max_num_breaks(MAX_BUFSIZE)];
47 if (fread(&blocklen, 4, 1, stdin) != 1) {
48 /* Unexpected end of input or other error. */
52 blocklen = ntohl(blocklen);
55 if (blocklen < 0 || blocklen > MAX_BUFSIZE)
58 if (fread(buf, 1, blocklen, stdin) != static_cast<size_t>(blocklen))
61 int num_breakpoints = chunk_compute_breaks(buf, blocklen, breakpoints);
62 for (int i = 0; i < num_breakpoints; i++) {
63 printf("%zd%c", breakpoints[i],
64 i == num_breakpoints - 1 ? '\n' : ' ');