Disk ARchive  2.5.2
Full featured and portable backup and archiving tool
cat_file.hpp
Go to the documentation of this file.
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 #ifndef CAT_FILE_HPP
00027 #define CAT_FILE_HPP
00028 
00029 #include "../my_config.h"
00030 
00031 extern "C"
00032 {
00033 } // end extern "C"
00034 
00035 #include "cat_inode.hpp"
00036 
00037 namespace libdar
00038 {
00039 
00042 
00043 
00045     class cat_file : public cat_inode
00046     {
00047     public :
00048     enum get_data_mode
00049     {
00050         keep_compressed, //< provide access to compressed data
00051         keep_hole,       //< provide access to uncompressed data but sparse_file datastructure
00052         normal,          //< provide access to full data (uncompressed, uses skip() to restore holes)
00053         plain            //< provide access to plain data, no skip to restore holes, provide instead zeroed bytes
00054     };
00055 
00056     static const U_8 FILE_DATA_WITH_HOLE = 0x01; //< file's data contains hole datastructure
00057     static const U_8 FILE_DATA_IS_DIRTY = 0x02;  //< data modified while being saved
00058 
00059         cat_file(const infinint & xuid,
00060          const infinint & xgid,
00061          U_16 xperm,
00062          const datetime & last_access,
00063          const datetime & last_modif,
00064          const datetime & last_change,
00065          const std::string & src,
00066          const path & che,
00067          const infinint & taille,
00068          const infinint & fs_device,
00069          bool x_furtive_read_mode);
00070         cat_file(const cat_file & ref);
00071         cat_file(user_interaction & dialog,
00072          const pile_descriptor & pdesc,
00073          const archive_version & reading_ver,
00074          saved_status saved,
00075          compression default_algo,
00076          bool small);
00077         ~cat_file() { detruit(); };
00078 
00079         bool has_changed_since(const cat_inode & ref, const infinint & hourshift, cat_inode::comparison_fields what_to_check) const;
00080         infinint get_size() const { return *size; };
00081     void change_size(const infinint & s) const { *size = s; };
00082         infinint get_storage_size() const { return *storage_size; };
00083         void set_storage_size(const infinint & s) { *storage_size = s; };
00084         virtual generic_file *get_data(get_data_mode mode) const; // returns a newly allocated object in read_only mode
00085         void clean_data(); // partially free memory (but get_data() becomes disabled)
00086         void set_offset(const infinint & r);
00087     const infinint & get_offset() const;
00088         unsigned char signature() const { return mk_signature('f', get_saved_status()); };
00089 
00090         void set_crc(const crc &c);
00091         bool get_crc(const crc * & c) const; //< the argument is set the an allocated crc object the owned by the "cat_file" object, its stay valid while this "cat_file" object exists and MUST NOT be deleted by the caller in any case
00092     bool has_crc() const { return check != nullptr; };
00093     bool get_crc_size(infinint & val) const; //< returns true if crc is know and puts its width in argument
00094     void drop_crc() { if(check != nullptr) { delete check; check = nullptr; } };
00095 
00096         // whether the plain file has to detect sparse file
00097     void set_sparse_file_detection_read(bool val) { if(status == from_cat) throw SRC_BUG; if(val) file_data_status_read |= FILE_DATA_WITH_HOLE; else file_data_status_read &= ~FILE_DATA_WITH_HOLE; };
00098 
00099     void set_sparse_file_detection_write(bool val) { if(val) file_data_status_write |= FILE_DATA_WITH_HOLE; else file_data_status_write &= ~FILE_DATA_WITH_HOLE; };
00100 
00101         // whether the plain file is stored with a sparse_file datastructure in the archive
00102     bool get_sparse_file_detection_read() const { return (file_data_status_read & FILE_DATA_WITH_HOLE) != 0; };
00103     bool get_sparse_file_detection_write() const { return (file_data_status_write & FILE_DATA_WITH_HOLE) != 0; };
00104 
00105         cat_entree *clone() const { return new (get_pool()) cat_file(*this); };
00106 
00107         compression get_compression_algo_read() const { return algo_read; };
00108 
00109     compression get_compression_algo_write() const { return algo_write; };
00110 
00111         // object migration methods (merging)
00112     void change_compression_algo_write(compression x) { algo_write = x; };
00113 
00114         // dirtiness
00115 
00116     bool is_dirty() const { return dirty; };
00117     void set_dirty(bool value) { dirty = value; };
00118 
00119     protected:
00120         void sub_compare(const cat_inode & other, bool isolated_mode) const;
00121         void inherited_dump(const pile_descriptor & pdesc, bool small) const;
00122     void post_constructor(const pile_descriptor & pdesc);
00123 
00124         enum { empty, from_path, from_cat } status;
00125 
00126     private:
00127     std::string chemin;     //< path to the data (when read from filesystem)
00128         infinint *offset;       //< start location of the data in 'loc'
00129         infinint *size;         //< size of the data (uncompressed)
00130         infinint *storage_size; //< how much data used in archive (after compression)
00131         crc *check;
00132     bool dirty;             //< true when a file has been modified at the time it was saved
00133 
00134         compression algo_read;  //< which compression algorithm to use to read the file's data
00135     compression algo_write; //< which compression algorithm to use to write down (merging) the file's data
00136     bool furtive_read_mode; // used only when status equals "from_path"
00137     char file_data_status_read; // defines the datastructure to use when reading the data
00138     char file_data_status_write; // defines the datastructure to apply when writing down the data
00139 
00140         void detruit();
00141     };
00142 
00144 
00145 } // end of namespace
00146 
00147 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines