Put fuse bindings in their own directory

This commit is contained in:
Sebastian Messmer 2014-11-15 17:24:07 +01:00
parent 382a7b89f1
commit 6dce6ffd80
36 changed files with 235 additions and 202 deletions

View File

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

View File

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

View File

@ -4,7 +4,8 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "fusepp/FuseDevice.h" #include "fusepp/fs_interface/FuseDevice.h"
#include "fusepp/utils/macros.h"
namespace cryfs { namespace cryfs {
@ -15,7 +16,7 @@ public:
CryDevice(const bf::path &rootdir); CryDevice(const bf::path &rootdir);
virtual ~CryDevice(); virtual ~CryDevice();
void statfs(const boost::filesystem::path &path, struct statvfs *fsstat) override; void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
const bf::path &RootDir() const; const bf::path &RootDir() const;
private: private:

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@
#define CRYFS_LIB_CRYFILE_H_ #define CRYFS_LIB_CRYFILE_H_
#include "CryNode.h" #include "CryNode.h"
#include "fusepp/FuseFile.h" #include "fusepp/fs_interface/FuseFile.h"
namespace cryfs { namespace cryfs {

View File

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

View File

@ -2,7 +2,7 @@
#ifndef CRYFS_LIB_CRYNODE_H_ #ifndef CRYFS_LIB_CRYNODE_H_
#define CRYFS_LIB_CRYNODE_H_ #define CRYFS_LIB_CRYNODE_H_
#include "fusepp/FuseNode.h" #include "fusepp/fs_interface/FuseNode.h"
#include "fusepp/utils/macros.h" #include "fusepp/utils/macros.h"
#include "CryDevice.h" #include "CryDevice.h"

View File

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

View File

@ -2,7 +2,7 @@
#ifndef CRYFS_LIB_CRYOPENFILE_H_ #ifndef CRYFS_LIB_CRYOPENFILE_H_
#define CRYFS_LIB_CRYOPENFILE_H_ #define CRYFS_LIB_CRYOPENFILE_H_
#include "fusepp/FuseOpenFile.h" #include "fusepp/fs_interface/FuseOpenFile.h"
#include "fusepp/utils/macros.h" #include "fusepp/utils/macros.h"
namespace cryfs { namespace cryfs {

View File

@ -1,3 +1,2 @@
add_library(fusepp Fuse.cpp FuseDevice.cpp FuseDir.cpp FuseErrnoException.cpp FuseFile.cpp FuseNode.cpp FuseOpenFile.cpp FuseOpenFileList.cpp IdList.cpp) add_subdirectory(fusebindings)
add_subdirectory(impl)
target_link_libraries(fusepp fuse boost_filesystem boost_system)

View File

@ -1,132 +0,0 @@
#include "FuseDevice.h"
#include <memory>
#include <fcntl.h>
#include "FuseDir.h"
#include "FuseErrnoException.h"
#include "FuseFile.h"
#include "utils/pointer.h"
using namespace fusepp;
using std::unique_ptr;
using std::make_unique;
using std::vector;
using std::string;
namespace bf = boost::filesystem;
FuseDevice::FuseDevice()
:_open_files() {
}
FuseDevice::~FuseDevice() {
}
unique_ptr<FuseFile> FuseDevice::LoadFile(const bf::path &path) {
auto node = Load(path);
auto file = dynamic_pointer_move<FuseFile>(node);
if (!file) {
throw FuseErrnoException(EISDIR);
}
return file;
}
unique_ptr<FuseDir> FuseDevice::LoadDir(const bf::path &path) {
auto node = Load(path);
auto dir = dynamic_pointer_move<FuseDir>(node);
if (!dir) {
throw FuseErrnoException(ENOTDIR);
}
return dir;
}
int FuseDevice::openFile(const bf::path &path, int flags) {
auto file = LoadFile(path);
return openFile(*file, flags);
}
int FuseDevice::openFile(const FuseFile &file, int flags) {
return _open_files.open(file, flags);
}
void FuseDevice::closeFile(int descriptor) {
_open_files.close(descriptor);
}
void FuseDevice::lstat(const bf::path &path, struct ::stat *stbuf) {
Load(path)->stat(stbuf);
}
void FuseDevice::fstat(int descriptor, struct ::stat *stbuf) {
_open_files.get(descriptor)->stat(stbuf);
}
void FuseDevice::truncate(const bf::path &path, off_t size) {
LoadFile(path)->truncate(size);
}
void FuseDevice::ftruncate(int descriptor, off_t size) {
_open_files.get(descriptor)->truncate(size);
}
int FuseDevice::read(int descriptor, void *buf, size_t count, off_t offset) {
return _open_files.get(descriptor)->read(buf, count, offset);
}
void FuseDevice::write(int descriptor, const void *buf, size_t count, off_t offset) {
_open_files.get(descriptor)->write(buf, count, offset);
}
void FuseDevice::fsync(int descriptor) {
_open_files.get(descriptor)->fsync();
}
void FuseDevice::fdatasync(int descriptor) {
_open_files.get(descriptor)->fdatasync();
}
void FuseDevice::access(const bf::path &path, int mask) {
Load(path)->access(mask);
}
int FuseDevice::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 FuseDevice::mkdir(const bf::path &path, mode_t mode) {
auto dir = LoadDir(path.parent_path());
dir->createDir(path.filename().native(), mode);
}
void FuseDevice::rmdir(const bf::path &path) {
auto dir = LoadDir(path);
dir->rmdir();
}
void FuseDevice::unlink(const bf::path &path) {
auto file = LoadFile(path);
file->unlink();
}
void FuseDevice::rename(const bf::path &from, const bf::path &to) {
auto node = Load(from);
node->rename(to);
}
unique_ptr<vector<string>> FuseDevice::readDir(const bf::path &path) {
auto dir = LoadDir(path);
return dir->children();
}
void FuseDevice::utimens(const bf::path &path, const timespec times[2]) {
auto node = Load(path);
node->utimens(times);
}

View File

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

View File

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

View File

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

View File

@ -1 +0,0 @@
#include "FuseOpenFile.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

@ -4,7 +4,6 @@
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "utils/macros.h"
#include <sys/stat.h> #include <sys/stat.h>
namespace fusepp { namespace fusepp {

View File

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

View File

@ -2,8 +2,8 @@
#include <memory> #include <memory>
#include <cassert> #include <cassert>
#include "FuseDevice.h" #include "fusepp/impl/FuseErrnoException.h"
#include "FuseErrnoException.h" #include "fusepp/impl/FilesystemImpl.h"
using std::unique_ptr; using std::unique_ptr;
using std::make_unique; using std::make_unique;
@ -11,7 +11,7 @@ using std::string;
namespace bf = boost::filesystem; namespace bf = boost::filesystem;
using namespace fusepp; using namespace fusepp::fusebindings;
#define FUSE_OBJ ((Fuse *) fuse_get_context()->private_data) #define FUSE_OBJ ((Fuse *) fuse_get_context()->private_data)
@ -205,8 +205,8 @@ fuse_operations *operations() {
Fuse::~Fuse() { Fuse::~Fuse() {
} }
Fuse::Fuse(FuseDevice *device) Fuse::Fuse(FilesystemImpl *impl)
:_device(device) { :_impl(impl) {
} }
void Fuse::run(int argc, char **argv) { void Fuse::run(int argc, char **argv) {
@ -216,7 +216,7 @@ void Fuse::run(int argc, char **argv) {
int Fuse::getattr(const bf::path &path, struct stat *stbuf) { int Fuse::getattr(const bf::path &path, struct stat *stbuf) {
//printf("getattr(%s, _, _)\n", path.c_str()); //printf("getattr(%s, _, _)\n", path.c_str());
try { try {
_device->lstat(path, stbuf); _impl->lstat(path, stbuf);
return 0; return 0;
} catch(fusepp::FuseErrnoException &e) { } catch(fusepp::FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -236,7 +236,7 @@ int Fuse::fgetattr(const bf::path &path, struct stat *stbuf, fuse_file_info *fil
} }
try { try {
_device->fstat(fileinfo->fh, stbuf); _impl->fstat(fileinfo->fh, stbuf);
return 0; return 0;
} catch(fusepp::FuseErrnoException &e) { } catch(fusepp::FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -263,7 +263,7 @@ int Fuse::mknod(const bf::path &path, mode_t mode, dev_t rdev) {
int Fuse::mkdir(const bf::path &path, mode_t mode) { int Fuse::mkdir(const bf::path &path, mode_t mode) {
//printf("mkdir(%s, %d)\n", path.c_str(), mode); //printf("mkdir(%s, %d)\n", path.c_str(), mode);
try { try {
_device->mkdir(path, mode); _impl->mkdir(path, mode);
return 0; return 0;
} catch(fusepp::FuseErrnoException &e) { } catch(fusepp::FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -273,7 +273,7 @@ int Fuse::mkdir(const bf::path &path, mode_t mode) {
int Fuse::unlink(const bf::path &path) { int Fuse::unlink(const bf::path &path) {
//printf("unlink(%s)\n", path.c_str()); //printf("unlink(%s)\n", path.c_str());
try { try {
_device->unlink(path); _impl->unlink(path);
return 0; return 0;
} catch(fusepp::FuseErrnoException &e) { } catch(fusepp::FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -282,7 +282,7 @@ int Fuse::unlink(const bf::path &path) {
int Fuse::rmdir(const bf::path &path) { int Fuse::rmdir(const bf::path &path) {
try { try {
_device->rmdir(path); _impl->rmdir(path);
return 0; return 0;
} catch(fusepp::FuseErrnoException &e) { } catch(fusepp::FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -292,8 +292,8 @@ int Fuse::rmdir(const bf::path &path) {
//TODO //TODO
int Fuse::symlink(const bf::path &from, const bf::path &to) { int Fuse::symlink(const bf::path &from, const bf::path &to) {
printf("NOT IMPLEMENTED: symlink(%s, %s)\n", from.c_str(), to.c_str()); printf("NOT IMPLEMENTED: symlink(%s, %s)\n", from.c_str(), to.c_str());
//auto real_from = _device->RootDir() / from; //auto real_from = _impl->RootDir() / from;
//auto real_to = _device->RootDir() / to; //auto real_to = _impl->RootDir() / to;
//int retstat = ::symlink(real_from.c_str(), real_to.c_str()); //int retstat = ::symlink(real_from.c_str(), real_to.c_str());
//return errcode_map(retstat); //return errcode_map(retstat);
return ENOSYS; return ENOSYS;
@ -302,7 +302,7 @@ int Fuse::symlink(const bf::path &from, const bf::path &to) {
int Fuse::rename(const bf::path &from, const bf::path &to) { int Fuse::rename(const bf::path &from, const bf::path &to) {
//printf("rename(%s, %s)\n", from.c_str(), to.c_str()); //printf("rename(%s, %s)\n", from.c_str(), to.c_str());
try { try {
_device->rename(from, to); _impl->rename(from, to);
return 0; return 0;
} catch(fusepp::FuseErrnoException &e) { } catch(fusepp::FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -312,8 +312,8 @@ int Fuse::rename(const bf::path &from, const bf::path &to) {
//TODO //TODO
int Fuse::link(const bf::path &from, const bf::path &to) { int Fuse::link(const bf::path &from, const bf::path &to) {
printf("NOT IMPLEMENTED: link(%s, %s)\n", from.c_str(), to.c_str()); printf("NOT IMPLEMENTED: link(%s, %s)\n", from.c_str(), to.c_str());
//auto real_from = _device->RootDir() / from; //auto real_from = _impl->RootDir() / from;
//auto real_to = _device->RootDir() / to; //auto real_to = _impl->RootDir() / to;
//int retstat = ::link(real_from.c_str(), real_to.c_str()); //int retstat = ::link(real_from.c_str(), real_to.c_str());
//return errcode_map(retstat); //return errcode_map(retstat);
return ENOSYS; return ENOSYS;
@ -322,7 +322,7 @@ int Fuse::link(const bf::path &from, const bf::path &to) {
//TODO //TODO
int Fuse::chmod(const bf::path &path, mode_t mode) { int Fuse::chmod(const bf::path &path, mode_t mode) {
printf("NOT IMPLEMENTED: chmod(%s, %d)\n", path.c_str(), mode); printf("NOT IMPLEMENTED: chmod(%s, %d)\n", path.c_str(), mode);
//auto real_path = _device->RootDir() / path; //auto real_path = _impl->RootDir() / path;
//int retstat = ::chmod(real_path.c_str(), mode); //int retstat = ::chmod(real_path.c_str(), mode);
//return errcode_map(retstat); //return errcode_map(retstat);
return ENOSYS; return ENOSYS;
@ -331,7 +331,7 @@ int Fuse::chmod(const bf::path &path, mode_t mode) {
//TODO //TODO
int Fuse::chown(const bf::path &path, uid_t uid, gid_t gid) { 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); printf("NOT IMPLEMENTED: chown(%s, %d, %d)\n", path.c_str(), uid, gid);
//auto real_path = _device->RootDir() / path; //auto real_path = _impl->RootDir() / path;
//int retstat = ::chown(real_path.c_str(), uid, gid); //int retstat = ::chown(real_path.c_str(), uid, gid);
//return errcode_map(retstat); //return errcode_map(retstat);
return ENOSYS; return ENOSYS;
@ -340,7 +340,7 @@ int Fuse::chown(const bf::path &path, uid_t uid, gid_t gid) {
int Fuse::truncate(const bf::path &path, off_t size) { int Fuse::truncate(const bf::path &path, off_t size) {
//printf("truncate(%s, %zu)\n", path.c_str(), size); //printf("truncate(%s, %zu)\n", path.c_str(), size);
try { try {
_device->truncate(path, size); _impl->truncate(path, size);
return 0; return 0;
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -351,7 +351,7 @@ int Fuse::ftruncate(const bf::path &path, off_t size, fuse_file_info *fileinfo)
//printf("ftruncate(%s, %zu, _)\n", path.c_str(), size); //printf("ftruncate(%s, %zu, _)\n", path.c_str(), size);
UNUSED(path); UNUSED(path);
try { try {
_device->ftruncate(fileinfo->fh, size); _impl->ftruncate(fileinfo->fh, size);
return 0; return 0;
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -362,7 +362,7 @@ int Fuse::ftruncate(const bf::path &path, off_t size, fuse_file_info *fileinfo)
int Fuse::utimens(const bf::path &path, const timespec times[2]) { int Fuse::utimens(const bf::path &path, const timespec times[2]) {
//printf("utimens(%s, _)\n", path.c_str()); //printf("utimens(%s, _)\n", path.c_str());
try { try {
_device->utimens(path, times); _impl->utimens(path, times);
return 0; return 0;
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -372,7 +372,7 @@ int Fuse::utimens(const bf::path &path, const timespec times[2]) {
int Fuse::open(const bf::path &path, fuse_file_info *fileinfo) { int Fuse::open(const bf::path &path, fuse_file_info *fileinfo) {
//printf("open(%s, _)\n", path.c_str()); //printf("open(%s, _)\n", path.c_str());
try { try {
fileinfo->fh = _device->openFile(path, fileinfo->flags); fileinfo->fh = _impl->openFile(path, fileinfo->flags);
return 0; return 0;
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -383,7 +383,7 @@ int Fuse::release(const bf::path &path, fuse_file_info *fileinfo) {
//printf("release(%s, _)\n", path.c_str()); //printf("release(%s, _)\n", path.c_str());
UNUSED(path); UNUSED(path);
try { try {
_device->closeFile(fileinfo->fh); _impl->closeFile(fileinfo->fh);
return 0; return 0;
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -396,7 +396,7 @@ int Fuse::read(const bf::path &path, char *buf, size_t size, off_t offset, fuse_
try { try {
//printf("Reading from file %d\n", fileinfo->fh); //printf("Reading from file %d\n", fileinfo->fh);
//fflush(stdout); //fflush(stdout);
return _device->read(fileinfo->fh, buf, size, offset); return _impl->read(fileinfo->fh, buf, size, offset);
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
} }
@ -406,7 +406,7 @@ int Fuse::write(const bf::path &path, const char *buf, size_t size, off_t offset
//printf("write(%s, _, %zu, %zu, _)\n", path.c_str(), size, offset); //printf("write(%s, _, %zu, %zu, _)\n", path.c_str(), size, offset);
UNUSED(path); UNUSED(path);
try { try {
_device->write(fileinfo->fh, buf, size, offset); _impl->write(fileinfo->fh, buf, size, offset);
return size; return size;
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -417,7 +417,7 @@ int Fuse::write(const bf::path &path, const char *buf, size_t size, off_t offset
int Fuse::statfs(const bf::path &path, struct statvfs *fsstat) { int Fuse::statfs(const bf::path &path, struct statvfs *fsstat) {
//printf("statfs(%s, _)\n", path.c_str()); //printf("statfs(%s, _)\n", path.c_str());
try { try {
_device->statfs(path, fsstat); _impl->statfs(path, fsstat);
return 0; return 0;
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -437,9 +437,9 @@ int Fuse::fsync(const bf::path &path, int datasync, fuse_file_info *fileinfo) {
UNUSED(path); UNUSED(path);
try { try {
if (datasync) { if (datasync) {
_device->fdatasync(fileinfo->fh); _impl->fdatasync(fileinfo->fh);
} else { } else {
_device->fsync(fileinfo->fh); _impl->fsync(fileinfo->fh);
} }
return 0; return 0;
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
@ -460,7 +460,7 @@ int Fuse::readdir(const bf::path &path, void *buf, fuse_fill_dir_t filler, off_t
//printf("readdir(%s, _, _, %zu, _)\n", path.c_str(), offset); //printf("readdir(%s, _, _, %zu, _)\n", path.c_str(), offset);
UNUSED(offset); UNUSED(offset);
try { try {
auto entries = _device->readDir(path); auto entries = _impl->readDir(path);
for (const auto &entry : *entries) { for (const auto &entry : *entries) {
//We could pass file metadata to filler() in its third parameter, //We could pass file metadata to filler() in its third parameter,
//but it doesn't help performance since fuse seems to ignore it. //but it doesn't help performance since fuse seems to ignore it.
@ -504,7 +504,7 @@ void Fuse::destroy() {
int Fuse::access(const bf::path &path, int mask) { int Fuse::access(const bf::path &path, int mask) {
//printf("access(%s, %d)\n", path.c_str(), mask); //printf("access(%s, %d)\n", path.c_str(), mask);
try { try {
_device->access(path, mask); _impl->access(path, mask);
return 0; return 0;
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();
@ -514,7 +514,7 @@ int Fuse::access(const bf::path &path, int mask) {
int Fuse::create(const bf::path &path, mode_t mode, fuse_file_info *fileinfo) { int Fuse::create(const bf::path &path, mode_t mode, fuse_file_info *fileinfo) {
//printf("create(%s, %d, _)\n", path.c_str(), mode); //printf("create(%s, %d, _)\n", path.c_str(), mode);
try { try {
fileinfo->fh = _device->createAndOpenFile(path, mode); fileinfo->fh = _impl->createAndOpenFile(path, mode);
return 0; return 0;
} catch (FuseErrnoException &e) { } catch (FuseErrnoException &e) {
return -e.getErrno(); return -e.getErrno();

View File

@ -8,14 +8,17 @@
#include <string> #include <string>
#include <sys/stat.h> #include <sys/stat.h>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "utils/macros.h" #include "../utils/macros.h"
namespace fusepp { namespace fusepp {
class FuseDevice; class FuseDevice;
class FilesystemImpl;
namespace fusebindings {
class Fuse { class Fuse {
public: public:
Fuse(FuseDevice *device); Fuse(FilesystemImpl *implementation);
virtual ~Fuse(); virtual ~Fuse();
void run(int argc, char **argv); void run(int argc, char **argv);
@ -52,10 +55,11 @@ public:
int create(const boost::filesystem::path &path, mode_t mode, fuse_file_info *fileinfo); int create(const boost::filesystem::path &path, mode_t mode, fuse_file_info *fileinfo);
private: private:
FuseDevice *_device; FilesystemImpl *_impl;
DISALLOW_COPY_AND_ASSIGN(Fuse); DISALLOW_COPY_AND_ASSIGN(Fuse);
}; };
} }
}
#endif /* FUSEPP_FUSE_H_ */ #endif /* FUSEPP_FUSE_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

@ -1,14 +1,14 @@
#pragma once #pragma once
#ifndef FUSEPP_FUSEDEVICE_H_ #ifndef FUSEPP_FILESYSTEMIMPL_H_
#define FUSEPP_FUSEDEVICE_H_ #define FUSEPP_FILESYSTEMIMPL_H_
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <fusepp/FuseOpenFileList.h> #include "FuseOpenFileList.h"
#include <memory> #include <memory>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/statvfs.h> #include <sys/statvfs.h>
#include "utils/macros.h" #include "fusepp/utils/macros.h"
namespace fusepp { namespace fusepp {
class FuseNode; class FuseNode;
@ -16,10 +16,10 @@ class FuseFile;
class FuseOpenFile; class FuseOpenFile;
class FuseDir; class FuseDir;
class FuseDevice { class FilesystemImpl {
public: public:
FuseDevice(); FilesystemImpl(FuseDevice *device);
virtual ~FuseDevice(); virtual ~FilesystemImpl();
int openFile(const boost::filesystem::path &path, int flags); int openFile(const boost::filesystem::path &path, int flags);
void closeFile(int descriptor); void closeFile(int descriptor);
@ -39,18 +39,19 @@ public:
void rename(const boost::filesystem::path &from, const boost::filesystem::path &to); 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); 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 utimens(const boost::filesystem::path &path, const timespec times[2]);
virtual void statfs(const boost::filesystem::path &path, struct statvfs *fsstat) = 0; void statfs(const boost::filesystem::path &path, struct statvfs *fsstat);
private: private:
virtual std::unique_ptr<FuseNode> Load(const boost::filesystem::path &path) = 0;
std::unique_ptr<FuseFile> LoadFile(const boost::filesystem::path &path); std::unique_ptr<FuseFile> LoadFile(const boost::filesystem::path &path);
std::unique_ptr<FuseDir> LoadDir(const boost::filesystem::path &path); std::unique_ptr<FuseDir> LoadDir(const boost::filesystem::path &path);
int openFile(const FuseFile &file, int flags); int openFile(const FuseFile &file, int flags);
FuseDevice *_device;
FuseOpenFileList _open_files; FuseOpenFileList _open_files;
DISALLOW_COPY_AND_ASSIGN(FuseDevice); DISALLOW_COPY_AND_ASSIGN(FilesystemImpl);
}; };
} }
#endif /* FUSEPP_FUSEDEVICE_H_ */ #endif /* FUSEPP_FILESYSTEMIMPL_H_ */

View File

@ -2,10 +2,10 @@
#ifndef FUSEPP_FUSEOPENFILELIST_H_ #ifndef FUSEPP_FUSEOPENFILELIST_H_
#define FUSEPP_FUSEOPENFILELIST_H_ #define FUSEPP_FUSEOPENFILELIST_H_
#include "utils/macros.h" #include "fusepp/utils/macros.h"
#include "IdList.h" #include "IdList.h"
#include "FuseFile.h" #include "fusepp/fs_interface/FuseFile.h"
#include "FuseOpenFile.h" #include "fusepp/fs_interface/FuseOpenFile.h"
namespace fusepp { namespace fusepp {

View File

@ -5,7 +5,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include "utils/macros.h" #include "fusepp/utils/macros.h"
namespace fusepp { namespace fusepp {

View File

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