Disk ARchive  2.4.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
fichier.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 
25 
26 #ifndef FICHIER_HPP
27 #define FICHIER_HPP
28 
29 
30 #include "../my_config.h"
31 
32 extern "C"
33 {
34 #if HAVE_UNISTD_H
35 #include <unistd.h>
36 #endif
37 } // end extern "C"
38 
39 #include "integers.hpp"
40 #include "thread_cancellation.hpp"
41 #include "label.hpp"
42 #include "crc.hpp"
43 #include "user_interaction.hpp"
44 #include "mem_ui.hpp"
45 
46 #include <string>
47 
48 namespace libdar
49 {
50 
53 
54  class fichier : public generic_file, public thread_cancellation
55  {
56  public :
57  // constructors
58  fichier(user_interaction & dialog, S_I fd);
59  fichier(user_interaction & dialog, const char *name, gf_mode m, U_I mode, bool furtive_mode);
60  fichier(user_interaction & dialog, const std::string & chemin, gf_mode m, U_I mode, bool furtive_mode);
61  fichier(const std::string & chemin, bool furtive_mode = false); // builds a read-only object
62  fichier(const fichier & ref) : generic_file(ref) { copy_from(ref); };
63 
64  // assignment operator
65  const fichier & operator = (const fichier & ref) { detruit(); copy_from(ref); return *this; };
66 
67  // destructor
68  ~fichier() { detruit(); };
69 
70 
72  virtual void change_ownership(const std::string & user, const std::string & group);
73 
75  virtual void change_permission(U_I perm);
76 
78  infinint get_size() const;
79 
80  // inherited from generic_file
81  bool skip(const infinint & pos);
82  bool skip_to_eof();
83  bool skip_relative(S_I x);
84  infinint get_position();
85 
86 #ifdef LIBDAR_SPECIAL_ALLOC
87  USE_SPECIAL_ALLOC(fichier);
88 #endif
89  protected :
90  U_I inherited_read(char *a, U_I size);
91  void inherited_write(const char *a, U_I size);
92  void inherited_sync_write() {};
93  void inherited_terminate() {};
94 
95  private :
96  S_I filedesc;
97  user_interaction *x_dialog;
98 
99  void open(const char *name, gf_mode m, U_I perm, bool furtive_mode);
100  void copy_from(const fichier & ref);
101  void detruit() { close(filedesc); filedesc = -1; if(x_dialog != NULL) { delete x_dialog; x_dialog = NULL; } };
102  void init_dialog(user_interaction &dialog);
103  };
104 
106 
107 } // end of namespace
108 
109 #endif