Loading...
Searching...
No Matches
filesystem_specific_attribute.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2024 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef FILESYSTEM_SPECIFIC_ATTRIBUTE_HPP
#define FILESYSTEM_SPECIFIC_ATTRIBUTE_HPP
#include "../my_config.h"
extern "C"
{
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
} // end extern "C"
#include <string>
#include <deque>
#include "integers.hpp"
#include "fsa_family.hpp"
#include "datetime.hpp"
#include "generic_file.hpp"
namespace libdar
{
class filesystem_specific_attribute
{
public:
filesystem_specific_attribute(fsa_family f) { fam = f; nat = fsan_unset; };
filesystem_specific_attribute(generic_file & f, fsa_family xfam, fsa_nature xnat) { fam = xfam; nat = xnat; };
filesystem_specific_attribute(const filesystem_specific_attribute & ref) = default;
filesystem_specific_attribute(filesystem_specific_attribute && ref) noexcept = default;
filesystem_specific_attribute & operator = (const filesystem_specific_attribute & ref) = default;
filesystem_specific_attribute & operator = (filesystem_specific_attribute && ref) noexcept = default;
virtual ~filesystem_specific_attribute() noexcept(false) {};
bool is_same_type_as(const filesystem_specific_attribute & ref) const;
virtual bool operator == (const filesystem_specific_attribute & ref) const { return is_same_type_as(ref) && equal_value_to(ref); };
bool operator != (const filesystem_specific_attribute & ref) const { return ! (*this == ref); };
bool operator < (const filesystem_specific_attribute & ref) const;
bool operator >= (const filesystem_specific_attribute & ref) const { return !(*this < ref); };
bool operator > (const filesystem_specific_attribute & ref) const { return ref < *this; };
bool operator <= (const filesystem_specific_attribute & ref) const { return !(*this > ref); };
fsa_family get_family() const { return fam; };
fsa_nature get_nature() const { return nat; };
virtual std::string show_val() const = 0;
virtual void write(generic_file & f) const = 0;
virtual infinint storage_size() const = 0;
virtual filesystem_specific_attribute *clone() const = 0;
protected:
void set_family(const fsa_family & val) { fam = val; };
void set_nature(const fsa_nature & val) { nat = val; };
virtual bool equal_value_to(const filesystem_specific_attribute & ref) const = 0;
private:
fsa_family fam;
fsa_nature nat;
};
class filesystem_specific_attribute_list
{
public:
filesystem_specific_attribute_list() {};
filesystem_specific_attribute_list(const filesystem_specific_attribute_list & ref) { copy_from(ref); };
filesystem_specific_attribute_list & operator = (const filesystem_specific_attribute_list & ref) { clear(); copy_from(ref); return *this; };
~filesystem_specific_attribute_list() { clear(); };
void clear();
void add(const filesystem_specific_attribute & fsa);
fsa_scope get_fsa_families() const { return familes; };
bool is_included_in(const filesystem_specific_attribute_list & ref, const fsa_scope & scope) const;
void read(generic_file & f, archive_version ver);
void write(generic_file & f) const;
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);
bool has_linux_immutable_set() const;
bool set_fsa_to_filesystem_for(const std::string & target,
const fsa_scope & scope,
user_interaction & ui,
bool set_linux_immutable) const;
bool empty() const { return fsa.empty(); };
U_I size() const { return fsa.size(); };
const filesystem_specific_attribute & operator [] (U_I arg) const;
infinint storage_size() const;
filesystem_specific_attribute_list operator + (const filesystem_specific_attribute_list & arg) const;
bool find(fsa_family fam, fsa_nature nat, const filesystem_specific_attribute *&ptr) const;
private:
std::deque<filesystem_specific_attribute *> fsa; //< sorted list of FSA
fsa_scope familes;
void copy_from(const filesystem_specific_attribute_list & ref);
void update_familes();
void priv_add(const filesystem_specific_attribute & ref); // add an entry without updating the "familes" field
void sort_fsa();
void fill_extX_FSA_with(const std::string & target, mode_t itype);
void fill_HFS_FSA_with(user_interaction & ui,
const std::string & target,
mode_t itype,
bool auto_zeroing_neg_dates);
bool set_extX_FSA_to(user_interaction & ui,
const std::string & target,
bool set_immutable) const;
bool set_hfs_FSA_to(user_interaction & ui, const std::string & target) const;
static std::string family_to_signature(fsa_family f);
static std::string nature_to_signature(fsa_nature n);
static fsa_family signature_to_family(const std::string & sig);
static fsa_nature signature_to_nature(const std::string & sig);
};
template <class T> T *cloner(const T *x)
{
if(x == nullptr)
throw SRC_BUG;
T *ret = new (std::nothrow) T(*x);
if(ret == nullptr)
throw Ememory("cloner template");
return ret;
}
class fsa_bool : public filesystem_specific_attribute
{
public:
fsa_bool(fsa_family f, fsa_nature n, bool xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
fsa_bool(generic_file & f, fsa_family fam, fsa_nature nat);
fsa_bool(const fsa_bool & ref) = default;
fsa_bool & operator = (const fsa_bool & ref) = default;
~fsa_bool() = default;
bool get_value() const { return val; };
virtual std::string show_val() const { return val ? gettext("true") : gettext("false"); };
virtual void write(generic_file & f) const { f.write(val ? "T" : "F", 1); };
virtual infinint storage_size() const { return 1; };
virtual filesystem_specific_attribute *clone() const { return cloner(this); };
protected:
virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
private:
bool val;
};
class fsa_infinint : public filesystem_specific_attribute
{
public:
fsa_infinint(fsa_family f, fsa_nature n, infinint xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
fsa_infinint(generic_file & f, fsa_family fam, fsa_nature nat);
fsa_infinint(const fsa_infinint & ref) = default;
fsa_infinint & operator = (const fsa_infinint & ref) = default;
~fsa_infinint() = default;
const infinint & get_value() const { return val; };
virtual std::string show_val() const;
virtual void write(generic_file & f) const { val.dump(f); };
virtual infinint storage_size() const { return val.get_storage_size(); };
virtual filesystem_specific_attribute *clone() const { return cloner(this); };
protected:
virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
private:
infinint val;
};
class fsa_time : public filesystem_specific_attribute
{
public:
fsa_time(fsa_family f, fsa_nature n, datetime xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); };
fsa_time(generic_file & f, archive_version ver, fsa_family fam, fsa_nature nat);
fsa_time(const fsa_time & ref) = default;
fsa_time & operator = (const fsa_time & ref) = default;
~fsa_time() = default;
const datetime & get_value() const { return val; };
virtual std::string show_val() const;
virtual void write(generic_file & f) const { val.dump(f); };
virtual infinint storage_size() const { return val.get_storage_size(); };
virtual filesystem_specific_attribute *clone() const { return cloner(this); };
protected:
virtual bool equal_value_to(const filesystem_specific_attribute & ref) const;
private:
datetime val;
};
} // end of namespace
#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::datetime::dump
void dump(generic_file &x) const
write down this to file
libdar::datetime::get_storage_size
infinint get_storage_size() const
return the storage it would require to dump this object
libdar::filesystem_specific_attribute_list
interface to fileystem for FSA
Definition filesystem_specific_attribute.hpp:138
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::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
fsa based on integer
Definition filesystem_specific_attribute.hpp:290
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
fsa based on time
Definition filesystem_specific_attribute.hpp:318
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:47
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