2014-11-04 22:33:43 +01:00
|
|
|
#pragma once
|
2015-10-15 13:04:57 +02:00
|
|
|
#ifndef MESSMER_FSPP_FUSE_FUSE_H_
|
|
|
|
#define MESSMER_FSPP_FUSE_FUSE_H_
|
2014-11-04 22:33:43 +01:00
|
|
|
|
|
|
|
#include "params.h"
|
|
|
|
#include <cstdio>
|
|
|
|
#include <string>
|
2015-10-15 03:41:02 +02:00
|
|
|
#include <vector>
|
2014-11-04 22:33:43 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <boost/filesystem.hpp>
|
2016-06-02 20:58:04 +02:00
|
|
|
#include <boost/optional.hpp>
|
2016-02-11 12:53:42 +01:00
|
|
|
#include <cpp-utils/macros.h>
|
2014-11-04 22:33:43 +01:00
|
|
|
|
2014-11-16 00:05:28 +01:00
|
|
|
namespace fspp {
|
2014-11-15 23:47:38 +01:00
|
|
|
class Device;
|
2014-11-15 17:24:07 +01:00
|
|
|
|
2014-11-16 00:05:28 +01:00
|
|
|
namespace fuse {
|
2014-11-28 14:46:45 +01:00
|
|
|
class Filesystem;
|
2014-11-04 22:33:43 +01:00
|
|
|
|
2015-11-27 14:05:48 +01:00
|
|
|
class Fuse final {
|
2014-11-04 22:33:43 +01:00
|
|
|
public:
|
2017-10-01 10:04:29 +02:00
|
|
|
explicit Fuse(Filesystem *fs, std::string fstype, boost::optional<std::string> fsname);
|
2015-11-27 14:05:48 +01:00
|
|
|
~Fuse();
|
2014-11-04 22:33:43 +01:00
|
|
|
|
2016-05-10 01:07:02 +02:00
|
|
|
void run(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions);
|
2015-11-27 14:05:48 +01:00
|
|
|
bool running() const;
|
|
|
|
void stop();
|
2014-11-04 22:33:43 +01:00
|
|
|
|
2014-11-15 16:33:24 +01:00
|
|
|
int getattr(const boost::filesystem::path &path, struct stat *stbuf);
|
|
|
|
int fgetattr(const boost::filesystem::path &path, struct stat *stbuf, fuse_file_info *fileinfo);
|
|
|
|
int readlink(const boost::filesystem::path &path, char *buf, size_t size);
|
|
|
|
int mknod(const boost::filesystem::path &path, mode_t mode, dev_t rdev);
|
|
|
|
int mkdir(const boost::filesystem::path &path, mode_t mode);
|
|
|
|
int unlink(const boost::filesystem::path &path);
|
|
|
|
int rmdir(const boost::filesystem::path &path);
|
|
|
|
int symlink(const boost::filesystem::path &from, const boost::filesystem::path &to);
|
|
|
|
int rename(const boost::filesystem::path &from, const boost::filesystem::path &to);
|
|
|
|
int link(const boost::filesystem::path &from, const boost::filesystem::path &to);
|
|
|
|
int chmod(const boost::filesystem::path &path, mode_t mode);
|
|
|
|
int chown(const boost::filesystem::path &path, uid_t uid, gid_t gid);
|
|
|
|
int truncate(const boost::filesystem::path &path, off_t size);
|
|
|
|
int ftruncate(const boost::filesystem::path &path, off_t size, fuse_file_info *fileinfo);
|
|
|
|
int utimens(const boost::filesystem::path &path, const timespec times[2]);
|
|
|
|
int open(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
|
|
|
int release(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
|
|
|
int read(const boost::filesystem::path &path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo);
|
|
|
|
int write(const boost::filesystem::path &path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo);
|
|
|
|
int statfs(const boost::filesystem::path &path, struct statvfs *fsstat);
|
|
|
|
int flush(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
|
|
|
int fsync(const boost::filesystem::path &path, int flags, fuse_file_info *fileinfo);
|
|
|
|
int opendir(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
|
|
|
int readdir(const boost::filesystem::path &path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo);
|
|
|
|
int releasedir(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
|
|
|
int fsyncdir(const boost::filesystem::path &path, int datasync, fuse_file_info *fileinfo);
|
|
|
|
void init(fuse_conn_info *conn);
|
|
|
|
void destroy();
|
|
|
|
int access(const boost::filesystem::path &path, int mask);
|
|
|
|
int create(const boost::filesystem::path &path, mode_t mode, fuse_file_info *fileinfo);
|
|
|
|
|
|
|
|
private:
|
2015-11-17 07:05:04 +01:00
|
|
|
static void _logException(const std::exception &e);
|
|
|
|
static void _logUnknownException();
|
2016-05-10 01:07:02 +02:00
|
|
|
static char *_create_c_string(const std::string &str);
|
2016-06-04 09:45:49 +02:00
|
|
|
static bool _has_option(const std::vector<char *> &vec, const std::string &key);
|
2016-06-23 02:57:00 +02:00
|
|
|
static bool _has_entry_with_prefix(const std::string &prefix, const std::vector<char *> &vec);
|
2016-06-04 09:45:49 +02:00
|
|
|
std::vector<char *> _build_argv(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions);
|
|
|
|
void _add_fuse_option_if_not_exists(std::vector<char *> *argv, const std::string &key, const std::string &value);
|
2015-11-17 07:05:04 +01:00
|
|
|
|
2014-11-19 00:14:35 +01:00
|
|
|
Filesystem *_fs;
|
2015-11-13 00:03:22 +01:00
|
|
|
boost::filesystem::path _mountdir;
|
2016-05-10 01:07:02 +02:00
|
|
|
std::vector<char*> _argv;
|
2014-11-18 00:14:33 +01:00
|
|
|
bool _running;
|
2016-06-02 11:51:44 +02:00
|
|
|
std::string _fstype;
|
2016-06-02 20:58:04 +02:00
|
|
|
boost::optional<std::string> _fsname;
|
2014-11-15 16:33:24 +01:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Fuse);
|
2014-11-04 22:33:43 +01:00
|
|
|
};
|
|
|
|
}
|
2014-11-15 17:24:07 +01:00
|
|
|
}
|
2014-11-04 22:33:43 +01:00
|
|
|
|
2015-10-17 17:23:35 +02:00
|
|
|
#endif
|