Disk ARchive 2.4.2
|
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 // $Id: header.hpp,v 1.19 2011/01/09 17:25:58 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 00028 00029 00030 #ifndef HEADER_HPP 00031 #define HEADER_HPP 00032 00033 #include "../my_config.h" 00034 00035 #include "infinint.hpp" 00036 #include "generic_file.hpp" 00037 #include "user_interaction.hpp" 00038 #include "tlv_list.hpp" 00039 #include "label.hpp" 00040 00041 #include <vector> 00042 00043 namespace libdar 00044 { 00045 00048 00049 const U_32 SAUV_MAGIC_NUMBER = 123; // Why "SAUV_..." because SAUV was the name of DAR much before its first release :-) 00050 00051 typedef U_32 magic_number; 00052 00053 enum flag_type 00054 { 00055 flag_type_terminal = 'T', 00056 flag_type_non_terminal = 'N', 00057 flag_type_located_at_end_of_slice = 'E' // since archive format version 8 00058 }; 00059 00060 00062 00071 00072 class header 00073 { 00074 public: 00075 // constructors & Co. 00076 00077 header(); 00078 header(const header & ref) { copy_from(ref); }; 00079 const struct header & operator = (const header & ref) { copy_from(ref); return *this; }; 00080 00081 // global methods 00082 00083 void read(user_interaction & ui, generic_file & f, bool lax = false ); 00084 void write(user_interaction &, generic_file & f); 00085 void read(user_interaction & dialog, S_I fd, bool lax = false); 00086 void write(user_interaction & dialog, S_I fd); 00087 00089 00097 static U_I min_size() { return sizeof(magic_number) + sizeof(label) + 2*sizeof(char); }; 00098 00099 00100 // fields access methods 00101 00102 magic_number & get_set_magic() { return magic; }; 00103 label & get_set_internal_name() { return internal_name; }; 00104 char & get_set_flag() { return flag; }; 00105 label & get_set_data_name() { return data_name; }; 00106 00107 bool get_first_slice_size(infinint & size); 00108 void set_first_slice_size(const infinint & size); 00109 void unset_first_slice_size() { if(first_size != NULL) { delete first_size; first_size = NULL; } }; 00110 00111 bool get_slice_size(infinint & size); 00112 void set_slice_size(const infinint & size); 00113 void unset_slice_size() { if(slice_size != NULL) { delete slice_size; slice_size = NULL; } }; 00114 00115 bool is_old_header() const { return old_header; }; 00116 00117 private: 00118 magic_number magic; //< constant string for all Dar archives 00119 label internal_name; //< constant string for all slices of a given archive (computed based on date and pid) 00120 label data_name; //< constant string for a set of data (constant with dar_xform, used to link isolated catalogue to its original data) 00121 char flag; //< whether slice is the last of the archive or not 00122 infinint *first_size; //< size of the first slice 00123 infinint *slice_size; //< size of slices (except first slice if specified else and last if not fulfilled) 00124 bool old_header; //< true if the header has been read from an old archive (before release 2.4.0) 00125 00126 00127 void copy_from(const header & ref); 00128 void clear_pointers(); 00129 void fill_from(user_interaction & ui, const tlv_list & list); 00130 tlv_list build_tlv_list(user_interaction & ui) const; 00131 }; 00132 00134 00135 } // end of namespace 00136 00137 #endif 00138