Disk ARchive  2.5.14-bis
Full featured and portable backup and archiving tool
cat_inode.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_INODE_HPP
27 #define CAT_INODE_HPP
28 
29 #include "../my_config.h"
30 
31 extern "C"
32 {
33 } // end extern "C"
34 
35 #include "infinint.hpp"
36 #include "generic_file.hpp"
37 #include "ea.hpp"
38 #include "compressor.hpp"
39 #include "integers.hpp"
40 #include "mask.hpp"
41 #include "user_interaction.hpp"
42 #include "escape.hpp"
44 #include "datetime.hpp"
45 #include "cat_nomme.hpp"
46 
47 namespace libdar
48 {
51 
52 
54  class cat_inode : public cat_nomme
55  {
56  public:
57 
59 
61  {
62  cf_all, //< consider any available field for comparing inodes
63  cf_ignore_owner, //< consider any available field except ownership fields
64  cf_mtime, //< consider any available field except ownership and permission fields
65  cf_inode_type //< only consider the file type
66  };
67 
68  cat_inode(const infinint & xuid,
69  const infinint & xgid,
70  U_16 xperm,
71  const datetime & last_access,
72  const datetime & last_modif,
73  const datetime & last_change,
74  const std::string & xname,
75  const infinint & device);
76  cat_inode(user_interaction & dialog,
77  const smart_pointer<pile_descriptor> & pdesc,
78  const archive_version & reading_ver,
79  saved_status saved,
80  bool small);
81  cat_inode(const cat_inode & ref);
82  const cat_inode & operator = (const cat_inode & ref);
83  ~cat_inode() throw(Ebug);
84 
85  const infinint & get_uid() const { return uid; };
86  const infinint & get_gid() const { return gid; };
87  U_16 get_perm() const { return perm; };
88  datetime get_last_access() const { return last_acc; };
89  datetime get_last_modif() const { return last_mod; };
90  void set_last_access(const datetime & x_time) { last_acc = x_time; };
91  void set_last_modif(const datetime & x_time) { last_mod = x_time; };
92  saved_status get_saved_status() const { return xsaved; };
93  void set_saved_status(saved_status x) { xsaved = x; };
94  infinint get_device() const { if(fs_dev == nullptr) throw SRC_BUG; return *fs_dev; };
95 
96  bool same_as(const cat_inode & ref) const;
97  bool is_more_recent_than(const cat_inode & ref, const infinint & hourshift) const;
98  // used for RESTORATION
99  virtual bool has_changed_since(const cat_inode & ref, const infinint & hourshift, comparison_fields what_to_check) const;
100  // signature() left as an abstract method
101  // clone is abstract too
102  // used for INCREMENTAL BACKUP
103  void compare(const cat_inode &other,
104  const mask & ea_mask,
105  comparison_fields what_to_check,
106  const infinint & hourshift,
107  bool symlink_date,
108  const fsa_scope & scope,
109  bool isolated_mode) const; //< do not try to compare pointed to data, EA of FSA (suitable for isolated catalogue)
110 
111  // throw Erange exception if a difference has been detected
112  // this is not a symetrical comparison, but all what is present
113  // in the current object is compared against the argument
114  // which may contain supplementary informations
115  // used for DIFFERENCE
116 
117 
118 
120  // EXTENDED ATTRIBUTES Methods
121  //
122 
123  enum ea_status { ea_none, ea_partial, ea_fake, ea_full, ea_removed };
124  // ea_none : no EA present for this inode in filesystem
125  // ea_partial : EA present in filesystem but not stored (ctime used to check changes)
126  // ea_fake : EA present in filesystem but not attached to this inode (isolation context) no more used in archive version "08" and above, ea_partial or ea_full stays a valid status in isolated catalogue because pointers to EA and data are no more removed during isolation process.
127  // ea_full : EA present in filesystem and attached to this inode
128  // ea_removed : EA were present in the reference version, but not present anymore
129 
130  // I : to know whether EA data is present or not for this object
131  void ea_set_saved_status(ea_status status);
132  ea_status ea_get_saved_status() const { return ea_saved; };
133 
134  // II : to associate EA list to an cat_inode object (mainly for backup operation) #EA_FULL only#
135  void ea_attach(ea_attributs *ref);
136  const ea_attributs *get_ea() const; // #<-- EA_FULL *and* EA_REMOVED# for this call only
137  void ea_detach() const; //discards any future call to get_ea() !
138  infinint ea_get_size() const; //returns the size of EA (still valid if ea have been detached) mainly used to define CRC width
139 
140  // III : to record where is dump the EA in the archive #EA_FULL only#
141  void ea_set_offset(const infinint & pos);
142  bool ea_get_offset(infinint & pos) const;
143  void ea_set_crc(const crc & val);
144  void ea_get_crc(const crc * & ptr) const; //< the argument is set to point to an allocated crc object owned by this "cat_inode" object, this reference stays valid while the "cat_inode" object exists and MUST NOT be deleted by the caller in any case
145  bool ea_get_crc_size(infinint & val) const; //< returns true if crc is know and puts its width in argument
146 
147  // IV : to know/record if EA and FSA have been modified # any EA status# and FSA status #
148  datetime get_last_change() const { return last_cha; };
149  void set_last_change(const datetime & x_time) { last_cha = x_time; };
150  bool has_last_change() const { return !last_cha.is_null(); };
151  // old format did provide last_change only when EA were present, since archive
152  // format 8, this field is always present even in absence of EA. Thus it is
153  // still necessary to check if the cat_inode has a last_change() before
154  // using get_last_change() (depends on the version of the archive read).
155 
156 
158  // FILESYSTEM SPECIFIC ATTRIBUTES Methods
159  //
160  // there is not "remove status for FSA, either the cat_inode contains
161  // full copy of FSA or only remembers the families of FSA found in the unchanged cat_inode
162  // FSA none is used when the file has no FSA because:
163  // - either the underlying filesystem has no known FSA
164  // - or the underlying filesystem FSA support has not been activated at compilation time
165  // - or the fsa_scope requested at execution time exclude the filesystem FSA families available here
166  enum fsa_status { fsa_none, fsa_partial, fsa_full };
167 
168  // I : which FSA are present
169  void fsa_set_saved_status(fsa_status status);
170  fsa_status fsa_get_saved_status() const { return fsa_saved; };
172  fsa_scope fsa_get_families() const { if(fsa_families == nullptr) throw SRC_BUG; return infinint_to_fsa_scope(*fsa_families); };
173 
174 
175 
176  // II : add or drop FSA list to the cat_inode
177  void fsa_attach(filesystem_specific_attribute_list *ref);
178  void fsa_partial_attach(const fsa_scope & val); // #<-- FSA_PARTIAL only
179  const filesystem_specific_attribute_list *get_fsa() const; // #<-- FSA_FULL only
180  void fsa_detach() const; // discard any future call to get_fsa() !
181  infinint fsa_get_size() const; // returns the size of FSA (still valid if fsal has been detached) / mainly used to define CRC size
182 
183  // III : to record where FSA are dumped in the archive (only if fsa_status not empty !)
184  void fsa_set_offset(const infinint & pos);
185  bool fsa_get_offset(infinint & pos) const;
186  void fsa_set_crc(const crc & val);
187  void fsa_get_crc(const crc * & ptr) const;
188  bool fsa_get_crc_size(infinint & val) const;
189 
190  protected:
191  virtual void sub_compare(const cat_inode & other, bool isolated_mode) const {};
192  bool get_small_read() const { return small_read; }; //< true if object has been created by sequential reading of an archive
193 
194  // inherited from cat_entree
195  void inherited_dump(const pile_descriptor & pdesc, bool small) const;
196 
197 
198  private :
199  infinint uid; //< inode owner's user ID
200  infinint gid; //< inode owner's group ID
201  U_16 perm; //< inode's permission
202  datetime last_acc; //< last access time (atime)
203  datetime last_mod; //< last modification time (mtime)
204  datetime last_cha; //< last inode meta data change (ctime)
205  saved_status xsaved; //< inode data status
206  ea_status ea_saved; //< inode Extended Attribute status
207  fsa_status fsa_saved; //< inode Filesystem Specific Attribute status
208 
209  bool small_read; //< whether we the object has been built with sequential-reading
210 
211  // the following is used only if ea_saved == full
212  infinint *ea_offset; //< offset in archive where to find EA
213  ea_attributs *ea; //< Extended Attributes read or to be written down
214  infinint *ea_size; //< storage size required by EA
215  // the following is used if ea_saved == full or ea_saved == partial or
216  crc *ea_crc; //< CRC computed on EA
217 
218  infinint *fsa_families; //< list of FSA families present for that inode (set to nullptr in fsa_none mode)
219  infinint *fsa_offset; //< offset in archive where to find FSA # always allocated (to be reviewed)
220  filesystem_specific_attribute_list *fsal; //< Filesystem Specific Attributes read or to be written down # only allocated if fsa_saved if set to FULL
221  infinint *fsa_size; //< storage size required for FSA
222  crc *fsa_crc; //< CRC computed on FSA
223  //
224  infinint *fs_dev; //< filesystem ID on which resides the inode (only used when read from filesystem)
225  archive_version edit; //< need to know EA and FSA format used in archive file
226 
227 
228  void nullifyptr();
229  void destroy();
230  void copy_from(const cat_inode & ref);
231 
232  static const ea_attributs empty_ea;
233  };
234 
236 
237 } // end of namespace
238 
239 #endif
base class of all objects contained in a catalogue and that can be named
the generic class, parent of all masks
Definition: mask.hpp:62
are defined here basic integer types that tend to be portable
class generic_file is defined here as well as class fichierthe generic_file interface is widely used ...
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...
defines the interaction between libdar and the user.Three classes are defined
class escape definition, used for sequential reading of archivesThe class escape is used to insert es...
the base class for all entry that have a name
Definition: cat_nomme.hpp:44
filesystem specific attributes
switch module to limitint (32 ou 64 bits integers) or infinint
here lies a collection of mask classes
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition: erreurs.hpp:137
this file contains the definition of class datetime that stores unix times in a portable way ...
compression engine implementation
the root class for all cat_inode
Definition: cat_inode.hpp:54
the arbitrary large positive integer class
fsa_scope fsa_get_families() const
gives the set of FSA family recorded for that inode
Definition: cat_inode.hpp:172
contains a set of routines to manage EA values associated to a file
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