![]() |
Disk ARchive
2.5.2
Full featured and portable backup and archiving tool
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 00025 00026 #ifndef FILESYSTEM_SPECIFIC_ATTRIBUTE_HPP 00027 #define FILESYSTEM_SPECIFIC_ATTRIBUTE_HPP 00028 00029 #include "../my_config.h" 00030 00031 extern "C" 00032 { 00033 #if HAVE_SYS_TYPES_H 00034 #include <sys/types.h> 00035 #endif 00036 #if HAVE_SYS_STAT_H 00037 #include <sys/stat.h> 00038 #endif 00039 #if HAVE_UNISTD_H 00040 #include <unistd.h> 00041 #endif 00042 00043 } // end extern "C" 00044 00045 #include <string> 00046 #include <vector> 00047 00048 #include "integers.hpp" 00049 #include "crc.hpp" 00050 #include "fsa_family.hpp" 00051 #include "on_pool.hpp" 00052 00053 namespace libdar 00054 { 00057 00058 00066 00067 class filesystem_specific_attribute : public on_pool 00068 { 00069 public: 00070 00072 00076 filesystem_specific_attribute(fsa_family f) { fam = f; nat = fsan_unset; }; 00077 00079 filesystem_specific_attribute(generic_file & f, fsa_family xfam, fsa_nature xnat) { fam = xfam; nat = xnat; }; 00080 00082 virtual ~filesystem_specific_attribute() throw(Ebug) {}; 00083 00085 bool is_same_type_as(const filesystem_specific_attribute & ref) const; 00086 00088 virtual bool operator == (const filesystem_specific_attribute & ref) const { return is_same_type_as(ref) && equal_value_to(ref); }; 00089 bool operator != (const filesystem_specific_attribute & ref) const { return ! (*this == ref); }; 00090 00092 bool operator < (const filesystem_specific_attribute & ref) const; 00093 bool operator >= (const filesystem_specific_attribute & ref) const { return !(*this < ref); }; 00094 bool operator > (const filesystem_specific_attribute & ref) const { return ref < *this; }; 00095 bool operator <= (const filesystem_specific_attribute & ref) const { return !(*this > ref); }; 00096 00097 00099 fsa_family get_family() const { return fam; }; 00100 00102 fsa_nature get_nature() const { return nat; }; 00103 00105 virtual std::string show_val() const = 0; 00106 00108 virtual void write(generic_file & f) const = 0; 00109 00111 virtual infinint storage_size() const = 0; 00112 00114 virtual filesystem_specific_attribute *clone() const = 0; 00115 00116 protected: 00117 void set_family(const fsa_family & val) { fam = val; }; 00118 void set_nature(const fsa_nature & val) { nat = val; }; 00119 00121 virtual bool equal_value_to(const filesystem_specific_attribute & ref) const = 0; 00122 00123 private: 00124 fsa_family fam; 00125 fsa_nature nat; 00126 }; 00127 00129 00130 class filesystem_specific_attribute_list : public on_pool 00131 { 00132 public: 00133 filesystem_specific_attribute_list() {}; 00134 filesystem_specific_attribute_list(const filesystem_specific_attribute_list & ref) { copy_from(ref); }; 00135 const filesystem_specific_attribute_list & operator = (const filesystem_specific_attribute_list & ref) { clear(); copy_from(ref); return *this; }; 00136 ~filesystem_specific_attribute_list() { clear(); }; 00137 00139 void clear(); 00140 00142 fsa_scope get_fsa_families() const { return familes; }; 00143 00145 bool is_included_in(const filesystem_specific_attribute_list & ref, const fsa_scope & scope) const; 00146 00148 void read(generic_file & f, archive_version ver); 00149 00151 void write(generic_file & f) const; 00152 00154 void get_fsa_from_filesystem_for(const std::string & target, 00155 const fsa_scope & scope, 00156 mode_t itype); 00157 00164 bool set_fsa_to_filesystem_for(const std::string & target, 00165 const fsa_scope & scope, 00166 user_interaction & ui) const; 00167 00169 bool empty() const { return fsa.empty(); }; 00170 00171 00173 U_I size() const { return fsa.size(); }; 00174 00175 00177 const filesystem_specific_attribute & operator [] (U_I arg) const; 00178 00180 infinint storage_size() const; 00181 00186 filesystem_specific_attribute_list operator + (const filesystem_specific_attribute_list & arg) const; 00187 00193 bool find(fsa_family fam, fsa_nature nat, const filesystem_specific_attribute *&ptr) const; 00194 00195 private: 00196 std::vector<filesystem_specific_attribute *> fsa; //< sorted list of FSA 00197 fsa_scope familes; 00198 00199 void copy_from(const filesystem_specific_attribute_list & ref); 00200 void update_familes(); 00201 void add(const filesystem_specific_attribute & ref); // add an entry without updating the "familes" field 00202 void sort_fsa(); 00203 00204 void fill_extX_FSA_with(const std::string & target, mode_t itype); 00205 void fill_HFS_FSA_with(const std::string & target, mode_t itype); 00206 00208 bool set_extX_FSA_to(user_interaction & ui, const std::string & target) const; 00209 00211 bool set_hfs_FSA_to(user_interaction & ui, const std::string & target) const; 00212 00213 static std::string family_to_signature(fsa_family f); 00214 static std::string nature_to_signature(fsa_nature n); 00215 static fsa_family signature_to_family(const std::string & sig); 00216 static fsa_nature signature_to_nature(const std::string & sig); 00217 }; 00218 00220 00221 template <class T> T *cloner(const T *x, memory_pool *p) 00222 { 00223 if(x == nullptr) 00224 throw SRC_BUG; 00225 T *ret = new (p) T(*x); 00226 if(ret == nullptr) 00227 throw Ememory("cloner template"); 00228 00229 return ret; 00230 } 00231 00233 00234 class fsa_bool : public filesystem_specific_attribute 00235 { 00236 public: 00237 fsa_bool(fsa_family f, fsa_nature n, bool xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); }; 00238 fsa_bool(generic_file & f, fsa_family fam, fsa_nature nat); 00239 00240 bool get_value() const { return val; }; 00241 00243 virtual std::string show_val() const { return val ? gettext("true") : gettext("false"); }; 00244 virtual void write(generic_file & f) const { f.write(val ? "T" : "F", 1); }; 00245 virtual infinint storage_size() const { return 1; }; 00246 virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); }; 00247 00248 protected: 00249 virtual bool equal_value_to(const filesystem_specific_attribute & ref) const; 00250 00251 private: 00252 bool val; 00253 }; 00254 00256 00257 class fsa_infinint : public filesystem_specific_attribute 00258 { 00259 public: 00260 fsa_infinint(fsa_family f, fsa_nature n, infinint xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); }; 00261 fsa_infinint(generic_file & f, fsa_family fam, fsa_nature nat); 00262 00263 const infinint & get_value() const { return val; }; 00264 00266 virtual std::string show_val() const; 00267 virtual void write(generic_file & f) const { val.dump(f); }; 00268 virtual infinint storage_size() const { return val.get_storage_size(); }; 00269 virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); }; 00270 00271 protected: 00272 virtual bool equal_value_to(const filesystem_specific_attribute & ref) const; 00273 00274 private: 00275 infinint val; 00276 }; 00277 00279 00280 class fsa_time : public filesystem_specific_attribute 00281 { 00282 public: 00283 fsa_time(fsa_family f, fsa_nature n, datetime xval) : filesystem_specific_attribute(f), val(xval) { set_nature(n); }; 00284 fsa_time(generic_file & f, archive_version ver, fsa_family fam, fsa_nature nat); 00285 00286 const datetime & get_value() const { return val; }; 00287 00289 virtual std::string show_val() const; 00290 virtual void write(generic_file & f) const { val.dump(f); }; 00291 virtual infinint storage_size() const { return val.get_storage_size(); }; 00292 virtual filesystem_specific_attribute *clone() const { return cloner(this, get_pool()); }; 00293 00294 protected: 00295 virtual bool equal_value_to(const filesystem_specific_attribute & ref) const; 00296 00297 private: 00298 datetime val; 00299 }; 00300 00302 00303 } // end of namespace 00304 00305 #endif