Disk ARchive
2.4.5
|
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 : dar.linux@free.fr 00020 /*********************************************************************/ 00021 // $Id$ 00022 // 00023 /*********************************************************************/ 00024 00025 #ifndef SAR_HPP 00026 #define SAR_HPP 00027 00028 #pragma interface 00029 00030 #include <string> 00031 #include "generic_file.hpp" 00032 #include "header.hpp" 00033 #include "path.hpp" 00034 #include "integers.hpp" 00035 00036 #define SAR_OPT_DEFAULT (SAR_OPT_WARN_OVERWRITE) 00037 #define SAR_OPT_WARN_OVERWRITE 0x01 00038 #define SAR_OPT_DONT_ERASE 0x02 00039 #define SAR_OPT_PAUSE 0x04 00040 00041 class sar : public generic_file 00042 { 00043 public: 00044 sar(const string & base_name, const string & extension, S_I options, const path & dir, const string & execute = ""); 00045 sar(const string & base_name, const string & extension, const infinint & file_size, const infinint & first_file_size, S_I options, const path & dir, const string & execute = ""); 00046 ~sar(); 00047 00048 // inherited from generic_file 00049 bool skip(const infinint &pos); 00050 bool skip_to_eof(); 00051 bool skip_relative(S_I x); 00052 infinint get_position(); 00053 00054 // informational routines 00055 infinint get_sub_file_size() const { return size; }; 00056 infinint get_first_sub_file_size() const { return first_size; }; 00057 bool get_total_file_number(infinint &num) const { num = of_last_file_num; return of_last_file_known; }; 00058 bool get_last_file_size(infinint &num) const { num = of_last_file_size; return of_last_file_known; }; 00059 00060 protected : 00061 S_I inherited_read(char *a, size_t sz); 00062 S_I inherited_write(char *a, size_t sz); 00063 00064 private : 00065 path archive_dir; 00066 string base, ext; 00067 string hook; 00068 infinint size; 00069 infinint first_size; 00070 infinint first_file_offset; 00071 infinint file_offset; 00072 00073 // theses following variables are modified by open_file 00074 // else the are used only for reading 00075 infinint of_current; 00076 infinint of_max_seen; 00077 bool of_last_file_known; 00078 infinint of_last_file_num; 00079 infinint of_last_file_size; 00080 label of_internal_name; 00081 fichier *of_fd; 00082 char of_flag; 00083 bool initial; 00084 00085 // theses are the option flags 00086 bool opt_warn_overwrite; 00087 bool opt_dont_erase; 00088 bool opt_pause; 00089 00090 bool skip_forward(U_I x); 00091 bool skip_backward(U_I x); 00092 void close_file(); 00093 void open_readonly(char *fic, const infinint &num); 00094 void open_writeonly(char *fic, const infinint &num); 00095 void open_file_init(); 00096 void open_file(infinint num); 00097 void set_options(S_I opt); 00098 void set_offset(infinint offset); 00099 void open_last_file(); 00100 header make_write_header(const infinint &num, char flag); 00101 00102 // hook to attach a command to execute after each slice 00103 string hook_substitute(const string & path, const string & basename, const string & num); 00104 void hook_execute(const infinint &num); 00105 }; 00106 00107 00108 class trivial_sar : public generic_file 00109 { 00110 public: 00111 trivial_sar(generic_file *ref); // trivial_sar own the argument 00112 ~trivial_sar() { if(reference != NULL) delete reference; }; 00113 00114 bool skip(const infinint & pos) { return reference->skip(pos + offset); }; 00115 bool skip_to_eof() { return reference->skip_to_eof(); }; 00116 bool skip_relative(S_I x); 00117 infinint get_position(); 00118 00119 protected: 00120 S_I inherited_read(char *a, size_t size) { return reference->read(a, size); }; 00121 S_I inherited_write(char *a, size_t size) { return reference->write(a, size); }; 00122 00123 private: 00124 generic_file *reference; 00125 infinint offset; 00126 }; 00127 00128 extern string sar_make_filename(string base_name, infinint num, string ext); 00129 00130 #endif