Fix some stuff and make getattr go through our class structure
This commit is contained in:
parent
f9fe4f579c
commit
a6b664063c
@ -5,6 +5,9 @@
|
||||
#include <dirent.h>
|
||||
#include <cassert>
|
||||
|
||||
#include "cryfs_lib/CryNode.h"
|
||||
#include "cryfs_lib/CryErrnoException.h"
|
||||
|
||||
#define UNUSED(expr) (void)(expr)
|
||||
|
||||
using fusepp::path;
|
||||
@ -25,11 +28,12 @@ CryFuse::CryFuse(CryDevice *device)
|
||||
}
|
||||
|
||||
int CryFuse::getattr(const path &path, struct stat *stbuf) {
|
||||
UNUSED(stbuf);
|
||||
//printf("getattr(%s, _)\n", path.c_str());
|
||||
auto real_path = _device->RootDir() / path;
|
||||
int retstat = lstat(real_path.c_str(), stbuf);
|
||||
return errcode_map(retstat);
|
||||
try {
|
||||
_device->LoadFromPath(path)->stat(stbuf);
|
||||
return 0;
|
||||
} catch(cryfs::CryErrnoException &e) {
|
||||
return -e.getErrno();
|
||||
}
|
||||
}
|
||||
|
||||
int CryFuse::fgetattr(const path &path, struct stat *stbuf, fuse_file_info *fileinfo) {
|
||||
|
@ -1,3 +1,3 @@
|
||||
add_library(cryfs_lib CryDevice.cpp)
|
||||
add_library(cryfs_lib CryDevice.cpp CryDir.cpp CryErrnoException.cpp CryFile.cpp CryNode.cpp)
|
||||
|
||||
target_link_libraries(cryfs_lib)
|
||||
target_link_libraries(cryfs_lib boost_filesystem)
|
||||
|
@ -1,12 +1,30 @@
|
||||
#include "../cryfs_lib/CryDevice.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "CryDir.h"
|
||||
#include "CryFile.h"
|
||||
#include "CryErrnoException.h"
|
||||
|
||||
using namespace cryfs;
|
||||
|
||||
CryDevice::CryDevice(const fusepp::path &rootdir)
|
||||
using std::unique_ptr;
|
||||
using std::make_unique;
|
||||
|
||||
CryDevice::CryDevice(const bf::path &rootdir)
|
||||
:_rootdir(rootdir) {
|
||||
}
|
||||
|
||||
CryDevice::~CryDevice() {
|
||||
}
|
||||
|
||||
unique_ptr<CryNode> CryDevice::LoadFromPath(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 CryErrnoException(ENOENT);
|
||||
}
|
||||
|
@ -2,24 +2,31 @@
|
||||
#ifndef CRYFS_LIB_CRYDEVICE_H_
|
||||
#define CRYFS_LIB_CRYDEVICE_H_
|
||||
|
||||
#include "fusepp/Fuse.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "utils/macros.h"
|
||||
#include <memory>
|
||||
|
||||
namespace cryfs {
|
||||
class CryNode;
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
class CryDevice {
|
||||
public:
|
||||
CryDevice(const fusepp::path &rootdir);
|
||||
CryDevice(const bf::path &rootdir);
|
||||
virtual ~CryDevice();
|
||||
|
||||
const fusepp::path &RootDir() const;
|
||||
std::unique_ptr<CryNode> LoadFromPath(const bf::path &path);
|
||||
//std::unique_ptr<const CryNode> LoadFromPath(const bf::path &path) const;
|
||||
|
||||
const bf::path &RootDir() const;
|
||||
private:
|
||||
const fusepp::path _rootdir;
|
||||
const bf::path _rootdir;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryDevice);
|
||||
};
|
||||
|
||||
inline const fusepp::path &CryDevice::RootDir() const {
|
||||
inline const bf::path &CryDevice::RootDir() const {
|
||||
return _rootdir;
|
||||
}
|
||||
|
||||
|
13
src/cryfs_lib/CryDir.cpp
Normal file
13
src/cryfs_lib/CryDir.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "CryDir.h"
|
||||
#include "CryDevice.h"
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryDir::CryDir(CryDevice *device, const bf::path &path)
|
||||
:CryNode(device, path) {
|
||||
}
|
||||
|
||||
CryDir::~CryDir() {
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
18
src/cryfs_lib/CryDir.h
Normal file
18
src/cryfs_lib/CryDir.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_CRYDIR_H_
|
||||
#define CRYFS_LIB_CRYDIR_H_
|
||||
|
||||
#include "CryNode.h"
|
||||
|
||||
namespace cryfs {
|
||||
class CryDevice;
|
||||
|
||||
class CryDir: public CryNode {
|
||||
public:
|
||||
CryDir(CryDevice *device, const bf::path &path);
|
||||
virtual ~CryDir();
|
||||
};
|
||||
|
||||
} /* namespace cryfs */
|
||||
|
||||
#endif /* CRYFS_LIB_CRYDIR_H_ */
|
24
src/cryfs_lib/CryErrnoException.cpp
Normal file
24
src/cryfs_lib/CryErrnoException.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
#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 */
|
28
src/cryfs_lib/CryErrnoException.h
Normal file
28
src/cryfs_lib/CryErrnoException.h
Normal file
@ -0,0 +1,28 @@
|
||||
#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_ */
|
13
src/cryfs_lib/CryFile.cpp
Normal file
13
src/cryfs_lib/CryFile.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
#include "CryFile.h"
|
||||
#include "CryErrnoException.h"
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryFile::CryFile(CryDevice *device, const bf::path &path)
|
||||
:CryNode(device, path) {
|
||||
}
|
||||
|
||||
CryFile::~CryFile() {
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
20
src/cryfs_lib/CryFile.h
Normal file
20
src/cryfs_lib/CryFile.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_CRYFILE_H_
|
||||
#define CRYFS_LIB_CRYFILE_H_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "CryDevice.h"
|
||||
#include "CryNode.h"
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
class CryFile: public CryNode {
|
||||
public:
|
||||
CryFile(CryDevice *device, const bf::path &path);
|
||||
virtual ~CryFile();
|
||||
};
|
||||
|
||||
} /* namespace cryfs */
|
||||
|
||||
#endif /* CRYFS_LIB_CRYFILE_H_ */
|
20
src/cryfs_lib/CryNode.cpp
Normal file
20
src/cryfs_lib/CryNode.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
#include "CryNode.h"
|
||||
|
||||
#include "CryDevice.h"
|
||||
#include "CryErrnoException.h"
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
CryNode::CryNode(CryDevice *device, const bf::path &path)
|
||||
:_device(device), _path(path) {
|
||||
}
|
||||
|
||||
CryNode::~CryNode() {
|
||||
}
|
||||
|
||||
void CryNode::stat(struct stat *result) const {
|
||||
int retval = ::lstat(base_path().c_str(), result);
|
||||
CHECK_RETVAL(retval);
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
39
src/cryfs_lib/CryNode.h
Normal file
39
src/cryfs_lib/CryNode.h
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#ifndef CRYFS_LIB_CRYNODE_H_
|
||||
#define CRYFS_LIB_CRYNODE_H_
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "utils/macros.h"
|
||||
#include "CryDevice.h"
|
||||
#include <sys/stat.h>
|
||||
|
||||
namespace cryfs {
|
||||
|
||||
namespace bf = boost::filesystem;
|
||||
|
||||
class CryNode {
|
||||
public:
|
||||
CryNode(CryDevice *device, const bf::path &path);
|
||||
virtual ~CryNode();
|
||||
|
||||
void stat(struct stat *result) const;
|
||||
|
||||
protected:
|
||||
bf::path base_path() const;
|
||||
CryDevice *device();
|
||||
|
||||
private:
|
||||
CryDevice *const _device;
|
||||
const bf::path _path;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(CryNode);
|
||||
};
|
||||
|
||||
inline bf::path CryNode::base_path() const {
|
||||
return _device->RootDir() / _path;
|
||||
}
|
||||
|
||||
} /* namespace cryfs */
|
||||
|
||||
#endif /* CRYFS_LIB_CRYNODE_H_ */
|
@ -6,5 +6,4 @@
|
||||
Class(const Class &rhs) = delete; \
|
||||
Class &operator=(const Class &rhs) = delete;
|
||||
|
||||
|
||||
#endif /* CRYFS_LIB_UTILS_MACROS_H_ */
|
||||
|
@ -8,7 +8,7 @@
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
printf("Version: %d\n", buildconfig::VERSION::MAJOR);
|
||||
cryfs::CryDevice device(fusepp::path("/mnt/root"));
|
||||
cryfs::CryDevice device(fusepp::path("/home/heinzi/cryfstest/root"));
|
||||
cryfs::CryFuse fuse(&device);
|
||||
fuse.run(argc, argv);
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user