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 : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 // $Id$ 00022 // 00023 /*********************************************************************/ 00024 00039 00040 00042 // IMPORTANT : THIS FILE MUST ALWAYS BE INCLUDE AFTER infinint.hpp // 00043 // (and infinint.hpp must be included too, always) // 00045 #include "infinint.hpp" 00047 00048 00049 00050 #ifndef GENERIC_FILE_HPP 00051 #define GENERIC_FILE_HPP 00052 00053 00054 #include "../my_config.h" 00055 00056 extern "C" 00057 { 00058 #if HAVE_UNISTD_H 00059 #include <unistd.h> 00060 #endif 00061 } // end extern "C" 00062 00063 #include "path.hpp" 00064 #include "integers.hpp" 00065 #include "thread_cancellation.hpp" 00066 #include "label.hpp" 00067 #include "crc.hpp" 00068 #include "user_interaction.hpp" 00069 #include "mem_ui.hpp" 00070 00071 #include <string> 00072 00073 namespace libdar 00074 { 00075 00078 00080 enum gf_mode 00081 { 00082 gf_read_only, 00083 gf_write_only, 00084 gf_read_write 00085 }; 00086 00087 00088 extern gf_mode generic_file_get_mode(S_I fd); 00089 extern const char * generic_file_get_name(gf_mode mode); 00090 00092 00104 class generic_file 00105 { 00106 public : 00108 generic_file(gf_mode m) { rw = m; terminated = false; enable_crc(false); checksum = NULL; }; 00109 00111 generic_file(const generic_file &ref) { copy_from(ref); }; 00112 00113 00115 00117 void terminate() const; 00118 00119 virtual ~generic_file() { destroy(); }; 00120 00122 const generic_file & operator = (const generic_file & ref) { destroy(); copy_from(ref); return *this; }; 00123 00125 gf_mode get_mode() const { return rw; }; 00126 00128 00134 U_I read(char *a, U_I size); 00135 00137 00139 void write(const char *a, U_I size); 00140 00142 00144 void write(const std::string & arg); 00145 00147 S_I read_back(char &a); 00148 00150 S_I read_forward(char &a) { if(terminated) throw SRC_BUG; return read(&a, 1); }; 00151 00153 00157 virtual bool skip(const infinint & pos) = 0; 00158 00160 virtual bool skip_to_eof() = 0; 00161 00163 virtual bool skip_relative(S_I x) = 0; 00164 00166 virtual infinint get_position() = 0; 00167 00169 virtual void copy_to(generic_file &ref); 00170 00172 00177 virtual void copy_to(generic_file &ref, const infinint & crc_size, crc * & value); 00178 00180 U_32 copy_to(generic_file &ref, U_32 size); // returns the number of byte effectively copied 00181 00183 infinint copy_to(generic_file &ref, infinint size); // returns the number of byte effectively copied 00184 00186 00194 bool diff(generic_file & f, const infinint & crc_size, crc * & value); 00195 00197 00199 void reset_crc(const infinint & width); 00200 00202 bool crc_status() const { return active_read == &generic_file::read_crc; }; 00203 00205 00209 crc *get_crc(); 00210 00212 void sync_write(); 00213 00214 protected : 00215 void set_mode(gf_mode x) { rw = x; }; 00216 00218 00227 virtual U_I inherited_read(char *a, U_I size) = 0; 00228 00230 00234 virtual void inherited_write(const char *a, U_I size) = 0; 00235 00236 00238 00241 virtual void inherited_sync_write() = 0; 00242 00243 00245 00248 virtual void inherited_terminate() = 0; 00249 00250 00253 bool is_terminated() const { return terminated; }; 00254 00255 private : 00256 gf_mode rw; 00257 crc *checksum; 00258 bool terminated; 00259 U_I (generic_file::* active_read)(char *a, U_I size); 00260 void (generic_file::* active_write)(const char *a, U_I size); 00261 00262 void enable_crc(bool mode); 00263 00264 U_I read_crc(char *a, U_I size); 00265 void write_crc(const char *a, U_I size); 00266 void destroy(); 00267 void copy_from(const generic_file & ref); 00268 }; 00269 00270 #define CONTEXT_INIT "init" 00271 #define CONTEXT_OP "operation" 00272 #define CONTEXT_LAST_SLICE "last_slice" 00273 00275 00290 00291 class label; 00292 00293 class contextual 00294 { 00295 public : 00296 contextual() { status = ""; }; 00297 virtual ~contextual() {}; 00298 00299 virtual void set_info_status(const std::string & s) { status = s; }; 00300 virtual std::string get_info_status() const { return status; }; 00301 virtual bool is_an_old_start_end_archive() const = 0; 00302 00303 virtual const label & get_data_name() const = 0; 00304 00305 private: 00306 std::string status; 00307 }; 00308 00310 00311 } // end of namespace 00312 00313 #endif