sar.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 SAR_HPP
#define SAR_HPP
#include "../my_config.h"
#include <string>
#include "infinint.hpp"
#include "generic_file.hpp"
#include "header.hpp"
#include "integers.hpp"
#include "entrepot.hpp"
#include "slice_layout.hpp"
#include "contextual.hpp"
#include "mem_ui.hpp"
namespace libdar
{
// contextual is defined in generic_file module
class sar : public generic_file, public contextual, protected mem_ui
{
public:
sar(const std::shared_ptr<user_interaction> & dialog,
const std::string & base_name,
const std::string & extension,
const std::shared_ptr<entrepot> & where,
bool by_the_end,
const infinint & x_min_digits,
bool sequential_read,
bool lax = false,
const std::string & execute = "");
sar(const std::shared_ptr<user_interaction> & dialog,
gf_mode open_mode,
const std::string & base_name,
const std::string & extension,
const infinint & file_size,
const infinint & first_file_size,
bool x_warn_overwrite,
bool x_allow_overwrite,
const infinint & pause,
const std::shared_ptr<entrepot> & where,
const label & internal_name,
const label & data_name,
bool force_permission,
U_I permission,
hash_algo x_hash,
const infinint & x_min_digits,
bool format_07_compatible,
const std::string & execute = "");
sar(const sar & ref) = delete;
sar(sar && ref) noexcept = delete;
sar & operator = (const sar & ref) = delete;
sar & operator = (sar && ref) noexcept = delete;
~sar();
// inherited from generic_file
virtual bool skippable(skippability direction, const infinint & amount) override;
virtual bool skip(const infinint &pos) override;
virtual bool skip_to_eof() override;
virtual bool skip_relative(S_I x) override;
virtual bool truncatable(const infinint & pos) const override;
virtual infinint get_position() const override;
// informational routines
const slice_layout & get_slicing() const { return slicing; };
bool get_total_file_number(infinint &num) const { num = of_last_file_num; return of_last_file_known; };
bool get_last_file_size(infinint &num) const { num = of_last_file_size; return of_last_file_known; };
// disable execution of user command when destroying the current object
void disable_natural_destruction() { natural_destruction = false; };
// enable back execution of user command when destroying the current object
void enable_natural_destruction() { natural_destruction = true; };
// true if sar's header is from an old archive format (<= "07")
virtual bool is_an_old_start_end_archive() const override { return slicing.older_sar_than_v8; };
// return the internal_name used to link slices toghether
const label & get_internal_name_used() const { return of_internal_name; };
// return the data_name used to link slices toghether
virtual const label & get_data_name() const override { return of_data_name; };
const std::shared_ptr<entrepot> & get_entrepot() const { return entr; };
const infinint & get_first_slice_header_size() const { return slicing.first_slice_header; };
const infinint & get_non_first_slice_header_size() const { return slicing.other_slice_header; };
protected :
virtual void inherited_read_ahead(const infinint & amount) override;
virtual U_I inherited_read(char *a, U_I size) override;
virtual void inherited_write(const char *a, U_I size) override;
virtual void inherited_truncate(const infinint & pos) override;
virtual void inherited_sync_write() override {}; // nothing to do
virtual void inherited_flush_read() override {}; // nothing to do
virtual void inherited_terminate() override;
private :
std::shared_ptr<entrepot> entr;
std::string base;
std::string ext;
std::string hook;
slice_layout slicing;
infinint file_offset;
hash_algo hash;
infinint min_digits;
bool natural_destruction;
// these following variables are modified by open_file / open_file_init
// else the are used only for reading
infinint of_current;
infinint size_of_current;
infinint of_max_seen;
bool of_last_file_known;
infinint of_last_file_num;
infinint of_last_file_size;
label of_internal_name;
label of_data_name;
bool force_perm;
U_I perm;
fichier_global *of_fd;
char of_flag;
bool initial;
// these are the option flags
bool opt_warn_overwrite;
bool opt_allow_overwrite;
//
infinint pause;
bool lax;
infinint to_read_ahead;
bool seq_read;
bool skip_forward(U_I x);
bool skip_backward(U_I x);
void close_file(bool terminal);
void open_readonly(const std::string & fic,
const infinint &num,
bool bytheend
);
void open_writeonly(const std::string & fic,
const infinint &num,
bool bytheend
);
void open_file_init();
void open_file(infinint num, bool bytheend);
void set_offset(infinint offset);
void open_last_file(bool bytheend);
bool is_current_eof_a_normal_end_of_slice() const;
infinint bytes_still_to_read_in_slice() const;
header make_write_header(const infinint &num, char flag);
// function to lauch the eventually existing command to execute after/before each slice
void hook_execute(const infinint &num);
};
} // end of namespace
#endif
libdar::contextual
the contextual class adds the information of phases in the generic_file
Definition: contextual.hpp:74
libdar::fichier_global
abstraction of filesystem files for entrepot
Definition: fichier_global.hpp:59
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:77
libdar::header
this class manages the header of each slice
Definition: header.hpp:66
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:62
libdar::label
manage label data structure used in archive slice headers
Definition: label.hpp:43
libdar::mem_ui
class mem_ui to keep a copy of a user_interaction object
Definition: mem_ui.hpp:55
libdar::sar
Sar class stands for Segmentation And Reassembly class.
Definition: sar.hpp:55
libdar::sar::inherited_read
virtual U_I inherited_read(char *a, U_I size) override
implementation of read() operation
libdar::sar::size_of_current
infinint size_of_current
size of the current slice (used in reading mode only)
Definition: sar.hpp:207
libdar::sar::operator=
sar & operator=(const sar &ref)=delete
assignment operator
libdar::sar::skip_backward
bool skip_backward(U_I x)
skip backward in sar global contents
libdar::sar::hook
std::string hook
command line to execute between slices
Definition: sar.hpp:198
libdar::sar::open_file
void open_file(infinint num, bool bytheend)
close current slice and open the slice 'num'
libdar::sar::of_data_name
label of_data_name
internal name linked to data (transparent to dar_xform and used by isolated catalogue as reference)
Definition: sar.hpp:213
libdar::sar::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
libdar::sar::to_read_ahead
infinint to_read_ahead
amount of data to read ahead for next slices
Definition: sar.hpp:225
libdar::sar::opt_warn_overwrite
bool opt_warn_overwrite
a warning must be issued before overwriting a slice
Definition: sar.hpp:220
libdar::sar::of_last_file_num
infinint of_last_file_num
number of the last slice (if met)
Definition: sar.hpp:210
libdar::sar::of_fd
fichier_global * of_fd
file object currently openned
Definition: sar.hpp:216
libdar::sar::pause
infinint pause
do we pause between slices
Definition: sar.hpp:223
libdar::sar::is_current_eof_a_normal_end_of_slice
bool is_current_eof_a_normal_end_of_slice() const
return true if current reading position is at end of slice
libdar::sar::initial
bool initial
do not launch hook command-line during sar initialization
Definition: sar.hpp:218
libdar::sar::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
libdar::sar::entr
std::shared_ptr< entrepot > entr
where are stored slices
Definition: sar.hpp:195
libdar::sar::is_an_old_start_end_archive
virtual bool is_an_old_start_end_archive() const override
returns whether the archive is a old archive (format < 8)
Definition: sar.hpp:169
libdar::sar::opt_allow_overwrite
bool opt_allow_overwrite
is slice overwriting allowed
Definition: sar.hpp:221
libdar::sar::seq_read
bool seq_read
whether sequential read has been requested
Definition: sar.hpp:226
libdar::sar::get_non_first_slice_header_size
const infinint & get_non_first_slice_header_size() const
get the non first slice header
Definition: sar.hpp:183
libdar::sar::sar
sar(const std::shared_ptr< user_interaction > &dialog, gf_mode open_mode, const std::string &base_name, const std::string &extension, const infinint &file_size, const infinint &first_file_size, bool x_warn_overwrite, bool x_allow_overwrite, const infinint &pause, const std::shared_ptr< entrepot > &where, const label &internal_name, const label &data_name, bool force_permission, U_I permission, hash_algo x_hash, const infinint &x_min_digits, bool format_07_compatible, const std::string &execute="")
this constructor creates a new set of slices
libdar::sar::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount) override
tells the object that several calls to read() will follow to probably obtain at least the given amoun...
libdar::sar::open_writeonly
void open_writeonly(const std::string &fic, const infinint &num, bool bytheend)
libdar::sar::set_offset
void set_offset(infinint offset)
skip to current slice relative offset
libdar::sar::lax
bool lax
whether to try to go further reading problems
Definition: sar.hpp:224
libdar::sar::~sar
~sar()
destructor
libdar::sar::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
libdar::sar::base
std::string base
archive base name
Definition: sar.hpp:196
libdar::sar::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
libdar::sar::force_perm
bool force_perm
true if any future slice has its permission to be set explicitely
Definition: sar.hpp:214
libdar::sar::of_internal_name
label of_internal_name
internal name shared in all slice header
Definition: sar.hpp:212
libdar::sar::of_flag
char of_flag
flags of the open file
Definition: sar.hpp:217
libdar::sar::of_last_file_known
bool of_last_file_known
whether the T terminal slice has been met
Definition: sar.hpp:209
libdar::sar::of_current
infinint of_current
number of the open slice
Definition: sar.hpp:206
libdar::sar::hash
hash_algo hash
whether to build a hashing when creating slices, and if so, which algorithm to use
Definition: sar.hpp:201
libdar::sar::close_file
void close_file(bool terminal)
close current openned file, adding (in write mode only) a terminal mark (last slice) or not
libdar::sar::skip_forward
bool skip_forward(U_I x)
skip forward in sar global contents
libdar::sar::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
libdar::sar::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition: sar.hpp:191
libdar::sar::sar
sar(sar &&ref) noexcept=delete
move constructor
libdar::sar::sar
sar(const std::shared_ptr< user_interaction > &dialog, const std::string &base_name, const std::string &extension, const std::shared_ptr< entrepot > &where, bool by_the_end, const infinint &x_min_digits, bool sequential_read, bool lax=false, const std::string &execute="")
this constructor reads data from a set of slices
libdar::sar::bytes_still_to_read_in_slice
infinint bytes_still_to_read_in_slice() const
returns the number of bytes expected before the end of slice
libdar::sar::min_digits
infinint min_digits
minimum number of digits the slices number is stored with in the filename
Definition: sar.hpp:202
libdar::sar::get_first_slice_header_size
const infinint & get_first_slice_header_size() const
get the first slice header
Definition: sar.hpp:180
libdar::sar::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
libdar::sar::open_readonly
void open_readonly(const std::string &fic, const infinint &num, bool bytheend)
libdar::sar::perm
U_I perm
if force_perm is true, value to use for slice permission
Definition: sar.hpp:215
libdar::sar::sar
sar(const sar &ref)=delete
the copy constructor
libdar::sar::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
libdar::sar::get_data_name
virtual const label & get_data_name() const override
obtain the data_name of the archive (label associated with the archive's data)
Definition: sar.hpp:175
libdar::sar::inherited_write
virtual void inherited_write(const char *a, U_I size) override
implementation of the write() operation
libdar::sar::of_max_seen
infinint of_max_seen
highest slice number seen so far
Definition: sar.hpp:208
libdar::sar::get_position
virtual infinint get_position() const override
get the current read/write position
libdar::sar::open_file_init
void open_file_init()
initialize some of_* fields
libdar::sar::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition: sar.hpp:190
libdar::sar::of_last_file_size
infinint of_last_file_size
size of the last slice (if met)
Definition: sar.hpp:211
libdar::sar::file_offset
infinint file_offset
current reading/writing position in the current slice (relative to the whole slice file,...
Definition: sar.hpp:200
libdar::sar::natural_destruction
bool natural_destruction
whether to execute commands between slices on object destruction
Definition: sar.hpp:203
libdar::sar::open_last_file
void open_last_file(bool bytheend)
open the last slice, ask the user, test, until last slice available
libdar::sar::ext
std::string ext
archive extension
Definition: sar.hpp:197
libdar::sar::slicing
slice_layout slicing
slice layout
Definition: sar.hpp:199
contextual.hpp
class contextual adds the information of phases in the generic_file
entrepot.hpp
defines the entrepot interface.
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::hash_algo
hash_algo
hashing algorithm available
Definition: archive_aux.hpp:63
libdar::gf_mode
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:44
header.hpp
slice header structure is defined here
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
integers.hpp
are defined here basic integer types that tend to be portable
mem_ui.hpp
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
slice_layout.hpp
object describing the slicing of an archive