| Disk ARchive 2.5.10 Full featured and portable backup and archiving tool

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
67 class filesystem_specific_attribute : public on_pool
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(const std::string & target,
158 const fsa_scope & scope,
159 mode_t itype);
160
167 bool set_fsa_to_filesystem_for(const std::string & target,
168 const fsa_scope & scope,
169 user_interaction & ui) const;
170
172 bool empty() const { return fsa.empty(); };
173
174
176 U_I size() const { return fsa.size(); };
177
178
180 const filesystem_specific_attribute & operator [] (U_I arg) const;
181
183 infinint storage_size() const;
184
189 filesystem_specific_attribute_list operator + (const filesystem_specific_attribute_list & arg) const;
190
196 bool find(fsa_family fam, fsa_nature nat, const filesystem_specific_attribute *&ptr) const;
197
198 private:
199 std::vector<filesystem_specific_attribute *> fsa; //< sorted list of FSA
200 fsa_scope familes;
201
202 void copy_from(const filesystem_specific_attribute_list & ref);
203 void update_familes();
204 void priv_add(const filesystem_specific_attribute & ref); // add an entry without updating the "familes" field
205 void sort_fsa();
206
207 void fill_extX_FSA_with(const std::string & target, mode_t itype);
208 void fill_HFS_FSA_with(const std::string & target, mode_t itype);
209
211 bool set_extX_FSA_to(user_interaction & ui, const std::string & target) const;
212
214 bool set_hfs_FSA_to(user_interaction & ui, const std::string & target) const;
215
216 static std::string family_to_signature(fsa_family f);
217 static std::string nature_to_signature(fsa_nature n);
218 static fsa_family signature_to_family(const std::string & sig);
219 static fsa_nature signature_to_nature(const std::string & sig);
220 };
221
223
224 template <class T> T *cloner(const T *x, memory_pool *p)
225 {
226 if(x == nullptr)
227 throw SRC_BUG;
228 T *ret = new (p) T(*x);
229 if(ret == nullptr)
230 throw Ememory("cloner template");
231
232 return ret;
233 }
234
236
237 class fsa_bool : public filesystem_specific_attribute
238 {
239 public:
240 fsa_bool(fsa_family f, fsa_nature n, bool xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
241 fsa_bool(generic_file & f, fsa_family fam, fsa_nature nat);
242
243 bool get_value() const { return val; };
244
246 virtual std::string show_val() const { return val ? gettext("true") : gettext("false"); };
247 virtual void write(generic_file & f) const { f.write(val ? "T" : "F", 1); };
248 virtual infinint storage_size() const { return 1; };
249 virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); };
250
251 protected:
252 virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
253
254 private:
255 bool val;
256 };
257
259
260 class fsa_infinint : public filesystem_specific_attribute
261 {
262 public:
263 fsa_infinint(fsa_family f, fsa_nature n, infinint xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
264 fsa_infinint(generic_file & f, fsa_family fam, fsa_nature nat);
265
266 const infinint & get_value() const { return val; };
267
269 virtual std::string show_val() const;
270 virtual void write(generic_file & f) const { val.dump(f); };
271 virtual infinint storage_size() const { return val.get_storage_size(); };
272 virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); };
273
274 protected:
275 virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
276
277 private:
278 infinint val;
279 };
280
282
283 class fsa_time : public filesystem_specific_attribute
284 {
285 public:
286 fsa_time(fsa_family f, fsa_nature n, datetime xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
287 fsa_time(generic_file & f, archive_version ver, fsa_family fam, fsa_nature nat);
288
289 const datetime & get_value() const { return val; };
290
292 virtual std::string show_val() const;
293 virtual void write(generic_file & f) const { val.dump(f); };
294 virtual infinint storage_size() const { return val.get_storage_size(); };
295 virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); };
296
297 protected:
298 virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
299
300 private:
301 datetime val;
302 };
303
305
306 } // end of namespace
307
308 #endif
libdar::on_pool
Definition: on_pool.hpp:52
fsa_family.hpp
filesystem specific attributes available families and fsa_scope definition
integers.hpp
are defined here basic integer types that tend to be portable
libdar::fsa_family
fsa_family
FSA family.
Definition: fsa_family.hpp:42
crc.hpp
class crc definition, used to handle Cyclic Redundancy Checks
libdar::filesystem_specific_attribute::filesystem_specific_attribute
filesystem_specific_attribute(fsa_family f)
constructor used to before reading the FSA from filesystem
Definition: filesystem_specific_attribute.hpp:76
libdar::fsa_nature
fsa_nature
FSA nature.
Definition: fsa_family.hpp:46
libdar::filesystem_specific_attribute::is_same_type_as
bool is_same_type_as(const filesystem_specific_attribute &ref) const
provide a mean to compare objects types
libdar::on_pool::get_pool
memory_pool * get_pool() const
Definition: on_pool.hpp:144
libdar::filesystem_specific_attribute::get_family
fsa_family get_family() const
obtain the family of the FSA
Definition: filesystem_specific_attribute.hpp:99
libdar::filesystem_specific_attribute::operator<
bool operator<(const filesystem_specific_attribute &ref) const
used to provided a sorted list of FSA
libdar::filesystem_specific_attribute::write
virtual void write(generic_file &f) const =0
write down to libdar archive
libdar::Ebug
exception used to signal a bug. A bug is triggered when reaching some code that should never be reach...
Definition: erreurs.hpp:137
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition: generic_file.hpp:100
on_pool.hpp
this is the base class of object that can be allocated on a memory pool
libdar::filesystem_specific_attribute
Definition: filesystem_specific_attribute.hpp:67
libdar::filesystem_specific_attribute::get_nature
fsa_nature get_nature() const
obtain the nature of the FSA
Definition: filesystem_specific_attribute.hpp:102
libdar::filesystem_specific_attribute::storage_size
virtual infinint storage_size() const =0
give the storage size for the FSA
libdar::filesystem_specific_attribute::equal_value_to
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...
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:59
libdar::filesystem_specific_attribute::show_val
virtual std::string show_val() const =0
provides a human readable value of the FSA
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
libdar::filesystem_specific_attribute::operator==
virtual bool operator==(const filesystem_specific_attribute &ref) const
provides a mean to compare objects values
Definition: filesystem_specific_attribute.hpp:88
libdar::filesystem_specific_attribute::filesystem_specific_attribute
filesystem_specific_attribute(generic_file &f, fsa_family xfam, fsa_nature xnat)
constructor used to read a FSA from a libdar archive
Definition: filesystem_specific_attribute.hpp:79
libdar::filesystem_specific_attribute::clone
virtual filesystem_specific_attribute * clone() const =0
provides a way to copy objects without having to know the more specific class of the object ...
libdar::filesystem_specific_attribute::~filesystem_specific_attribute
virtual ~filesystem_specific_attribute()
virtual destructor for inherited classes
Definition: filesystem_specific_attribute.hpp:82