00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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 }
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
00066
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
00077
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
00122
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;
00132 std::vector<etage> pile;
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
00152
00153 void skip_read_filename_in_parent_dir();
00154
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
00178
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
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
00191
00192 void write_hard_linked_target_if_not_set(const etiquette *ref, const std::string & chemin);
00193
00194
00195
00196 bool known_etiquette(const infinint & eti);
00197
00198
00199
00200 bool get_ea_erase() const { return ea_erase; };
00201
00202 protected:
00203 void corres_reset() { corres_write.clear(); };
00204 void make_file(const nomme * ref, const path & ou, bool dir_perm, inode::comparison_fields what_to_check);
00205
00206 void clear_corres(const infinint & ligne);
00207
00208 user_interaction & get_fs_ui() const { return *fs_ui; };
00209
00210 private:
00211 struct corres_ino_ea
00212 {
00213 std::string chemin;
00214 bool ea_restored;
00215 };
00216
00217 std::map <infinint, corres_ino_ea> corres_write;
00218 user_interaction *fs_ui;
00219 bool ea_erase;
00220
00221 void copy_from(const filesystem_hard_link_write & ref);
00222 void detruire();
00223 };
00224
00226 class filesystem_restore : public filesystem_hard_link_write, public filesystem_hard_link_read
00227 {
00228 public:
00229 filesystem_restore(user_interaction & dialog,
00230 const path &root, bool x_allow_overwrite, bool x_warn_overwrite, bool x_info_details,
00231 const mask & x_ea_mask, inode::comparison_fields what_to_check, bool x_warn_remove_no_match, bool empty, bool ea_erase);
00232 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); };
00233 filesystem_restore & operator = (const filesystem_restore & ref) { detruire(); copy_from(ref); return *this; };
00234 ~filesystem_restore() { restore_stack_dir_ownership(); detruire(); };
00235
00236 void reset_write();
00237 bool write(const entree *x);
00238
00239
00240
00241
00242 nomme *get_before_write(const nomme *x);
00243
00244 void pseudo_write(const directory *dir);
00245
00246
00247 bool set_ea(const nomme *e, const ea_attributs & l,
00248 bool allow_overwrite,
00249 bool warn_overwrite,
00250 bool info_details)
00251 { return empty ? true : filesystem_hard_link_write::set_ea(e, l, *current_dir,
00252 allow_overwrite,
00253 warn_overwrite,
00254 *ea_mask,
00255 info_details);
00256 };
00257
00258 protected:
00259 user_interaction & get_fs_ui() const { return filesystem_hard_link_read::get_fs_ui(); };
00260
00261 private:
00262 path *fs_root;
00263 bool info_details;
00264 mask *ea_mask;
00265 bool allow_overwrite;
00266 bool warn_overwrite;
00267 inode::comparison_fields what_to_check;
00268 bool warn_remove_no_match;
00269 std::vector<directory> stack_dir;
00270 path *current_dir;
00271 bool empty;
00272
00273 void detruire();
00274 void copy_from(const filesystem_restore & ref);
00275 void restore_stack_dir_ownership();
00276 };
00277
00279
00280 }
00281
00282 #endif