Disk ARchive  2.5.4
Full featured and portable backup and archiving tool
 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 
25 
26 
27 #ifndef HEADER_HPP
28 #define HEADER_HPP
29 
30 #include "../my_config.h"
31 
32 #include "infinint.hpp"
33 #include "generic_file.hpp"
34 #include "user_interaction.hpp"
35 #include "tlv_list.hpp"
36 #include "label.hpp"
37 #include "on_pool.hpp"
38 
39 #include <vector>
40 
41 namespace libdar
42 {
43 
46 
47  const U_32 SAUV_MAGIC_NUMBER = 123; // Why "SAUV_..." because SAUV was the name of DAR much before its first release :-)
48 
49  typedef U_32 magic_number;
50 
51  enum flag_type
52  {
53  flag_type_terminal = 'T',
54  flag_type_non_terminal = 'N',
55  flag_type_located_at_end_of_slice = 'E' // since archive format version 8
56  };
57 
58 
60 
67 
68  class header : public on_pool
69  {
70  public:
71  // constructors & Co.
72 
73  header();
74  header(const header & ref) { copy_from(ref); };
75  const header & operator = (const header & ref) { free_pointers(); copy_from(ref); return *this; };
76  ~header() { free_pointers(); };
77 
78  // global methods
79 
80  void read(user_interaction & ui, generic_file & f, bool lax = false );
81  void write(user_interaction &, generic_file & f) const;
82 
84 
92  static U_I min_size() { return sizeof(magic_number) + sizeof(label) + 2*sizeof(char); };
93 
94 
95  // fields access methods
96 
97  magic_number & get_set_magic() { return magic; };
98  label & get_set_internal_name() { return internal_name; };
99  char & get_set_flag() { return flag; };
100  label & get_set_data_name() { return data_name; };
101 
102  bool get_first_slice_size(infinint & size) const;
103  void set_first_slice_size(const infinint & size);
104  void unset_first_slice_size() { if(first_size != nullptr) { delete first_size; first_size = nullptr; } };
105 
106  bool get_slice_size(infinint & size) const;
107  void set_slice_size(const infinint & size);
108  void unset_slice_size() { if(slice_size != nullptr) { delete slice_size; slice_size = nullptr; } };
109 
110  bool is_old_header() const { return old_header; };
111  void set_format_07_compatibility() { old_header = true; };
112 
113  private:
114  magic_number magic; //< constant string for all Dar archives
115  label internal_name; //< constant string for all slices of a given archive (computed based on date and pid)
116  label data_name; //< constant string for a set of data (constant with dar_xform, used to link isolated catalogue to its original data)
117  char flag; //< whether slice is the last of the archive or not
118  infinint *first_size; //< size of the first slice
119  infinint *slice_size; //< size of slices (except first slice if specified else and last if not fulfilled)
120  bool old_header; //< true if the header has been read from an old archive (before release 2.4.0, format 07 and below) and if true when writing, create an old slice header (compatible with format 07).
121 
122  void copy_from(const header & ref);
123  void free_pointers();
124  void fill_from(user_interaction & ui, const tlv_list & list);
125  tlv_list build_tlv_list(user_interaction & ui) const;
126  };
127 
129 
130 } // end of namespace
131 
132 #endif
133