CryDevice stores root path to which we work relatively
This commit is contained in:
parent
560d304fb8
commit
728d97e9e8
@ -4,11 +4,9 @@
|
||||
|
||||
using namespace cryfs;
|
||||
|
||||
CryDevice::CryDevice() {
|
||||
std::cout << "Created CryDevice\n";
|
||||
|
||||
CryDevice::CryDevice(const fusepp::path &rootdir)
|
||||
:_rootdir(rootdir) {
|
||||
}
|
||||
|
||||
CryDevice::~CryDevice() {
|
||||
}
|
||||
|
||||
|
@ -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_ */
|
||||
|
@ -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;
|
||||
|
@ -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 */
|
||||
|
10
src/cryfs_lib/utils/macros.h
Normal file
10
src/cryfs_lib/utils/macros.h
Normal 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_ */
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user