| Disk ARchive 2.5.10 Full featured and portable backup and archiving tool

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

generic_file.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
36
37
39 // IMPORTANT : THIS FILE MUST ALWAYS BE INCLUDE AFTER infinint.hpp //
40 // (and infinint.hpp must be included too, always) //
42 #include "infinint.hpp"
44
45
46
47 #ifndef GENERIC_FILE_HPP
48 #define GENERIC_FILE_HPP
49
50
51 #include "../my_config.h"
52
53 extern "C"
54 {
55 #if HAVE_UNISTD_H
56 #include <unistd.h>
57 #endif
58 } // end extern "C"
59
60 #include "path.hpp"
61 #include "integers.hpp"
62 #include "thread_cancellation.hpp"
63 #include "label.hpp"
64 #include "crc.hpp"
65 #include "user_interaction.hpp"
66 #include "on_pool.hpp"
67
68 #include <string>
69
70 namespace libdar
71 {
72
75
77 enum gf_mode
78 {
79 gf_read_only,
80 gf_write_only,
81 gf_read_write
82 };
83
85 extern const char * generic_file_get_name(gf_mode mode);
86
88
100 class generic_file : public on_pool
101 {
102 public :
104 generic_file(gf_mode m) { rw = m; terminated = no_read_ahead = false; enable_crc(false); checksum = nullptr; };
105
107 generic_file(const generic_file &ref) { copy_from(ref); };
108
110 virtual ~generic_file() throw(Ebug) { destroy(); };
111
113 void terminate() const;
114
115
117 const generic_file & operator = (const generic_file & ref) { destroy(); copy_from(ref); return *this; };
118
120 gf_mode get_mode() const { return rw; };
121
126 virtual void read_ahead(const infinint & amount);
127
134 void ignore_read_ahead(bool mode) { no_read_ahead = mode; };
135
137
143 U_I read(char *a, U_I size);
144
146
148 void write(const char *a, U_I size);
149
151
153 void write(const std::string & arg);
154
156 S_I read_back(char &a);
157
159 S_I read_forward(char &a) { if(terminated) throw SRC_BUG; return read(&a, 1); };
160
161
162 enum skippability { skip_backward, skip_forward };
163
169 virtual bool skippable(skippability direction, const infinint & amount) = 0;
170
176 virtual bool skip(const infinint & pos) = 0;
177
179 virtual bool skip_to_eof() = 0;
180
182 virtual bool skip_relative(S_I x) = 0;
183
185 virtual infinint get_position() const = 0;
186
188 virtual void copy_to(generic_file &ref);
189
191
196 virtual void copy_to(generic_file &ref, const infinint & crc_size, crc * & value);
197
199 U_32 copy_to(generic_file &ref, U_32 size); // returns the number of byte effectively copied
200
202 infinint copy_to(generic_file &ref, infinint size); // returns the number of byte effectively copied
203
205
215 bool diff(generic_file & f,
216 const infinint & me_read_ahead,
217 const infinint & you_read_ahead,
218 const infinint & crc_size,
219 crc * & value);
220
232 bool diff(generic_file & f,
233 const infinint & me_read_ahead,
234 const infinint & you_read_ahead,
235 const infinint & crc_size,
236 crc * & value,
237 infinint & err_offset);
238
240
242 void reset_crc(const infinint & width);
243
245 bool crc_status() const { return active_read == &generic_file::read_crc; };
246
248
252 crc *get_crc();
253
255 void sync_write();
256
258 void flush_read();
259
260
261 protected :
262 void set_mode(gf_mode x) { rw = x; };
263
269 virtual void inherited_read_ahead(const infinint & amount) = 0;
270
271
273
282 virtual U_I inherited_read(char *a, U_I size) = 0;
283
285
289 virtual void inherited_write(const char *a, U_I size) = 0;
290
291
293
297 virtual void inherited_sync_write() = 0;
298
305 virtual void inherited_flush_read() = 0;
306
308
311 virtual void inherited_terminate() = 0;
312
313
316 bool is_terminated() const { return terminated; };
317
318 private :
319 gf_mode rw;
320 crc *checksum;
321 bool terminated;
322 bool no_read_ahead;
323 U_I (generic_file::* active_read)(char *a, U_I size);
324 void (generic_file::* active_write)(const char *a, U_I size);
325
326 void enable_crc(bool mode);
327
328 U_I read_crc(char *a, U_I size);
329 void write_crc(const char *a, U_I size);
330 void destroy();
331 void copy_from(const generic_file & ref);
332 };
333
334 #define CONTEXT_INIT "init"
335 #define CONTEXT_OP "operation"
336 #define CONTEXT_LAST_SLICE "last_slice"
337
339
354
355 class label;
356
357 class contextual
358 {
359 public :
360 contextual() { status = ""; };
361 virtual ~contextual() throw(Ebug) {};
362
368 virtual void set_info_status(const std::string & s) { status = s; };
369
371 virtual std::string get_info_status() const { return status; };
372
374 virtual bool is_an_old_start_end_archive() const = 0;
375
380 virtual const label & get_data_name() const = 0;
381
382 private:
383 std::string status;
384 };
385
387
388 } // end of namespace
389
390 #endif
libdar::on_pool
Definition: on_pool.hpp:52
libdar::generic_file::inherited_write
virtual void inherited_write(const char *a, U_I size)=0
implementation of the write() operation
integers.hpp
are defined here basic integer types that tend to be portable
libdar::gf_write_only
write only access
Definition: generic_file.hpp:80
crc.hpp
class crc definition, used to handle Cyclic Redundancy Checks
libdar::generic_file::diff
bool diff(generic_file &f, const infinint &me_read_ahead, const infinint &you_read_ahead, const infinint &crc_size, crc *&value)
compares the contents with the object in argument
libdar::generic_file::get_position
virtual infinint get_position() const =0
get the current read/write position
libdar::generic_file::generic_file
generic_file(const generic_file &ref)
copy constructor
Definition: generic_file.hpp:107
label.hpp
define the datastructure "label" used to identify slice membership to an archive
libdar::generic_file::flush_read
void flush_read()
be ready to read at current position, reseting all pending data for reading, cached and in compressio...
libdar::generic_file::skip
virtual bool skip(const infinint &pos)=0
libdar::generic_file::read
U_I read(char *a, U_I size)
read data from the generic_file
libdar::generic_file::read_ahead
virtual void read_ahead(const infinint &amount)
libdar::generic_file::ignore_read_ahead
void ignore_read_ahead(bool mode)
Definition: generic_file.hpp:134
libdar::generic_file::~generic_file
virtual ~generic_file()
virtual destructor, this let inherited destructor to be called even from a generic_file pointer to an...
Definition: generic_file.hpp:110
libdar::generic_file::inherited_flush_read
virtual void inherited_flush_read()=0
libdar::gf_mode
gf_mode
generic_file openning modes
Definition: generic_file.hpp:77
libdar::generic_file::read_back
S_I read_back(char &a)
skip back one char, read on char and skip back one char
libdar::generic_file::skip_relative
virtual bool skip_relative(S_I x)=0
skip relatively to the current position
libdar::generic_file::is_terminated
bool is_terminated() const
Definition: generic_file.hpp:316
libdar::generic_file::get_crc
crc * get_crc()
get CRC of the transfered date since last reset
libdar::generic_file::inherited_sync_write
virtual void inherited_sync_write()=0
write down any pending data
libdar::generic_file::terminate
void terminate() const
destructor-like call, except that it is allowed to throw exceptions
user_interaction.hpp
defines the interaction between libdar and the user.Three classes are defined
libdar::generic_file_get_name
const char * generic_file_get_name(gf_mode mode)
provides a human readable string defining the gf_mode given in argument
path.hpp
here is the definition of the path classthe path class handle path and provide several operation on t...
thread_cancellation.hpp
to be able to cancel libdar operation while running in a given thread.the class thread_cancellation i...
libdar::generic_file::generic_file
generic_file(gf_mode m)
main constructor
Definition: generic_file.hpp:104
libdar::generic_file::operator=
const generic_file & operator=(const generic_file &ref)
assignment operator
Definition: generic_file.hpp:117
libdar::generic_file::inherited_terminate
virtual void inherited_terminate()=0
destructor-like call, except that it is allowed to throw exceptions
libdar::generic_file::get_mode
gf_mode get_mode() const
retreive the openning mode for this object
Definition: generic_file.hpp:120
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
libdar::generic_file::inherited_read
virtual U_I inherited_read(char *a, U_I size)=0
implementation of read() operation
libdar::generic_file::crc_status
bool crc_status() const
to known whether CRC calculation is activated or not
Definition: generic_file.hpp:245
libdar::generic_file::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount)=0
libdar::Ebug
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition: erreurs.hpp:137
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:100
libdar::generic_file::write
void write(const char *a, U_I size)
write data to the generic_file
libdar::gf_read_write
read and write access
Definition: generic_file.hpp:81
on_pool.hpp
this is the base class of object that can be allocated on a memory pool
libdar::generic_file::copy_to
virtual void copy_to(generic_file &ref)
copy all data from current position to the object in argument
libdar::generic_file::sync_write
void sync_write()
write any pending data
libdar::generic_file::reset_crc
void reset_crc(const infinint &width)
reset CRC on read or writen data
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:59
libdar::generic_file::skip_to_eof
virtual bool skip_to_eof()=0
skip to the end of file
libdar::gf_read_only
read only access
Definition: generic_file.hpp:79
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
libdar::generic_file::skippable
virtual bool skippable(skippability direction, const infinint &amount)=0
libdar::generic_file::read_forward
S_I read_forward(char &a)
read one char
Definition: generic_file.hpp:159