Remove Cryfs Implementation
This commit is contained in:
parent
39ab086bb6
commit
51bcc2f191
@ -12,30 +12,25 @@ using std::make_unique;
|
||||
|
||||
//TODO Get rid of this in favor of exception hierarchy
|
||||
using fspp::fuse::CHECK_RETVAL;
|
||||
using fspp::fuse::FuseErrnoException;
|
||||
|
||||
using blobstore::BlobStore;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryDevice::CryDevice(const bf::path &root_path): _root_path(root_path) {
|
||||
CryDevice::CryDevice(unique_ptr<BlobStore> blobStore)
|
||||
: _blobStore(std::move(blobStore)) {
|
||||
}
|
||||
|
||||
CryDevice::~CryDevice() {
|
||||
}
|
||||
|
||||
unique_ptr<fspp::Node> CryDevice::Load(const bf::path &path) {
|
||||
auto real_path = RootDir() / path;
|
||||
if(bf::is_directory(real_path)) {
|
||||
return make_unique<CryDir>(this, path);
|
||||
} else if(bf::is_regular_file(real_path)) {
|
||||
return make_unique<CryFile>(this, path);
|
||||
}
|
||||
|
||||
throw fspp::fuse::FuseErrnoException(ENOENT);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryDevice::statfs(const bf::path &path, struct statvfs *fsstat) {
|
||||
auto real_path = RootDir() / path;
|
||||
int retval = ::statvfs(real_path.c_str(), fsstat);
|
||||
CHECK_RETVAL(retval);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <fspp/fs_interface/Device.h>
|
||||
|
||||
#include "blobstore/interface/BlobStore.h"
|
||||
|
||||
#include "fspp/utils/macros.h"
|
||||
|
||||
namespace cryfs {
|
||||
@ -13,24 +15,19 @@ namespace bf = boost::filesystem;
|
||||
|
||||
class CryDevice: public fspp::Device {
|
||||
public:
|
||||
CryDevice(const bf::path &rootdir);
|
||||
CryDevice(std::unique_ptr<blobstore::BlobStore> blobStore);
|
||||
virtual ~CryDevice();
|
||||
|
||||
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
||||
|
||||
const bf::path &RootDir() const;
|
||||
private:
|
||||
std::unique_ptr<fspp::Node> Load(const bf::path &path) override;
|
||||
|
||||
const bf::path _root_path;
|
||||
std::unique_ptr<blobstore::BlobStore> _blobStore;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryDevice);
|
||||
};
|
||||
|
||||
inline const bf::path &CryDevice::RootDir() const {
|
||||
return _root_path;
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
||||
|
||||
#endif /* CRYFS_LIB_CRYDEVICE_H_ */
|
||||
#endif
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
//TODO Get rid of this in favor of exception hierarchy
|
||||
using fspp::fuse::CHECK_RETVAL;
|
||||
using fspp::fuse::FuseErrnoException;
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
@ -21,61 +22,26 @@ using std::vector;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryDir::CryDir(CryDevice *device, const bf::path &path)
|
||||
:CryNode(device, path) {
|
||||
assert(bf::is_directory(base_path()));
|
||||
CryDir::CryDir() {
|
||||
}
|
||||
|
||||
CryDir::~CryDir() {
|
||||
}
|
||||
|
||||
unique_ptr<fspp::File> CryDir::createFile(const string &name, mode_t mode) {
|
||||
auto file_path = base_path() / name;
|
||||
//Create file
|
||||
int fd = ::creat(file_path.c_str(), mode);
|
||||
CHECK_RETVAL(fd);
|
||||
::close(fd);
|
||||
return make_unique<CryFile>(device(), path() / name);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
unique_ptr<fspp::Dir> CryDir::createDir(const string &name, mode_t mode) {
|
||||
auto dir_path = base_path() / name;
|
||||
//Create dir
|
||||
int retval = ::mkdir(dir_path.c_str(), mode);
|
||||
CHECK_RETVAL(retval);
|
||||
return make_unique<CryDir>(device(), path() / name);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryDir::rmdir() {
|
||||
int retval = ::rmdir(base_path().c_str());
|
||||
CHECK_RETVAL(retval);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
unique_ptr<vector<string>> CryDir::children() const {
|
||||
DIR *dir = ::opendir(base_path().c_str());
|
||||
if (dir == nullptr) {
|
||||
throw fspp::fuse::FuseErrnoException(errno);
|
||||
}
|
||||
|
||||
// Set errno=0 so we can detect whether it changed later
|
||||
errno = 0;
|
||||
|
||||
auto result = make_unique<vector<string>>();
|
||||
|
||||
struct dirent *entry = ::readdir(dir);
|
||||
while(entry != nullptr) {
|
||||
result->push_back(entry->d_name);
|
||||
entry = ::readdir(dir);
|
||||
}
|
||||
//On error, ::readdir returns nullptr and sets errno.
|
||||
if (errno != 0) {
|
||||
int readdir_errno = errno;
|
||||
::closedir(dir);
|
||||
throw fspp::fuse::FuseErrnoException(readdir_errno);
|
||||
}
|
||||
int retval = ::closedir(dir);
|
||||
CHECK_RETVAL(retval);
|
||||
return result;
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace cryfs {
|
||||
|
||||
class CryDir: public fspp::Dir, CryNode {
|
||||
public:
|
||||
CryDir(CryDevice *device, const bf::path &path);
|
||||
CryDir();
|
||||
virtual ~CryDir();
|
||||
|
||||
//TODO return type variance to CryFile/CryDir?
|
||||
@ -23,6 +23,6 @@ private:
|
||||
DISALLOW_COPY_AND_ASSIGN(CryDir);
|
||||
};
|
||||
|
||||
} /* namespace cryfs */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -8,32 +8,29 @@ namespace bf = boost::filesystem;
|
||||
|
||||
//TODO Get rid of this in favor of exception hierarchy
|
||||
using fspp::fuse::CHECK_RETVAL;
|
||||
using fspp::fuse::FuseErrnoException;
|
||||
|
||||
using std::unique_ptr;
|
||||
using std::make_unique;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryFile::CryFile(CryDevice *device, const bf::path &path)
|
||||
:CryNode(device, path) {
|
||||
assert(bf::is_regular_file(base_path()));
|
||||
CryFile::CryFile() {
|
||||
}
|
||||
|
||||
CryFile::~CryFile() {
|
||||
}
|
||||
|
||||
unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
|
||||
return make_unique<CryOpenFile>(device(), path(), flags);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryFile::truncate(off_t size) const {
|
||||
int retval = ::truncate(base_path().c_str(), size);
|
||||
CHECK_RETVAL(retval);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryFile::unlink() {
|
||||
int retval = ::unlink(base_path().c_str());
|
||||
CHECK_RETVAL(retval);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace cryfs {
|
||||
|
||||
class CryFile: public fspp::File, CryNode {
|
||||
public:
|
||||
CryFile(CryDevice *device, const boost::filesystem::path &path);
|
||||
CryFile();
|
||||
virtual ~CryFile();
|
||||
|
||||
std::unique_ptr<fspp::OpenFile> open(int flags) const override;
|
||||
@ -20,6 +20,6 @@ private:
|
||||
DISALLOW_COPY_AND_ASSIGN(CryFile);
|
||||
};
|
||||
|
||||
} /* namespace cryfs */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -9,38 +9,30 @@ namespace bf = boost::filesystem;
|
||||
|
||||
//TODO Get rid of this in favor of an exception hierarchy
|
||||
using fspp::fuse::CHECK_RETVAL;
|
||||
using fspp::fuse::FuseErrnoException;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryNode::CryNode(CryDevice *device, const bf::path &path)
|
||||
:_device(device), _path(path) {
|
||||
CryNode::CryNode() {
|
||||
}
|
||||
|
||||
CryNode::~CryNode() {
|
||||
}
|
||||
|
||||
void CryNode::stat(struct ::stat *result) const {
|
||||
int retval = ::lstat(base_path().c_str(), result);
|
||||
CHECK_RETVAL(retval);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryNode::access(int mask) const {
|
||||
int retval = ::access(base_path().c_str(), mask);
|
||||
CHECK_RETVAL(retval);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryNode::rename(const bf::path &to) {
|
||||
auto new_base_path = device()->RootDir() / to;
|
||||
int retval = ::rename(base_path().c_str(), new_base_path.c_str());
|
||||
CHECK_RETVAL(retval);
|
||||
_path = to;
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryNode::utimens(const timespec times[2]) {
|
||||
struct timeval timevals[2];
|
||||
TIMESPEC_TO_TIMEVAL(&timevals[0], ×[0]);
|
||||
TIMESPEC_TO_TIMEVAL(&timevals[1], ×[1]);
|
||||
::lutimes(base_path().c_str(), timevals);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
||||
|
@ -11,7 +11,7 @@ namespace cryfs {
|
||||
|
||||
class CryNode: public virtual fspp::Node {
|
||||
public:
|
||||
CryNode(CryDevice *device, const boost::filesystem::path &path);
|
||||
CryNode();
|
||||
virtual ~CryNode();
|
||||
|
||||
void stat(struct ::stat *result) const override;
|
||||
@ -19,35 +19,11 @@ public:
|
||||
void rename(const boost::filesystem::path &to) override;
|
||||
void utimens(const timespec times[2]) override;
|
||||
|
||||
protected:
|
||||
boost::filesystem::path base_path() const;
|
||||
const boost::filesystem::path &path() const;
|
||||
CryDevice *device();
|
||||
const CryDevice *device() const;
|
||||
|
||||
private:
|
||||
CryDevice *const _device;
|
||||
boost::filesystem::path _path;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryNode);
|
||||
};
|
||||
|
||||
inline boost::filesystem::path CryNode::base_path() const {
|
||||
return _device->RootDir() / _path;
|
||||
}
|
||||
|
||||
inline const boost::filesystem::path &CryNode::path() const {
|
||||
return _path;
|
||||
}
|
||||
|
||||
inline CryDevice *CryNode::device() {
|
||||
return const_cast<CryDevice*>(const_cast<const CryNode*>(this)->device());
|
||||
}
|
||||
|
||||
inline const CryDevice *CryNode::device() const {
|
||||
return _device;
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
||||
|
||||
#endif
|
||||
|
@ -10,57 +10,44 @@ namespace bf = boost::filesystem;
|
||||
|
||||
//TODO Get rid of this in favor of a exception hierarchy
|
||||
using fspp::fuse::CHECK_RETVAL;
|
||||
using fspp::fuse::FuseErrnoException;
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryOpenFile::CryOpenFile(const CryDevice *device, const bf::path &path, int flags)
|
||||
:_descriptor(::open((device->RootDir() / path).c_str(), flags)) {
|
||||
CHECK_RETVAL(_descriptor);
|
||||
CryOpenFile::CryOpenFile() {
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
CryOpenFile::~CryOpenFile() {
|
||||
int retval = ::close(_descriptor);
|
||||
CHECK_RETVAL(retval);
|
||||
//TODO
|
||||
}
|
||||
|
||||
void CryOpenFile::flush() {
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryOpenFile::stat(struct ::stat *result) const {
|
||||
int retval = ::fstat(_descriptor, result);
|
||||
CHECK_RETVAL(retval);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryOpenFile::truncate(off_t size) const {
|
||||
int retval = ::ftruncate(_descriptor, size);
|
||||
CHECK_RETVAL(retval);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
int CryOpenFile::read(void *buf, size_t count, off_t offset) {
|
||||
//printf("Reading from real descriptor %d (%d, %d)\n", _descriptor, offset, count);
|
||||
//fflush(stdout);
|
||||
int retval = ::pread(_descriptor, buf, count, offset);
|
||||
CHECK_RETVAL(retval);
|
||||
//printf("retval: %d, count: %d\n", retval, count);
|
||||
//fflush(stdout);
|
||||
assert(static_cast<unsigned int>(retval) <= count);
|
||||
return retval;
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryOpenFile::write(const void *buf, size_t count, off_t offset) {
|
||||
int retval = ::pwrite(_descriptor, buf, count, offset);
|
||||
CHECK_RETVAL(retval);
|
||||
assert(static_cast<unsigned int>(retval) == count);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryOpenFile::fsync() {
|
||||
int retval = ::fsync(_descriptor);
|
||||
CHECK_RETVAL(retval);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
void CryOpenFile::fdatasync() {
|
||||
int retval = ::fdatasync(_descriptor);
|
||||
CHECK_RETVAL(retval);
|
||||
throw FuseErrnoException(ENOTSUP);
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ class CryDevice;
|
||||
|
||||
class CryOpenFile: public fspp::OpenFile {
|
||||
public:
|
||||
CryOpenFile(const CryDevice *device, const boost::filesystem::path &path, int flags);
|
||||
CryOpenFile();
|
||||
virtual ~CryOpenFile();
|
||||
|
||||
void stat(struct ::stat *result) const override;
|
||||
@ -22,11 +22,10 @@ public:
|
||||
void fdatasync() override;
|
||||
|
||||
private:
|
||||
int _descriptor;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryOpenFile);
|
||||
};
|
||||
|
||||
} /* namespace cryfs */
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -7,13 +7,19 @@
|
||||
#include "fspp/impl/FilesystemImpl.h"
|
||||
#include "copyfs/CopyDevice.h"
|
||||
#include "cryfs_lib/CryDevice.h"
|
||||
#include "blobstore/implementations/ondisk/OnDiskBlobStore.h"
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
using blobstore::ondisk::OnDiskBlobStore;
|
||||
|
||||
using std::make_unique;
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
printf("Version: %d\n", buildconfig::VERSION::MAJOR);
|
||||
copyfs::CopyDevice device(bf::path("/home/heinzi/cryfstest/root"));
|
||||
auto blobStore = make_unique<OnDiskBlobStore>(bf::path("/home/heinzi/cryfstest/root"));
|
||||
cryfs::CryDevice device(std::move(blobStore));
|
||||
fspp::FilesystemImpl fsimpl(&device);
|
||||
fspp::fuse::Fuse fuse(&fsimpl);
|
||||
fuse.run(argc, argv);
|
||||
|
Loading…
x
Reference in New Issue
Block a user