Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
.pc/delete2/filesystem.hpp
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 : dar.linux@free.fr
00020 /*********************************************************************/
00021 // $Id$
00022 //
00023 /*********************************************************************/
00024 
00025 #ifndef FILESYSTEM_HPP
00026 #define FILESYSTEM_HPP
00027 
00028 #include <map>
00029 #include <unistd.h>
00030 #include <sys/stat.h>
00031 #include <vector>
00032 #include "catalogue.hpp"
00033 #include "infinint.hpp"
00034 #include "etage.hpp"
00035 
00036 
00037 class filesystem_hard_link_read
00038 {               
00039 
00040         // this class is not to be used directly
00041         // it only provides some routine for the inherited classes
00042 
00043 public:
00044     void forget_etiquette(file_etiquette *obj);
00045         // tell the filesystem module that the reference of that etiquette does not
00046         // exist anymore (not covered by filter for example)
00047     
00048 protected:
00049     void corres_reset() { corres_read.clear(); };
00050 
00051     nomme *make_read_entree(path & lieu, const string & name, bool see_hard_link, bool ea_root_mode, bool ea_user_mode);
00052     
00053 private:
00054     struct couple
00055     {
00056         nlink_t count;
00057         file_etiquette *obj;
00058     };          
00059     map <ino_t, couple> corres_read;
00060 };
00061 
00062 
00063 class filesystem_backup : public filesystem_hard_link_read
00064 {
00065 public:
00066     filesystem_backup(const path &root, bool x_info_details, bool root_ea, bool user_ea, bool check_no_dump_flag);
00067     filesystem_backup(const filesystem_backup & ref) { copy_from(ref); };
00068     filesystem_backup & operator = (const filesystem_backup & ref) { detruire(); copy_from(ref); return *this; };
00069     ~filesystem_backup() { detruire(); };
00070 
00071     void reset_read();
00072     bool read(entree * & ref);
00073     void skip_read_to_parent_dir();
00074         //  continue reading in parent directory and
00075         // ignore all entry not yet read of current directory
00076 private:
00077 
00078     struct filename_struct
00079     {
00080         infinint last_acc;
00081         infinint last_mod;
00082     };
00083 
00084     path *fs_root;
00085     bool info_details;
00086     bool ea_root;
00087     bool ea_user;
00088     bool no_dump_check;
00089     path *current_dir;  // to translate from an hard linked inode to an  already allocated object 
00090     vector<filename_struct> filename_pile; // to be able to restore last access of directory we open for reading
00091     vector<etage> pile;         // to store the contents of a directory
00092 
00093     void detruire();
00094     void copy_from(const filesystem_backup & ref);
00095 };
00096 
00097 class filesystem_diff : public filesystem_hard_link_read
00098 {
00099 public:
00100     filesystem_diff(const path &root, bool x_info_details, bool root_ea, bool user_ea);
00101     filesystem_diff(const filesystem_diff & ref) { copy_from(ref); };
00102     filesystem_diff & operator = (const filesystem_diff & ref) { detruire(); copy_from(ref); return *this; };
00103     ~filesystem_diff() { detruire(); };
00104         
00105     void reset_read();
00106     bool read_filename(const string & name, nomme * &ref);
00107         // looks for a file of name given in argument, in current reading directory
00108         // if this is a directory subsequent read are done in it
00109     void skip_read_filename_in_parent_dir();
00110         // subsequent calls to read_filename will take place in parent directory.
00111 
00112 private:
00113     struct filename_struct
00114     {
00115         infinint last_acc;
00116         infinint last_mod;
00117     };
00118 
00119     path *fs_root;
00120     bool info_details;
00121     bool ea_root;
00122     bool ea_user;
00123     path *current_dir;
00124     vector<filename_struct> filename_pile;
00125 
00126     void detruire();
00127     void copy_from(const filesystem_diff & ref);
00128 };
00129 
00130 class filesystem_hard_link_write
00131 {
00132 
00133         // this class is not to be used directly
00134         // it only provides routines to its inherited classes
00135         // this not public part is present.
00136 
00137 public:
00138     bool ea_has_been_restored(const hard_link *h);
00139         // true if the inode pointed to by the arg has already got its EA restored
00140     bool set_ea(const nomme *e, const ea_attributs & l, path spot, 
00141                 bool allow_overwrite, bool warn_overwrite, bool info_details);
00142         // check the inode for which to restore EA, is not a hard link to
00143         // an already restored inode, else call the proper ea_filesystem call
00144     void write_hard_linked_target_if_not_set(const etiquette *ref, const string & chemin);
00145         // if a hard linked inode has not been restored (no change, or less recent than the one on filesystem)
00146         // it is necessary to inform filesystem, where to hard link on, any future hard_link 
00147         // that could be necessary to restore.
00148     bool known_etiquette(const infinint & eti);
00149         // return true if an inode in filesystem has been seen for that hard linked inode
00150 
00151 protected:
00152     void corres_reset() { corres_write.clear(); };
00153     void make_file(const nomme * ref, const path & ou, bool dir_perm, bool ignore_owner);
00154         // generate inode or make a hard link on an already restored inode.
00155     void clear_corres(const infinint & ligne);
00156 
00157 
00158 private:
00159     struct corres_ino_ea
00160     {
00161         string chemin;
00162         bool ea_restored;
00163     };
00164 
00165     map <infinint, corres_ino_ea> corres_write;
00166 };              
00167 
00168 
00169 class filesystem_restore : public filesystem_hard_link_write, public filesystem_hard_link_read
00170 {
00171 public:
00172     filesystem_restore(const path &root, bool x_allow_overwrite, bool x_warn_overwrite, bool x_info_details,
00173                        bool root_ea, bool user_ea, bool ignore_owner);
00174     filesystem_restore(const filesystem_restore  & ref) { copy_from(ref); };
00175     filesystem_restore & operator =(const filesystem_restore  & ref) { detruire(); copy_from(ref); return *this; };
00176     ~filesystem_restore() { detruire(); };
00177         
00178     void reset_write();
00179     bool write(const entree *x);
00180         // the argument may be an object from class destroy
00181         // return true upon success, 
00182         // false if overwriting not allowed or refused 
00183         // throw exception on other errors
00184     nomme *get_before_write(const nomme *x);
00185         // in this case the target has to be removed from the filesystem
00186     void pseudo_write(const directory *dir);    
00187         // do not restore the directory, just stores that we are now 
00188         // inspecting its contents
00189     bool set_ea(const nomme *e, const ea_attributs & l, 
00190                 bool allow_overwrite, 
00191                 bool warn_overwrite, 
00192                 bool info_details)
00193         {  return filesystem_hard_link_write::set_ea(e, l, *current_dir, 
00194                                                      allow_overwrite, 
00195                                                      warn_overwrite, 
00196                                                      info_details); 
00197         };
00198 
00199 
00200         
00201 private:
00202     path *fs_root;
00203     bool info_details;
00204     bool ea_root;
00205     bool ea_user;
00206     bool allow_overwrite;
00207     bool warn_overwrite;
00208     bool ignore_ownership;
00209     vector<directory> stack_dir;
00210     path *current_dir;
00211 
00212     void detruire();
00213     void copy_from(const filesystem_restore & ref);
00214 
00215 };
00216 
00217 
00218 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines