Disk ARchive  2.5.14-bis
Full featured and portable backup and archiving tool
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:
72  bool x_furtive_read_mode,
73  const fsa_scope & scope) : mem_ui(&dialog)
74  { furtive_read_mode = x_furtive_read_mode; sc = scope; ask_before_zeroing_neg_dates = true; };
75 
76  // the copy of the current object would make copy of addresses in
77  // corres_read that could be released twice ... thus, copy constructor and
78  // assignement are forbidden for this class:
79 
80  filesystem_hard_link_read(const filesystem_hard_link_read & ref) : mem_ui(ref) { throw SRC_BUG; };
81  const filesystem_hard_link_read & operator = (const filesystem_hard_link_read & ref) { throw SRC_BUG; };
82 
83  // get the last assigned number for a hard linked inode
84  const infinint & get_last_etoile_ref() const { return etiquette_counter; };
85 
86  virtual ~filesystem_hard_link_read() {};
87 
89  const fsa_scope get_fsa_scope() const { return sc; };
90 
92  void zeroing_negative_dates_without_asking() { ask_before_zeroing_neg_dates = false; };
93 
94  protected:
95  // reset the whole list of hard linked inodes (hard linked inode stay alive but are no more referenced by the current object)
96  void corres_reset() { corres_read.clear(); etiquette_counter = 0; };
97 
98  // create and return a libdar object corresponding to one pointed to by its path
99  // during this operation, hard linked inode are recorded in a list to be easily pointed
100  // to by a new reference to it.
101  cat_nomme *make_read_entree(path & lieu, //< path of the file to read
102  const std::string & name, //< name of the file to read
103  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)
104  const mask & ea_mask); //< which EA to consider when creating the object
105 
106  bool get_ask_before_zeroing_neg_dates() const { return ask_before_zeroing_neg_dates; };
107  private:
108 
109  // private datastructure
110 
111  struct couple
112  {
113  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)
114  cat_etoile *obj; //< the address of the corresponding cat_etoile object for that inode
115  cat_mirage holder; //< it increments by one the obj internal counters, thus, while this object is alive, the obj will not be destroyed
116 
117  couple(cat_etoile *ptr, nlink_t ino_count) : holder("FAKE", ptr) { count = ino_count; obj = ptr; };
118  };
119 
120  struct node
121  {
122  node(ino_t num, dev_t dev) { numnode = num; device = dev; };
123 
124  // this operator is required to use the type node in a std::map
125  bool operator < (const node & ref) const { return numnode < ref.numnode || (numnode == ref.numnode && device < ref.device); };
126  ino_t numnode;
127  dev_t device;
128  };
129 
130  // private variable
131 
132  std::map <node, couple> corres_read;
133  infinint etiquette_counter;
134  bool furtive_read_mode;
135  fsa_scope sc;
136  bool ask_before_zeroing_neg_dates;
137 
138  };
139 
140 
141 
143 
145  {
146  public:
148  const path &root,
149  bool x_info_details,
150  const mask & x_ea_mask,
151  bool check_no_dump_flag,
152  bool alter_atime,
153  bool furtive_read_mode,
154  bool x_cache_directory_tagging,
155  infinint & root_fs_device,
156  bool x_ignore_unknown,
157  const fsa_scope & scope);
158  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); };
159  const filesystem_backup & operator = (const filesystem_backup & ref) { detruire(); copy_from(ref); return *this; };
160  ~filesystem_backup() { detruire(); };
161 
162  void reset_read(infinint & root_fs_device);
163  bool read(cat_entree * & ref, infinint & errors, infinint & skipped_dump);
164  void skip_read_to_parent_dir();
165  // continue reading in parent directory and
166  // ignore all entry not yet read of current directory
167  private:
168 
169  path *fs_root; //< filesystem's root to consider
170  bool info_details; //< detailed information returned to the user
171  mask *ea_mask; //< mask defining the EA to consider
172  bool no_dump_check; //< whether to check against the nodump flag presence
173  bool alter_atime; //< whether to set back atime or not
174  bool furtive_read_mode; //< whether to use furtive read mode (if true, alter_atime is ignored)
175  bool cache_directory_tagging; //< whether to consider cache directory taggin standard
176  path *current_dir; //< needed to translate from an hard linked inode to an already allocated object
177  std::vector<etage> pile; //< to store the contents of a directory
178  bool ignore_unknown; //< whether to ignore unknown inode types
179 
180  void detruire();
181  void copy_from(const filesystem_backup & ref);
182  };
183 
184 
186 
188  {
189  public:
191  const path &root,
192  bool x_info_details,
193  const mask & x_ea_mask,
194  bool alter_atime,
195  bool furtive_read_mode,
196  const fsa_scope & scope);
197  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); };
198  const filesystem_diff & operator = (const filesystem_diff & ref) { detruire(); copy_from(ref); return *this; };
199  ~filesystem_diff() { detruire(); };
200 
201  void reset_read();
202  bool read_filename(const std::string & name, cat_nomme * &ref);
203  // looks for a file of name given in argument, in current reading directory
204  // if this is a directory, subsequent read take place in it
205 
206  void skip_read_filename_in_parent_dir();
207  // subsequent calls to read_filename will take place in parent directory.
208 
209  private:
210  struct filename_struct
211  {
212  datetime last_acc;
213  datetime last_mod;
214  };
215 
216  path *fs_root;
217  bool info_details;
218  mask *ea_mask;
219  bool alter_atime;
220  bool furtive_read_mode;
221  path *current_dir;
222  std::vector<filename_struct> filename_pile;
223 
224  void detruire();
225  void copy_from(const filesystem_diff & ref);
226  };
227 
229 
230  class filesystem_hard_link_write : virtual protected mem_ui, virtual public on_pool
231  {
232  // this class is not to be used directly
233  // it only provides routines to its inherited classes
234 
235  public:
236  filesystem_hard_link_write(user_interaction & dialog) : mem_ui(& dialog) { corres_write.clear(); };
237  filesystem_hard_link_write(const filesystem_hard_link_write & ref) : mem_ui(ref) { throw SRC_BUG; };
238  const filesystem_hard_link_write & operator = (const filesystem_hard_link_write & ref) { throw SRC_BUG; };
239 
240  void write_hard_linked_target_if_not_set(const cat_mirage *ref, const std::string & chemin);
241  // if a hard linked inode has not been restored (no change, or less recent than the one on filesystem)
242  // it is necessary to inform filesystem, where to hard link on, any future hard_link
243  // that could be necessary to restore.
244 
245  bool known_etiquette(const infinint & eti);
246  // return true if an inode in filesystem has been seen for that hard linked inode
247 
251  void clear_corres_if_pointing_to(const infinint & ligne, const std::string & path);
252 
253  protected:
254  void corres_reset() { corres_write.clear(); };
255  void make_file(const cat_nomme * ref, //< object to restore in filesystem
256  const path & ou, //< where to restore it
257  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
258  cat_inode::comparison_fields what_to_check, //< defines whether to restore permission, ownership, dates, etc.
259  const fsa_scope & scope); //< fsa scope to use for restoration
260  // generate inode or make a hard link on an already restored or existing inode.
261 
262 
264 
272  bool raw_set_ea(const cat_nomme *e,
273  const ea_attributs & list_ea,
274  const std::string & spot,
275  const mask & ea_mask);
276  // check whether the inode for which to restore EA is not a hard link to
277  // an already restored inode. if not, it calls the proper ea_filesystem call to restore EA
278 
280 
284  bool raw_clear_ea_set(const cat_nomme *e, const std::string & path);
285 
286 
287  private:
288  struct corres_ino_ea
289  {
290  std::string chemin;
291  bool ea_restored;
292  };
293 
294  std::map <infinint, corres_ino_ea> corres_write;
295  };
296 
297 
299 
301  {
302  public:
305  const path & root,
306  bool x_warn_overwrite,
307  bool x_info_details,
308  const mask & x_ea_mask,
309  cat_inode::comparison_fields what_to_check,
310  bool x_warn_remove_no_match,
311  bool empty,
312  const crit_action *x_overwrite,
313  bool x_only_overwrite,
314  const fsa_scope & scope);
318  const filesystem_restore & operator = (const filesystem_restore & ref) { throw SRC_BUG; };
320  ~filesystem_restore() { restore_stack_dir_ownership(); detruire(); };
321 
323  void reset_write();
324 
325  typedef enum
326  {
327  done_data_restored, //< data has been restored to filesystem
328  done_no_change_no_data, //< no change in filesystem because no data present in archive
329  done_no_change_policy, //< no change in filesystem because of overwiting policy decision
330  done_data_removed //< data (= whole inode) removed from filesystem
331  } action_done_for_data;
332 
334 
343  void write(const cat_entree *x,
344  action_done_for_data & data_restored,
345  bool & ea_restored,
346  bool & data_created,
347  bool & hard_link,
348  bool & fsa_restored);
349 
350 
355  void ignore_overwrite_restrictions_for_next_write() { ignore_over_restricts = true; };
356 
357 
358  private:
359  class stack_dir_t : public cat_directory
360  {
361  public:
362  stack_dir_t(const cat_directory & ref, bool restore) : cat_directory(ref) { restore_date = restore; };
363 
364  bool get_restore_date() const { return restore_date; };
365  void set_restore_date(bool val) { restore_date = val; };
366 
367  private:
368  bool restore_date;
369  };
370 
371  path *fs_root;
372  bool info_details;
373  mask *ea_mask;
374  bool warn_overwrite;
375  cat_inode::comparison_fields what_to_check;
376  bool warn_remove_no_match;
377  std::vector<stack_dir_t> stack_dir;
378  path *current_dir;
379  bool empty;
380  bool ignore_over_restricts;
381  const crit_action *overwrite;
382  bool only_overwrite;
383 
384  void detruire();
385  void restore_stack_dir_ownership();
386 
387  // subroutines of write()
388 
390  void action_over_remove(const cat_inode *in_place,
391  const cat_detruit *to_be_added,
392  const std::string & spot,
393  over_action_data action);
395  void action_over_data(const cat_inode *in_place,
396  const cat_nomme *to_be_added,
397  const std::string & spot,
398  over_action_data action,
399  action_done_for_data & data_done);
401  bool action_over_ea(const cat_inode *in_place,
402  const cat_nomme *to_be_added,
403  const std::string & spot,
404  over_action_ea action);
406  bool action_over_fsa(const cat_inode *in_place,
407  const cat_nomme *to_be_added,
408  const std::string & spot,
409  over_action_ea action);
410 
411  };
412 
413 
415 
416 } // end of namespace
417 
418 #endif
contains classes that let the user define the policy for overwriting files
filesystem specific attributes available families and fsa_scope definition
the deleted file entry
Definition: cat_detruit.hpp:47
the generic class, parent of all masks
Definition: mask.hpp:62
the hard link implementation (etoile means star in French, seen a star as a point from which are thro...
Definition: cat_etoile.hpp:46
user_interaction & get_ui() const
get access to the user_interaction cloned object
over_action_data
the possible actions for overwriting data
Definition: criterium.hpp:44
void ignore_overwrite_restrictions_for_next_write()
Definition: filesystem.hpp:355
This is a pure virtual class that is used by libdar when interaction with the user is required...
make a flow sequence of inode to feed the backup filtering routing
Definition: filesystem.hpp:144
over_action_ea
the possible action for overwriting EA
Definition: criterium.hpp:58
the hard link implementation, cat_mirage is the named entry owned by a directory it points to a commo...
Definition: cat_mirage.hpp:47
the cat_directory inode class
definition of the etage structure is done here
filesystem_restore(const filesystem_restore &ref)
copy constructor is forbidden (throws an exception)
Definition: filesystem.hpp:316
the global action for overwriting
Definition: criterium.hpp:77
mem_ui(const user_interaction &dialog)
constructor
Definition: mem_ui.hpp:62
the base class for all entry that have a name
Definition: cat_nomme.hpp:44
switch module to limitint (32 ou 64 bits integers) or infinint
class mem_ui to keep a copy of a user_interaction object
Definition: mem_ui.hpp:53
~filesystem_restore()
destructor
Definition: filesystem.hpp:320
make a flow of inode to feed the difference filter routine
Definition: filesystem.hpp:187
this is the base class of object that can be allocated on a memory pool
the root class for all cat_inode
Definition: cat_inode.hpp:54
receive the flow of inode from the restoration filtering routing and promotes these to real filesyste...
Definition: filesystem.hpp:300
the arbitrary large positive integer class
include file gathering all entree found in a catalogue
the root class from all other inherite for any entry in the catalogue
Definition: cat_entree.hpp:85
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
comparison_fields
flag used to only consider certain fields when comparing/restoring inodes
Definition: cat_inode.hpp:60
here is defined the many classed which is build of the catalogue
the class path is here to manipulate paths in the Unix notation: using&#39;/&#39;
Definition: path.hpp:50