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

Loading...
Searching...
No Matches
filesystem_specific_attribute.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2026 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
67 class filesystem_specific_attribute
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
81 filesystem_specific_attribute(const filesystem_specific_attribute & ref) = default;
82 filesystem_specific_attribute(filesystem_specific_attribute && ref) noexcept = default;
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
90 bool is_same_type_as(const filesystem_specific_attribute & ref) const;
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
137 class filesystem_specific_attribute_list
138 {
139 public:
140 filesystem_specific_attribute_list() {};
141 filesystem_specific_attribute_list(const filesystem_specific_attribute_list & ref) { copy_from(ref); };
142 filesystem_specific_attribute_list & operator = (const filesystem_specific_attribute_list & ref) { clear(); copy_from(ref); return *this; };
143 ~filesystem_specific_attribute_list() { clear(); };
144
146 void clear();
147
149 void add(const filesystem_specific_attribute & fsa);
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
158 void read(generic_file & f, archive_version ver);
159
161 void write(generic_file & f) const;
162
164 void get_fsa_from_filesystem_for(user_interaction & ui,
165 const std::string & target,
166 const fsa_scope & scope,
167 mode_t itype,
168 bool auto_zeroing_neg_dates);
169
171 bool has_linux_immutable_set() const;
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
194 const filesystem_specific_attribute & operator [] (U_I arg) const;
195
197 infinint storage_size() const;
198
200
203 filesystem_specific_attribute_list operator + (const filesystem_specific_attribute_list & arg) const;
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;
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
233 bool set_extX_FSA_to(user_interaction & ui,
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
289 class fsa_infinint : public filesystem_specific_attribute
290 {
291 public:
292 fsa_infinint(fsa_family f, fsa_nature n, infinint xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
293 fsa_infinint(generic_file & f, fsa_family fam, fsa_nature nat);
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
317 class fsa_time : public filesystem_specific_attribute
318 {
319 public:
320 fsa_time(fsa_family f, fsa_nature n, datetime xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
321 fsa_time(generic_file & f, archive_version ver, fsa_family fam, fsa_nature nat);
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
libdar::Ememory
exception used when memory has been exhausted
Definition erreurs.hpp:127
libdar::archive_version
class archive_version manages the version of the archive format
Definition archive_version.hpp:47
libdar::datetime
stores time information
Definition datetime.hpp:59
libdar::filesystem_specific_attribute_list::get_fsa_families
fsa_scope get_fsa_families() const
gives the set of FSA family present in the list
Definition filesystem_specific_attribute.hpp:152
libdar::filesystem_specific_attribute_list::clear
void clear()
clear all attributes
libdar::filesystem_specific_attribute_list::find
bool find(fsa_family fam, fsa_nature nat, const filesystem_specific_attribute *&ptr) const
look for the FSA of given familly and nature
libdar::filesystem_specific_attribute_list::has_linux_immutable_set
bool has_linux_immutable_set() const
return true if this FSA_list contains linux FSA with the immutable attribute set to true
libdar::filesystem_specific_attribute_list::add
void add(const filesystem_specific_attribute &fsa)
add an fsa to the list
libdar::filesystem_specific_attribute_list::read
void read(generic_file &f, archive_version ver)
read FSA list from archive
libdar::filesystem_specific_attribute_list::set_hfs_FSA_to
bool set_hfs_FSA_to(user_interaction &ui, const std::string &target) const
libdar::filesystem_specific_attribute_list::fsa
std::deque< filesystem_specific_attribute * > fsa
sorted list of FSA
Definition filesystem_specific_attribute.hpp:214
libdar::filesystem_specific_attribute_list::write
void write(generic_file &f) const
write FSA list to archive
libdar::filesystem_specific_attribute_list::get_fsa_from_filesystem_for
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
libdar::filesystem_specific_attribute_list::size
U_I size() const
access to members of the list
Definition filesystem_specific_attribute.hpp:190
libdar::filesystem_specific_attribute_list::empty
bool empty() const
whether the list has at least one FSA
Definition filesystem_specific_attribute.hpp:186
libdar::filesystem_specific_attribute_list::is_included_in
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...
libdar::filesystem_specific_attribute_list::operator+
filesystem_specific_attribute_list operator+(const filesystem_specific_attribute_list &arg) const
addition operator
libdar::filesystem_specific_attribute_list::operator[]
const filesystem_specific_attribute & operator[](U_I arg) const
provide reference to FSA given its index
libdar::filesystem_specific_attribute_list::storage_size
infinint storage_size() const
give the storage size for the EA
libdar::filesystem_specific_attribute_list::set_fsa_to_filesystem_for
bool set_fsa_to_filesystem_for(const std::string &target, const fsa_scope &scope, user_interaction &ui, bool set_linux_immutable) const
libdar::filesystem_specific_attribute_list::set_extX_FSA_to
bool set_extX_FSA_to(user_interaction &ui, const std::string &target, bool set_immutable) const
libdar::filesystem_specific_attribute
Filesystem Specific Attributes (FSA) class.
Definition filesystem_specific_attribute.hpp:68
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::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::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:93
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::operator<
bool operator<(const filesystem_specific_attribute &ref) const
used to provided a sorted list of FSA
libdar::filesystem_specific_attribute::get_nature
fsa_nature get_nature() const
obtain the nature of the FSA
Definition filesystem_specific_attribute.hpp:107
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::filesystem_specific_attribute::storage_size
virtual infinint storage_size() const =0
give the storage size for the FSA
libdar::filesystem_specific_attribute::get_family
fsa_family get_family() const
obtain the family of the FSA
Definition filesystem_specific_attribute.hpp:104
libdar::filesystem_specific_attribute::~filesystem_specific_attribute
virtual ~filesystem_specific_attribute() noexcept(false)
virtual destructor for inherited classes
Definition filesystem_specific_attribute.hpp:87
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::write
virtual void write(generic_file &f) const =0
write down to libdar archive
libdar::filesystem_specific_attribute::show_val
virtual std::string show_val() const =0
provides a human readable value of the FSA
libdar::fsa_infinint::write
virtual void write(generic_file &f) const
write down to libdar archive
Definition filesystem_specific_attribute.hpp:302
libdar::fsa_infinint::storage_size
virtual infinint storage_size() const
give the storage size for the FSA
Definition filesystem_specific_attribute.hpp:303
libdar::fsa_infinint::clone
virtual filesystem_specific_attribute * clone() const
provides a way to copy objects without having to know the more specific class of the object
Definition filesystem_specific_attribute.hpp:304
libdar::fsa_infinint::equal_value_to
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...
libdar::fsa_infinint::show_val
virtual std::string show_val() const
inherited from filesystem_specific_attribute
libdar::fsa_time::write
virtual void write(generic_file &f) const
write down to libdar archive
Definition filesystem_specific_attribute.hpp:330
libdar::fsa_time::show_val
virtual std::string show_val() const
inherited from filesystem_specific_attribute
libdar::fsa_time::storage_size
virtual infinint storage_size() const
give the storage size for the FSA
Definition filesystem_specific_attribute.hpp:331
libdar::fsa_time::equal_value_to
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...
libdar::fsa_time::clone
virtual filesystem_specific_attribute * clone() const
provides a way to copy objects without having to know the more specific class of the object
Definition filesystem_specific_attribute.hpp:332
libdar::generic_file
this is the interface class from which all other data transfer classes inherit
Definition generic_file.hpp:77
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
libdar::user_interaction
This is a pure virtual class that is used by libdar when interaction with the user is required.
Definition user_interaction.hpp:58
datetime.hpp
this file contains the definition of class datetime that stores unix times in a portable way
fsa_family.hpp
filesystem specific attributes available families and fsa_scope definition
generic_file.hpp
class generic_file is defined here as well as class fichier
libdar::fsa_scope
std::set< fsa_family > fsa_scope
set of fsa families
Definition fsa_family.hpp:70
libdar::fsa_family
fsa_family
FSA family.
Definition fsa_family.hpp:42
libdar::infinint::get_storage_size
infinint get_storage_size() const noexcept
it returns number of byte of information necessary to store the integer
Definition real_infinint.hpp:128
libdar::fsa_nature
fsa_nature
FSA nature.
Definition fsa_family.hpp:48
integers.hpp
are defined here basic integer types that tend to be portable
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47