Merge branch 'feature/abstract' into develop

This commit is contained in:
Sebastian Messmer 2014-11-15 18:10:36 +01:00
commit 70dbe8108a
43 changed files with 1152 additions and 1022 deletions

View File

@ -1,336 +0,0 @@
#include "CryFuse.h"
#include <sys/types.h>
#include <sys/time.h>
#include <dirent.h>
#include <cassert>
#include "cryfs_lib/CryNode.h"
#include "cryfs_lib/CryErrnoException.h"
#define UNUSED(expr) (void)(expr)
using fusepp::path;
namespace cryfs {
CryFuse::CryFuse(CryDevice *device)
:_device(device) {
}
int CryFuse::getattr(const path &path, struct stat *stbuf) {
//printf("getattr(%s, _, _)\n", path.c_str());
try {
_device->lstat(path, stbuf);
return 0;
} catch(cryfs::CryErrnoException &e) {
return -e.getErrno();
}
}
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().
// TODO Check if necessary
if (path.native() == "/") {
return getattr(path, stbuf);
}
try {
_device->fstat(fileinfo->fh, stbuf);
return 0;
} catch(cryfs::CryErrnoException &e) {
return -e.getErrno();
}
}
//TODO
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);
UNUSED(mode);
UNUSED(path);
printf("Called non-implemented mknod(%s, %d, _)\n", path.c_str(), mode);
return ENOSYS;
}
int CryFuse::mkdir(const path &path, mode_t mode) {
//printf("mkdir(%s, %d)\n", path.c_str(), mode);
try {
_device->mkdir(path, mode);
return 0;
} catch(cryfs::CryErrnoException &e) {
return -e.getErrno();
}
}
int CryFuse::unlink(const path &path) {
//printf("unlink(%s)\n", path.c_str());
try {
_device->unlink(path);
return 0;
} catch(cryfs::CryErrnoException &e) {
return -e.getErrno();
}
}
int CryFuse::rmdir(const path &path) {
try {
_device->rmdir(path);
return 0;
} catch(cryfs::CryErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int CryFuse::symlink(const path &from, const path &to) {
printf("NOT IMPLEMENTED: 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);
return ENOSYS;
}
int CryFuse::rename(const path &from, const path &to) {
//printf("rename(%s, %s)\n", from.c_str(), to.c_str());
try {
_device->rename(from, to);
return 0;
} catch(cryfs::CryErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int CryFuse::link(const path &from, const path &to) {
printf("NOT IMPLEMENTED: 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);
return ENOSYS;
}
//TODO
int CryFuse::chmod(const path &path, mode_t mode) {
printf("NOT IMPLEMENTED: 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);
return ENOSYS;
}
//TODO
int CryFuse::chown(const path &path, uid_t uid, gid_t gid) {
printf("NOT IMPLEMENTED: 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);
return ENOSYS;
}
int CryFuse::truncate(const path &path, off_t size) {
//printf("truncate(%s, %zu)\n", path.c_str(), size);
try {
_device->truncate(path, size);
return 0;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
int CryFuse::ftruncate(const path &path, off_t size, fuse_file_info *fileinfo) {
//printf("ftruncate(%s, %zu, _)\n", path.c_str(), size);
UNUSED(path);
try {
_device->ftruncate(fileinfo->fh, size);
return 0;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int CryFuse::utimens(const path &path, const timespec times[2]) {
//printf("utimens(%s, _)\n", path.c_str());
try {
_device->utimens(path, times);
return 0;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
int CryFuse::open(const path &path, fuse_file_info *fileinfo) {
//printf("open(%s, _)\n", path.c_str());
try {
fileinfo->fh = _device->openFile(path, fileinfo->flags);
return 0;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
int CryFuse::release(const path &path, fuse_file_info *fileinfo) {
//printf("release(%s, _)\n", path.c_str());
UNUSED(path);
try {
_device->closeFile(fileinfo->fh);
return 0;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
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);
UNUSED(path);
try {
//printf("Reading from file %d\n", fileinfo->fh);
//fflush(stdout);
return _device->read(fileinfo->fh, buf, size, offset);
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
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);
UNUSED(path);
try {
_device->write(fileinfo->fh, buf, size, offset);
return size;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int CryFuse::statfs(const path &path, struct statvfs *fsstat) {
//printf("statfs(%s, _)\n", path.c_str());
try {
_device->statfs(path, fsstat);
return 0;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
//TODO
int CryFuse::flush(const path &path, fuse_file_info *fileinfo) {
//printf("Called non-implemented flush(%s, _)\n", path.c_str());
UNUSED(path);
UNUSED(fileinfo);
return 0;
}
int CryFuse::fsync(const path &path, int datasync, fuse_file_info *fileinfo) {
//printf("fsync(%s, %d, _)\n", path.c_str(), datasync);
UNUSED(path);
try {
if (datasync) {
_device->fdatasync(fileinfo->fh);
} else {
_device->fsync(fileinfo->fh);
}
return 0;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
int CryFuse::opendir(const 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 CryFuse::readdir(const 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 = _device->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 (CryErrnoException &e) {
return -e.getErrno();
}
}
int CryFuse::releasedir(const 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 CryFuse::fsyncdir(const 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 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);
try {
_device->access(path, mask);
return 0;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
int CryFuse::create(const path &path, mode_t mode, fuse_file_info *fileinfo) {
//printf("create(%s, %d, _)\n", path.c_str(), mode);
try {
fileinfo->fh = _device->createAndOpenFile(path, mode);
return 0;
} catch (CryErrnoException &e) {
return -e.getErrno();
}
}
} /* namespace cryfs */

View File

@ -1,54 +0,0 @@
#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_ */

View File

@ -1,3 +1,3 @@
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryErrnoException.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp CryOpenFileList.cpp IdList.cpp)
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryFile.cpp CryNode.cpp CryOpenFile.cpp)
target_link_libraries(cryfs_lib boost_filesystem)
target_link_libraries(cryfs_lib boost_filesystem boost_system)

View File

@ -1,29 +1,27 @@
#include "../cryfs_lib/CryDevice.h"
#include <memory>
#include <fcntl.h>
#include "CryDevice.h"
#include "CryDir.h"
#include "CryFile.h"
#include "CryOpenFile.h"
#include "CryErrnoException.h"
#include "utils/pointer.h"
using namespace cryfs;
#include "fusepp/impl/FuseErrnoException.h"
using std::unique_ptr;
using std::unique_ptr;
using std::make_unique;
using std::vector;
using std::string;
CryDevice::CryDevice(const bf::path &rootdir)
:_rootdir(rootdir), _open_files() {
//TODO Get rid of this in favor of exception hierarchy
using fusepp::CHECK_RETVAL;
namespace cryfs {
CryDevice::CryDevice(const bf::path &root_path): _root_path(root_path) {
}
CryDevice::~CryDevice() {
}
unique_ptr<CryNode> CryDevice::Load(const bf::path &path) {
unique_ptr<fusepp::FuseNode> CryDevice::Load(const bf::path &path) {
auto real_path = RootDir() / path;
if(bf::is_directory(real_path)) {
return make_unique<CryDir>(this, path);
@ -31,115 +29,13 @@ unique_ptr<CryNode> CryDevice::Load(const bf::path &path) {
return make_unique<CryFile>(this, path);
}
throw CryErrnoException(ENOENT);
}
unique_ptr<CryFile> CryDevice::LoadFile(const bf::path &path) {
auto node = Load(path);
auto file = dynamic_pointer_move<CryFile>(node);
if (!file) {
throw CryErrnoException(EISDIR);
}
return file;
}
unique_ptr<CryDir> CryDevice::LoadDir(const bf::path &path) {
auto node = Load(path);
auto dir = dynamic_pointer_move<CryDir>(node);
if (!dir) {
throw CryErrnoException(ENOTDIR);
}
return dir;
}
int CryDevice::openFile(const bf::path &path, int flags) {
auto file = LoadFile(path);
return openFile(*file, flags);
}
int CryDevice::openFile(const CryFile &file, int flags) {
return _open_files.open(file, flags);
}
void CryDevice::closeFile(int descriptor) {
_open_files.close(descriptor);
}
void CryDevice::lstat(const bf::path &path, struct ::stat *stbuf) {
Load(path)->stat(stbuf);
}
void CryDevice::fstat(int descriptor, struct ::stat *stbuf) {
_open_files.get(descriptor)->stat(stbuf);
}
void CryDevice::truncate(const bf::path &path, off_t size) {
LoadFile(path)->truncate(size);
}
void CryDevice::ftruncate(int descriptor, off_t size) {
_open_files.get(descriptor)->truncate(size);
}
int CryDevice::read(int descriptor, void *buf, size_t count, off_t offset) {
return _open_files.get(descriptor)->read(buf, count, offset);
}
void CryDevice::write(int descriptor, const void *buf, size_t count, off_t offset) {
_open_files.get(descriptor)->write(buf, count, offset);
}
void CryDevice::fsync(int descriptor) {
_open_files.get(descriptor)->fsync();
}
void CryDevice::fdatasync(int descriptor) {
_open_files.get(descriptor)->fdatasync();
}
void CryDevice::access(const bf::path &path, int mask) {
Load(path)->access(mask);
}
int CryDevice::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 CryDevice::mkdir(const bf::path &path, mode_t mode) {
auto dir = LoadDir(path.parent_path());
dir->createDir(path.filename().native(), mode);
}
void CryDevice::rmdir(const bf::path &path) {
auto dir = LoadDir(path);
dir->rmdir();
}
void CryDevice::unlink(const bf::path &path) {
auto file = LoadFile(path);
file->unlink();
}
void CryDevice::rename(const bf::path &from, const bf::path &to) {
auto node = Load(from);
node->rename(to);
}
unique_ptr<vector<string>> CryDevice::readDir(const bf::path &path) {
auto dir = LoadDir(path);
return dir->children();
}
void CryDevice::utimens(const bf::path &path, const timespec times[2]) {
auto node = Load(path);
node->utimens(times);
throw fusepp::FuseErrnoException(ENOENT);
}
void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) {
int retval = ::statvfs(path.c_str(), fsstat);
auto real_path = RootDir() / path;
int retval = ::statvfs(real_path.c_str(), fsstat);
CHECK_RETVAL(retval);
}
} /* namespace cryfs */

View File

@ -3,62 +3,34 @@
#define CRYFS_LIB_CRYDEVICE_H_
#include <boost/filesystem.hpp>
#include <memory>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include "utils/macros.h"
#include "CryOpenFileList.h"
#include "fusepp/fs_interface/FuseDevice.h"
#include "fusepp/utils/macros.h"
namespace cryfs {
class CryNode;
class CryFile;
class CryOpenFile;
class CryDir;
namespace bf = boost::filesystem;
class CryDevice {
class CryDevice: public fusepp::FuseDevice {
public:
CryDevice(const bf::path &rootdir);
virtual ~CryDevice();
CryDevice(const bf::path &rootdir);
virtual ~CryDevice();
int openFile(const bf::path &path, int flags);
void closeFile(int descriptor);
void lstat(const bf::path &path, struct ::stat *stbuf);
void fstat(int descriptor, struct ::stat *stbuf);
void truncate(const bf::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 bf::path &path, int mask);
int createAndOpenFile(const bf::path &path, mode_t mode);
void mkdir(const bf::path &path, mode_t mode);
void rmdir(const bf::path &path);
void unlink(const bf::path &path);
void rename(const bf::path &from, const bf::path &to);
std::unique_ptr<std::vector<std::string>> readDir(const bf::path &path);
void utimens(const bf::path &path, const timespec times[2]);
void statfs(const bf::path &path, struct statvfs *fsstat);
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
const bf::path &RootDir() const;
const bf::path &RootDir() const;
private:
std::unique_ptr<CryNode> Load(const bf::path &path);
std::unique_ptr<CryFile> LoadFile(const bf::path &path);
std::unique_ptr<CryDir> LoadDir(const bf::path &path);
int openFile(const CryFile &file, int flags);
const bf::path _rootdir;
CryOpenFileList _open_files;
std::unique_ptr<fusepp::FuseNode> Load(const bf::path &path) override;
const bf::path _root_path;
DISALLOW_COPY_AND_ASSIGN(CryDevice);
};
inline const bf::path &CryDevice::RootDir() const {
return _rootdir;
return _root_path;
}
}
} /* namespace cryfs */
#endif /* CRYFS_LIB_CRYDEVICE_H_ */

View File

@ -5,13 +5,18 @@
#include <fcntl.h>
#include <dirent.h>
#include "fusepp/impl/FuseErrnoException.h"
#include "CryDevice.h"
#include "CryFile.h"
#include "CryErrnoException.h"
using std::string;
//TODO Get rid of this in favor of exception hierarchy
using fusepp::CHECK_RETVAL;
namespace bf = boost::filesystem;
using std::unique_ptr;
using std::make_unique;
using std::string;
using std::vector;
namespace cryfs {
@ -24,7 +29,7 @@ CryDir::CryDir(CryDevice *device, const bf::path &path)
CryDir::~CryDir() {
}
unique_ptr<CryFile> CryDir::createFile(const string &name, mode_t mode) {
unique_ptr<fusepp::FuseFile> CryDir::createFile(const string &name, mode_t mode) {
auto file_path = base_path() / name;
//Create file
int fd = ::creat(file_path.c_str(), mode);
@ -33,7 +38,7 @@ unique_ptr<CryFile> CryDir::createFile(const string &name, mode_t mode) {
return make_unique<CryFile>(device(), path() / name);
}
unique_ptr<CryDir> CryDir::createDir(const string &name, mode_t mode) {
unique_ptr<fusepp::FuseDir> CryDir::createDir(const string &name, mode_t mode) {
auto dir_path = base_path() / name;
//Create dir
int retval = ::mkdir(dir_path.c_str(), mode);
@ -49,7 +54,7 @@ void CryDir::rmdir() {
unique_ptr<vector<string>> CryDir::children() const {
DIR *dir = ::opendir(base_path().c_str());
if (dir == nullptr) {
throw CryErrnoException(errno);
throw fusepp::FuseErrnoException(errno);
}
// Set errno=0 so we can detect whether it changed later
@ -66,7 +71,7 @@ unique_ptr<vector<string>> CryDir::children() const {
if (errno != 0) {
int readdir_errno = errno;
::closedir(dir);
throw CryErrnoException(readdir_errno);
throw fusepp::FuseErrnoException(readdir_errno);
}
int retval = ::closedir(dir);
CHECK_RETVAL(retval);

View File

@ -2,26 +2,22 @@
#ifndef CRYFS_LIB_CRYDIR_H_
#define CRYFS_LIB_CRYDIR_H_
#include <memory>
#include <string>
#include "fusepp/fs_interface/FuseDir.h"
#include "CryNode.h"
#include "utils/macros.h"
namespace cryfs {
class CryDevice;
class CryOpenDir;
class CryDir: public CryNode {
class CryDir: public fusepp::FuseDir, CryNode {
public:
CryDir(CryDevice *device, const bf::path &path);
virtual ~CryDir();
std::unique_ptr<CryFile> createFile(const std::string &name, mode_t mode);
std::unique_ptr<CryDir> createDir(const std::string &name, mode_t mode);
void rmdir();
//TODO return type variance to CryFile/CryDir?
std::unique_ptr<fusepp::FuseFile> createFile(const std::string &name, mode_t mode) override;
std::unique_ptr<fusepp::FuseDir> createDir(const std::string &name, mode_t mode) override;
void rmdir() override;
std::unique_ptr<std::vector<std::string>> children() const;
std::unique_ptr<std::vector<std::string>> children() const override;
private:
DISALLOW_COPY_AND_ASSIGN(CryDir);
@ -29,4 +25,4 @@ private:
} /* namespace cryfs */
#endif /* CRYFS_LIB_CRYDIR_H_ */
#endif

View File

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

View File

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

View File

@ -1,7 +1,13 @@
#include "CryFile.h"
#include "CryOpenFile.h"
#include "CryErrnoException.h"
#include "CryDevice.h"
#include "CryOpenFile.h"
#include "fusepp/impl/FuseErrnoException.h"
namespace bf = boost::filesystem;
//TODO Get rid of this in favor of exception hierarchy
using fusepp::CHECK_RETVAL;
using std::unique_ptr;
using std::make_unique;
@ -16,7 +22,7 @@ CryFile::CryFile(CryDevice *device, const bf::path &path)
CryFile::~CryFile() {
}
std::unique_ptr<CryOpenFile> CryFile::open(int flags) const {
unique_ptr<fusepp::FuseOpenFile> CryFile::open(int flags) const {
return make_unique<CryOpenFile>(device(), path(), flags);
}

View File

@ -2,27 +2,24 @@
#ifndef CRYFS_LIB_CRYFILE_H_
#define CRYFS_LIB_CRYFILE_H_
#include <memory>
#include "CryNode.h"
#include "utils/macros.h"
#include "fusepp/fs_interface/FuseFile.h"
namespace cryfs {
class CryDevice;
class CryOpenFile;
class CryFile: public CryNode {
class CryFile: public fusepp::FuseFile, CryNode {
public:
CryFile(CryDevice *device, const bf::path &path);
CryFile(CryDevice *device, const boost::filesystem::path &path);
virtual ~CryFile();
std::unique_ptr<CryOpenFile> open(int flags) const;
void truncate(off_t size) const;
void unlink();
std::unique_ptr<fusepp::FuseOpenFile> open(int flags) const override;
void truncate(off_t size) const override;
void unlink() override;
private:
DISALLOW_COPY_AND_ASSIGN(CryFile);
};
} /* namespace cryfs */
#endif /* CRYFS_LIB_CRYFILE_H_ */
#endif

View File

@ -3,7 +3,12 @@
#include <sys/time.h>
#include "CryDevice.h"
#include "CryErrnoException.h"
#include "fusepp/impl/FuseErrnoException.h"
namespace bf = boost::filesystem;
//TODO Get rid of this in favor of an exception hierarchy
using fusepp::CHECK_RETVAL;
namespace cryfs {

View File

@ -2,44 +2,41 @@
#ifndef CRYFS_LIB_CRYNODE_H_
#define CRYFS_LIB_CRYNODE_H_
#include <boost/filesystem.hpp>
#include "fusepp/fs_interface/FuseNode.h"
#include "fusepp/utils/macros.h"
#include "utils/macros.h"
#include "CryDevice.h"
#include <sys/stat.h>
namespace cryfs {
namespace bf = boost::filesystem;
class CryNode {
class CryNode: public virtual fusepp::FuseNode {
public:
CryNode(CryDevice *device, const bf::path &path);
CryNode(CryDevice *device, const boost::filesystem::path &path);
virtual ~CryNode();
void stat(struct ::stat *result) const;
void access(int mask) const;
void rename(const bf::path &to);
void utimens(const timespec times[2]);
void stat(struct ::stat *result) const override;
void access(int mask) const override;
void rename(const boost::filesystem::path &to) override;
void utimens(const timespec times[2]) override;
protected:
bf::path base_path() const;
const bf::path &path() const;
boost::filesystem::path base_path() const;
const boost::filesystem::path &path() const;
CryDevice *device();
const CryDevice *device() const;
private:
CryDevice *const _device;
bf::path _path;
boost::filesystem::path _path;
DISALLOW_COPY_AND_ASSIGN(CryNode);
};
inline bf::path CryNode::base_path() const {
inline boost::filesystem::path CryNode::base_path() const {
return _device->RootDir() / _path;
}
inline const bf::path &CryNode::path() const {
inline const boost::filesystem::path &CryNode::path() const {
return _path;
}
@ -53,4 +50,4 @@ inline const CryDevice *CryNode::device() const {
} /* namespace cryfs */
#endif /* CRYFS_LIB_CRYNODE_H_ */
#endif

View File

@ -1,12 +1,17 @@
#include <cryfs_lib/CryOpenFile.h>
#include "CryOpenFile.h"
#include <sys/types.h>
#include <fcntl.h>
#include "CryErrnoException.h"
#include "CryDevice.h"
#include "fusepp/impl/FuseErrnoException.h"
using namespace cryfs;
namespace bf = boost::filesystem;
//TODO Get rid of this in favor of a exception hierarchy
using fusepp::CHECK_RETVAL;
namespace cryfs {
CryOpenFile::CryOpenFile(const CryDevice *device, const bf::path &path, int flags)
:_descriptor(::open((device->RootDir() / path).c_str(), flags)) {
@ -54,3 +59,5 @@ void CryOpenFile::fdatasync() {
int retval = ::fdatasync(_descriptor);
CHECK_RETVAL(retval);
}
} /* namespace cryfs */

View File

@ -1,33 +1,31 @@
#pragma once
#ifndef CRYFS_LIB_CRYOPENFILE_H_
#define CRYFS_LIB_CRYOPENFILE_H_
#include <boost/filesystem.hpp>
#include <sys/stat.h>
#include "utils/macros.h"
#include "fusepp/fs_interface/FuseOpenFile.h"
#include "fusepp/utils/macros.h"
namespace cryfs {
class CryDevice;
namespace bf = boost::filesystem;
class CryOpenFile {
class CryOpenFile: public fusepp::FuseOpenFile {
public:
CryOpenFile(const CryDevice *device, const bf::path &path, int flags);
CryOpenFile(const CryDevice *device, const boost::filesystem::path &path, int flags);
virtual ~CryOpenFile();
void stat(struct ::stat *result) const;
void truncate(off_t size) const;
int read(void *buf, size_t count, off_t offset);
void write(const void *buf, size_t count, off_t offset);
void fsync();
void fdatasync();
void stat(struct ::stat *result) const override;
void truncate(off_t size) const override;
int read(void *buf, size_t count, off_t offset) override;
void write(const void *buf, size_t count, off_t offset) override;
void fsync() override;
void fdatasync() override;
private:
int _descriptor;
DISALLOW_COPY_AND_ASSIGN(CryOpenFile);
};
}
} /* namespace cryfs */
#endif /* CRYFS_LIB_CRYOPENFILE_H_ */
#endif

View File

@ -1,25 +0,0 @@
#include <cryfs_lib/CryOpenFileList.h>
#include "CryFile.h"
#include "CryOpenFile.h"
using namespace cryfs;
CryOpenFileList::~CryOpenFileList() {
}
CryOpenFileList::CryOpenFileList()
:_open_files() {
}
int CryOpenFileList::open(const CryFile &file, int flags) {
return _open_files.add(file.open(flags));
}
CryOpenFile *CryOpenFileList::get(int descriptor) {
return _open_files.get(descriptor);
}
void CryOpenFileList::close(int descriptor) {
//The destructor of the stored CryOpenFile closes the file
_open_files.remove(descriptor);
}

View File

@ -1,28 +0,0 @@
#ifndef CRYFS_LIB_CRYOPENFILELIST_H_
#define CRYFS_LIB_CRYOPENFILELIST_H_
#include "utils/macros.h"
#include "IdList.h"
namespace cryfs {
class CryOpenFile;
class CryFile;
class CryOpenFileList {
public:
CryOpenFileList();
virtual ~CryOpenFileList();
int open(const CryFile &rhs, int flags);
CryOpenFile *get(int descriptor);
void close(int descriptor);
private:
IdList<CryOpenFile> _open_files;
DISALLOW_COPY_AND_ASSIGN(CryOpenFileList);
};
}
#endif /* CRYFS_LIB_CRYOPENFILELIST_H_ */

View File

@ -1,5 +0,0 @@
#include <cryfs_lib/IdList.h>
namespace cryfs {
} /* namespace cryfs */

View File

@ -1,3 +1,2 @@
add_library(fusepp Fuse.cpp)
target_link_libraries(fusepp fuse boost_filesystem boost_system)
add_subdirectory(fusebindings)
add_subdirectory(impl)

View File

@ -1,208 +0,0 @@
#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)
#define UNUSED(obj) (void)obj
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() {
}
void Fuse::run(int argc, char **argv) {
fuse_main(argc, argv, operations(), (void*)this);
}

View File

@ -1,58 +0,0 @@
#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_ */

View File

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

View File

@ -0,0 +1,26 @@
#pragma once
#ifndef FUSEPP_FUSEDIR_H_
#define FUSEPP_FUSEDIR_H_
#include "FuseNode.h"
#include <memory>
#include <string>
namespace fusepp {
class FuseDevice;
class FuseFile;
class FuseDir: public virtual FuseNode {
public:
virtual ~FuseDir() {}
virtual std::unique_ptr<FuseFile> createFile(const std::string &name, mode_t mode) = 0;
virtual std::unique_ptr<FuseDir> 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 fusepp */
#endif /* FUSEPP_FUSEDIR_H_ */

View File

@ -0,0 +1,23 @@
#pragma once
#ifndef FUSEPP_FUSEFILE_H_
#define FUSEPP_FUSEFILE_H_
#include "FuseNode.h"
#include <memory>
namespace fusepp {
class FuseDevice;
class FuseOpenFile;
class FuseFile: public virtual FuseNode {
public:
virtual ~FuseFile() {}
virtual std::unique_ptr<FuseOpenFile> open(int flags) const = 0;
virtual void truncate(off_t size) const = 0;
virtual void unlink() = 0;
};
} /* namespace fusepp */
#endif /* FUSEPP_FUSEFILE_H_ */

View File

@ -0,0 +1,23 @@
#pragma once
#ifndef FUSEPP_FUSENODE_H_
#define FUSEPP_FUSENODE_H_
#include <boost/filesystem.hpp>
#include <sys/stat.h>
namespace fusepp {
class FuseNode {
public:
virtual ~FuseNode() {}
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 fusepp */
#endif /* FUSEPP_FUSENODE_H_ */

View File

@ -0,0 +1,25 @@
#pragma once
#ifndef FUSEPP_FUSEOPENFILE_H_
#define FUSEPP_FUSEOPENFILE_H_
#include <boost/filesystem.hpp>
#include <sys/stat.h>
namespace fusepp {
class FuseDevice;
class FuseOpenFile {
public:
virtual ~FuseOpenFile() {}
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 /* FUSEPP_FUSEOPENFILE_H_ */

View File

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

View File

@ -0,0 +1,522 @@
#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 fusepp::fusebindings;
#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(fusepp::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(fusepp::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(fusepp::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(fusepp::FuseErrnoException &e) {
return -e.getErrno();
}
}
int Fuse::rmdir(const bf::path &path) {
try {
_impl->rmdir(path);
return 0;
} catch(fusepp::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(fusepp::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

@ -0,0 +1,65 @@
#pragma once
#ifndef FUSEPP_FUSE_H_
#define FUSEPP_FUSE_H_
#include "params.h"
#include <fuse.h>
#include <cstdio>
#include <string>
#include <sys/stat.h>
#include <boost/filesystem.hpp>
#include "../utils/macros.h"
namespace fusepp {
class FuseDevice;
class FilesystemImpl;
namespace fusebindings {
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 /* FUSEPP_FUSE_H_ */

View File

@ -0,0 +1,7 @@
#pragma once
#ifndef FUSEPP_PARAMS_H_
#define FUSEPP_PARAMS_H_
#define FUSE_USE_VERSION 26
#endif /* FUSEPP_PARAMS_H_ */

View File

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

View File

@ -0,0 +1,137 @@
#include "FilesystemImpl.h"
#include <memory>
#include <fcntl.h>
#include "fusepp/fs_interface/FuseDevice.h"
#include "fusepp/fs_interface/FuseDir.h"
#include "FuseErrnoException.h"
#include "fusepp/fs_interface/FuseFile.h"
#include "fusepp/utils/pointer.h"
using namespace fusepp;
using std::unique_ptr;
using std::make_unique;
using std::vector;
using std::string;
namespace bf = boost::filesystem;
FilesystemImpl::FilesystemImpl(FuseDevice *device)
:_device(device), _open_files() {
}
FilesystemImpl::~FilesystemImpl() {
}
unique_ptr<FuseFile> FilesystemImpl::LoadFile(const bf::path &path) {
auto node = _device->Load(path);
auto file = dynamic_pointer_move<FuseFile>(node);
if (!file) {
throw FuseErrnoException(EISDIR);
}
return file;
}
unique_ptr<FuseDir> FilesystemImpl::LoadDir(const bf::path &path) {
auto node = _device->Load(path);
auto dir = dynamic_pointer_move<FuseDir>(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 FuseFile &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

@ -0,0 +1,57 @@
#pragma once
#ifndef FUSEPP_FILESYSTEMIMPL_H_
#define FUSEPP_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 fusepp {
class FuseNode;
class FuseFile;
class FuseOpenFile;
class FuseDir;
class FilesystemImpl {
public:
FilesystemImpl(FuseDevice *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<FuseFile> LoadFile(const boost::filesystem::path &path);
std::unique_ptr<FuseDir> LoadDir(const boost::filesystem::path &path);
int openFile(const FuseFile &file, int flags);
FuseDevice *_device;
FuseOpenFileList _open_files;
DISALLOW_COPY_AND_ASSIGN(FilesystemImpl);
};
}
#endif /* FUSEPP_FILESYSTEMIMPL_H_ */

View File

@ -0,0 +1,24 @@
#include "FuseErrnoException.h"
#include <cstring>
#include <cassert>
#include <string>
using std::string;
using std::runtime_error;
namespace fusepp {
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

@ -0,0 +1,28 @@
#pragma once
#ifndef FUSEPP_FUSEERRNOEXCEPTION_H_
#define FUSEPP_FUSEERRNOEXCEPTION_H_
#include <stdexcept>
#include <errno.h>
namespace fusepp {
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 fusepp */
#endif /* FUSEPP_FUSEERRNOEXCEPTION_H_ */

View File

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

View File

@ -0,0 +1,46 @@
#pragma once
#ifndef FUSEPP_FUSEOPENFILELIST_H_
#define FUSEPP_FUSEOPENFILELIST_H_
#include "fusepp/utils/macros.h"
#include "IdList.h"
#include "fusepp/fs_interface/FuseFile.h"
#include "fusepp/fs_interface/FuseOpenFile.h"
namespace fusepp {
class FuseOpenFileList {
public:
FuseOpenFileList();
virtual ~FuseOpenFileList();
int open(const FuseFile &rhs, int flags);
FuseOpenFile *get(int descriptor);
void close(int descriptor);
private:
IdList<FuseOpenFile> _open_files;
DISALLOW_COPY_AND_ASSIGN(FuseOpenFileList);
};
inline FuseOpenFileList::FuseOpenFileList()
:_open_files() {
}
inline int FuseOpenFileList::open(const FuseFile &file, int flags) {
return _open_files.add(file.open(flags));
}
inline FuseOpenFile *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 /* FUSEPP_FUSEOPENFILELIST_H_ */

View File

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

View File

@ -1,12 +1,13 @@
#ifndef CRYFS_LIB_IDLIST_H_
#define CRYFS_LIB_IDLIST_H_
#pragma once
#ifndef FUSEPP_IDLIST_H_
#define FUSEPP_IDLIST_H_
#include <map>
#include <memory>
#include <mutex>
#include "utils/macros.h"
#include "fusepp/utils/macros.h"
namespace cryfs {
namespace fusepp {
template<class Entry>
class IdList {
@ -62,6 +63,6 @@ void IdList<Entry>::remove(int id) {
_entries.erase(id);
}
} /* namespace cryfs */
} /* namespace fusepp */
#endif /* CRYFS_LIB_IDLIST_H_ */
#endif /* FUSEPP_IDLIST_H_ */

View File

@ -1,7 +0,0 @@
#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_ */

View File

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

View File

@ -1,10 +1,11 @@
#pragma once
#ifndef CRYFS_LIB_UTILS_POINTER_H_
#define CRYFS_LIB_UTILS_POINTER_H_
#ifndef FUSEPP_UTILS_POINTER_H_
#define FUSEPP_UTILS_POINTER_H_
#include <memory>
namespace cryfs {
namespace fusepp {
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());

View File

@ -3,13 +3,18 @@
#include <cstdlib>
#include "buildconfig/BuildConfig.h"
#include "CryFuse.h"
#include "fusepp/fusebindings/Fuse.h"
#include "fusepp/impl/FilesystemImpl.h"
#include "cryfs_lib/CryDevice.h"
namespace bf = boost::filesystem;
int main (int argc, char *argv[])
{
printf("Version: %d\n", buildconfig::VERSION::MAJOR);
cryfs::CryDevice device(fusepp::path("/home/heinzi/cryfstest/root"));
cryfs::CryFuse fuse(&device);
cryfs::CryDevice device(bf::path("/home/heinzi/cryfstest/root"));
fusepp::FilesystemImpl fsimpl(&device);
fusepp::fusebindings::Fuse fuse(&fsimpl);
fuse.run(argc, argv);
return 0;
}