libcryfs/src/fspp/fuse/Fuse.h

86 lines
3.3 KiB
C
Raw Normal View History

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
2022-06-18 21:11:24 +02:00
#include <sys/statvfs.h>
2014-11-04 22:33:43 +01:00
#include <cstdio>
#include <string>
#include <vector>
2014-11-04 22:33:43 +01:00
#include <sys/stat.h>
#include <boost/filesystem.hpp>
#include <boost/optional.hpp>
2016-02-11 12:53:42 +01:00
#include <cpp-utils/macros.h>
2018-01-15 02:58:48 +01:00
#include <atomic>
#include <memory>
2018-09-16 03:02:03 +02:00
#include "stat_compatibility.h"
#include <fspp/fs_interface/Context.h>
2014-11-04 22:33:43 +01:00
2022-06-18 21:11:24 +02:00
typedef int (*fuse_fill_dir_t)(void*, const char*, fspp::fuse::STAT*);
2014-11-16 00:05:28 +01:00
namespace fspp {
2014-11-15 23:47:38 +01:00
class Device;
2014-11-16 00:05:28 +01:00
namespace fuse {
class Filesystem;
2014-11-04 22:33:43 +01:00
class Fuse final {
2014-11-04 22:33:43 +01:00
public:
2022-06-18 21:11:24 +02:00
explicit Fuse(std::function<std::shared_ptr<Filesystem> ()> init, std::string fstype, boost::optional<std::string> fsname);
~Fuse();
2014-11-04 22:33:43 +01:00
bool running() const;
void stop();
2014-11-04 22:33:43 +01:00
2018-09-16 03:02:03 +02:00
int getattr(const boost::filesystem::path &path, fspp::fuse::STAT *stbuf);
2022-06-18 21:11:24 +02:00
int fgetattr(const boost::filesystem::path &path, fspp::fuse::STAT *stbuf, uint64_t fh);
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);
2018-09-15 23:32:58 +02:00
int truncate(const boost::filesystem::path &path, int64_t size);
2022-06-18 21:11:24 +02:00
int ftruncate(int64_t size, uint64_t fh);
2022-06-24 23:01:05 +02:00
int utimens(const boost::filesystem::path &path, const timespec lastAccessTime, const timespec lastModificationTime);
2022-06-18 21:11:24 +02:00
int open(const boost::filesystem::path &path, uint64_t* fh, int flags);
int release(uint64_t fh);
int read(char *buf, size_t size, int64_t offset, uint64_t fh);
int write(const char *buf, size_t size, int64_t offset, uint64_t fh);
int statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat);
2022-06-18 21:11:24 +02:00
int flush(uint64_t fh);
int fsync(int flags, uint64_t fh);
int readdir(const boost::filesystem::path &path, void *buf, fuse_fill_dir_t filler);
void init();
void destroy();
int access(const boost::filesystem::path &path, int mask);
2022-06-18 21:11:24 +02:00
int create(const boost::filesystem::path &path, ::mode_t mode, uint64_t* fh);
private:
2015-11-17 07:05:04 +01:00
static void _logException(const std::exception &e);
static void _logUnknownException();
static char *_create_c_string(const std::string &str);
static void _removeAndWarnIfExists(std::vector<std::string> *fuseOptions, const std::string &option);
static bool _has_option(const std::vector<char *> &vec, const std::string &key);
static bool _has_entry_with_prefix(const std::string &prefix, const std::vector<char *> &vec);
void _add_fuse_option_if_not_exists(std::vector<char *> *argv, const std::string &key, const std::string &value);
void _createContext(const std::vector<std::string> &fuseOptions);
2015-11-17 07:05:04 +01:00
2022-06-18 21:11:24 +02:00
std::function<std::shared_ptr<Filesystem> ()> _init;
std::shared_ptr<Filesystem> _fs;
std::vector<char*> _argv;
2018-01-15 02:58:48 +01:00
std::atomic<bool> _running;
std::string _fstype;
boost::optional<std::string> _fsname;
boost::optional<Context> _context;
2022-06-18 21:11:24 +02:00
::uid_t uid;
::gid_t gid;
2014-11-04 22:33:43 +01:00
};
}
}
2014-11-04 22:33:43 +01:00
2015-10-17 17:23:35 +02:00
#endif