filesystem.hpp

Go to the documentation of this file.
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: filesystem.hpp,v 1.22.2.1 2006/06/20 20:28:50 edrusb Rel $
00022 //
00023 /*********************************************************************/
00024 
00034 
00035 #ifndef FILESYSTEM_HPP
00036 #define FILESYSTEM_HPP
00037 
00038 #include "../my_config.h"
00039 
00040 extern "C"
00041 {
00042 #if HAVE_UNISTD_H
00043 #include <unistd.h>
00044 #endif
00045 
00046 #if HAVE_SYS_STAT_H
00047 #include <sys/stat.h>
00048 #endif
00049 } // end extern "C"
00050 
00051 #include <map>
00052 #include <vector>
00053 #include "catalogue.hpp"
00054 #include "infinint.hpp"
00055 #include "etage.hpp"
00056 
00057 namespace libdar
00058 {
00061 
00063     class filesystem_hard_link_read
00064     {
00065             // this class is not to be used directly
00066             // it only provides some routine for the inherited classes
00067 
00068     public:
00069         filesystem_hard_link_read(user_interaction & dialog) { fs_ui = dialog.clone(); };
00070         filesystem_hard_link_read(const filesystem_hard_link_read & ref) { copy_from(ref); };
00071         filesystem_hard_link_read & operator = (const filesystem_hard_link_read & ref) { detruire(); copy_from(ref); return *this; };
00072         ~filesystem_hard_link_read() { detruire(); };
00073 
00074 
00075         void forget_etiquette(file_etiquette *obj);
00076             // tell the filesystem module that the reference of that etiquette does not
00077             // exist anymore (not covered by filter for example)
00078 
00079     protected:
00080         void corres_reset() { corres_read.clear(); etiquette_counter = 0; };
00081 
00082         nomme *make_read_entree(path & lieu, const std::string & name, bool see_hard_link, const mask & ea_mask);
00083 
00084         user_interaction & get_fs_ui() const { return *fs_ui; };
00085 
00086     private:
00087         struct couple
00088         {
00089             nlink_t count;
00090             file_etiquette *obj;
00091         };
00092         std::map <ino_t, couple> corres_read;
00093         infinint etiquette_counter;
00094 
00095         user_interaction *fs_ui;
00096 
00097         void copy_from(const filesystem_hard_link_read & ref);
00098         void detruire();
00099     };
00100 
00101 
00103     class filesystem_backup : public filesystem_hard_link_read
00104     {
00105     public:
00106         filesystem_backup(user_interaction & dialog,
00107                           const path &root,
00108                           bool x_info_details,
00109                           const mask & x_ea_mask,
00110                           bool check_no_dump_flag,
00111                           bool alter_atime,
00112                           bool x_cache_directory_tagging,
00113                           infinint & root_fs_device);
00114         filesystem_backup(const filesystem_backup & ref) : filesystem_hard_link_read(ref.get_fs_ui()) { copy_from(ref); };
00115         filesystem_backup & operator = (const filesystem_backup & ref) { detruire(); copy_from(ref); return *this; };
00116         ~filesystem_backup() { detruire(); };
00117 
00118         void reset_read(infinint & root_fs_device);
00119         bool read(entree * & ref, infinint & errors, infinint & skipped_dump);
00120         void skip_read_to_parent_dir();
00121             //  continue reading in parent directory and
00122             // ignore all entry not yet read of current directory
00123     private:
00124 
00125         path *fs_root;
00126         bool info_details;
00127         mask *ea_mask;
00128         bool no_dump_check;
00129         bool alter_atime;
00130         bool cache_directory_tagging;
00131         path *current_dir;      // to translate from an hard linked inode to an  already allocated object
00132         std::vector<etage> pile;        // to store the contents of a directory
00133 
00134         void detruire();
00135         void copy_from(const filesystem_backup & ref);
00136     };
00137 
00139     class filesystem_diff : public filesystem_hard_link_read
00140     {
00141     public:
00142         filesystem_diff(user_interaction & dialog,
00143                         const path &root, bool x_info_details,
00144                         const mask & x_ea_mask, bool alter_atime);
00145         filesystem_diff(const filesystem_diff & ref) : filesystem_hard_link_read(ref.get_fs_ui()) { copy_from(ref); };
00146         filesystem_diff & operator = (const filesystem_diff & ref) { detruire(); copy_from(ref); return *this; };
00147         ~filesystem_diff() { detruire(); };
00148 
00149         void reset_read();
00150         bool read_filename(const std::string & name, nomme * &ref);
00151             // looks for a file of name given in argument, in current reading directory
00152             // if this is a directory subsequent read are done in it
00153         void skip_read_filename_in_parent_dir();
00154             // subsequent calls to read_filename will take place in parent directory.
00155 
00156     private:
00157         struct filename_struct
00158         {
00159             infinint last_acc;
00160             infinint last_mod;
00161         };
00162 
00163         path *fs_root;
00164         bool info_details;
00165         mask *ea_mask;
00166         bool alter_atime;
00167         path *current_dir;
00168         std::vector<filename_struct> filename_pile;
00169 
00170         void detruire();
00171         void copy_from(const filesystem_diff & ref);
00172     };
00173 
00175     class filesystem_hard_link_write
00176     {
00177             // this class is not to be used directly
00178             // it only provides routines to its inherited classes
00179 
00180     public:
00181         filesystem_hard_link_write(user_interaction & dialog, bool x_ea_erase) { fs_ui = dialog.clone(); ea_erase = x_ea_erase; };
00182         filesystem_hard_link_write(const filesystem_hard_link_write & ref) { copy_from(ref); };
00183         filesystem_hard_link_write & operator = (const filesystem_hard_link_write & ref) { detruire(); copy_from(ref); return *this; };
00184         ~filesystem_hard_link_write() { detruire(); };
00185 
00186         bool ea_has_been_restored(const hard_link *h);
00187             // true if the inode pointed to by the arg has already got its EA restored
00188         bool set_ea(const nomme *e, const ea_attributs & list_ea, path spot,
00189                     bool allow_overwrite, bool warn_overwrite, const mask & ea_mask, bool info_details);
00190             // check whether the inode for which to restore EA is not a hard link to
00191             // an already restored inode. if not, it calls the proper ea_filesystem call to restore EA
00192         void write_hard_linked_target_if_not_set(const etiquette *ref, const std::string & chemin);
00193             // if a hard linked inode has not been restored (no change, or less recent than the one on filesystem)
00194             // it is necessary to inform filesystem, where to hard link on, any future hard_link
00195             // that could be necessary to restore.
00196         bool known_etiquette(const infinint & eti);
00197             // return true if an inode in filesystem has been seen for that hard linked inode
00198 
00199             // return the ea_ease status (whether EA are first erased before being restored, else they are overwritten)
00200         bool get_ea_erase() const { return ea_erase; };
00201             // set the ea_erase status
00202         void set_ea_erase(bool status) { ea_erase = status; };
00203 
00204     protected:
00205         void corres_reset() { corres_write.clear(); };
00206         void make_file(const nomme * ref, const path & ou, bool dir_perm, inode::comparison_fields what_to_check);
00207             // generate inode or make a hard link on an already restored inode.
00208         void clear_corres(const infinint & ligne);
00209 
00210         user_interaction & get_fs_ui() const { return *fs_ui; };
00211 
00212     private:
00213         struct corres_ino_ea
00214         {
00215             std::string chemin;
00216             bool ea_restored;
00217         };
00218 
00219         std::map <infinint, corres_ino_ea> corres_write;
00220         user_interaction *fs_ui;
00221         bool ea_erase;
00222 
00223         void copy_from(const filesystem_hard_link_write & ref);
00224         void detruire();
00225     };
00226 
00228     class filesystem_restore : public filesystem_hard_link_write, public filesystem_hard_link_read
00229     {
00230     public:
00231         filesystem_restore(user_interaction & dialog,
00232                            const path &root, bool x_allow_overwrite, bool x_warn_overwrite, bool x_info_details,
00233                            const mask & x_ea_mask, inode::comparison_fields what_to_check, bool x_warn_remove_no_match, bool empty, bool ea_erase);
00234         filesystem_restore(const filesystem_restore  & ref) : filesystem_hard_link_write(ref.filesystem_hard_link_write::get_fs_ui(), ref.get_ea_erase()), filesystem_hard_link_read(ref.filesystem_hard_link_read::get_fs_ui()) { copy_from(ref); };
00235         filesystem_restore & operator = (const filesystem_restore  & ref) { detruire(); copy_from(ref); return *this; };
00236         ~filesystem_restore() { restore_stack_dir_ownership(); detruire(); };
00237 
00238         void reset_write();
00239         bool write(const entree *x, bool & created);
00240             // the 'x' argument may be an object from class destroy
00241             // the 'created' argument is set back to true if no overwriting was necessary to restore the file
00242             // return true upon success,
00243             // false if overwriting not allowed or refused
00244             // throw exception on other errors
00245         nomme *get_before_write(const nomme *x);
00246             // in this case the target has to be removed from the filesystem
00247         void pseudo_write(const directory *dir);
00248             // do not restore the directory, just stores that we are now
00249             // inspecting its contents
00250         bool set_ea(const nomme *e, const ea_attributs & l,
00251                     bool allow_overwrite,
00252                     bool warn_overwrite,
00253                     bool info_details)
00254             {  return empty ? true : filesystem_hard_link_write::set_ea(e, l, *current_dir,
00255                                                                         allow_overwrite,
00256                                                                         warn_overwrite,
00257                                                                         *ea_mask,
00258                                                                         info_details);
00259             };
00260 
00261     protected:
00262         user_interaction & get_fs_ui() const { return filesystem_hard_link_read::get_fs_ui(); };
00263 
00264     private:
00265         path *fs_root;
00266         bool info_details;
00267         mask *ea_mask;
00268         bool allow_overwrite;
00269         bool warn_overwrite;
00270         inode::comparison_fields what_to_check;
00271         bool warn_remove_no_match;
00272         std::vector<directory> stack_dir;
00273         path *current_dir;
00274         bool empty;
00275 
00276         void detruire();
00277         void copy_from(const filesystem_restore & ref);
00278         void restore_stack_dir_ownership();
00279     };
00280 
00282 
00283 } // end of namespace
00284 
00285 #endif

Generated on Fri Dec 29 02:36:10 2006 for Disk ARchive by  doxygen 1.5.1