Started implementing reading/writing files
This commit is contained in:
parent
e4a0084ea3
commit
43c4f29927
@ -71,7 +71,7 @@ unique_ptr<fspp::Node> CryDevice::Load(const bf::path &path) {
|
|||||||
if (DirBlob::IsDir(*currentBlob)) {
|
if (DirBlob::IsDir(*currentBlob)) {
|
||||||
return make_unique<CryDir>(this, std::move(make_unique<DirBlob>(std::move(currentBlob))));
|
return make_unique<CryDir>(this, std::move(make_unique<DirBlob>(std::move(currentBlob))));
|
||||||
} else if (FileBlob::IsFile(*currentBlob)) {
|
} else if (FileBlob::IsFile(*currentBlob)) {
|
||||||
return make_unique<CryFile>(std::move(make_unique<FileBlob>(std::move(currentBlob))));
|
return make_unique<CryFile>(this, std::move(make_unique<FileBlob>(std::move(currentBlob))));
|
||||||
} else {
|
} else {
|
||||||
throw FuseErrnoException(EIO);
|
throw FuseErrnoException(EIO);
|
||||||
}
|
}
|
||||||
@ -85,4 +85,8 @@ unique_ptr<blobstore::Blob> CryDevice::CreateBlob() {
|
|||||||
return _blobStore->create();
|
return _blobStore->create();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unique_ptr<blobstore::Blob> CryDevice::LoadBlob(const blockstore::Key &key) {
|
||||||
|
return _blobStore->load(key);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public:
|
|||||||
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
||||||
|
|
||||||
std::unique_ptr<blobstore::Blob> CreateBlob();
|
std::unique_ptr<blobstore::Blob> CreateBlob();
|
||||||
|
std::unique_ptr<blobstore::Blob> LoadBlob(const blockstore::Key &key);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
blockstore::Key GetOrCreateRootKey(CryConfig *config);
|
blockstore::Key GetOrCreateRootKey(CryConfig *config);
|
||||||
|
@ -41,7 +41,7 @@ unique_ptr<fspp::File> CryDir::createFile(const string &name, mode_t mode) {
|
|||||||
//TODO Do we need a return value in createDir for fspp? If not, change fspp!
|
//TODO Do we need a return value in createDir for fspp? If not, change fspp!
|
||||||
auto fileblob = make_unique<FileBlob>(std::move(child));
|
auto fileblob = make_unique<FileBlob>(std::move(child));
|
||||||
fileblob->InitializeEmptyFile();
|
fileblob->InitializeEmptyFile();
|
||||||
return make_unique<CryFile>(std::move(fileblob));
|
return make_unique<CryFile>(_device, std::move(fileblob));
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<fspp::Dir> CryDir::createDir(const string &name, mode_t mode) {
|
unique_ptr<fspp::Dir> CryDir::createDir(const string &name, mode_t mode) {
|
||||||
|
@ -15,15 +15,17 @@ using std::make_unique;
|
|||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
CryFile::CryFile(unique_ptr<FileBlob> blob)
|
CryFile::CryFile(CryDevice *device, unique_ptr<FileBlob> blob)
|
||||||
: _blob(std::move(blob)) {
|
: _device(device),
|
||||||
|
_blob(std::move(blob)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CryFile::~CryFile() {
|
CryFile::~CryFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
|
unique_ptr<fspp::OpenFile> CryFile::open(int flags) const {
|
||||||
throw FuseErrnoException(ENOTSUP);
|
//TODO This is a performance issue because we open the blob twice on the "open" syscall
|
||||||
|
return make_unique<CryOpenFile>(make_unique<FileBlob>(_device->LoadBlob(_blob->key())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryFile::stat(struct ::stat *result) const {
|
void CryFile::stat(struct ::stat *result) const {
|
||||||
|
@ -11,7 +11,7 @@ namespace cryfs {
|
|||||||
|
|
||||||
class CryFile: public fspp::File, CryNode {
|
class CryFile: public fspp::File, CryNode {
|
||||||
public:
|
public:
|
||||||
CryFile(std::unique_ptr<FileBlob> blob);
|
CryFile(CryDevice *device, std::unique_ptr<FileBlob> blob);
|
||||||
virtual ~CryFile();
|
virtual ~CryFile();
|
||||||
|
|
||||||
void stat(struct ::stat *result) const override;
|
void stat(struct ::stat *result) const override;
|
||||||
@ -20,6 +20,7 @@ public:
|
|||||||
void unlink() override;
|
void unlink() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
CryDevice *_device;
|
||||||
std::unique_ptr<FileBlob> _blob;
|
std::unique_ptr<FileBlob> _blob;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CryFile);
|
DISALLOW_COPY_AND_ASSIGN(CryFile);
|
||||||
|
@ -5,17 +5,21 @@
|
|||||||
|
|
||||||
#include "CryDevice.h"
|
#include "CryDevice.h"
|
||||||
#include "messmer/fspp/fuse/FuseErrnoException.h"
|
#include "messmer/fspp/fuse/FuseErrnoException.h"
|
||||||
|
#include "impl/FileBlob.h"
|
||||||
|
|
||||||
namespace bf = boost::filesystem;
|
namespace bf = boost::filesystem;
|
||||||
|
|
||||||
|
using std::unique_ptr;
|
||||||
|
using blobstore::Blob;
|
||||||
|
|
||||||
//TODO Get rid of this in favor of a exception hierarchy
|
//TODO Get rid of this in favor of a exception hierarchy
|
||||||
using fspp::fuse::CHECK_RETVAL;
|
using fspp::fuse::CHECK_RETVAL;
|
||||||
using fspp::fuse::FuseErrnoException;
|
using fspp::fuse::FuseErrnoException;
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
|
|
||||||
CryOpenFile::CryOpenFile() {
|
CryOpenFile::CryOpenFile(unique_ptr<FileBlob> fileBlob)
|
||||||
throw FuseErrnoException(ENOTSUP);
|
: _fileBlob(std::move(fileBlob)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CryOpenFile::~CryOpenFile() {
|
CryOpenFile::~CryOpenFile() {
|
||||||
@ -35,11 +39,13 @@ void CryOpenFile::truncate(off_t size) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int CryOpenFile::read(void *buf, size_t count, off_t offset) {
|
int CryOpenFile::read(void *buf, size_t count, off_t offset) {
|
||||||
throw FuseErrnoException(ENOTSUP);
|
//TODO Return number of read bytes
|
||||||
|
_fileBlob->read(buf, offset, count);
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryOpenFile::write(const void *buf, size_t count, off_t offset) {
|
void CryOpenFile::write(const void *buf, size_t count, off_t offset) {
|
||||||
throw FuseErrnoException(ENOTSUP);
|
_fileBlob->write(buf, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryOpenFile::fsync() {
|
void CryOpenFile::fsync() {
|
||||||
|
@ -7,10 +7,11 @@
|
|||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
class CryDevice;
|
class CryDevice;
|
||||||
|
class FileBlob;
|
||||||
|
|
||||||
class CryOpenFile: public fspp::OpenFile {
|
class CryOpenFile: public fspp::OpenFile {
|
||||||
public:
|
public:
|
||||||
CryOpenFile();
|
CryOpenFile(std::unique_ptr<FileBlob> fileBlob);
|
||||||
virtual ~CryOpenFile();
|
virtual ~CryOpenFile();
|
||||||
|
|
||||||
void stat(struct ::stat *result) const override;
|
void stat(struct ::stat *result) const override;
|
||||||
@ -22,6 +23,7 @@ public:
|
|||||||
void fdatasync() override;
|
void fdatasync() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unique_ptr<FileBlob> _fileBlob;
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CryOpenFile);
|
DISALLOW_COPY_AND_ASSIGN(CryOpenFile);
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "FileBlob.h"
|
#include "FileBlob.h"
|
||||||
|
|
||||||
#include "MagicNumbers.h"
|
#include "MagicNumbers.h"
|
||||||
|
#include <messmer/blockstore/utils/Key.h>
|
||||||
|
|
||||||
using std::unique_ptr;
|
using std::unique_ptr;
|
||||||
using blobstore::Blob;
|
using blobstore::Blob;
|
||||||
@ -34,4 +35,16 @@ bool FileBlob::IsFile(const Blob &blob) {
|
|||||||
return magicNumber(blob) == MagicNumbers::FILE;
|
return magicNumber(blob) == MagicNumbers::FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileBlob::read(void *target, uint64_t offset, uint64_t count) const {
|
||||||
|
_blob->read(target, offset + 1, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileBlob::write(const void *source, uint64_t offset, uint64_t count) {
|
||||||
|
_blob->write(source, offset + 1, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
blockstore::Key FileBlob::key() const {
|
||||||
|
return _blob->key();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,11 @@ public:
|
|||||||
|
|
||||||
void InitializeEmptyFile();
|
void InitializeEmptyFile();
|
||||||
|
|
||||||
|
void read(void *target, uint64_t offset, uint64_t count) const;
|
||||||
|
void write(const void *source, uint64_t offset, uint64_t count);
|
||||||
|
|
||||||
|
blockstore::Key key() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<blobstore::Blob> _blob;
|
std::unique_ptr<blobstore::Blob> _blob;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user