revert
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -19,6 +19,7 @@
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#include "common.hpp"
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "drives/fuse/fuse_base.hpp"
|
||||
@@ -28,6 +29,7 @@
|
||||
#include "events/event_system.hpp"
|
||||
#include "events/events.hpp"
|
||||
#include "providers/i_provider.hpp"
|
||||
#include "utils/file_utils.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
#include "utils/string_utils.hpp"
|
||||
#include "utils/utils.hpp"
|
||||
@@ -99,16 +101,20 @@ fuse_base::fuse_base(app_config &config) : config_(config) {
|
||||
fuse_base::~fuse_base() { E_CONSUMER_RELEASE(); }
|
||||
|
||||
auto fuse_base::access_(const char *path, int mask) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().access_impl(api_path, mask);
|
||||
});
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
auto fuse_base::chflags_(const char *path, uint32_t flags) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().chflags_impl(api_path, flags);
|
||||
});
|
||||
}
|
||||
@@ -117,15 +123,19 @@ auto fuse_base::chflags_(const char *path, uint32_t flags) -> int {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto fuse_base::chmod_(const char *path, mode_t mode, struct fuse_file_info *fi)
|
||||
-> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().chmod_impl(api_path, mode, fi);
|
||||
});
|
||||
}
|
||||
#else
|
||||
auto fuse_base::chmod_(const char *path, mode_t mode) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().chmod_impl(api_path, mode);
|
||||
});
|
||||
}
|
||||
@@ -134,15 +144,19 @@ auto fuse_base::chmod_(const char *path, mode_t mode) -> int {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto fuse_base::chown_(const char *path, uid_t uid, gid_t gid,
|
||||
struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().chown_impl(api_path, uid, gid, fi);
|
||||
});
|
||||
}
|
||||
#else
|
||||
auto fuse_base::chown_(const char *path, uid_t uid, gid_t gid) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().chown_impl(api_path, uid, gid);
|
||||
});
|
||||
}
|
||||
@@ -150,16 +164,22 @@ auto fuse_base::chown_(const char *path, uid_t uid, gid_t gid) -> int {
|
||||
|
||||
auto fuse_base::create_(const char *path, mode_t mode,
|
||||
struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().create_impl(api_path, mode, fi);
|
||||
});
|
||||
}
|
||||
|
||||
void fuse_base::destroy_(void *ptr) {
|
||||
execute_void_callback(__FUNCTION__, [&]() { instance().destroy_impl(ptr); });
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
execute_void_callback(function_name, [&]() { instance().destroy_impl(ptr); });
|
||||
}
|
||||
|
||||
void fuse_base::destroy_impl(void * /* ptr */) { repertory_shutdown(); }
|
||||
|
||||
void fuse_base::display_options(
|
||||
[[maybe_unused]] std::vector<const char *> args) {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
@@ -176,7 +196,7 @@ void fuse_base::display_options(
|
||||
|
||||
void fuse_base::display_version_information(std::vector<const char *> args) {
|
||||
struct fuse_operations fuse_ops {};
|
||||
fuse_main(args.size(),
|
||||
fuse_main(static_cast<int>(args.size()),
|
||||
reinterpret_cast<char **>(const_cast<char **>(args.data())),
|
||||
&fuse_ops, nullptr);
|
||||
}
|
||||
@@ -224,8 +244,10 @@ auto fuse_base::execute_void_pointer_callback(const std::string &function_name,
|
||||
|
||||
auto fuse_base::fallocate_(const char *path, int mode, off_t offset,
|
||||
off_t length, struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().fallocate_impl(api_path, mode, offset, length, fi);
|
||||
});
|
||||
}
|
||||
@@ -233,8 +255,10 @@ auto fuse_base::fallocate_(const char *path, int mode, off_t offset,
|
||||
#if FUSE_USE_VERSION < 30
|
||||
auto fuse_base::fgetattr_(const char *path, struct stat *st,
|
||||
struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().fgetattr_impl(api_path, st, fi);
|
||||
});
|
||||
}
|
||||
@@ -243,8 +267,10 @@ auto fuse_base::fgetattr_(const char *path, struct stat *st,
|
||||
#ifdef __APPLE__
|
||||
auto fuse_base::fsetattr_x_(const char *path, struct setattr_x *attr,
|
||||
struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().fsetattr_x_impl(api_path, attr, fi);
|
||||
});
|
||||
}
|
||||
@@ -252,8 +278,10 @@ auto fuse_base::fsetattr_x_(const char *path, struct setattr_x *attr,
|
||||
|
||||
auto fuse_base::fsync_(const char *path, int datasync,
|
||||
struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().fsync_impl(api_path, datasync, fi);
|
||||
});
|
||||
}
|
||||
@@ -261,8 +289,10 @@ auto fuse_base::fsync_(const char *path, int datasync,
|
||||
#if FUSE_USE_VERSION < 30
|
||||
auto fuse_base::ftruncate_(const char *path, off_t size,
|
||||
struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().ftruncate_impl(api_path, size, fi);
|
||||
});
|
||||
}
|
||||
@@ -271,15 +301,19 @@ auto fuse_base::ftruncate_(const char *path, off_t size,
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto fuse_base::getattr_(const char *path, struct stat *st,
|
||||
struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().getattr_impl(api_path, st, fi);
|
||||
});
|
||||
}
|
||||
#else
|
||||
auto fuse_base::getattr_(const char *path, struct stat *st) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().getattr_impl(api_path, st);
|
||||
});
|
||||
}
|
||||
@@ -288,8 +322,10 @@ auto fuse_base::getattr_(const char *path, struct stat *st) -> int {
|
||||
#ifdef __APPLE__
|
||||
auto fuse_base::getxtimes_(const char *path, struct timespec *bkuptime,
|
||||
struct timespec *crtime) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().getxtimes_impl(api_path, bkuptime, crtime);
|
||||
});
|
||||
}
|
||||
@@ -298,20 +334,27 @@ auto fuse_base::getxtimes_(const char *path, struct timespec *bkuptime,
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto fuse_base::init_(struct fuse_conn_info *conn, struct fuse_config *cfg)
|
||||
-> void * {
|
||||
return execute_void_pointer_callback(__FUNCTION__, [&]() -> void * {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return execute_void_pointer_callback(function_name, [&]() -> void * {
|
||||
return instance().init_impl(conn, cfg);
|
||||
});
|
||||
}
|
||||
#else
|
||||
auto fuse_base::init_(struct fuse_conn_info *conn) -> void * {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return execute_void_pointer_callback(
|
||||
__FUNCTION__, [&]() -> void * { return instance().init_impl(conn); });
|
||||
function_name, [&]() -> void * { return instance().init_impl(conn); });
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto fuse_base::init_impl([[maybe_unused]] struct fuse_conn_info *conn,
|
||||
struct fuse_config *cfg) -> void * {
|
||||
utils::file::change_to_process_directory();
|
||||
repertory_init();
|
||||
|
||||
#ifdef __APPLE__
|
||||
conn->want |= FUSE_CAP_VOL_RENAME;
|
||||
conn->want |= FUSE_CAP_XTIMES;
|
||||
@@ -324,6 +367,9 @@ auto fuse_base::init_impl([[maybe_unused]] struct fuse_conn_info *conn,
|
||||
}
|
||||
#else
|
||||
auto fuse_base::init_impl(struct fuse_conn_info *conn) -> void * {
|
||||
utils::file::change_to_process_directory();
|
||||
repertory_init();
|
||||
|
||||
#ifdef __APPLE__
|
||||
conn->want |= FUSE_CAP_VOL_RENAME;
|
||||
conn->want |= FUSE_CAP_XTIMES;
|
||||
@@ -336,8 +382,10 @@ auto fuse_base::init_impl(struct fuse_conn_info *conn) -> void * {
|
||||
#endif
|
||||
|
||||
auto fuse_base::mkdir_(const char *path, mode_t mode) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().mkdir_impl(api_path, mode);
|
||||
});
|
||||
}
|
||||
@@ -351,8 +399,9 @@ auto fuse_base::mount(std::vector<std::string> args) -> int {
|
||||
}
|
||||
|
||||
{
|
||||
struct fuse_args fa = FUSE_ARGS_INIT(static_cast<int>(fuse_argv.size()),
|
||||
(char **)&fuse_argv[0]);
|
||||
struct fuse_args fa = FUSE_ARGS_INIT(
|
||||
static_cast<int>(fuse_argv.size()),
|
||||
reinterpret_cast<char **>(const_cast<char **>(fuse_argv.data())));
|
||||
|
||||
char *mount_location{nullptr};
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
@@ -374,8 +423,10 @@ auto fuse_base::mount(std::vector<std::string> args) -> int {
|
||||
#if FUSE_USE_VERSION < 30
|
||||
umask(0);
|
||||
#endif
|
||||
ret = fuse_main(static_cast<int>(fuse_argv.size()), (char **)&fuse_argv[0],
|
||||
&fuse_ops_, this);
|
||||
ret = fuse_main(
|
||||
static_cast<int>(fuse_argv.size()),
|
||||
reinterpret_cast<char **>(const_cast<char **>(fuse_argv.data())),
|
||||
&fuse_ops_, this);
|
||||
notify_fuse_main_exit(ret);
|
||||
}
|
||||
|
||||
@@ -383,24 +434,30 @@ auto fuse_base::mount(std::vector<std::string> args) -> int {
|
||||
}
|
||||
|
||||
auto fuse_base::open_(const char *path, struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().open_impl(api_path, fi);
|
||||
});
|
||||
}
|
||||
|
||||
auto fuse_base::opendir_(const char *path, struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().opendir_impl(api_path, fi);
|
||||
});
|
||||
}
|
||||
|
||||
auto fuse_base::read_(const char *path, char *buffer, size_t read_size,
|
||||
off_t read_offset, struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::size_t bytes_read{};
|
||||
const auto res = instance().execute_callback(
|
||||
__FUNCTION__, path,
|
||||
function_name, path,
|
||||
[&](const std::string &api_path) -> api_error {
|
||||
return instance().read_impl(api_path, buffer, read_size, read_offset,
|
||||
fi, bytes_read);
|
||||
@@ -414,8 +471,10 @@ auto fuse_base::readdir_(const char *path, void *buf,
|
||||
fuse_fill_dir_t fuse_fill_dir, off_t offset,
|
||||
struct fuse_file_info *fi, fuse_readdir_flags flags)
|
||||
-> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().readdir_impl(api_path, buf, fuse_fill_dir, offset, fi,
|
||||
flags);
|
||||
});
|
||||
@@ -424,8 +483,10 @@ auto fuse_base::readdir_(const char *path, void *buf,
|
||||
auto fuse_base::readdir_(const char *path, void *buf,
|
||||
fuse_fill_dir_t fuse_fill_dir, off_t offset,
|
||||
struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().readdir_impl(api_path, buf, fuse_fill_dir, offset,
|
||||
fi);
|
||||
});
|
||||
@@ -433,16 +494,20 @@ auto fuse_base::readdir_(const char *path, void *buf,
|
||||
#endif
|
||||
|
||||
auto fuse_base::release_(const char *path, struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().release_impl(api_path, fi);
|
||||
});
|
||||
}
|
||||
|
||||
auto fuse_base::releasedir_(const char *path, struct fuse_file_info *fi)
|
||||
-> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().releasedir_impl(api_path, fi);
|
||||
});
|
||||
}
|
||||
@@ -450,8 +515,10 @@ auto fuse_base::releasedir_(const char *path, struct fuse_file_info *fi)
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto fuse_base::rename_(const char *from, const char *to, unsigned int flags)
|
||||
-> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, from, to,
|
||||
function_name, from, to,
|
||||
[&](const std::string &from_api_file,
|
||||
const std::string &to_api_path) -> api_error {
|
||||
return instance().rename_impl(from_api_file, to_api_path, flags);
|
||||
@@ -459,8 +526,10 @@ auto fuse_base::rename_(const char *from, const char *to, unsigned int flags)
|
||||
}
|
||||
#else
|
||||
auto fuse_base::rename_(const char *from, const char *to) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, from, to,
|
||||
function_name, from, to,
|
||||
[&](const std::string &from_api_file,
|
||||
const std::string &to_api_path) -> api_error {
|
||||
return instance().rename_impl(from_api_file, to_api_path);
|
||||
@@ -469,8 +538,10 @@ auto fuse_base::rename_(const char *from, const char *to) -> int {
|
||||
#endif
|
||||
|
||||
auto fuse_base::rmdir_(const char *path) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().rmdir_impl(api_path);
|
||||
});
|
||||
}
|
||||
@@ -479,9 +550,11 @@ auto fuse_base::rmdir_(const char *path) -> int {
|
||||
#ifdef __APPLE__
|
||||
auto fuse_base::getxattr_(const char *path, const char *name, char *value,
|
||||
size_t size, uint32_t position) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
int attribute_size = 0;
|
||||
const auto res = instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().getxattr_impl(api_path, name, value, size, position,
|
||||
attribute_size);
|
||||
});
|
||||
@@ -491,9 +564,11 @@ auto fuse_base::getxattr_(const char *path, const char *name, char *value,
|
||||
#else // __APPLE__
|
||||
auto fuse_base::getxattr_(const char *path, const char *name, char *value,
|
||||
size_t size) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
int attribute_size = 0;
|
||||
const auto res = instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().getxattr_impl(api_path, name, value, size,
|
||||
attribute_size);
|
||||
});
|
||||
@@ -503,11 +578,13 @@ auto fuse_base::getxattr_(const char *path, const char *name, char *value,
|
||||
#endif // __APPLE__
|
||||
|
||||
auto fuse_base::listxattr_(const char *path, char *buffer, size_t size) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
int required_size = 0;
|
||||
bool return_size = false;
|
||||
|
||||
const auto res = instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().listxattr_impl(api_path, buffer, size, required_size,
|
||||
return_size);
|
||||
});
|
||||
@@ -620,8 +697,10 @@ void fuse_base::raise_fuse_event(std::string function_name,
|
||||
}
|
||||
|
||||
auto fuse_base::removexattr_(const char *path, const char *name) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().removexattr_impl(api_path, name);
|
||||
});
|
||||
}
|
||||
@@ -629,8 +708,10 @@ auto fuse_base::removexattr_(const char *path, const char *name) -> int {
|
||||
#ifdef __APPLE__
|
||||
auto fuse_base::setxattr_(const char *path, const char *name, const char *value,
|
||||
size_t size, int flags, uint32_t position) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
const auto res = instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setxattr_impl(api_path, name, value, size, flags,
|
||||
position);
|
||||
});
|
||||
@@ -643,8 +724,10 @@ auto fuse_base::setxattr_(const char *path, const char *name, const char *value,
|
||||
#else // __APPLE__
|
||||
auto fuse_base::setxattr_(const char *path, const char *name, const char *value,
|
||||
size_t size, int flags) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
const auto res = instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setxattr_impl(api_path, name, value, size, flags);
|
||||
});
|
||||
if (res != 0) {
|
||||
@@ -664,53 +747,67 @@ void fuse_base::shutdown() {
|
||||
|
||||
#ifdef __APPLE__
|
||||
auto fuse_base::setattr_x_(const char *path, struct setattr_x *attr) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setattr_x_impl(api_path, attr);
|
||||
});
|
||||
}
|
||||
|
||||
auto fuse_base::setbkuptime_(const char *path, const struct timespec *bkuptime)
|
||||
-> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setbkuptime_impl(api_path, bkuptime);
|
||||
});
|
||||
}
|
||||
|
||||
auto fuse_base::setchgtime_(const char *path, const struct timespec *chgtime)
|
||||
-> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setchgtime_impl(api_path, chgtime);
|
||||
});
|
||||
}
|
||||
|
||||
auto fuse_base::setcrtime_(const char *path, const struct timespec *crtime)
|
||||
-> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setcrtime_impl(api_path, crtime);
|
||||
});
|
||||
}
|
||||
|
||||
auto fuse_base::setvolname_(const char *volname) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, volname, [&](const std::string &api_path) -> api_error {
|
||||
function_name, volname, [&](const std::string &api_path) -> api_error {
|
||||
return instance().setvolname_impl(volname);
|
||||
});
|
||||
}
|
||||
|
||||
auto fuse_base::statfs_x_(const char *path, struct statfs *stbuf) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().statfs_x_impl(api_path, stbuf);
|
||||
});
|
||||
}
|
||||
#else // __APPLE__
|
||||
auto fuse_base::statfs_(const char *path, struct statvfs *stbuf) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().statfs_impl(api_path, stbuf);
|
||||
});
|
||||
}
|
||||
@@ -719,23 +816,29 @@ auto fuse_base::statfs_(const char *path, struct statvfs *stbuf) -> int {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto fuse_base::truncate_(const char *path, off_t size,
|
||||
struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().truncate_impl(api_path, size, fi);
|
||||
});
|
||||
}
|
||||
#else
|
||||
auto fuse_base::truncate_(const char *path, off_t size) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().truncate_impl(api_path, size);
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
auto fuse_base::unlink_(const char *path) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().unlink_impl(api_path);
|
||||
});
|
||||
}
|
||||
@@ -757,15 +860,19 @@ auto fuse_base::unmount(const std::string &mount_location) -> int {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto fuse_base::utimens_(const char *path, const struct timespec tv[2],
|
||||
struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().utimens_impl(api_path, tv, fi);
|
||||
});
|
||||
}
|
||||
#else
|
||||
auto fuse_base::utimens_(const char *path, const struct timespec tv[2]) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
return instance().execute_callback(
|
||||
__FUNCTION__, path, [&](const std::string &api_path) -> api_error {
|
||||
function_name, path, [&](const std::string &api_path) -> api_error {
|
||||
return instance().utimens_impl(api_path, tv);
|
||||
});
|
||||
}
|
||||
@@ -773,10 +880,12 @@ auto fuse_base::utimens_(const char *path, const struct timespec tv[2]) -> int {
|
||||
|
||||
auto fuse_base::write_(const char *path, const char *buffer, size_t write_size,
|
||||
off_t write_offset, struct fuse_file_info *fi) -> int {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::size_t bytes_written{};
|
||||
|
||||
const auto res = instance().execute_callback(
|
||||
__FUNCTION__, path,
|
||||
function_name, path,
|
||||
[&](const std::string &api_path) -> api_error {
|
||||
return instance().write_impl(api_path, buffer, write_size, write_offset,
|
||||
fi, bytes_written);
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -204,7 +204,9 @@ auto fuse_drive::create_impl(std::string api_path, mode_t mode,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
void fuse_drive::destroy_impl(void * /* ptr */) {
|
||||
void fuse_drive::destroy_impl(void *ptr) {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
event_system::instance().raise<drive_unmount_pending>(get_mount_location());
|
||||
|
||||
remote_server_.reset();
|
||||
@@ -240,8 +242,10 @@ void fuse_drive::destroy_impl(void * /* ptr */) {
|
||||
config_.save();
|
||||
|
||||
if (not lock_data_.set_mount_state(false, "", -1)) {
|
||||
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
|
||||
utils::error::raise_error(function_name, "failed to set mount state");
|
||||
}
|
||||
|
||||
fuse_base::destroy_impl(ptr);
|
||||
}
|
||||
|
||||
auto fuse_drive::fallocate_impl(std::string /*api_path*/, int mode,
|
||||
@@ -387,10 +391,12 @@ auto fuse_drive::get_directory_item_count(const std::string &api_path) const
|
||||
|
||||
auto fuse_drive::get_directory_items(const std::string &api_path) const
|
||||
-> directory_item_list {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
directory_item_list list{};
|
||||
auto res = provider_.get_directory_items(api_path, list);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to get directory items");
|
||||
}
|
||||
|
||||
@@ -399,10 +405,12 @@ auto fuse_drive::get_directory_items(const std::string &api_path) const
|
||||
|
||||
auto fuse_drive::get_file_size(const std::string &api_path) const
|
||||
-> std::uint64_t {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::uint64_t file_size{};
|
||||
auto res = provider_.get_file_size(api_path, file_size);
|
||||
if (res == api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to get file size from provider");
|
||||
}
|
||||
|
||||
@@ -519,7 +527,13 @@ auto fuse_drive::init_impl(struct fuse_conn_info *conn, struct fuse_config *cfg)
|
||||
#else
|
||||
void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
|
||||
#endif
|
||||
utils::file::change_to_process_directory();
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto *ret = fuse_drive_base::init_impl(conn, cfg);
|
||||
#else
|
||||
auto *ret = fuse_drive_base::init_impl(conn);
|
||||
#endif
|
||||
|
||||
if (console_enabled_) {
|
||||
console_consumer_ = std::make_unique<console_consumer>();
|
||||
@@ -562,22 +576,18 @@ void *fuse_drive::init_impl(struct fuse_conn_info *conn) {
|
||||
}
|
||||
|
||||
if (not lock_data_.set_mount_state(true, get_mount_location(), getpid())) {
|
||||
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
|
||||
utils::error::raise_error(function_name, "failed to set mount state");
|
||||
}
|
||||
event_system::instance().raise<drive_mounted>(get_mount_location());
|
||||
} catch (const std::exception &e) {
|
||||
utils::error::raise_error(__FUNCTION__, e, "exception during fuse init");
|
||||
utils::error::raise_error(function_name, e, "exception during fuse init");
|
||||
|
||||
destroy_impl(this);
|
||||
|
||||
fuse_exit(fuse_get_context()->fuse);
|
||||
}
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
return fuse_drive_base::init_impl(conn, cfg);
|
||||
#else
|
||||
return fuse_drive_base::init_impl(conn);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto fuse_drive::is_processing(const std::string &api_path) const -> bool {
|
||||
@@ -585,6 +595,8 @@ auto fuse_drive::is_processing(const std::string &api_path) const -> bool {
|
||||
}
|
||||
|
||||
auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
auto res = check_parent_access(api_path, W_OK | X_OK);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
@@ -594,17 +606,18 @@ auto fuse_drive::mkdir_impl(std::string api_path, mode_t mode) -> api_error {
|
||||
auto meta = create_meta_attributes(now, FILE_ATTRIBUTE_DIRECTORY, now, now,
|
||||
true, get_effective_gid(), "", mode, now,
|
||||
0U, 0U, 0U, "", get_effective_uid(), now);
|
||||
if ((res = provider_.create_directory(api_path, meta)) !=
|
||||
api_error::success) {
|
||||
res = provider_.create_directory(api_path, meta);
|
||||
if (res != api_error::success) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (api_path != "/") {
|
||||
if ((res = provider_.set_item_meta(
|
||||
utils::path::get_parent_api_path(api_path), META_MODIFIED,
|
||||
std::to_string(now))) != api_error::success) {
|
||||
res = provider_.set_item_meta(utils::path::get_parent_api_path(api_path),
|
||||
META_MODIFIED, std::to_string(now));
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(
|
||||
__FUNCTION__, api_path, res, "failed to set directory modified time");
|
||||
function_name, api_path, res,
|
||||
"failed to set directory modified time");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,13 +674,6 @@ auto fuse_drive::opendir_impl(std::string api_path,
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
void fuse_drive::populate_stat(const directory_item &dir_item,
|
||||
struct stat &st) const {
|
||||
fuse_drive_base::populate_stat(dir_item.api_path, dir_item.size,
|
||||
dir_item.meta, dir_item.directory, provider_,
|
||||
&st);
|
||||
}
|
||||
|
||||
auto fuse_drive::read_impl(std::string api_path, char *buffer, size_t read_size,
|
||||
off_t read_offset, struct fuse_file_info *file_info,
|
||||
std::size_t &bytes_read) -> api_error {
|
||||
@@ -910,8 +916,8 @@ auto fuse_drive::listxattr_impl(std::string api_path, char *buffer, size_t size,
|
||||
#endif
|
||||
const auto attribute_name_size = strlen(attribute_name.c_str()) + 1U;
|
||||
if (size >= attribute_name_size) {
|
||||
strncpy(&buffer[required_size], attribute_name.c_str(),
|
||||
attribute_name_size);
|
||||
std::memcpy(&buffer[required_size], attribute_name.data(),
|
||||
attribute_name_size);
|
||||
size -= attribute_name_size;
|
||||
} else {
|
||||
res = api_error::xattr_buffer_small;
|
||||
@@ -1024,9 +1030,11 @@ auto fuse_drive::setxattr_impl(std::string api_path, const char *name,
|
||||
void fuse_drive::set_item_meta(const std::string &api_path,
|
||||
const std::string &key,
|
||||
const std::string &value) {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
auto res = provider_.set_item_meta(api_path, key, value);
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"key|" + key + "|value|" + value);
|
||||
}
|
||||
}
|
||||
@@ -1187,10 +1195,11 @@ auto fuse_drive::statfs_x_impl(std::string /*api_path*/, struct statfs *stbuf)
|
||||
stbuf->f_files = 4294967295;
|
||||
stbuf->f_ffree = stbuf->f_files - provider_.get_total_item_count();
|
||||
stbuf->f_owner = getuid();
|
||||
strncpy(&stbuf->f_mntonname[0], get_mount_location().c_str(), MNAMELEN);
|
||||
strncpy(&stbuf->f_mntfromname[0],
|
||||
strncpy(&stbuf->f_mntonname[0U], get_mount_location().c_str(),
|
||||
get_mount_location().size());
|
||||
strncpy(&stbuf->f_mntfromname[0U],
|
||||
(utils::create_volume_label(config_.get_provider_type())).c_str(),
|
||||
MNAMELEN);
|
||||
sizeof(stbuf->f_mntfromname) - 1U);
|
||||
|
||||
return api_error::success;
|
||||
}
|
||||
@@ -1203,11 +1212,10 @@ auto fuse_drive::statfs_impl(std::string /*api_path*/, struct statvfs *stbuf)
|
||||
|
||||
const auto total_bytes = provider_.get_total_drive_space();
|
||||
const auto total_used = provider_.get_used_drive_space();
|
||||
const auto used_blocks = utils::divide_with_ceiling(
|
||||
total_used, static_cast<std::uint64_t>(stbuf->f_frsize));
|
||||
const auto used_blocks =
|
||||
utils::divide_with_ceiling(total_used, stbuf->f_frsize);
|
||||
stbuf->f_files = 4294967295;
|
||||
stbuf->f_blocks = utils::divide_with_ceiling(
|
||||
total_bytes, static_cast<std::uint64_t>(stbuf->f_frsize));
|
||||
stbuf->f_blocks = utils::divide_with_ceiling(total_bytes, stbuf->f_frsize);
|
||||
stbuf->f_bavail = stbuf->f_bfree =
|
||||
stbuf->f_blocks == 0U ? 0 : (stbuf->f_blocks - used_blocks);
|
||||
stbuf->f_ffree = stbuf->f_favail =
|
||||
@@ -1345,11 +1353,13 @@ auto fuse_drive::write_impl(std::string /*api_path*/
|
||||
}
|
||||
|
||||
void fuse_drive::update_accessed_time(const std::string &api_path) {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
if (atime_enabled_) {
|
||||
auto res = provider_.set_item_meta(
|
||||
api_path, META_ACCESSED, std::to_string(utils::get_file_time_now()));
|
||||
if (res != api_error::success) {
|
||||
utils::error::raise_api_path_error(__FUNCTION__, api_path, res,
|
||||
utils::error::raise_api_path_error(function_name, api_path, res,
|
||||
"failed to set accessed time");
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -232,9 +232,9 @@ auto fuse_drive_base::get_mode_from_meta(const api_meta_map &meta) -> mode_t {
|
||||
void fuse_drive_base::get_timespec_from_meta(const api_meta_map &meta,
|
||||
const std::string &name,
|
||||
struct timespec &ts) {
|
||||
const auto t = utils::string::to_uint64(meta.at(name));
|
||||
ts.tv_nsec = t % NANOS_PER_SECOND;
|
||||
ts.tv_sec = t / NANOS_PER_SECOND;
|
||||
const auto meta_time = utils::string::to_int64(meta.at(name));
|
||||
ts.tv_nsec = meta_time % NANOS_PER_SECOND;
|
||||
ts.tv_sec = meta_time / NANOS_PER_SECOND;
|
||||
}
|
||||
|
||||
auto fuse_drive_base::get_uid_from_meta(const api_meta_map &meta) -> uid_t {
|
||||
@@ -304,22 +304,23 @@ void fuse_drive_base::populate_stat(const std::string &api_path,
|
||||
const api_meta_map &meta, bool directory,
|
||||
i_provider &provider, struct stat *st) {
|
||||
memset(st, 0, sizeof(struct stat));
|
||||
st->st_nlink =
|
||||
(directory
|
||||
? 2 + (size_or_count ? size_or_count
|
||||
: provider.get_directory_item_count(api_path))
|
||||
: 1);
|
||||
st->st_nlink = static_cast<nlink_t>(
|
||||
directory ? 2 + (size_or_count == 0U
|
||||
? provider.get_directory_item_count(api_path)
|
||||
: size_or_count)
|
||||
: 1);
|
||||
if (directory) {
|
||||
st->st_blocks = 0;
|
||||
} else {
|
||||
st->st_size = size_or_count;
|
||||
static const auto block_size_stat = static_cast<std::uint64_t>(512u);
|
||||
static const auto block_size = static_cast<std::uint64_t>(4096u);
|
||||
st->st_size = static_cast<off_t>(size_or_count);
|
||||
static const auto block_size_stat = static_cast<std::uint64_t>(512U);
|
||||
static const auto block_size = static_cast<std::uint64_t>(4096U);
|
||||
const auto size = utils::divide_with_ceiling(
|
||||
static_cast<std::uint64_t>(st->st_size), block_size) *
|
||||
block_size;
|
||||
st->st_blocks = std::max(block_size / block_size_stat,
|
||||
utils::divide_with_ceiling(size, block_size_stat));
|
||||
st->st_blocks = static_cast<blkcnt_t>(
|
||||
std::max(block_size / block_size_stat,
|
||||
utils::divide_with_ceiling(size, block_size_stat)));
|
||||
}
|
||||
st->st_gid = get_gid_from_meta(meta);
|
||||
st->st_mode = (directory ? S_IFDIR : S_IFREG) | get_mode_from_meta(meta);
|
||||
@@ -344,9 +345,9 @@ void fuse_drive_base::populate_stat(const std::string &api_path,
|
||||
void fuse_drive_base::set_timespec_from_meta(const api_meta_map &meta,
|
||||
const std::string &name,
|
||||
struct timespec &ts) {
|
||||
const auto t = utils::string::to_uint64(meta.at(name));
|
||||
ts.tv_nsec = t % NANOS_PER_SECOND;
|
||||
ts.tv_sec = t / NANOS_PER_SECOND;
|
||||
const auto meta_time = utils::string::to_int64(meta.at(name));
|
||||
ts.tv_nsec = meta_time % NANOS_PER_SECOND;
|
||||
ts.tv_sec = meta_time / NANOS_PER_SECOND;
|
||||
}
|
||||
} // namespace repertory
|
||||
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -36,49 +36,59 @@ remote_client::remote_client(const app_config &config)
|
||||
|
||||
auto remote_client::fuse_access(const char *path, const std::int32_t &mask)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(mask);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_chflags(const char *path, std::uint32_t flags)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(flags);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_chmod(const char *path, const remote::file_mode &mode)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(mode);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(uid);
|
||||
request.encode(gid);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_destroy() -> packet::error_type {
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, service_flags);
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, service_flags);
|
||||
}
|
||||
|
||||
/*packet::error_type remote_client::fuse_fallocate(const char *path, const
|
||||
@@ -90,14 +100,16 @@ std::int32_t &mode, const remote::file_offset &offset, const remote::file_offset
|
||||
request.encode(length);
|
||||
request.encode(handle);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packetClient_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags {};
|
||||
return packetClient_.send(function_name, request, service_flags);
|
||||
}*/
|
||||
|
||||
auto remote_client::fuse_fgetattr(const char *path, remote::stat &st,
|
||||
bool &directory,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(handle);
|
||||
@@ -105,12 +117,12 @@ auto remote_client::fuse_fgetattr(const char *path, remote::stat &st,
|
||||
request.encode(gid_);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
if ((ret = response.decode(st)) == 0) {
|
||||
std::uint8_t d = 0u;
|
||||
std::uint8_t d{};
|
||||
if ((ret = response.decode(d)) == 0) {
|
||||
directory = static_cast<bool>(d);
|
||||
}
|
||||
@@ -124,51 +136,59 @@ auto remote_client::fuse_fsetattr_x(const char *path,
|
||||
const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(attr);
|
||||
request.encode(handle);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(datasync);
|
||||
request.encode(handle);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_ftruncate(const char *path,
|
||||
const remote::file_offset &size,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(size);
|
||||
request.encode(handle);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_getattr(const char *path, remote::stat &st,
|
||||
bool &directory) -> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(uid_);
|
||||
request.encode(gid_);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
if ((ret = response.decode(st)) == 0) {
|
||||
std::uint8_t d = 0;
|
||||
@@ -188,8 +208,8 @@ packet request; request.encode(path); request.encode(name);
|
||||
request.encode(size);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
if ((ret = packetClient_.send(__FUNCTION__, request, response,
|
||||
std::uint32_t service_flags {};
|
||||
if ((ret = packetClient_.send(function_name, request, response,
|
||||
service_flags)) == 0) { remote::file_size size2; if ((ret =
|
||||
response.decode(size2)) == 0) { if (size2 >
|
||||
std::numeric_limits<std::size_t>::max()) { ret = -ERANGE; } else { memcpy(value,
|
||||
@@ -211,8 +231,8 @@ packet::error_type ret = 0; if (size > std::numeric_limits<std::size_t>::max())
|
||||
request.encode(position);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
if ((ret = packetClient_.send(__FUNCTION__, request, response,
|
||||
std::uint32_t service_flags {};
|
||||
if ((ret = packetClient_.send(function_name, request, response,
|
||||
service_flags)) == 0) { remote::file_size size2; if ((ret =
|
||||
response.decode(size2)) == 0) { if (size2 >
|
||||
std::numeric_limits<std::size_t>::max()) { ret = -ERANGE; } else { memcpy(value,
|
||||
@@ -229,13 +249,15 @@ auto remote_client::fuse_getxtimes(const char *path,
|
||||
remote::file_time &bkuptime,
|
||||
remote::file_time &crtime)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
DECODE_OR_RETURN(&response, bkuptime);
|
||||
DECODE_OR_RETURN(&response, crtime);
|
||||
@@ -245,8 +267,10 @@ auto remote_client::fuse_getxtimes(const char *path,
|
||||
}
|
||||
|
||||
auto remote_client::fuse_init() -> packet::error_type {
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, service_flags);
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, service_flags);
|
||||
}
|
||||
|
||||
/*packet::error_type remote_client::fuse_listxattr(const char *path, char
|
||||
@@ -255,8 +279,8 @@ std::numeric_limits<std::size_t>::max()) { ret = -ERANGE; } else { packet
|
||||
request; request.encode(path); request.encode(size);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
if ((ret = packetClient_.send(__FUNCTION__, request, response,
|
||||
std::uint32_t service_flags {};
|
||||
if ((ret = packetClient_.send(function_name, request, response,
|
||||
service_flags)) == 0) { remote::file_size size2; if ((ret =
|
||||
response.decode(size2)) == 0) { if (size2 >
|
||||
std::numeric_limits<std::size_t>::max()) { ret = -ERANGE; } else {
|
||||
@@ -272,23 +296,27 @@ static_cast<std::size_t>(size2));
|
||||
|
||||
auto remote_client::fuse_mkdir(const char *path, const remote::file_mode &mode)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(mode);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_opendir(const char *path, remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
ret = response.decode(handle);
|
||||
}
|
||||
@@ -300,15 +328,17 @@ auto remote_client::fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags,
|
||||
remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(mode);
|
||||
request.encode(flags);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
ret = response.decode(handle);
|
||||
}
|
||||
@@ -319,14 +349,16 @@ auto remote_client::fuse_create(const char *path, const remote::file_mode &mode,
|
||||
auto remote_client::fuse_open(const char *path, const remote::open_flags &flags,
|
||||
remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(flags);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
ret = response.decode(handle);
|
||||
}
|
||||
@@ -339,6 +371,8 @@ auto remote_client::fuse_read(const char *path, char *buffer,
|
||||
const remote::file_offset &read_offset,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(read_size);
|
||||
@@ -346,11 +380,11 @@ auto remote_client::fuse_read(const char *path, char *buffer,
|
||||
request.encode(handle);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret > 0) {
|
||||
memcpy(buffer, response.current_pointer(), ret);
|
||||
memcpy(buffer, response.current_pointer(), static_cast<std::size_t>(ret));
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -358,12 +392,14 @@ auto remote_client::fuse_read(const char *path, char *buffer,
|
||||
|
||||
auto remote_client::fuse_rename(const char *from, const char *to)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(from);
|
||||
request.encode(to);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_write(const char *path, const char *buffer,
|
||||
@@ -371,6 +407,8 @@ auto remote_client::fuse_write(const char *path, const char *buffer,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
if (write_size > std::numeric_limits<std::size_t>::max()) {
|
||||
return -ERANGE;
|
||||
}
|
||||
@@ -382,8 +420,8 @@ auto remote_client::fuse_write(const char *path, const char *buffer,
|
||||
request.encode(write_offset);
|
||||
request.encode(handle);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_write_base64(const char *path, const char *buffer,
|
||||
@@ -391,6 +429,8 @@ auto remote_client::fuse_write_base64(const char *path, const char *buffer,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
if (write_size > std::numeric_limits<std::size_t>::max()) {
|
||||
return -ERANGE;
|
||||
}
|
||||
@@ -402,23 +442,25 @@ auto remote_client::fuse_write_base64(const char *path, const char *buffer,
|
||||
request.encode(write_offset);
|
||||
request.encode(handle);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_readdir(const char *path,
|
||||
const remote::file_offset &offset,
|
||||
const remote::file_handle &handle,
|
||||
std::string &item_path) -> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(offset);
|
||||
request.encode(handle);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
DECODE_OR_IGNORE(&response, item_path);
|
||||
}
|
||||
@@ -429,90 +471,106 @@ auto remote_client::fuse_readdir(const char *path,
|
||||
auto remote_client::fuse_release(const char *path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(handle);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_releasedir(const char *path,
|
||||
const remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(handle);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
/*packet::error_type remote_client::fuse_removexattr(const char *path, const
|
||||
char *name) override { packet request; request.encode(path);
|
||||
request.Encode(name);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packetClient_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags {};
|
||||
return packetClient_.send(function_name, request, service_flags);
|
||||
}*/
|
||||
|
||||
auto remote_client::fuse_rmdir(const char *path) -> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_setattr_x(const char *path, remote::setattr_x &attr)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(attr);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_setbkuptime(const char *path,
|
||||
const remote::file_time &bkuptime)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(bkuptime);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_setchgtime(const char *path,
|
||||
const remote::file_time &chgtime)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(chgtime);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_setcrtime(const char *path,
|
||||
const remote::file_time &crtime)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(crtime);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_setvolname(const char *volname) -> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(volname);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
/*packet::error_type remote_client::fuse_setxattr(const char *path, const char
|
||||
@@ -523,8 +581,8 @@ request; request.encode(path); request.encode(name); request.encode(size);
|
||||
request.encode(value, static_cast<std::size_t>(size));
|
||||
request.encode(flags);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
ret = packetClient_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags {};
|
||||
ret = packetClient_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -538,8 +596,8 @@ packet request; request.encode(path); request.Encode(name);
|
||||
request.Encode(size); request.encode(value, static_cast<std::size_t>(size));
|
||||
request.encode(flags); request.encode(position);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
ret = packetClient_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags {};
|
||||
ret = packetClient_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -547,14 +605,16 @@ request.encode(flags); request.encode(position);
|
||||
|
||||
auto remote_client::fuse_statfs(const char *path, std::uint64_t frsize,
|
||||
remote::statfs &st) -> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(frsize);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
ret = response.decode(st);
|
||||
}
|
||||
@@ -564,14 +624,16 @@ auto remote_client::fuse_statfs(const char *path, std::uint64_t frsize,
|
||||
|
||||
auto remote_client::fuse_statfs_x(const char *path, std::uint64_t bsize,
|
||||
remote::statfs_x &st) -> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(bsize);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
ret = response.decode(st);
|
||||
}
|
||||
@@ -582,45 +644,53 @@ auto remote_client::fuse_statfs_x(const char *path, std::uint64_t bsize,
|
||||
auto remote_client::fuse_truncate(const char *path,
|
||||
const remote::file_offset &size)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(size);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_unlink(const char *path) -> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
std::uint64_t op0, std::uint64_t op1)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(&tv[0], sizeof(remote::file_time) * 2);
|
||||
request.encode(op0);
|
||||
request.encode(op1);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
auto remote_client::json_create_directory_snapshot(const std::string &path,
|
||||
json &json_data)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
ret = packet::decode_json(response, json_data);
|
||||
}
|
||||
@@ -631,15 +701,17 @@ auto remote_client::json_create_directory_snapshot(const std::string &path,
|
||||
auto remote_client::json_read_directory_snapshot(
|
||||
const std::string &path, const remote::file_handle &handle,
|
||||
std::uint32_t page, json &json_data) -> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(handle);
|
||||
request.encode(page);
|
||||
|
||||
packet response;
|
||||
std::uint32_t service_flags = 0u;
|
||||
std::uint32_t service_flags{};
|
||||
auto ret =
|
||||
packet_client_.send(__FUNCTION__, request, response, service_flags);
|
||||
packet_client_.send(function_name, request, response, service_flags);
|
||||
if (ret == 0) {
|
||||
ret = packet::decode_json(response, json_data);
|
||||
}
|
||||
@@ -650,12 +722,14 @@ auto remote_client::json_read_directory_snapshot(
|
||||
auto remote_client::json_release_directory_snapshot(
|
||||
const std::string &path, const remote::file_handle &handle)
|
||||
-> packet::error_type {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
packet request;
|
||||
request.encode(path);
|
||||
request.encode(handle);
|
||||
|
||||
std::uint32_t service_flags = 0u;
|
||||
return packet_client_.send(__FUNCTION__, request, service_flags);
|
||||
std::uint32_t service_flags{};
|
||||
return packet_client_.send(function_name, request, service_flags);
|
||||
}
|
||||
|
||||
void remote_client::set_fuse_uid_gid(const remote::user_id &uid,
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright <2018-2023> <scott.e.graves@protonmail.com>
|
||||
Copyright <2018-2024> <scott.e.graves@protonmail.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -54,7 +54,7 @@ api_error remote_fuse_drive::chflags_impl(std::string api_path,
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
struct fuse_file_info * /*f_info*/)
|
||||
-> api_error {
|
||||
#else
|
||||
auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode)
|
||||
@@ -66,7 +66,7 @@ auto remote_fuse_drive::chmod_impl(std::string api_path, mode_t mode)
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto remote_fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
struct fuse_file_info * /*f_info*/)
|
||||
-> api_error {
|
||||
#else
|
||||
auto remote_fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid)
|
||||
@@ -77,14 +77,17 @@ auto remote_fuse_drive::chown_impl(std::string api_path, uid_t uid, gid_t gid)
|
||||
}
|
||||
|
||||
auto remote_fuse_drive::create_impl(std::string api_path, mode_t mode,
|
||||
struct fuse_file_info *fi) -> api_error {
|
||||
struct fuse_file_info *f_info)
|
||||
-> api_error {
|
||||
return utils::to_api_error(remote_instance_->fuse_create(
|
||||
api_path.c_str(), static_cast<remote::file_mode>(mode),
|
||||
remote::create_open_flags(static_cast<std::uint32_t>(fi->flags)),
|
||||
fi->fh));
|
||||
remote::create_open_flags(static_cast<std::uint32_t>(f_info->flags)),
|
||||
f_info->fh));
|
||||
}
|
||||
|
||||
void remote_fuse_drive::destroy_impl(void * /*ptr*/) {
|
||||
void remote_fuse_drive::destroy_impl(void *ptr) {
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
event_system::instance().raise<drive_unmount_pending>(get_mount_location());
|
||||
|
||||
if (server_) {
|
||||
@@ -95,7 +98,7 @@ void remote_fuse_drive::destroy_impl(void * /*ptr*/) {
|
||||
if (remote_instance_) {
|
||||
const auto res = remote_instance_->fuse_destroy();
|
||||
if (res != 0) {
|
||||
utils::error::raise_error(__FUNCTION__,
|
||||
utils::error::raise_error(function_name,
|
||||
"remote fuse_destroy() failed|err|" +
|
||||
std::to_string(res));
|
||||
}
|
||||
@@ -103,21 +106,25 @@ void remote_fuse_drive::destroy_impl(void * /*ptr*/) {
|
||||
}
|
||||
|
||||
if (not lock_data_.set_mount_state(false, "", -1)) {
|
||||
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
|
||||
utils::error::raise_error(function_name, "failed to set mount state");
|
||||
}
|
||||
|
||||
event_system::instance().raise<drive_unmounted>(get_mount_location());
|
||||
|
||||
fuse_base::destroy_impl(ptr);
|
||||
}
|
||||
|
||||
auto remote_fuse_drive::fgetattr_impl(std::string api_path, struct stat *st,
|
||||
struct fuse_file_info *fi) -> api_error {
|
||||
remote::stat r{};
|
||||
auto remote_fuse_drive::fgetattr_impl(std::string api_path,
|
||||
struct stat *unix_st,
|
||||
struct fuse_file_info *f_info)
|
||||
-> api_error {
|
||||
remote::stat r_stat{};
|
||||
auto directory = false;
|
||||
|
||||
const auto res =
|
||||
remote_instance_->fuse_fgetattr(api_path.c_str(), r, directory, fi->fh);
|
||||
const auto res = remote_instance_->fuse_fgetattr(api_path.c_str(), r_stat,
|
||||
directory, f_info->fh);
|
||||
if (res == 0) {
|
||||
populate_stat(r, directory, *st);
|
||||
populate_stat(r_stat, directory, *unix_st);
|
||||
}
|
||||
|
||||
return utils::to_api_error(res);
|
||||
@@ -126,7 +133,7 @@ auto remote_fuse_drive::fgetattr_impl(std::string api_path, struct stat *st,
|
||||
#ifdef __APPLE__
|
||||
api_error remote_fuse_drive::fsetattr_x_impl(std::string api_path,
|
||||
struct setattr_x *attr,
|
||||
struct fuse_file_info *fi) {
|
||||
struct fuse_file_info *f_info) {
|
||||
remote::setattr_x attributes{};
|
||||
attributes.valid = attr->valid;
|
||||
attributes.mode = attr->mode;
|
||||
@@ -144,41 +151,42 @@ api_error remote_fuse_drive::fsetattr_x_impl(std::string api_path,
|
||||
attributes.bkuptime =
|
||||
((attr->bkuptime.tv_sec * NANOS_PER_SECOND) + attr->bkuptime.tv_nsec);
|
||||
attributes.flags = attr->flags;
|
||||
return utils::to_api_error(
|
||||
remote_instance_->fuse_fsetattr_x(api_path.c_str(), attributes, fi->fh));
|
||||
return utils::to_api_error(remote_instance_->fuse_fsetattr_x(
|
||||
api_path.c_str(), attributes, f_info->fh));
|
||||
}
|
||||
#endif
|
||||
|
||||
auto remote_fuse_drive::fsync_impl(std::string api_path, int datasync,
|
||||
struct fuse_file_info *fi) -> api_error {
|
||||
struct fuse_file_info *f_info) -> api_error {
|
||||
|
||||
return utils::to_api_error(
|
||||
remote_instance_->fuse_fsync(api_path.c_str(), datasync, fi->fh));
|
||||
remote_instance_->fuse_fsync(api_path.c_str(), datasync, f_info->fh));
|
||||
}
|
||||
|
||||
#if FUSE_USE_VERSION < 30
|
||||
auto remote_fuse_drive::ftruncate_impl(std::string api_path, off_t size,
|
||||
struct fuse_file_info *fi) -> api_error {
|
||||
struct fuse_file_info *f_info)
|
||||
-> api_error {
|
||||
return utils::to_api_error(
|
||||
remote_instance_->fuse_ftruncate(api_path.c_str(), size, fi->fh));
|
||||
remote_instance_->fuse_ftruncate(api_path.c_str(), size, f_info->fh));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto remote_fuse_drive::getattr_impl(std::string api_path, struct stat *st,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
auto remote_fuse_drive::getattr_impl(std::string api_path, struct stat *unix_st,
|
||||
struct fuse_file_info * /*f_info*/)
|
||||
-> api_error {
|
||||
#else
|
||||
auto remote_fuse_drive::getattr_impl(std::string api_path, struct stat *st)
|
||||
auto remote_fuse_drive::getattr_impl(std::string api_path, struct stat *unix_st)
|
||||
-> api_error {
|
||||
#endif
|
||||
bool directory = false;
|
||||
remote::stat r{};
|
||||
remote::stat r_stat{};
|
||||
|
||||
const auto res =
|
||||
remote_instance_->fuse_getattr(api_path.c_str(), r, directory);
|
||||
remote_instance_->fuse_getattr(api_path.c_str(), r_stat, directory);
|
||||
if (res == 0) {
|
||||
populate_stat(r, directory, *st);
|
||||
populate_stat(r_stat, directory, *unix_st);
|
||||
}
|
||||
|
||||
return utils::to_api_error(res);
|
||||
@@ -214,7 +222,14 @@ auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn,
|
||||
#else
|
||||
auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn) -> void * {
|
||||
#endif
|
||||
utils::file::change_to_process_directory();
|
||||
constexpr const auto *function_name = static_cast<const char *>(__FUNCTION__);
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto *ret = fuse_base::init_impl(conn, cfg);
|
||||
#else
|
||||
auto *ret = fuse_base::init_impl(conn);
|
||||
#endif
|
||||
|
||||
was_mounted_ = true;
|
||||
|
||||
if (console_enabled_) {
|
||||
@@ -225,14 +240,14 @@ auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn) -> void * {
|
||||
event_system::instance().start();
|
||||
|
||||
if (not lock_data_.set_mount_state(true, get_mount_location(), getpid())) {
|
||||
utils::error::raise_error(__FUNCTION__, "failed to set mount state");
|
||||
utils::error::raise_error(function_name, "failed to set mount state");
|
||||
}
|
||||
|
||||
remote_instance_ = factory_();
|
||||
remote_instance_->set_fuse_uid_gid(getuid(), getgid());
|
||||
|
||||
if (remote_instance_->fuse_init() != 0) {
|
||||
utils::error::raise_error(__FUNCTION__,
|
||||
utils::error::raise_error(function_name,
|
||||
"failed to connect to remote server");
|
||||
event_system::instance().raise<unmount_requested>();
|
||||
} else {
|
||||
@@ -241,11 +256,7 @@ auto remote_fuse_drive::init_impl(struct fuse_conn_info *conn) -> void * {
|
||||
event_system::instance().raise<drive_mounted>(get_mount_location());
|
||||
}
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
return fuse_base::init_impl(conn, cfg);
|
||||
#else
|
||||
return fuse_base::init_impl(conn);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
auto remote_fuse_drive::mkdir_impl(std::string api_path, mode_t mode)
|
||||
@@ -264,76 +275,88 @@ void remote_fuse_drive::notify_fuse_main_exit(int &ret) {
|
||||
}
|
||||
|
||||
auto remote_fuse_drive::open_impl(std::string api_path,
|
||||
struct fuse_file_info *fi) -> api_error {
|
||||
struct fuse_file_info *f_info) -> api_error {
|
||||
return utils::to_api_error(remote_instance_->fuse_open(
|
||||
api_path.c_str(), remote::create_open_flags(fi->flags), fi->fh));
|
||||
api_path.c_str(),
|
||||
remote::create_open_flags(static_cast<std::uint32_t>(f_info->flags)),
|
||||
f_info->fh));
|
||||
}
|
||||
|
||||
auto remote_fuse_drive::opendir_impl(std::string api_path,
|
||||
struct fuse_file_info *fi) -> api_error {
|
||||
struct fuse_file_info *f_info)
|
||||
-> api_error {
|
||||
|
||||
return utils::to_api_error(
|
||||
remote_instance_->fuse_opendir(api_path.c_str(), fi->fh));
|
||||
remote_instance_->fuse_opendir(api_path.c_str(), f_info->fh));
|
||||
}
|
||||
|
||||
void remote_fuse_drive::populate_stat(const remote::stat &r, bool directory,
|
||||
struct stat &st) {
|
||||
memset(&st, 0, sizeof(struct stat));
|
||||
void remote_fuse_drive::populate_stat(const remote::stat &r_stat,
|
||||
bool directory, struct stat &unix_st) {
|
||||
memset(&unix_st, 0, sizeof(struct stat));
|
||||
|
||||
#ifdef __APPLE__
|
||||
st.st_blksize = 0;
|
||||
unix_st.st_blksize = 0;
|
||||
|
||||
st.st_atimespec.tv_nsec = r.st_atimespec % NANOS_PER_SECOND;
|
||||
st.st_atimespec.tv_sec = r.st_atimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_atimespec.tv_nsec = r_stat.st_atimespec % NANOS_PER_SECOND;
|
||||
unix_st.st_atimespec.tv_sec = r_stat.st_atimespec / NANOS_PER_SECOND;
|
||||
|
||||
st.st_birthtimespec.tv_nsec = r.st_birthtimespec % NANOS_PER_SECOND;
|
||||
st.st_birthtimespec.tv_sec = r.st_birthtimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_birthtimespec.tv_nsec = r_stat.st_birthtimespec % NANOS_PER_SECOND;
|
||||
unix_st.st_birthtimespec.tv_sec = r_stat.st_birthtimespec / NANOS_PER_SECOND;
|
||||
|
||||
st.st_ctimespec.tv_nsec = r.st_ctimespec % NANOS_PER_SECOND;
|
||||
st.st_ctimespec.tv_sec = r.st_ctimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_ctimespec.tv_nsec = r_stat.st_ctimespec % NANOS_PER_SECOND;
|
||||
unix_st.st_ctimespec.tv_sec = r_stat.st_ctimespec / NANOS_PER_SECOND;
|
||||
|
||||
st.st_mtimespec.tv_nsec = r.st_mtimespec % NANOS_PER_SECOND;
|
||||
st.st_mtimespec.tv_sec = r.st_mtimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_mtimespec.tv_nsec = r_stat.st_mtimespec % NANOS_PER_SECOND;
|
||||
unix_st.st_mtimespec.tv_sec = r_stat.st_mtimespec / NANOS_PER_SECOND;
|
||||
|
||||
st.st_flags = r.st_flags;
|
||||
unix_st.st_flags = r_stat.st_flags;
|
||||
#else
|
||||
st.st_blksize = 4096;
|
||||
unix_st.st_blksize = 4096;
|
||||
|
||||
st.st_atim.tv_nsec = r.st_atimespec % NANOS_PER_SECOND;
|
||||
st.st_atim.tv_sec = r.st_atimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_atim.tv_nsec =
|
||||
static_cast<suseconds_t>(r_stat.st_atimespec % NANOS_PER_SECOND);
|
||||
unix_st.st_atim.tv_sec =
|
||||
static_cast<suseconds_t>(r_stat.st_atimespec / NANOS_PER_SECOND);
|
||||
|
||||
st.st_ctim.tv_nsec = r.st_ctimespec % NANOS_PER_SECOND;
|
||||
st.st_ctim.tv_sec = r.st_ctimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_ctim.tv_nsec =
|
||||
static_cast<suseconds_t>(r_stat.st_ctimespec % NANOS_PER_SECOND);
|
||||
unix_st.st_ctim.tv_sec =
|
||||
static_cast<suseconds_t>(r_stat.st_ctimespec / NANOS_PER_SECOND);
|
||||
|
||||
st.st_mtim.tv_nsec = r.st_mtimespec % NANOS_PER_SECOND;
|
||||
st.st_mtim.tv_sec = r.st_mtimespec / NANOS_PER_SECOND;
|
||||
unix_st.st_mtim.tv_nsec =
|
||||
static_cast<suseconds_t>(r_stat.st_mtimespec % NANOS_PER_SECOND);
|
||||
unix_st.st_mtim.tv_sec =
|
||||
static_cast<suseconds_t>(r_stat.st_mtimespec / NANOS_PER_SECOND);
|
||||
#endif
|
||||
if (not directory) {
|
||||
const auto block_size_stat = static_cast<std::uint64_t>(512u);
|
||||
const auto block_size = static_cast<std::uint64_t>(4096u);
|
||||
const auto size = utils::divide_with_ceiling(
|
||||
static_cast<std::uint64_t>(st.st_size), block_size) *
|
||||
block_size;
|
||||
st.st_blocks = std::max(block_size / block_size_stat,
|
||||
utils::divide_with_ceiling(size, block_size_stat));
|
||||
const auto block_size_stat = static_cast<std::uint64_t>(512U);
|
||||
const auto block_size = static_cast<std::uint64_t>(4096U);
|
||||
const auto size =
|
||||
utils::divide_with_ceiling(static_cast<std::uint64_t>(unix_st.st_size),
|
||||
block_size) *
|
||||
block_size;
|
||||
unix_st.st_blocks = static_cast<blkcnt_t>(
|
||||
std::max(block_size / block_size_stat,
|
||||
utils::divide_with_ceiling(size, block_size_stat)));
|
||||
}
|
||||
|
||||
st.st_gid = r.st_gid;
|
||||
st.st_mode = (directory ? S_IFDIR : S_IFREG) | r.st_mode;
|
||||
unix_st.st_gid = r_stat.st_gid;
|
||||
unix_st.st_mode = (directory ? S_IFDIR : S_IFREG) | r_stat.st_mode;
|
||||
|
||||
st.st_nlink = r.st_nlink;
|
||||
st.st_size = r.st_size;
|
||||
st.st_uid = r.st_uid;
|
||||
unix_st.st_nlink = r_stat.st_nlink;
|
||||
unix_st.st_size = static_cast<off_t>(r_stat.st_size);
|
||||
unix_st.st_uid = r_stat.st_uid;
|
||||
}
|
||||
|
||||
auto remote_fuse_drive::read_impl(std::string api_path, char *buffer,
|
||||
size_t read_size, off_t read_offset,
|
||||
struct fuse_file_info *fi,
|
||||
struct fuse_file_info *f_info,
|
||||
std::size_t &bytes_read) -> api_error {
|
||||
auto res = remote_instance_->fuse_read(api_path.c_str(), buffer, read_size,
|
||||
read_offset, fi->fh);
|
||||
auto res = remote_instance_->fuse_read(
|
||||
api_path.c_str(), buffer, read_size,
|
||||
static_cast<remote::file_offset>(read_offset), f_info->fh);
|
||||
if (res >= 0) {
|
||||
bytes_read = res;
|
||||
bytes_read = static_cast<size_t>(res);
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
@@ -343,19 +366,22 @@ auto remote_fuse_drive::read_impl(std::string api_path, char *buffer,
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto remote_fuse_drive::readdir_impl(std::string api_path, void *buf,
|
||||
fuse_fill_dir_t fuse_fill_dir,
|
||||
off_t offset, struct fuse_file_info *fi,
|
||||
off_t offset,
|
||||
struct fuse_file_info *f_info,
|
||||
fuse_readdir_flags /*flags*/)
|
||||
-> api_error {
|
||||
#else
|
||||
auto remote_fuse_drive::readdir_impl(std::string api_path, void *buf,
|
||||
fuse_fill_dir_t fuse_fill_dir,
|
||||
off_t offset, struct fuse_file_info *fi)
|
||||
off_t offset,
|
||||
struct fuse_file_info *f_info)
|
||||
-> api_error {
|
||||
#endif
|
||||
std::string item_path;
|
||||
int res = 0;
|
||||
while ((res = remote_instance_->fuse_readdir(api_path.c_str(), offset, fi->fh,
|
||||
item_path)) == 0) {
|
||||
while ((res = remote_instance_->fuse_readdir(
|
||||
api_path.c_str(), static_cast<remote::file_offset>(offset),
|
||||
f_info->fh, item_path)) == 0) {
|
||||
if ((item_path != ".") && (item_path != "..")) {
|
||||
item_path = utils::path::strip_to_file_name(item_path);
|
||||
}
|
||||
@@ -378,16 +404,17 @@ auto remote_fuse_drive::readdir_impl(std::string api_path, void *buf,
|
||||
}
|
||||
|
||||
auto remote_fuse_drive::release_impl(std::string api_path,
|
||||
struct fuse_file_info *fi) -> api_error {
|
||||
struct fuse_file_info *f_info)
|
||||
-> api_error {
|
||||
return utils::to_api_error(
|
||||
remote_instance_->fuse_release(api_path.c_str(), fi->fh));
|
||||
remote_instance_->fuse_release(api_path.c_str(), f_info->fh));
|
||||
}
|
||||
|
||||
auto remote_fuse_drive::releasedir_impl(std::string api_path,
|
||||
struct fuse_file_info *fi)
|
||||
struct fuse_file_info *f_info)
|
||||
-> api_error {
|
||||
return utils::to_api_error(
|
||||
remote_instance_->fuse_releasedir(api_path.c_str(), fi->fh));
|
||||
remote_instance_->fuse_releasedir(api_path.c_str(), f_info->fh));
|
||||
}
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
@@ -471,8 +498,8 @@ api_error remote_fuse_drive::statfs_x_impl(std::string api_path,
|
||||
stbuf->f_ffree = r.f_ffree;
|
||||
stbuf->f_files = r.f_files;
|
||||
stbuf->f_owner = getuid();
|
||||
strncpy(&stbuf->f_mntonname[0u], get_mount_location().c_str(), MNAMELEN);
|
||||
strncpy(&stbuf->f_mntfromname[0u], &r.f_mntfromname[0], MNAMELEN);
|
||||
strncpy(&stbuf->f_mntonname[0U], get_mount_location().c_str(), MNAMELEN);
|
||||
strncpy(&stbuf->f_mntfromname[0U], &r.f_mntfromname[0U], MNAMELEN);
|
||||
}
|
||||
} else {
|
||||
res = -errno;
|
||||
@@ -485,15 +512,16 @@ auto remote_fuse_drive::statfs_impl(std::string api_path, struct statvfs *stbuf)
|
||||
-> api_error {
|
||||
auto res = statvfs(config_.get_data_directory().c_str(), stbuf);
|
||||
if (res == 0) {
|
||||
remote::statfs r{};
|
||||
if ((res = remote_instance_->fuse_statfs(api_path.c_str(), stbuf->f_frsize,
|
||||
r)) == 0) {
|
||||
stbuf->f_blocks = r.f_blocks;
|
||||
stbuf->f_bavail = r.f_bavail;
|
||||
stbuf->f_bfree = r.f_bfree;
|
||||
stbuf->f_ffree = r.f_ffree;
|
||||
stbuf->f_favail = r.f_favail;
|
||||
stbuf->f_files = r.f_files;
|
||||
remote::statfs r_stat{};
|
||||
res = remote_instance_->fuse_statfs(api_path.c_str(), stbuf->f_frsize,
|
||||
r_stat);
|
||||
if (res == 0) {
|
||||
stbuf->f_blocks = r_stat.f_blocks;
|
||||
stbuf->f_bavail = r_stat.f_bavail;
|
||||
stbuf->f_bfree = r_stat.f_bfree;
|
||||
stbuf->f_ffree = r_stat.f_ffree;
|
||||
stbuf->f_favail = r_stat.f_favail;
|
||||
stbuf->f_files = r_stat.f_files;
|
||||
}
|
||||
} else {
|
||||
res = -errno;
|
||||
@@ -505,14 +533,14 @@ auto remote_fuse_drive::statfs_impl(std::string api_path, struct statvfs *stbuf)
|
||||
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto remote_fuse_drive::truncate_impl(std::string api_path, off_t size,
|
||||
struct fuse_file_info * /*fi*/)
|
||||
struct fuse_file_info * /*f_info*/)
|
||||
-> api_error {
|
||||
#else
|
||||
auto remote_fuse_drive::truncate_impl(std::string api_path, off_t size)
|
||||
-> api_error {
|
||||
#endif
|
||||
return utils::to_api_error(
|
||||
remote_instance_->fuse_truncate(api_path.c_str(), size));
|
||||
return utils::to_api_error(remote_instance_->fuse_truncate(
|
||||
api_path.c_str(), static_cast<remote::file_offset>(size)));
|
||||
}
|
||||
|
||||
auto remote_fuse_drive::unlink_impl(std::string api_path) -> api_error {
|
||||
@@ -522,31 +550,35 @@ auto remote_fuse_drive::unlink_impl(std::string api_path) -> api_error {
|
||||
#if FUSE_USE_VERSION >= 30
|
||||
auto remote_fuse_drive::utimens_impl(std::string api_path,
|
||||
const struct timespec tv[2],
|
||||
struct fuse_file_info * /*fi*/)
|
||||
struct fuse_file_info * /*f_info*/)
|
||||
-> api_error {
|
||||
#else
|
||||
auto remote_fuse_drive::utimens_impl(std::string api_path,
|
||||
const struct timespec tv[2]) -> api_error {
|
||||
#endif
|
||||
remote::file_time rtv[2u] = {0};
|
||||
if (tv) {
|
||||
rtv[0u] = tv[0u].tv_nsec + (tv[0u].tv_sec * NANOS_PER_SECOND);
|
||||
rtv[1u] = tv[1u].tv_nsec + (tv[1u].tv_sec * NANOS_PER_SECOND);
|
||||
remote::file_time rtv[2U] = {0};
|
||||
if (tv != nullptr) {
|
||||
rtv[0U] = static_cast<remote::file_time>(
|
||||
tv[0U].tv_nsec + (tv[0U].tv_sec * NANOS_PER_SECOND));
|
||||
rtv[1U] = static_cast<remote::file_time>(
|
||||
tv[1U].tv_nsec + (tv[1U].tv_sec * NANOS_PER_SECOND));
|
||||
}
|
||||
|
||||
return utils::to_api_error(remote_instance_->fuse_utimens(
|
||||
api_path.c_str(), rtv, tv ? tv[0u].tv_nsec : 0u,
|
||||
tv ? tv[1u].tv_nsec : 0u));
|
||||
api_path.c_str(), &rtv[0U],
|
||||
static_cast<std::uint64_t>(tv == nullptr ? 0 : tv[0U].tv_nsec),
|
||||
static_cast<std::uint64_t>(tv == nullptr ? 0 : tv[1U].tv_nsec)));
|
||||
}
|
||||
|
||||
auto remote_fuse_drive::write_impl(std::string api_path, const char *buffer,
|
||||
size_t write_size, off_t write_offset,
|
||||
struct fuse_file_info *fi,
|
||||
struct fuse_file_info *f_info,
|
||||
std::size_t &bytes_written) -> api_error {
|
||||
const auto res = remote_instance_->fuse_write(
|
||||
api_path.c_str(), buffer, write_size, write_offset, fi->fh);
|
||||
api_path.c_str(), buffer, write_size,
|
||||
static_cast<remote::file_offset>(write_offset), f_info->fh);
|
||||
if (res >= 0) {
|
||||
bytes_written = res;
|
||||
bytes_written = static_cast<std::size_t>(res);
|
||||
return api_error::success;
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user