Disk ARchive  2.6.0
Full featured and portable backup and archiving tool
cat_delta_signature.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2018 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
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.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 
25 
26 #ifndef CAT_DELTA_SIGNATURE_HPP
27 #define CAT_DELTA_SIGNATURE_HPP
28 
29 #include "../my_config.h"
30 
31 extern "C"
32 {
33 } // end extern "C"
34 
35 #include "memory_file.hpp"
36 #include "crc.hpp"
37 
38 namespace libdar
39 {
40 
43 
44  // Datastructure in archive (DATA+METADATA)
45  //
46  // SEQUENTIAL MODE - in the core of the archive
47  // +------+------+---------------+----------+--------+
48  // | base | sig | sig data | data CRC | result |
49  // | CRC | size | (if size > 0) | if | CRC |
50  // | | | | size > 0 | |
51  // +------+------+---------------+----------+--------+
52  //
53  // DIRECT MODE - in catalogue at end of archive (METADATA)
54  // +------+------+---------------+--------+
55  // | base | sig | sig offset | result |
56  // | CRC | size | (if size > 0) | CRC |
57  // | | | | |
58  // +------+------+---------------+--------+
59  //
60  // DIRECT MODE - in the core of the archive (DATA)
61  // +---------------+----------+
62  // | sig data | data CRC |
63  // | (if size > 0) | if |
64  // | | size > 0 |
65  // +---------------+----------+
66  //
67  //
68  // this structure is used for all cat_file inode that have
69  // either a delta signature or contain a delta patch (s_delta status)
70  // base_crc is used to check we apply the patch on the good file before proceeding
71  // result_crc is used to store the crc of the file the signature has been compulted on
72  // result_crc is also used once a patch has been applied to verify the correctness of the patch result
73 
74 
76 
88  {
89  public:
91 
94  cat_delta_signature(generic_file & f, bool sequential_read);
95 
97  cat_delta_signature() { init(); };
98 
100  cat_delta_signature(const cat_delta_signature & ref) { init(); copy_from(ref); };
101 
103  cat_delta_signature(cat_delta_signature && ref) noexcept { init(); move_from(std::move(ref)); };
104 
106  cat_delta_signature & operator = (const cat_delta_signature & ref) { destroy(); init(); copy_from(ref); return *this; };
107 
109  cat_delta_signature & operator = (cat_delta_signature && ref) noexcept { move_from(std::move(ref)); return *this; };
110 
112  ~cat_delta_signature() { destroy(); };
113 
115 
117 
119  void read_metadata(generic_file & f, bool sequential_read);
120 
122 
124  void read_data(generic_file & f);
125 
127  bool can_obtain_sig() { return !just_crc; };
128 
130 
133 
135 
137 
139 
141  void will_have_signature() { just_crc = false; clear_sig(); };
142 
143  void set_sig_ref(memory_file *ptr);
144 
146  void set_sig_ref() { just_crc = true; delta_sig_size = 0; };
147 
149  void dump_data(generic_file & f, bool sequential_mode) const;
150 
153  void dump_metadata(generic_file & f) const;
154 
155 
157 
159  bool has_patch_base_crc() const { return patch_base_check != nullptr; };
160 
162  bool get_patch_base_crc(const crc * & c) const;
163 
165  void set_patch_base_crc(const crc & c);
166 
168  bool has_patch_result_crc() const { return patch_result_check != nullptr; };
169 
171  bool get_patch_result_crc(const crc * & c) const;
172 
174  void set_patch_result_crc(const crc & c);
175 
177  void clear() { destroy(); init(); };
178 
179  private:
183  bool sig_is_ours;
186  bool just_crc;
187 
188  void init() noexcept;
189  void copy_from(const cat_delta_signature & ref);
190  void move_from(cat_delta_signature && ref) noexcept;
191  void clear_sig() noexcept;
192  void destroy() noexcept;
193  };
194 
196 
197 } // end of namespace
198 
199 #endif
crc * patch_base_check
associated CRC for the file this signature has been computed on
cat_delta_signature & operator=(const cat_delta_signature &ref)
assignement operator
bool has_patch_base_crc() const
returns whether the object has a base patch CRC (s_delta status objects)
class crc definition, used to handle Cyclic Redundancy Checks
bool has_patch_result_crc() const
returns whether the object has a CRC corresponding to data (for s_saved, s_delta, and when delta sign...
bool get_patch_base_crc(const crc *&c) const
returns the CRC of the file to base the patch on, for s_delta objects
bool get_patch_result_crc(const crc *&c) const
returns the CRC the file will have once restored or patched (for s_saved, s_delta, and when delta signature is present)
memory_file * sig
the signature data, if set nullptr it will be fetched from f in direct access mode only ...
void set_patch_result_crc(const crc &c)
set the CRC the file will have once restored or patched (for s_saved, s_delta, and when delta signatu...
generic_file stored in memory
Definition: memory_file.hpp:40
void set_sig_ref()
variante used when the delta_signature object will only contain CRCs (no delta signature) ...
crc * patch_result_check
associated CRC
infinint delta_sig_offset
where to read data from to setup "sig" (set to zero when read in sequential mode, sig is setup on-fly...
Memory_file is a generic_file class that only uses virtual memory.
the cat_delta_signature file class
bool can_obtain_sig()
the cat_delta_signature structure can only hold CRC without delta_signature, this call gives the situ...
memory_file * obtain_sig()
provide a memory_file object which the caller has the duty to destroy after use
void dump_metadata(generic_file &f) const
void set_patch_base_crc(const crc &c)
set the reference CRC of the file to base the patch on, for s_detla objects
void will_have_signature()
give the object where to fetch from the delta signature, object must exist up to the next call to dum...
infinint delta_sig_size
size of the data to setup "sig" (set to zero when reading in sequential mode, sig is then setup on-fl...
cat_delta_signature(const cat_delta_signature &ref)
copy constructor
this is the interface class from which all other data transfer classes inherit
bool just_crc
whether a delta signature is present or just checksum are stored
bool sig_is_ours
whether sig has been created on our behalf or given as reference by another class ...
cat_delta_signature()
constructor creating a brand new empty object
void dump_data(generic_file &f, bool sequential_mode) const
write down the data only (only for archive without sequential read mode support)
the arbitrary large positive integer class
void read_data(generic_file &f)
fetch data assuming the object has already read the metadata
pure virtual class defining interface of a CRC object
Definition: crc.hpp:46
void clear()
reset the object
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:46
void read_metadata(generic_file &f, bool sequential_read)
same action as the first constructor but on an existing object
cat_delta_signature(cat_delta_signature &&ref) noexcept
move constructor