| Disk ARchive 2.5.10 Full featured and portable backup and archiving tool

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

filesystem.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21
31
32 #ifndef FILESYSTEM_HPP
33 #define FILESYSTEM_HPP
34
35 #include "../my_config.h"
36
37 extern "C"
38 {
39 #if HAVE_UNISTD_H
40 #include <unistd.h>
41 #endif
42
43 #if HAVE_SYS_STAT_H
44 #include <sys/stat.h>
45 #endif
46 } // end extern "C"
47
48 #include <map>
49 #include <vector>
50 #include "catalogue.hpp"
51 #include "infinint.hpp"
52 #include "etage.hpp"
53 #include "criterium.hpp"
54 #include "fsa_family.hpp"
55 #include "on_pool.hpp"
56 #include "cat_all_entrees.hpp"
57
58 namespace libdar
59 {
62
64
65 class filesystem_hard_link_read : virtual protected mem_ui, virtual public on_pool
66 {
67 // this class is not to be used directly
68 // it only provides some routine for the inherited classes
69
70 public:
71 filesystem_hard_link_read(user_interaction & dialog,
72 bool x_furtive_read_mode,
73 const fsa_scope & scope) : mem_ui(&dialog) { furtive_read_mode = x_furtive_read_mode; sc = scope; };
74
75 // the copy of the current object would make copy of addresses in
76 // corres_read that could be released twice ... thus, copy constructor and
77 // assignement are forbidden for this class:
78
79 filesystem_hard_link_read(const filesystem_hard_link_read & ref) : mem_ui(ref) { throw SRC_BUG; };
80 const filesystem_hard_link_read & operator = (const filesystem_hard_link_read & ref) { throw SRC_BUG; };
81
82 // get the last assigned number for a hard linked inode
83 const infinint & get_last_etoile_ref() const { return etiquette_counter; };
84
85 virtual ~filesystem_hard_link_read() {};
86
88 const fsa_scope get_fsa_scope() const { return sc; };
89
90 protected:
91 // reset the whole list of hard linked inodes (hard linked inode stay alive but are no more referenced by the current object)
92 void corres_reset() { corres_read.clear(); etiquette_counter = 0; };
93
94 // create and return a libdar object corresponding to one pointed to by its path
95 // during this operation, hard linked inode are recorded in a list to be easily pointed
96 // to by a new reference to it.
97 cat_nomme *make_read_entree(path & lieu, //< path of the file to read
98 const std::string & name, //< name of the file to read
99 bool see_hard_link, //< whether we want to detect hard_link and eventually return a cat_mirage object (not necessary when diffing an archive with filesystem)
100 const mask & ea_mask); //< which EA to consider when creating the object
101
102 private:
103
104 // private datastructure
105
106 struct couple
107 {
108 nlink_t count; //< counts the number of hard link on that inode that have not yet been found in filesystem, once this count reaches zero, the "couple" structure can be dropped and the "holder" too (no more expected hard links to be found)
109 cat_etoile *obj; //< the address of the corresponding cat_etoile object for that inode
110 cat_mirage holder; //< it increments by one the obj internal counters, thus, while this object is alive, the obj will not be destroyed
111
112 couple(cat_etoile *ptr, nlink_t ino_count) : holder("FAKE", ptr) { count = ino_count; obj = ptr; };
113 };
114
115 struct node
116 {
117 node(ino_t num, dev_t dev) { numnode = num; device = dev; };
118
119 // this operator is required to use the type node in a std::map
120 bool operator < (const node & ref) const { return numnode < ref.numnode || (numnode == ref.numnode && device < ref.device); };
121 ino_t numnode;
122 dev_t device;
123 };
124
125 // private variable
126
127 std::map <node, couple> corres_read;
128 infinint etiquette_counter;
129 bool furtive_read_mode;
130 fsa_scope sc;
131
132 };
133
134
135
137
138 class filesystem_backup : public filesystem_hard_link_read
139 {
140 public:
141 filesystem_backup(user_interaction & dialog,
142 const path &root,
143 bool x_info_details,
144 const mask & x_ea_mask,
145 bool check_no_dump_flag,
146 bool alter_atime,
147 bool furtive_read_mode,
148 bool x_cache_directory_tagging,
149 infinint & root_fs_device,
150 bool x_ignore_unknown,
151 const fsa_scope & scope);
152 filesystem_backup(const filesystem_backup & ref) : mem_ui(ref), filesystem_hard_link_read(ref.get_ui(), ref.furtive_read_mode, get_fsa_scope()) { copy_from(ref); };
153 const filesystem_backup & operator = (const filesystem_backup & ref) { detruire(); copy_from(ref); return *this; };
154 ~filesystem_backup() { detruire(); };
155
156 void reset_read(infinint & root_fs_device);
157 bool read(cat_entree * & ref, infinint & errors, infinint & skipped_dump);
158 void skip_read_to_parent_dir();
159 // continue reading in parent directory and
160 // ignore all entry not yet read of current directory
161 private:
162
163 path *fs_root; //< filesystem's root to consider
164 bool info_details; //< detailed information returned to the user
165 mask *ea_mask; //< mask defining the EA to consider
166 bool no_dump_check; //< whether to check against the nodump flag presence
167 bool alter_atime; //< whether to set back atime or not
168 bool furtive_read_mode; //< whether to use furtive read mode (if true, alter_atime is ignored)
169 bool cache_directory_tagging; //< whether to consider cache directory taggin standard
170 path *current_dir; //< needed to translate from an hard linked inode to an already allocated object
171 std::vector<etage> pile; //< to store the contents of a directory
172 bool ignore_unknown; //< whether to ignore unknown inode types
173
174 void detruire();
175 void copy_from(const filesystem_backup & ref);
176 };
177
178
180
181 class filesystem_diff : public filesystem_hard_link_read
182 {
183 public:
184 filesystem_diff(user_interaction & dialog,
185 const path &root,
186 bool x_info_details,
187 const mask & x_ea_mask,
188 bool alter_atime,
189 bool furtive_read_mode,
190 const fsa_scope & scope);
191 filesystem_diff(const filesystem_diff & ref) : mem_ui(ref), filesystem_hard_link_read(ref.get_ui(), ref.furtive_read_mode, get_fsa_scope()) { copy_from(ref); };
192 const filesystem_diff & operator = (const filesystem_diff & ref) { detruire(); copy_from(ref); return *this; };
193 ~filesystem_diff() { detruire(); };
194
195 void reset_read();
196 bool read_filename(const std::string & name, cat_nomme * &ref);
197 // looks for a file of name given in argument, in current reading directory
198 // if this is a directory, subsequent read take place in it
199
200 void skip_read_filename_in_parent_dir();
201 // subsequent calls to read_filename will take place in parent directory.
202
203 private:
204 struct filename_struct
205 {
206 datetime last_acc;
207 datetime last_mod;
208 };
209
210 path *fs_root;
211 bool info_details;
212 mask *ea_mask;
213 bool alter_atime;
214 bool furtive_read_mode;
215 path *current_dir;
216 std::vector<filename_struct> filename_pile;
217
218 void detruire();
219 void copy_from(const filesystem_diff & ref);
220 };
221
223
224 class filesystem_hard_link_write : virtual protected mem_ui, virtual public on_pool
225 {
226 // this class is not to be used directly
227 // it only provides routines to its inherited classes
228
229 public:
230 filesystem_hard_link_write(user_interaction & dialog) : mem_ui(& dialog) { corres_write.clear(); };
231 filesystem_hard_link_write(const filesystem_hard_link_write & ref) : mem_ui(ref) { throw SRC_BUG; };
232 const filesystem_hard_link_write & operator = (const filesystem_hard_link_write & ref) { throw SRC_BUG; };
233
234 void write_hard_linked_target_if_not_set(const cat_mirage *ref, const std::string & chemin);
235 // if a hard linked inode has not been restored (no change, or less recent than the one on filesystem)
236 // it is necessary to inform filesystem, where to hard link on, any future hard_link
237 // that could be necessary to restore.
238
239 bool known_etiquette(const infinint & eti);
240 // return true if an inode in filesystem has been seen for that hard linked inode
241
245 void clear_corres_if_pointing_to(const infinint & ligne, const std::string & path);
246
247 protected:
248 void corres_reset() { corres_write.clear(); };
249 void make_file(const cat_nomme * ref, //< object to restore in filesystem
250 const path & ou, //< where to restore it
251 bool dir_perm, //< false for already existing directories, this makes dar set the minimum available permission to be able to restore files in that directory at a later time
252 cat_inode::comparison_fields what_to_check, //< defines whether to restore permission, ownership, dates, etc.
253 const fsa_scope & scope); //< fsa scope to use for restoration
254 // generate inode or make a hard link on an already restored or existing inode.
255
256
258
266 bool raw_set_ea(const cat_nomme *e,
267 const ea_attributs & list_ea,
268 const std::string & spot,
269 const mask & ea_mask);
270 // check whether the inode for which to restore EA is not a hard link to
271 // an already restored inode. if not, it calls the proper ea_filesystem call to restore EA
272
274
278 bool raw_clear_ea_set(const cat_nomme *e, const std::string & path);
279
280
281 private:
282 struct corres_ino_ea
283 {
284 std::string chemin;
285 bool ea_restored;
286 };
287
288 std::map <infinint, corres_ino_ea> corres_write;
289 };
290
291
293
294 class filesystem_restore : public filesystem_hard_link_write, public filesystem_hard_link_read
295 {
296 public:
298 filesystem_restore(user_interaction & dialog,
299 const path & root,
300 bool x_warn_overwrite,
301 bool x_info_details,
302 const mask & x_ea_mask,
303 cat_inode::comparison_fields what_to_check,
304 bool x_warn_remove_no_match,
305 bool empty,
306 const crit_action *x_overwrite,
307 bool x_only_overwrite,
308 const fsa_scope & scope);
310 filesystem_restore(const filesystem_restore & ref) : mem_ui(ref), filesystem_hard_link_write(ref), filesystem_hard_link_read(get_ui(), true, get_fsa_scope()) { throw SRC_BUG; };
312 const filesystem_restore & operator = (const filesystem_restore & ref) { throw SRC_BUG; };
314 ~filesystem_restore() { restore_stack_dir_ownership(); detruire(); };
315
317 void reset_write();
318
319 typedef enum
320 {
321 done_data_restored, //< data has been restored to filesystem
322 done_no_change_no_data, //< no change in filesystem because no data present in archive
323 done_no_change_policy, //< no change in filesystem because of overwiting policy decision
324 done_data_removed //< data (= whole inode) removed from filesystem
325 } action_done_for_data;
326
328
337 void write(const cat_entree *x,
338 action_done_for_data & data_restored,
339 bool & ea_restored,
340 bool & data_created,
341 bool & hard_link,
342 bool & fsa_restored);
343
344
349 void ignore_overwrite_restrictions_for_next_write() { ignore_over_restricts = true; };
350
351
352 private:
353 class stack_dir_t : public cat_directory
354 {
355 public:
356 stack_dir_t(const cat_directory & ref, bool restore) : cat_directory(ref) { restore_date = restore; };
357
358 bool get_restore_date() const { return restore_date; };
359 void set_restore_date(bool val) { restore_date = val; };
360
361 private:
362 bool restore_date;
363 };
364
365 path *fs_root;
366 bool info_details;
367 mask *ea_mask;
368 bool warn_overwrite;
369 cat_inode::comparison_fields what_to_check;
370 bool warn_remove_no_match;
371 std::vector<stack_dir_t> stack_dir;
372 path *current_dir;
373 bool empty;
374 bool ignore_over_restricts;
375 const crit_action *overwrite;
376 bool only_overwrite;
377
378 void detruire();
379 void restore_stack_dir_ownership();
380
381 // subroutines of write()
382
384 void action_over_remove(const cat_inode *in_place,
385 const cat_detruit *to_be_added,
386 const std::string & spot,
387 over_action_data action);
389 void action_over_data(const cat_inode *in_place,
390 const cat_nomme *to_be_added,
391 const std::string & spot,
392 over_action_data action,
393 action_done_for_data & data_done);
395 bool action_over_ea(const cat_inode *in_place,
396 const cat_nomme *to_be_added,
397 const std::string & spot,
398 over_action_ea action);
400 bool action_over_fsa(const cat_inode *in_place,
401 const cat_nomme *to_be_added,
402 const std::string & spot,
403 over_action_ea action);
404
405 };
406
407
409
410 } // end of namespace
411
412 #endif
libdar::on_pool
Definition: on_pool.hpp:52
criterium.hpp
contains classes that let the user define the policy for overwriting files
libdar::filesystem_restore::write
void write(const cat_entree *x, action_done_for_data &data_restored, bool &ea_restored, bool &data_created, bool &hard_link, bool &fsa_restored)
restore a libdar object to a filesystem entry both data and EA
fsa_family.hpp
filesystem specific attributes available families and fsa_scope definition
libdar::mask
the generic class, parent of all masks
Definition: mask.hpp:61
libdar::over_action_data
over_action_data
the possible actions for overwriting data
Definition: criterium.hpp:44
libdar::filesystem_hard_link_read
keep trace of hard links when reading the filesystem
Definition: filesystem.hpp:65
libdar::filesystem_restore::ignore_overwrite_restrictions_for_next_write
void ignore_overwrite_restrictions_for_next_write()
Definition: filesystem.hpp:349
libdar::user_interaction
This is a pure virtual class that is used by libdar when interaction with the user is required...
Definition: user_interaction.hpp:98
libdar::filesystem_backup
make a flow sequence of inode to feed the backup filtering routing
Definition: filesystem.hpp:138
libdar::filesystem_hard_link_read::get_fsa_scope
const fsa_scope get_fsa_scope() const
provide the FSA scope used by the object
Definition: filesystem.hpp:88
libdar::over_action_ea
over_action_ea
the possible action for overwriting EA
Definition: criterium.hpp:58
libdar::filesystem_restore::operator=
const filesystem_restore & operator=(const filesystem_restore &ref)
assignment operator is forbidden (throws an exception)
Definition: filesystem.hpp:312
libdar::cat_mirage
the hard link implementation, cat_mirage is the named entry owned by a directory it points to a commo...
Definition: cat_mirage.hpp:47
libdar::cat_directory
the cat_directory inode class
Definition: cat_directory.hpp:51
etage.hpp
definition of the etage structure is done here
libdar::filesystem_restore::filesystem_restore
filesystem_restore(const filesystem_restore &ref)
copy constructor is forbidden (throws an exception)
Definition: filesystem.hpp:310
libdar::crit_action
the global action for overwriting
Definition: criterium.hpp:77
libdar::mem_ui::mem_ui
mem_ui(const user_interaction &dialog)
constructor
Definition: mem_ui.hpp:62
libdar::cat_nomme
the base class for all entry that have a name
Definition: cat_nomme.hpp:44
libdar::filesystem_hard_link_write::raw_set_ea
bool raw_set_ea(const cat_nomme *e, const ea_attributs &list_ea, const std::string &spot, const mask &ea_mask)
add the given EA matching the given mask to the file pointed to by "e" and spot
libdar::filesystem_hard_link_write::raw_clear_ea_set
bool raw_clear_ea_set(const cat_nomme *e, const std::string &path)
remove EA set from filesystem's file, allows subsequent raw_set_ea
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
libdar::filesystem_hard_link_write::clear_corres_if_pointing_to
void clear_corres_if_pointing_to(const infinint &ligne, const std::string &path)
libdar::filesystem_restore::reset_write
void reset_write()
reset the writing process for the current object
libdar::mem_ui
class mem_ui to keep a copy of a user_interaction object
Definition: mem_ui.hpp:53
libdar::filesystem_restore::~filesystem_restore
~filesystem_restore()
destructor
Definition: filesystem.hpp:314
libdar::filesystem_diff
make a flow of inode to feed the difference filter routine
Definition: filesystem.hpp:181
on_pool.hpp
this is the base class of object that can be allocated on a memory pool
libdar::filesystem_restore
receive the flow of inode from the restoration filtering routing and promotes these to real filesyste...
Definition: filesystem.hpp:294
libdar::infinint
the arbitrary large positive integer class
Definition: real_infinint.hpp:59
cat_all_entrees.hpp
include file gathering all entree found in a catalogue
libdar::cat_inode::comparison_fields
comparison_fields
flag used to only consider certain fields when comparing/restoring inodes
Definition: cat_inode.hpp:60
libdar::cat_entree
the root class from all other inherite for any entry in the catalogue
Definition: cat_entree.hpp:85
libdar::mem_ui::get_ui
user_interaction & get_ui() const
get access to the user_interaction cloned object
libdar::ea_attributs
the class ea_attributs manages the set of EA that can be associated to an inode
Definition: ea.hpp:47
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
catalogue.hpp
here is defined the many classed which is build of the catalogue
libdar::filesystem_restore::filesystem_restore
filesystem_restore(user_interaction &dialog, const path &root, bool x_warn_overwrite, bool x_info_details, const mask &x_ea_mask, cat_inode::comparison_fields what_to_check, bool x_warn_remove_no_match, bool empty, const crit_action *x_overwrite, bool x_only_overwrite, const fsa_scope &scope)
constructor
libdar::filesystem_hard_link_write
keep trace of already written inodes to restore hard links
Definition: filesystem.hpp:224
libdar::path
the class path is here to manipulate paths in the Unix notation: using'/'
Definition: path.hpp:50