1 /* Cumulus: Smart Filesystem Backup to Dumb Servers
3 * Copyright (C) 2008 The Regents of the University of California
4 * Written by Michael Vrable <mvrable@cs.ucsd.edu>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 /* Allow for sub-file incremental backups: if only a portion of a file changes,
22 * allow the new data to be written out, and the old data to simply be
23 * referenced from the new metadata log. */
25 #ifndef _LBS_SUBFILE_H
26 #define _LBS_SUBFILE_H
37 #include "third_party/chunk.h"
41 Subfile(LocalDb *localdb);
44 // Prepare to compute a subfile incremental by loading signatures for data
46 void load_old_blocks(const std::list<ObjectReference> &blocks);
48 // Break a new block of data into small chunks, and compute checksums of
49 // the chunks. After doing so, a delta can be computed, or the signatures
50 // can be written out to the database. The caller must not modify the
51 // buffer until all operations referring to it are finished.
52 void analyze_new_block(const char *buf, size_t len);
54 // Store the signatures for the most recently-analyzed block in the local
55 // database (linked to the specified object), if the block is sufficiently
56 // large. If signatures already exist, they will be overwritten.
57 void store_analyzed_signatures(ObjectReference ref);
59 std::list<ObjectReference> create_incremental(TarSegmentStore *tss,
63 static const int HASH_SIZE = 20;
71 struct block_summary {
74 struct chunk_info *chunks;
78 bool checksums_loaded;
79 std::set<ObjectReference> old_blocks;
80 std::vector<block_summary> block_list;
81 std::map<std::string, std::pair<int, int> > chunk_index;
83 bool new_block_summary_valid;
84 block_summary new_block_summary;
86 const char *analyzed_buf;
89 void ensure_signatures_loaded();
90 void index_chunks(ObjectReference ref);
92 void store_block_signatures(ObjectReference ref, block_summary summary);
94 std::string get_algorithm() {
95 return chunk_algorithm_name() + "/sha1";
99 #endif // _LBS_SUBFILE_H