Loading...
Searching...
No Matches
hash_fichier.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2025 Denis Corbin
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// to contact the author, see the AUTHOR file
/*********************************************************************/
#ifndef HASH_FICHIER_HPP
#define HASH_FICHIER_HPP
#include "../my_config.h"
extern "C"
{
#if HAVE_GCRYPT_H
#ifndef GCRYPT_NO_DEPRECATED
#define GCRYPT_NO_DEPRECATED
#endif
#include <gcrypt.h>
#endif
#if HAVE_RHASH_H
#include <rhash.h>
#endif
}
#include <string>
#include "fichier_global.hpp"
#include "integers.hpp"
#include "archive_aux.hpp"
namespace libdar
{
class hash_fichier : public fichier_global
{
public:
hash_fichier(const std::shared_ptr<user_interaction> & dialog,
fichier_global *under,
const std::string & under_filename,
fichier_global *hash_file,
hash_algo algo);
hash_fichier(const hash_fichier & ref) = delete;
hash_fichier(hash_fichier && ref) noexcept = delete;
hash_fichier & operator = (const hash_fichier & ref) = delete;
hash_fichier & operator = (hash_fichier && ref) noexcept = delete;
~hash_fichier();
// inherited from fichier_global
virtual void change_ownership(const std::string & user, const std::string & group) override { if(ref == nullptr || hash_ref == nullptr) throw SRC_BUG; ref->change_ownership(user, group); hash_ref->change_ownership(user, group); };
virtual void change_permission(U_I perm) override { if(ref == nullptr || hash_ref == nullptr) throw SRC_BUG; ref->change_permission(perm); hash_ref->change_permission(perm); };
virtual infinint get_size() const override { if(ref == nullptr) throw SRC_BUG; return ref->get_size(); };
virtual void fadvise(advise adv) const override { if(ref == nullptr) throw SRC_BUG; ref->fadvise(adv); };
// inherited from generic_file
virtual bool skippable(skippability direction, const infinint & amount) override { return false; };
virtual bool skip(const infinint & pos) override {if(ref == nullptr || pos != ref->get_position()) throw SRC_BUG; else return true; };
virtual bool skip_to_eof() override { if(get_mode() == gf_write_only) return true; else throw SRC_BUG; };
virtual bool skip_relative(S_I x) override { if(x != 0) throw SRC_BUG; else return true; };
virtual bool truncatable(const infinint & pos) const override { return false; };
virtual infinint get_position() const override { if(ref == nullptr) throw SRC_BUG; return ref->get_position(); };
void set_only_hash() { only_hash = true; };
protected:
// inherited from fichier_global
virtual void inherited_read_ahead(const infinint & amount) override { ref->read_ahead(amount); };
virtual U_I fichier_global_inherited_write(const char *a, U_I size) override;
virtual bool fichier_global_inherited_read(char *a, U_I size, U_I & read, std::string & message) override;
// inherited from generic_file
virtual void inherited_truncate(const infinint & pos) override { throw SRC_BUG; }; // truncate not supported on hash files
virtual void inherited_sync_write() override {};
virtual void inherited_flush_read() override {};
virtual void inherited_terminate() override;
private:
fichier_global *ref;
fichier_global *hash_ref;
bool only_hash;
#if CRYPTO_AVAILABLE
gcry_md_hd_t hash_handle;
#endif
#if RHASH_AVAILABLE
rhash rhash_ctxt;
#endif
std::string ref_filename;
U_I hash_gcrypt;
bool eof;
bool hash_dumped;
hash_algo algor;
void write_hash_in_hexa(void const* digest, U_I digest_size);
};
} // end of namespace
#endif
archive_aux.hpp
set of datastructures used to interact with a catalogue object
libdar::fichier_global::advise
advise
Definition fichier_global.hpp:62
libdar::fichier_global::fichier_global
fichier_global(const std::shared_ptr< user_interaction > &dialog, gf_mode mode)
constructor
Definition fichier_global.hpp:76
libdar::generic_file::get_mode
gf_mode get_mode() const
retreive the openning mode for this object
Definition generic_file.hpp:109
libdar::generic_file::read
virtual U_I read(char *a, U_I size) override
read data from the generic_file inherited from proto_generic_file
libdar::hash_fichier::inherited_read_ahead
virtual void inherited_read_ahead(const infinint &amount) override
tells the object that several calls to read() will follow to probably obtain at least the given amoun...
Definition hash_fichier.hpp:116
libdar::hash_fichier::~hash_fichier
~hash_fichier()
destructor
libdar::hash_fichier::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
Definition hash_fichier.hpp:121
libdar::hash_fichier::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
libdar::hash_fichier::hash_fichier
hash_fichier(const hash_fichier &ref)=delete
copy constructor
libdar::hash_fichier::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition hash_fichier.hpp:104
libdar::hash_fichier::change_ownership
virtual void change_ownership(const std::string &user, const std::string &group) override
set the ownership of the file
Definition hash_fichier.hpp:98
libdar::hash_fichier::get_position
virtual infinint get_position() const override
get the current read/write position
Definition hash_fichier.hpp:109
libdar::hash_fichier::get_size
virtual infinint get_size() const override
return the size of the file
Definition hash_fichier.hpp:100
libdar::hash_fichier::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition hash_fichier.hpp:108
libdar::hash_fichier::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
Definition hash_fichier.hpp:106
libdar::hash_fichier::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
Definition hash_fichier.hpp:107
libdar::hash_fichier::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
Definition hash_fichier.hpp:105
libdar::hash_fichier::fichier_global_inherited_read
virtual bool fichier_global_inherited_read(char *a, U_I size, U_I &read, std::string &message) override
replaces generic_file::inherited_read() method, to allow the return of partial reading
libdar::hash_fichier::hash_fichier
hash_fichier(const std::shared_ptr< user_interaction > &dialog, fichier_global *under, const std::string &under_filename, fichier_global *hash_file, hash_algo algo)
libdar::hash_fichier::set_only_hash
void set_only_hash()
for debugging purposes only
Definition hash_fichier.hpp:112
libdar::hash_fichier::change_permission
virtual void change_permission(U_I perm) override
change the permission of the file
Definition hash_fichier.hpp:99
libdar::hash_fichier::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition hash_fichier.hpp:122
libdar::hash_fichier::fichier_global_inherited_write
virtual U_I fichier_global_inherited_write(const char *a, U_I size) override
replaces generic_file::inherited_write() method, to allow the return of partial writings
libdar::hash_fichier::operator=
hash_fichier & operator=(const hash_fichier &ref)=delete
assignment operator
libdar::hash_fichier::fadvise
virtual void fadvise(advise adv) const override
set posix_fadvise for the whole file
Definition hash_fichier.hpp:101
libdar::hash_fichier::only_hash
bool only_hash
if set, avoids copying data to file, only compute hash (debugging purpose)
Definition hash_fichier.hpp:129
libdar::hash_fichier::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition hash_fichier.hpp:123
libdar::hash_fichier::hash_fichier
hash_fichier(hash_fichier &&ref) noexcept=delete
move constructor
libdar::infinint
the arbitrary large positive integer class
Definition real_infinint.hpp:62
fichier_global.hpp
class fichier_global definition. This class is a pure virtual class class fichier_global is an abstra...
libdar::hash_algo
hash_algo
hashing algorithm available
Definition archive_aux.hpp:63
libdar::gf_write_only
@ gf_write_only
write only access
Definition gf_mode.hpp:46
integers.hpp
are defined here basic integer types that tend to be portable
my_config.h
include macro defined by the configure script and some specific additional ones
libdar
libdar namespace encapsulate all libdar symbols
Definition archive.hpp:47