Disk ARchive  2.5.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-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 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 <vector>
47 
48 #include "integers.hpp"
49 #include "crc.hpp"
50 #include "fsa_family.hpp"
51 #include "on_pool.hpp"
52 
53 namespace libdar
54 {
57 
58 
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 
82  virtual ~filesystem_specific_attribute() throw(Ebug) {};
83 
85  bool is_same_type_as(const filesystem_specific_attribute & ref) const;
86 
88  virtual bool operator == (const filesystem_specific_attribute & ref) const { return is_same_type_as(ref) && equal_value_to(ref); };
89  bool operator != (const filesystem_specific_attribute & ref) const { return ! (*this == ref); };
90 
92  bool operator < (const filesystem_specific_attribute & ref) const;
93  bool operator >= (const filesystem_specific_attribute & ref) const { return !(*this < ref); };
94  bool operator > (const filesystem_specific_attribute & ref) const { return ref < *this; };
95  bool operator <= (const filesystem_specific_attribute & ref) const { return !(*this > ref); };
96 
97 
99  fsa_family get_family() const { return fam; };
100 
102  fsa_nature get_nature() const { return nat; };
103 
105  virtual std::string show_val() const = 0;
106 
108  virtual void write(generic_file & f) const = 0;
109 
111  virtual infinint storage_size() const = 0;
112 
114  virtual filesystem_specific_attribute *clone() const = 0;
115 
116  protected:
117  void set_family(const fsa_family & val) { fam = val; };
118  void set_nature(const fsa_nature & val) { nat = val; };
119 
121  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const = 0;
122 
123  private:
124  fsa_family fam;
125  fsa_nature nat;
126  };
127 
129 
130  class filesystem_specific_attribute_list : public on_pool
131  {
132  public:
133  filesystem_specific_attribute_list() {};
134  filesystem_specific_attribute_list(const filesystem_specific_attribute_list & ref) { copy_from(ref); };
135  const filesystem_specific_attribute_list & operator = (const filesystem_specific_attribute_list & ref) { clear(); copy_from(ref); return *this; };
136  ~filesystem_specific_attribute_list() { clear(); };
137 
139  void clear();
140 
142  void add(const filesystem_specific_attribute & fsa);
143 
145  fsa_scope get_fsa_families() const { return familes; };
146 
148  bool is_included_in(const filesystem_specific_attribute_list & ref, const fsa_scope & scope) const;
149 
151  void read(generic_file & f, archive_version ver);
152 
154  void write(generic_file & f) const;
155 
157  void get_fsa_from_filesystem_for(user_interaction & ui,
158  const std::string & target,
159  const fsa_scope & scope,
160  mode_t itype,
161  bool auto_zeroing_neg_dates);
162 
169  bool set_fsa_to_filesystem_for(const std::string & target,
170  const fsa_scope & scope,
171  user_interaction & ui) const;
172 
174  bool empty() const { return fsa.empty(); };
175 
176 
178  U_I size() const { return fsa.size(); };
179 
180 
182  const filesystem_specific_attribute & operator [] (U_I arg) const;
183 
185  infinint storage_size() const;
186 
191  filesystem_specific_attribute_list operator + (const filesystem_specific_attribute_list & arg) const;
192 
198  bool find(fsa_family fam, fsa_nature nat, const filesystem_specific_attribute *&ptr) const;
199 
200  private:
201  std::vector<filesystem_specific_attribute *> fsa; //< sorted list of FSA
202  fsa_scope familes;
203 
204  void copy_from(const filesystem_specific_attribute_list & ref);
205  void update_familes();
206  void priv_add(const filesystem_specific_attribute & ref); // add an entry without updating the "familes" field
207  void sort_fsa();
208 
209  void fill_extX_FSA_with(const std::string & target, mode_t itype);
210  void fill_HFS_FSA_with(user_interaction & ui,
211  const std::string & target,
212  mode_t itype,
213  bool auto_zeroing_neg_dates);
214 
216  bool set_extX_FSA_to(user_interaction & ui, const std::string & target) const;
217 
219  bool set_hfs_FSA_to(user_interaction & ui, const std::string & target) const;
220 
221  static std::string family_to_signature(fsa_family f);
222  static std::string nature_to_signature(fsa_nature n);
223  static fsa_family signature_to_family(const std::string & sig);
224  static fsa_nature signature_to_nature(const std::string & sig);
225  };
226 
228 
229  template <class T> T *cloner(const T *x, memory_pool *p)
230  {
231  if(x == nullptr)
232  throw SRC_BUG;
233  T *ret = new (p) T(*x);
234  if(ret == nullptr)
235  throw Ememory("cloner template");
236 
237  return ret;
238  }
239 
241 
242  class fsa_bool : public filesystem_specific_attribute
243  {
244  public:
245  fsa_bool(fsa_family f, fsa_nature n, bool xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
246  fsa_bool(generic_file & f, fsa_family fam, fsa_nature nat);
247 
248  bool get_value() const { return val; };
249 
251  virtual std::string show_val() const { return val ? gettext("true") : gettext("false"); };
252  virtual void write(generic_file & f) const { f.write(val ? "T" : "F", 1); };
253  virtual infinint storage_size() const { return 1; };
254  virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); };
255 
256  protected:
257  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
258 
259  private:
260  bool val;
261  };
262 
264 
265  class fsa_infinint : public filesystem_specific_attribute
266  {
267  public:
268  fsa_infinint(fsa_family f, fsa_nature n, infinint xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
269  fsa_infinint(generic_file & f, fsa_family fam, fsa_nature nat);
270 
271  const infinint & get_value() const { return val; };
272 
274  virtual std::string show_val() const;
275  virtual void write(generic_file & f) const { val.dump(f); };
276  virtual infinint storage_size() const { return val.get_storage_size(); };
277  virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); };
278 
279  protected:
280  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
281 
282  private:
283  infinint val;
284  };
285 
287 
288  class fsa_time : public filesystem_specific_attribute
289  {
290  public:
291  fsa_time(fsa_family f, fsa_nature n, datetime xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
292  fsa_time(generic_file & f, archive_version ver, fsa_family fam, fsa_nature nat);
293 
294  const datetime & get_value() const { return val; };
295 
297  virtual std::string show_val() const;
298  virtual void write(generic_file & f) const { val.dump(f); };
299  virtual infinint storage_size() const { return val.get_storage_size(); };
300  virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); };
301 
302  protected:
303  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
304 
305  private:
306  datetime val;
307  };
308 
310 
311 } // end of namespace
312 
313 #endif
filesystem specific attributes available families and fsa_scope definition
memory_pool * get_pool() const
Definition: on_pool.hpp:144
are defined here basic integer types that tend to be portable
fsa_family
FSA family.
Definition: fsa_family.hpp:42
class crc definition, used to handle Cyclic Redundancy Checks
fsa_family get_family() const
obtain the family of the FSA
filesystem_specific_attribute(fsa_family f)
constructor used to before reading the FSA from filesystem
fsa_nature
FSA nature.
Definition: fsa_family.hpp:46
This is a pure virtual class that is used by libdar when interaction with the user is required...
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
exception used when memory has been exhausted
Definition: erreurs.hpp:111
virtual void write(generic_file &f) const =0
write down to libdar archive
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition: erreurs.hpp:137
this is the interface class from which all other data transfer classes inherit
void write(const char *a, U_I size)
write data to the generic_file
this is the base class of object that can be allocated on a memory pool
virtual infinint storage_size() const =0
give the storage size for the FSA
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 &#39;this&#39; false in any other case...
the arbitrary large positive integer class
bool is_same_type_as(const filesystem_specific_attribute &ref) const
provide a mean to compare objects types
virtual std::string show_val() const =0
provides a human readable value of the FSA
virtual bool operator==(const filesystem_specific_attribute &ref) const
provides a mean to compare objects values
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
filesystem_specific_attribute(generic_file &f, fsa_family xfam, fsa_nature xnat)
constructor used to read a FSA from a libdar archive
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()
virtual destructor for inherited classes