initial commit
This commit is contained in:
39
include/drives/fuse/events.hpp
Normal file
39
include/drives/fuse/events.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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 in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_EVENTS_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_EVENTS_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
|
||||
namespace repertory {
|
||||
// clang-format off
|
||||
E_SIMPLE3(fuse_event, debug, true,
|
||||
std::string, function, func, E_STRING,
|
||||
std::string, api_path, ap, E_STRING,
|
||||
int, result, res, E_FROM_INT32
|
||||
);
|
||||
|
||||
E_SIMPLE1(fuse_args_parsed, normal, true,
|
||||
std::string, arguments, args, E_STRING
|
||||
);
|
||||
// clang-format on
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DRIVES_FUSE_EVENTS_HPP_
|
506
include/drives/fuse/fuse_base.hpp
Normal file
506
include/drives/fuse/fuse_base.hpp
Normal file
@ -0,0 +1,506 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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 in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_FUSE_BASE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_FUSE_BASE_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "drives/fuse/i_fuse_drive.hpp"
|
||||
#include "utils/path_utils.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class i_provider;
|
||||
|
||||
class fuse_base : public i_fuse_drive {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
explicit fuse_base(app_config &config_);
|
||||
|
||||
virtual ~fuse_base();
|
||||
|
||||
protected:
|
||||
app_config &config_;
|
||||
|
||||
private:
|
||||
std::string mount_location_;
|
||||
|
||||
protected:
|
||||
bool atime_enabled_ = true;
|
||||
bool console_enabled_ = false;
|
||||
std::optional<gid_t> forced_gid_;
|
||||
std::optional<uid_t> forced_uid_;
|
||||
std::optional<mode_t> forced_umask_;
|
||||
|
||||
private:
|
||||
static fuse_base &instance();
|
||||
|
||||
private:
|
||||
// clang-format off
|
||||
struct fuse_operations fuse_ops_ {
|
||||
.getattr = fuse_base::getattr_,
|
||||
.readlink = nullptr, // int (*readlink) (const char *, char *, size_t);
|
||||
.getdir = nullptr, // int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
|
||||
.mknod = nullptr, // int (*mknod) (const char *, mode_t, dev_t);
|
||||
.mkdir = fuse_base::mkdir_,
|
||||
.unlink = fuse_base::unlink_,
|
||||
.rmdir = fuse_base::rmdir_,
|
||||
.symlink = nullptr, // int (*symlink) (const char *, const char *);
|
||||
.rename = fuse_base::rename_,
|
||||
.link = nullptr, // int (*link) (const char *, const char *);
|
||||
.chmod = fuse_base::chmod_,
|
||||
.chown = fuse_base::chown_,
|
||||
.truncate = fuse_base::truncate_,
|
||||
.utime = nullptr, // int (*utime) (const char *, struct utimbuf *);
|
||||
.open = fuse_base::open_,
|
||||
.read = fuse_base::read_,
|
||||
.write = fuse_base::write_,
|
||||
#ifdef __APPLE__
|
||||
.statfs = nullptr,
|
||||
#else // __APPLE__
|
||||
.statfs = fuse_base::statfs_,
|
||||
#endif // __APPLE__
|
||||
.flush = nullptr, // int (*flush) (const char *, struct fuse_file_info *);
|
||||
.release = fuse_base::release_,
|
||||
.fsync = fuse_base::fsync_,
|
||||
#if HAS_SETXATTR
|
||||
.setxattr = fuse_base::setxattr_,
|
||||
.getxattr = fuse_base::getxattr_,
|
||||
.listxattr = fuse_base::listxattr_,
|
||||
.removexattr = fuse_base::removexattr_,
|
||||
#else // HAS_SETXATTR
|
||||
.setxattr = nullptr,
|
||||
.getxattr = nullptr,
|
||||
.listxattr = nullptr,
|
||||
.removexattr = nullptr,
|
||||
#endif // HAS_SETXATTR
|
||||
.opendir = fuse_base::opendir_,
|
||||
.readdir = fuse_base::readdir_,
|
||||
.releasedir = fuse_base::releasedir_,
|
||||
.fsyncdir = nullptr, // int (*fsyncdir) (const char *, int, struct fuse_file_info *);
|
||||
.init = fuse_base::init_,
|
||||
.destroy = fuse_base::destroy_,
|
||||
.access = fuse_base::access_,
|
||||
.create = fuse_base::create_,
|
||||
.ftruncate = fuse_base::ftruncate_,
|
||||
.fgetattr = fuse_base::fgetattr_,
|
||||
.lock = nullptr, // int (*lock) (const char *, struct fuse_file_info *, int cmd, struct flock *);
|
||||
.utimens = fuse_base::utimens_,
|
||||
.bmap = nullptr, // int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
|
||||
.flag_nullpath_ok = 0,
|
||||
.flag_nopath = 0,
|
||||
.flag_utime_omit_ok = 1,
|
||||
.flag_reserved = 0,
|
||||
.ioctl = nullptr, // int (*ioctl) (const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void *data);
|
||||
.poll = nullptr, // int (*poll) (const char *, struct fuse_file_info *, struct fuse_pollhandle *ph, unsigned *reventsp);
|
||||
.write_buf = nullptr, // int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *);
|
||||
.read_buf = nullptr, // int (*read_buf) (const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *);
|
||||
.flock = nullptr, // int (*flock) (const char *, struct fuse_file_info *, int op);
|
||||
.fallocate = fuse_base::fallocate_
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
private:
|
||||
int execute_callback(const std::string &function_name, const char *from, const char *to,
|
||||
const std::function<api_error(const std::string &, const std::string &)> &cb,
|
||||
const bool &disable_logging = false);
|
||||
|
||||
int execute_callback(const std::string &function_name, const char *path,
|
||||
const std::function<api_error(const std::string &)> &cb,
|
||||
const bool &disable_logging = false);
|
||||
|
||||
static void execute_void_callback(const std::string &function_name,
|
||||
const std::function<void()> &cb);
|
||||
|
||||
static void *execute_void_pointer_callback(const std::string &function_name,
|
||||
const std::function<void *()> &cb);
|
||||
|
||||
void raise_fuse_event(std::string function_name, const std::string &api_file, const int &ret,
|
||||
const bool &disable_logging);
|
||||
|
||||
private:
|
||||
static int access_(const char *path, int mask);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int chflags_(const char *path, uint32_t flags);
|
||||
#endif // __APPLE__
|
||||
|
||||
static int chmod_(const char *path, mode_t mode);
|
||||
|
||||
static int chown_(const char *path, uid_t uid, gid_t gid);
|
||||
|
||||
static int create_(const char *path, mode_t mode, struct fuse_file_info *fi);
|
||||
|
||||
static void destroy_(void *ptr);
|
||||
|
||||
static int fallocate_(const char *path, int mode, off_t offset, off_t length,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
static int fgetattr_(const char *path, struct stat *st, struct fuse_file_info *fi);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int fsetattr_x_(const char *path, struct setattr_x *attr, struct fuse_file_info *fi);
|
||||
#endif // __APPLE__
|
||||
|
||||
static int fsync_(const char *path, int datasync, struct fuse_file_info *fi);
|
||||
|
||||
static int ftruncate_(const char *path, off_t size, struct fuse_file_info *fi);
|
||||
|
||||
static int getattr_(const char *path, struct stat *st);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int getxtimes_(const char *path, struct timespec *bkuptime, struct timespec *crtime);
|
||||
#endif // __APPLE__
|
||||
|
||||
static void *init_(struct fuse_conn_info *conn);
|
||||
|
||||
static int mkdir_(const char *path, mode_t mode);
|
||||
|
||||
static int open_(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int opendir_(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int read_(const char *path, char *buffer, size_t read_size, off_t read_offset,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
static int readdir_(const char *path, void *buf, fuse_fill_dir_t fuse_fill_dir, off_t offset,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
static int release_(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int releasedir_(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int rename_(const char *from, const char *to);
|
||||
|
||||
static int rmdir_(const char *path);
|
||||
|
||||
#ifdef HAS_SETXATTR
|
||||
#ifdef __APPLE__
|
||||
static int getxattr_(const char *path, const char *name, char *value, size_t size,
|
||||
uint32_t position);
|
||||
|
||||
#else // __APPLE__
|
||||
static int getxattr_(const char *path, const char *name, char *value, size_t size);
|
||||
#endif // __APPLE__
|
||||
|
||||
static int listxattr_(const char *path, char *buffer, size_t size);
|
||||
|
||||
static int removexattr_(const char *path, const char *name);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int setxattr_(const char *path, const char *name, const char *value, size_t size,
|
||||
int flags, uint32_t position);
|
||||
|
||||
#else // __APPLE__
|
||||
static int setxattr_(const char *path, const char *name, const char *value, size_t size,
|
||||
int flags);
|
||||
#endif // __APPLE__
|
||||
#endif // HAS_SETXATTR
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int setattr_x_(const char *path, struct setattr_x *attr);
|
||||
|
||||
static int setbkuptime_(const char *path, const struct timespec *bkuptime);
|
||||
|
||||
static int setchgtime_(const char *path, const struct timespec *chgtime);
|
||||
|
||||
static int setcrtime_(const char *path, const struct timespec *crtime);
|
||||
|
||||
static int setvolname_(const char *volname);
|
||||
|
||||
static int statfs_x_(const char *path, struct statfs *stbuf);
|
||||
|
||||
#else // __APPLE__
|
||||
static int statfs_(const char *path, struct statvfs *stbuf);
|
||||
#endif // __APPLE__
|
||||
|
||||
static int truncate_(const char *path, off_t size);
|
||||
|
||||
static int unlink_(const char *path);
|
||||
|
||||
static int utimens_(const char *path, const struct timespec tv[2]);
|
||||
|
||||
static int write_(const char *path, const char *buffer, size_t write_size, off_t write_offset,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
protected:
|
||||
api_error check_access(const std::string &api_path, int mask) const;
|
||||
|
||||
api_error check_and_perform(const std::string &api_path, int parent_mask,
|
||||
const std::function<api_error(api_meta_map &meta)> &action);
|
||||
|
||||
uid_t get_effective_uid() const;
|
||||
|
||||
gid_t get_effective_gid() const;
|
||||
|
||||
static api_error check_open_flags(const int &flags, const int &mask, const api_error &fail_error);
|
||||
|
||||
api_error check_owner(const api_meta_map &meta) const;
|
||||
|
||||
static api_error check_readable(const int &flags, const api_error &fail_error);
|
||||
|
||||
static api_error check_writeable(const int &flags, const api_error &fail_error);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static __uint32_t get_flags_from_meta(const api_meta_map &meta);
|
||||
#endif // __APPLE__
|
||||
|
||||
static gid_t get_gid_from_meta(const api_meta_map &meta);
|
||||
|
||||
static mode_t get_mode_from_meta(const api_meta_map &meta);
|
||||
|
||||
static void get_timespec_from_meta(const api_meta_map &meta, const std::string &name,
|
||||
struct timespec &ts);
|
||||
|
||||
static uid_t get_uid_from_meta(const api_meta_map &meta);
|
||||
|
||||
static void populate_stat(const std::string &api_path, const std::uint64_t &size_or_count,
|
||||
const api_meta_map &meta, const bool &directory, i_provider &provider,
|
||||
struct stat *st);
|
||||
|
||||
static void set_timespec_from_meta(const api_meta_map &meta, const std::string &name,
|
||||
struct timespec &ts);
|
||||
|
||||
protected:
|
||||
virtual api_error access_impl(std::string api_path, int mask) {
|
||||
return check_access(api_path, mask);
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
virtual api_error chflags_impl(std::string /*api_path*/, uint32_t /*flags*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
virtual api_error chmod_impl(std::string /*api_path*/, mode_t /*mode*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error chown_impl(std::string /*api_path*/, uid_t /*uid*/, gid_t /*gid*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error create_impl(std::string /*api_path*/, mode_t /*mode*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual void destroy_impl(void * /*ptr*/) { return; }
|
||||
|
||||
virtual api_error fallocate_impl(std::string /*api_path*/, int /*mode*/, off_t /*offset*/,
|
||||
off_t /*length*/, struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error fgetattr_impl(std::string /*api_path*/, struct stat * /*st*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error fsetattr_x_impl(std::string /*api_path*/, struct setattr_x * /*attr*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error fsync_impl(std::string /*api_path*/, int /*datasync*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error ftruncate_impl(std::string /*api_path*/, off_t /*size*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error getattr_impl(std::string /*api_path*/, struct stat * /*st*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
virtual api_error getxtimes_impl(std::string /*api_path*/, struct timespec * /*bkuptime*/,
|
||||
struct timespec * /*crtime*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
virtual void *init_impl(struct fuse_conn_info *conn);
|
||||
|
||||
virtual api_error mkdir_impl(std::string /*api_path*/, mode_t /*mode*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error open_impl(std::string /*api_path*/, struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error opendir_impl(std::string /*api_path*/, struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error read_impl(std::string /*api_path*/, char * /*buffer*/, size_t /*read_size*/,
|
||||
off_t /*read_offset*/, struct fuse_file_info * /*fi*/,
|
||||
std::size_t & /*bytes_read*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error readdir_impl(std::string /*api_path*/, void * /*buf*/,
|
||||
fuse_fill_dir_t /*fuse_fill_dir*/, off_t /*offset*/,
|
||||
struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error release_impl(std::string /*api_path*/, struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error releasedir_impl(std::string /*api_path*/, struct fuse_file_info * /*fi*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error rename_impl(std::string /*from_api_path*/, std::string /*to_api_path*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error rmdir_impl(std::string /*api_path*/) { return api_error::not_implemented; }
|
||||
|
||||
#ifdef HAS_SETXATTR
|
||||
#ifdef __APPLE__
|
||||
virtual api_error getxattr_impl(std::string /*api_path*/, const char * /*name*/, char * /*value*/,
|
||||
size_t /*size*/, uint32_t /*position*/,
|
||||
int & /*attribute_size*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else // __APPLE__
|
||||
virtual api_error getxattr_impl(std::string /*api_path*/, const char * /*name*/, char * /*value*/,
|
||||
size_t /*size*/, int & /*attribute_size*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
virtual api_error listxattr_impl(std::string /*api_path*/, char * /*buffer*/, size_t /*size*/,
|
||||
int & /*required_size*/, bool & /*return_size*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error removexattr_impl(std::string /*api_path*/, const char * /*name*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
virtual api_error setxattr_impl(std::string /*api_path*/, const char * /*name*/,
|
||||
const char * /*value*/, size_t /*size*/, int /*flags*/,
|
||||
uint32_t /*position*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else // __APPLE__
|
||||
virtual api_error setxattr_impl(std::string /*api_path*/, const char * /*name*/,
|
||||
const char * /*value*/, size_t /*size*/, int /*flags*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
#endif // HAS_SETXATTR
|
||||
|
||||
#ifdef __APPLE__
|
||||
virtual api_error setattr_x_impl(std::string /*api_path*/, struct setattr_x * /*attr*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error setbkuptime_impl(std::string /*api_path*/,
|
||||
const struct timespec * /*bkuptime*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error setchgtime_impl(std::string /*api_path*/, const struct timespec * /*chgtime*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error setcrtime_impl(std::string /*api_path*/, const struct timespec * /*crtime*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error setvolname_impl(const char * /*volname*/) { return api_error::not_implemented; }
|
||||
|
||||
virtual api_error statfs_x_impl(std::string /*api_path*/, struct statfs * /*stbuf*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#else // __APPLE__
|
||||
virtual api_error statfs_impl(std::string /*api_path*/, struct statvfs * /*stbuf*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
#endif // __APPLE__
|
||||
|
||||
virtual api_error truncate_impl(std::string /*api_path*/, off_t /*size*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error unlink_impl(std::string /*api_path*/) { return api_error::not_implemented; }
|
||||
|
||||
virtual api_error utimens_impl(std::string /*api_path*/, const struct timespec /*tv*/[2]) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
virtual api_error write_impl(std::string /*api_path*/, const char * /*buffer*/,
|
||||
size_t /*write_size*/, off_t /*write_offset*/,
|
||||
struct fuse_file_info * /*fi*/, std::size_t & /*bytes_written*/) {
|
||||
return api_error::not_implemented;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void notify_fuse_args_parsed(const std::vector<std::string> & /*args*/) {}
|
||||
|
||||
virtual void notify_fuse_main_exit(int & /*ret*/) {}
|
||||
|
||||
virtual int parse_args(std::vector<std::string> &args);
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error parse_xattr_parameters(const char *name, const uint32_t &position,
|
||||
std::string &attribute_name, const std::string &api_path);
|
||||
#else
|
||||
api_error parse_xattr_parameters(const char *name, std::string &attribute_name,
|
||||
const std::string &api_path);
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error parse_xattr_parameters(const char *name, const char *value, size_t size,
|
||||
const uint32_t &position, std::string &attribute_name,
|
||||
const std::string &api_path);
|
||||
#else
|
||||
api_error parse_xattr_parameters(const char *name, const char *value, size_t size,
|
||||
std::string &attribute_name, const std::string &api_path);
|
||||
#endif
|
||||
|
||||
virtual int shutdown();
|
||||
|
||||
public:
|
||||
static void display_options(int argc, char *argv[]);
|
||||
|
||||
static void display_version_information(int argc, char *argv[]);
|
||||
|
||||
api_error check_parent_access(const std::string &api_path, int mask) const override;
|
||||
|
||||
std::string get_mount_location() const { return mount_location_; }
|
||||
|
||||
int mount(std::vector<std::string> args);
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // INCLUDE_DRIVES_FUSE_FUSE_BASE_HPP_
|
217
include/drives/fuse/fuse_drive.hpp
Normal file
217
include/drives/fuse/fuse_drive.hpp
Normal file
@ -0,0 +1,217 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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 in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_FUSE_DRIVE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_FUSE_DRIVE_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/fuse/fuse_base.hpp"
|
||||
#include "drives/open_file_table.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_provider;
|
||||
class app_config;
|
||||
class console_consumer;
|
||||
class directory_cache;
|
||||
class download_manager;
|
||||
class eviction;
|
||||
class full_server;
|
||||
class lock_data;
|
||||
class logging_consumer;
|
||||
namespace remote_fuse {
|
||||
class remote_server;
|
||||
}
|
||||
|
||||
class fuse_drive final : public fuse_base {
|
||||
public:
|
||||
fuse_drive(app_config &config, lock_data &lock_data, i_provider &provider);
|
||||
|
||||
~fuse_drive() override = default;
|
||||
|
||||
private:
|
||||
lock_data &lock_data_;
|
||||
i_provider &provider_;
|
||||
|
||||
std::shared_ptr<console_consumer> console_consumer_;
|
||||
std::shared_ptr<directory_cache> directory_cache_;
|
||||
std::shared_ptr<download_manager> download_manager_;
|
||||
std::shared_ptr<eviction> eviction_;
|
||||
std::shared_ptr<logging_consumer> logging_consumer_;
|
||||
std::shared_ptr<open_file_table<open_file_data>> oft_;
|
||||
std::shared_ptr<remote_fuse::remote_server> remote_server_;
|
||||
std::shared_ptr<full_server> server_;
|
||||
bool was_mounted_ = false;
|
||||
|
||||
protected:
|
||||
#ifdef __APPLE__
|
||||
api_error chflags_impl(std::string api_path, uint32_t flags) override;
|
||||
#endif // __APPLE__
|
||||
|
||||
api_error chmod_impl(std::string api_path, mode_t mode) override;
|
||||
|
||||
api_error chown_impl(std::string api_path, uid_t uid, gid_t gid) override;
|
||||
|
||||
api_error create_impl(std::string api_path, mode_t mode, struct fuse_file_info *fi) override;
|
||||
|
||||
void destroy_impl(void *ptr) override;
|
||||
|
||||
api_error fallocate_impl(std::string api_path, int mode, off_t offset, off_t length,
|
||||
struct fuse_file_info *fi) override;
|
||||
|
||||
api_error fgetattr_impl(std::string api_path, struct stat *st,
|
||||
struct fuse_file_info *fi) override;
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error fsetattr_x_impl(std::string api_path, struct setattr_x *attr,
|
||||
struct fuse_file_info *fi) override;
|
||||
#endif // __APPLE__
|
||||
|
||||
api_error fsync_impl(std::string api_path, int datasync, struct fuse_file_info *fi) override;
|
||||
|
||||
api_error ftruncate_impl(std::string api_path, off_t size, struct fuse_file_info *fi) override;
|
||||
|
||||
api_error getattr_impl(std::string api_path, struct stat *st) override;
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error getxtimes_impl(std::string api_path, struct timespec *bkuptime,
|
||||
struct timespec *crtime) override;
|
||||
#endif // __APPLE__
|
||||
|
||||
void *init_impl(struct fuse_conn_info *conn) override;
|
||||
|
||||
api_error mkdir_impl(std::string api_path, mode_t mode) override;
|
||||
|
||||
api_error open_impl(std::string api_path, struct fuse_file_info *fi) override;
|
||||
|
||||
api_error opendir_impl(std::string api_path, struct fuse_file_info *fi) override;
|
||||
|
||||
api_error read_impl(std::string api_path, char *buffer, size_t read_size, off_t read_offset,
|
||||
struct fuse_file_info *fi, std::size_t &bytes_read) override;
|
||||
|
||||
api_error readdir_impl(std::string api_path, void *buf, fuse_fill_dir_t fuse_fill_dir,
|
||||
off_t offset, struct fuse_file_info *fi) override;
|
||||
|
||||
api_error release_impl(std::string api_path, struct fuse_file_info *fi) override;
|
||||
|
||||
api_error releasedir_impl(std::string api_path, struct fuse_file_info *fi) override;
|
||||
|
||||
api_error rename_impl(std::string from_api_path, std::string to_api_path) override;
|
||||
|
||||
api_error rmdir_impl(std::string api_path) override;
|
||||
|
||||
#ifdef HAS_SETXATTR
|
||||
api_error getxattr_common(std::string api_path, const char *name, char *value, size_t size,
|
||||
int &attribute_size, uint32_t *position);
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error getxattr_impl(std::string api_path, const char *name, char *value, size_t size,
|
||||
uint32_t position, int &attribute_size) override;
|
||||
#else // __APPLE__
|
||||
api_error getxattr_impl(std::string api_path, const char *name, char *value, size_t size,
|
||||
int &attribute_size) override;
|
||||
#endif // __APPLE__
|
||||
|
||||
api_error listxattr_impl(std::string api_path, char *buffer, size_t size, int &required_size,
|
||||
bool &return_size) override;
|
||||
|
||||
api_error removexattr_impl(std::string api_path, const char *name) override;
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error setxattr_impl(std::string api_path, const char *name, const char *value, size_t size,
|
||||
int flags, uint32_t position) override;
|
||||
#else // __APPLE__
|
||||
api_error setxattr_impl(std::string api_path, const char *name, const char *value, size_t size,
|
||||
int flags) override;
|
||||
#endif // __APPLE__
|
||||
#endif // HAS_SETXATTR
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error setattr_x_impl(std::string api_path, struct setattr_x *attr) override;
|
||||
|
||||
api_error setbkuptime_impl(std::string api_path, const struct timespec *bkuptime) override;
|
||||
|
||||
api_error setchgtime_impl(std::string api_path, const struct timespec *chgtime) override;
|
||||
|
||||
api_error setcrtime_impl(std::string api_path, const struct timespec *crtime) override;
|
||||
|
||||
api_error setvolname_impl(const char *volname) override;
|
||||
|
||||
api_error statfs_x_impl(std::string api_path, struct statfs *stbuf) override;
|
||||
#else // __APPLE__
|
||||
api_error statfs_impl(std::string api_path, struct statvfs *stbuf) override;
|
||||
#endif // __APPLE__
|
||||
|
||||
api_error truncate_impl(std::string api_path, off_t size) override;
|
||||
|
||||
api_error unlink_impl(std::string api_path) override;
|
||||
|
||||
api_error utimens_impl(std::string api_path, const struct timespec tv[2]) override;
|
||||
|
||||
api_error write_impl(std::string api_path, const char *buffer, size_t write_size,
|
||||
off_t write_offset, struct fuse_file_info *fi,
|
||||
std::size_t &bytes_written) override;
|
||||
|
||||
protected:
|
||||
void notify_fuse_args_parsed(const std::vector<std::string> &args) override;
|
||||
|
||||
void notify_fuse_main_exit(int &ret) override;
|
||||
|
||||
int shutdown() override;
|
||||
|
||||
void update_accessed_time(const std::string &api_path);
|
||||
|
||||
public:
|
||||
std::uint64_t get_directory_item_count(const std::string &api_path) const override;
|
||||
|
||||
directory_item_list get_directory_items(const std::string &api_path) const override;
|
||||
|
||||
std::uint64_t get_file_size(const std::string &api_path) const override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, const std::string &name,
|
||||
std::string &value) const override;
|
||||
|
||||
std::uint64_t get_total_drive_space() const override;
|
||||
|
||||
std::uint64_t get_total_item_count() const override;
|
||||
|
||||
std::uint64_t get_used_drive_space() const override;
|
||||
|
||||
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) const override;
|
||||
|
||||
bool is_processing(const std::string &api_path) const override;
|
||||
|
||||
void populate_stat(const directory_item &di, struct stat &st) const override;
|
||||
|
||||
int rename_directory(const std::string &from_api_path, const std::string &to_api_path) override;
|
||||
|
||||
int rename_file(const std::string &from_api_path, const std::string &to_api_path,
|
||||
const bool &overwrite) override;
|
||||
|
||||
void set_item_meta(const std::string &api_path, const std::string &key,
|
||||
const std::string &value) override;
|
||||
|
||||
void update_directory_item(directory_item &di) const override;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // INCLUDE_DRIVES_FUSE_FUSE_DRIVE_HPP_
|
71
include/drives/fuse/i_fuse_drive.hpp
Normal file
71
include/drives/fuse/i_fuse_drive.hpp
Normal file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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 in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_I_FUSE_DRIVE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_I_FUSE_DRIVE_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "types/repertory.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class i_fuse_drive {
|
||||
INTERFACE_SETUP(i_fuse_drive);
|
||||
|
||||
public:
|
||||
virtual api_error check_parent_access(const std::string &api_path, int mask) const = 0;
|
||||
|
||||
virtual std::uint64_t get_directory_item_count(const std::string &api_path) const = 0;
|
||||
|
||||
virtual directory_item_list get_directory_items(const std::string &api_path) const = 0;
|
||||
|
||||
virtual std::uint64_t get_file_size(const std::string &api_path) const = 0;
|
||||
|
||||
virtual api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const = 0;
|
||||
|
||||
virtual api_error get_item_meta(const std::string &api_path, const std::string &name,
|
||||
std::string &value) const = 0;
|
||||
|
||||
virtual std::uint64_t get_total_drive_space() const = 0;
|
||||
|
||||
virtual std::uint64_t get_total_item_count() const = 0;
|
||||
|
||||
virtual std::uint64_t get_used_drive_space() const = 0;
|
||||
|
||||
virtual void get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) const = 0;
|
||||
|
||||
virtual bool is_processing(const std::string &api_path) const = 0;
|
||||
|
||||
virtual void populate_stat(const directory_item &di, struct stat &st) const = 0;
|
||||
|
||||
virtual int rename_directory(const std::string &from_api_path,
|
||||
const std::string &to_api_path) = 0;
|
||||
|
||||
virtual int rename_file(const std::string &from_api_path, const std::string &to_api_path,
|
||||
const bool &overwrite) = 0;
|
||||
|
||||
virtual void set_item_meta(const std::string &api_path, const std::string &key,
|
||||
const std::string &value) = 0;
|
||||
|
||||
virtual void update_directory_item(directory_item &di) const = 0;
|
||||
};
|
||||
} // namespace repertory
|
||||
|
||||
#endif
|
||||
#endif // INCLUDE_DRIVES_FUSE_I_FUSE_DRIVE_HPP_
|
151
include/drives/fuse/remotefuse/i_remote_instance.hpp
Normal file
151
include/drives/fuse/remotefuse/i_remote_instance.hpp
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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 in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_REMOTEFUSE_I_REMOTE_INSTANCE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_REMOTEFUSE_I_REMOTE_INSTANCE_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/remote/i_remote_json.hpp"
|
||||
#include "types/remote.hpp"
|
||||
|
||||
namespace repertory::remote_fuse {
|
||||
class i_remote_instance : public virtual i_remote_json {
|
||||
INTERFACE_SETUP(i_remote_instance);
|
||||
|
||||
public:
|
||||
virtual packet::error_type fuse_access(const char *path, const std::int32_t &mask) = 0;
|
||||
|
||||
virtual packet::error_type fuse_chflags(const char *path, const std::uint32_t &flags) = 0;
|
||||
|
||||
virtual packet::error_type fuse_chmod(const char *path, const remote::file_mode &mode) = 0;
|
||||
|
||||
virtual packet::error_type fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid) = 0;
|
||||
|
||||
virtual packet::error_type fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags,
|
||||
remote::file_handle &handle) = 0;
|
||||
virtual packet::error_type fuse_destroy() = 0;
|
||||
|
||||
/*virtual packet::error_type fuse_fallocate(const char *path, const std::int32_t &mode,
|
||||
const remote::file_offset &offset,
|
||||
const remote::file_offset &length,
|
||||
const remote::file_offset &length,
|
||||
const remote::file_handle &handle) = 0;*/
|
||||
|
||||
virtual packet::error_type fuse_fgetattr(const char *path, remote::stat &st, bool &directory,
|
||||
const remote::file_handle &handle) = 0;
|
||||
|
||||
virtual packet::error_type fuse_fsetattr_x(const char *path, const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle) = 0;
|
||||
|
||||
virtual packet::error_type fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle) = 0;
|
||||
|
||||
virtual packet::error_type fuse_ftruncate(const char *path, const remote::file_offset &size,
|
||||
const remote::file_handle &handle) = 0;
|
||||
|
||||
virtual packet::error_type fuse_getattr(const char *path, remote::stat &st, bool &directory) = 0;
|
||||
|
||||
/*virtual packet::error_type fuse_getxattr(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size) = 0;
|
||||
|
||||
virtual packet::error_type fuse_getxattrOSX(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size,
|
||||
const std::uint32_t &position) = 0;*/
|
||||
|
||||
virtual packet::error_type fuse_getxtimes(const char *path, remote::file_time &bkuptime,
|
||||
remote::file_time &crtime) = 0;
|
||||
|
||||
virtual packet::error_type fuse_init() = 0;
|
||||
|
||||
/*virtual packet::error_type fuse_listxattr(const char *path, char *buffer,
|
||||
const remote::file_size &size) = 0;*/
|
||||
|
||||
virtual packet::error_type fuse_mkdir(const char *path, const remote::file_mode &mode) = 0;
|
||||
|
||||
virtual packet::error_type fuse_open(const char *path, const remote::open_flags &flags,
|
||||
remote::file_handle &handle) = 0;
|
||||
|
||||
virtual packet::error_type fuse_opendir(const char *path, remote::file_handle &handle) = 0;
|
||||
|
||||
virtual packet::error_type fuse_read(const char *path, char *buffer,
|
||||
const remote::file_size &readSize,
|
||||
const remote::file_offset &readOffset,
|
||||
const remote::file_handle &handle) = 0;
|
||||
|
||||
virtual packet::error_type fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle, std::string &itemPath) = 0;
|
||||
|
||||
virtual packet::error_type fuse_release(const char *path, const remote::file_handle &handle) = 0;
|
||||
|
||||
virtual packet::error_type fuse_releasedir(const char *path, const remote::file_handle &handle) = 0;
|
||||
|
||||
// virtual packet::error_type fuse_removexattr(const char *path, const char *name) = 0;
|
||||
|
||||
virtual packet::error_type fuse_rename(const char *from, const char *to) = 0;
|
||||
|
||||
virtual packet::error_type fuse_rmdir(const char *path) = 0;
|
||||
|
||||
virtual packet::error_type fuse_setattr_x(const char *path, remote::setattr_x &attr) = 0;
|
||||
|
||||
virtual packet::error_type fuse_setbkuptime(const char *path, const remote::file_time &bkuptime) = 0;
|
||||
|
||||
virtual packet::error_type fuse_setchgtime(const char *path, const remote::file_time &chgtime) = 0;
|
||||
|
||||
virtual packet::error_type fuse_setcrtime(const char *path, const remote::file_time &crtime) = 0;
|
||||
|
||||
virtual packet::error_type fuse_setvolname(const char *volname) = 0;
|
||||
|
||||
/*virtual packet::error_type fuse_setxattr(const char *path, const char *name,
|
||||
const char *value, const remote::file_size &size,
|
||||
const std::int32_t &flags) = 0;
|
||||
virtual packet::error_type fuse_setxattr_osx(const char *path, const char *name,
|
||||
const char *value, const remote::file_size &size,
|
||||
const std::int32_t &flags,
|
||||
const std::uint32_t &position) = 0;*/
|
||||
|
||||
virtual packet::error_type fuse_statfs(const char *path, const std::uint64_t &frsize,
|
||||
remote::statfs &st) = 0;
|
||||
|
||||
virtual packet::error_type fuse_statfs_x(const char *path, const std::uint64_t &bsize,
|
||||
remote::statfs_x &st) = 0;
|
||||
|
||||
virtual packet::error_type fuse_truncate(const char *path, const remote::file_offset &size) = 0;
|
||||
|
||||
virtual packet::error_type fuse_unlink(const char *path) = 0;
|
||||
|
||||
virtual packet::error_type fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
const std::uint64_t &op0, const std::uint64_t &op1) = 0;
|
||||
|
||||
virtual packet::error_type fuse_write(const char *path, const char *buffer,
|
||||
const remote::file_size &writeSize,
|
||||
const remote::file_offset &writeOffset,
|
||||
const remote::file_handle &handle) = 0;
|
||||
|
||||
virtual packet::error_type fuse_write_base64(const char *path, const char *buffer,
|
||||
const remote::file_size &writeSize,
|
||||
const remote::file_offset &writeOffset,
|
||||
const remote::file_handle &handle) = 0;
|
||||
|
||||
virtual void set_fuse_uid_gid(const remote::user_id &uid, const remote::group_id &gid) = 0;
|
||||
};
|
||||
typedef std::function<std::unique_ptr<i_remote_instance>()> remote_instance_factory;
|
||||
} // namespace repertory::remote_fuse
|
||||
|
||||
#endif // INCLUDE_DRIVES_FUSE_REMOTEFUSE_I_REMOTE_INSTANCE_HPP_
|
172
include/drives/fuse/remotefuse/remote_client.hpp
Normal file
172
include/drives/fuse/remotefuse/remote_client.hpp
Normal file
@ -0,0 +1,172 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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 in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_CLIENT_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_CLIENT_HPP_
|
||||
|
||||
#include "common.hpp"
|
||||
#include "comm/packet/packet_client.hpp"
|
||||
#include "drives/fuse/remotefuse/i_remote_instance.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
#include "types/remote.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
|
||||
namespace remote_fuse {
|
||||
class remote_client final : public i_remote_instance {
|
||||
public:
|
||||
explicit remote_client(const app_config &config);
|
||||
|
||||
private:
|
||||
const app_config &config_;
|
||||
packet_client packet_client_;
|
||||
remote::user_id uid_ = 0;
|
||||
remote::group_id gid_ = 0;
|
||||
|
||||
public:
|
||||
packet::error_type fuse_access(const char *path, const std::int32_t &mask) override;
|
||||
|
||||
packet::error_type fuse_chflags(const char *path, const std::uint32_t &flags) override;
|
||||
|
||||
packet::error_type fuse_chmod(const char *path, const remote::file_mode &mode) override;
|
||||
|
||||
packet::error_type fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid) override;
|
||||
|
||||
packet::error_type fuse_destroy() override;
|
||||
|
||||
/*packet::error_type fuse_fallocate(const char *path, const std::int32_t &mode,
|
||||
const remote::file_offset &offset,
|
||||
const remote::file_offset &length,
|
||||
const remote::file_handle &handle) override ;*/
|
||||
|
||||
packet::error_type fuse_fgetattr(const char *path, remote::stat &st, bool &directory,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_fsetattr_x(const char *path, const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_ftruncate(const char *path, const remote::file_offset &size,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_getattr(const char *path, remote::stat &st, bool &directory) override;
|
||||
|
||||
/*packet::error_type fuse_getxattr(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size) override ;
|
||||
|
||||
packet::error_type fuse_getxattrOSX(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size,
|
||||
const std::uint32_t &position) override ;*/
|
||||
|
||||
packet::error_type fuse_getxtimes(const char *path, remote::file_time &bkuptime,
|
||||
remote::file_time &crtime) override;
|
||||
|
||||
packet::error_type fuse_init() override;
|
||||
|
||||
/*packet::error_type fuse_listxattr(const char *path, char *buffer,
|
||||
const remote::file_size &size) override ;*/
|
||||
|
||||
packet::error_type fuse_mkdir(const char *path, const remote::file_mode &mode) override;
|
||||
|
||||
packet::error_type fuse_opendir(const char *path, remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags, remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_open(const char *path, const remote::open_flags &flags,
|
||||
remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_read(const char *path, char *buffer, const remote::file_size &read_size,
|
||||
const remote::file_offset &read_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_rename(const char *from, const char *to) override;
|
||||
|
||||
packet::error_type fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle, std::string &item_path) override;
|
||||
|
||||
packet::error_type fuse_release(const char *path, const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_releasedir(const char *path, const remote::file_handle &handle) override;
|
||||
|
||||
/*packet::error_type fuse_removexattr(const char *path, const char *name) override ;*/
|
||||
|
||||
packet::error_type fuse_rmdir(const char *path) override;
|
||||
|
||||
packet::error_type fuse_setattr_x(const char *path, remote::setattr_x &attr) override;
|
||||
|
||||
packet::error_type fuse_setbkuptime(const char *path, const remote::file_time &bkuptime) override;
|
||||
|
||||
packet::error_type fuse_setchgtime(const char *path, const remote::file_time &chgtime) override;
|
||||
|
||||
packet::error_type fuse_setcrtime(const char *path, const remote::file_time &crtime) override;
|
||||
|
||||
packet::error_type fuse_setvolname(const char *volname) override;
|
||||
|
||||
/*packet::error_type fuse_setxattr(const char *path, const char *name, const char *value,
|
||||
const remote::file_size &size,
|
||||
const std::int32_t &flags) override ;
|
||||
|
||||
packet::error_type fuse_setxattr_osx(const char *path, const char *name, const char *value,
|
||||
const remote::file_size &size, const std::int32_t &flags,
|
||||
const std::uint32_t &position) override ;*/
|
||||
|
||||
packet::error_type fuse_statfs(const char *path, const std::uint64_t &frsize,
|
||||
remote::statfs &st) override;
|
||||
|
||||
packet::error_type fuse_statfs_x(const char *path, const std::uint64_t &bsize,
|
||||
remote::statfs_x &st) override;
|
||||
|
||||
packet::error_type fuse_truncate(const char *path, const remote::file_offset &size) override;
|
||||
|
||||
packet::error_type fuse_unlink(const char *path) override;
|
||||
|
||||
packet::error_type fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
const std::uint64_t &op0, const std::uint64_t &op1) override;
|
||||
|
||||
packet::error_type fuse_write(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_write_base64(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type json_create_directory_snapshot(const std::string &path,
|
||||
json &json_data) override;
|
||||
|
||||
packet::error_type json_read_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle,
|
||||
const std::uint32_t &page,
|
||||
json &json_data) override;
|
||||
|
||||
packet::error_type json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
void set_fuse_uid_gid(const remote::user_id &uid, const remote::group_id &gid) override;
|
||||
};
|
||||
} // namespace remote_fuse
|
||||
} // namespace repertory
|
||||
|
||||
#endif // INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_CLIENT_HPP_
|
257
include/drives/fuse/remotefuse/remote_fuse_drive.hpp
Normal file
257
include/drives/fuse/remotefuse/remote_fuse_drive.hpp
Normal file
@ -0,0 +1,257 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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 in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/fuse/remotefuse/i_remote_instance.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class console_consumer;
|
||||
class logging_consumer;
|
||||
class lock_data;
|
||||
class server;
|
||||
|
||||
namespace remote_fuse {
|
||||
class remote_fuse_drive final {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
remote_fuse_drive(app_config &config, lock_data &lock, remote_instance_factory factory);
|
||||
|
||||
~remote_fuse_drive() { E_CONSUMER_RELEASE(); }
|
||||
|
||||
private:
|
||||
app_config &config_;
|
||||
lock_data &lock_;
|
||||
remote_instance_factory factory_;
|
||||
std::string mount_location_;
|
||||
|
||||
private:
|
||||
static void shutdown(std::string mount_location);
|
||||
|
||||
private:
|
||||
class remote_fuse_impl final {
|
||||
public:
|
||||
static app_config *config_;
|
||||
static lock_data *lock_;
|
||||
static std::string *mount_location_;
|
||||
static remote_instance_factory *factory_;
|
||||
static std::unique_ptr<console_consumer> console_consumer_;
|
||||
static std::unique_ptr<logging_consumer> logging_consumer_;
|
||||
static std::unique_ptr<i_remote_instance> remote_instance_;
|
||||
static std::unique_ptr<server> server_;
|
||||
static std::optional<gid_t> forced_gid_;
|
||||
static std::optional<uid_t> forced_uid_;
|
||||
static std::optional<mode_t> forced_umask_;
|
||||
static bool console_enabled_;
|
||||
static bool was_mounted_;
|
||||
|
||||
public:
|
||||
static void tear_down(const int &ret);
|
||||
|
||||
private:
|
||||
static void populate_stat(const remote::stat &r, const bool &directory, struct stat &st);
|
||||
|
||||
public:
|
||||
static int repertory_access(const char *path, int mask);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int repertory_chflags(const char *path, uint32_t flags);
|
||||
#endif
|
||||
|
||||
static int repertory_chmod(const char *path, mode_t mode);
|
||||
|
||||
static int repertory_chown(const char *path, uid_t uid, gid_t gid);
|
||||
|
||||
static int repertory_create(const char *path, mode_t mode, struct fuse_file_info *fi);
|
||||
|
||||
static void repertory_destroy(void * /*ptr*/);
|
||||
|
||||
/*static int repertory_fallocate(const char *path, int mode, off_t offset, off_t length,
|
||||
struct fuse_file_info *fi) ;*/
|
||||
|
||||
static int repertory_fgetattr(const char *path, struct stat *st, struct fuse_file_info *fi);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int repertory_fsetattr_x(const char *path, struct setattr_x *attr,
|
||||
struct fuse_file_info *fi);
|
||||
#endif
|
||||
|
||||
static int repertory_fsync(const char *path, int datasync, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_ftruncate(const char *path, off_t size, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_getattr(const char *path, struct stat *st);
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int repertory_getxtimes(const char *path, struct timespec *bkuptime,
|
||||
struct timespec *crtime);
|
||||
#endif
|
||||
|
||||
static void *repertory_init(struct fuse_conn_info *conn);
|
||||
|
||||
static int repertory_mkdir(const char *path, mode_t mode);
|
||||
|
||||
static int repertory_open(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_opendir(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_read(const char *path, char *buffer, size_t readSize, off_t readOffset,
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_readdir(const char *path, void *buf, fuse_fill_dir_t fuseFillDir,
|
||||
off_t offset, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_release(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_releasedir(const char *path, struct fuse_file_info *fi);
|
||||
|
||||
static int repertory_rename(const char *from, const char *to);
|
||||
|
||||
static int repertory_rmdir(const char *path);
|
||||
/*
|
||||
#ifdef HAS_SETXATTR
|
||||
#ifdef __APPLE__
|
||||
static int repertory_getxattr(const char *path, const char *name, char *value, size_t size,
|
||||
uint32_t position) ;
|
||||
#else
|
||||
static int repertory_getxattr(const char *path, const char *name, char *value, size_t size) ;
|
||||
|
||||
#endif
|
||||
static int repertory_listxattr(const char *path, char *buffer, size_t size) ;
|
||||
|
||||
static int repertory_removexattr(const char *path, const char *name) ;
|
||||
#ifdef __APPLE__
|
||||
static int repertory_setxattr(const char *path, const char *name, const char *value,
|
||||
size_t size, int flags, uint32_t position) ;
|
||||
#else
|
||||
static int repertory_setxattr(const char *path, const char *name, const char *value,
|
||||
size_t size, int flags) ;
|
||||
#endif
|
||||
#endif
|
||||
*/
|
||||
#ifdef __APPLE__
|
||||
static int repertory_setattr_x(const char *path, struct setattr_x *attr);
|
||||
|
||||
static int repertory_setbkuptime(const char *path, const struct timespec *bkuptime);
|
||||
|
||||
static int repertory_setchgtime(const char *path, const struct timespec *chgtime);
|
||||
|
||||
static int repertory_setcrtime(const char *path, const struct timespec *crtime);
|
||||
|
||||
static int repertory_setvolname(const char *volname);
|
||||
|
||||
static int repertory_statfs_x(const char *path, struct statfs *stbuf);
|
||||
#else
|
||||
|
||||
static int repertory_statfs(const char *path, struct statvfs *stbuf);
|
||||
|
||||
#endif
|
||||
|
||||
static int repertory_truncate(const char *path, off_t size);
|
||||
|
||||
static int repertory_unlink(const char *path);
|
||||
|
||||
static int repertory_utimens(const char *path, const struct timespec tv[2]);
|
||||
|
||||
static int repertory_write(const char *path, const char *buffer, size_t writeSize,
|
||||
off_t writeOffset, struct fuse_file_info *fi);
|
||||
};
|
||||
|
||||
private:
|
||||
// clang-format off
|
||||
struct fuse_operations fuse_ops_ {
|
||||
.getattr = remote_fuse_impl::repertory_getattr,
|
||||
.readlink = nullptr, // int (*readlink) (const char *, char *, size_t);
|
||||
.getdir = nullptr, // int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
|
||||
.mknod = nullptr, // int (*mknod) (const char *, mode_t, dev_t);
|
||||
.mkdir = remote_fuse_impl::repertory_mkdir,
|
||||
.unlink = remote_fuse_impl::repertory_unlink,
|
||||
.rmdir = remote_fuse_impl::repertory_rmdir,
|
||||
.symlink = nullptr, // int (*symlink) (const char *, const char *);
|
||||
.rename = remote_fuse_impl::repertory_rename,
|
||||
.link = nullptr, // int (*link) (const char *, const char *);
|
||||
.chmod = remote_fuse_impl::repertory_chmod,
|
||||
.chown = remote_fuse_impl::repertory_chown,
|
||||
.truncate = remote_fuse_impl::repertory_truncate,
|
||||
.utime = nullptr, // int (*utime) (const char *, struct utimbuf *);
|
||||
.open = remote_fuse_impl::repertory_open,
|
||||
.read = remote_fuse_impl::repertory_read,
|
||||
.write = remote_fuse_impl::repertory_write,
|
||||
#ifdef __APPLE__
|
||||
.statfs = nullptr,
|
||||
#else
|
||||
.statfs = remote_fuse_impl::repertory_statfs,
|
||||
#endif
|
||||
.flush = nullptr, // int (*flush) (const char *, struct fuse_file_info *);
|
||||
.release = remote_fuse_impl::repertory_release,
|
||||
.fsync = remote_fuse_impl::repertory_fsync,
|
||||
#if HAS_SETXATTR
|
||||
.setxattr = nullptr, // remote_fuse_impl::repertory_setxattr,
|
||||
.getxattr = nullptr, // remote_fuse_impl::repertory_getxattr,
|
||||
.listxattr = nullptr, // remote_fuse_impl::repertory_listxattr,
|
||||
.removexattr = nullptr, // remote_fuse_impl::repertory_removexattr,
|
||||
#else
|
||||
.setxattr = nullptr,
|
||||
.getxattr = nullptr,
|
||||
.listxattr = nullptr,
|
||||
.removexattr = nullptr,
|
||||
#endif
|
||||
.opendir = remote_fuse_impl::repertory_opendir,
|
||||
.readdir = remote_fuse_impl::repertory_readdir,
|
||||
.releasedir = remote_fuse_impl::repertory_releasedir,
|
||||
.fsyncdir = nullptr, // int (*fsyncdir) (const char *, int, struct fuse_file_info *);
|
||||
.init = remote_fuse_impl::repertory_init,
|
||||
.destroy = remote_fuse_impl::repertory_destroy,
|
||||
.access = remote_fuse_impl::repertory_access,
|
||||
.create = remote_fuse_impl::repertory_create,
|
||||
.ftruncate = remote_fuse_impl::repertory_ftruncate,
|
||||
.fgetattr = remote_fuse_impl::repertory_fgetattr,
|
||||
.lock = nullptr, // int (*lock) (const char *, struct fuse_file_info *, int cmd, struct flock *);
|
||||
.utimens = remote_fuse_impl::repertory_utimens,
|
||||
.bmap = nullptr, // int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
|
||||
.flag_nullpath_ok = 0,
|
||||
.flag_nopath = 0,
|
||||
.flag_utime_omit_ok = 1,
|
||||
.flag_reserved = 0,
|
||||
.ioctl = nullptr, // int (*ioctl) (const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void *data);
|
||||
.poll = nullptr, // int (*poll) (const char *, struct fuse_file_info *, struct fuse_pollhandle *ph, unsigned *reventsp);
|
||||
.write_buf = nullptr, // int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *);
|
||||
.read_buf = nullptr, // int (*read_buf) (const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *);
|
||||
.flock = nullptr, // int (*flock) (const char *, struct fuse_file_info *, int op);
|
||||
.fallocate = nullptr // remote_fuse_impl::repertory_fallocate,
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
public:
|
||||
int mount(std::vector<std::string> drive_args);
|
||||
|
||||
static void display_options(int argc, char *argv[]);
|
||||
|
||||
static void display_version_information(int argc, char *argv[]);
|
||||
};
|
||||
} // namespace remote_fuse
|
||||
} // namespace repertory
|
||||
|
||||
#endif // _WIN32
|
||||
#endif // INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE_HPP_
|
101
include/drives/fuse/remotefuse/remote_fuse_drive2.hpp
Normal file
101
include/drives/fuse/remotefuse/remote_fuse_drive2.hpp
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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 in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE2_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE2_HPP_
|
||||
#ifndef _WIN32
|
||||
#if 0
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/fuse/fuse_base.hpp"
|
||||
#include "drives/fuse/remotefuse/i_remote_instance.hpp"
|
||||
#include "events/event_system.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
class console_consumer;
|
||||
class logging_consumer;
|
||||
class lock_data;
|
||||
class server;
|
||||
|
||||
namespace utils {
|
||||
api_error to_api_error(packet::error_type e) { return api_error::success; }
|
||||
} // namespace utils
|
||||
|
||||
namespace remote_fuse {
|
||||
class remote_fuse_drive2 final : public fuse_base {
|
||||
E_CONSUMER();
|
||||
|
||||
public:
|
||||
~remote_fuse_drive2() override = default;
|
||||
|
||||
private:
|
||||
std::unique_ptr<i_remote_instance> remote_instance_;
|
||||
|
||||
protected:
|
||||
api_error access_impl(std::string api_path, int mask) override;
|
||||
|
||||
#ifdef __APPLE__
|
||||
api_error chflags_impl(std::string api_path, uint32_t flags) override;
|
||||
#endif // __APPLE__
|
||||
|
||||
api_error chmod_impl(std::string api_path, mode_t mode) override;
|
||||
|
||||
public:
|
||||
api_error check_parent_access(const std::string &api_path, int mask) const override;
|
||||
|
||||
std::uint64_t get_directory_item_count(const std::string &api_path) const override;
|
||||
|
||||
directory_item_list get_directory_items(const std::string &api_path) const override;
|
||||
|
||||
std::uint64_t get_file_size(const std::string &api_path) const override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, api_meta_map &meta) const override;
|
||||
|
||||
api_error get_item_meta(const std::string &api_path, const std::string &name,
|
||||
std::string &value) const override;
|
||||
|
||||
std::uint64_t get_total_drive_space() const override;
|
||||
|
||||
std::uint64_t get_total_item_count() const override;
|
||||
|
||||
std::uint64_t get_used_drive_space() const override;
|
||||
|
||||
void get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) const override;
|
||||
|
||||
bool is_processing(const std::string &api_path) const override;
|
||||
|
||||
void populate_stat(const directory_item &di, struct stat &st) const override;
|
||||
|
||||
int rename_directory(const std::string &from_api_path, const std::string &to_api_path) override;
|
||||
|
||||
int rename_file(const std::string &from_api_path, const std::string &to_api_path,
|
||||
const bool &overwrite) override;
|
||||
|
||||
void set_item_meta(const std::string &api_path, const std::string &key,
|
||||
const std::string &value) override;
|
||||
|
||||
void update_directory_item(directory_item &di) const override;
|
||||
};
|
||||
} // namespace remote_fuse
|
||||
} // namespace repertory
|
||||
|
||||
#endif // 0
|
||||
#endif // _WIN32
|
||||
#endif // INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_FUSE_DRIVE2_HPP_
|
253
include/drives/fuse/remotefuse/remote_server.hpp
Normal file
253
include/drives/fuse/remotefuse/remote_server.hpp
Normal file
@ -0,0 +1,253 @@
|
||||
/*
|
||||
Copyright <2018-2022> <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 in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or
|
||||
substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
|
||||
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_SERVER_HPP_
|
||||
#define INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_SERVER_HPP_
|
||||
#ifndef _WIN32
|
||||
|
||||
#include "common.hpp"
|
||||
#include "drives/directory_cache.hpp"
|
||||
#include "drives/fuse/i_fuse_drive.hpp"
|
||||
#include "drives/remote/remote_server_base.hpp"
|
||||
|
||||
namespace repertory {
|
||||
class app_config;
|
||||
|
||||
namespace remote_fuse {
|
||||
class remote_server final : public virtual remote_server_base<i_fuse_drive> {
|
||||
public:
|
||||
remote_server(app_config &config, i_fuse_drive &drive, const std::string &mount_location);
|
||||
|
||||
private:
|
||||
directory_cache directory_cache_;
|
||||
|
||||
private:
|
||||
std::string construct_path(std::string path);
|
||||
|
||||
std::string construct_path(const std::wstring &path);
|
||||
|
||||
static std::string empty_as_zero(const json &data);
|
||||
|
||||
packet::error_type populate_file_info(const std::string &api_path, remote::file_info &file_info);
|
||||
|
||||
void populate_file_info(const std::string &api_path, const UINT64 &file_size,
|
||||
const UINT32 &attributes, remote::file_info &file_info);
|
||||
|
||||
static void populate_stat(const struct stat &st1, remote::stat &st);
|
||||
|
||||
json &update_to_windows_format(json &item);
|
||||
|
||||
protected:
|
||||
void delete_open_directory(void *dir) override;
|
||||
|
||||
public:
|
||||
// FUSE Layer
|
||||
packet::error_type fuse_access(const char *path, const std::int32_t &mask) override;
|
||||
|
||||
packet::error_type fuse_chflags(const char *path, const std::uint32_t &flags) override;
|
||||
|
||||
packet::error_type fuse_chmod(const char *path, const remote::file_mode &mode) override;
|
||||
|
||||
packet::error_type fuse_chown(const char *path, const remote::user_id &uid,
|
||||
const remote::group_id &gid) override;
|
||||
|
||||
packet::error_type fuse_create(const char *path, const remote::file_mode &mode,
|
||||
const remote::open_flags &flags, remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_destroy() override;
|
||||
|
||||
/*packet::error_type fuse_fallocate(const char *path, const std::int32_t &mode,
|
||||
const remote::file_offset &offset,
|
||||
const remote::file_offset &length,
|
||||
const remote::file_handle &handle) override ;*/
|
||||
|
||||
packet::error_type fuse_fgetattr(const char *path, remote::stat &st, bool &directory,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_fsetattr_x(const char *path, const remote::setattr_x &attr,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_fsync(const char *path, const std::int32_t &datasync,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_ftruncate(const char *path, const remote::file_offset &size,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_getattr(const char *path, remote::stat &st, bool &directory) override;
|
||||
|
||||
/*packet::error_type fuse_getxattr(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size) override ;
|
||||
|
||||
packet::error_type fuse_getxattrOSX(const char *path, const char *name, char *value,
|
||||
const remote::file_size &size,
|
||||
const std::uint32_t &position) override ;*/
|
||||
|
||||
packet::error_type fuse_getxtimes(const char *path, remote::file_time &bkuptime,
|
||||
remote::file_time &crtime) override;
|
||||
|
||||
packet::error_type fuse_init() override;
|
||||
|
||||
/*packet::error_type fuse_listxattr(const char *path, char *buffer,
|
||||
const remote::file_size &size) override ;*/
|
||||
|
||||
packet::error_type fuse_mkdir(const char *path, const remote::file_mode &mode) override;
|
||||
|
||||
packet::error_type fuse_open(const char *path, const remote::open_flags &flags,
|
||||
remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_opendir(const char *path, remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_read(const char *path, char *buffer, const remote::file_size &read_size,
|
||||
const remote::file_offset &read_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_rename(const char *from, const char *to) override;
|
||||
|
||||
packet::error_type fuse_readdir(const char *path, const remote::file_offset &offset,
|
||||
const remote::file_handle &handle, std::string &item_path) override;
|
||||
|
||||
packet::error_type fuse_release(const char *path, const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_releasedir(const char *path, const remote::file_handle &handle) override;
|
||||
|
||||
/*packet::error_type fuse_removexattr(const char *path, const char *name) override ;*/
|
||||
|
||||
packet::error_type fuse_rmdir(const char *path) override;
|
||||
|
||||
packet::error_type fuse_setattr_x(const char *path, remote::setattr_x &attr) override;
|
||||
|
||||
packet::error_type fuse_setbkuptime(const char *path, const remote::file_time &bkuptime) override;
|
||||
|
||||
packet::error_type fuse_setchgtime(const char *path, const remote::file_time &chgtime) override;
|
||||
|
||||
packet::error_type fuse_setcrtime(const char *path, const remote::file_time &crtime) override;
|
||||
|
||||
packet::error_type fuse_setvolname(const char *volname) override;
|
||||
|
||||
/*packet::error_type fuse_setxattr(const char *path, const char *name, const char *value,
|
||||
const remote::file_size &size,
|
||||
const std::int32_t &flags) override ;
|
||||
|
||||
packet::error_type fuse_setxattr_osx(const char *path, const char *name, const char *value,
|
||||
const remote::file_size &size, const std::int32_t &flags,
|
||||
const std::uint32_t &position) override ;*/
|
||||
|
||||
packet::error_type fuse_statfs(const char *path, const std::uint64_t &frsize,
|
||||
remote::statfs &st) override;
|
||||
|
||||
packet::error_type fuse_statfs_x(const char *path, const std::uint64_t &bsize,
|
||||
remote::statfs_x &st) override;
|
||||
|
||||
packet::error_type fuse_truncate(const char *path, const remote::file_offset &size) override;
|
||||
|
||||
packet::error_type fuse_unlink(const char *path) override;
|
||||
|
||||
packet::error_type fuse_utimens(const char *path, const remote::file_time *tv,
|
||||
const std::uint64_t &op0, const std::uint64_t &op1) override;
|
||||
|
||||
packet::error_type fuse_write(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
packet::error_type fuse_write_base64(const char *path, const char *buffer,
|
||||
const remote::file_size &write_size,
|
||||
const remote::file_offset &write_offset,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
void set_fuse_uid_gid(const remote::user_id &, const remote::group_id &) override {}
|
||||
|
||||
// JSON Layer
|
||||
packet::error_type winfsp_get_dir_buffer(PVOID /*file_desc*/, PVOID *& /*ptr*/) override {
|
||||
return STATUS_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
packet::error_type json_create_directory_snapshot(const std::string &path,
|
||||
json &jsonData) override;
|
||||
|
||||
packet::error_type json_read_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle,
|
||||
const std::uint32_t &page,
|
||||
json &jsonData) override;
|
||||
|
||||
packet::error_type json_release_directory_snapshot(const std::string &path,
|
||||
const remote::file_handle &handle) override;
|
||||
|
||||
// WinFSP Layer
|
||||
packet::error_type winfsp_can_delete(PVOID file_desc, PWSTR file_name) override;
|
||||
|
||||
packet::error_type winfsp_cleanup(PVOID file_desc, PWSTR file_name, UINT32 flags,
|
||||
BOOLEAN &wasClosed) override;
|
||||
|
||||
packet::error_type winfsp_close(PVOID file_desc) override;
|
||||
|
||||
packet::error_type winfsp_create(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
UINT32 attributes, UINT64 /*allocation_size*/, PVOID *file_desc,
|
||||
remote::file_info *file_info, std::string &normalized_name,
|
||||
BOOLEAN &exists) override;
|
||||
|
||||
packet::error_type winfsp_flush(PVOID file_desc, remote::file_info *file_info) override;
|
||||
|
||||
packet::error_type winfsp_get_file_info(PVOID file_desc, remote::file_info *file_info) override;
|
||||
|
||||
packet::error_type winfsp_get_security_by_name(PWSTR file_name, PUINT32 attributes,
|
||||
std::uint64_t * /*securityDescriptorSize*/,
|
||||
std::wstring & /*strDescriptor*/) override;
|
||||
|
||||
packet::error_type winfsp_get_volume_info(UINT64 &total_size, UINT64 &free_size,
|
||||
std::string &volume_label) override;
|
||||
|
||||
packet::error_type winfsp_mounted(const std::wstring &location) override;
|
||||
|
||||
packet::error_type winfsp_open(PWSTR file_name, UINT32 create_options, UINT32 granted_access,
|
||||
PVOID *file_desc, remote::file_info *file_info,
|
||||
std::string &normalized_name) override;
|
||||
|
||||
packet::error_type winfsp_overwrite(PVOID file_desc, UINT32 attributes,
|
||||
BOOLEAN replace_attributes, UINT64 /*allocation_size*/,
|
||||
remote::file_info *file_info) override;
|
||||
|
||||
packet::error_type winfsp_read(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
PUINT32 bytes_transferred) override;
|
||||
|
||||
packet::error_type winfsp_read_directory(PVOID file_desc, PWSTR /*pattern*/, PWSTR marker,
|
||||
json &itemList) override;
|
||||
|
||||
packet::error_type winfsp_rename(PVOID /*file_desc*/, PWSTR file_name, PWSTR new_file_name,
|
||||
BOOLEAN replace_if_exists) override;
|
||||
|
||||
packet::error_type winfsp_set_basic_info(PVOID file_desc, UINT32 attributes, UINT64 creation_time,
|
||||
UINT64 last_access_time, UINT64 last_write_time,
|
||||
UINT64 change_time,
|
||||
remote::file_info *file_info) override;
|
||||
|
||||
packet::error_type winfsp_set_file_size(PVOID file_desc, UINT64 newSize,
|
||||
BOOLEAN set_allocation_size,
|
||||
remote::file_info *file_info) override;
|
||||
|
||||
packet::error_type winfsp_unmounted(const std::wstring &location) override;
|
||||
|
||||
packet::error_type winfsp_write(PVOID file_desc, PVOID buffer, UINT64 offset, UINT32 length,
|
||||
BOOLEAN write_to_end, BOOLEAN constrained_io,
|
||||
PUINT32 bytes_transferred, remote::file_info *file_info) override;
|
||||
};
|
||||
} // namespace remote_fuse
|
||||
} // namespace repertory
|
||||
|
||||
#endif
|
||||
#endif // INCLUDE_DRIVES_FUSE_REMOTEFUSE_REMOTE_SERVER_HPP_
|
Reference in New Issue
Block a user