Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
sar.hpp
Go to the documentation of this file.
00001 /*********************************************************************/
00002 // dar - disk archive - a backup/restoration program
00003 // Copyright (C) 2002-2052 Denis Corbin
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 //
00019 // to contact the author : http://dar.linux.free.fr/email.html
00020 /*********************************************************************/
00021 
00025 
00026 #ifndef SAR_HPP
00027 #define SAR_HPP
00028 
00029 #include "../my_config.h"
00030 
00031 #include <string>
00032 #include "infinint.hpp"
00033 #include "generic_file.hpp"
00034 #include "header.hpp"
00035 #include "path.hpp"
00036 #include "integers.hpp"
00037 #include "entrepot.hpp"
00038 #include "tools.hpp"
00039 #include "slice_layout.hpp"
00040 
00041 namespace libdar
00042 {
00043     // contextual is defined in generic_file module
00044 
00047 
00049 
00054     class sar : public generic_file, public contextual, protected mem_ui
00055     {
00056     public:
00057 
00059 
00072         sar(const user_interaction & dialog,
00073         const std::string & base_name,
00074         const std::string & extension,
00075         const entrepot & where,
00076         bool by_the_end,
00077         const infinint & x_min_digits,
00078         bool lax = false,
00079         const std::string & execute = "");
00080 
00081 
00083 
00104         sar(const user_interaction  & dialog,
00105         gf_mode open_mode,
00106         const std::string & base_name,
00107         const std::string & extension,
00108         const infinint & file_size,
00109         const infinint & first_file_size,
00110         bool x_warn_overwrite,
00111         bool x_allow_overwrite,
00112         const infinint & pause,
00113         const entrepot & where,
00114         const label & internal_name,
00115         const label & data_name,
00116         bool force_permission,
00117         U_I permission,
00118         hash_algo x_hash,
00119         const infinint & x_min_digits,
00120         bool format_07_compatible,
00121         const std::string & execute = "");
00122 
00124 
00125     sar(const sar & ref) : generic_file(ref), mem_ui(ref) { throw Efeature("class sar's copy constructor is not implemented"); };
00126 
00128         ~sar();
00129 
00130             // inherited from generic_file
00131     bool skippable(skippability direction, const infinint & amount);
00132         bool skip(const infinint &pos);
00133         bool skip_to_eof();
00134         bool skip_relative(S_I x);
00135         infinint get_position() const;
00136 
00137             // informational routines
00138     const slice_layout & get_slicing() const { return slicing; };
00139         bool get_total_file_number(infinint &num) const { num = of_last_file_num; return of_last_file_known; };
00140         bool get_last_file_size(infinint &num) const { num = of_last_file_size; return of_last_file_known; };
00141 
00142         // disable execution of user command when destroying the current object
00143     void disable_natural_destruction() { natural_destruction = false; };
00144 
00145         // enable back execution of user command when destroying the current object
00146     void enable_natural_destruction() { natural_destruction = true; };
00147 
00148         // true if sar's header is from an old archive format (<= "07")
00149     bool is_an_old_start_end_archive() const { return slicing.older_sar_than_v8; };
00150 
00151         // return the internal_name used to link slices toghether
00152     const label & get_internal_name_used() const { return of_internal_name; };
00153 
00154         // return the data_name used to link slices toghether
00155     const label & get_data_name() const { return of_data_name; };
00156 
00157     const entrepot *get_entrepot() const { return entr; };
00158 
00159     protected :
00160     void inherited_read_ahead(const infinint & amount);
00161         U_I inherited_read(char *a, U_I size);
00162         void inherited_write(const char *a, U_I size);
00163     void inherited_sync_write() {}; // nothing to do
00164     void inherited_flush_read() {}; // nothing to do
00165     void inherited_terminate();
00166 
00167     private :
00168     entrepot *entr;              //< where are stored slices
00169         std::string base;            //< archive base name
00170     std::string ext;             //< archive extension
00171         std::string hook;            //< command line to execute between slices
00172     slice_layout slicing;        //< slice layout
00173         infinint file_offset;        //< current reading/writing position in the current slice (relative to the whole slice file, including headers)
00174     hash_algo hash;              //< whether to build a hashing when creating slices, and if so, which algorithm to use
00175     infinint min_digits;         //< minimum number of digits the slices number is stored with in the filename
00176         bool natural_destruction;    //< whether to execute commands between slices on object destruction
00177             // these following variables are modified by open_file / open_file_init
00178             // else the are used only for reading
00179         infinint of_current;         //< number of the open slice
00180     infinint size_of_current;    //< size of the current slice (used in reading mode only)
00181         infinint of_max_seen;        //< highest slice number seen so far
00182         bool of_last_file_known;     //< whether the T terminal slice has been met
00183         infinint of_last_file_num;   //< number of the last slice (if met)
00184         infinint of_last_file_size;  //< size of the last slice (if met)
00185         label of_internal_name;      //< internal name shared in all slice header
00186     label of_data_name;          //< internal name linked to data (transparent to dar_xform and used by isolated catalogue as reference)
00187     bool force_perm;             //< true if any future slice has its permission to be set explicitely
00188     U_I perm;                    //< if force_perm is true, value to use for slice permission
00189         fichier_global *of_fd;       //< file object currently openned
00190         char of_flag;                //< flags of the open file
00191         bool initial;                //< do not launch hook command-line during sar initialization
00192             // these are the option flags
00193         bool opt_warn_overwrite;     //<  a warning must be issued before overwriting a slice
00194         bool opt_allow_overwrite;    //< is slice overwriting allowed
00195         //
00196         infinint pause;              //< do we pause between slices
00197     bool lax;                    //< whether to try to go further reading problems
00198     infinint to_read_ahead;      //< amount of data to read ahead for next slices
00199 
00200         bool skip_forward(U_I x);                                  //< skip forward in sar global contents
00201         bool skip_backward(U_I x);                                 //< skip backward in sar global contents
00202         void close_file(bool terminal);                            //< close current openned file, adding (in write mode only) a terminal mark (last slice) or not
00203         void open_readonly(const std::string & fic, const infinint &num);  //< open file of name "filename" for read only "num" is the slice number
00204         void open_writeonly(const std::string & fic, const infinint &num); //< open file of name "filename" for write only "num" is the slice number
00205         void open_file_init();            //< initialize some of_* fields
00206         void open_file(infinint num);     //< close current slice and open the slice 'num'
00207         void set_offset(infinint offset); //< skip to current slice relative offset
00208         void open_last_file();            //< open the last slice, ask the user, test, until last slice available
00209     bool is_current_eof_a_normal_end_of_slice() const;  //< return true if current reading position is at end of slice
00210     infinint bytes_still_to_read_in_slice() const;  //< returns the number of bytes expected before the end of slice
00211         header make_write_header(const infinint &num, char flag);
00212 
00213             // function to lauch the eventually existing command to execute after/before each slice
00214         void hook_execute(const infinint &num);
00215     };
00216 
00218 
00219 } // end of namespace
00220 
00221 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines