cat_file.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2023 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_FILE_HPP
#define CAT_FILE_HPP
#include "../my_config.h"
extern "C"
{
} // end extern "C"
#include "cat_inode.hpp"
#include "memory_file.hpp"
#include "cat_delta_signature.hpp"
namespace libdar
{
class cat_file : public cat_inode
{
public :
enum get_data_mode
{
keep_compressed,
keep_hole,
normal,
plain
};
static constexpr U_8 FILE_DATA_WITH_HOLE = 0x01;
static constexpr U_8 FILE_DATA_IS_DIRTY = 0x02;
static constexpr U_8 FILE_DATA_HAS_DELTA_SIG = 0x04;
cat_file(const infinint & xuid,
const infinint & xgid,
U_16 xperm,
const datetime & last_access,
const datetime & last_modif,
const datetime & last_change,
const std::string & src,
const path & che,
const infinint & taille,
const infinint & fs_device,
bool x_furtive_read_mode);
cat_file(const std::shared_ptr<user_interaction> & dialog,
const smart_pointer<pile_descriptor> & pdesc,
const archive_version & reading_ver,
saved_status saved,
compression default_algo,
bool small);
cat_file(const cat_file & ref);
cat_file(cat_file && ref) = delete;
cat_file & operator = (const cat_file & ref) = delete;
cat_file & operator = (cat_file && ref) = delete;
~cat_file() { detruit(); };
virtual bool has_changed_since(const cat_inode & ref,
const infinint & hourshift,
comparison_fields what_to_check) const override;
infinint get_size() const { return *size; };
void change_size(const infinint & s) const { *size = s; };
infinint get_storage_size() const { return *storage_size; };
void set_storage_size(const infinint & s) { *storage_size = s; };
bool can_get_data() const { return get_saved_status() == saved_status::saved || get_saved_status() == saved_status::delta || status == from_path; };
virtual generic_file *get_data(get_data_mode mode,
std::shared_ptr<memory_file> delta_sig_mem,
U_I signature_block_size,
std::shared_ptr<memory_file> delta_ref,
const crc **checksum = nullptr) const;
void clean_data(); // partially free memory (but get_data() becomes disabled)
void set_offset(const infinint & r);
const infinint & get_offset() const;
virtual unsigned char signature() const override { return 'f'; };
virtual std::string get_description() const override { return "file"; };
void set_crc(const crc &c);
bool get_crc(const crc * & c) const;
bool has_crc() const { return check != nullptr; };
bool get_crc_size(infinint & val) const;
void drop_crc() { if(check != nullptr) { delete check; check = nullptr; } };
// whether the plain file has to detect sparse file
void set_sparse_file_detection_read(bool val) { if(status == from_cat) throw SRC_BUG; if(val) file_data_status_read |= FILE_DATA_WITH_HOLE; else file_data_status_read &= ~FILE_DATA_WITH_HOLE; };
void set_sparse_file_detection_write(bool val) { if(val) file_data_status_write |= FILE_DATA_WITH_HOLE; else file_data_status_write &= ~FILE_DATA_WITH_HOLE; };
// whether the plain file is stored with a sparse_file datastructure in the archive
bool get_sparse_file_detection_read() const { return (file_data_status_read & FILE_DATA_WITH_HOLE) != 0; };
bool get_sparse_file_detection_write() const { return (file_data_status_write & FILE_DATA_WITH_HOLE) != 0; };
virtual cat_entree *clone() const override { return new (std::nothrow) cat_file(*this); };
compression get_compression_algo_read() const { return algo_read; };
compression get_compression_algo_write() const { return algo_write; };
// object migration methods (merging)
void change_compression_algo_write(compression x) { algo_write = x; };
// dirtiness
bool is_dirty() const { return dirty; };
void set_dirty(bool value) { dirty = value; };
bool has_delta_signature_structure() const { return delta_sig != nullptr; };
bool has_delta_signature_available() const { return delta_sig != nullptr && delta_sig->can_obtain_sig(); };
bool has_patch_base_crc() const;
bool get_patch_base_crc(const crc * & c) const;
void set_patch_base_crc(const crc & c);
bool has_patch_result_crc() const;
bool get_patch_result_crc(const crc * & c) const;
void set_patch_result_crc(const crc & c);
void will_have_delta_signature_structure();
void will_have_delta_signature_available();
void dump_delta_signature(std::shared_ptr<memory_file> & sig, U_I sign_block_size, generic_file & where, bool small) const;
void dump_delta_signature(generic_file & where, bool small) const;
void read_delta_signature_metadata() const;
void read_delta_signature(std::shared_ptr<memory_file> & delta_sig,
U_I & block_len) const;
void drop_delta_signature_data() const;
bool has_same_delta_signature(const cat_file & ref) const;
void clear_delta_signature_only();
void clear_delta_signature_structure();
virtual bool operator == (const cat_entree & ref) const override { return true; };
bool same_data_as(const cat_file & other, bool check_data, const infinint & hourshift);
const archive_version & get_archive_version() const { return read_ver; };
protected:
virtual void sub_compare(const cat_inode & other, bool isolated_mode) const override;
virtual void inherited_dump(const pile_descriptor & pdesc, bool small) const override;
virtual void post_constructor(const pile_descriptor & pdesc) override;
enum { empty, from_path, from_cat } status;
private:
std::string chemin;
infinint *offset;
infinint *size;
infinint *storage_size;
crc *check;
bool dirty;
compression algo_read;
compression algo_write;
bool furtive_read_mode;
char file_data_status_read;
char file_data_status_write;
crc *patch_base_check;
cat_delta_signature *delta_sig;
mutable bool delta_sig_read;
archive_version read_ver;
void sub_compare_internal(const cat_inode & other,
bool can_read_my_data,
bool can_read_other_data,
const infinint & hourshift) const;
void clean_patch_base_crc();
void detruit();
};
} // end of namespace
#endif
cat_delta_signature.hpp
class used to manage binary delta signature in catalogue and archive
cat_inode.hpp
base object for all inode types, managed EA and FSA, dates, permissions, ownership,...
libdar::archive_version
class archive_version manages the version of the archive format
Definition: archive_version.hpp:47
libdar::cat_delta_signature
the cat_delta_signature file class
Definition: cat_delta_signature.hpp:94
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:134
libdar::cat_entree
the root class from all other inherite for any entry in the catalogue
Definition: cat_entree.hpp:60
libdar::cat_entree::get_saved_status
saved_status get_saved_status() const
obtain the saved status of the object
Definition: cat_entree.hpp:164
libdar::cat_file
the plain file class
Definition: cat_file.hpp:49
libdar::cat_file::size
infinint * size
size of the data (uncompressed)
Definition: cat_file.hpp:252
libdar::cat_file::get_crc
bool get_crc(const crc *&c) const
the argument is set the an allocated crc object the owned by the "cat_file" object,...
libdar::cat_file::has_same_delta_signature
bool has_same_delta_signature(const cat_file &ref) const
return true if ref and "this" have both equal delta signatures
libdar::cat_file::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_file::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_file::dump_delta_signature
void dump_delta_signature(std::shared_ptr< memory_file > &sig, U_I sign_block_size, generic_file &where, bool small) const
write down to archive the given delta signature
libdar::cat_file::get_archive_version
const archive_version & get_archive_version() const
expose the archive format the object of the backup this object comes from
Definition: cat_file.hpp:240
libdar::cat_file::FILE_DATA_HAS_DELTA_SIG
static constexpr U_8 FILE_DATA_HAS_DELTA_SIG
delta signature is present
Definition: cat_file.hpp:63
libdar::cat_file::read_delta_signature
void read_delta_signature(std::shared_ptr< memory_file > &delta_sig, U_I &block_len) const
fetch the delta signature from the archive
libdar::cat_file::drop_delta_signature_data
void drop_delta_signature_data() const
drop the delta signature from memory (will not more be posible to be read, using read_delta_signature...
libdar::cat_file::post_constructor
virtual void post_constructor(const pile_descriptor &pdesc) override
let inherited classes build object's data after CRC has been read from file in small read mode
libdar::cat_file::dirty
bool dirty
true when a file has been modified at the time it was saved
Definition: cat_file.hpp:255
libdar::cat_file::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_file::algo_write
compression algo_write
which compression algorithm to use to write down (merging) the file's data
Definition: cat_file.hpp:257
libdar::cat_file::same_data_as
bool same_data_as(const cat_file &other, bool check_data, const infinint &hourshift)
compare just data not inode information EA nor FSA
libdar::cat_file::delta_sig_read
bool delta_sig_read
whether delta sig has been read/initialized from filesystem
Definition: cat_file.hpp:263
libdar::cat_file::FILE_DATA_IS_DIRTY
static constexpr U_8 FILE_DATA_IS_DIRTY
data modified while being saved
Definition: cat_file.hpp:62
libdar::cat_file::get_data_mode
get_data_mode
how to get data from archive
Definition: cat_file.hpp:54
libdar::cat_file::keep_compressed
@ keep_compressed
provide access to compressed data
Definition: cat_file.hpp:55
libdar::cat_file::normal
@ normal
provide access to full data (uncompressed, uses skip() to restore holes)
Definition: cat_file.hpp:57
libdar::cat_file::keep_hole
@ keep_hole
provide access to uncompressed data but sparse_file datastructure
Definition: cat_file.hpp:56
libdar::cat_file::plain
@ plain
provide access to plain data, no skip to restore holes, provide instead zeroed bytes
Definition: cat_file.hpp:58
libdar::cat_file::delta_sig
cat_delta_signature * delta_sig
delta signature and associated CRC
Definition: cat_file.hpp:262
libdar::cat_file::patch_base_check
crc * patch_base_check
when data contains a delta patch, moved from delta_sig since format 10.2
Definition: cat_file.hpp:261
libdar::cat_file::will_have_delta_signature_available
void will_have_delta_signature_available()
prepare the object to receive a delta signature structure including delta signature
libdar::cat_file::clear_delta_signature_structure
void clear_delta_signature_structure()
remove any information about delta signature
libdar::cat_file::get_crc_size
bool get_crc_size(infinint &val) const
returns true if crc is know and puts its width in argument
libdar::cat_file::clear_delta_signature_only
void clear_delta_signature_only()
remove information about delta signature also associated CRCs if status is not s_delta
libdar::cat_file::has_delta_signature_structure
bool has_delta_signature_structure() const
return whether the object has an associated delta signature structure
Definition: cat_file.hpp:155
libdar::cat_file::file_data_status_read
char file_data_status_read
defines the datastructure to use when reading the data
Definition: cat_file.hpp:259
libdar::cat_file::storage_size
infinint * storage_size
how much data used in archive (after compression)
Definition: cat_file.hpp:253
libdar::cat_file::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...
libdar::cat_file::check
crc * check
crc computed on the data
Definition: cat_file.hpp:254
libdar::cat_file::FILE_DATA_WITH_HOLE
static constexpr U_8 FILE_DATA_WITH_HOLE
file's data contains hole datastructure
Definition: cat_file.hpp:61
libdar::cat_file::inherited_dump
virtual void inherited_dump(const pile_descriptor &pdesc, bool small) const override
true if object has been created by sequential reading of an archive
libdar::cat_file::operator==
virtual bool operator==(const cat_entree &ref) const override
not used
Definition: cat_file.hpp:234
libdar::cat_file::has_delta_signature_available
bool has_delta_signature_available() const
return whether the object has an associated delta signature structure including a delta signature dat...
Definition: cat_file.hpp:162
libdar::cat_file::clone
virtual cat_entree * clone() const override
a way to copy the exact type of an object even if pointed to by a parent class pointer
Definition: cat_file.hpp:139
libdar::cat_file::furtive_read_mode
bool furtive_read_mode
used only when status equals "from_path"
Definition: cat_file.hpp:258
libdar::cat_file::file_data_status_write
char file_data_status_write
defines the datastructure to apply when writing down the data
Definition: cat_file.hpp:260
libdar::cat_file::will_have_delta_signature_structure
void will_have_delta_signature_structure()
prepare the object to receive a delta signature structure
libdar::cat_file::read_ver
archive_version read_ver
archive format used/to use
Definition: cat_file.hpp:264
libdar::cat_file::read_delta_signature_metadata
void read_delta_signature_metadata() const
load metadata (and delta signature when in sequential mode) into memory
libdar::cat_file::get_description
virtual std::string get_description() const override
inherited class designation
Definition: cat_file.hpp:122
libdar::cat_file::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_file::can_get_data
bool can_get_data() const
check whether the object will be able to provide a object using get_data() method
Definition: cat_file.hpp:97
libdar::cat_file::dump_delta_signature
void dump_delta_signature(generic_file &where, bool small) const
variant of dump_delta_signature when just CRC have to be dumped
libdar::cat_file::has_patch_base_crc
bool has_patch_base_crc() const
returns whether the object has a base patch CRC (s_delta status objects)
libdar::cat_file::chemin
std::string chemin
path to the data (when read from filesystem)
Definition: cat_file.hpp:250
libdar::cat_file::signature
virtual unsigned char signature() const override
inherited class signature
Definition: cat_file.hpp:121
libdar::cat_file::offset
infinint * offset
start location of the data in 'loc'
Definition: cat_file.hpp:251
libdar::cat_file::get_data
virtual generic_file * get_data(get_data_mode mode, std::shared_ptr< memory_file > delta_sig_mem, U_I signature_block_size, std::shared_ptr< memory_file > delta_ref, const crc **checksum=nullptr) const
returns a newly allocated object in read_only mode
libdar::cat_file::algo_read
compression algo_read
which compression algorithm to use to read the file's data
Definition: cat_file.hpp:256
libdar::cat_inode
the root class for all cat_inode
Definition: cat_inode.hpp:53
libdar::crc
pure virtual class defining interface of a CRC object
Definition: crc.hpp:47
libdar::datetime
stores time information
Definition: datetime.hpp:59
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
libdar::path
the class path is here to manipulate paths in the Unix notation: using'/'
Definition: path.hpp:51
libdar::smart_pointer< pile_descriptor >
libdar::comparison_fields
comparison_fields
how to consider file change during comparison and incremental backup
Definition: archive_aux.hpp:53
libdar::compression
compression
the different compression algorithm available
Definition: compression.hpp:46
libdar::saved_status
saved_status
data saved status for an entry
Definition: cat_status.hpp:45
libdar::saved_status::saved
@ saved
inode is saved in the archive
libdar::saved_status::delta
@ delta
inode is saved but as delta binary from the content (delta signature) of what was found in the archiv...
memory_file.hpp
Memory_file is a generic_file class that only uses virtual memory.
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47