Disk ARchive 2.8.0
Full featured and portable backup and archiving tool
macro_tools.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2025 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
25
26#ifndef MACRO_TOOLS_HPP
27#define MACRO_TOOLS_HPP
28
29#include "../my_config.h"
30
31extern "C"
32{
33#if HAVE_LIMITS_H
34#include <limits.h>
35#endif
36}
37#include <string>
38#include <vector>
39
40#include "catalogue.hpp"
41#include "compression.hpp"
42#include "infinint.hpp"
43#include "header_version.hpp"
44#include "generic_file.hpp"
45#include "crypto.hpp"
46#include "pile.hpp"
47#include "entrepot.hpp"
48#include "range.hpp"
49#include "slice_layout.hpp"
50#include "tuyau.hpp"
51#include "trivial_sar.hpp"
52#include "proto_compressor.hpp"
53
54
55#define BUFFER_SIZE 102400
56#ifdef SSIZE_MAX
57#if SSIZE_MAX < BUFFER_SIZE
58#undef BUFFER_SIZE
59#define BUFFER_SIZE SSIZE_MAX
60#endif
61#endif
62
63namespace libdar
64{
65
68
69 constexpr U_I GLOBAL_ELASTIC_BUFFER_SIZE = 51200;
70
71 extern const archive_version macro_tools_supported_version;
72 extern const std::string LIBDAR_STACK_LABEL_UNCOMPRESSED;
73 extern const std::string LIBDAR_STACK_LABEL_CLEAR;
74 extern const std::string LIBDAR_STACK_LABEL_UNCYPHERED;
75 extern const std::string LIBDAR_STACK_LABEL_LEVEL1;
76
78 extern trivial_sar *macro_tools_open_archive_tuyau(const std::shared_ptr<user_interaction> & dialog,
79 S_I fd,
80 gf_mode mode,
81 const label & internal_name,
82 const label & data_name,
83 bool slice_header_format_07,
84 const std::string & execute);
85
86
88
109
110 extern void macro_tools_open_archive(const std::shared_ptr<user_interaction> & dialog,
111 const std::shared_ptr<entrepot> & where,
112 const std::string &basename,
113 const infinint & min_digits,
114 const std::string &extension,
115 crypto_algo crypto,
116 const secu_string &pass,
117 U_32 crypto_size,
118 pile & stack,
119 header_version &ver,
120 const std::string &input_pipe,
121 const std::string &output_pipe,
122 const std::string & execute,
123 infinint & second_terminateur_offset,
124 bool lax,
125 bool has_external_cat,
126 bool sequential_read,
127 bool info_details,
128 std::list<signator> & gnupg_signed,
129 slice_layout & sl,
130 U_I multi_threaded_crypto,
131 U_I multi_threaded_compress,
132 bool header_only,
133 bool silent,
134 bool force_read_first_slice
135 );
136 // all allocated objects (ret1, ret2, scram), must be deleted when no more needed by the caller of this routine
137
139 extern catalogue *macro_tools_get_derivated_catalogue_from(const std::shared_ptr<user_interaction> & dialog,
140 pile & data_stack, // where to get the files and EA from
141 pile & cata_stack, // where to get the catalogue from
142 const header_version & ver, // version format as defined in the header of the archive to read
143 bool info_details, // verbose display (throught user_interaction)
144 infinint &cat_size, // return size of archive in file (not in memory !)
145 const infinint & second_terminateur_offset, // location of the second terminateur (zero if none exist)
146 std::list<signator> & signatories, // returns the list of signatories (empty if archive is was not signed)
147 bool lax_mode); // whether to do relaxed checkings
148
150 extern catalogue *macro_tools_get_catalogue_from(const std::shared_ptr<user_interaction> & dialog,
151 pile & stack, // raw data access object
152 const header_version & ver, // version format as defined in the header of the archive to read
153 bool info_details, // verbose display (throught user_interaction)
154 infinint &cat_size, // return size of archive in file (not in memory !)
155 const infinint & second_terminateur_offset,
156 std::list<signator> & signatories, // returns the list of signatories (empty if archive is was not signed)
157 bool lax_mode);
158
160 extern catalogue *macro_tools_read_catalogue(const std::shared_ptr<user_interaction> & dialog,
161 const header_version & ver,
162 const pile_descriptor & cata_pdesc,
163 const infinint & cat_size,
164 std::list<signator> & signatories,
165 bool lax_mode,
166 const label & lax_layer1_data_name,
167 bool only_detruits);
168
169 extern catalogue *macro_tools_lax_search_catalogue(const std::shared_ptr<user_interaction> & dialog,
170 pile & stack,
171 const archive_version & edition,
172 compression compr_algo,
173 bool info_details,
174 bool even_partial_catalogues,
175 const label & layer1_data_name);
176
177 // return the offset of the beginning of the catalogue.
178 extern infinint macro_tools_get_terminator_start(generic_file & f, const archive_version & reading_ver);
179
181
239
240 extern void macro_tools_create_layers(const std::shared_ptr<user_interaction> & dialog,
241 pile & layers,
242 header_version & ver,
243 slice_layout & slicing,
244 const slice_layout *ref_slicing,
245 const std::shared_ptr<entrepot> & sauv_path_t,
246 const std::string & filename,
247 const std::string & extension,
248 bool allow_over,
249 bool warn_over,
250 bool info_details,
251 const infinint & pause,
252 compression algo,
253 U_I compression_level,
254 U_I compression_block_size,
255 const infinint & file_size,
256 const infinint & first_file_size,
257 const std::string & execute,
258 crypto_algo crypto,
259 const secu_string & pass,
260 U_32 crypto_size,
261 const std::vector<std::string> & gnupg_recipients,
262 const std::vector<std::string> & gnupg_signatories,
263 bool empty,
264 const std::string & slice_permission,
265 bool add_marks_for_sequential_reading,
266 const std::string & user_comment,
267 hash_algo hash,
268 const infinint & slice_min_digits,
269 const label & internal_name,
270 const label & data_name,
271 const infinint & iteration_count,
272 hash_algo kdf_hash,
273 U_I multi_threaded_crypto,
274 U_I multi_threaded_compress);
275
277
288 extern void macro_tools_close_layers(const std::shared_ptr<user_interaction> & dialog,
289 pile & layers,
290 const header_version & ver,
291 const catalogue & cat,
292 bool info_details,
293 crypto_algo crypto,
294 compression algo,
295 const std::vector<std::string> & gnupg_recipients,
296 const std::vector<std::string> & gnupg_signatories,
297 bool empty);
298
299
301
306 extern range macro_tools_get_slices(const cat_nomme *obj, slice_layout sl);
307
309
316 extern void macro_tools_open_pipes(const std::shared_ptr<user_interaction> & dialog,
317 const std::string &input,
318 const std::string & output,
319 tuyau *&in,
320 tuyau *&out);
321
323
329 generic_file & base,
330 U_I compression_level,
331 U_I num_workers);
332
334
340 extern proto_compressor* macro_tools_build_block_compressor(compression algo,
341 generic_file & base,
342 U_I compression_level,
343 U_I num_workers,
344 U_I block_size);
345
347
348} // end of namespace
349
350
351#endif
here is defined the classe used to manage catalogue of archives
class archive_version manages the version of the archive format
the base class for all entry that have a name
Definition: cat_nomme.hpp:45
the catalogue class which gather all objects contained in a give archive
Definition: catalogue.hpp:60
this is the interface class from which all other data transfer classes inherit
manages the archive header and trailer
the arbitrary large positive integer class
manage label data structure used in archive slice headers
Definition: label.hpp:43
stores a stack of generic_files writing/reading on each others
Definition: pile.hpp:44
stores a range of integers or a set of ranges
Definition: range.hpp:44
class secu_string
Definition: secu_string.hpp:54
pipe implementation under the generic_file interface.
Definition: tuyau.hpp:49
compression parameters for API
the crypto algoritm definition
defines the entrepot interface.
class generic_file is defined here as well as class fichier
hash_algo
hashing algorithm available
Definition: archive_aux.hpp:63
compression
the different compression algorithm available
Definition: compression.hpp:46
crypto_algo
the different cypher available for encryption (strong or weak)
Definition: crypto.hpp:50
void macro_tools_create_layers(const std::shared_ptr< user_interaction > &dialog, pile &layers, header_version &ver, slice_layout &slicing, const slice_layout *ref_slicing, const std::shared_ptr< entrepot > &sauv_path_t, const std::string &filename, const std::string &extension, bool allow_over, bool warn_over, bool info_details, const infinint &pause, compression algo, U_I compression_level, U_I compression_block_size, const infinint &file_size, const infinint &first_file_size, const std::string &execute, crypto_algo crypto, const secu_string &pass, U_32 crypto_size, const std::vector< std::string > &gnupg_recipients, const std::vector< std::string > &gnupg_signatories, bool empty, const std::string &slice_permission, bool add_marks_for_sequential_reading, const std::string &user_comment, hash_algo hash, const infinint &slice_min_digits, const label &internal_name, const label &data_name, const infinint &iteration_count, hash_algo kdf_hash, U_I multi_threaded_crypto, U_I multi_threaded_compress)
build layers for a new archive
void macro_tools_close_layers(const std::shared_ptr< user_interaction > &dialog, pile &layers, const header_version &ver, const catalogue &cat, bool info_details, crypto_algo crypto, compression algo, const std::vector< std::string > &gnupg_recipients, const std::vector< std::string > &gnupg_signatories, bool empty)
dumps the catalogue and close all the archive layers to terminate the archive
range macro_tools_get_slices(const cat_nomme *obj, slice_layout sl)
gives the location of data EA and FSA (when they are saved) of the object given in argument
catalogue * macro_tools_read_catalogue(const std::shared_ptr< user_interaction > &dialog, const header_version &ver, const pile_descriptor &cata_pdesc, const infinint &cat_size, std::list< signator > &signatories, bool lax_mode, const label &lax_layer1_data_name, bool only_detruits)
read the catalogue from cata_stack assuming the cata_stack is positionned at the beginning of the are...
catalogue * macro_tools_get_catalogue_from(const std::shared_ptr< user_interaction > &dialog, pile &stack, const header_version &ver, bool info_details, infinint &cat_size, const infinint &second_terminateur_offset, std::list< signator > &signatories, bool lax_mode)
uses terminator to skip to the position where to find the catalogue and read it
void macro_tools_open_pipes(const std::shared_ptr< user_interaction > &dialog, const std::string &input, const std::string &output, tuyau *&in, tuyau *&out)
open a pair of tuyau objects encapsulating two named pipes.
catalogue * macro_tools_get_derivated_catalogue_from(const std::shared_ptr< user_interaction > &dialog, pile &data_stack, pile &cata_stack, const header_version &ver, bool info_details, infinint &cat_size, const infinint &second_terminateur_offset, std::list< signator > &signatories, bool lax_mode)
uses terminator to skip to the position where to find the catalogue and read it, taking care of havin...
proto_compressor * macro_tools_build_block_compressor(compression algo, generic_file &base, U_I compression_level, U_I num_workers, U_I block_size)
return a proto_compressor object realizing the desired (de)compression level/algo on to of "base" in ...
proto_compressor * macro_tools_build_streaming_compressor(compression algo, generic_file &base, U_I compression_level, U_I num_workers)
return a proto_compressor object realizing the desired (de)compression level/aglo on top of "base" in...
gf_mode
generic_file openning modes
Definition: gf_mode.hpp:44
trivial_sar * macro_tools_open_archive_tuyau(const std::shared_ptr< user_interaction > &dialog, S_I fd, gf_mode mode, const label &internal_name, const label &data_name, bool slice_header_format_07, const std::string &execute)
create an container to write an archive to a pipe
void macro_tools_open_archive(const std::shared_ptr< user_interaction > &dialog, const std::shared_ptr< entrepot > &where, const std::string &basename, const infinint &min_digits, const std::string &extension, crypto_algo crypto, const secu_string &pass, U_32 crypto_size, pile &stack, header_version &ver, const std::string &input_pipe, const std::string &output_pipe, const std::string &execute, infinint &second_terminateur_offset, bool lax, bool has_external_cat, bool sequential_read, bool info_details, std::list< signator > &gnupg_signed, slice_layout &sl, U_I multi_threaded_crypto, U_I multi_threaded_compress, bool header_only, bool silent, bool force_read_first_slice)
setup the given pile object to contain a stack of generic_files suitable to read an archive
archive global header/trailer structure is defined here
switch module to limitint (32 ou 64 bits integers) or infinint
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
class pile definition. Used to manage a stack of generic_file objects
abstracted ancestor class for compressor and parallel_compressor classes
class than provide a way to manipulate and represent range of integer numbers (infinint)
object describing the slicing of an archive
the trivial_sar classes manages the slicing layer when single slice is used
defines the implementation of pipe under the generic_file interface.