Finished renaming fusepp -> fspp

This commit is contained in:
Sebastian Messmer 2014-11-16 00:10:29 +01:00
parent e863e5b6ce
commit 193b2b1b88
32 changed files with 15 additions and 1131 deletions

View File

@ -3,7 +3,7 @@
#include "CryDir.h"
#include "CryFile.h"
#include "fusepp/impl/FuseErrnoException.h"
#include "fspp/impl/FuseErrnoException.h"
using std::unique_ptr;

View File

@ -3,9 +3,9 @@
#define CRYFS_LIB_CRYDEVICE_H_
#include <boost/filesystem.hpp>
#include <fusepp/fs_interface/Device.h>
#include <fspp/fs_interface/Device.h>
#include "fusepp/utils/macros.h"
#include "fspp/utils/macros.h"
namespace cryfs {

View File

@ -5,7 +5,7 @@
#include <fcntl.h>
#include <dirent.h>
#include "fusepp/impl/FuseErrnoException.h"
#include "fspp/impl/FuseErrnoException.h"
#include "CryDevice.h"
#include "CryFile.h"

View File

@ -2,7 +2,7 @@
#ifndef CRYFS_LIB_CRYDIR_H_
#define CRYFS_LIB_CRYDIR_H_
#include <fusepp/fs_interface/Dir.h>
#include <fspp/fs_interface/Dir.h>
#include "CryNode.h"
namespace cryfs {

View File

@ -2,7 +2,7 @@
#include "CryDevice.h"
#include "CryOpenFile.h"
#include "fusepp/impl/FuseErrnoException.h"
#include "fspp/impl/FuseErrnoException.h"
namespace bf = boost::filesystem;

View File

@ -2,7 +2,7 @@
#ifndef CRYFS_LIB_CRYFILE_H_
#define CRYFS_LIB_CRYFILE_H_
#include <fusepp/fs_interface/File.h>
#include <fspp/fs_interface/File.h>
#include "CryNode.h"
namespace cryfs {

View File

@ -3,7 +3,7 @@
#include <sys/time.h>
#include "CryDevice.h"
#include "fusepp/impl/FuseErrnoException.h"
#include "fspp/impl/FuseErrnoException.h"
namespace bf = boost::filesystem;

View File

@ -2,8 +2,8 @@
#ifndef CRYFS_LIB_CRYNODE_H_
#define CRYFS_LIB_CRYNODE_H_
#include <fusepp/fs_interface/Node.h>
#include "fusepp/utils/macros.h"
#include <fspp/fs_interface/Node.h>
#include "fspp/utils/macros.h"
#include "CryDevice.h"

View File

@ -4,7 +4,7 @@
#include <fcntl.h>
#include "CryDevice.h"
#include "fusepp/impl/FuseErrnoException.h"
#include "fspp/impl/FuseErrnoException.h"
namespace bf = boost::filesystem;

View File

@ -2,8 +2,8 @@
#ifndef CRYFS_LIB_CRYOPENFILE_H_
#define CRYFS_LIB_CRYOPENFILE_H_
#include <fusepp/fs_interface/OpenFile.h>
#include "fusepp/utils/macros.h"
#include "fspp/fs_interface/OpenFile.h"
#include "fspp/utils/macros.h"
namespace cryfs {
class CryDevice;

View File

@ -1,2 +0,0 @@
add_subdirectory(fusebindings)
add_subdirectory(impl)

View File

@ -1,22 +0,0 @@
#pragma once
#ifndef FSPP_DEVICE_H_
#define FSPP_DEVICE_H_
#include <boost/filesystem.hpp>
#include <memory>
#include <sys/statvfs.h>
namespace fspp {
class Node;
class Device {
public:
virtual ~Device() {}
virtual void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) = 0;
virtual std::unique_ptr<Node> Load(const boost::filesystem::path &path) = 0;
};
}
#endif /* FSPP_DEVICE_H_ */

View File

@ -1,26 +0,0 @@
#pragma once
#ifndef FSPP_DIR_H_
#define FSPP_DIR_H_
#include <fusepp/fs_interface/Node.h>
#include <memory>
#include <string>
namespace fspp {
class Device;
class File;
class Dir: public virtual Node {
public:
virtual ~Dir() {}
virtual std::unique_ptr<File> createFile(const std::string &name, mode_t mode) = 0;
virtual std::unique_ptr<Dir> createDir(const std::string &name, mode_t mode) = 0;
virtual void rmdir() = 0;
virtual std::unique_ptr<std::vector<std::string>> children() const = 0;
};
} /* namespace fspp */
#endif /* FSPP_DIR_H_ */

View File

@ -1,23 +0,0 @@
#pragma once
#ifndef FSPP_FILE_H_
#define FSPP_FILE_H_
#include <fusepp/fs_interface/Node.h>
#include <memory>
namespace fspp {
class Device;
class OpenFile;
class File: public virtual Node {
public:
virtual ~File() {}
virtual std::unique_ptr<OpenFile> open(int flags) const = 0;
virtual void truncate(off_t size) const = 0;
virtual void unlink() = 0;
};
} /* namespace fspp */
#endif /* FSPP_FILE_H_ */

View File

@ -1,23 +0,0 @@
#pragma once
#ifndef FSPP_NODE_H_
#define FSPP_NODE_H_
#include <boost/filesystem.hpp>
#include <sys/stat.h>
namespace fspp {
class Node {
public:
virtual ~Node() {}
virtual void stat(struct ::stat *result) const = 0;
virtual void access(int mask) const = 0;
virtual void rename(const boost::filesystem::path &to) = 0;
virtual void utimens(const timespec times[2]) = 0;
};
} /* namespace fspp */
#endif /* FSPP_NODE_H_ */

View File

@ -1,25 +0,0 @@
#pragma once
#ifndef FSPP_OPENFILE_H_
#define FSPP_OPENFILE_H_
#include <boost/filesystem.hpp>
#include <sys/stat.h>
namespace fspp {
class Device;
class OpenFile {
public:
virtual ~OpenFile() {}
virtual void stat(struct ::stat *result) const = 0;
virtual void truncate(off_t size) const = 0;
virtual int read(void *buf, size_t count, off_t offset) = 0;
virtual void write(const void *buf, size_t count, off_t offset) = 0;
virtual void fsync() = 0;
virtual void fdatasync() = 0;
};
}
#endif /* FSPP_OPENFILE_H_ */

View File

@ -1,3 +0,0 @@
add_library(fusepp_fuse_bindings Fuse.cpp)
target_link_libraries(fusepp_fuse_bindings fuse fusepp_impl)

View File

@ -1,522 +0,0 @@
#include "Fuse.h"
#include <memory>
#include <cassert>
#include "fusepp/impl/FuseErrnoException.h"
#include "fusepp/impl/FilesystemImpl.h"
using std::unique_ptr;
using std::make_unique;
using std::string;
namespace bf = boost::filesystem;
using namespace fspp::fuse;
#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);
UNUSED(userdata); //In the Release build, the assert doesn't run
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() {
}
Fuse::Fuse(FilesystemImpl *impl)
:_impl(impl) {
}
void Fuse::run(int argc, char **argv) {
fuse_main(argc, argv, operations(), (void*)this);
}
int Fuse::getattr(const bf::path &path, struct stat *stbuf) {
//printf("getattr(%s, _, _)\n", path.c_str());
try {
_impl->lstat(path, stbuf);
return 0;
} catch(fspp::FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::fgetattr(const bf::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().
// TODO Check if necessary
if (path.native() == "/") {
return getattr(path, stbuf);
}
try {
_impl->fstat(fileinfo->fh, stbuf);
return 0;
} catch(fspp::FuseErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int Fuse::readlink(const bf::path &path, char *buf, size_t size) {
UNUSED(path);
UNUSED(buf);
UNUSED(size);
printf("Called non-implemented readlink(%s, _, %zu)\n", path.c_str(), size);
return ENOSYS;
}
int Fuse::mknod(const bf::path &path, mode_t mode, dev_t rdev) {
UNUSED(rdev);
UNUSED(mode);
UNUSED(path);
printf("Called non-implemented mknod(%s, %d, _)\n", path.c_str(), mode);
return ENOSYS;
}
int Fuse::mkdir(const bf::path &path, mode_t mode) {
//printf("mkdir(%s, %d)\n", path.c_str(), mode);
try {
_impl->mkdir(path, mode);
return 0;
} catch(fspp::FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::unlink(const bf::path &path) {
//printf("unlink(%s)\n", path.c_str());
try {
_impl->unlink(path);
return 0;
} catch(fspp::FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::rmdir(const bf::path &path) {
try {
_impl->rmdir(path);
return 0;
} catch(fspp::FuseErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int Fuse::symlink(const bf::path &from, const bf::path &to) {
printf("NOT IMPLEMENTED: symlink(%s, %s)\n", from.c_str(), to.c_str());
//auto real_from = _impl->RootDir() / from;
//auto real_to = _impl->RootDir() / to;
//int retstat = ::symlink(real_from.c_str(), real_to.c_str());
//return errcode_map(retstat);
return ENOSYS;
}
int Fuse::rename(const bf::path &from, const bf::path &to) {
//printf("rename(%s, %s)\n", from.c_str(), to.c_str());
try {
_impl->rename(from, to);
return 0;
} catch(fspp::FuseErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int Fuse::link(const bf::path &from, const bf::path &to) {
printf("NOT IMPLEMENTED: link(%s, %s)\n", from.c_str(), to.c_str());
//auto real_from = _impl->RootDir() / from;
//auto real_to = _impl->RootDir() / to;
//int retstat = ::link(real_from.c_str(), real_to.c_str());
//return errcode_map(retstat);
return ENOSYS;
}
//TODO
int Fuse::chmod(const bf::path &path, mode_t mode) {
printf("NOT IMPLEMENTED: chmod(%s, %d)\n", path.c_str(), mode);
//auto real_path = _impl->RootDir() / path;
//int retstat = ::chmod(real_path.c_str(), mode);
//return errcode_map(retstat);
return ENOSYS;
}
//TODO
int Fuse::chown(const bf::path &path, uid_t uid, gid_t gid) {
printf("NOT IMPLEMENTED: chown(%s, %d, %d)\n", path.c_str(), uid, gid);
//auto real_path = _impl->RootDir() / path;
//int retstat = ::chown(real_path.c_str(), uid, gid);
//return errcode_map(retstat);
return ENOSYS;
}
int Fuse::truncate(const bf::path &path, off_t size) {
//printf("truncate(%s, %zu)\n", path.c_str(), size);
try {
_impl->truncate(path, size);
return 0;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::ftruncate(const bf::path &path, off_t size, fuse_file_info *fileinfo) {
//printf("ftruncate(%s, %zu, _)\n", path.c_str(), size);
UNUSED(path);
try {
_impl->ftruncate(fileinfo->fh, size);
return 0;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int Fuse::utimens(const bf::path &path, const timespec times[2]) {
//printf("utimens(%s, _)\n", path.c_str());
try {
_impl->utimens(path, times);
return 0;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::open(const bf::path &path, fuse_file_info *fileinfo) {
//printf("open(%s, _)\n", path.c_str());
try {
fileinfo->fh = _impl->openFile(path, fileinfo->flags);
return 0;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::release(const bf::path &path, fuse_file_info *fileinfo) {
//printf("release(%s, _)\n", path.c_str());
UNUSED(path);
try {
_impl->closeFile(fileinfo->fh);
return 0;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::read(const bf::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);
UNUSED(path);
try {
//printf("Reading from file %d\n", fileinfo->fh);
//fflush(stdout);
return _impl->read(fileinfo->fh, buf, size, offset);
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::write(const bf::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);
UNUSED(path);
try {
_impl->write(fileinfo->fh, buf, size, offset);
return size;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int Fuse::statfs(const bf::path &path, struct statvfs *fsstat) {
//printf("statfs(%s, _)\n", path.c_str());
try {
_impl->statfs(path, fsstat);
return 0;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int Fuse::flush(const bf::path &path, fuse_file_info *fileinfo) {
//printf("Called non-implemented flush(%s, _)\n", path.c_str());
UNUSED(path);
UNUSED(fileinfo);
return 0;
}
int Fuse::fsync(const bf::path &path, int datasync, fuse_file_info *fileinfo) {
//printf("fsync(%s, %d, _)\n", path.c_str(), datasync);
UNUSED(path);
try {
if (datasync) {
_impl->fdatasync(fileinfo->fh);
} else {
_impl->fsync(fileinfo->fh);
}
return 0;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::opendir(const bf::path &path, fuse_file_info *fileinfo) {
UNUSED(path);
UNUSED(fileinfo);
//printf("opendir(%s, _)\n", path.c_str());
//We don't need opendir, because readdir works directly on the path
return 0;
}
int Fuse::readdir(const bf::path &path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) {
UNUSED(fileinfo);
//printf("readdir(%s, _, _, %zu, _)\n", path.c_str(), offset);
UNUSED(offset);
try {
auto entries = _impl->readDir(path);
for (const auto &entry : *entries) {
//We could pass file metadata to filler() in its third parameter,
//but it doesn't help performance since fuse seems to ignore it.
//It does getattr() calls on all entries nevertheless.
if (filler(buf, entry.c_str(), nullptr, 0) != 0) {
return -ENOMEM;
}
}
return 0;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::releasedir(const bf::path &path, fuse_file_info *fileinfo) {
UNUSED(path);
UNUSED(fileinfo);
//printf("releasedir(%s, _)\n", path.c_str());
//We don't need releasedir, because readdir works directly on the path
return 0;
}
//TODO
int Fuse::fsyncdir(const bf::path &path, int datasync, fuse_file_info *fileinfo) {
UNUSED(fileinfo);
UNUSED(datasync);
UNUSED(path);
//printf("Called non-implemented fsyncdir(%s, %d, _)\n", path.c_str(), datasync);
return 0;
}
void Fuse::init(fuse_conn_info *conn) {
UNUSED(conn);
//printf("init()\n");
}
void Fuse::destroy() {
//printf("destroy()\n");
}
int Fuse::access(const bf::path &path, int mask) {
//printf("access(%s, %d)\n", path.c_str(), mask);
try {
_impl->access(path, mask);
return 0;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::create(const bf::path &path, mode_t mode, fuse_file_info *fileinfo) {
//printf("create(%s, %d, _)\n", path.c_str(), mode);
try {
fileinfo->fh = _impl->createAndOpenFile(path, mode);
return 0;
} catch (FuseErrnoException &e) {
return -e.getErrno();
}
}

View File

@ -1,64 +0,0 @@
#pragma once
#ifndef FSPP_FUSE_FUSE_H_
#define FSPP_FUSE_FUSE_H_
#include "params.h"
#include <cstdio>
#include <string>
#include <sys/stat.h>
#include <boost/filesystem.hpp>
#include "../utils/macros.h"
namespace fspp {
class Device;
class FilesystemImpl;
namespace fuse {
class Fuse {
public:
Fuse(FilesystemImpl *implementation);
virtual ~Fuse();
void run(int argc, char **argv);
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:
FilesystemImpl *_impl;
DISALLOW_COPY_AND_ASSIGN(Fuse);
};
}
}
#endif /* FSPP_FUSE_FUSE_H_ */

View File

@ -1,8 +0,0 @@
#pragma once
#ifndef FSPP_FUSE_PARAMS_H_
#define FSPP_FUSE_PARAMS_H_
#define FUSE_USE_VERSION 26
#include <fuse.h>
#endif /* FSPP_FUSE_PARAMS_H_ */

View File

@ -1 +0,0 @@
add_library(fusepp_impl FilesystemImpl.cpp FuseOpenFileList.cpp IdList.cpp FuseErrnoException.cpp)

View File

@ -1,137 +0,0 @@
#include "FilesystemImpl.h"
#include <memory>
#include <fcntl.h>
#include <fusepp/fs_interface/Device.h>
#include <fusepp/fs_interface/Dir.h>
#include "FuseErrnoException.h"
#include "fusepp/fs_interface/File.h"
#include "fusepp/utils/pointer.h"
using namespace fspp;
using std::unique_ptr;
using std::make_unique;
using std::vector;
using std::string;
namespace bf = boost::filesystem;
FilesystemImpl::FilesystemImpl(Device *device)
:_device(device), _open_files() {
}
FilesystemImpl::~FilesystemImpl() {
}
unique_ptr<File> FilesystemImpl::LoadFile(const bf::path &path) {
auto node = _device->Load(path);
auto file = dynamic_pointer_move<File>(node);
if (!file) {
throw FuseErrnoException(EISDIR);
}
return file;
}
unique_ptr<Dir> FilesystemImpl::LoadDir(const bf::path &path) {
auto node = _device->Load(path);
auto dir = dynamic_pointer_move<Dir>(node);
if (!dir) {
throw FuseErrnoException(ENOTDIR);
}
return dir;
}
int FilesystemImpl::openFile(const bf::path &path, int flags) {
auto file = LoadFile(path);
return openFile(*file, flags);
}
int FilesystemImpl::openFile(const File &file, int flags) {
return _open_files.open(file, flags);
}
void FilesystemImpl::closeFile(int descriptor) {
_open_files.close(descriptor);
}
void FilesystemImpl::lstat(const bf::path &path, struct ::stat *stbuf) {
_device->Load(path)->stat(stbuf);
}
void FilesystemImpl::fstat(int descriptor, struct ::stat *stbuf) {
_open_files.get(descriptor)->stat(stbuf);
}
void FilesystemImpl::truncate(const bf::path &path, off_t size) {
LoadFile(path)->truncate(size);
}
void FilesystemImpl::ftruncate(int descriptor, off_t size) {
_open_files.get(descriptor)->truncate(size);
}
int FilesystemImpl::read(int descriptor, void *buf, size_t count, off_t offset) {
return _open_files.get(descriptor)->read(buf, count, offset);
}
void FilesystemImpl::write(int descriptor, const void *buf, size_t count, off_t offset) {
_open_files.get(descriptor)->write(buf, count, offset);
}
void FilesystemImpl::fsync(int descriptor) {
_open_files.get(descriptor)->fsync();
}
void FilesystemImpl::fdatasync(int descriptor) {
_open_files.get(descriptor)->fdatasync();
}
void FilesystemImpl::access(const bf::path &path, int mask) {
_device->Load(path)->access(mask);
}
int FilesystemImpl::createAndOpenFile(const bf::path &path, mode_t mode) {
//TODO Creating the file opens and closes it. We then reopen it afterwards.
// This is slow. Improve!
auto dir = LoadDir(path.parent_path());
auto file = dir->createFile(path.filename().native(), mode);
return openFile(*file, O_WRONLY | O_TRUNC);
}
void FilesystemImpl::mkdir(const bf::path &path, mode_t mode) {
auto dir = LoadDir(path.parent_path());
dir->createDir(path.filename().native(), mode);
}
void FilesystemImpl::rmdir(const bf::path &path) {
auto dir = LoadDir(path);
dir->rmdir();
}
void FilesystemImpl::unlink(const bf::path &path) {
auto file = LoadFile(path);
file->unlink();
}
void FilesystemImpl::rename(const bf::path &from, const bf::path &to) {
auto node = _device->Load(from);
node->rename(to);
}
unique_ptr<vector<string>> FilesystemImpl::readDir(const bf::path &path) {
auto dir = LoadDir(path);
return dir->children();
}
void FilesystemImpl::utimens(const bf::path &path, const timespec times[2]) {
auto node = _device->Load(path);
node->utimens(times);
}
void FilesystemImpl::statfs(const bf::path &path, struct statvfs *fsstat) {
_device->statfs(path, fsstat);
}

View File

@ -1,57 +0,0 @@
#pragma once
#ifndef FSPP_IMPL_FILESYSTEMIMPL_H_
#define FSPP_IMPL_FILESYSTEMIMPL_H_
#include <boost/filesystem.hpp>
#include "FuseOpenFileList.h"
#include <memory>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include "fusepp/utils/macros.h"
namespace fspp {
class Node;
class File;
class OpenFile;
class Dir;
class FilesystemImpl {
public:
FilesystemImpl(Device *device);
virtual ~FilesystemImpl();
int openFile(const boost::filesystem::path &path, int flags);
void closeFile(int descriptor);
void lstat(const boost::filesystem::path &path, struct ::stat *stbuf);
void fstat(int descriptor, struct ::stat *stbuf);
void truncate(const boost::filesystem::path &path, off_t size);
void ftruncate(int descriptor, off_t size);
int read(int descriptor, void *buf, size_t count, off_t offset);
void write(int descriptor, const void *buf, size_t count, off_t offset);
void fsync(int descriptor);
void fdatasync(int descriptor);
void access(const boost::filesystem::path &path, int mask);
int createAndOpenFile(const boost::filesystem::path &path, mode_t mode);
void mkdir(const boost::filesystem::path &path, mode_t mode);
void rmdir(const boost::filesystem::path &path);
void unlink(const boost::filesystem::path &path);
void rename(const boost::filesystem::path &from, const boost::filesystem::path &to);
std::unique_ptr<std::vector<std::string>> readDir(const boost::filesystem::path &path);
void utimens(const boost::filesystem::path &path, const timespec times[2]);
void statfs(const boost::filesystem::path &path, struct statvfs *fsstat);
private:
std::unique_ptr<File> LoadFile(const boost::filesystem::path &path);
std::unique_ptr<Dir> LoadDir(const boost::filesystem::path &path);
int openFile(const File &file, int flags);
Device *_device;
FuseOpenFileList _open_files;
DISALLOW_COPY_AND_ASSIGN(FilesystemImpl);
};
}
#endif /* FSPP_IMPL_FILESYSTEMIMPL_H_ */

View File

@ -1,24 +0,0 @@
#include "FuseErrnoException.h"
#include <cstring>
#include <cassert>
#include <string>
using std::string;
using std::runtime_error;
namespace fspp {
FuseErrnoException::FuseErrnoException(int errno_)
:runtime_error(strerror(errno_)), _errno(errno_) {
assert(_errno != 0);
}
FuseErrnoException::~FuseErrnoException() {
}
int FuseErrnoException::getErrno() const {
return _errno;
}
} /* namespace fusepp */

View File

@ -1,28 +0,0 @@
#pragma once
#ifndef FSPP_FUSE_FUSEERRNOEXCEPTION_H_
#define FSPP_FUSE_FUSEERRNOEXCEPTION_H_
#include <stdexcept>
#include <errno.h>
namespace fspp {
class FuseErrnoException: public std::runtime_error {
public:
FuseErrnoException(int errno_);
virtual ~FuseErrnoException();
int getErrno() const;
private:
int _errno;
};
inline void CHECK_RETVAL(int retval) {
if (retval < 0) {
throw FuseErrnoException(errno);
}
}
} /* namespace fspp */
#endif /* FSPP_FUSE_FUSEERRNOEXCEPTION_H_ */

View File

@ -1,6 +0,0 @@
#include "FuseOpenFileList.h"
using namespace fspp;
FuseOpenFileList::~FuseOpenFileList() {
}

View File

@ -1,46 +0,0 @@
#pragma once
#ifndef FSPP_IMPL_FUSEOPENFILELIST_H_
#define FSPP_IMPL_FUSEOPENFILELIST_H_
#include <fusepp/fs_interface/File.h>
#include <fusepp/fs_interface/OpenFile.h>
#include "fusepp/utils/macros.h"
#include "IdList.h"
namespace fspp {
class FuseOpenFileList {
public:
FuseOpenFileList();
virtual ~FuseOpenFileList();
int open(const File &rhs, int flags);
OpenFile *get(int descriptor);
void close(int descriptor);
private:
IdList<OpenFile> _open_files;
DISALLOW_COPY_AND_ASSIGN(FuseOpenFileList);
};
inline FuseOpenFileList::FuseOpenFileList()
:_open_files() {
}
inline int FuseOpenFileList::open(const File &file, int flags) {
return _open_files.add(file.open(flags));
}
inline OpenFile *FuseOpenFileList::get(int descriptor) {
return _open_files.get(descriptor);
}
inline void FuseOpenFileList::close(int descriptor) {
//The destructor of the stored FuseOpenFile closes the file
_open_files.remove(descriptor);
}
}
#endif /* FSPP_IMPL_FUSEOPENFILELIST_H_ */

View File

@ -1 +0,0 @@
#include "IdList.h"

View File

@ -1,68 +0,0 @@
#pragma once
#ifndef FSPP_FUSE_IDLIST_H_
#define FSPP_FUSE_IDLIST_H_
#include <map>
#include <memory>
#include <mutex>
#include "fusepp/utils/macros.h"
namespace fspp {
template<class Entry>
class IdList {
public:
IdList();
virtual ~IdList();
int add(std::unique_ptr<Entry> entry);
Entry *get(int id);
const Entry *get(int id) const;
void remove(int id);
private:
std::map<int, std::unique_ptr<Entry>> _entries;
int _id_counter;
mutable std::mutex _mutex;
DISALLOW_COPY_AND_ASSIGN(IdList<Entry>)
};
template<class Entry>
IdList<Entry>::IdList()
: _entries(), _id_counter(0), _mutex() {
}
template<class Entry>
IdList<Entry>::~IdList() {
}
template<class Entry>
int IdList<Entry>::add(std::unique_ptr<Entry> entry) {
std::lock_guard<std::mutex> lock(_mutex);
//TODO Reuse IDs (ids = descriptors)
int new_id = ++_id_counter;
_entries[new_id] = std::move(entry);
return new_id;
}
template<class Entry>
Entry *IdList<Entry>::get(int id) {
return const_cast<Entry*>(const_cast<const IdList<Entry>*>(this)->get(id));
}
template<class Entry>
const Entry *IdList<Entry>::get(int id) const {
std::lock_guard<std::mutex> lock(_mutex);
const Entry *result = _entries.at(id).get();
return result;
}
template<class Entry>
void IdList<Entry>::remove(int id) {
std::lock_guard<std::mutex> lock(_mutex);
_entries.erase(id);
}
} /* namespace fusepp */
#endif /* FSPP_FUSE_IDLIST_H_ */

View File

@ -1,11 +0,0 @@
#pragma once
#ifndef FSPP_UTILS_MACROS_H_
#define FSPP_UTILS_MACROS_H_
#define DISALLOW_COPY_AND_ASSIGN(Class) \
Class(const Class &rhs) = delete; \
Class &operator=(const Class &rhs) = delete;
#define UNUSED(expr) (void)(expr)
#endif /* FSPP_UTILS_MACROS_H_ */

View File

@ -1,19 +0,0 @@
#pragma once
#ifndef FSPP_UTILS_POINTER_H_
#define FSPP_UTILS_POINTER_H_
#include <memory>
namespace fspp {
template<typename DST, typename SRC>
inline std::unique_ptr<DST> dynamic_pointer_move(std::unique_ptr<SRC> &source) {
DST *casted = dynamic_cast<DST*>(source.get());
if (casted != nullptr) {
source.release();
}
return std::unique_ptr<DST>(casted);
}
}
#endif

View File

@ -3,8 +3,8 @@
#include <cstdlib>
#include "buildconfig/BuildConfig.h"
#include "fusepp/fusebindings/Fuse.h"
#include "fusepp/impl/FilesystemImpl.h"
#include "fspp/fuse/Fuse.h"
#include "fspp/impl/FilesystemImpl.h"
#include "cryfs_lib/CryDevice.h"
namespace bf = boost::filesystem;