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>
|
|
|
|
|
2014-11-28 14:46:45 +01:00
|
|
|
#include "fspp/fuse/FuseErrnoException.h"
|
2014-11-15 16:33:24 +01:00
|
|
|
#include "CryDevice.h"
|
|
|
|
#include "CryFile.h"
|
|
|
|
|
|
|
|
//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;
|
|
|
|
|
|
|
|
namespace cryfs {
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
CryDir::CryDir(CryDevice *device, unique_ptr<DirBlock> block)
|
|
|
|
: _device(device), _block(std::move(block)) {
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CryDir::~CryDir() {
|
|
|
|
}
|
|
|
|
|
2014-11-16 00:05:28 +01:00
|
|
|
unique_ptr<fspp::File> CryDir::createFile(const string &name, mode_t mode) {
|
2014-12-09 17:19:59 +01:00
|
|
|
auto child = _device->CreateBlock(0);
|
|
|
|
_block->AddChild(name, child.key);
|
2014-12-09 16:34:34 +01:00
|
|
|
//TODO Di we need a return value in createDir for fspp? If not, change fspp!
|
2014-12-09 17:19:59 +01:00
|
|
|
auto fileblock = make_unique<FileBlock>(std::move(child.block));
|
|
|
|
fileblock->InitializeEmptyFile();
|
|
|
|
return make_unique<CryFile>(std::move(fileblock));
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-16 00:05:28 +01:00
|
|
|
unique_ptr<fspp::Dir> CryDir::createDir(const string &name, mode_t mode) {
|
2014-12-09 17:19:59 +01:00
|
|
|
auto child = _device->CreateBlock(CryDevice::DIR_BLOCKSIZE);
|
|
|
|
_block->AddChild(name, child.key);
|
2014-12-07 10:42:16 +01:00
|
|
|
//TODO I don't think we need a return value in createDir for fspp. Change fspp!
|
2014-12-09 17:19:59 +01:00
|
|
|
auto dirblock = make_unique<DirBlock>(std::move(child.block));
|
|
|
|
dirblock->InitializeEmptyDir();
|
|
|
|
return make_unique<CryDir>(_device, std::move(dirblock));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
unique_ptr<vector<string>> CryDir::children() const {
|
2014-12-09 17:19:59 +01:00
|
|
|
return _block->GetChildren();
|
2014-11-15 16:33:24 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 08:57:23 +01:00
|
|
|
}
|