![]() |
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 CAT_INODE_HPP 00027 #define CAT_INODE_HPP 00028 00029 #include "../my_config.h" 00030 00031 extern "C" 00032 { 00033 } // end extern "C" 00034 00035 #include "infinint.hpp" 00036 #include "generic_file.hpp" 00037 #include "ea.hpp" 00038 #include "compressor.hpp" 00039 #include "integers.hpp" 00040 #include "mask.hpp" 00041 #include "user_interaction.hpp" 00042 #include "escape.hpp" 00043 #include "filesystem_specific_attribute.hpp" 00044 #include "datetime.hpp" 00045 #include "cat_nomme.hpp" 00046 00047 namespace libdar 00048 { 00051 00052 00054 class cat_inode : public cat_nomme 00055 { 00056 public: 00057 00059 00060 enum comparison_fields 00061 { 00062 cf_all, //< consider any available field for comparing inodes 00063 cf_ignore_owner, //< consider any available field except ownership fields 00064 cf_mtime, //< consider any available field except ownership and permission fields 00065 cf_inode_type //< only consider the file type 00066 }; 00067 00068 cat_inode(const infinint & xuid, 00069 const infinint & xgid, 00070 U_16 xperm, 00071 const datetime & last_access, 00072 const datetime & last_modif, 00073 const datetime & last_change, 00074 const std::string & xname, 00075 const infinint & device); 00076 cat_inode(user_interaction & dialog, 00077 const pile_descriptor & pdesc, 00078 const archive_version & reading_ver, 00079 saved_status saved, 00080 bool small); 00081 cat_inode(const cat_inode & ref); 00082 const cat_inode & operator = (const cat_inode & ref); 00083 ~cat_inode() throw(Ebug); 00084 00085 const infinint & get_uid() const { return uid; }; 00086 const infinint & get_gid() const { return gid; }; 00087 U_16 get_perm() const { return perm; }; 00088 datetime get_last_access() const { return last_acc; }; 00089 datetime get_last_modif() const { return last_mod; }; 00090 void set_last_access(const datetime & x_time) { last_acc = x_time; }; 00091 void set_last_modif(const datetime & x_time) { last_mod = x_time; }; 00092 saved_status get_saved_status() const { return xsaved; }; 00093 void set_saved_status(saved_status x) { xsaved = x; }; 00094 infinint get_device() const { if(fs_dev == nullptr) throw SRC_BUG; return *fs_dev; }; 00095 00096 bool same_as(const cat_inode & ref) const; 00097 bool is_more_recent_than(const cat_inode & ref, const infinint & hourshift) const; 00098 // used for RESTORATION 00099 virtual bool has_changed_since(const cat_inode & ref, const infinint & hourshift, comparison_fields what_to_check) const; 00100 // signature() left as an abstract method 00101 // clone is abstract too 00102 // used for INCREMENTAL BACKUP 00103 void compare(const cat_inode &other, 00104 const mask & ea_mask, 00105 comparison_fields what_to_check, 00106 const infinint & hourshift, 00107 bool symlink_date, 00108 const fsa_scope & scope, 00109 bool isolated_mode) const; //< do not try to compare pointed to data, EA of FSA (suitable for isolated catalogue) 00110 00111 // throw Erange exception if a difference has been detected 00112 // this is not a symetrical comparison, but all what is present 00113 // in the current object is compared against the argument 00114 // which may contain supplementary informations 00115 // used for DIFFERENCE 00116 00117 00118 00120 // EXTENDED ATTRIBUTES Methods 00121 // 00122 00123 enum ea_status { ea_none, ea_partial, ea_fake, ea_full, ea_removed }; 00124 // ea_none : no EA present for this inode in filesystem 00125 // ea_partial : EA present in filesystem but not stored (ctime used to check changes) 00126 // ea_fake : EA present in filesystem but not attached to this inode (isolation context) no more used in archive version "08" and above, ea_partial or ea_full stays a valid status in isolated catalogue because pointers to EA and data are no more removed during isolation process. 00127 // ea_full : EA present in filesystem and attached to this inode 00128 // ea_removed : EA were present in the reference version, but not present anymore 00129 00130 // I : to know whether EA data is present or not for this object 00131 void ea_set_saved_status(ea_status status); 00132 ea_status ea_get_saved_status() const { return ea_saved; }; 00133 00134 // II : to associate EA list to an cat_inode object (mainly for backup operation) #EA_FULL only# 00135 void ea_attach(ea_attributs *ref); 00136 const ea_attributs *get_ea() const; // #<-- EA_FULL *and* EA_REMOVED# for this call only 00137 void ea_detach() const; //discards any future call to get_ea() ! 00138 infinint ea_get_size() const; //returns the size of EA (still valid if ea have been detached) mainly used to define CRC width 00139 00140 // III : to record where is dump the EA in the archive #EA_FULL only# 00141 void ea_set_offset(const infinint & pos); 00142 bool ea_get_offset(infinint & pos) const; 00143 void ea_set_crc(const crc & val); 00144 void ea_get_crc(const crc * & ptr) const; //< the argument is set to point to an allocated crc object owned by this "cat_inode" object, this reference stays valid while the "cat_inode" object exists and MUST NOT be deleted by the caller in any case 00145 bool ea_get_crc_size(infinint & val) const; //< returns true if crc is know and puts its width in argument 00146 00147 // IV : to know/record if EA and FSA have been modified # any EA status# and FSA status # 00148 datetime get_last_change() const; 00149 void set_last_change(const datetime & x_time); 00150 bool has_last_change() const { return last_cha != nullptr; }; 00151 // old format did provide last_change only when EA were present, since archive 00152 // format 8, this field is always present even in absence of EA. Thus it is 00153 // still necessary to check if the cat_inode has a last_change() before 00154 // using get_last_change() (depends on the version of the archive read). 00155 00156 00158 // FILESYSTEM SPECIFIC ATTRIBUTES Methods 00159 // 00160 // there is not "remove status for FSA, either the cat_inode contains 00161 // full copy of FSA or only remembers the families of FSA found in the unchanged cat_inode 00162 // FSA none is used when the file has no FSA because: 00163 // - either the underlying filesystem has no known FSA 00164 // - or the underlying filesystem FSA support has not been activated at compilation time 00165 // - or the fsa_scope requested at execution time exclude the filesystem FSA families available here 00166 enum fsa_status { fsa_none, fsa_partial, fsa_full }; 00167 00168 // I : which FSA are present 00169 void fsa_set_saved_status(fsa_status status); 00170 fsa_status fsa_get_saved_status() const { return fsa_saved; }; 00172 fsa_scope fsa_get_families() const { if(fsa_families == nullptr) throw SRC_BUG; return infinint_to_fsa_scope(*fsa_families); }; 00173 00174 00175 00176 // II : add or drop FSA list to the cat_inode 00177 void fsa_attach(filesystem_specific_attribute_list *ref); 00178 const filesystem_specific_attribute_list *get_fsa() const; // #<-- FSA_FULL only 00179 void fsa_detach() const; // discard any future call to get_fsa() ! 00180 infinint fsa_get_size() const; // returns the size of FSA (still valid if fsal has been detached) / mainly used to define CRC size 00181 00182 // III : to record where FSA are dumped in the archive (only if fsa_status not empty !) 00183 void fsa_set_offset(const infinint & pos); 00184 bool fsa_get_offset(infinint & pos) const; 00185 void fsa_set_crc(const crc & val); 00186 void fsa_get_crc(const crc * & ptr) const; 00187 bool fsa_get_crc_size(infinint & val) const; 00188 00189 protected: 00190 virtual void sub_compare(const cat_inode & other, bool isolated_mode) const {}; 00191 bool get_small_read() const { return small_read; }; //< true if object has been created by sequential reading of an archive 00192 00193 // inherited from cat_entree 00194 void inherited_dump(const pile_descriptor & pdesc, bool small) const; 00195 00196 00197 private : 00198 infinint uid; //< inode owner's user ID 00199 infinint gid; //< inode owner's group ID 00200 U_16 perm; //< inode's permission 00201 datetime last_acc; //< last access time (atime) 00202 datetime last_mod; //< last modification time (mtime) 00203 datetime *last_cha; //< last inode meta data change (ctime) 00204 saved_status xsaved; //< inode data status 00205 ea_status ea_saved; //< inode Extended Attribute status 00206 fsa_status fsa_saved; //< inode Filesystem Specific Attribute status 00207 00208 bool small_read; //< whether we the object has been built with sequential-reading 00209 00210 // the following is used only if ea_saved == full 00211 infinint *ea_offset; //< offset in archive where to find EA 00212 ea_attributs *ea; //< Extended Attributes read or to be written down 00213 infinint *ea_size; //< storage size required by EA 00214 // the following is used if ea_saved == full or ea_saved == partial or 00215 crc *ea_crc; //< CRC computed on EA 00216 00217 infinint *fsa_families; //< list of FSA families present for that inode (set to nullptr in fsa_none mode) 00218 infinint *fsa_offset; //< offset in archive where to find FSA # always allocated (to be reviewed) 00219 filesystem_specific_attribute_list *fsal; //< Filesystem Specific Attributes read or to be written down # only allocated if fsa_saved if set to FULL 00220 infinint *fsa_size; //< storage size required for FSA 00221 crc *fsa_crc; //< CRC computed on FSA 00222 // 00223 infinint *fs_dev; //< filesystem ID on which resides the inode (only used when read from filesystem) 00224 archive_version edit; //< need to know EA and FSA format used in archive file 00225 00226 00227 void nullifyptr(); 00228 void destroy(); 00229 void copy_from(const cat_inode & ref); 00230 00231 static const ea_attributs empty_ea; 00232 }; 00233 00235 00236 } // end of namespace 00237 00238 #endif