Loading...
Searching...
No Matches
cat_delta_signature.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2026 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef CAT_DELTA_SIGNATURE_HPP
#define CAT_DELTA_SIGNATURE_HPP
#include "../my_config.h"
extern "C"
{
} // end extern "C"
#include "memory_file.hpp"
#include "crc.hpp"
#include "proto_compressor.hpp"
#include "archive_version.hpp"
#include <memory>
namespace libdar
{
// Datastructure in archive (DATA+METADATA)
//
// SEQUENTIAL MODE - in the core of the archive
// +------+------+-----------+--------------+----------+--------+
// | base | sig | sig block |sig data | data CRC | result |
// | CRC | size | len (if |(if size > 0) | if | CRC |
// | (*) | | size > 0) | | size > 0 | |
// +------+------+-----------+--------------+----------+--------+
//
// DIRECT MODE - in catalogue at end of archive (METADATA)
// +------+------+---------------+--------+
// | base | sig | sig offset | result |
// | CRC | size | (if size > 0) | CRC |
// | (*) | | | |
// +------+------+---------------+--------+
//
// DIRECT MODE - in the core of the archive (DATA)
// +-----------+---------------+----------+
// | sig block | sig data | data CRC |
// | len (if | (if size > 0) | if |
// | size > 0) | | size > 0 |
// +-----------+---------------+----------+
//
// Note that the SEQUENTIAL MODE is wrapping the DIRECT MODE structure in the core
// of the archive, the core of the archive contains either the sequential mode structure
// or the direct mode. While in the catalogue, the "sig offset" fields points to the
// offset of the direct mode in the core (possibly wrapped in the structure forming the
// one of the sequential mode).
//
// (*) base_CRC has been moved to cat_file structure since format 11,2
// in order to read this field before the delta patch in sequential read mode
//
// this structure is used for all cat_file inode that have
// either a delta signature or contain a delta patch (s_delta status)
// base_crc is used to check we apply the patch on the good file before proceeding
// result_crc is used to store the crc of the file the signature has been computed on
// result_crc is also used once a patch has been applied to verify the correctness of the patch result
class cat_delta_signature
{
public:
cat_delta_signature(generic_file *f, proto_compressor* c);
cat_delta_signature() { init(); };
cat_delta_signature(const cat_delta_signature & ref) { init(); copy_from(ref); };
cat_delta_signature(cat_delta_signature && ref) noexcept { init(); move_from(std::move(ref)); };
cat_delta_signature & operator = (const cat_delta_signature & ref) { clear(); copy_from(ref); return *this; };
cat_delta_signature & operator = (cat_delta_signature && ref) noexcept { move_from(std::move(ref)); return *this; };
~cat_delta_signature() { destroy(); };
bool is_pending_read() const { return pending_read; };
void read(bool sequential_read, const archive_version & ver);
bool can_obtain_sig() const { return !delta_sig_size.is_zero(); };
std::shared_ptr<memory_file> obtain_sig(const archive_version & ver) const;
U_I obtain_sig_block_size() const { return sig_block_len; };
void drop_sig() const { sig.reset(); };
void will_have_signature() { delta_sig_size = 1; };
void set_sig(const std::shared_ptr<memory_file> & ptr, U_I sig_block_size);
void set_sig() { delta_sig_size = 0; delta_sig_offset = 0; sig_block_len = 0; sig.reset(); };
void dump_data(generic_file & f, bool sequential_mode, const archive_version & ver) const;
void dump_metadata(generic_file & f) const;
bool has_patch_base_crc() const { return patch_base_check != nullptr; };
bool get_patch_base_crc(const crc * & c) const;
void set_patch_base_crc(const crc & c);
bool has_patch_result_crc() const { return patch_result_check != nullptr; };
bool get_patch_result_crc(const crc * & c) const;
void set_patch_result_crc(const crc & c);
void clear() { destroy(); init(); };
private:
crc *patch_base_check;
infinint delta_sig_size;
infinint delta_sig_offset;
mutable std::shared_ptr<memory_file>sig;
crc *patch_result_check;
generic_file *src;
proto_compressor *zip;
mutable U_I sig_block_len;
bool pending_read;
void init() noexcept;
void copy_from(const cat_delta_signature & ref);
void move_from(cat_delta_signature && ref) noexcept;
void destroy() noexcept;
// reads sig_block_len + sig data
void fetch_data(const archive_version & ver) const;
};
} // end of namespace
#endif
archive_version.hpp
class archive_version that rules which archive format to follow
libdar::archive_version
class archive_version manages the version of the archive format
Definition archive_version.hpp:47
libdar::cat_delta_signature::pending_read
bool pending_read
when the object has been created for read but data not yet read from archive
Definition cat_delta_signature.hpp:219
libdar::cat_delta_signature::obtain_sig
std::shared_ptr< memory_file > obtain_sig(const archive_version &ver) const
provide a memory_file object which the caller has the duty to destroy after use
libdar::cat_delta_signature::delta_sig_size
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...
Definition cat_delta_signature.hpp:211
libdar::cat_delta_signature::dump_metadata
void dump_metadata(generic_file &f) const
write down the delta_signature metadata for catalogue
libdar::cat_delta_signature::get_patch_result_crc
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,...
libdar::cat_delta_signature::cat_delta_signature
cat_delta_signature(const cat_delta_signature &ref)
copy constructor
Definition cat_delta_signature.hpp:115
libdar::cat_delta_signature::has_patch_base_crc
bool has_patch_base_crc() const
returns whether the object has a base patch CRC (s_delta status objects)
Definition cat_delta_signature.hpp:189
libdar::cat_delta_signature::drop_sig
void drop_sig() const
drop signature but keep metadata available
Definition cat_delta_signature.hpp:156
libdar::cat_delta_signature::cat_delta_signature
cat_delta_signature()
constructor to write an object to filesytem/backup (using dump_* methods later on)
Definition cat_delta_signature.hpp:112
libdar::cat_delta_signature::read
void read(bool sequential_read, const archive_version &ver)
libdar::cat_delta_signature::set_sig
void set_sig()
variante used when the delta_signature object will only contain CRCs (no delta signature)
Definition cat_delta_signature.hpp:174
libdar::cat_delta_signature::get_patch_base_crc
bool get_patch_base_crc(const crc *&c) const
returns the CRC of the file to base the patch on, for s_delta objects
libdar::cat_delta_signature::can_obtain_sig
bool can_obtain_sig() const
the cat_delta_signature structure can only hold CRC without delta_signature, this call gives the situ...
Definition cat_delta_signature.hpp:140
libdar::cat_delta_signature::will_have_signature
void will_have_signature()
give the object where to fetch from the delta signature, object must exist up to the next call to dum...
Definition cat_delta_signature.hpp:165
libdar::cat_delta_signature::clear
void clear()
reset the object
Definition cat_delta_signature.hpp:207
libdar::cat_delta_signature::sig_block_len
U_I sig_block_len
block length used within delta signature
Definition cat_delta_signature.hpp:218
libdar::cat_delta_signature::has_patch_result_crc
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...
Definition cat_delta_signature.hpp:198
libdar::cat_delta_signature::cat_delta_signature
cat_delta_signature(cat_delta_signature &&ref) noexcept
move constructor
Definition cat_delta_signature.hpp:118
libdar::cat_delta_signature::set_patch_base_crc
void set_patch_base_crc(const crc &c)
set the reference CRC of the file to base the patch on, for s_detla objects
libdar::cat_delta_signature::set_patch_result_crc
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...
libdar::cat_delta_signature::set_sig
void set_sig(const std::shared_ptr< memory_file > &ptr, U_I sig_block_size)
the object pointed to by ptr must stay available when calling dump_data()/dump_metadata() later on
libdar::cat_delta_signature::dump_data
void dump_data(generic_file &f, bool sequential_mode, const archive_version &ver) const
write down the data eventually with sequential read mark followed by delta sig metadata
libdar::cat_delta_signature::patch_base_check
crc * patch_base_check
associated CRC for the file this signature has been computed on, moved to cat_file since format 11....
Definition cat_delta_signature.hpp:210
libdar::cat_delta_signature::is_pending_read
bool is_pending_read() const
tells whether the read() call has been invoked
Definition cat_delta_signature.hpp:132
libdar::cat_delta_signature::obtain_sig_block_size
U_I obtain_sig_block_size() const
provide the block size used for delta signature
Definition cat_delta_signature.hpp:150
libdar::cat_delta_signature::sig
std::shared_ptr< memory_file > sig
the signature data, if set nullptr it will be fetched from f in direct access mode only
Definition cat_delta_signature.hpp:214
libdar::cat_delta_signature::patch_result_check
crc * patch_result_check
associated CRC
Definition cat_delta_signature.hpp:215
libdar::cat_delta_signature::zip
proto_compressor * zip
needed to disable compression when reading delta signature data from an archive
Definition cat_delta_signature.hpp:217
libdar::cat_delta_signature::~cat_delta_signature
~cat_delta_signature()
destructor
Definition cat_delta_signature.hpp:127
libdar::cat_delta_signature::src
generic_file * src
where to read data from
Definition cat_delta_signature.hpp:216
libdar::cat_delta_signature::delta_sig_offset
infinint delta_sig_offset
Definition cat_delta_signature.hpp:212
libdar::cat_delta_signature::cat_delta_signature
cat_delta_signature(generic_file *f, proto_compressor *c)
constructor to read an object (using read() later on) from filesystem/backup
libdar::cat_delta_signature::operator=
cat_delta_signature & operator=(const cat_delta_signature &ref)
assignement operator
Definition cat_delta_signature.hpp:121
libdar::crc
pure virtual class defining interface of a CRC object
Definition crc.hpp:47
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition generic_file.hpp:77
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
crc.hpp
class crc definition, used to handle Cyclic Redundancy Checks
memory_file.hpp
Memory_file is a generic_file class that only uses virtual memory.
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47
proto_compressor.hpp
abstracted ancestor class for compressor and parallel_compressor classes