Disk ARchive  2.5.4
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  fsa_scope get_fsa_families() const { return familes; };
143 
145  bool is_included_in(const filesystem_specific_attribute_list & ref, const fsa_scope & scope) const;
146 
148  void read(generic_file & f, archive_version ver);
149 
151  void write(generic_file & f) const;
152 
154  void get_fsa_from_filesystem_for(const std::string & target,
155  const fsa_scope & scope,
156  mode_t itype);
157 
164  bool set_fsa_to_filesystem_for(const std::string & target,
165  const fsa_scope & scope,
166  user_interaction & ui) const;
167 
169  bool empty() const { return fsa.empty(); };
170 
171 
173  U_I size() const { return fsa.size(); };
174 
175 
177  const filesystem_specific_attribute & operator [] (U_I arg) const;
178 
180  infinint storage_size() const;
181 
186  filesystem_specific_attribute_list operator + (const filesystem_specific_attribute_list & arg) const;
187 
193  bool find(fsa_family fam, fsa_nature nat, const filesystem_specific_attribute *&ptr) const;
194 
195  private:
196  std::vector<filesystem_specific_attribute *> fsa; //< sorted list of FSA
197  fsa_scope familes;
198 
199  void copy_from(const filesystem_specific_attribute_list & ref);
200  void update_familes();
201  void add(const filesystem_specific_attribute & ref); // add an entry without updating the "familes" field
202  void sort_fsa();
203 
204  void fill_extX_FSA_with(const std::string & target, mode_t itype);
205  void fill_HFS_FSA_with(const std::string & target, mode_t itype);
206 
208  bool set_extX_FSA_to(user_interaction & ui, const std::string & target) const;
209 
211  bool set_hfs_FSA_to(user_interaction & ui, const std::string & target) const;
212 
213  static std::string family_to_signature(fsa_family f);
214  static std::string nature_to_signature(fsa_nature n);
215  static fsa_family signature_to_family(const std::string & sig);
216  static fsa_nature signature_to_nature(const std::string & sig);
217  };
218 
220 
221  template <class T> T *cloner(const T *x, memory_pool *p)
222  {
223  if(x == nullptr)
224  throw SRC_BUG;
225  T *ret = new (p) T(*x);
226  if(ret == nullptr)
227  throw Ememory("cloner template");
228 
229  return ret;
230  }
231 
233 
234  class fsa_bool : public filesystem_specific_attribute
235  {
236  public:
237  fsa_bool(fsa_family f, fsa_nature n, bool xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
238  fsa_bool(generic_file & f, fsa_family fam, fsa_nature nat);
239 
240  bool get_value() const { return val; };
241 
243  virtual std::string show_val() const { return val ? gettext("true") : gettext("false"); };
244  virtual void write(generic_file & f) const { f.write(val ? "T" : "F", 1); };
245  virtual infinint storage_size() const { return 1; };
246  virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); };
247 
248  protected:
249  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
250 
251  private:
252  bool val;
253  };
254 
256 
257  class fsa_infinint : public filesystem_specific_attribute
258  {
259  public:
260  fsa_infinint(fsa_family f, fsa_nature n, infinint xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
261  fsa_infinint(generic_file & f, fsa_family fam, fsa_nature nat);
262 
263  const infinint & get_value() const { return val; };
264 
266  virtual std::string show_val() const;
267  virtual void write(generic_file & f) const { val.dump(f); };
268  virtual infinint storage_size() const { return val.get_storage_size(); };
269  virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); };
270 
271  protected:
272  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
273 
274  private:
275  infinint val;
276  };
277 
279 
280  class fsa_time : public filesystem_specific_attribute
281  {
282  public:
283  fsa_time(fsa_family f, fsa_nature n, datetime xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
284  fsa_time(generic_file & f, archive_version ver, fsa_family fam, fsa_nature nat);
285 
286  const datetime & get_value() const { return val; };
287 
289  virtual std::string show_val() const;
290  virtual void write(generic_file & f) const { val.dump(f); };
291  virtual infinint storage_size() const { return val.get_storage_size(); };
292  virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); };
293 
294  protected:
295  virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
296 
297  private:
298  datetime val;
299  };
300 
302 
303 } // end of namespace
304 
305 #endif
filesystem specific attributes available families and fsa_scope definition
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
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 is_same_type_as(const filesystem_specific_attribute &ref) const
provide a mean to compare objects types
memory_pool * get_pool() const
Definition: on_pool.hpp:144
fsa_family get_family() const
obtain the family of the FSA
exception used when memory has been exhausted
Definition: erreurs.hpp:111
bool operator<(const filesystem_specific_attribute &ref) const
used to provided a sorted list of FSA
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
fsa_nature get_nature() const
obtain the nature of the FSA
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
class archive_version manages the version of the archive format
virtual std::string show_val() const =0
provides a human readable value of the FSA
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
virtual bool operator==(const filesystem_specific_attribute &ref) const
provides a mean to compare objects values
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