Disk ARchive  2.5.9
Full featured and portable backup and archiving tool
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
fichier_local.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 
26 
27 #ifndef FICHIER_LOCAL_HPP
28 #define FICHIER_LOCAL_HPP
29 
30 
31 #include "../my_config.h"
32 
33 extern "C"
34 {
35 #if HAVE_UNISTD_H
36 #include <unistd.h>
37 #endif
38 } // end extern "C"
39 
40 #include "integers.hpp"
41 #include "thread_cancellation.hpp"
42 #include "label.hpp"
43 #include "crc.hpp"
44 #include "user_interaction.hpp"
45 #include "mem_ui.hpp"
46 #include "fichier_global.hpp"
47 
48 #include <string>
49 
50 namespace libdar
51 {
52 
55 
56 
58 
60  {
61  public :
62 
63  // constructors
64 
66  const std::string & chemin,
67  gf_mode m,
68  U_I permission,
69  bool fail_if_exists,
70  bool erase,
71  bool furtive_mode);
72  fichier_local(const std::string & chemin, bool furtive_mode = false); // builds a read-only object
73  fichier_local(const fichier_local & ref) : fichier_global(ref) { copy_from(ref); };
74 
75  // assignment operator
76  const fichier_local & operator = (const fichier_local & ref) { detruit(); copy_parent_from(ref); copy_from(ref); return *this; };
77 
78  // destructor
79  ~fichier_local() { detruit(); };
80 
81 
83  virtual void change_ownership(const std::string & user, const std::string & group);
84 
86  virtual void change_permission(U_I perm);
87 
89  infinint get_size() const;
90 
92  void fadvise(advise adv) const;
93 
94  // inherited from generic_file
95  bool skippable(skippability direction, const infinint & amount) { return true; };
96  bool skip(const infinint & pos);
97  bool skip_to_eof();
98  bool skip_relative(S_I x);
99  infinint get_position() const;
100 
104  S_I give_fd_and_terminate() { int ret = filedesc; filedesc = -1; terminate(); return ret; };
105 
106  protected :
107  // inherited from generic_file grand-parent class
108  void inherited_read_ahead(const infinint & amount) {}; // nothing done, calling readahead(2) could be added in the future
109  void inherited_sync_write() { fsync(); };
110  void inherited_flush_read() {}; // nothing stored in transit in this object
111  void inherited_terminate() { if(adv == advise_dontneed) fadvise(adv); };
112 
113  // inherited from fichier_global parent class
114  U_I fichier_global_inherited_write(const char *a, U_I size);
115  bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message);
116 
117  private :
118  S_I filedesc;
119  advise adv;
120 
121  void open(const std::string & chemin,
122  gf_mode m,
123  U_I permission,
124  bool fail_if_exists,
125  bool erase,
126  bool furtive_mode);
127 
128  void copy_from(const fichier_local & ref);
129  void copy_parent_from(const fichier_local & ref);
130  void detruit() { if(filedesc >= 0) close(filedesc); filedesc = -1; };
131  int advise_to_int(advise arg) const;
132 
134 
138  void fsync() const;
139 
140  };
141 
143 
144 } // end of namespace
145 
146 #endif
class mem_ui definition. This class is to be used as parent class to handle user_interaction object m...
void inherited_read_ahead(const infinint &amount)
are defined here basic integer types that tend to be portable
class crc definition, used to handle Cyclic Redundancy Checks
define the datastructure "label" used to identify slice membership to an archive
This is a pure virtual class that is used by libdar when interaction with the user is required...
U_I read(char *a, U_I size)
read data from the generic_file
filesystem local files
gf_mode
generic_file openning modes
infinint get_position() const
get the current read/write position
void inherited_sync_write()
write down any pending data
void terminate() const
destructor-like call, except that it is allowed to throw exceptions
defines the interaction between libdar and the user.Three classes are defined
class fichier_global definition. This class is a pure virtual class class fichier_global is an abstra...
abstraction of filesystem files for entrepot
to be able to cancel libdar operation while running in a given thread.the class thread_cancellation i...
bool skippable(skippability direction, const infinint &amount)
virtual void change_ownership(const std::string &user, const std::string &group)
set the ownership of the file
U_I fichier_global_inherited_write(const char *a, U_I size)
bool skip(const infinint &pos)
fichier_global(const user_interaction &dialog, gf_mode mode)
void fadvise(advise adv) const
set posix_fadvise for the whole file
bool skip_relative(S_I x)
skip relatively to the current position
the arbitrary large positive integer class
void inherited_terminate()
destructor-like call, except that it is allowed to throw exceptions
bool fichier_global_inherited_read(char *a, U_I size, U_I &read, std::string &message)
bool skip_to_eof()
skip to the end of file
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47
virtual void change_permission(U_I perm)
change the permission of the file
infinint get_size() const
return the size of the file