Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
cat_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 
25 
26 #ifndef CAT_FILE_HPP
27 #define CAT_FILE_HPP
28 
29 #include "../my_config.h"
30 
31 extern "C"
32 {
33 } // end extern "C"
34 
35 #include "cat_inode.hpp"
36 
37 namespace libdar
38 {
39 
42 
43 
45  class cat_file : public cat_inode
46  {
47  public :
48  enum get_data_mode
49  {
50  keep_compressed, //< provide access to compressed data
51  keep_hole, //< provide access to uncompressed data but sparse_file datastructure
52  normal, //< provide access to full data (uncompressed, uses skip() to restore holes)
53  plain //< provide access to plain data, no skip to restore holes, provide instead zeroed bytes
54  };
55 
56  static const U_8 FILE_DATA_WITH_HOLE = 0x01; //< file's data contains hole datastructure
57  static const U_8 FILE_DATA_IS_DIRTY = 0x02; //< data modified while being saved
58 
59  cat_file(const infinint & xuid,
60  const infinint & xgid,
61  U_16 xperm,
62  const datetime & last_access,
63  const datetime & last_modif,
64  const datetime & last_change,
65  const std::string & src,
66  const path & che,
67  const infinint & taille,
68  const infinint & fs_device,
69  bool x_furtive_read_mode);
70  cat_file(const cat_file & ref);
71  cat_file(user_interaction & dialog,
72  const pile_descriptor & pdesc,
73  const archive_version & reading_ver,
74  saved_status saved,
75  compression default_algo,
76  bool small);
77  ~cat_file() { detruit(); };
78 
79  bool has_changed_since(const cat_inode & ref, const infinint & hourshift, cat_inode::comparison_fields what_to_check) const;
80  infinint get_size() const { return *size; };
81  void change_size(const infinint & s) const { *size = s; };
82  infinint get_storage_size() const { return *storage_size; };
83  void set_storage_size(const infinint & s) { *storage_size = s; };
84  virtual generic_file *get_data(get_data_mode mode) const; // returns a newly allocated object in read_only mode
85  void clean_data(); // partially free memory (but get_data() becomes disabled)
86  void set_offset(const infinint & r);
87  const infinint & get_offset() const;
88  unsigned char signature() const { return mk_signature('f', get_saved_status()); };
89 
90  void set_crc(const crc &c);
91  bool get_crc(const crc * & c) const; //< the argument is set the an allocated crc object the owned by the "cat_file" object, its stay valid while this "cat_file" object exists and MUST NOT be deleted by the caller in any case
92  bool has_crc() const { return check != nullptr; };
93  bool get_crc_size(infinint & val) const; //< returns true if crc is know and puts its width in argument
94  void drop_crc() { if(check != nullptr) { delete check; check = nullptr; } };
95 
96  // whether the plain file has to detect sparse file
97  void set_sparse_file_detection_read(bool val) { if(status == from_cat) throw SRC_BUG; if(val) file_data_status_read |= FILE_DATA_WITH_HOLE; else file_data_status_read &= ~FILE_DATA_WITH_HOLE; };
98 
99  void set_sparse_file_detection_write(bool val) { if(val) file_data_status_write |= FILE_DATA_WITH_HOLE; else file_data_status_write &= ~FILE_DATA_WITH_HOLE; };
100 
101  // whether the plain file is stored with a sparse_file datastructure in the archive
102  bool get_sparse_file_detection_read() const { return (file_data_status_read & FILE_DATA_WITH_HOLE) != 0; };
103  bool get_sparse_file_detection_write() const { return (file_data_status_write & FILE_DATA_WITH_HOLE) != 0; };
104 
105  cat_entree *clone() const { return new (get_pool()) cat_file(*this); };
106 
107  compression get_compression_algo_read() const { return algo_read; };
108 
109  compression get_compression_algo_write() const { return algo_write; };
110 
111  // object migration methods (merging)
112  void change_compression_algo_write(compression x) { algo_write = x; };
113 
114  // dirtiness
115 
116  bool is_dirty() const { return dirty; };
117  void set_dirty(bool value) { dirty = value; };
118 
119  protected:
120  void sub_compare(const cat_inode & other, bool isolated_mode) const;
121  void inherited_dump(const pile_descriptor & pdesc, bool small) const;
122  void post_constructor(const pile_descriptor & pdesc);
123 
124  enum { empty, from_path, from_cat } status;
125 
126  private:
127  std::string chemin; //< path to the data (when read from filesystem)
128  infinint *offset; //< start location of the data in 'loc'
129  infinint *size; //< size of the data (uncompressed)
130  infinint *storage_size; //< how much data used in archive (after compression)
131  crc *check;
132  bool dirty; //< true when a file has been modified at the time it was saved
133 
134  compression algo_read; //< which compression algorithm to use to read the file's data
135  compression algo_write; //< which compression algorithm to use to write down (merging) the file's data
136  bool furtive_read_mode; // used only when status equals "from_path"
137  char file_data_status_read; // defines the datastructure to use when reading the data
138  char file_data_status_write; // defines the datastructure to apply when writing down the data
139 
140  void detruit();
141  };
142 
144 
145 } // end of namespace
146 
147 #endif
void inherited_dump(const pile_descriptor &pdesc, bool small) const
inherited class may overload this method but shall first call the parent's inherited_dump() in the ov...
This is a pure virtual class that is used by libdar when interaction with the user is required...
cat_entree * clone() const
a way to copy the exact type of an object even if pointed to by a parent class pointer ...
Definition: cat_file.hpp:105
memory_pool * get_pool() const
Definition: on_pool.hpp:144
the plain file class
Definition: cat_file.hpp:45
void post_constructor(const pile_descriptor &pdesc)
compression
the different compression algorithm available
Definition: compressor.hpp:43
this is the interface class from which all other data transfer classes inherit
unsigned char signature() const
inherited class signature
Definition: cat_file.hpp:88
the root class for all cat_inode
Definition: cat_inode.hpp:54
base object for all inode types, managed EA and FSA, dates, permissions, ownership, ...
the arbitrary large positive integer class
class archive_version manages the version of the archive format
comparison_fields
flag used to only consider certain fields when comparing/restoring inodes
Definition: cat_inode.hpp:60
the root class from all other inherite for any entry in the catalogue
Definition: cat_entree.hpp:84
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
the class path is here to manipulate paths in the Unix notation: using'/'
Definition: path.hpp:50