Further simplify getLstatSize

This commit is contained in:
Sebastian Messmer 2022-12-18 07:14:13 +01:00
parent 9ac813270b
commit 4c10d47cd6
9 changed files with 50 additions and 51 deletions

View File

@ -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

View File

@ -8,6 +8,7 @@
#include <cpp-utils/system/time.h>
#include <cpp-utils/system/stat.h>
#include <cpp-utils/logging/logging.h>
#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());
}
}

View File

@ -5,6 +5,7 @@
#include "CryDevice.h"
#include <fspp/fs_interface/FuseErrnoException.h>
#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 {

View File

@ -54,14 +54,6 @@ public:
return _base->RenameChild(blockId, newName, onOverwritten);
}
fspp::Node::stat_info statChild(const blockstore::BlockId &blockId, std::function<fspp::num_bytes_t(const blockstore::BlockId&)> 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);
}

View File

@ -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<int64_t>(512));
return result;
}
}

View File

@ -0,0 +1,16 @@
#pragma once
#ifndef MESSMER_CRYFS_FILESYSTEM_ENTRYHELPER_H_
#define MESSMER_CRYFS_FILESYSTEM_ENTRYHELPER_H_
#include <cpp-utils/macros.h>
#include <fspp/fs_interface/Dir.h>
#include <fspp/fs_interface/Node.h>
#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

View File

@ -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<fspp::num_bytes_t(const blockstore::BlockId&)> 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<int64_t>(512));
return result;
}
void DirBlob::updateAccessTimestampForChild(const BlockId &blockId, fspp::TimestampUpdateBehavior timestampUpdateBehavior) {
std::unique_lock<std::mutex> lock(_entriesAndChangedMutex);
if (_entries.updateAccessTimestampForChild(blockId, timestampUpdateBehavior)) {

View File

@ -56,10 +56,6 @@ namespace cryfs {
void flush();
fspp::Node::stat_info statChild(const blockstore::BlockId &blockId, std::function<fspp::num_bytes_t (const blockstore::BlockId&)>) 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);

View File

@ -49,14 +49,6 @@ public:
return _base->RenameChild(blockId, newName, onOverwritten);
}
fspp::Node::stat_info statChild(const blockstore::BlockId &blockId, std::function<fspp::num_bytes_t(const blockstore::BlockId&)> 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);
}