diff --git a/src/cryfs/CMakeLists.txt b/src/cryfs/CMakeLists.txt index 10b56865..b8a80105 100644 --- a/src/cryfs/CMakeLists.txt +++ b/src/cryfs/CMakeLists.txt @@ -35,6 +35,7 @@ set(LIB_SOURCES impl/filesystem/parallelaccessfsblobstore/FsBlobRef.cpp impl/filesystem/parallelaccessfsblobstore/FileBlobRef.cpp impl/filesystem/parallelaccessfsblobstore/SymlinkBlobRef.cpp + impl/filesystem/entry_helper.cpp impl/filesystem/CrySymlink.cpp impl/filesystem/CryDir.cpp impl/filesystem/cachingfsblobstore/DirBlobRef.cpp diff --git a/src/cryfs/impl/filesystem/CryNode.cpp b/src/cryfs/impl/filesystem/CryNode.cpp index 20a36f11..20de3045 100644 --- a/src/cryfs/impl/filesystem/CryNode.cpp +++ b/src/cryfs/impl/filesystem/CryNode.cpp @@ -8,6 +8,7 @@ #include #include #include +#include "entry_helper.h" namespace bf = boost::filesystem; @@ -185,9 +186,11 @@ CryNode::stat_info CryNode::stat() const { result.ctime = now; return result; } else { - return (*_parent)->statChild(_blockId, [&] (const blockstore::BlockId &blobId) { - return _device->LoadBlob(blobId)->lstat_size(); - }); + auto childOpt = (*_parent)->GetChild(_blockId); + if (childOpt == boost::none) { + throw fspp::fuse::FuseErrnoException(ENOENT); + } + return dirEntryToStatInfo(*childOpt, LoadBlob()->lstat_size()); } } diff --git a/src/cryfs/impl/filesystem/CryOpenFile.cpp b/src/cryfs/impl/filesystem/CryOpenFile.cpp index 036e6fac..da923fb9 100644 --- a/src/cryfs/impl/filesystem/CryOpenFile.cpp +++ b/src/cryfs/impl/filesystem/CryOpenFile.cpp @@ -5,6 +5,7 @@ #include "CryDevice.h" #include +#include "entry_helper.h" using std::shared_ptr; @@ -32,7 +33,11 @@ void CryOpenFile::flush() { fspp::Node::stat_info CryOpenFile::stat() const { _device->callFsActionCallbacks(); - return _parent->statChildWithKnownSize(_fileBlob->blockId(), _fileBlob->size()); + auto childOpt = _parent->GetChild(_fileBlob->blockId()); + if (childOpt == boost::none) { + throw fspp::fuse::FuseErrnoException(ENOENT); + } + return dirEntryToStatInfo(*childOpt, _fileBlob->size()); } void CryOpenFile::truncate(fspp::num_bytes_t size) const { diff --git a/src/cryfs/impl/filesystem/cachingfsblobstore/DirBlobRef.h b/src/cryfs/impl/filesystem/cachingfsblobstore/DirBlobRef.h index 4c363c16..ebcca09b 100644 --- a/src/cryfs/impl/filesystem/cachingfsblobstore/DirBlobRef.h +++ b/src/cryfs/impl/filesystem/cachingfsblobstore/DirBlobRef.h @@ -54,14 +54,6 @@ public: return _base->RenameChild(blockId, newName, onOverwritten); } - fspp::Node::stat_info statChild(const blockstore::BlockId &blockId, std::function getLstatSize) const { - return _base->statChild(blockId, std::move(getLstatSize)); - } - - fspp::Node::stat_info statChildWithKnownSize(const blockstore::BlockId &blockId, fspp::num_bytes_t size) const { - return _base->statChildWithKnownSize(blockId, size); - } - void updateAccessTimestampForChild(const blockstore::BlockId &blockId, fspp::TimestampUpdateBehavior timestampUpdateBehavior) { return _base->updateAccessTimestampForChild(blockId, timestampUpdateBehavior); } diff --git a/src/cryfs/impl/filesystem/entry_helper.cpp b/src/cryfs/impl/filesystem/entry_helper.cpp new file mode 100644 index 00000000..00144c56 --- /dev/null +++ b/src/cryfs/impl/filesystem/entry_helper.cpp @@ -0,0 +1,21 @@ +#include "entry_helper.h" +#include "blobstore/implementations/onblocks/utils/Math.h" + +namespace cryfs { +fspp::Node::stat_info dirEntryToStatInfo(const fsblobstore::DirEntry &dirEntry, fspp::num_bytes_t size) { + fspp::Node::stat_info result; + + result.mode = dirEntry.mode(); + result.uid = dirEntry.uid(); + result.gid = dirEntry.gid(); + //TODO If possible without performance loss, then for a directory, st_nlink should return number of dir entries (including "." and "..") + result.nlink = 1; + result.size = size; + result.atime = dirEntry.lastAccessTime(); + result.mtime = dirEntry.lastModificationTime(); + result.ctime = dirEntry.lastMetadataChangeTime(); + //TODO Move ceilDivision to general utils which can be used by cryfs as well + result.blocks = blobstore::onblocks::utils::ceilDivision(size.value(), static_cast(512)); + return result; +} +} diff --git a/src/cryfs/impl/filesystem/entry_helper.h b/src/cryfs/impl/filesystem/entry_helper.h new file mode 100644 index 00000000..cac7ae2b --- /dev/null +++ b/src/cryfs/impl/filesystem/entry_helper.h @@ -0,0 +1,16 @@ +#pragma once +#ifndef MESSMER_CRYFS_FILESYSTEM_ENTRYHELPER_H_ +#define MESSMER_CRYFS_FILESYSTEM_ENTRYHELPER_H_ + +#include +#include +#include +#include "cryfs/impl/filesystem/fsblobstore/utils/DirEntry.h" + +namespace cryfs { + +fspp::Node::stat_info dirEntryToStatInfo(const fsblobstore::DirEntry &direntry, fspp::num_bytes_t size); + +} + +#endif \ No newline at end of file diff --git a/src/cryfs/impl/filesystem/fsblobstore/DirBlob.cpp b/src/cryfs/impl/filesystem/fsblobstore/DirBlob.cpp index c8d2346b..cc5148ba 100644 --- a/src/cryfs/impl/filesystem/fsblobstore/DirBlob.cpp +++ b/src/cryfs/impl/filesystem/fsblobstore/DirBlob.cpp @@ -136,33 +136,6 @@ fspp::num_bytes_t DirBlob::lstat_size() const { return DIR_LSTAT_SIZE; } -fspp::Node::stat_info DirBlob::statChild(const BlockId &blockId, std::function getLstatSize) const { - auto lstatSize = getLstatSize(blockId); - return statChildWithKnownSize(blockId, lstatSize); -} - -fspp::Node::stat_info DirBlob::statChildWithKnownSize(const BlockId &blockId, fspp::num_bytes_t size) const { - fspp::Node::stat_info result; - - auto childOpt = GetChild(blockId); - if (childOpt == boost::none) { - throw fspp::fuse::FuseErrnoException(ENOENT); - } - const auto &child = *childOpt; - result.mode = child.mode(); - result.uid = child.uid(); - result.gid = child.gid(); - //TODO If possible without performance loss, then for a directory, st_nlink should return number of dir entries (including "." and "..") - result.nlink = 1; - result.size = size; - result.atime = child.lastAccessTime(); - result.mtime = child.lastModificationTime(); - result.ctime = child.lastMetadataChangeTime(); - //TODO Move ceilDivision to general utils which can be used by cryfs as well - result.blocks = blobstore::onblocks::utils::ceilDivision(size.value(), static_cast(512)); - return result; -} - void DirBlob::updateAccessTimestampForChild(const BlockId &blockId, fspp::TimestampUpdateBehavior timestampUpdateBehavior) { std::unique_lock lock(_entriesAndChangedMutex); if (_entries.updateAccessTimestampForChild(blockId, timestampUpdateBehavior)) { diff --git a/src/cryfs/impl/filesystem/fsblobstore/DirBlob.h b/src/cryfs/impl/filesystem/fsblobstore/DirBlob.h index ce50f34d..1d7689a9 100644 --- a/src/cryfs/impl/filesystem/fsblobstore/DirBlob.h +++ b/src/cryfs/impl/filesystem/fsblobstore/DirBlob.h @@ -56,10 +56,6 @@ namespace cryfs { void flush(); - fspp::Node::stat_info statChild(const blockstore::BlockId &blockId, std::function) const; - - fspp::Node::stat_info statChildWithKnownSize(const blockstore::BlockId &blockId, fspp::num_bytes_t size) const; - void updateAccessTimestampForChild(const blockstore::BlockId &blockId, fspp::TimestampUpdateBehavior timestampUpdateBehavior); void updateModificationTimestampForChild(const blockstore::BlockId &blockId); diff --git a/src/cryfs/impl/filesystem/parallelaccessfsblobstore/DirBlobRef.h b/src/cryfs/impl/filesystem/parallelaccessfsblobstore/DirBlobRef.h index 75e2115e..12a2b588 100644 --- a/src/cryfs/impl/filesystem/parallelaccessfsblobstore/DirBlobRef.h +++ b/src/cryfs/impl/filesystem/parallelaccessfsblobstore/DirBlobRef.h @@ -49,14 +49,6 @@ public: return _base->RenameChild(blockId, newName, onOverwritten); } - fspp::Node::stat_info statChild(const blockstore::BlockId &blockId, std::function getLstatSize) const { - return _base->statChild(blockId, std::move(getLstatSize)); - } - - fspp::Node::stat_info statChildWithKnownSize(const blockstore::BlockId &blockId, fspp::num_bytes_t size) const { - return _base->statChildWithKnownSize(blockId, size); - } - void updateAccessTimestampForChild(const blockstore::BlockId &blockId, fspp::TimestampUpdateBehavior timestampUpdateBehavior) { return _base->updateAccessTimestampForChild(blockId, timestampUpdateBehavior); }