Reorder folder structure
This commit is contained in:
parent
429f4a7173
commit
fd07c4892d
276
src/CryFuse.cpp
Normal file
276
src/CryFuse.cpp
Normal file
@ -0,0 +1,276 @@
|
||||
#include "CryFuse.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <dirent.h>
|
||||
#include <cassert>
|
||||
|
||||
#define UNUSED(expr) (void)(expr)
|
||||
|
||||
using fusepp::path;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
namespace {
|
||||
int errcode_map(int exit_status) {
|
||||
if (exit_status < 0) {
|
||||
return -errno;
|
||||
}
|
||||
return exit_status;
|
||||
}
|
||||
}
|
||||
|
||||
CryFuse::CryFuse(CryDevice *device)
|
||||
:_device(device) {
|
||||
}
|
||||
|
||||
int CryFuse::getattr(const path &path, struct stat *stbuf) {
|
||||
UNUSED(stbuf);
|
||||
//printf("getattr(%s, _)\n", path.c_str());
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int retstat = lstat(real_path.c_str(), stbuf);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::fgetattr(const path &path, struct stat *stbuf, fuse_file_info *fileinfo) {
|
||||
//printf("fgetattr(%s, _, _)\n", path.c_str());
|
||||
|
||||
// On FreeBSD, trying to do anything with the mountpoint ends up
|
||||
// opening it, and then using the FD for an fgetattr. So in the
|
||||
// special case of a path of "/", I need to do a getattr on the
|
||||
// underlying root directory instead of doing the fgetattr().
|
||||
if (path.native() == "/") {
|
||||
return getattr(path, stbuf);
|
||||
}
|
||||
|
||||
int retstat = fstat(fileinfo->fh, stbuf);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::readlink(const path &path, char *buf, size_t size) {
|
||||
//printf("readlink(%s, _, %zu)\n", path.c_str(), size);
|
||||
auto real_path = _device->RootDir() / path;
|
||||
//size-1, because the fuse readlink() function includes the null terminating byte in the buffer size,
|
||||
//but the posix version does not and also doesn't append one.
|
||||
int real_size = ::readlink(real_path.c_str(), buf, size-1);
|
||||
if (real_size < 0) {
|
||||
return -errno;
|
||||
}
|
||||
//Terminate the string
|
||||
buf[real_size] = '\0';
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CryFuse::mknod(const path &path, mode_t mode, dev_t rdev) {
|
||||
UNUSED(rdev);
|
||||
//printf("Called non-implemented mknod(%s, %d, _)\n", path.c_str(), mode);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CryFuse::mkdir(const path &path, mode_t mode) {
|
||||
//printf("mkdir(%s, %d)\n", path.c_str(), mode);
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int retstat = ::mkdir(real_path.c_str(), mode);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::unlink(const path &path) {
|
||||
//printf("unlink(%s)\n", path.c_str());
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int retstat = ::unlink(real_path.c_str());
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::rmdir(const path &path) {
|
||||
//printf("rmdir(%s)\n", path.c_str());
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int retstat = ::rmdir(real_path.c_str());
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::symlink(const path &from, const path &to) {
|
||||
//printf("symlink(%s, %s)\n", from.c_str(), to.c_str());
|
||||
auto real_from = _device->RootDir() / from;
|
||||
auto real_to = _device->RootDir() / to;
|
||||
int retstat = ::symlink(real_from.c_str(), real_to.c_str());
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::rename(const path &from, const path &to) {
|
||||
//printf("rename(%s, %s)\n", from.c_str(), to.c_str());
|
||||
auto real_from = _device->RootDir() / from;
|
||||
auto real_to = _device->RootDir() / to;
|
||||
int retstat = ::rename(real_from.c_str(), real_to.c_str());
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::link(const path &from, const path &to) {
|
||||
//printf("link(%s, %s)\n", from.c_str(), to.c_str());
|
||||
auto real_from = _device->RootDir() / from;
|
||||
auto real_to = _device->RootDir() / to;
|
||||
int retstat = ::link(real_from.c_str(), real_to.c_str());
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::chmod(const path &path, mode_t mode) {
|
||||
//printf("chmod(%s, %d)\n", path.c_str(), mode);
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int retstat = ::chmod(real_path.c_str(), mode);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::chown(const path &path, uid_t uid, gid_t gid) {
|
||||
//printf("chown(%s, %d, %d)\n", path.c_str(), uid, gid);
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int retstat = ::chown(real_path.c_str(), uid, gid);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::truncate(const path &path, off_t size) {
|
||||
//printf("truncate(%s, %zu)\n", path.c_str(), size);
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int retstat = ::truncate(real_path.c_str(), size);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::ftruncate(const path &path, off_t size, fuse_file_info *fileinfo) {
|
||||
//printf("ftruncate(%s, %zu, _)\n", path.c_str(), size);
|
||||
int retstat = ::ftruncate(fileinfo->fh, size);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::utimens(const path &path, const timespec times[2]) {
|
||||
//printf("utimens(%s, _)\n", path.c_str());
|
||||
auto real_path = _device->RootDir() / path;
|
||||
struct timeval tv[2];
|
||||
tv[0].tv_sec = times[0].tv_sec;
|
||||
tv[0].tv_usec = times[0].tv_nsec / 1000;
|
||||
tv[1].tv_sec = times[1].tv_sec;
|
||||
tv[1].tv_usec = times[1].tv_nsec / 1000;
|
||||
int retstat = ::lutimes(real_path.c_str(), tv);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::open(const path &path, fuse_file_info *fileinfo) {
|
||||
//printf("open(%s, _)\n", path.c_str());
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int fd = ::open(real_path.c_str(), fileinfo->flags);
|
||||
if (fd < 0) {
|
||||
return -errno;
|
||||
}
|
||||
fileinfo->fh = fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CryFuse::release(const path &path, fuse_file_info *fileinfo) {
|
||||
//printf("release(%s, _)\n", path.c_str());
|
||||
int retstat = ::close(fileinfo->fh);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::read(const path &path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
|
||||
//printf("read(%s, _, %zu, %zu, _)\n", path.c_str(), size, offset);
|
||||
int retstat = ::pread(fileinfo->fh, buf, size, offset);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::write(const path &path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
|
||||
//printf("write(%s, _, %zu, %zu, _)\n", path.c_str(), size, offset);
|
||||
int retstat = ::pwrite(fileinfo->fh, buf, size, offset);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::statfs(const path &path, struct statvfs *fsstat) {
|
||||
//printf("statfs(%s, _)\n", path.c_str());
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int retstat = ::statvfs(real_path.c_str(), fsstat);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::flush(const path &path, fuse_file_info *fileinfo) {
|
||||
//printf("Called non-implemented flush(%s, _)\n", path.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CryFuse::fsync(const path &path, int datasync, fuse_file_info *fileinfo) {
|
||||
//printf("fsync(%s, %d, _)\n", path.c_str(), datasync);
|
||||
int retstat = 0;
|
||||
if (datasync) {
|
||||
retstat = ::fdatasync(fileinfo->fh);
|
||||
} else {
|
||||
retstat = ::fsync(fileinfo->fh);
|
||||
}
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::opendir(const path &path, fuse_file_info *fileinfo) {
|
||||
//printf("opendir(%s, _)\n", path.c_str());
|
||||
auto real_path = _device->RootDir() / path;
|
||||
DIR *dp = ::opendir(real_path.c_str());
|
||||
if (dp == nullptr) {
|
||||
return -errno;
|
||||
}
|
||||
fileinfo->fh = (intptr_t)dp;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CryFuse::readdir(const path &path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) {
|
||||
//printf("readdir(%s, _, _, %zu, _)\n", path.c_str(), offset);
|
||||
auto real_path = _device->RootDir() / path;
|
||||
|
||||
DIR *dp = (DIR*)(uintptr_t)fileinfo->fh;
|
||||
struct dirent *de = ::readdir(dp);
|
||||
if (de == nullptr) {
|
||||
return -errno;
|
||||
}
|
||||
|
||||
do {
|
||||
if (filler(buf, de->d_name, nullptr, 0) != 0) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
} while ((de = ::readdir(dp)) != nullptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CryFuse::releasedir(const path &path, fuse_file_info *fileinfo) {
|
||||
//printf("releasedir(%s, _)\n", path.c_str());
|
||||
int retstat = closedir((DIR*)(uintptr_t)fileinfo->fh);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::fsyncdir(const path &path, int datasync, fuse_file_info *fileinfo) {
|
||||
UNUSED(fileinfo);
|
||||
//printf("Called non-implemented fsyncdir(%s, %d, _)\n", path.c_str(), datasync);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CryFuse::init(fuse_conn_info *conn) {
|
||||
UNUSED(conn);
|
||||
//printf("init()\n");
|
||||
}
|
||||
|
||||
void CryFuse::destroy() {
|
||||
//printf("destroy()\n");
|
||||
}
|
||||
|
||||
int CryFuse::access(const path &path, int mask) {
|
||||
//printf("access(%s, %d)\n", path.c_str(), mask);
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int retstat = ::access(real_path.c_str(), mask);
|
||||
return errcode_map(retstat);
|
||||
}
|
||||
|
||||
int CryFuse::create(const path &path, mode_t mode, fuse_file_info *fileinfo) {
|
||||
//printf("create(%s, %d, _)\n", path.c_str(), mode);
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int fd = ::creat(real_path.c_str(), mode);
|
||||
if (fd < 0) {
|
||||
return -errno;
|
||||
}
|
||||
fileinfo->fh = fd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
54
src/CryFuse.h
Normal file
54
src/CryFuse.h
Normal file
@ -0,0 +1,54 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_CRYFUSE_H_
|
||||
#define CRYFS_LIB_CRYFUSE_H_
|
||||
|
||||
#include "fusepp/Fuse.h"
|
||||
#include "cryfs_lib/CryDevice.h"
|
||||
#include "cryfs_lib/utils/macros.h"
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
class CryFuse: public fusepp::Fuse {
|
||||
public:
|
||||
CryFuse(CryDevice *device);
|
||||
|
||||
int getattr(const fusepp::path &path, struct stat *stbuf) override;
|
||||
int fgetattr(const fusepp::path &path, struct stat *stbuf, fuse_file_info *fileinfo) override;
|
||||
int readlink(const fusepp::path &path, char *buf, size_t size) override;
|
||||
int mknod(const fusepp::path &path, mode_t mode, dev_t rdev) override;
|
||||
int mkdir(const fusepp::path &path, mode_t mode) override;
|
||||
int unlink(const fusepp::path &path) override;
|
||||
int rmdir(const fusepp::path &path) override;
|
||||
int symlink(const fusepp::path &from, const fusepp::path &to) override;
|
||||
int rename(const fusepp::path &from, const fusepp::path &to) override;
|
||||
int link(const fusepp::path &from, const fusepp::path &to) override;
|
||||
int chmod(const fusepp::path &path, mode_t mode) override;
|
||||
int chown(const fusepp::path &path, uid_t uid, gid_t gid) override;
|
||||
int truncate(const fusepp::path &path, off_t size) override;
|
||||
int ftruncate(const fusepp::path &path, off_t size, fuse_file_info *fileinfo) override;
|
||||
int utimens(const fusepp::path &path, const timespec times[2]) override;
|
||||
int open(const fusepp::path &path, fuse_file_info *fileinfo) override;
|
||||
int release(const fusepp::path &path, fuse_file_info *fileinfo) override;
|
||||
int read(const fusepp::path &path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) override;
|
||||
int write(const fusepp::path &path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) override;
|
||||
int statfs(const fusepp::path &path, struct statvfs *fsstat) override;
|
||||
int flush(const fusepp::path &path, fuse_file_info *fileinfo) override;
|
||||
int fsync(const fusepp::path &path, int flags, fuse_file_info *fileinfo) override;
|
||||
int opendir(const fusepp::path &path, fuse_file_info *fileinfo) override;
|
||||
int readdir(const fusepp::path &path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) override;
|
||||
int releasedir(const fusepp::path &path, fuse_file_info *fileinfo) override;
|
||||
int fsyncdir(const fusepp::path &path, int datasync, fuse_file_info *fileinfo) override;
|
||||
void init(fuse_conn_info *conn) override;
|
||||
void destroy() override;
|
||||
int access(const fusepp::path &path, int mask) override;
|
||||
int create(const fusepp::path &path, mode_t mode, fuse_file_info *fileinfo) override;
|
||||
|
||||
private:
|
||||
CryDevice *_device;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryFuse);
|
||||
};
|
||||
|
||||
} /* namespace cryfs */
|
||||
|
||||
#endif /* CRYFS_LIB_CRYFUSE_H_ */
|
3
src/fusepp/CMakeLists.txt
Normal file
3
src/fusepp/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
add_library(fusepp Fuse.cpp)
|
||||
|
||||
target_link_libraries(fusepp fuse boost_filesystem boost_system)
|
206
src/fusepp/Fuse.cpp
Normal file
206
src/fusepp/Fuse.cpp
Normal file
@ -0,0 +1,206 @@
|
||||
#include "../fusepp/Fuse.h"
|
||||
#include <memory>
|
||||
#include <cassert>
|
||||
|
||||
using std::unique_ptr;
|
||||
using std::make_unique;
|
||||
using std::string;
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
using namespace fusepp;
|
||||
|
||||
#define FUSE_OBJ ((Fuse *) fuse_get_context()->private_data)
|
||||
|
||||
namespace {
|
||||
int fusepp_getattr(const char *path, struct stat *stbuf) {
|
||||
return FUSE_OBJ->getattr(bf::path(path), stbuf);
|
||||
}
|
||||
|
||||
int fusepp_fgetattr(const char *path, struct stat *stbuf, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->fgetattr(bf::path(path), stbuf, fileinfo);
|
||||
}
|
||||
|
||||
int fusepp_readlink(const char *path, char *buf, size_t size) {
|
||||
return FUSE_OBJ->readlink(bf::path(path), buf, size);
|
||||
}
|
||||
|
||||
int fusepp_mknod(const char *path, mode_t mode, dev_t rdev) {
|
||||
return FUSE_OBJ->mknod(bf::path(path), mode, rdev);
|
||||
}
|
||||
|
||||
int fusepp_mkdir(const char *path, mode_t mode) {
|
||||
return FUSE_OBJ->mkdir(bf::path(path), mode);
|
||||
}
|
||||
|
||||
int fusepp_unlink(const char *path) {
|
||||
return FUSE_OBJ->unlink(bf::path(path));
|
||||
}
|
||||
|
||||
int fusepp_rmdir(const char *path) {
|
||||
return FUSE_OBJ->rmdir(bf::path(path));
|
||||
}
|
||||
|
||||
int fusepp_symlink(const char *from, const char *to) {
|
||||
return FUSE_OBJ->symlink(bf::path(from), bf::path(to));
|
||||
}
|
||||
|
||||
int fusepp_rename(const char *from, const char *to) {
|
||||
return FUSE_OBJ->rename(bf::path(from), bf::path(to));
|
||||
}
|
||||
|
||||
int fusepp_link(const char *from, const char *to) {
|
||||
return FUSE_OBJ->link(bf::path(from), bf::path(to));
|
||||
}
|
||||
|
||||
int fusepp_chmod(const char *path, mode_t mode) {
|
||||
return FUSE_OBJ->chmod(bf::path(path), mode);
|
||||
}
|
||||
|
||||
int fusepp_chown(const char *path, uid_t uid, gid_t gid) {
|
||||
return FUSE_OBJ->chown(bf::path(path), uid, gid);
|
||||
}
|
||||
|
||||
int fusepp_truncate(const char *path, off_t size) {
|
||||
return FUSE_OBJ->truncate(bf::path(path), size);
|
||||
}
|
||||
|
||||
int fusepp_ftruncate(const char *path, off_t size, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->ftruncate(bf::path(path), size, fileinfo);
|
||||
}
|
||||
|
||||
int fusepp_utimens(const char *path, const timespec times[2]) {
|
||||
return FUSE_OBJ->utimens(bf::path(path), times);
|
||||
}
|
||||
|
||||
int fusepp_open(const char *path, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->open(bf::path(path), fileinfo);
|
||||
}
|
||||
|
||||
int fusepp_release(const char *path, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->release(bf::path(path), fileinfo);
|
||||
}
|
||||
|
||||
int fusepp_read(const char *path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->read(bf::path(path), buf, size, offset, fileinfo);
|
||||
}
|
||||
|
||||
int fusepp_write(const char *path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->write(bf::path(path), buf, size, offset, fileinfo);
|
||||
}
|
||||
|
||||
int fusepp_statfs(const char *path, struct statvfs *fsstat) {
|
||||
return FUSE_OBJ->statfs(bf::path(path), fsstat);
|
||||
}
|
||||
|
||||
int fusepp_flush(const char *path, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->flush(bf::path(path), fileinfo);
|
||||
}
|
||||
|
||||
int fusepp_fsync(const char *path, int datasync, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->fsync(bf::path(path), datasync, fileinfo);
|
||||
}
|
||||
|
||||
//int fusepp_setxattr(const char*, const char*, const char*, size_t, int)
|
||||
//int fusepp_getxattr(const char*, const char*, char*, size_t)
|
||||
//int fusepp_listxattr(const char*, char*, size_t)
|
||||
//int fusepp_removexattr(const char*, const char*)
|
||||
|
||||
int fusepp_opendir(const char *path, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->opendir(bf::path(path), fileinfo);
|
||||
}
|
||||
|
||||
int fusepp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->readdir(bf::path(path), buf, filler, offset, fileinfo);
|
||||
}
|
||||
|
||||
int fusepp_releasedir(const char *path, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->releasedir(bf::path(path), fileinfo);
|
||||
}
|
||||
|
||||
int fusepp_fsyncdir(const char *path, int datasync, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->fsyncdir(bf::path(path), datasync, fileinfo);
|
||||
}
|
||||
|
||||
void* fusepp_init(fuse_conn_info *conn) {
|
||||
auto f = FUSE_OBJ;
|
||||
f->init(conn);
|
||||
return f;
|
||||
}
|
||||
|
||||
void fusepp_destroy(void *userdata) {
|
||||
auto f = FUSE_OBJ;
|
||||
assert(userdata == f);
|
||||
f->destroy();
|
||||
}
|
||||
|
||||
int fusepp_access(const char *path, int mask) {
|
||||
return FUSE_OBJ->access(bf::path(path), mask);
|
||||
}
|
||||
|
||||
int fusepp_create(const char *path, mode_t mode, fuse_file_info *fileinfo) {
|
||||
return FUSE_OBJ->create(bf::path(path), mode, fileinfo);
|
||||
}
|
||||
|
||||
/*int fusepp_lock(const char*, fuse_file_info*, int cmd, flock*)
|
||||
int fusepp_bmap(const char*, size_t blocksize, uint64_t *idx)
|
||||
int fusepp_ioctl(const char*, int cmd, void *arg, fuse_file_info*, unsigned int flags, void *data)
|
||||
int fusepp_poll(const char*, fuse_file_info*, fuse_pollhandle *ph, unsigned *reventsp)
|
||||
int fusepp_write_buf(const char*, fuse_bufvec *buf, off_t off, fuse_file_info*)
|
||||
int fusepp_read_buf(const chas*, struct fuse_bufvec **bufp, size_t size, off_T off, fuse_file_info*)
|
||||
int fusepp_flock(const char*, fuse_file_info*, int op)
|
||||
int fusepp_fallocate(const char*, int, off_t, off_t, fuse_file_info*)*/
|
||||
|
||||
fuse_operations *operations() {
|
||||
static unique_ptr<fuse_operations> singleton(nullptr);
|
||||
|
||||
if (!singleton) {
|
||||
singleton = make_unique<fuse_operations>();
|
||||
singleton->getattr = &fusepp_getattr;
|
||||
singleton->fgetattr = &fusepp_fgetattr;
|
||||
singleton->readlink = &fusepp_readlink;
|
||||
singleton->mknod = &fusepp_mknod;
|
||||
singleton->mkdir = &fusepp_mkdir;
|
||||
singleton->unlink = &fusepp_unlink;
|
||||
singleton->rmdir = &fusepp_rmdir;
|
||||
singleton->symlink = &fusepp_symlink;
|
||||
singleton->rename = &fusepp_rename;
|
||||
singleton->link = &fusepp_link;
|
||||
singleton->chmod = &fusepp_chmod;
|
||||
singleton->chown = &fusepp_chown;
|
||||
singleton->truncate = &fusepp_truncate;
|
||||
singleton->utimens = &fusepp_utimens;
|
||||
singleton->open = &fusepp_open;
|
||||
singleton->read = &fusepp_read;
|
||||
singleton->write = &fusepp_write;
|
||||
singleton->statfs = &fusepp_statfs;
|
||||
singleton->flush = &fusepp_flush;
|
||||
singleton->release = &fusepp_release;
|
||||
singleton->fsync = &fusepp_fsync;
|
||||
/*#ifdef HAVE_SYS_XATTR_H
|
||||
singleton->setxattr = &fusepp_setxattr;
|
||||
singleton->getxattr = &fusepp_getxattr;
|
||||
singleton->listxattr = &fusepp_listxattr;
|
||||
singleton->removexattr = &fusepp_removexattr;
|
||||
#endif*/
|
||||
singleton->opendir = &fusepp_opendir;
|
||||
singleton->readdir = &fusepp_readdir;
|
||||
singleton->releasedir = &fusepp_releasedir;
|
||||
singleton->fsyncdir = &fusepp_fsyncdir;
|
||||
singleton->init = &fusepp_init;
|
||||
singleton->destroy = &fusepp_destroy;
|
||||
singleton->access = &fusepp_access;
|
||||
singleton->create = &fusepp_create;
|
||||
singleton->ftruncate = &fusepp_ftruncate;
|
||||
}
|
||||
|
||||
return singleton.get();
|
||||
}
|
||||
}
|
||||
|
||||
Fuse::~Fuse() {
|
||||
}
|
||||
|
||||
void Fuse::run(int argc, char **argv) {
|
||||
fuse_main(argc, argv, operations(), (void*)this);
|
||||
}
|
58
src/fusepp/Fuse.h
Normal file
58
src/fusepp/Fuse.h
Normal file
@ -0,0 +1,58 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_FUSEPP_FUSE_H_
|
||||
#define CRYFS_LIB_FUSEPP_FUSE_H_
|
||||
|
||||
#include "params.h"
|
||||
#include <fuse.h>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace fusepp {
|
||||
|
||||
typedef boost::filesystem::path path;
|
||||
|
||||
//TODO If performance suffers here, we could use template<class FuseImpl>
|
||||
// and redirect the fuse calls directly to the FuseImpl class instead
|
||||
// of using virtual functions.
|
||||
class Fuse {
|
||||
public:
|
||||
virtual ~Fuse();
|
||||
|
||||
void run(int argc, char **argv);
|
||||
|
||||
virtual int getattr(const path &path, struct stat *stbuf) = 0;
|
||||
virtual int fgetattr(const path &path, struct stat *stbuf, fuse_file_info *fileinfo) = 0;
|
||||
virtual int readlink(const path &path, char *buf, size_t size) = 0;
|
||||
virtual int mknod(const path &path, mode_t mode, dev_t rdev) = 0;
|
||||
virtual int mkdir(const path &path, mode_t mode) = 0;
|
||||
virtual int unlink(const path &path) = 0;
|
||||
virtual int rmdir(const path &path) = 0;
|
||||
virtual int symlink(const path &from, const path &to) = 0;
|
||||
virtual int rename(const path &from, const path &to) = 0;
|
||||
virtual int link(const path &from, const path &to) = 0;
|
||||
virtual int chmod(const path &path, mode_t mode) = 0;
|
||||
virtual int chown(const path &path, uid_t uid, gid_t gid) = 0;
|
||||
virtual int truncate(const path &path, off_t size) = 0;
|
||||
virtual int ftruncate(const path &path, off_t size, fuse_file_info *fileinfo) = 0;
|
||||
virtual int utimens(const path &path, const timespec times[2]) = 0;
|
||||
virtual int open(const path &path, fuse_file_info *fileinfo) = 0;
|
||||
virtual int release(const path &path, fuse_file_info *fileinfo) = 0;
|
||||
virtual int read(const path &path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) = 0;
|
||||
virtual int write(const path &path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) = 0;
|
||||
virtual int statfs(const path &path, struct statvfs *fsstat) = 0;
|
||||
virtual int flush(const path &path, fuse_file_info *fileinfo) = 0;
|
||||
virtual int fsync(const path &path, int datasync, fuse_file_info *fileinfo) = 0;
|
||||
virtual int opendir(const path &path, fuse_file_info *fileinfo) = 0;
|
||||
virtual int readdir(const path &path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) = 0;
|
||||
virtual int releasedir(const path &path, fuse_file_info *fileinfo) = 0;
|
||||
virtual int fsyncdir(const path &path, int datasync, fuse_file_info *fileinfo) = 0;
|
||||
virtual void init(fuse_conn_info *conn) = 0;
|
||||
virtual void destroy() = 0;
|
||||
virtual int access(const path &path, int mask) = 0;
|
||||
virtual int create(const path &path, mode_t mode, fuse_file_info *fileinfo) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* CRYFS_LIB_FUSEPP_FUSE_H_ */
|
7
src/fusepp/params.h
Normal file
7
src/fusepp/params.h
Normal file
@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_FUSEPP_PARAMS_H_
|
||||
#define CRYFS_LIB_FUSEPP_PARAMS_H_
|
||||
|
||||
#define FUSE_USE_VERSION 26
|
||||
|
||||
#endif /* CRYFS_LIB_FUSEPP_PARAMS_H_ */
|
Loading…
Reference in New Issue
Block a user