Loading...
Searching...
No Matches
fichier_local.hpp
Go to the documentation of this file.
/*********************************************************************/
// dar - disk archive - a backup/restoration program
// Copyright (C) 2002-2024 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 FICHIER_LOCAL_HPP
#define FICHIER_LOCAL_HPP
#include "../my_config.h"
extern "C"
{
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
} // end extern "C"
#include "integers.hpp"
#include "user_interaction.hpp"
#include "fichier_global.hpp"
#include <string>
namespace libdar
{
class fichier_local : public fichier_global
{
public :
fichier_local(const std::shared_ptr<user_interaction> & dialog,
const std::string & chemin,
gf_mode m,
U_I permission,
bool fail_if_exists,
bool erase,
bool furtive_mode);
fichier_local(const std::string & chemin, bool furtive_mode = false);
fichier_local(const fichier_local & ref) : fichier_global(ref) { copy_from(ref); };
fichier_local(fichier_local && ref) noexcept: fichier_global(std::move(ref)) { move_from(std::move(ref)); };
fichier_local & operator = (const fichier_local & ref) { detruit(); copy_from(ref); return *this; };
fichier_local & operator = (fichier_local && ref) noexcept { fichier_global::operator = (std::move(ref)); move_from(std::move(ref)); return *this; };
~fichier_local() { detruit(); };
virtual void change_ownership(const std::string & user, const std::string & group) override;
virtual void change_permission(U_I perm) override;
virtual infinint get_size() const override;
virtual void fadvise(advise adv) const override;
// inherited from generic_file
virtual bool skippable(skippability direction, const infinint & amount) override { return true; };
virtual bool skip(const infinint & pos) override;
virtual bool skip_to_eof() override;
virtual bool skip_relative(S_I x) override;
virtual bool truncatable(const infinint & pos) const override { return true; };
virtual infinint get_position() const override;
S_I give_fd_and_terminate() { int ret = filedesc; filedesc = -1; terminate(); return ret; };
protected :
// inherited from generic_file grand-parent class
virtual void inherited_truncate(const infinint & pos) override;
virtual void inherited_read_ahead(const infinint & amount) override {}; // nothing done, calling readahead(2) could be added in the future
virtual void inherited_sync_write() override { fsync(); };
virtual void inherited_flush_read() override {}; // nothing stored in transit in this object
virtual void inherited_terminate() override { if(adv == advise_dontneed) fadvise(adv); };
// inherited from fichier_global parent class
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;
private :
S_I filedesc;
advise adv;
void open(const std::string & chemin,
gf_mode m,
U_I permission,
bool fail_if_exists,
bool erase,
bool furtive_mode);
void copy_from(const fichier_local & ref);
void move_from(fichier_local && ref) noexcept;
void detruit() { if(filedesc >= 0) close(filedesc); filedesc = -1; };
int advise_to_int(advise arg) const;
void fsync() const;
off_t get_eof_offset() const;
};
} // end of namespace
#endif
libdar::fichier_global
abstraction of filesystem files for entrepot
Definition fichier_global.hpp:59
libdar::fichier_global::advise
advise
Definition fichier_global.hpp:62
libdar::fichier_global::advise_dontneed
@ advise_dontneed
application will not read the data in near future
Definition fichier_global.hpp:68
libdar::fichier_global::operator=
fichier_global & operator=(const fichier_global &ref)=default
assignment operator
libdar::fichier_global::fichier_global
fichier_global(const std::shared_ptr< user_interaction > &dialog, gf_mode mode)
constructor
Definition fichier_global.hpp:76
libdar::fichier_local
filesystem local files
Definition fichier_local.hpp:56
libdar::fichier_local::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::fichier_local::change_permission
virtual void change_permission(U_I perm) override
change the permission of the file
libdar::fichier_local::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 fichier_local.hpp:117
libdar::fichier_local::fichier_local
fichier_local(const fichier_local &ref)
copy constructor
Definition fichier_local.hpp:74
libdar::fichier_local::inherited_terminate
virtual void inherited_terminate() override
destructor-like call, except that it is allowed to throw exceptions
Definition fichier_local.hpp:120
libdar::fichier_local::fichier_local
fichier_local(const std::shared_ptr< user_interaction > &dialog, const std::string &chemin, gf_mode m, U_I permission, bool fail_if_exists, bool erase, bool furtive_mode)
full featured constructors
libdar::fichier_local::truncatable
virtual bool truncatable(const infinint &pos) const override
whether the implementation is able to truncate to the given position
Definition fichier_local.hpp:106
libdar::fichier_local::skip
virtual bool skip(const infinint &pos) override
skip at the absolute position
libdar::fichier_local::skip_to_eof
virtual bool skip_to_eof() override
skip to the end of file
libdar::fichier_local::inherited_flush_read
virtual void inherited_flush_read() override
reset internal engine, flush caches in order to read the data at current position
Definition fichier_local.hpp:119
libdar::fichier_local::skip_relative
virtual bool skip_relative(S_I x) override
skip relatively to the current position
libdar::fichier_local::inherited_sync_write
virtual void inherited_sync_write() override
write down any pending data
Definition fichier_local.hpp:118
libdar::fichier_local::fichier_local
fichier_local(const std::string &chemin, bool furtive_mode=false)
constructor without user_interaction
libdar::fichier_local::fichier_local
fichier_local(fichier_local &&ref) noexcept
move constructor
Definition fichier_local.hpp:77
libdar::fichier_local::~fichier_local
~fichier_local()
destructor
Definition fichier_local.hpp:86
libdar::fichier_local::get_size
virtual infinint get_size() const override
return the size of the file
libdar::fichier_local::fadvise
virtual void fadvise(advise adv) const override
set posix_fadvise for the whole file
libdar::fichier_local::change_ownership
virtual void change_ownership(const std::string &user, const std::string &group) override
set the ownership of the file
libdar::fichier_local::get_position
virtual infinint get_position() const override
get the current read/write position
libdar::fichier_local::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::fichier_local::inherited_truncate
virtual void inherited_truncate(const infinint &pos) override
truncate file at the give offset
libdar::fichier_local::give_fd_and_terminate
S_I give_fd_and_terminate()
provide the low level filedescriptor to the call and terminate()
Definition fichier_local.hpp:112
libdar::fichier_local::operator=
fichier_local & operator=(const fichier_local &ref)
assignment operator
Definition fichier_local.hpp:80
libdar::fichier_local::fsync
void fsync() const
sync the data to disk
libdar::fichier_local::skippable
virtual bool skippable(skippability direction, const infinint &amount) override
whether the implementation is able to skip
Definition fichier_local.hpp:102
libdar::generic_file::terminate
void terminate()
destructor-like call, except that it is allowed to throw exceptions
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::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::gf_mode
gf_mode
generic_file openning modes
Definition gf_mode.hpp:44
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
user_interaction.hpp
defines the interaction interface between libdar and users.