Disk ARchive  2.5.0
Full featured and portable backup and archiving tool
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
sar.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 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 SAR_HPP
27 #define SAR_HPP
28 
29 #include "../my_config.h"
30 
31 #include <string>
32 #include "infinint.hpp"
33 #include "generic_file.hpp"
34 #include "header.hpp"
35 #include "path.hpp"
36 #include "integers.hpp"
37 #include "entrepot.hpp"
38 #include "tools.hpp"
39 #include "slice_layout.hpp"
40 
41 namespace libdar
42 {
43  // contextual is defined in generic_file module
44 
47 
49 
54  class sar : public generic_file, public contextual, protected mem_ui
55  {
56  public:
57 
59 
72  sar(const user_interaction & dialog,
73  const std::string & base_name,
74  const std::string & extension,
75  const entrepot & where,
76  bool by_the_end,
77  const infinint & x_min_digits,
78  bool lax = false,
79  const std::string & execute = "");
80 
81 
83 
104  sar(const user_interaction & dialog,
105  gf_mode open_mode,
106  const std::string & base_name,
107  const std::string & extension,
108  const infinint & file_size,
109  const infinint & first_file_size,
110  bool x_warn_overwrite,
111  bool x_allow_overwrite,
112  const infinint & pause,
113  const entrepot & where,
114  const label & internal_name,
115  const label & data_name,
116  bool force_permission,
117  U_I permission,
118  hash_algo x_hash,
119  const infinint & x_min_digits,
120  bool format_07_compatible,
121  const std::string & execute = "");
122 
124 
125  sar(const sar & ref) : generic_file(ref), mem_ui(ref) { throw Efeature("class sar's copy constructor is not implemented"); };
126 
128  ~sar();
129 
130  // inherited from generic_file
131  bool skippable(skippability direction, const infinint & amount);
132  bool skip(const infinint &pos);
133  bool skip_to_eof();
134  bool skip_relative(S_I x);
135  infinint get_position() const;
136 
137  // informational routines
138  const slice_layout & get_slicing() const { return slicing; };
139  bool get_total_file_number(infinint &num) const { num = of_last_file_num; return of_last_file_known; };
140  bool get_last_file_size(infinint &num) const { num = of_last_file_size; return of_last_file_known; };
141 
142  // disable execution of user command when destroying the current object
143  void disable_natural_destruction() { natural_destruction = false; };
144 
145  // enable back execution of user command when destroying the current object
146  void enable_natural_destruction() { natural_destruction = true; };
147 
148  // true if sar's header is from an old archive format (<= "07")
149  bool is_an_old_start_end_archive() const { return slicing.older_sar_than_v8; };
150 
151  // return the internal_name used to link slices toghether
152  const label & get_internal_name_used() const { return of_internal_name; };
153 
154  // return the data_name used to link slices toghether
155  const label & get_data_name() const { return of_data_name; };
156 
157  const entrepot *get_entrepot() const { return entr; };
158 
159  protected :
160  void inherited_read_ahead(const infinint & amount);
161  U_I inherited_read(char *a, U_I size);
162  void inherited_write(const char *a, U_I size);
163  void inherited_sync_write() {}; // nothing to do
164  void inherited_flush_read() {}; // nothing to do
165  void inherited_terminate();
166 
167  private :
168  entrepot *entr; //< where are stored slices
169  std::string base; //< archive base name
170  std::string ext; //< archive extension
171  std::string hook; //< command line to execute between slices
172  slice_layout slicing; //< slice layout
173  infinint file_offset; //< current reading/writing position in the current slice (relative to the whole slice file, including headers)
174  hash_algo hash; //< whether to build a hashing when creating slices, and if so, which algorithm to use
175  infinint min_digits; //< minimum number of digits the slices number is stored with in the filename
176  bool natural_destruction; //< whether to execute commands between slices on object destruction
177  // these following variables are modified by open_file / open_file_init
178  // else the are used only for reading
179  infinint of_current; //< number of the open slice
180  infinint size_of_current; //< size of the current slice (used in reading mode only)
181  infinint of_max_seen; //< highest slice number seen so far
182  bool of_last_file_known; //< whether the T terminal slice has been met
183  infinint of_last_file_num; //< number of the last slice (if met)
184  infinint of_last_file_size; //< size of the last slice (if met)
185  label of_internal_name; //< internal name shared in all slice header
186  label of_data_name; //< internal name linked to data (transparent to dar_xform and used by isolated catalogue as reference)
187  bool force_perm; //< true if any future slice has its permission to be set explicitely
188  U_I perm; //< if force_perm is true, value to use for slice permission
189  fichier_global *of_fd; //< file object currently openned
190  char of_flag; //< flags of the open file
191  bool initial; //< do not launch hook command-line during sar initialization
192  // these are the option flags
193  bool opt_warn_overwrite; //< a warning must be issued before overwriting a slice
194  bool opt_allow_overwrite; //< is slice overwriting allowed
195  //
196  infinint pause; //< do we pause between slices
197  bool lax; //< whether to try to go further reading problems
198  infinint to_read_ahead; //< amount of data to read ahead for next slices
199 
200  bool skip_forward(U_I x); //< skip forward in sar global contents
201  bool skip_backward(U_I x); //< skip backward in sar global contents
202  void close_file(bool terminal); //< close current openned file, adding (in write mode only) a terminal mark (last slice) or not
203  void open_readonly(const std::string & fic, const infinint &num); //< open file of name "filename" for read only "num" is the slice number
204  void open_writeonly(const std::string & fic, const infinint &num); //< open file of name "filename" for write only "num" is the slice number
205  void open_file_init(); //< initialize some of_* fields
206  void open_file(infinint num); //< close current slice and open the slice 'num'
207  void set_offset(infinint offset); //< skip to current slice relative offset
208  void open_last_file(); //< open the last slice, ask the user, test, until last slice available
209  bool is_current_eof_a_normal_end_of_slice() const; //< return true if current reading position is at end of slice
210  infinint bytes_still_to_read_in_slice() const; //< returns the number of bytes expected before the end of slice
211  header make_write_header(const infinint &num, char flag);
212 
213  // function to lauch the eventually existing command to execute after/before each slice
214  void hook_execute(const infinint &num);
215  };
216 
218 
219 } // end of namespace
220 
221 #endif
void inherited_flush_read()
Definition: sar.hpp:164
defines the entrepot interface. Entrepot interface defines a generic way to interact with files (slic...
sar(const sar &ref)
the destructor
Definition: sar.hpp:125
are defined here basic integer types that tend to be portable
a set of general purpose routines
bool skip_to_eof()
skip to the end of file
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
void inherited_sync_write()
write down any pending data
Definition: sar.hpp:163
This is a pure virtual class that is used by libdar when interaction with the user is required...
Sar class stands for Segmentation And Reassembly class.
Definition: sar.hpp:54
U_I inherited_read(char *a, U_I size)
implementation of read() operation
~sar()
destructor
gf_mode
generic_file openning modes
object describing the slicing of an archive
void inherited_read_ahead(const infinint &amount)
bool skippable(skippability direction, const infinint &amount)
slice header structure is defined here
here is the definition of the path classthe path class handle path and provide several operation on t...
exception used when a requested feature is not (yet) implemented
Definition: erreurs.hpp:206
void inherited_terminate()
destructor-like call, except that it is allowed to throw exceptions
switch module to limitint (32 ou 64 bits integers) or infinint
this is the interface class from which all other data transfer classes inherit
class mem_ui to keep a copy of a user_interaction object
Definition: mem_ui.hpp:53
bool skip(const infinint &pos)
void inherited_write(const char *a, U_I size)
implementation of the write() operation
the arbitrary large positive integer class
bool skip_relative(S_I x)
skip relatively to the current position
this class manages the header of each slice
Definition: header.hpp:68
sar(const user_interaction &dialog, const std::string &base_name, const std::string &extension, const entrepot &where, bool by_the_end, const infinint &x_min_digits, bool lax=false, const std::string &execute="")
this constructor reads data from a set of slices
the Entrepot interface
Definition: entrepot.hpp:61
infinint get_position() const
get the current read/write position