Disk ARchive  2.4.15
 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 
38 #include <vector>
39 
40 namespace libdar
41 {
42 
45 
46  const U_32 SAUV_MAGIC_NUMBER = 123; // Why "SAUV_..." because SAUV was the name of DAR much before its first release :-)
47 
48  typedef U_32 magic_number;
49 
50  enum flag_type
51  {
52  flag_type_terminal = 'T',
53  flag_type_non_terminal = 'N',
54  flag_type_located_at_end_of_slice = 'E' // since archive format version 8
55  };
56 
57 
59 
68 
69  class header
70  {
71  public:
72  // constructors & Co.
73 
74  header();
75  header(const header & ref) { copy_from(ref); };
76  const header & operator = (const header & ref) { free_pointers(); copy_from(ref); return *this; };
77  ~header() { free_pointers(); };
78 
79  // global methods
80 
81  void read(user_interaction & ui, generic_file & f, bool lax = false );
82  void write(user_interaction &, generic_file & f) const;
83  void read(user_interaction & dialog, S_I fd, bool lax = false);
84  void write(user_interaction & dialog, S_I fd) const;
85 
87 
95  static U_I min_size() { return sizeof(magic_number) + sizeof(label) + 2*sizeof(char); };
96 
97 
98  // fields access methods
99 
100  magic_number & get_set_magic() { return magic; };
101  label & get_set_internal_name() { return internal_name; };
102  char & get_set_flag() { return flag; };
103  label & get_set_data_name() { return data_name; };
104 
105  bool get_first_slice_size(infinint & size) const;
106  void set_first_slice_size(const infinint & size);
107  void unset_first_slice_size() { if(first_size != NULL) { delete first_size; first_size = NULL; } };
108 
109  bool get_slice_size(infinint & size) const;
110  void set_slice_size(const infinint & size);
111  void unset_slice_size() { if(slice_size != NULL) { delete slice_size; slice_size = NULL; } };
112 
113  bool is_old_header() const { return old_header; };
114  void set_format_07_compatibility() { old_header = true; };
115 
116  private:
117  magic_number magic; //< constant string for all Dar archives
118  label internal_name; //< constant string for all slices of a given archive (computed based on date and pid)
119  label data_name; //< constant string for a set of data (constant with dar_xform, used to link isolated catalogue to its original data)
120  char flag; //< whether slice is the last of the archive or not
121  infinint *first_size; //< size of the first slice
122  infinint *slice_size; //< size of slices (except first slice if specified else and last if not fulfilled)
123  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).
124 
125  void copy_from(const header & ref);
126  void free_pointers();
127  void fill_from(user_interaction & ui, const tlv_list & list);
128  tlv_list build_tlv_list(user_interaction & ui) const;
129  };
130 
132 
133 } // end of namespace
134 
135 #endif
136