Allow creating files

This commit is contained in:
Sebastian Messmer 2014-12-09 16:34:34 +01:00
parent 79455cf01f
commit ebc70cff53
3 changed files with 20 additions and 2 deletions

View File

@ -30,14 +30,21 @@ CryDir::~CryDir() {
} }
unique_ptr<fspp::File> CryDir::createFile(const string &name, mode_t mode) { unique_ptr<fspp::File> 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<FileBlob>(std::move(child.blob));
fileblob->InitializeEmptyFile();
return make_unique<CryFile>(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) {
auto child = _device->CreateBlob(CryDevice::DIR_BLOBSIZE); auto child = _device->CreateBlob(CryDevice::DIR_BLOBSIZE);
_blob->AddChild(name, child.key); _blob->AddChild(name, child.key);
//TODO I don't think we need a return value in createDir for fspp. Change fspp! //TODO I don't think we need a return value in createDir for fspp. Change fspp!
return make_unique<CryDir>(_device, make_unique<DirBlob>(std::move(child.blob))); auto dirblob = make_unique<DirBlob>(std::move(child.blob));
dirblob->InitializeEmptyDir();
return make_unique<CryDir>(_device, std::move(dirblob));
} }
void CryDir::rmdir() { void CryDir::rmdir() {

View File

@ -14,6 +14,14 @@ FileBlob::FileBlob(unique_ptr<Blob> blob)
FileBlob::~FileBlob() { FileBlob::~FileBlob() {
} }
void FileBlob::InitializeEmptyFile() {
*magicNumber() = MagicNumbers::FILE;
}
unsigned char *FileBlob::magicNumber() {
return const_cast<unsigned char*>(magicNumber(const_cast<const Blob&>(*_blob)));
}
const unsigned char *FileBlob::magicNumber(const blobstore::Blob &blob) { const unsigned char *FileBlob::magicNumber(const blobstore::Blob &blob) {
return (unsigned char*)blob.data(); return (unsigned char*)blob.data();
} }

View File

@ -15,9 +15,12 @@ public:
static bool IsFile(const blobstore::Blob &blob); static bool IsFile(const blobstore::Blob &blob);
void InitializeEmptyFile();
private: private:
std::unique_ptr<blobstore::Blob> _blob; std::unique_ptr<blobstore::Blob> _blob;
unsigned char *magicNumber();
static const unsigned char *magicNumber(const blobstore::Blob &blob); static const unsigned char *magicNumber(const blobstore::Blob &blob);
}; };