Further simplify getLstatSize
This commit is contained in:
parent
9ac813270b
commit
4c10d47cd6
@ -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
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
21
src/cryfs/impl/filesystem/entry_helper.cpp
Normal file
21
src/cryfs/impl/filesystem/entry_helper.cpp
Normal 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;
|
||||
}
|
||||
}
|
16
src/cryfs/impl/filesystem/entry_helper.h
Normal file
16
src/cryfs/impl/filesystem/entry_helper.h
Normal 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
|
@ -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)) {
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user