2014-11-15 16:33:24 +01:00
|
|
|
#include "CryDir.h"
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
|
2015-02-17 01:02:15 +01:00
|
|
|
#include "messmer/fspp/fuse/FuseErrnoException.h"
|
2014-11-15 16:33:24 +01:00
|
|
|
#include "CryDevice.h"
|
|
|
|
#include "CryFile.h"
|
2015-03-11 00:23:52 +01:00
|
|
|
#include "CryOpenFile.h"
|
2014-11-15 16:33:24 +01:00
|
|
|
|
|
|
|
//TODO Get rid of this in favor of exception hierarchy
|
2014-11-28 14:46:45 +01:00
|
|
|
using fspp::fuse::CHECK_RETVAL;
|
2014-12-07 08:57:23 +01:00
|
|
|
using fspp::fuse::FuseErrnoException;
|
2014-11-15 16:33:24 +01:00
|
|
|
|
|
|
|
namespace bf = boost::filesystem;
|
|
|
|
|
|
|
|
using std::unique_ptr;
|
|
|
|
using std::make_unique;
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2015-03-11 00:23:52 +01:00
|
|
|
using blockstore::Key;
|
|
|
|
|
2014-11-15 16:33:24 +01:00
|
|
|
namespace cryfs {
|
|
|
|
|
2015-03-11 00:23:52 +01:00
|
|
|
CryDir::CryDir(CryDevice *device, const Key &key)
|
|
|
|
: _device(device), _key(key) {
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CryDir::~CryDir() {
|
|
|
|
}
|
|
|
|
|
2015-03-08 03:25:20 +01:00
|
|
|
void CryDir::stat(struct ::stat *result) const {
|
|
|
|
result->st_mode = S_IFDIR | S_IRUSR | S_IXUSR | S_IWUSR;
|
|
|
|
return;
|
|
|
|
throw FuseErrnoException(ENOTSUP);
|
|
|
|
}
|
|
|
|
|
2015-03-11 00:23:52 +01:00
|
|
|
unique_ptr<fspp::OpenFile> CryDir::createAndOpenFile(const string &name, mode_t mode) {
|
|
|
|
auto blob = LoadBlob();
|
2015-02-27 00:51:51 +01:00
|
|
|
auto child = _device->CreateBlob();
|
2015-03-11 00:23:52 +01:00
|
|
|
Key childkey = child->key();
|
|
|
|
blob->AddChildFile(name, childkey);
|
|
|
|
//TODO Do we need a return value in createDir for fspp? If not, change fspp Dir interface!
|
|
|
|
auto childblob = FileBlob::InitializeEmptyFile(std::move(child));
|
|
|
|
return make_unique<CryOpenFile>(std::move(childblob));
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
2015-03-11 00:23:52 +01:00
|
|
|
void CryDir::createDir(const string &name, mode_t mode) {
|
|
|
|
auto blob = LoadBlob();
|
2015-02-27 00:51:51 +01:00
|
|
|
auto child = _device->CreateBlob();
|
2015-03-11 00:23:52 +01:00
|
|
|
Key childkey = child->key();
|
|
|
|
blob->AddChildDir(name, childkey);
|
|
|
|
DirBlob::InitializeEmptyDir(std::move(child));
|
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<DirBlob> CryDir::LoadBlob() const {
|
|
|
|
return make_unique<DirBlob>(_device->LoadBlob(_key));
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CryDir::rmdir() {
|
2014-12-07 08:57:23 +01:00
|
|
|
throw FuseErrnoException(ENOTSUP);
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
2015-03-10 21:51:42 +01:00
|
|
|
unique_ptr<vector<fspp::Dir::Entry>> CryDir::children() const {
|
2015-03-11 00:23:52 +01:00
|
|
|
return LoadBlob()->GetChildren();
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 08:57:23 +01:00
|
|
|
}
|