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