Disk ARchive
2.4.5
|
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$ 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) { free_pointers(); copy_from(ref); return *this; }; 00080 ~header() { free_pointers(); }; 00081 00082 // global methods 00083 00084 void read(user_interaction & ui, generic_file & f, bool lax = false ); 00085 void write(user_interaction &, generic_file & f) const; 00086 void read(user_interaction & dialog, S_I fd, bool lax = false); 00087 void write(user_interaction & dialog, S_I fd) const; 00088 00090 00098 static U_I min_size() { return sizeof(magic_number) + sizeof(label) + 2*sizeof(char); }; 00099 00100 00101 // fields access methods 00102 00103 magic_number & get_set_magic() { return magic; }; 00104 label & get_set_internal_name() { return internal_name; }; 00105 char & get_set_flag() { return flag; }; 00106 label & get_set_data_name() { return data_name; }; 00107 00108 bool get_first_slice_size(infinint & size) const; 00109 void set_first_slice_size(const infinint & size); 00110 void unset_first_slice_size() { if(first_size != NULL) { delete first_size; first_size = NULL; } }; 00111 00112 bool get_slice_size(infinint & size) const; 00113 void set_slice_size(const infinint & size); 00114 void unset_slice_size() { if(slice_size != NULL) { delete slice_size; slice_size = NULL; } }; 00115 00116 bool is_old_header() const { return old_header; }; 00117 00118 private: 00119 magic_number magic; //< constant string for all Dar archives 00120 label internal_name; //< constant string for all slices of a given archive (computed based on date and pid) 00121 label data_name; //< constant string for a set of data (constant with dar_xform, used to link isolated catalogue to its original data) 00122 char flag; //< whether slice is the last of the archive or not 00123 infinint *first_size; //< size of the first slice 00124 infinint *slice_size; //< size of slices (except first slice if specified else and last if not fulfilled) 00125 bool old_header; //< true if the header has been read from an old archive (before release 2.4.0) 00126 00127 00128 void copy_from(const header & ref); 00129 void free_pointers(); 00130 void fill_from(user_interaction & ui, const tlv_list & list); 00131 tlv_list build_tlv_list(user_interaction & ui) const; 00132 }; 00133 00135 00136 } // end of namespace 00137 00138 #endif 00139