Disk ARchive  2.7.15
Full featured and portable backup and archiving tool
filesystem_specific_attribute.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 FILESYSTEM_SPECIFIC_ATTRIBUTE_HPP
27 #define FILESYSTEM_SPECIFIC_ATTRIBUTE_HPP
28 
29 #include "../my_config.h"
30 
31 extern "C"
32 {
33 #if HAVE_SYS_TYPES_H
34 #include <sys/types.h>
35 #endif
36 #if HAVE_SYS_STAT_H
37 #include <sys/stat.h>
38 #endif
39 #if HAVE_UNISTD_H
40 #include <unistd.h>
41 #endif
42 
43 } // end extern "C"
44 
45 #include <string>
46 #include <deque>
47 
48 #include "integers.hpp"
49 #include "fsa_family.hpp"
50 #include "datetime.hpp"
51 #include "generic_file.hpp"
52 
53 namespace libdar
54 {
57 
58 
60 
66 
68  {
69  public:
70 
72 
76  filesystem_specific_attribute(fsa_family f) { fam = f; nat = fsan_unset; };
77 
79  filesystem_specific_attribute(generic_file & f, fsa_family xfam, fsa_nature xnat) { fam = xfam; nat = xnat; };
80 
83  filesystem_specific_attribute & operator = (const filesystem_specific_attribute & ref) = default;
84  filesystem_specific_attribute & operator = (filesystem_specific_attribute && ref) noexcept = default;
85 
87  virtual ~filesystem_specific_attribute() noexcept(false) {};
88 
91 
93  virtual bool operator == (const filesystem_specific_attribute & ref) const { return is_same_type_as(ref) && equal_value_to(ref); };
94  bool operator != (const filesystem_specific_attribute & ref) const { return ! (*this == ref); };
95 
97  bool operator < (const filesystem_specific_attribute & ref) const;
98  bool operator >= (const filesystem_specific_attribute & ref) const { return !(*this < ref); };
99  bool operator > (const filesystem_specific_attribute & ref) const { return ref < *this; };
100  bool operator <= (const filesystem_specific_attribute & ref) const { return !(*this > ref); };
101 
102 
104  fsa_family get_family() const { return fam; };
105 
107  fsa_nature get_nature() const { return nat; };
108 
110  virtual std::string show_val() const = 0;
111 
113  virtual void write(generic_file & f) const = 0;
114 
116  virtual infinint storage_size() const = 0;
117 
119  virtual filesystem_specific_attribute *clone() const = 0;
120 
121  protected:
122  void set_family(const fsa_family & val) { fam = val; };
123  void set_nature(const fsa_nature & val) { nat = val; };
124 
126  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const = 0;
127 
128  private:
129  fsa_family fam;
130  fsa_nature nat;
131  };
132 
134 
136 
138  {
139  public:
142  filesystem_specific_attribute_list & operator = (const filesystem_specific_attribute_list & ref) { clear(); copy_from(ref); return *this; };
144 
146  void clear();
147 
150 
152  fsa_scope get_fsa_families() const { return familes; };
153 
155  bool is_included_in(const filesystem_specific_attribute_list & ref, const fsa_scope & scope) const;
156 
159 
161  void write(generic_file & f) const;
162 
165  const std::string & target,
166  const fsa_scope & scope,
167  mode_t itype,
168  bool auto_zeroing_neg_dates);
169 
172 
180  bool set_fsa_to_filesystem_for(const std::string & target,
181  const fsa_scope & scope,
182  user_interaction & ui,
183  bool set_linux_immutable) const;
184 
186  bool empty() const { return fsa.empty(); };
187 
188 
190  U_I size() const { return fsa.size(); };
191 
192 
195 
198 
200 
204 
206 
211  bool find(fsa_family fam, fsa_nature nat, const filesystem_specific_attribute *&ptr) const;
212 
213  private:
214  std::deque<filesystem_specific_attribute *> fsa; //< sorted list of FSA
215  fsa_scope familes;
216 
217  void copy_from(const filesystem_specific_attribute_list & ref);
218  void update_familes();
219  void priv_add(const filesystem_specific_attribute & ref); // add an entry without updating the "familes" field
220  void sort_fsa();
221 
222  void fill_extX_FSA_with(const std::string & target, mode_t itype);
223  void fill_HFS_FSA_with(user_interaction & ui,
224  const std::string & target,
225  mode_t itype,
226  bool auto_zeroing_neg_dates);
227 
229 
234  const std::string & target,
235  bool set_immutable) const;
236 
238  bool set_hfs_FSA_to(user_interaction & ui, const std::string & target) const;
239 
240  static std::string family_to_signature(fsa_family f);
241  static std::string nature_to_signature(fsa_nature n);
242  static fsa_family signature_to_family(const std::string & sig);
243  static fsa_nature signature_to_nature(const std::string & sig);
244  };
245 
247 
248  template <class T> T *cloner(const T *x)
249  {
250  if(x == nullptr)
251  throw SRC_BUG;
252  T *ret = new (std::nothrow) T(*x);
253  if(ret == nullptr)
254  throw Ememory("cloner template");
255 
256  return ret;
257  }
258 
260 
261  class fsa_bool : public filesystem_specific_attribute
262  {
263  public:
264  fsa_bool(fsa_family f, fsa_nature n, bool xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
265  fsa_bool(generic_file & f, fsa_family fam, fsa_nature nat);
266  fsa_bool(const fsa_bool & ref) = default;
267  fsa_bool & operator = (const fsa_bool & ref) = default;
268  ~fsa_bool() = default;
269 
270  bool get_value() const { return val; };
271 
273  virtual std::string show_val() const { return val ? gettext("true") : gettext("false"); };
274  virtual void write(generic_file & f) const { f.write(val ? "T" : "F", 1); };
275  virtual infinint storage_size() const { return 1; };
276  virtual filesystem_specific_attribute *clone() const { return cloner(this); };
277 
278  protected:
279  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
280 
281  private:
282  bool val;
283  };
284 
286 
288 
290  {
291  public:
292  fsa_infinint(fsa_family f, fsa_nature n, infinint xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
294  fsa_infinint(const fsa_infinint & ref) = default;
295  fsa_infinint & operator = (const fsa_infinint & ref) = default;
296  ~fsa_infinint() = default;
297 
298  const infinint & get_value() const { return val; };
299 
301  virtual std::string show_val() const;
302  virtual void write(generic_file & f) const { val.dump(f); };
303  virtual infinint storage_size() const { return val.get_storage_size(); };
304  virtual filesystem_specific_attribute *clone() const { return cloner(this); };
305 
306  protected:
307  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
308 
309  private:
310  infinint val;
311  };
312 
314 
316 
318  {
319  public:
320  fsa_time(fsa_family f, fsa_nature n, datetime xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
322  fsa_time(const fsa_time & ref) = default;
323  fsa_time & operator = (const fsa_time & ref) = default;
324  ~fsa_time() = default;
325 
326  const datetime & get_value() const { return val; };
327 
329  virtual std::string show_val() const;
330  virtual void write(generic_file & f) const { val.dump(f); };
331  virtual infinint storage_size() const { return val.get_storage_size(); };
332  virtual filesystem_specific_attribute *clone() const { return cloner(this); };
333 
334  protected:
335  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
336 
337  private:
338  datetime val;
339  };
340 
342 
343 } // end of namespace
344 
345 #endif
exception used when memory has been exhausted
Definition: erreurs.hpp:127
class archive_version manages the version of the archive format
stores time information
Definition: datetime.hpp:59
void dump(generic_file &x) const
write down this to file
infinint get_storage_size() const
return the storage it would require to dump this object
fsa_scope get_fsa_families() const
gives the set of FSA family present in the list
const filesystem_specific_attribute & operator[](U_I arg) const
provide reference to FSA given its index
bool find(fsa_family fam, fsa_nature nat, const filesystem_specific_attribute *&ptr) const
look for the FSA of given familly and nature
bool has_linux_immutable_set() const
return true if this FSA_list contains linux FSA with the immutable attribute set to true
void add(const filesystem_specific_attribute &fsa)
add an fsa to the list
void read(generic_file &f, archive_version ver)
read FSA list from archive
bool set_hfs_FSA_to(user_interaction &ui, const std::string &target) const
void write(generic_file &f) const
write FSA list to archive
void get_fsa_from_filesystem_for(user_interaction &ui, const std::string &target, const fsa_scope &scope, mode_t itype, bool auto_zeroing_neg_dates)
read FSA list from filesystem
U_I size() const
access to members of the list
bool empty() const
whether the list has at least one FSA
bool is_included_in(const filesystem_specific_attribute_list &ref, const fsa_scope &scope) const
compare two lists of FSA to see whether they have equal FSA with identical values within the given fa...
filesystem_specific_attribute_list operator+(const filesystem_specific_attribute_list &arg) const
addition operator
infinint storage_size() const
give the storage size for the EA
bool set_fsa_to_filesystem_for(const std::string &target, const fsa_scope &scope, user_interaction &ui, bool set_linux_immutable) const
bool set_extX_FSA_to(user_interaction &ui, const std::string &target, bool set_immutable) const
Filesystem Specific Attributes (FSA) class.
bool is_same_type_as(const filesystem_specific_attribute &ref) const
provide a mean to compare objects types
virtual bool equal_value_to(const filesystem_specific_attribute &ref) const =0
should return true if the value of the argument is equal to the one of 'this' false in any other case...
virtual bool operator==(const filesystem_specific_attribute &ref) const
provides a mean to compare objects values
bool operator<(const filesystem_specific_attribute &ref) const
used to provided a sorted list of FSA
fsa_nature get_nature() const
obtain the nature of the FSA
filesystem_specific_attribute(fsa_family f)
constructor used to before reading the FSA from filesystem
virtual infinint storage_size() const =0
give the storage size for the FSA
fsa_family get_family() const
obtain the family of the FSA
virtual filesystem_specific_attribute * clone() const =0
provides a way to copy objects without having to know the more specific class of the object
virtual ~filesystem_specific_attribute() noexcept(false)
virtual destructor for inherited classes
filesystem_specific_attribute(generic_file &f, fsa_family xfam, fsa_nature xnat)
constructor used to read a FSA from a libdar archive
virtual void write(generic_file &f) const =0
write down to libdar archive
virtual std::string show_val() const =0
provides a human readable value of the FSA
virtual void write(generic_file &f) const
write down to libdar archive
virtual infinint storage_size() const
give the storage size for the FSA
virtual bool equal_value_to(const filesystem_specific_attribute &ref) const
should return true if the value of the argument is equal to the one of 'this' false in any other case...
virtual filesystem_specific_attribute * clone() const
provides a way to copy objects without having to know the more specific class of the object
virtual std::string show_val() const
inherited from filesystem_specific_attribute
virtual void write(generic_file &f) const
write down to libdar archive
virtual filesystem_specific_attribute * clone() const
provides a way to copy objects without having to know the more specific class of the object
virtual std::string show_val() const
inherited from filesystem_specific_attribute
virtual infinint storage_size() const
give the storage size for the FSA
virtual bool equal_value_to(const filesystem_specific_attribute &ref) const
should return true if the value of the argument is equal to the one of 'this' false in any other case...
this is the interface class from which all other data transfer classes inherit
the arbitrary large positive integer class
This is a pure virtual class that is used by libdar when interaction with the user is required.
this file contains the definition of class datetime that stores unix times in a portable way
filesystem specific attributes available families and fsa_scope definition
class generic_file is defined here as well as class fichier
std::set< fsa_family > fsa_scope
set of fsa families
Definition: fsa_family.hpp:70
fsa_family
FSA family.
Definition: fsa_family.hpp:42
infinint get_storage_size() const noexcept
it returns number of byte of information necessary to store the integer
fsa_nature
FSA nature.
Definition: fsa_family.hpp:48
are defined here basic integer types that tend to be portable
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47