Disk ARchive  2.7.14
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-2024 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 //
19 // to contact the author, see the AUTHOR file
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 "ea.hpp"
37 #include "integers.hpp"
38 #include "mask.hpp"
39 #include "user_interaction.hpp"
41 #include "datetime.hpp"
42 #include "cat_nomme.hpp"
43 #include "archive_aux.hpp"
44 
45 namespace libdar
46 {
49 
51 
52  class cat_inode : public cat_nomme
53  {
54  public:
55 
57 
58  cat_inode(const infinint & xuid,
59  const infinint & xgid,
60  U_16 xperm,
61  const datetime & last_access,
62  const datetime & last_modif,
63  const datetime & last_change,
64  const std::string & xname,
65  const infinint & device);
66  cat_inode(const std::shared_ptr<user_interaction> & dialog,
67  const smart_pointer<pile_descriptor> & pdesc,
68  const archive_version & reading_ver,
69  saved_status saved,
70  bool small);
71  cat_inode(const cat_inode & ref);
72  cat_inode(cat_inode && ref) noexcept: cat_nomme(std::move(ref)) { nullifyptr(); move_from(std::move(ref)); };
73  cat_inode & operator = (const cat_inode & ref);
74  cat_inode & operator = (cat_inode && ref) noexcept { cat_nomme::operator = (std::move(ref)); move_from(std::move(ref)); return *this; };
75  ~cat_inode() noexcept(false);
76 
77  const infinint & get_uid() const { return uid; };
78  const infinint & get_gid() const { return gid; };
79  U_16 get_perm() const { return perm; };
80  datetime get_last_access() const { return last_acc; };
81  datetime get_last_modif() const { return last_mod; };
82  void set_last_access(const datetime & x_time) { last_acc = x_time; };
83  void set_last_modif(const datetime & x_time) { last_mod = x_time; };
84  infinint get_device() const { if(fs_dev == nullptr) throw SRC_BUG; return *fs_dev; };
85 
86  bool same_as(const cat_inode & ref) const;
87  bool is_more_recent_than(const cat_inode & ref, const infinint & hourshift) const;
88  // used for RESTORATION
89  virtual bool has_changed_since(const cat_inode & ref, const infinint & hourshift, comparison_fields what_to_check) const;
90  // signature() left as an abstract method
91  // clone is abstract too
92  // used for INCREMENTAL BACKUP
93  void compare(const cat_inode &other,
94  const mask & ea_mask,
95  comparison_fields what_to_check,
96  const infinint & hourshift,
97  bool symlink_date,
98  const fsa_scope & scope,
99  bool isolated_mode) const;
100 
101  // throw Erange exception if a difference has been detected
102  // this is not a symetrical comparison, but all what is present
103  // in the current object is compared against the argument
104  // which may contain supplementary informations
105  // used for DIFFERENCE
106 
107 
108 
110  // EXTENDED ATTRIBUTES Methods
111  //
112 
113  // I : to know whether EA data is present or not for this object
114  void ea_set_saved_status(ea_saved_status status);
115  ea_saved_status ea_get_saved_status() const { return ea_saved; };
116 
117  // II : to associate EA list to an cat_inode object (mainly for backup operation) #EA_FULL only#
118  void ea_attach(ea_attributs *ref);
119 
121  const ea_attributs *get_ea() const; // #<-- EA_FULL *and* EA_REMOVED# for this call only
122  void ea_detach() const; //discards any future call to get_ea() !
123  infinint ea_get_size() const; //returns the size of EA (still valid if ea have been detached) mainly used to define CRC width
124 
125  // III : to record where is dump the EA in the archive #EA_FULL only#
126  void ea_set_offset(const infinint & pos);
127  bool ea_get_offset(infinint & pos) const;
128  void ea_set_crc(const crc & val);
129  void ea_get_crc(const crc * & ptr) const;
130  bool ea_get_crc_size(infinint & val) const;
131 
132  // IV : to know/record if EA and FSA have been modified # any EA status# and FSA status #
133  datetime get_last_change() const { return last_cha; };
134  void set_last_change(const datetime & x_time) { last_cha = x_time; };
135  bool has_last_change() const { return !last_cha.is_null(); };
136  // old format did provide last_change only when EA were present, since archive
137  // format 8, this field is always present even in absence of EA. Thus it is
138  // still necessary to check if the cat_inode has a last_change() before
139  // using get_last_change() (depends on the version of the archive read).
140 
141 
143  // FILESYSTEM SPECIFIC ATTRIBUTES Methods
144  //
145 
146  // I : which FSA are present
147  void fsa_set_saved_status(fsa_saved_status status);
148  fsa_saved_status fsa_get_saved_status() const { return fsa_saved; };
150  fsa_scope fsa_get_families() const { if(fsa_families == nullptr) throw SRC_BUG; return infinint_to_fsa_scope(*fsa_families); };
151 
152 
153 
154  // II : add or drop FSA list to the cat_inode
155  void fsa_attach(filesystem_specific_attribute_list *ref);
156  void fsa_partial_attach(const fsa_scope & val); // #<-- FSA_PARTIAL only
157  const filesystem_specific_attribute_list *get_fsa() const; // #<-- FSA_FULL only
158  void fsa_detach() const; // discard any future call to get_fsa() !
159  infinint fsa_get_size() const; // returns the size of FSA (still valid if fsal has been detached) / mainly used to define CRC size
160 
161  // III : to record where FSA are dumped in the archive (only if fsa_status not empty !)
162  void fsa_set_offset(const infinint & pos);
163  bool fsa_get_offset(infinint & pos) const;
164  void fsa_set_crc(const crc & val);
165  void fsa_get_crc(const crc * & ptr) const;
166  bool fsa_get_crc_size(infinint & val) const;
167 
168  protected:
169  virtual void sub_compare(const cat_inode & other, bool isolated_mode) const {};
170  bool get_small_read() const { return small_read; };
171 
172  // inherited from cat_entree
173  virtual void inherited_dump(const pile_descriptor & pdesc, bool small) const override;
174 
175 
176  private :
179  U_16 perm;
185 
186  bool small_read;
187 
188  // the following is used only if ea_saved == full
192  // the following is used if ea_saved == full or ea_saved == partial or
194 
200  //
203 
204 
205  void nullifyptr() noexcept;
206  void destroy() noexcept;
207  void copy_from(const cat_inode & ref);
208  void move_from(cat_inode && ref) noexcept;
209 
210  static const ea_attributs empty_ea;
211  };
212 
214 
215 } // end of namespace
216 
217 #endif
set of datastructures used to interact with a catalogue object
base class of all objects contained in a catalogue and that can be named
class archive_version manages the version of the archive format
the root class for all cat_inode
Definition: cat_inode.hpp:53
infinint * ea_size
storage size required by EA
Definition: cat_inode.hpp:191
void compare(const cat_inode &other, const mask &ea_mask, comparison_fields what_to_check, const infinint &hourshift, bool symlink_date, const fsa_scope &scope, bool isolated_mode) const
do not try to compare pointed to data, EA of FSA (suitable for isolated catalogue)
datetime last_mod
last modification time (mtime)
Definition: cat_inode.hpp:181
datetime last_acc
last access time (atime)
Definition: cat_inode.hpp:180
U_16 perm
inode's permission
Definition: cat_inode.hpp:179
bool ea_get_crc_size(infinint &val) const
returns true if crc is know and puts its width in argument
archive_version edit
need to know EA and FSA format used in archive file
Definition: cat_inode.hpp:202
virtual void inherited_dump(const pile_descriptor &pdesc, bool small) const override
true if object has been created by sequential reading of an archive
ea_attributs * ea
Extended Attributes read or to be written down.
Definition: cat_inode.hpp:190
infinint uid
inode owner's user ID
Definition: cat_inode.hpp:177
infinint * fsa_size
storage size required for FSA
Definition: cat_inode.hpp:198
cat_inode(const infinint &xuid, const infinint &xgid, U_16 xperm, const datetime &last_access, const datetime &last_modif, const datetime &last_change, const std::string &xname, const infinint &device)
flag used to only consider certain fields when comparing/restoring inodes
infinint * fsa_families
list of FSA families present for that inode (set to nullptr in fsa_none mode)
Definition: cat_inode.hpp:195
crc * fsa_crc
CRC computed on FSA.
Definition: cat_inode.hpp:199
bool small_read
whether we the object has been built with sequential-reading
Definition: cat_inode.hpp:186
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,...
infinint * fs_dev
filesystem ID on which resides the inode (only used when read from filesystem)
Definition: cat_inode.hpp:201
crc * ea_crc
CRC computed on EA.
Definition: cat_inode.hpp:193
infinint * ea_offset
offset in archive where to find EA
Definition: cat_inode.hpp:189
ea_saved_status ea_saved
inode Extended Attribute status
Definition: cat_inode.hpp:183
datetime last_cha
last inode meta data change (ctime)
Definition: cat_inode.hpp:182
fsa_saved_status fsa_saved
inode Filesystem Specific Attribute status
Definition: cat_inode.hpp:184
infinint * fsa_offset
offset in archive where to find FSA # always allocated (to be reviewed)
Definition: cat_inode.hpp:196
filesystem_specific_attribute_list * fsal
Filesystem Specific Attributes read or to be written down # only allocated if fsa_saved if set to FUL...
Definition: cat_inode.hpp:197
infinint gid
inode owner's group ID
Definition: cat_inode.hpp:178
const ea_attributs * get_ea() const
the returned value is the address of an existing file of the cat_inode object and shall not be delete...
fsa_scope fsa_get_families() const
gives the set of FSA family recorded for that inode
Definition: cat_inode.hpp:150
the base class for all entry that have a name
Definition: cat_nomme.hpp:45
pure virtual class defining interface of a CRC object
Definition: crc.hpp:47
stores time information
Definition: datetime.hpp:59
bool is_null() const
return true if the datetime is exactly January 1st, 1970, 0 h 0 mn 0 s
Definition: datetime.hpp:131
the class ea_attributs manages the set of EA that can be associated to an inode
Definition: ea.hpp:49
the arbitrary large positive integer class
the generic class, parent of all masks
Definition: mask.hpp:62
this file contains the definition of class datetime that stores unix times in a portable way
contains a set of routines to manage EA values associated to a file
filesystem specific attributes
comparison_fields
how to consider file change during comparison and incremental backup
Definition: archive_aux.hpp:53
std::set< fsa_family > fsa_scope
set of fsa families
Definition: fsa_family.hpp:70
fsa_scope infinint_to_fsa_scope(const infinint &ref)
convert an infinint to fsa_scape
fsa_saved_status
FSA saved status for an entry.
Definition: cat_status.hpp:74
saved_status
data saved status for an entry
Definition: cat_status.hpp:45
ea_saved_status
EA saved status for an entry.
Definition: cat_status.hpp:56
switch module to limitint (32 ou 64 bits integers) or infinint
are defined here basic integer types that tend to be portable
here lies a collection of mask classes
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
defines the interaction interface between libdar and users.