Disk ARchive  2.4.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
header.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 // $Id: header.hpp,v 1.19.2.1 2012/02/12 20:43:34 edrusb Rel $
22 //
23 /*********************************************************************/
24 
28 
29 
30 #ifndef HEADER_HPP
31 #define HEADER_HPP
32 
33 #include "../my_config.h"
34 
35 #include "infinint.hpp"
36 #include "generic_file.hpp"
37 #include "user_interaction.hpp"
38 #include "tlv_list.hpp"
39 #include "label.hpp"
40 
41 #include <vector>
42 
43 namespace libdar
44 {
45 
48 
49  const U_32 SAUV_MAGIC_NUMBER = 123; // Why "SAUV_..." because SAUV was the name of DAR much before its first release :-)
50 
51  typedef U_32 magic_number;
52 
53  enum flag_type
54  {
55  flag_type_terminal = 'T',
56  flag_type_non_terminal = 'N',
57  flag_type_located_at_end_of_slice = 'E' // since archive format version 8
58  };
59 
60 
62 
71 
72  class header
73  {
74  public:
75  // constructors & Co.
76 
77  header();
78  header(const header & ref) { copy_from(ref); };
79  const struct header & operator = (const header & ref) { free_pointers(); copy_from(ref); return *this; };
80  ~header() { free_pointers(); };
81 
82  // global methods
83 
84  void read(user_interaction & ui, generic_file & f, bool lax = false );
85  void write(user_interaction &, generic_file & f) const;
86  void read(user_interaction & dialog, S_I fd, bool lax = false);
87  void write(user_interaction & dialog, S_I fd) const;
88 
90 
98  static U_I min_size() { return sizeof(magic_number) + sizeof(label) + 2*sizeof(char); };
99 
100 
101  // fields access methods
102 
103  magic_number & get_set_magic() { return magic; };
104  label & get_set_internal_name() { return internal_name; };
105  char & get_set_flag() { return flag; };
106  label & get_set_data_name() { return data_name; };
107 
108  bool get_first_slice_size(infinint & size) const;
109  void set_first_slice_size(const infinint & size);
110  void unset_first_slice_size() { if(first_size != NULL) { delete first_size; first_size = NULL; } };
111 
112  bool get_slice_size(infinint & size) const;
113  void set_slice_size(const infinint & size);
114  void unset_slice_size() { if(slice_size != NULL) { delete slice_size; slice_size = NULL; } };
115 
116  bool is_old_header() const { return old_header; };
117 
118  private:
119  magic_number magic; //< constant string for all Dar archives
120  label internal_name; //< constant string for all slices of a given archive (computed based on date and pid)
121  label data_name; //< constant string for a set of data (constant with dar_xform, used to link isolated catalogue to its original data)
122  char flag; //< whether slice is the last of the archive or not
123  infinint *first_size; //< size of the first slice
124  infinint *slice_size; //< size of slices (except first slice if specified else and last if not fulfilled)
125  bool old_header; //< true if the header has been read from an old archive (before release 2.4.0)
126 
127 
128  void copy_from(const header & ref);
129  void free_pointers();
130  void fill_from(user_interaction & ui, const tlv_list & list);
131  tlv_list build_tlv_list(user_interaction & ui) const;
132  };
133 
135 
136 } // end of namespace
137 
138 #endif
139