CryDevice stores root path to which we work relatively

This commit is contained in:
Sebastian Messmer 2014-11-04 21:03:04 +01:00
parent 560d304fb8
commit 728d97e9e8
6 changed files with 43 additions and 8 deletions

View File

@ -4,11 +4,9 @@
using namespace cryfs;
CryDevice::CryDevice() {
std::cout << "Created CryDevice\n";
CryDevice::CryDevice(const fusepp::path &rootdir)
:_rootdir(rootdir) {
}
CryDevice::~CryDevice() {
}

View File

@ -3,15 +3,26 @@
#define CRYFS_LIB_CRYDEVICE_H_
#include "fusepp/Fuse.h"
#include "utils/macros.h"
namespace cryfs {
class CryDevice {
public:
CryDevice();
CryDevice(const fusepp::path &rootdir);
virtual ~CryDevice();
const fusepp::path &RootDir() const;
private:
const fusepp::path _rootdir;
DISALLOW_COPY_AND_ASSIGN(CryDevice);
};
inline const fusepp::path &CryDevice::RootDir() const {
return _rootdir;
}
}
#endif /* CRYFS_LIB_CRYDEVICE_H_ */

View File

@ -10,9 +10,14 @@ using fusepp::path;
namespace cryfs {
CryFuse::CryFuse(CryDevice *device)
:_device(device) {
}
int CryFuse::getattr(const path &path, struct stat *stbuf) {
UNUSED(stbuf);
int retstat = lstat(path.c_str(), stbuf);
auto real_path = _device->RootDir() / path;
int retstat = lstat(real_path.c_str(), stbuf);
if (retstat != 0) {
retstat = -errno;
}
@ -140,7 +145,8 @@ int CryFuse::fsync(const path &path, int flags, fuse_file_info *fileinfo) {
}
int CryFuse::opendir(const path &path, fuse_file_info *fileinfo) {
DIR *dp = ::opendir(path.c_str());
auto real_path = _device->RootDir() / path;
DIR *dp = ::opendir(real_path.c_str());
int retstat = 0;
if (dp == nullptr) {
retstat = -errno;

View File

@ -3,11 +3,15 @@
#define CRYFS_LIB_CRYFUSE_H_
#include "fusepp/Fuse.h"
#include "CryDevice.h"
#include "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;
@ -38,6 +42,11 @@ public:
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 */

View File

@ -0,0 +1,10 @@
#pragma once
#ifndef CRYFS_LIB_UTILS_MACROS_H_
#define CRYFS_LIB_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_ */

View File

@ -9,7 +9,8 @@
int main (int argc, char *argv[])
{
printf("Version: %d\n", buildconfig::VERSION::MAJOR);
cryfs::CryFuse fuse;
cryfs::CryDevice device(fusepp::path("/"));
cryfs::CryFuse fuse(&device);
fuse.run(argc, argv);
return 0;
}