|
Disk ARchive
2.4.12
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 00025 00026 00027 #ifndef HEADER_HPP 00028 #define HEADER_HPP 00029 00030 #include "../my_config.h" 00031 00032 #include "infinint.hpp" 00033 #include "generic_file.hpp" 00034 #include "user_interaction.hpp" 00035 #include "tlv_list.hpp" 00036 #include "label.hpp" 00037 00038 #include <vector> 00039 00040 namespace libdar 00041 { 00042 00045 00046 const U_32 SAUV_MAGIC_NUMBER = 123; // Why "SAUV_..." because SAUV was the name of DAR much before its first release :-) 00047 00048 typedef U_32 magic_number; 00049 00050 enum flag_type 00051 { 00052 flag_type_terminal = 'T', 00053 flag_type_non_terminal = 'N', 00054 flag_type_located_at_end_of_slice = 'E' // since archive format version 8 00055 }; 00056 00057 00059 00068 00069 class header 00070 { 00071 public: 00072 // constructors & Co. 00073 00074 header(); 00075 header(const header & ref) { copy_from(ref); }; 00076 const struct header & operator = (const header & ref) { free_pointers(); copy_from(ref); return *this; }; 00077 ~header() { free_pointers(); }; 00078 00079 // global methods 00080 00081 void read(user_interaction & ui, generic_file & f, bool lax = false ); 00082 void write(user_interaction &, generic_file & f) const; 00083 void read(user_interaction & dialog, S_I fd, bool lax = false); 00084 void write(user_interaction & dialog, S_I fd) const; 00085 00087 00095 static U_I min_size() { return sizeof(magic_number) + sizeof(label) + 2*sizeof(char); }; 00096 00097 00098 // fields access methods 00099 00100 magic_number & get_set_magic() { return magic; }; 00101 label & get_set_internal_name() { return internal_name; }; 00102 char & get_set_flag() { return flag; }; 00103 label & get_set_data_name() { return data_name; }; 00104 00105 bool get_first_slice_size(infinint & size) const; 00106 void set_first_slice_size(const infinint & size); 00107 void unset_first_slice_size() { if(first_size != NULL) { delete first_size; first_size = NULL; } }; 00108 00109 bool get_slice_size(infinint & size) const; 00110 void set_slice_size(const infinint & size); 00111 void unset_slice_size() { if(slice_size != NULL) { delete slice_size; slice_size = NULL; } }; 00112 00113 bool is_old_header() const { return old_header; }; 00114 void set_format_07_compatibility() { old_header = true; }; 00115 00116 private: 00117 magic_number magic; //< constant string for all Dar archives 00118 label internal_name; //< constant string for all slices of a given archive (computed based on date and pid) 00119 label data_name; //< constant string for a set of data (constant with dar_xform, used to link isolated catalogue to its original data) 00120 char flag; //< whether slice is the last of the archive or not 00121 infinint *first_size; //< size of the first slice 00122 infinint *slice_size; //< size of slices (except first slice if specified else and last if not fulfilled) 00123 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). 00124 00125 void copy_from(const header & ref); 00126 void free_pointers(); 00127 void fill_from(user_interaction & ui, const tlv_list & list); 00128 tlv_list build_tlv_list(user_interaction & ui) const; 00129 }; 00130 00132 00133 } // end of namespace 00134 00135 #endif 00136
1.7.6.1