2020-06-27 20:45:28 +02:00
// NOMINMAX works around an MSVC issue, see https://github.com/microsoft/cppwinrt/issues/479
# if defined(_MSC_VER)
# define NOMINMAX
# endif
2014-11-15 16:33:24 +01:00
# include "Fuse.h"
2014-11-04 22:33:43 +01:00
# include <memory>
# include <cassert>
2018-05-21 08:18:34 +02:00
# include "../fs_interface/FuseErrnoException.h"
2014-11-28 14:46:45 +01:00
# include "Filesystem.h"
2015-07-21 19:45:44 +02:00
# include <iostream>
2016-02-11 12:53:42 +01:00
# include <cpp-utils/assert/assert.h>
# include <cpp-utils/logging/logging.h>
2019-01-19 22:02:41 +01:00
# include <cpp-utils/process/subprocess.h>
2019-01-20 12:25:21 +01:00
# include <cpp-utils/thread/debugging.h>
2015-11-13 00:03:22 +01:00
# include <csignal>
2018-12-03 07:57:21 +01:00
# include "InvalidFilesystem.h"
2019-01-27 14:24:26 +01:00
# include <codecvt>
2020-02-24 02:42:44 +01:00
# include <boost/algorithm/string/replace.hpp>
2014-11-15 16:33:24 +01:00
2019-01-19 22:02:41 +01:00
# if defined(_MSC_VER)
# include <dokan/dokan.h>
# endif
2015-10-15 03:41:02 +02:00
using std : : vector ;
2014-11-04 22:33:43 +01:00
using std : : string ;
namespace bf = boost : : filesystem ;
2015-10-17 17:23:35 +02:00
using namespace cpputils : : logging ;
2018-12-03 07:57:21 +01:00
using std : : make_shared ;
using std : : shared_ptr ;
2019-01-20 12:25:21 +01:00
using std : : string ;
2014-11-16 00:05:28 +01:00
using namespace fspp : : fuse ;
2019-01-20 12:25:21 +01:00
using cpputils : : set_thread_name ;
2014-11-04 22:33:43 +01:00
2018-07-30 09:33:34 +02:00
namespace {
bool is_valid_fspp_path ( const bf : : path & path ) {
// TODO In boost 1.63, we can use path.generic() or path.generic_path() instead of path.generic_string()
2018-07-30 09:42:51 +02:00
return path . has_root_directory ( ) // must be absolute path
& & ! path . has_root_name ( ) // on Windows, it shouldn't have a device specifier (i.e. no "C:")
& & ( path . string ( ) = = path . generic_string ( ) ) ; // must use portable '/' as directory separator
2018-07-30 09:33:34 +02:00
}
2019-01-20 12:25:21 +01:00
class ThreadNameForDebugging final {
public :
ThreadNameForDebugging ( const string & threadName ) {
std : : string name = " fspp_ " + threadName ;
set_thread_name ( name . c_str ( ) ) ;
}
~ ThreadNameForDebugging ( ) {
set_thread_name ( " fspp_idle " ) ;
}
} ;
2018-07-30 09:33:34 +02:00
}
2015-09-30 14:13:26 +02:00
// Remove the following line, if you don't want to output each fuse operation on the console
2022-06-25 16:57:50 +02:00
//#define FSPP_LOG 1
2014-11-04 22:33:43 +01:00
Fuse : : ~ Fuse ( ) {
2016-05-10 01:07:02 +02:00
for ( char * arg : _argv ) {
2017-10-02 08:56:31 +02:00
delete [ ] arg ;
2016-05-10 01:07:02 +02:00
arg = nullptr ;
}
_argv . clear ( ) ;
2014-11-04 22:33:43 +01:00
}
2022-06-18 21:11:24 +02:00
Fuse : : Fuse ( std : : function < shared_ptr < Filesystem > ( ) > init , std : : string fstype , boost : : optional < std : : string > fsname )
2022-06-25 16:57:50 +02:00
: _init ( std : : move ( init ) ) , _fs ( make_shared < InvalidFilesystem > ( ) ) , _running ( false ) , _fstype ( std : : move ( fstype ) ) , _fsname ( std : : move ( fsname ) ) {
2018-12-09 18:27:53 +01:00
ASSERT ( static_cast < bool > ( _init ) , " Invalid init given " ) ;
2014-11-15 16:33:24 +01:00
}
2015-11-17 07:05:04 +01:00
void Fuse : : _logException ( const std : : exception & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " Exception thrown: {} " , e . what ( ) ) ;
2015-11-17 07:05:04 +01:00
}
void Fuse : : _logUnknownException ( ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " Unknown exception thrown " ) ;
2015-11-17 07:05:04 +01:00
}
2018-12-22 02:26:38 +01:00
void Fuse : : _removeAndWarnIfExists ( vector < string > * fuseOptions , const std : : string & option ) {
auto found = std : : find ( fuseOptions - > begin ( ) , fuseOptions - > end ( ) , option ) ;
if ( found ! = fuseOptions - > end ( ) ) {
LOG ( WARN , " The fuse option {} only works when running in foreground. Removing fuse option. " , option ) ;
do {
fuseOptions - > erase ( found ) ;
found = std : : find ( fuseOptions - > begin ( ) , fuseOptions - > end ( ) , option ) ;
} while ( found ! = fuseOptions - > end ( ) ) ;
}
}
2014-11-18 00:14:33 +01:00
bool Fuse : : running ( ) const {
return _running ;
}
2018-09-16 03:02:03 +02:00
int Fuse : : getattr ( const bf : : path & path , fspp : : fuse : : STAT * stbuf ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " getattr " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " getattr({}, _, _) " , path ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2014-11-19 00:14:35 +01:00
_fs - > lstat ( path , stbuf ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " getattr({}, _, _): success " , path ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::getattr: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2018-07-31 16:29:35 +02:00
} catch ( const fspp : : fuse : : FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " getattr({}, _, _): failed with errno {} " , path , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-18 21:11:24 +02:00
int Fuse : : fgetattr ( const bf : : path & path , fspp : : fuse : : STAT * stbuf , uint64_t fh ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " fgetattr " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2019-05-26 04:25:28 +02:00
LOG ( DEBUG , " fgetattr({}, _, _) " , path ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
// On FreeBSD, trying to do anything with the mountpoint ends up
// opening it, and then using the FD for an fgetattr. So in the
// special case of a path of "/", I need to do a getattr on the
2016-02-19 02:10:10 +01:00
// underlying base directory instead of doing the fgetattr().
2014-11-15 16:33:24 +01:00
// TODO Check if necessary
2018-05-21 01:20:38 +02:00
if ( path . string ( ) = = " / " ) {
2019-05-26 04:25:28 +02:00
int result = getattr ( path , stbuf ) ;
# ifdef FSPP_LOG
LOG ( DEBUG , " fgetattr({}, _, _): success " , path ) ;
# endif
return result ;
2014-11-15 16:33:24 +01:00
}
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2022-06-18 21:11:24 +02:00
_fs - > fstat ( fh , stbuf ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " fgetattr({}, _, _): success " , path ) ;
# endif
2015-07-21 19:45:44 +02:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::fgetattr: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2018-07-31 16:29:35 +02:00
} catch ( const fspp : : fuse : : FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( ERR , " fgetattr({}, _, _): error " , path ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
int Fuse : : readlink ( const bf : : path & path , char * buf , size_t size ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " readlink " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " readlink({}, _, {}) " , path , size ) ;
2015-09-30 14:13:26 +02:00
# endif
2015-04-22 16:00:14 +02:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2018-09-15 23:32:58 +02:00
_fs - > readSymlink ( path , buf , fspp : : num_bytes_t ( size ) ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " readlink({}, _, {}): success " , path , size ) ;
# endif
2015-04-22 16:00:14 +02:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::readlink: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2015-04-22 16:00:14 +02:00
} catch ( fspp : : fuse : : FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " readlink({}, _, {}): failed with errno {} " , path , size , e . getErrno ( ) ) ;
# endif
2015-04-22 16:00:14 +02:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2015-04-22 16:00:14 +02:00
}
2014-11-15 16:33:24 +01:00
}
2018-09-14 11:34:11 +02:00
int Fuse : : mkdir ( const bf : : path & path , : : mode_t mode ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " mkdir " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " mkdir({}, {}) " , path , mode ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2019-05-25 22:35:44 +02:00
// DokanY seems to call mkdir("/"). Ignore that
if ( " / " = = path ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " mkdir({}, {}): ignored " , path , mode ) ;
# endif
2019-05-25 22:35:44 +02:00
return 0 ;
}
2022-06-18 21:11:24 +02:00
_fs - > mkdir ( path , mode , uid , gid ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " mkdir({}, {}): success " , path , mode ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::mkdir: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2018-07-31 16:29:35 +02:00
} catch ( const fspp : : fuse : : FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " mkdir({}, {}): failed with errno {} " , path , mode , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
int Fuse : : unlink ( const bf : : path & path ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " unlink " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " unlink({}) " , path ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2014-11-19 00:14:35 +01:00
_fs - > unlink ( path ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " unlink({}): success " , path ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::unlink: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2018-07-31 16:29:35 +02:00
} catch ( const fspp : : fuse : : FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " unlink({}): failed with errno {} " , path , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
int Fuse : : rmdir ( const bf : : path & path ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " rmdir " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " rmdir({}) " , path ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2014-11-19 00:14:35 +01:00
_fs - > rmdir ( path ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " rmdir({}): success " , path ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::rmdir: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2018-07-31 16:29:35 +02:00
} catch ( const fspp : : fuse : : FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " rmdir({}): failed with errno {} " , path , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2019-01-13 18:27:50 +01:00
int Fuse : : symlink ( const bf : : path & to , const bf : : path & from ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " symlink " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2019-01-13 18:27:50 +01:00
LOG ( DEBUG , " symlink({}, {}) " , to , from ) ;
2015-09-30 14:13:26 +02:00
# endif
2015-04-22 16:00:14 +02:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( from ) , " has to be an absolute path " ) ;
2022-06-18 21:11:24 +02:00
_fs - > createSymlink ( to , from , uid , gid ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " symlink({}, {}): success " , to , from ) ;
# endif
2015-04-22 16:00:14 +02:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::symlink: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2018-07-31 16:29:35 +02:00
} catch ( const fspp : : fuse : : FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " symlink({}, {}): failed with errno {} " , to , from , e . getErrno ( ) ) ;
# endif
2015-04-22 16:00:14 +02:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2015-04-22 16:00:14 +02:00
}
2014-11-15 16:33:24 +01:00
}
int Fuse : : rename ( const bf : : path & from , const bf : : path & to ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " rename " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " rename({}, {}) " , from , to ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( from ) , " from has to be an absolute path " ) ;
ASSERT ( is_valid_fspp_path ( to ) , " rename target has to be an absolute path. If this assert throws, we have to add code here that makes the path absolute. " ) ;
2014-11-19 00:14:35 +01:00
_fs - > rename ( from , to ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " rename({}, {}): success " , from , to ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::rename: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2018-07-31 16:29:35 +02:00
} catch ( const fspp : : fuse : : FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " rename({}, {}): failed with errno {} " , from , to , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
//TODO
int Fuse : : link ( const bf : : path & from , const bf : : path & to ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " link " ) ;
2017-02-04 20:03:20 +01:00
LOG ( WARN , " NOT IMPLEMENTED: link({}, {}) " , from , to ) ;
2014-11-15 17:24:07 +01:00
//auto real_from = _impl->RootDir() / from;
//auto real_to = _impl->RootDir() / to;
2018-05-21 01:20:38 +02:00
//int retstat = ::link(real_from.string().c_str(), real_to.string().c_str());
2014-11-15 16:33:24 +01:00
//return errcode_map(retstat);
return ENOSYS ;
}
2018-09-14 11:34:11 +02:00
int Fuse : : chmod ( const bf : : path & path , : : mode_t mode ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " chmod " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " chmod({}, {}) " , path , mode ) ;
2015-09-30 14:13:26 +02:00
# endif
2015-04-21 21:08:23 +02:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2015-04-21 21:08:23 +02:00
_fs - > chmod ( path , mode ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " chmod({}, {}): success " , path , mode ) ;
# endif
2015-04-21 21:08:23 +02:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::chmod: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2015-04-21 21:08:23 +02:00
} catch ( fspp : : fuse : : FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " chmod({}, {}): failed with errno {} " , path , mode , e . getErrno ( ) ) ;
# endif
2015-04-21 21:08:23 +02:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2015-04-21 21:08:23 +02:00
}
2014-11-15 16:33:24 +01:00
}
2018-09-14 11:34:11 +02:00
int Fuse : : chown ( const bf : : path & path , : : uid_t uid , : : gid_t gid ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " chown " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " chown({}, {}, {}) " , path , uid , gid ) ;
2015-09-30 14:13:26 +02:00
# endif
2015-04-21 21:08:23 +02:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2015-04-21 21:08:23 +02:00
_fs - > chown ( path , uid , gid ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " chown({}, {}, {}): success " , path , uid , gid ) ;
# endif
2015-04-21 21:08:23 +02:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::chown: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2015-04-21 21:08:23 +02:00
} catch ( fspp : : fuse : : FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " chown({}, {}, {}): failed with errno {} " , path , uid , gid , e . getErrno ( ) ) ;
# endif
2015-04-21 21:08:23 +02:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2015-04-21 21:08:23 +02:00
}
2014-11-15 16:33:24 +01:00
}
2018-09-15 23:32:58 +02:00
int Fuse : : truncate ( const bf : : path & path , int64_t size ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " truncate " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " truncate({}, {}) " , path , size ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2018-09-15 23:32:58 +02:00
_fs - > truncate ( path , fspp : : num_bytes_t ( size ) ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " truncate({}, {}): success " , path , size ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::truncate: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " truncate({}, {}): failed with errno {} " , path , size , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-18 21:11:24 +02:00
int Fuse : : ftruncate ( int64_t size , uint64_t fh ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " ftruncate " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " ftruncate({}, {}) " , fh , size ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2022-06-18 21:11:24 +02:00
_fs - > ftruncate ( fh , fspp : : num_bytes_t ( size ) ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " ftruncate({}, {}): success " , fh , size ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::ftruncate: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( WARN , " ftruncate({}, {}): failed with errno {} " , fh , size , e . getErrno ( ) ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-24 23:01:05 +02:00
int Fuse : : utimens ( const bf : : path & path , const timespec lastAccessTime , const timespec lastModificationTime ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " utimens " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " utimens({}, _) " , path ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2022-06-24 23:01:05 +02:00
_fs - > utimens ( path , lastAccessTime , lastModificationTime ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " utimens({}, _): success " , path ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::utimens: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " utimens({}, _): failed with errno {} " , path , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-18 21:11:24 +02:00
int Fuse : : open ( const bf : : path & path , uint64_t * fh , int flags ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " open " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " open({}, _) " , path ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2022-06-18 21:11:24 +02:00
* fh = _fs - > openFile ( path , flags ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " open({}, _): success " , path ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::open: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " open({}, _): failed with errno {} " , path , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-18 21:11:24 +02:00
int Fuse : : release ( uint64_t fh ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " release " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " release({}, _) " , fh ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2022-06-18 21:11:24 +02:00
_fs - > closeFile ( fh ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " release({}, _): success " , fh ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::release: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( WARN , " release({}, _): failed with errno {} " , fh , e . getErrno ( ) ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-18 21:11:24 +02:00
int Fuse : : read ( char * buf , size_t size , int64_t offset , uint64_t fh ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " read " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " read({}, _, {}, {}, _) " , fh , size , offset ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2022-06-18 21:11:24 +02:00
int result = _fs - > read ( fh , buf , fspp : : num_bytes_t ( size ) , fspp : : num_bytes_t ( offset ) ) . value ( ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " read({}, _, {}, {}, _): success with {} " , fh , size , offset , result ) ;
2019-05-26 04:25:28 +02:00
# endif
return result ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::read: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( WARN , " read({}, _, {}, {}, _): failed with errno {} " , fh , size , offset , e . getErrno ( ) ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-18 21:11:24 +02:00
int Fuse : : write ( const char * buf , size_t size , int64_t offset , uint64_t fh ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " write " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " write({}, _, {}, {}, _) " , fh , size , offset ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2022-06-18 21:11:24 +02:00
_fs - > write ( fh , buf , fspp : : num_bytes_t ( size ) , fspp : : num_bytes_t ( offset ) ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " write({}, _, {}, {}, _): success " , fh , size , offset ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return size ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::write: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( WARN , " write({}, _, {}, {}, _): failed with errno {} " , fh , size , offset , e . getErrno ( ) ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2018-09-14 11:34:11 +02:00
int Fuse : : statfs ( const bf : : path & path , struct : : statvfs * fsstat ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " statfs " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " statfs({}, _) " , path ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2018-09-22 23:24:31 +02:00
_fs - > statfs ( fsstat ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " statfs({}, _): success " , path ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::statfs: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " statfs({}, _): failed with errno {} " , path , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-18 21:11:24 +02:00
int Fuse : : flush ( uint64_t fh ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " flush " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( WARN , " flush({}, _) " , fh ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-21 01:11:24 +01:00
try {
2022-06-18 21:11:24 +02:00
_fs - > flush ( fh ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( WARN , " flush({}, _): success " , fh ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-21 01:11:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::flush: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-21 01:11:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( WARN , " flush({}, _): failed with errno {} " , fh , e . getErrno ( ) ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-21 01:11:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-21 01:11:24 +01:00
}
2014-11-15 16:33:24 +01:00
}
2022-06-18 21:11:24 +02:00
int Fuse : : fsync ( int datasync , uint64_t fh ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " fsync " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " fsync({}, {}, _) " , fh , datasync ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
if ( datasync ) {
2022-06-18 21:11:24 +02:00
_fs - > fdatasync ( fh ) ;
2014-11-15 16:33:24 +01:00
} else {
2022-06-18 21:11:24 +02:00
_fs - > fsync ( fh ) ;
2014-11-15 16:33:24 +01:00
}
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " fsync({}, {}, _): success " , fh , datasync ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::fsync: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( WARN , " fsync({}, {}, _): failed with errno {} " , fh , datasync , e . getErrno ( ) ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-18 21:11:24 +02:00
int Fuse : : readdir ( const bf : : path & path , void * buf , fuse_fill_dir_t filler ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " readdir " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " readdir({}, _, _) " , path ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2014-11-19 00:14:35 +01:00
auto entries = _fs - > readDir ( path ) ;
2018-09-16 03:02:03 +02:00
fspp : : fuse : : STAT stbuf { } ;
2019-10-13 17:49:57 +02:00
for ( const auto & entry : entries ) {
2015-04-21 23:19:50 +02:00
//We could pass more file metadata to filler() in its third parameter,
//but it doesn't help performance since fuse ignores everything in stbuf
//except for file-type bits in st_mode and (if used) st_ino.
2014-11-15 16:33:24 +01:00
//It does getattr() calls on all entries nevertheless.
2015-03-11 00:22:36 +01:00
if ( entry . type = = Dir : : EntryType : : DIR ) {
2015-04-21 23:19:50 +02:00
stbuf . st_mode = S_IFDIR ;
2015-04-22 16:00:14 +02:00
} else if ( entry . type = = Dir : : EntryType : : FILE ) {
2015-04-21 23:19:50 +02:00
stbuf . st_mode = S_IFREG ;
2015-04-22 16:00:14 +02:00
} else if ( entry . type = = Dir : : EntryType : : SYMLINK ) {
stbuf . st_mode = S_IFLNK ;
} else {
2015-07-22 13:48:34 +02:00
ASSERT ( false , " Unknown entry type " ) ;
2015-03-11 00:22:36 +01:00
}
2022-06-18 21:11:24 +02:00
if ( filler ( buf , entry . name . c_str ( ) , & stbuf ) ! = 0 ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " readdir({}, _, _): failure with ENOMEM " , path ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return - ENOMEM ;
}
}
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( DEBUG , " readdir({}, _, _): success " , path ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::readdir: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
2022-06-18 21:11:24 +02:00
LOG ( WARN , " readdir({}, _, _): failed with errno {} " , path , e . getErrno ( ) ) ;
2019-05-26 04:25:28 +02:00
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-18 21:11:24 +02:00
void Fuse : : init ( ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " init " ) ;
2022-06-18 21:11:24 +02:00
_fs = _init ( ) ;
2018-12-03 07:57:21 +01:00
2022-06-18 21:11:24 +02:00
_context = Context ( noatime ( ) ) ;
2019-10-13 13:29:59 +02:00
ASSERT ( _context ! = boost : : none , " Context should have been initialized in Fuse::run() but somehow didn't " ) ;
_fs - > setContext ( fspp : : Context { * _context } ) ;
2017-02-04 20:03:20 +01:00
LOG ( INFO , " Filesystem started. " ) ;
2016-02-14 01:18:19 +01:00
2014-11-18 00:14:33 +01:00
_running = true ;
2015-10-17 17:23:35 +02:00
# ifdef FSPP_LOG
cpputils : : logging : : setLevel ( DEBUG ) ;
# endif
2014-11-15 16:33:24 +01:00
}
void Fuse : : destroy ( ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " destroy " ) ;
2018-12-03 07:57:21 +01:00
_fs = make_shared < InvalidFilesystem > ( ) ;
2017-02-04 20:03:20 +01:00
LOG ( INFO , " Filesystem stopped. " ) ;
2016-02-14 01:18:19 +01:00
_running = false ;
2018-12-03 07:57:21 +01:00
cpputils : : logging : : logger ( ) - > flush ( ) ;
2014-11-15 16:33:24 +01:00
}
int Fuse : : access ( const bf : : path & path , int mask ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " access " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " access({}, {}) " , path , mask ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2014-11-19 00:14:35 +01:00
_fs - > access ( path , mask ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " access({}, {}): success " , path , mask ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::access: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " access({}, {}): failed with errno {} " , path , mask , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}
2022-06-18 21:11:24 +02:00
int Fuse : : create ( const bf : : path & path , : : mode_t mode , uint64_t * fh ) {
2019-01-20 12:25:21 +01:00
ThreadNameForDebugging _threadName ( " create " ) ;
2015-09-30 14:13:26 +02:00
# ifdef FSPP_LOG
2017-02-04 20:03:20 +01:00
LOG ( DEBUG , " create({}, {}, _) " , path , mode ) ;
2015-09-30 14:13:26 +02:00
# endif
2014-11-15 16:33:24 +01:00
try {
2018-07-30 09:33:34 +02:00
ASSERT ( is_valid_fspp_path ( path ) , " has to be an absolute path " ) ;
2022-06-18 21:11:24 +02:00
* fh = _fs - > createAndOpenFile ( path , mode , uid , gid ) ;
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( DEBUG , " create({}, {}, _): success " , path , mode ) ;
# endif
2014-11-15 16:33:24 +01:00
return 0 ;
2015-07-22 13:48:34 +02:00
} catch ( const cpputils : : AssertFailed & e ) {
2018-05-17 08:03:03 +02:00
LOG ( ERR , " AssertFailed in Fuse::create: {} " , e . what ( ) ) ;
2015-07-21 19:45:44 +02:00
return - EIO ;
2014-11-15 16:33:24 +01:00
} catch ( FuseErrnoException & e ) {
2019-05-26 04:25:28 +02:00
# ifdef FSPP_LOG
LOG ( WARN , " create({}, {}, _): failed with errno {} " , path , mode , e . getErrno ( ) ) ;
# endif
2014-11-15 16:33:24 +01:00
return - e . getErrno ( ) ;
2015-11-17 07:05:04 +01:00
} catch ( const std : : exception & e ) {
_logException ( e ) ;
return - EIO ;
} catch ( . . . ) {
_logUnknownException ( ) ;
return - EIO ;
2014-11-15 16:33:24 +01:00
}
}