diff --git a/src/cryfs_lib/CryDir.cpp b/src/cryfs_lib/CryDir.cpp index cfd806dc..5f9a2464 100644 --- a/src/cryfs_lib/CryDir.cpp +++ b/src/cryfs_lib/CryDir.cpp @@ -30,14 +30,21 @@ CryDir::~CryDir() { } unique_ptr CryDir::createFile(const string &name, mode_t mode) { - throw FuseErrnoException(ENOTSUP); + auto child = _device->CreateBlob(0); + _blob->AddChild(name, child.key); + //TODO Di we need a return value in createDir for fspp? If not, change fspp! + auto fileblob = make_unique(std::move(child.blob)); + fileblob->InitializeEmptyFile(); + return make_unique(std::move(fileblob)); } unique_ptr CryDir::createDir(const string &name, mode_t mode) { auto child = _device->CreateBlob(CryDevice::DIR_BLOBSIZE); _blob->AddChild(name, child.key); //TODO I don't think we need a return value in createDir for fspp. Change fspp! - return make_unique(_device, make_unique(std::move(child.blob))); + auto dirblob = make_unique(std::move(child.blob)); + dirblob->InitializeEmptyDir(); + return make_unique(_device, std::move(dirblob)); } void CryDir::rmdir() { diff --git a/src/cryfs_lib/impl/FileBlob.cpp b/src/cryfs_lib/impl/FileBlob.cpp index ef9a9ac8..7525a0ed 100644 --- a/src/cryfs_lib/impl/FileBlob.cpp +++ b/src/cryfs_lib/impl/FileBlob.cpp @@ -14,6 +14,14 @@ FileBlob::FileBlob(unique_ptr blob) FileBlob::~FileBlob() { } +void FileBlob::InitializeEmptyFile() { + *magicNumber() = MagicNumbers::FILE; +} + +unsigned char *FileBlob::magicNumber() { + return const_cast(magicNumber(const_cast(*_blob))); +} + const unsigned char *FileBlob::magicNumber(const blobstore::Blob &blob) { return (unsigned char*)blob.data(); } diff --git a/src/cryfs_lib/impl/FileBlob.h b/src/cryfs_lib/impl/FileBlob.h index af2c9390..5b1a31a1 100644 --- a/src/cryfs_lib/impl/FileBlob.h +++ b/src/cryfs_lib/impl/FileBlob.h @@ -15,9 +15,12 @@ public: static bool IsFile(const blobstore::Blob &blob); + void InitializeEmptyFile(); + private: std::unique_ptr _blob; + unsigned char *magicNumber(); static const unsigned char *magicNumber(const blobstore::Blob &blob); };