Introduce fspp::num_bytes_t
This commit is contained in:
parent
26e33a44ea
commit
8d21e09159
@ -59,7 +59,7 @@ void DataLeafNode::resize(uint32_t new_size) {
|
|||||||
node().setSize(new_size);
|
node().setSize(new_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataLeafNode::fillDataWithZeroesFromTo(off_t begin, off_t end) {
|
void DataLeafNode::fillDataWithZeroesFromTo(uint64_t begin, uint64_t end) {
|
||||||
Data ZEROES(end-begin);
|
Data ZEROES(end-begin);
|
||||||
ZEROES.FillWithZeroes();
|
ZEROES.FillWithZeroes();
|
||||||
node().write(ZEROES.data(), begin, end-begin);
|
node().write(ZEROES.data(), begin, end-begin);
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
void resize(uint32_t size);
|
void resize(uint32_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fillDataWithZeroesFromTo(off_t begin, off_t end);
|
void fillDataWithZeroesFromTo(uint64_t begin, uint64_t end);
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(DataLeafNode);
|
DISALLOW_COPY_AND_ASSIGN(DataLeafNode);
|
||||||
};
|
};
|
||||||
|
@ -40,7 +40,7 @@ unique_ref<fspp::OpenFile> CryFile::open(int flags) {
|
|||||||
return make_unique_ref<CryOpenFile>(device(), parent(), std::move(blob));
|
return make_unique_ref<CryOpenFile>(device(), parent(), std::move(blob));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryFile::truncate(off_t size) {
|
void CryFile::truncate(fspp::num_bytes_t size) {
|
||||||
device()->callFsActionCallbacks();
|
device()->callFsActionCallbacks();
|
||||||
auto blob = LoadBlob(); // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
|
auto blob = LoadBlob(); // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
|
||||||
blob->resize(size);
|
blob->resize(size);
|
||||||
|
@ -15,7 +15,7 @@ public:
|
|||||||
~CryFile();
|
~CryFile();
|
||||||
|
|
||||||
cpputils::unique_ref<fspp::OpenFile> open(int flags) override;
|
cpputils::unique_ref<fspp::OpenFile> open(int flags) override;
|
||||||
void truncate(off_t size) override;
|
void truncate(fspp::num_bytes_t size) override;
|
||||||
fspp::Dir::EntryType getType() const override;
|
fspp::Dir::EntryType getType() const override;
|
||||||
void remove() override;
|
void remove() override;
|
||||||
|
|
||||||
|
@ -35,19 +35,19 @@ fspp::Node::stat_info CryOpenFile::stat() const {
|
|||||||
return _parent->statChildWithKnownSize(_fileBlob->blockId(), _fileBlob->size());
|
return _parent->statChildWithKnownSize(_fileBlob->blockId(), _fileBlob->size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryOpenFile::truncate(off_t size) const {
|
void CryOpenFile::truncate(fspp::num_bytes_t size) const {
|
||||||
_device->callFsActionCallbacks();
|
_device->callFsActionCallbacks();
|
||||||
_fileBlob->resize(size);
|
_fileBlob->resize(size);
|
||||||
_parent->updateModificationTimestampForChild(_fileBlob->blockId());
|
_parent->updateModificationTimestampForChild(_fileBlob->blockId());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CryOpenFile::read(void *buf, size_t count, off_t offset) const {
|
fspp::num_bytes_t CryOpenFile::read(void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) const {
|
||||||
_device->callFsActionCallbacks();
|
_device->callFsActionCallbacks();
|
||||||
_parent->updateAccessTimestampForChild(_fileBlob->blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME);
|
_parent->updateAccessTimestampForChild(_fileBlob->blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME);
|
||||||
return _fileBlob->read(buf, offset, count);
|
return _fileBlob->read(buf, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CryOpenFile::write(const void *buf, size_t count, off_t offset) {
|
void CryOpenFile::write(const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
_device->callFsActionCallbacks();
|
_device->callFsActionCallbacks();
|
||||||
_parent->updateModificationTimestampForChild(_fileBlob->blockId());
|
_parent->updateModificationTimestampForChild(_fileBlob->blockId());
|
||||||
_fileBlob->write(buf, offset, count);
|
_fileBlob->write(buf, offset, count);
|
||||||
|
@ -15,9 +15,9 @@ public:
|
|||||||
~CryOpenFile();
|
~CryOpenFile();
|
||||||
|
|
||||||
stat_info stat() const override;
|
stat_info stat() const override;
|
||||||
void truncate(off_t size) const override;
|
void truncate(fspp::num_bytes_t size) const override;
|
||||||
size_t read(void *buf, size_t count, off_t offset) const override;
|
fspp::num_bytes_t read(void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) const override;
|
||||||
void write(const void *buf, size_t count, off_t offset) override;
|
void write(const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) override;
|
||||||
void flush() override;
|
void flush() override;
|
||||||
void fsync() override;
|
void fsync() override;
|
||||||
void fdatasync() override;
|
void fdatasync() override;
|
||||||
|
@ -58,7 +58,7 @@ public:
|
|||||||
return _base->statChild(blockId);
|
return _base->statChild(blockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
fspp::Node::stat_info statChildWithKnownSize(const blockstore::BlockId &blockId, uint64_t size) const {
|
fspp::Node::stat_info statChildWithKnownSize(const blockstore::BlockId &blockId, fspp::num_bytes_t size) const {
|
||||||
return _base->statChildWithKnownSize(blockId, size);
|
return _base->statChildWithKnownSize(blockId, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,11 +102,11 @@ public:
|
|||||||
return _base->blockId();
|
return _base->blockId();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t lstat_size() const {
|
fspp::num_bytes_t lstat_size() const {
|
||||||
return _base->lstat_size();
|
return _base->lstat_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLstatSizeGetter(std::function<off_t(const blockstore::BlockId&)> getLstatSize) {
|
void setLstatSizeGetter(std::function<fspp::num_bytes_t(const blockstore::BlockId&)> getLstatSize) {
|
||||||
return _base->setLstatSizeGetter(getLstatSize);
|
return _base->setLstatSizeGetter(getLstatSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,19 +16,19 @@ public:
|
|||||||
ASSERT(_base != nullptr, "We just initialized this with a pointer to FileBlob. Can't be something else now.");
|
ASSERT(_base != nullptr, "We just initialized this with a pointer to FileBlob. Can't be something else now.");
|
||||||
}
|
}
|
||||||
|
|
||||||
void resize(off_t size) {
|
void resize(fspp::num_bytes_t size) {
|
||||||
return _base->resize(size);
|
return _base->resize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t size() const {
|
fspp::num_bytes_t size() const {
|
||||||
return _base->size();
|
return _base->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t read(void *target, uint64_t offset, uint64_t count) const {
|
fspp::num_bytes_t read(void *target, fspp::num_bytes_t offset, fspp::num_bytes_t count) const {
|
||||||
return _base->read(target, offset, count);
|
return _base->read(target, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const void *source, uint64_t offset, uint64_t count) {
|
void write(const void *source, fspp::num_bytes_t offset, fspp::num_bytes_t count) {
|
||||||
return _base->write(source, offset, count);
|
return _base->write(source, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +40,7 @@ public:
|
|||||||
return _base->blockId();
|
return _base->blockId();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t lstat_size() const {
|
fspp::num_bytes_t lstat_size() const {
|
||||||
return _base->lstat_size();
|
return _base->lstat_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class FsBlobRef {
|
|||||||
public:
|
public:
|
||||||
virtual ~FsBlobRef();
|
virtual ~FsBlobRef();
|
||||||
virtual const blockstore::BlockId &blockId() const = 0;
|
virtual const blockstore::BlockId &blockId() const = 0;
|
||||||
virtual off_t lstat_size() const = 0;
|
virtual fspp::num_bytes_t lstat_size() const = 0;
|
||||||
|
|
||||||
const blockstore::BlockId &parentPointer() const {
|
const blockstore::BlockId &parentPointer() const {
|
||||||
return _baseBlob->parentPointer();
|
return _baseBlob->parentPointer();
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
return _base->blockId();
|
return _base->blockId();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t lstat_size() const {
|
fspp::num_bytes_t lstat_size() const {
|
||||||
return _base->lstat_size();
|
return _base->lstat_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ using boost::none;
|
|||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
namespace fsblobstore {
|
namespace fsblobstore {
|
||||||
|
|
||||||
constexpr off_t DirBlob::DIR_LSTAT_SIZE;
|
constexpr fspp::num_bytes_t DirBlob::DIR_LSTAT_SIZE;
|
||||||
|
|
||||||
DirBlob::DirBlob(FsBlobStore *fsBlobStore, unique_ref<Blob> blob, std::function<off_t (const blockstore::BlockId&)> getLstatSize) :
|
DirBlob::DirBlob(FsBlobStore *fsBlobStore, unique_ref<Blob> blob, std::function<fspp::num_bytes_t (const blockstore::BlockId&)> getLstatSize) :
|
||||||
FsBlob(std::move(blob)), _fsBlobStore(fsBlobStore), _getLstatSize(getLstatSize), _entries(), _mutex(), _changed(false) {
|
FsBlob(std::move(blob)), _fsBlobStore(fsBlobStore), _getLstatSize(getLstatSize), _entries(), _mutex(), _changed(false) {
|
||||||
ASSERT(baseBlob().blobType() == FsBlobView::BlobType::DIR, "Loaded blob is not a directory");
|
ASSERT(baseBlob().blobType() == FsBlobView::BlobType::DIR, "Loaded blob is not a directory");
|
||||||
_readEntriesFromBlob();
|
_readEntriesFromBlob();
|
||||||
@ -43,7 +43,7 @@ void DirBlob::flush() {
|
|||||||
baseBlob().flush();
|
baseBlob().flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
unique_ref<DirBlob> DirBlob::InitializeEmptyDir(FsBlobStore *fsBlobStore, unique_ref<Blob> blob, const blockstore::BlockId &parent, std::function<off_t(const blockstore::BlockId&)> getLstatSize) {
|
unique_ref<DirBlob> DirBlob::InitializeEmptyDir(FsBlobStore *fsBlobStore, unique_ref<Blob> blob, const blockstore::BlockId &parent, std::function<fspp::num_bytes_t(const blockstore::BlockId&)> getLstatSize) {
|
||||||
InitializeBlob(blob.get(), FsBlobView::BlobType::DIR, parent);
|
InitializeBlob(blob.get(), FsBlobView::BlobType::DIR, parent);
|
||||||
return make_unique_ref<DirBlob>(fsBlobStore, std::move(blob), getLstatSize);
|
return make_unique_ref<DirBlob>(fsBlobStore, std::move(blob), getLstatSize);
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ void DirBlob::AppendChildrenTo(vector<fspp::Dir::Entry> *result) const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t DirBlob::lstat_size() const {
|
fspp::num_bytes_t DirBlob::lstat_size() const {
|
||||||
return DIR_LSTAT_SIZE;
|
return DIR_LSTAT_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ fspp::Node::stat_info DirBlob::statChild(const BlockId &blockId) const {
|
|||||||
return statChildWithKnownSize(blockId, _getLstatSize(blockId));
|
return statChildWithKnownSize(blockId, _getLstatSize(blockId));
|
||||||
}
|
}
|
||||||
|
|
||||||
fspp::Node::stat_info DirBlob::statChildWithKnownSize(const BlockId &blockId, uint64_t size) const {
|
fspp::Node::stat_info DirBlob::statChildWithKnownSize(const BlockId &blockId, fspp::num_bytes_t size) const {
|
||||||
fspp::Node::stat_info result;
|
fspp::Node::stat_info result;
|
||||||
|
|
||||||
auto childOpt = GetChild(blockId);
|
auto childOpt = GetChild(blockId);
|
||||||
@ -158,7 +158,7 @@ fspp::Node::stat_info DirBlob::statChildWithKnownSize(const BlockId &blockId, ui
|
|||||||
result.mtime = child.lastModificationTime();
|
result.mtime = child.lastModificationTime();
|
||||||
result.ctime = child.lastMetadataChangeTime();
|
result.ctime = child.lastMetadataChangeTime();
|
||||||
//TODO Move ceilDivision to general utils which can be used by cryfs as well
|
//TODO Move ceilDivision to general utils which can be used by cryfs as well
|
||||||
result.blocks = blobstore::onblocks::utils::ceilDivision(size, static_cast<uint64_t>(512));
|
result.blocks = blobstore::onblocks::utils::ceilDivision(size.value(), static_cast<int64_t>(512));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ void DirBlob::utimensChild(const BlockId &blockId, timespec lastAccessTime, time
|
|||||||
_changed = true;
|
_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DirBlob::setLstatSizeGetter(std::function<off_t(const blockstore::BlockId&)> getLstatSize) {
|
void DirBlob::setLstatSizeGetter(std::function<fspp::num_bytes_t(const blockstore::BlockId&)> getLstatSize) {
|
||||||
std::unique_lock<std::mutex> lock(_mutex);
|
std::unique_lock<std::mutex> lock(_mutex);
|
||||||
_getLstatSize = getLstatSize;
|
_getLstatSize = getLstatSize;
|
||||||
}
|
}
|
||||||
|
@ -16,17 +16,17 @@ namespace cryfs {
|
|||||||
|
|
||||||
class DirBlob final : public FsBlob {
|
class DirBlob final : public FsBlob {
|
||||||
public:
|
public:
|
||||||
constexpr static off_t DIR_LSTAT_SIZE = 4096;
|
constexpr static fspp::num_bytes_t DIR_LSTAT_SIZE = fspp::num_bytes_t(4096);
|
||||||
|
|
||||||
static cpputils::unique_ref<DirBlob> InitializeEmptyDir(FsBlobStore *fsBlobStore, cpputils::unique_ref<blobstore::Blob> blob,
|
static cpputils::unique_ref<DirBlob> InitializeEmptyDir(FsBlobStore *fsBlobStore, cpputils::unique_ref<blobstore::Blob> blob,
|
||||||
const blockstore::BlockId &parent,
|
const blockstore::BlockId &parent,
|
||||||
std::function<off_t (const blockstore::BlockId&)> getLstatSize);
|
std::function<fspp::num_bytes_t (const blockstore::BlockId&)> getLstatSize);
|
||||||
|
|
||||||
DirBlob(FsBlobStore *fsBlobStore, cpputils::unique_ref<blobstore::Blob> blob, std::function<off_t (const blockstore::BlockId&)> getLstatSize);
|
DirBlob(FsBlobStore *fsBlobStore, cpputils::unique_ref<blobstore::Blob> blob, std::function<fspp::num_bytes_t (const blockstore::BlockId&)> getLstatSize);
|
||||||
|
|
||||||
~DirBlob();
|
~DirBlob();
|
||||||
|
|
||||||
off_t lstat_size() const override;
|
fspp::num_bytes_t lstat_size() const override;
|
||||||
|
|
||||||
void AppendChildrenTo(std::vector<fspp::Dir::Entry> *result) const;
|
void AppendChildrenTo(std::vector<fspp::Dir::Entry> *result) const;
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ namespace cryfs {
|
|||||||
|
|
||||||
fspp::Node::stat_info statChild(const blockstore::BlockId &blockId) const;
|
fspp::Node::stat_info statChild(const blockstore::BlockId &blockId) const;
|
||||||
|
|
||||||
fspp::Node::stat_info statChildWithKnownSize(const blockstore::BlockId &blockId, uint64_t size) const;
|
fspp::Node::stat_info statChildWithKnownSize(const blockstore::BlockId &blockId, fspp::num_bytes_t size) const;
|
||||||
|
|
||||||
void updateAccessTimestampForChild(const blockstore::BlockId &blockId, TimestampUpdateBehavior timestampUpdateBehavior);
|
void updateAccessTimestampForChild(const blockstore::BlockId &blockId, TimestampUpdateBehavior timestampUpdateBehavior);
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ namespace cryfs {
|
|||||||
|
|
||||||
void utimensChild(const blockstore::BlockId &blockId, timespec lastAccessTime, timespec lastModificationTime);
|
void utimensChild(const blockstore::BlockId &blockId, timespec lastAccessTime, timespec lastModificationTime);
|
||||||
|
|
||||||
void setLstatSizeGetter(std::function<off_t(const blockstore::BlockId&)> getLstatSize);
|
void setLstatSizeGetter(std::function<fspp::num_bytes_t(const blockstore::BlockId&)> getLstatSize);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ namespace cryfs {
|
|||||||
cpputils::unique_ref<blobstore::Blob> releaseBaseBlob() override;
|
cpputils::unique_ref<blobstore::Blob> releaseBaseBlob() override;
|
||||||
|
|
||||||
FsBlobStore *_fsBlobStore;
|
FsBlobStore *_fsBlobStore;
|
||||||
std::function<off_t (const blockstore::BlockId&)> _getLstatSize;
|
std::function<fspp::num_bytes_t (const blockstore::BlockId&)> _getLstatSize;
|
||||||
DirEntryList _entries;
|
DirEntryList _entries;
|
||||||
mutable std::mutex _mutex;
|
mutable std::mutex _mutex;
|
||||||
bool _changed;
|
bool _changed;
|
||||||
|
@ -21,28 +21,28 @@ unique_ref<FileBlob> FileBlob::InitializeEmptyFile(unique_ref<Blob> blob, const
|
|||||||
return make_unique_ref<FileBlob>(std::move(blob));
|
return make_unique_ref<FileBlob>(std::move(blob));
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t FileBlob::read(void *target, uint64_t offset, uint64_t count) const {
|
fspp::num_bytes_t FileBlob::read(void *target, fspp::num_bytes_t offset, fspp::num_bytes_t count) const {
|
||||||
return baseBlob().tryRead(target, offset, count);
|
return fspp::num_bytes_t(baseBlob().tryRead(target, offset.value(), count.value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileBlob::write(const void *source, uint64_t offset, uint64_t count) {
|
void FileBlob::write(const void *source, fspp::num_bytes_t offset, fspp::num_bytes_t count) {
|
||||||
baseBlob().write(source, offset, count);
|
baseBlob().write(source, offset.value(), count.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileBlob::flush() {
|
void FileBlob::flush() {
|
||||||
baseBlob().flush();
|
baseBlob().flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileBlob::resize(off_t size) {
|
void FileBlob::resize(fspp::num_bytes_t size) {
|
||||||
baseBlob().resize(size);
|
baseBlob().resize(size.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t FileBlob::lstat_size() const {
|
fspp::num_bytes_t FileBlob::lstat_size() const {
|
||||||
return size();
|
return size();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t FileBlob::size() const {
|
fspp::num_bytes_t FileBlob::size() const {
|
||||||
return baseBlob().size();
|
return fspp::num_bytes_t(baseBlob().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,17 +13,17 @@ namespace cryfs {
|
|||||||
|
|
||||||
FileBlob(cpputils::unique_ref<blobstore::Blob> blob);
|
FileBlob(cpputils::unique_ref<blobstore::Blob> blob);
|
||||||
|
|
||||||
size_t read(void *target, uint64_t offset, uint64_t count) const;
|
fspp::num_bytes_t read(void *target, fspp::num_bytes_t offset, fspp::num_bytes_t count) const;
|
||||||
|
|
||||||
void write(const void *source, uint64_t offset, uint64_t count);
|
void write(const void *source, fspp::num_bytes_t offset, fspp::num_bytes_t count);
|
||||||
|
|
||||||
void flush();
|
void flush();
|
||||||
|
|
||||||
void resize(off_t size);
|
void resize(fspp::num_bytes_t size);
|
||||||
|
|
||||||
off_t lstat_size() const override;
|
fspp::num_bytes_t lstat_size() const override;
|
||||||
|
|
||||||
off_t size() const;
|
fspp::num_bytes_t size() const;
|
||||||
private:
|
private:
|
||||||
DISALLOW_COPY_AND_ASSIGN(FileBlob);
|
DISALLOW_COPY_AND_ASSIGN(FileBlob);
|
||||||
};
|
};
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include <cpp-utils/pointer/unique_ref.h>
|
#include <cpp-utils/pointer/unique_ref.h>
|
||||||
#include <blobstore/interface/Blob.h>
|
#include <blobstore/interface/Blob.h>
|
||||||
#include "FsBlobView.h"
|
#include "FsBlobView.h"
|
||||||
|
#include <fspp/fs_interface/Types.h>
|
||||||
|
|
||||||
namespace cryfs {
|
namespace cryfs {
|
||||||
namespace fsblobstore {
|
namespace fsblobstore {
|
||||||
@ -12,7 +13,7 @@ namespace cryfs {
|
|||||||
public:
|
public:
|
||||||
virtual ~FsBlob();
|
virtual ~FsBlob();
|
||||||
|
|
||||||
virtual off_t lstat_size() const = 0;
|
virtual fspp::num_bytes_t lstat_size() const = 0;
|
||||||
const blockstore::BlockId &blockId() const;
|
const blockstore::BlockId &blockId() const;
|
||||||
const blockstore::BlockId &parentPointer() const;
|
const blockstore::BlockId &parentPointer() const;
|
||||||
void setParentPointer(const blockstore::BlockId &parentId);
|
void setParentPointer(const blockstore::BlockId &parentId);
|
||||||
|
@ -38,7 +38,7 @@ namespace cryfs {
|
|||||||
void _migrate(cpputils::unique_ref<blobstore::Blob> node, const blockstore::BlockId &parentId);
|
void _migrate(cpputils::unique_ref<blobstore::Blob> node, const blockstore::BlockId &parentId);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::function<off_t(const blockstore::BlockId &)> _getLstatSize();
|
std::function<fspp::num_bytes_t(const blockstore::BlockId &)> _getLstatSize();
|
||||||
|
|
||||||
cpputils::unique_ref<blobstore::BlobStore> _baseBlobStore;
|
cpputils::unique_ref<blobstore::BlobStore> _baseBlobStore;
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ namespace cryfs {
|
|||||||
_baseBlobStore->remove(blockId);
|
_baseBlobStore->remove(blockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::function<off_t (const blockstore::BlockId &)> FsBlobStore::_getLstatSize() {
|
inline std::function<fspp::num_bytes_t (const blockstore::BlockId &)> FsBlobStore::_getLstatSize() {
|
||||||
return [this] (const blockstore::BlockId &blockId) {
|
return [this] (const blockstore::BlockId &blockId) {
|
||||||
auto blob = load(blockId);
|
auto blob = load(blockId);
|
||||||
ASSERT(blob != boost::none, "Blob not found");
|
ASSERT(blob != boost::none, "Blob not found");
|
||||||
|
@ -38,8 +38,8 @@ const bf::path &SymlinkBlob::target() const {
|
|||||||
return _target;
|
return _target;
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t SymlinkBlob::lstat_size() const {
|
fspp::num_bytes_t SymlinkBlob::lstat_size() const {
|
||||||
return target().string().size();
|
return fspp::num_bytes_t(target().string().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ namespace cryfs {
|
|||||||
|
|
||||||
const boost::filesystem::path &target() const;
|
const boost::filesystem::path &target() const;
|
||||||
|
|
||||||
off_t lstat_size() const override;
|
fspp::num_bytes_t lstat_size() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
boost::filesystem::path _target;
|
boost::filesystem::path _target;
|
||||||
|
@ -54,7 +54,7 @@ public:
|
|||||||
return _base->statChild(blockId);
|
return _base->statChild(blockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
fspp::Node::stat_info statChildWithKnownSize(const blockstore::BlockId &blockId, uint64_t size) const {
|
fspp::Node::stat_info statChildWithKnownSize(const blockstore::BlockId &blockId, fspp::num_bytes_t size) const {
|
||||||
return _base->statChildWithKnownSize(blockId, size);
|
return _base->statChildWithKnownSize(blockId, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ public:
|
|||||||
return _base->blockId();
|
return _base->blockId();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t lstat_size() const override {
|
fspp::num_bytes_t lstat_size() const override {
|
||||||
return _base->lstat_size();
|
return _base->lstat_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,19 +12,19 @@ class FileBlobRef final: public FsBlobRef {
|
|||||||
public:
|
public:
|
||||||
FileBlobRef(cachingfsblobstore::FileBlobRef *base) : _base(base) {}
|
FileBlobRef(cachingfsblobstore::FileBlobRef *base) : _base(base) {}
|
||||||
|
|
||||||
void resize(off_t size) {
|
void resize(fspp::num_bytes_t size) {
|
||||||
return _base->resize(size);
|
return _base->resize(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t size() const {
|
fspp::num_bytes_t size() const {
|
||||||
return _base->size();
|
return _base->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t read(void *target, uint64_t offset, uint64_t count) const {
|
fspp::num_bytes_t read(void *target, fspp::num_bytes_t offset, fspp::num_bytes_t count) const {
|
||||||
return _base->read(target, offset, count);
|
return _base->read(target, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(const void *source, uint64_t offset, uint64_t count) {
|
void write(const void *source, fspp::num_bytes_t offset, fspp::num_bytes_t count) {
|
||||||
return _base->write(source, offset, count);
|
return _base->write(source, offset, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ public:
|
|||||||
return _base->blockId();
|
return _base->blockId();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t lstat_size() const override {
|
fspp::num_bytes_t lstat_size() const override {
|
||||||
return _base->lstat_size();
|
return _base->lstat_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ class FsBlobRef: public parallelaccessstore::ParallelAccessStore<cachingfsblobst
|
|||||||
public:
|
public:
|
||||||
virtual ~FsBlobRef() {}
|
virtual ~FsBlobRef() {}
|
||||||
virtual const blockstore::BlockId &blockId() const = 0;
|
virtual const blockstore::BlockId &blockId() const = 0;
|
||||||
virtual off_t lstat_size() const = 0;
|
virtual fspp::num_bytes_t lstat_size() const = 0;
|
||||||
virtual const blockstore::BlockId &parentPointer() const = 0;
|
virtual const blockstore::BlockId &parentPointer() const = 0;
|
||||||
virtual void setParentPointer(const blockstore::BlockId &parentId) = 0;
|
virtual void setParentPointer(const blockstore::BlockId &parentId) = 0;
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ namespace cryfs {
|
|||||||
cpputils::unique_ref<cachingfsblobstore::CachingFsBlobStore> _baseBlobStore;
|
cpputils::unique_ref<cachingfsblobstore::CachingFsBlobStore> _baseBlobStore;
|
||||||
parallelaccessstore::ParallelAccessStore<cachingfsblobstore::FsBlobRef, FsBlobRef, blockstore::BlockId> _parallelAccessStore;
|
parallelaccessstore::ParallelAccessStore<cachingfsblobstore::FsBlobRef, FsBlobRef, blockstore::BlockId> _parallelAccessStore;
|
||||||
|
|
||||||
std::function<off_t (const blockstore::BlockId &)> _getLstatSize();
|
std::function<fspp::num_bytes_t (const blockstore::BlockId &)> _getLstatSize();
|
||||||
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(ParallelAccessFsBlobStore);
|
DISALLOW_COPY_AND_ASSIGN(ParallelAccessFsBlobStore);
|
||||||
};
|
};
|
||||||
@ -50,7 +50,7 @@ namespace cryfs {
|
|||||||
return _parallelAccessStore.remove(blockId, std::move(blob));
|
return _parallelAccessStore.remove(blockId, std::move(blob));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::function<off_t (const blockstore::BlockId &blockId)> ParallelAccessFsBlobStore::_getLstatSize() {
|
inline std::function<fspp::num_bytes_t (const blockstore::BlockId &blockId)> ParallelAccessFsBlobStore::_getLstatSize() {
|
||||||
return [this] (const blockstore::BlockId &blockId) {
|
return [this] (const blockstore::BlockId &blockId) {
|
||||||
auto blob = load(blockId);
|
auto blob = load(blockId);
|
||||||
ASSERT(blob != boost::none, "Blob not found");
|
ASSERT(blob != boost::none, "Blob not found");
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
return _base->blockId();
|
return _base->blockId();
|
||||||
}
|
}
|
||||||
|
|
||||||
off_t lstat_size() const override {
|
fspp::num_bytes_t lstat_size() const override {
|
||||||
return _base->lstat_size();
|
return _base->lstat_size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#define MESSMER_FSPP_FSINTERFACE_FILE_H_
|
#define MESSMER_FSPP_FSINTERFACE_FILE_H_
|
||||||
|
|
||||||
#include <cpp-utils/pointer/unique_ref.h>
|
#include <cpp-utils/pointer/unique_ref.h>
|
||||||
|
#include "Types.h"
|
||||||
|
|
||||||
namespace fspp {
|
namespace fspp {
|
||||||
class Device;
|
class Device;
|
||||||
@ -13,7 +14,7 @@ public:
|
|||||||
virtual ~File() {}
|
virtual ~File() {}
|
||||||
|
|
||||||
virtual cpputils::unique_ref<OpenFile> open(int flags) = 0;
|
virtual cpputils::unique_ref<OpenFile> open(int flags) = 0;
|
||||||
virtual void truncate(off_t size) = 0;
|
virtual void truncate(fspp::num_bytes_t size) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,9 @@ public:
|
|||||||
using stat_info = fspp::stat_info;
|
using stat_info = fspp::stat_info;
|
||||||
|
|
||||||
virtual stat_info stat() const = 0;
|
virtual stat_info stat() const = 0;
|
||||||
virtual void truncate(off_t size) const = 0;
|
virtual void truncate(fspp::num_bytes_t size) const = 0;
|
||||||
virtual size_t read(void *buf, size_t count, off_t offset) const = 0;
|
virtual fspp::num_bytes_t read(void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) const = 0;
|
||||||
virtual void write(const void *buf, size_t count, off_t offset) = 0;
|
virtual void write(const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) = 0;
|
||||||
virtual void flush() = 0;
|
virtual void flush() = 0;
|
||||||
virtual void fsync() = 0;
|
virtual void fsync() = 0;
|
||||||
virtual void fdatasync() = 0;
|
virtual void fdatasync() = 0;
|
||||||
|
@ -113,12 +113,23 @@ struct mode_t final : cpputils::value_type::FlagsValueType<mode_t, uint32_t> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct num_bytes_t final : cpputils::value_type::QuantityValueType<num_bytes_t, int64_t> {
|
||||||
|
// TODO Remove default constructor
|
||||||
|
constexpr num_bytes_t() noexcept: QuantityValueType(0) {}
|
||||||
|
|
||||||
|
constexpr explicit num_bytes_t(int64_t id) noexcept: QuantityValueType(id) {}
|
||||||
|
|
||||||
|
constexpr int64_t value() const noexcept {
|
||||||
|
return value_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
struct stat_info final {
|
struct stat_info final {
|
||||||
uint32_t nlink;
|
uint32_t nlink;
|
||||||
fspp::mode_t mode;
|
fspp::mode_t mode;
|
||||||
fspp::uid_t uid;
|
fspp::uid_t uid;
|
||||||
fspp::gid_t gid;
|
fspp::gid_t gid;
|
||||||
uint64_t size;
|
fspp::num_bytes_t size;
|
||||||
uint64_t blocks;
|
uint64_t blocks;
|
||||||
struct timespec atime;
|
struct timespec atime;
|
||||||
struct timespec mtime;
|
struct timespec mtime;
|
||||||
|
@ -24,36 +24,36 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Test_Truncate_DontChange1(fspp::File *file, fspp::Node *node) {
|
void Test_Truncate_DontChange1(fspp::File *file, fspp::Node *node) {
|
||||||
file->truncate(0);
|
file->truncate(fspp::num_bytes_t(0));
|
||||||
this->EXPECT_SIZE(0, file, node);
|
this->EXPECT_SIZE(fspp::num_bytes_t(0), file, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_Truncate_GrowTo1(fspp::File *file, fspp::Node *node) {
|
void Test_Truncate_GrowTo1(fspp::File *file, fspp::Node *node) {
|
||||||
file->truncate(1);
|
file->truncate(fspp::num_bytes_t(1));
|
||||||
this->EXPECT_SIZE(1, file, node);
|
this->EXPECT_SIZE(fspp::num_bytes_t(1), file, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_Truncate_Grow(fspp::File *file, fspp::Node *node) {
|
void Test_Truncate_Grow(fspp::File *file, fspp::Node *node) {
|
||||||
file->truncate(10*1024*1024);
|
file->truncate(fspp::num_bytes_t(10*1024*1024));
|
||||||
this->EXPECT_SIZE(10*1024*1024, file, node);
|
this->EXPECT_SIZE(fspp::num_bytes_t(10*1024*1024), file, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_Truncate_DontChange2(fspp::File *file, fspp::Node *node) {
|
void Test_Truncate_DontChange2(fspp::File *file, fspp::Node *node) {
|
||||||
file->truncate(10*1024*1024);
|
file->truncate(fspp::num_bytes_t(10*1024*1024));
|
||||||
file->truncate(10*1024*1024);
|
file->truncate(fspp::num_bytes_t(10*1024*1024));
|
||||||
this->EXPECT_SIZE(10*1024*1024, file, node);
|
this->EXPECT_SIZE(fspp::num_bytes_t(10*1024*1024), file, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_Truncate_Shrink(fspp::File *file, fspp::Node *node) {
|
void Test_Truncate_Shrink(fspp::File *file, fspp::Node *node) {
|
||||||
file->truncate(10*1024*1024);
|
file->truncate(fspp::num_bytes_t(10*1024*1024));
|
||||||
file->truncate(5*1024*1024);
|
file->truncate(fspp::num_bytes_t(5*1024*1024));
|
||||||
this->EXPECT_SIZE(5*1024*1024, file, node);
|
this->EXPECT_SIZE(fspp::num_bytes_t(5*1024*1024), file, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_Truncate_ShrinkTo0(fspp::File *file, fspp::Node *node) {
|
void Test_Truncate_ShrinkTo0(fspp::File *file, fspp::Node *node) {
|
||||||
file->truncate(10*1024*1024);
|
file->truncate(fspp::num_bytes_t(10*1024*1024));
|
||||||
file->truncate(0);
|
file->truncate(fspp::num_bytes_t(0));
|
||||||
this->EXPECT_SIZE(0, file, node);
|
this->EXPECT_SIZE(fspp::num_bytes_t(0), file, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Test_Chown_Uid(fspp::File *file, fspp::Node *node) {
|
void Test_Chown_Uid(fspp::File *file, fspp::Node *node) {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
template<class ConcreteFileSystemTestFixture>
|
template<class ConcreteFileSystemTestFixture>
|
||||||
class FsppFileTest_Timestamps: public TimestampTestUtils<ConcreteFileSystemTestFixture> {
|
class FsppFileTest_Timestamps: public TimestampTestUtils<ConcreteFileSystemTestFixture> {
|
||||||
public:
|
public:
|
||||||
cpputils::unique_ref<fspp::File> CreateFileWithSize(const boost::filesystem::path &path, off_t size) {
|
cpputils::unique_ref<fspp::File> CreateFileWithSize(const boost::filesystem::path &path, fspp::num_bytes_t size) {
|
||||||
auto file = this->CreateFile(path);
|
auto file = this->CreateFile(path);
|
||||||
file->truncate(size);
|
file->truncate(size);
|
||||||
assert(this->stat(*this->Load(path)).size == size);
|
assert(this->stat(*this->Load(path)).size == size);
|
||||||
@ -49,41 +49,41 @@ TYPED_TEST_P(FsppFileTest_Timestamps, open_rdwr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_empty_to_empty) {
|
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_empty_to_empty) {
|
||||||
auto file = this->CreateFileWithSize("/myfile", 0);
|
auto file = this->CreateFileWithSize("/myfile", fspp::num_bytes_t(0));
|
||||||
auto operation = [&file] () {
|
auto operation = [&file] () {
|
||||||
file->truncate(0);
|
file->truncate(fspp::num_bytes_t(0));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_empty_to_nonempty) {
|
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_empty_to_nonempty) {
|
||||||
auto file = this->CreateFileWithSize("/myfile", 0);
|
auto file = this->CreateFileWithSize("/myfile", fspp::num_bytes_t(0));
|
||||||
auto operation = [&file] () {
|
auto operation = [&file] () {
|
||||||
file->truncate(10);
|
file->truncate(fspp::num_bytes_t(10));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_nonempty_to_empty) {
|
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_nonempty_to_empty) {
|
||||||
auto file = this->CreateFileWithSize("/myfile", 10);
|
auto file = this->CreateFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
auto operation = [&file] () {
|
auto operation = [&file] () {
|
||||||
file->truncate(0);
|
file->truncate(fspp::num_bytes_t(0));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_nonempty_to_nonempty_shrink) {
|
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_nonempty_to_nonempty_shrink) {
|
||||||
auto file = this->CreateFileWithSize("/myfile", 10);
|
auto file = this->CreateFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
auto operation = [&file] () {
|
auto operation = [&file] () {
|
||||||
file->truncate(5);
|
file->truncate(fspp::num_bytes_t(5));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_nonempty_to_nonempty_grow) {
|
TYPED_TEST_P(FsppFileTest_Timestamps, truncate_nonempty_to_nonempty_grow) {
|
||||||
auto file = this->CreateFileWithSize("/myfile", 10);
|
auto file = this->CreateFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
auto operation = [&file] () {
|
auto operation = [&file] () {
|
||||||
file->truncate(20);
|
file->truncate(fspp::num_bytes_t(20));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ TYPED_TEST_CASE_P(FsppNodeTest_Stat_FileOnly);
|
|||||||
TYPED_TEST_P(FsppNodeTest_Stat_FileOnly, CreatedFileIsEmpty) {
|
TYPED_TEST_P(FsppNodeTest_Stat_FileOnly, CreatedFileIsEmpty) {
|
||||||
this->CreateFile("/myfile");
|
this->CreateFile("/myfile");
|
||||||
auto node = this->Load("/myfile");
|
auto node = this->Load("/myfile");
|
||||||
this->EXPECT_SIZE(0, node.get());
|
this->EXPECT_SIZE(fspp::num_bytes_t(0), node.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppNodeTest_Stat_FileOnly, FileIsFile) {
|
TYPED_TEST_P(FsppNodeTest_Stat_FileOnly, FileIsFile) {
|
||||||
|
@ -12,20 +12,20 @@ public:
|
|||||||
callback(st);
|
callback(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_SIZE(uint64_t expectedSize, fspp::OpenFile *openFile) {
|
void EXPECT_SIZE(fspp::num_bytes_t expectedSize, fspp::OpenFile *openFile) {
|
||||||
IN_STAT(openFile, [expectedSize] (const fspp::OpenFile::stat_info& st) {
|
IN_STAT(openFile, [expectedSize] (const fspp::OpenFile::stat_info& st) {
|
||||||
EXPECT_EQ(expectedSize, static_cast<uint64_t>(st.size));
|
EXPECT_EQ(expectedSize, st.size);
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_NUMBYTES_READABLE(expectedSize, openFile);
|
EXPECT_NUMBYTES_READABLE(expectedSize, openFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_NUMBYTES_READABLE(uint64_t expectedSize, fspp::OpenFile *openFile) {
|
void EXPECT_NUMBYTES_READABLE(fspp::num_bytes_t expectedSize, fspp::OpenFile *openFile) {
|
||||||
cpputils::Data data(expectedSize);
|
cpputils::Data data(expectedSize.value());
|
||||||
//Try to read one byte more than the expected size
|
//Try to read one byte more than the expected size
|
||||||
ssize_t readBytes = openFile->read(data.data(), expectedSize+1, 0);
|
fspp::num_bytes_t readBytes = openFile->read(data.data(), expectedSize+fspp::num_bytes_t(1), fspp::num_bytes_t(0));
|
||||||
//and check that it only read the expected size (but also not less)
|
//and check that it only read the expected size (but also not less)
|
||||||
EXPECT_EQ(expectedSize, static_cast<uint64_t>(readBytes));
|
EXPECT_EQ(expectedSize, readBytes);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ TYPED_TEST_CASE_P(FsppOpenFileTest);
|
|||||||
TYPED_TEST_P(FsppOpenFileTest, CreatedFileIsEmpty) {
|
TYPED_TEST_P(FsppOpenFileTest, CreatedFileIsEmpty) {
|
||||||
auto file = this->CreateFile("/myfile");
|
auto file = this->CreateFile("/myfile");
|
||||||
auto openFile = this->LoadFile("/myfile")->open(O_RDONLY);
|
auto openFile = this->LoadFile("/myfile")->open(O_RDONLY);
|
||||||
this->EXPECT_SIZE(0, openFile.get());
|
this->EXPECT_SIZE(fspp::num_bytes_t(0), openFile.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest, FileIsFile) {
|
TYPED_TEST_P(FsppOpenFileTest, FileIsFile) {
|
||||||
|
@ -10,7 +10,7 @@ public:
|
|||||||
cpputils::unique_ref<fspp::OpenFile> CreateAndOpenFile(const boost::filesystem::path &path) {
|
cpputils::unique_ref<fspp::OpenFile> CreateAndOpenFile(const boost::filesystem::path &path) {
|
||||||
return this->CreateFile(path)->open(O_RDWR);
|
return this->CreateFile(path)->open(O_RDWR);
|
||||||
}
|
}
|
||||||
cpputils::unique_ref<fspp::OpenFile> CreateAndOpenFileWithSize(const boost::filesystem::path &path, off_t size) {
|
cpputils::unique_ref<fspp::OpenFile> CreateAndOpenFileWithSize(const boost::filesystem::path &path, fspp::num_bytes_t size) {
|
||||||
auto file = this->CreateFile(path);
|
auto file = this->CreateFile(path);
|
||||||
file->truncate(size);
|
file->truncate(size);
|
||||||
auto openFile = file->open(O_RDWR);
|
auto openFile = file->open(O_RDWR);
|
||||||
@ -30,82 +30,82 @@ TYPED_TEST_P(FsppOpenFileTest_Timestamps, stat) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, truncate_empty_to_empty) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, truncate_empty_to_empty) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 0);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(0));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
openFile->truncate(0);
|
openFile->truncate(fspp::num_bytes_t(0));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, truncate_empty_to_nonempty) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, truncate_empty_to_nonempty) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 0);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(0));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
openFile->truncate(10);
|
openFile->truncate(fspp::num_bytes_t(10));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, truncate_nonempty_to_empty) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, truncate_nonempty_to_empty) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
openFile->truncate(0);
|
openFile->truncate(fspp::num_bytes_t(0));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, truncate_nonempty_to_nonempty_shrink) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, truncate_nonempty_to_nonempty_shrink) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
openFile->truncate(5);
|
openFile->truncate(fspp::num_bytes_t(5));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, truncate_nonempty_to_nonempty_grow) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, truncate_nonempty_to_nonempty_grow) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
openFile->truncate(20);
|
openFile->truncate(fspp::num_bytes_t(20));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, read_inbounds) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, read_inbounds) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
char buffer[5];
|
char buffer[5];
|
||||||
openFile->read(buffer, 5, 0);
|
openFile->read(buffer, fspp::num_bytes_t(5), fspp::num_bytes_t(0));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectUpdatesAccessTimestamp, this->ExpectDoesntUpdateModificationTimestamp, this->ExpectDoesntUpdateMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectUpdatesAccessTimestamp, this->ExpectDoesntUpdateModificationTimestamp, this->ExpectDoesntUpdateMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, read_outofbounds) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, read_outofbounds) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 0);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(0));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
char buffer[5];
|
char buffer[5];
|
||||||
openFile->read(buffer, 5, 2);
|
openFile->read(buffer, fspp::num_bytes_t(5), fspp::num_bytes_t(2));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectUpdatesAccessTimestamp, this->ExpectDoesntUpdateModificationTimestamp, this->ExpectDoesntUpdateMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectUpdatesAccessTimestamp, this->ExpectDoesntUpdateModificationTimestamp, this->ExpectDoesntUpdateMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, write_inbounds) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, write_inbounds) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
openFile->write("content", 7, 0);
|
openFile->write("content", fspp::num_bytes_t(7), fspp::num_bytes_t(0));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, write_outofbounds) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, write_outofbounds) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 0);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(0));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
openFile->write("content", 7, 2);
|
openFile->write("content", fspp::num_bytes_t(7), fspp::num_bytes_t(2));
|
||||||
};
|
};
|
||||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
|
||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, flush) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, flush) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
openFile->write("content", 7, 0);
|
openFile->write("content", fspp::num_bytes_t(7), fspp::num_bytes_t(0));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
openFile->flush();
|
openFile->flush();
|
||||||
};
|
};
|
||||||
@ -113,8 +113,8 @@ TYPED_TEST_P(FsppOpenFileTest_Timestamps, flush) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, fsync) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, fsync) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
openFile->write("content", 7, 0);
|
openFile->write("content", fspp::num_bytes_t(7), fspp::num_bytes_t(0));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
openFile->fsync();
|
openFile->fsync();
|
||||||
};
|
};
|
||||||
@ -122,8 +122,8 @@ TYPED_TEST_P(FsppOpenFileTest_Timestamps, fsync) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TYPED_TEST_P(FsppOpenFileTest_Timestamps, fdatasync) {
|
TYPED_TEST_P(FsppOpenFileTest_Timestamps, fdatasync) {
|
||||||
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
|
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
|
||||||
openFile->write("content", 7, 0);
|
openFile->write("content", fspp::num_bytes_t(7), fspp::num_bytes_t(0));
|
||||||
auto operation = [&openFile] () {
|
auto operation = [&openFile] () {
|
||||||
openFile->fdatasync();
|
openFile->fdatasync();
|
||||||
};
|
};
|
||||||
|
@ -35,21 +35,21 @@ public:
|
|||||||
callback(st2);
|
callback(st2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_SIZE(uint64_t expectedSize, fspp::File *file, fspp::Node *node) {
|
void EXPECT_SIZE(fspp::num_bytes_t expectedSize, fspp::File *file, fspp::Node *node) {
|
||||||
IN_STAT(file, node, [expectedSize] (const fspp::Node::stat_info& st) {
|
IN_STAT(file, node, [expectedSize] (const fspp::Node::stat_info& st) {
|
||||||
EXPECT_EQ(expectedSize, static_cast<uint64_t>(st.size));
|
EXPECT_EQ(expectedSize, st.size);
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_NUMBYTES_READABLE(expectedSize, file);
|
EXPECT_NUMBYTES_READABLE(expectedSize, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_NUMBYTES_READABLE(uint64_t expectedSize, fspp::File *file) {
|
void EXPECT_NUMBYTES_READABLE(fspp::num_bytes_t expectedSize, fspp::File *file) {
|
||||||
auto openFile = file->open(O_RDONLY);
|
auto openFile = file->open(O_RDONLY);
|
||||||
cpputils::Data data(expectedSize);
|
cpputils::Data data(expectedSize.value());
|
||||||
//Try to read one byte more than the expected size
|
//Try to read one byte more than the expected size
|
||||||
ssize_t readBytes = openFile->read(data.data(), expectedSize+1, 0);
|
fspp::num_bytes_t readBytes = openFile->read(data.data(), expectedSize+fspp::num_bytes_t(1), fspp::num_bytes_t(0));
|
||||||
//and check that it only read the expected size (but also not less)
|
//and check that it only read the expected size (but also not less)
|
||||||
EXPECT_EQ(expectedSize, static_cast<uint64_t>(readBytes));
|
EXPECT_EQ(expectedSize, readBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_ATIME_EQ(struct timespec expected, const fspp::Node::stat_info& st) {
|
void EXPECT_ATIME_EQ(struct timespec expected, const fspp::Node::stat_info& st) {
|
||||||
|
@ -14,9 +14,9 @@ public:
|
|||||||
callback(st);
|
callback(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_SIZE(uint64_t expectedSize, fspp::Node *node) {
|
void EXPECT_SIZE(fspp::num_bytes_t expectedSize, fspp::Node *node) {
|
||||||
IN_STAT(node, [expectedSize] (const fspp::Node::stat_info& st) {
|
IN_STAT(node, [expectedSize] (const fspp::Node::stat_info& st) {
|
||||||
EXPECT_EQ(expectedSize, static_cast<uint64_t>(st.size));
|
EXPECT_EQ(expectedSize, st.size);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -25,10 +25,10 @@ public:
|
|||||||
virtual void chmod(const boost::filesystem::path &path, ::mode_t mode) = 0;
|
virtual void chmod(const boost::filesystem::path &path, ::mode_t mode) = 0;
|
||||||
//TODO Test chown
|
//TODO Test chown
|
||||||
virtual void chown(const boost::filesystem::path &path, ::uid_t uid, ::gid_t gid) = 0;
|
virtual void chown(const boost::filesystem::path &path, ::uid_t uid, ::gid_t gid) = 0;
|
||||||
virtual void truncate(const boost::filesystem::path &path, off_t size) = 0;
|
virtual void truncate(const boost::filesystem::path &path, fspp::num_bytes_t size) = 0;
|
||||||
virtual void ftruncate(int descriptor, off_t size) = 0;
|
virtual void ftruncate(int descriptor, fspp::num_bytes_t size) = 0;
|
||||||
virtual size_t read(int descriptor, void *buf, size_t count, off_t offset) = 0;
|
virtual fspp::num_bytes_t read(int descriptor, void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) = 0;
|
||||||
virtual void write(int descriptor, const void *buf, size_t count, off_t offset) = 0;
|
virtual void write(int descriptor, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) = 0;
|
||||||
virtual void fsync(int descriptor) = 0;
|
virtual void fsync(int descriptor) = 0;
|
||||||
virtual void fdatasync(int descriptor) = 0;
|
virtual void fdatasync(int descriptor) = 0;
|
||||||
virtual void access(const boost::filesystem::path &path, int mask) = 0;
|
virtual void access(const boost::filesystem::path &path, int mask) = 0;
|
||||||
@ -44,7 +44,7 @@ public:
|
|||||||
//TODO Test createSymlink
|
//TODO Test createSymlink
|
||||||
virtual void createSymlink(const boost::filesystem::path &to, const boost::filesystem::path &from, ::uid_t uid, ::gid_t gid) = 0;
|
virtual void createSymlink(const boost::filesystem::path &to, const boost::filesystem::path &from, ::uid_t uid, ::gid_t gid) = 0;
|
||||||
//TODO Test readSymlink
|
//TODO Test readSymlink
|
||||||
virtual void readSymlink(const boost::filesystem::path &path, char *buf, size_t size) = 0;
|
virtual void readSymlink(const boost::filesystem::path &path, char *buf, fspp::num_bytes_t size) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -80,11 +80,11 @@ int fusepp_chown(const char *path, ::uid_t uid, ::gid_t gid) {
|
|||||||
return FUSE_OBJ->chown(bf::path(path), uid, gid);
|
return FUSE_OBJ->chown(bf::path(path), uid, gid);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fusepp_truncate(const char *path, off_t size) {
|
int fusepp_truncate(const char *path, int64_t size) {
|
||||||
return FUSE_OBJ->truncate(bf::path(path), size);
|
return FUSE_OBJ->truncate(bf::path(path), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fusepp_ftruncate(const char *path, off_t size, fuse_file_info *fileinfo) {
|
int fusepp_ftruncate(const char *path, int64_t size, fuse_file_info *fileinfo) {
|
||||||
return FUSE_OBJ->ftruncate(bf::path(path), size, fileinfo);
|
return FUSE_OBJ->ftruncate(bf::path(path), size, fileinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,11 +100,11 @@ int fusepp_release(const char *path, fuse_file_info *fileinfo) {
|
|||||||
return FUSE_OBJ->release(bf::path(path), fileinfo);
|
return FUSE_OBJ->release(bf::path(path), fileinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fusepp_read(const char *path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
|
int fusepp_read(const char *path, char *buf, size_t size, int64_t offset, fuse_file_info *fileinfo) {
|
||||||
return FUSE_OBJ->read(bf::path(path), buf, size, offset, fileinfo);
|
return FUSE_OBJ->read(bf::path(path), buf, size, offset, fileinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fusepp_write(const char *path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
|
int fusepp_write(const char *path, const char *buf, size_t size, int64_t offset, fuse_file_info *fileinfo) {
|
||||||
return FUSE_OBJ->write(bf::path(path), buf, size, offset, fileinfo);
|
return FUSE_OBJ->write(bf::path(path), buf, size, offset, fileinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ int fusepp_opendir(const char *path, fuse_file_info *fileinfo) {
|
|||||||
return FUSE_OBJ->opendir(bf::path(path), fileinfo);
|
return FUSE_OBJ->opendir(bf::path(path), fileinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int fusepp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) {
|
int fusepp_readdir(const char *path, void *buf, fuse_fill_dir_t filler, int64_t offset, fuse_file_info *fileinfo) {
|
||||||
return FUSE_OBJ->readdir(bf::path(path), buf, filler, offset, fileinfo);
|
return FUSE_OBJ->readdir(bf::path(path), buf, filler, offset, fileinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,10 +166,10 @@ int fusepp_create(const char *path, ::mode_t mode, fuse_file_info *fileinfo) {
|
|||||||
int fusepp_bmap(const char*, size_t blocksize, uint64_t *idx)
|
int fusepp_bmap(const char*, size_t blocksize, uint64_t *idx)
|
||||||
int fusepp_ioctl(const char*, int cmd, void *arg, fuse_file_info*, unsigned int flags, void *data)
|
int fusepp_ioctl(const char*, int cmd, void *arg, fuse_file_info*, unsigned int flags, void *data)
|
||||||
int fusepp_poll(const char*, fuse_file_info*, fuse_pollhandle *ph, unsigned *reventsp)
|
int fusepp_poll(const char*, fuse_file_info*, fuse_pollhandle *ph, unsigned *reventsp)
|
||||||
int fusepp_write_buf(const char*, fuse_bufvec *buf, off_t off, fuse_file_info*)
|
int fusepp_write_buf(const char*, fuse_bufvec *buf, int64_t off, fuse_file_info*)
|
||||||
int fusepp_read_buf(const chas*, struct fuse_bufvec **bufp, size_t size, off_T off, fuse_file_info*)
|
int fusepp_read_buf(const chas*, struct fuse_bufvec **bufp, size_t size, int64_t off, fuse_file_info*)
|
||||||
int fusepp_flock(const char*, fuse_file_info*, int op)
|
int fusepp_flock(const char*, fuse_file_info*, int op)
|
||||||
int fusepp_fallocate(const char*, int, off_t, off_t, fuse_file_info*)*/
|
int fusepp_fallocate(const char*, int, int64_t, int64_t, fuse_file_info*)*/
|
||||||
|
|
||||||
fuse_operations *operations() {
|
fuse_operations *operations() {
|
||||||
static std::unique_ptr<fuse_operations> singleton(nullptr);
|
static std::unique_ptr<fuse_operations> singleton(nullptr);
|
||||||
@ -369,7 +369,7 @@ int Fuse::readlink(const bf::path &path, char *buf, size_t size) {
|
|||||||
#endif
|
#endif
|
||||||
try {
|
try {
|
||||||
ASSERT(is_valid_fspp_path(path), "has to be an absolute path");
|
ASSERT(is_valid_fspp_path(path), "has to be an absolute path");
|
||||||
_fs->readSymlink(path, buf, size);
|
_fs->readSymlink(path, buf, fspp::num_bytes_t(size));
|
||||||
return 0;
|
return 0;
|
||||||
} catch(const cpputils::AssertFailed &e) {
|
} catch(const cpputils::AssertFailed &e) {
|
||||||
LOG(ERR, "AssertFailed in Fuse::readlink: {}", e.what());
|
LOG(ERR, "AssertFailed in Fuse::readlink: {}", e.what());
|
||||||
@ -560,13 +560,13 @@ int Fuse::chown(const bf::path &path, ::uid_t uid, ::gid_t gid) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fuse::truncate(const bf::path &path, off_t size) {
|
int Fuse::truncate(const bf::path &path, int64_t size) {
|
||||||
#ifdef FSPP_LOG
|
#ifdef FSPP_LOG
|
||||||
LOG(DEBUG, "truncate({}, {})", path, size);
|
LOG(DEBUG, "truncate({}, {})", path, size);
|
||||||
#endif
|
#endif
|
||||||
try {
|
try {
|
||||||
ASSERT(is_valid_fspp_path(path), "has to be an absolute path");
|
ASSERT(is_valid_fspp_path(path), "has to be an absolute path");
|
||||||
_fs->truncate(path, size);
|
_fs->truncate(path, fspp::num_bytes_t(size));
|
||||||
return 0;
|
return 0;
|
||||||
} catch(const cpputils::AssertFailed &e) {
|
} catch(const cpputils::AssertFailed &e) {
|
||||||
LOG(ERR, "AssertFailed in Fuse::truncate: {}", e.what());
|
LOG(ERR, "AssertFailed in Fuse::truncate: {}", e.what());
|
||||||
@ -582,13 +582,13 @@ int Fuse::truncate(const bf::path &path, off_t size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fuse::ftruncate(const bf::path &path, off_t size, fuse_file_info *fileinfo) {
|
int Fuse::ftruncate(const bf::path &path, int64_t size, fuse_file_info *fileinfo) {
|
||||||
#ifdef FSPP_LOG
|
#ifdef FSPP_LOG
|
||||||
LOG(DEBUG, "ftruncate({}, {})", path, size);
|
LOG(DEBUG, "ftruncate({}, {})", path, size);
|
||||||
#endif
|
#endif
|
||||||
UNUSED(path);
|
UNUSED(path);
|
||||||
try {
|
try {
|
||||||
_fs->ftruncate(fileinfo->fh, size);
|
_fs->ftruncate(fileinfo->fh, fspp::num_bytes_t(size));
|
||||||
return 0;
|
return 0;
|
||||||
} catch(const cpputils::AssertFailed &e) {
|
} catch(const cpputils::AssertFailed &e) {
|
||||||
LOG(ERR, "AssertFailed in Fuse::ftruncate: {}", e.what());
|
LOG(ERR, "AssertFailed in Fuse::ftruncate: {}", e.what());
|
||||||
@ -670,13 +670,13 @@ int Fuse::release(const bf::path &path, fuse_file_info *fileinfo) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fuse::read(const bf::path &path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
|
int Fuse::read(const bf::path &path, char *buf, size_t size, int64_t offset, fuse_file_info *fileinfo) {
|
||||||
#ifdef FSPP_LOG
|
#ifdef FSPP_LOG
|
||||||
LOG(DEBUG, "read({}, _, {}, {}, _)", path, size, offset);
|
LOG(DEBUG, "read({}, _, {}, {}, _)", path, size, offset);
|
||||||
#endif
|
#endif
|
||||||
UNUSED(path);
|
UNUSED(path);
|
||||||
try {
|
try {
|
||||||
return _fs->read(fileinfo->fh, buf, size, offset);
|
return _fs->read(fileinfo->fh, buf, fspp::num_bytes_t(size), fspp::num_bytes_t(offset)).value();
|
||||||
} catch(const cpputils::AssertFailed &e) {
|
} catch(const cpputils::AssertFailed &e) {
|
||||||
LOG(ERR, "AssertFailed in Fuse::read: {}", e.what());
|
LOG(ERR, "AssertFailed in Fuse::read: {}", e.what());
|
||||||
return -EIO;
|
return -EIO;
|
||||||
@ -691,13 +691,13 @@ int Fuse::read(const bf::path &path, char *buf, size_t size, off_t offset, fuse_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fuse::write(const bf::path &path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo) {
|
int Fuse::write(const bf::path &path, const char *buf, size_t size, int64_t offset, fuse_file_info *fileinfo) {
|
||||||
#ifdef FSPP_LOG
|
#ifdef FSPP_LOG
|
||||||
LOG(DEBUG, "write({}, _, {}, {}, _)", path, size, offsset);
|
LOG(DEBUG, "write({}, _, {}, {}, _)", path, size, offsset);
|
||||||
#endif
|
#endif
|
||||||
UNUSED(path);
|
UNUSED(path);
|
||||||
try {
|
try {
|
||||||
_fs->write(fileinfo->fh, buf, size, offset);
|
_fs->write(fileinfo->fh, buf, fspp::num_bytes_t(size), fspp::num_bytes_t(offset));
|
||||||
return size;
|
return size;
|
||||||
} catch(const cpputils::AssertFailed &e) {
|
} catch(const cpputils::AssertFailed &e) {
|
||||||
LOG(ERR, "AssertFailed in Fuse::write: {}", e.what());
|
LOG(ERR, "AssertFailed in Fuse::write: {}", e.what());
|
||||||
@ -792,7 +792,7 @@ int Fuse::opendir(const bf::path &path, fuse_file_info *fileinfo) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Fuse::readdir(const bf::path &path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo) {
|
int Fuse::readdir(const bf::path &path, void *buf, fuse_fill_dir_t filler, int64_t offset, fuse_file_info *fileinfo) {
|
||||||
#ifdef FSPP_LOG
|
#ifdef FSPP_LOG
|
||||||
LOG(DEBUG, "readdir({}, _, _, {}, _)", path, offest);
|
LOG(DEBUG, "readdir({}, _, _, {}, _)", path, offest);
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,18 +39,18 @@ public:
|
|||||||
int link(const boost::filesystem::path &from, const boost::filesystem::path &to);
|
int link(const boost::filesystem::path &from, const boost::filesystem::path &to);
|
||||||
int chmod(const boost::filesystem::path &path, ::mode_t mode);
|
int chmod(const boost::filesystem::path &path, ::mode_t mode);
|
||||||
int chown(const boost::filesystem::path &path, ::uid_t uid, ::gid_t gid);
|
int chown(const boost::filesystem::path &path, ::uid_t uid, ::gid_t gid);
|
||||||
int truncate(const boost::filesystem::path &path, off_t size);
|
int truncate(const boost::filesystem::path &path, int64_t size);
|
||||||
int ftruncate(const boost::filesystem::path &path, off_t size, fuse_file_info *fileinfo);
|
int ftruncate(const boost::filesystem::path &path, int64_t size, fuse_file_info *fileinfo);
|
||||||
int utimens(const boost::filesystem::path &path, const timespec times[2]);
|
int utimens(const boost::filesystem::path &path, const timespec times[2]);
|
||||||
int open(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
int open(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
||||||
int release(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
int release(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
||||||
int read(const boost::filesystem::path &path, char *buf, size_t size, off_t offset, fuse_file_info *fileinfo);
|
int read(const boost::filesystem::path &path, char *buf, size_t size, int64_t offset, fuse_file_info *fileinfo);
|
||||||
int write(const boost::filesystem::path &path, const char *buf, size_t size, off_t offset, fuse_file_info *fileinfo);
|
int write(const boost::filesystem::path &path, const char *buf, size_t size, int64_t offset, fuse_file_info *fileinfo);
|
||||||
int statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat);
|
int statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat);
|
||||||
int flush(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
int flush(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
||||||
int fsync(const boost::filesystem::path &path, int flags, fuse_file_info *fileinfo);
|
int fsync(const boost::filesystem::path &path, int flags, fuse_file_info *fileinfo);
|
||||||
int opendir(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
int opendir(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
||||||
int readdir(const boost::filesystem::path &path, void *buf, fuse_fill_dir_t filler, off_t offset, fuse_file_info *fileinfo);
|
int readdir(const boost::filesystem::path &path, void *buf, fuse_fill_dir_t filler, int64_t offset, fuse_file_info *fileinfo);
|
||||||
int releasedir(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
int releasedir(const boost::filesystem::path &path, fuse_file_info *fileinfo);
|
||||||
int fsyncdir(const boost::filesystem::path &path, int datasync, fuse_file_info *fileinfo);
|
int fsyncdir(const boost::filesystem::path &path, int datasync, fuse_file_info *fileinfo);
|
||||||
void init(fuse_conn_info *conn);
|
void init(fuse_conn_info *conn);
|
||||||
|
@ -144,7 +144,7 @@ void convert_stat_info_(const fspp::Node::stat_info& input, struct ::stat *outpu
|
|||||||
output->st_mode = input.mode.value();
|
output->st_mode = input.mode.value();
|
||||||
output->st_uid = input.uid.value();
|
output->st_uid = input.uid.value();
|
||||||
output->st_gid = input.gid.value();
|
output->st_gid = input.gid.value();
|
||||||
output->st_size = input.size;
|
output->st_size = input.size.value();
|
||||||
output->st_blocks = input.blocks;
|
output->st_blocks = input.blocks;
|
||||||
output->st_atim = input.atime;
|
output->st_atim = input.atime;
|
||||||
output->st_mtim = input.mtime;
|
output->st_mtim = input.mtime;
|
||||||
@ -189,22 +189,22 @@ void FilesystemImpl::chown(const boost::filesystem::path &path, ::uid_t uid, ::g
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilesystemImpl::truncate(const bf::path &path, off_t size) {
|
void FilesystemImpl::truncate(const bf::path &path, fspp::num_bytes_t size) {
|
||||||
PROFILE(_truncateNanosec);
|
PROFILE(_truncateNanosec);
|
||||||
LoadFile(path)->truncate(size);
|
LoadFile(path)->truncate(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilesystemImpl::ftruncate(int descriptor, off_t size) {
|
void FilesystemImpl::ftruncate(int descriptor, fspp::num_bytes_t size) {
|
||||||
PROFILE(_ftruncateNanosec);
|
PROFILE(_ftruncateNanosec);
|
||||||
_open_files.get(descriptor)->truncate(size);
|
_open_files.get(descriptor)->truncate(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t FilesystemImpl::read(int descriptor, void *buf, size_t count, off_t offset) {
|
fspp::num_bytes_t FilesystemImpl::read(int descriptor, void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
PROFILE(_readNanosec);
|
PROFILE(_readNanosec);
|
||||||
return _open_files.get(descriptor)->read(buf, count, offset);
|
return _open_files.get(descriptor)->read(buf, count, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilesystemImpl::write(int descriptor, const void *buf, size_t count, off_t offset) {
|
void FilesystemImpl::write(int descriptor, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
PROFILE(_writeNanosec);
|
PROFILE(_writeNanosec);
|
||||||
_open_files.get(descriptor)->write(buf, count, offset);
|
_open_files.get(descriptor)->write(buf, count, offset);
|
||||||
}
|
}
|
||||||
@ -317,10 +317,10 @@ void FilesystemImpl::createSymlink(const bf::path &to, const bf::path &from, ::u
|
|||||||
parent->createSymlink(from.filename().string(), to, fspp::uid_t(uid), fspp::gid_t(gid));
|
parent->createSymlink(from.filename().string(), to, fspp::uid_t(uid), fspp::gid_t(gid));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilesystemImpl::readSymlink(const bf::path &path, char *buf, size_t size) {
|
void FilesystemImpl::readSymlink(const bf::path &path, char *buf, fspp::num_bytes_t size) {
|
||||||
PROFILE(_readSymlinkNanosec);
|
PROFILE(_readSymlinkNanosec);
|
||||||
string target = LoadSymlink(path)->target().string();
|
string target = LoadSymlink(path)->target().string();
|
||||||
PROFILE(_readSymlinkNanosec_withoutLoading);
|
PROFILE(_readSymlinkNanosec_withoutLoading);
|
||||||
std::memcpy(buf, target.c_str(), std::min(target.size()+1, size));
|
std::memcpy(buf, target.c_str(), std::min(static_cast<int64_t>(target.size()+1), size.value()));
|
||||||
buf[size-1] = '\0';
|
buf[size.value()-1] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -31,10 +31,10 @@ public:
|
|||||||
void fstat(int descriptor, struct ::stat *stbuf) override;
|
void fstat(int descriptor, struct ::stat *stbuf) override;
|
||||||
void chmod(const boost::filesystem::path &path, ::mode_t mode) override;
|
void chmod(const boost::filesystem::path &path, ::mode_t mode) override;
|
||||||
void chown(const boost::filesystem::path &path, ::uid_t uid, ::gid_t gid) override;
|
void chown(const boost::filesystem::path &path, ::uid_t uid, ::gid_t gid) override;
|
||||||
void truncate(const boost::filesystem::path &path, off_t size) override;
|
void truncate(const boost::filesystem::path &path, fspp::num_bytes_t size) override;
|
||||||
void ftruncate(int descriptor, off_t size) override;
|
void ftruncate(int descriptor, fspp::num_bytes_t size) override;
|
||||||
size_t read(int descriptor, void *buf, size_t count, off_t offset) override;
|
fspp::num_bytes_t read(int descriptor, void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) override;
|
||||||
void write(int descriptor, const void *buf, size_t count, off_t offset) override;
|
void write(int descriptor, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) override;
|
||||||
void fsync(int descriptor) override;
|
void fsync(int descriptor) override;
|
||||||
void fdatasync(int descriptor) override;
|
void fdatasync(int descriptor) override;
|
||||||
void access(const boost::filesystem::path &path, int mask) override;
|
void access(const boost::filesystem::path &path, int mask) override;
|
||||||
@ -47,7 +47,7 @@ public:
|
|||||||
void utimens(const boost::filesystem::path &path, timespec lastAccessTime, timespec lastModificationTime) override;
|
void utimens(const boost::filesystem::path &path, timespec lastAccessTime, timespec lastModificationTime) override;
|
||||||
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
void statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat) override;
|
||||||
void createSymlink(const boost::filesystem::path &to, const boost::filesystem::path &from, ::uid_t uid, ::gid_t gid) override;
|
void createSymlink(const boost::filesystem::path &to, const boost::filesystem::path &from, ::uid_t uid, ::gid_t gid) override;
|
||||||
void readSymlink(const boost::filesystem::path &path, char *buf, size_t size) override;
|
void readSymlink(const boost::filesystem::path &path, char *buf, fspp::num_bytes_t size) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cpputils::unique_ref<File> LoadFile(const boost::filesystem::path &path);
|
cpputils::unique_ref<File> LoadFile(const boost::filesystem::path &path);
|
||||||
|
@ -64,9 +64,9 @@ TEST_F(BlobReadWriteTest, WritingCloseTo16ByteLimitDoesntDestroySize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct DataRange {
|
struct DataRange {
|
||||||
size_t blobsize;
|
uint64_t blobsize;
|
||||||
off_t offset;
|
uint64_t offset;
|
||||||
size_t count;
|
uint64_t count;
|
||||||
};
|
};
|
||||||
class BlobReadWriteDataTest: public BlobReadWriteTest, public WithParamInterface<DataRange> {
|
class BlobReadWriteDataTest: public BlobReadWriteTest, public WithParamInterface<DataRange> {
|
||||||
public:
|
public:
|
||||||
@ -79,7 +79,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<class DataClass>
|
template<class DataClass>
|
||||||
void EXPECT_DATA_READS_AS_OUTSIDE_OF(const DataClass &expected, const Blob &blob, off_t start, size_t count) {
|
void EXPECT_DATA_READS_AS_OUTSIDE_OF(const DataClass &expected, const Blob &blob, uint64_t start, uint64_t count) {
|
||||||
Data begin(start);
|
Data begin(start);
|
||||||
Data end(GetParam().blobsize - count - start);
|
Data end(GetParam().blobsize - count - start);
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ public:
|
|||||||
EXPECT_DATA_READS_AS(end, blob, start + count, end.size());
|
EXPECT_DATA_READS_AS(end, blob, start + count, end.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_DATA_IS_ZEROES_OUTSIDE_OF(const Blob &blob, off_t start, size_t count) {
|
void EXPECT_DATA_IS_ZEROES_OUTSIDE_OF(const Blob &blob, uint64_t start, uint64_t count) {
|
||||||
Data ZEROES(GetParam().blobsize);
|
Data ZEROES(GetParam().blobsize);
|
||||||
ZEROES.FillWithZeroes();
|
ZEROES.FillWithZeroes();
|
||||||
EXPECT_DATA_READS_AS_OUTSIDE_OF(ZEROES, blob, start, count);
|
EXPECT_DATA_READS_AS_OUTSIDE_OF(ZEROES, blob, start, count);
|
||||||
|
@ -259,9 +259,9 @@ TEST_F(DataLeafNodeTest, CopyDataLeaf) {
|
|||||||
|
|
||||||
|
|
||||||
struct DataRange {
|
struct DataRange {
|
||||||
size_t leafsize;
|
uint64_t leafsize;
|
||||||
off_t offset;
|
uint64_t offset;
|
||||||
size_t count;
|
uint64_t count;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DataLeafNodeDataTest: public DataLeafNodeTest, public WithParamInterface<DataRange> {
|
class DataLeafNodeDataTest: public DataLeafNodeTest, public WithParamInterface<DataRange> {
|
||||||
@ -282,13 +282,13 @@ public:
|
|||||||
return newleaf->blockId();
|
return newleaf->blockId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_DATA_READS_AS(const Data &expected, const DataLeafNode &leaf, off_t offset, size_t count) {
|
void EXPECT_DATA_READS_AS(const Data &expected, const DataLeafNode &leaf, uint64_t offset, uint64_t count) {
|
||||||
Data read(count);
|
Data read(count);
|
||||||
leaf.read(read.data(), offset, count);
|
leaf.read(read.data(), offset, count);
|
||||||
EXPECT_EQ(expected, read);
|
EXPECT_EQ(expected, read);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_DATA_READS_AS_OUTSIDE_OF(const Data &expected, const DataLeafNode &leaf, off_t start, size_t count) {
|
void EXPECT_DATA_READS_AS_OUTSIDE_OF(const Data &expected, const DataLeafNode &leaf, uint64_t start, uint64_t count) {
|
||||||
Data begin(start);
|
Data begin(start);
|
||||||
Data end(GetParam().leafsize - count - start);
|
Data end(GetParam().leafsize - count - start);
|
||||||
|
|
||||||
@ -299,7 +299,7 @@ public:
|
|||||||
EXPECT_DATA_READS_AS(end, leaf, start + count, end.size());
|
EXPECT_DATA_READS_AS(end, leaf, start + count, end.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_DATA_IS_ZEROES_OUTSIDE_OF(const DataLeafNode &leaf, off_t start, size_t count) {
|
void EXPECT_DATA_IS_ZEROES_OUTSIDE_OF(const DataLeafNode &leaf, uint64_t start, uint64_t count) {
|
||||||
Data ZEROES(GetParam().leafsize);
|
Data ZEROES(GetParam().leafsize);
|
||||||
ZEROES.FillWithZeroes();
|
ZEROES.FillWithZeroes();
|
||||||
EXPECT_DATA_READS_AS_OUTSIDE_OF(ZEROES, leaf, start, count);
|
EXPECT_DATA_READS_AS_OUTSIDE_OF(ZEROES, leaf, start, count);
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
// This file is meant to be included by BlockStoreTest.h only
|
// This file is meant to be included by BlockStoreTest.h only
|
||||||
|
|
||||||
struct DataRange {
|
struct DataRange {
|
||||||
size_t blocksize;
|
uint64_t blocksize;
|
||||||
off_t offset;
|
uint64_t offset;
|
||||||
size_t count;
|
uint64_t count;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BlockStoreDataParametrizedTest {
|
class BlockStoreDataParametrizedTest {
|
||||||
@ -116,13 +116,13 @@ private:
|
|||||||
return newblock->blockId();
|
return newblock->blockId();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_DATA_READS_AS(const cpputils::Data &expected, const blockstore::Block &block, off_t offset, size_t count) {
|
void EXPECT_DATA_READS_AS(const cpputils::Data &expected, const blockstore::Block &block, uint64_t offset, uint64_t count) {
|
||||||
cpputils::Data read(count);
|
cpputils::Data read(count);
|
||||||
std::memcpy(read.data(), static_cast<const uint8_t*>(block.data()) + offset, count);
|
std::memcpy(read.data(), static_cast<const uint8_t*>(block.data()) + offset, count);
|
||||||
EXPECT_EQ(expected, read);
|
EXPECT_EQ(expected, read);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_DATA_READS_AS_OUTSIDE_OF(const cpputils::Data &expected, const blockstore::Block &block, off_t start, size_t count) {
|
void EXPECT_DATA_READS_AS_OUTSIDE_OF(const cpputils::Data &expected, const blockstore::Block &block, uint64_t start, uint64_t count) {
|
||||||
cpputils::Data begin(start);
|
cpputils::Data begin(start);
|
||||||
cpputils::Data end(testData.blocksize - count - start);
|
cpputils::Data end(testData.blocksize - count - start);
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ private:
|
|||||||
EXPECT_DATA_READS_AS(end, block, start + count, end.size());
|
EXPECT_DATA_READS_AS(end, block, start + count, end.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void EXPECT_DATA_IS_ZEROES_OUTSIDE_OF(const blockstore::Block &block, off_t start, size_t count) {
|
void EXPECT_DATA_IS_ZEROES_OUTSIDE_OF(const blockstore::Block &block, uint64_t start, uint64_t count) {
|
||||||
cpputils::Data ZEROES(testData.blocksize);
|
cpputils::Data ZEROES(testData.blocksize);
|
||||||
ZEROES.FillWithZeroes();
|
ZEROES.FillWithZeroes();
|
||||||
EXPECT_DATA_READS_AS_OUTSIDE_OF(ZEROES, block, start, count);
|
EXPECT_DATA_READS_AS_OUTSIDE_OF(ZEROES, block, start, count);
|
||||||
|
@ -36,9 +36,9 @@ TEST_P(FuseCreateAndOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
|||||||
ReturnDoesntExistOnLstat(FILENAME);
|
ReturnDoesntExistOnLstat(FILENAME);
|
||||||
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _))
|
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _))
|
||||||
.Times(1).WillOnce(Return(GetParam()));
|
.Times(1).WillOnce(Return(GetParam()));
|
||||||
EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(1));
|
EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(fspp::num_bytes_t(1)));
|
||||||
//For the syscall to succeed, we also need to give an fstat implementation.
|
//For the syscall to succeed, we also need to give an fstat implementation.
|
||||||
ReturnIsFileOnFstatWithSize(GetParam(), 1);
|
ReturnIsFileOnFstatWithSize(GetParam(), fspp::num_bytes_t(1));
|
||||||
|
|
||||||
CreateAndOpenAndReadFile(FILENAME);
|
CreateAndOpenAndReadFile(FILENAME);
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,6 @@ TEST_P(FuseFTruncateErrorTest, ReturnedErrorIsCorrect) {
|
|||||||
//Needed to make ::ftruncate system call return successfully
|
//Needed to make ::ftruncate system call return successfully
|
||||||
ReturnIsFileOnFstat(0);
|
ReturnIsFileOnFstat(0);
|
||||||
|
|
||||||
int error = FTruncateFileReturnError(FILENAME, 0);
|
int error = FTruncateFileReturnError(FILENAME, fspp::num_bytes_t(0));
|
||||||
EXPECT_EQ(GetParam(), error);
|
EXPECT_EQ(GetParam(), error);
|
||||||
}
|
}
|
||||||
|
@ -23,5 +23,5 @@ TEST_P(FuseFTruncateFileDescriptorTest, FileDescriptorIsCorrect) {
|
|||||||
//Needed to make ::ftruncate system call return successfully
|
//Needed to make ::ftruncate system call return successfully
|
||||||
ReturnIsFileOnFstat(GetParam());
|
ReturnIsFileOnFstat(GetParam());
|
||||||
|
|
||||||
FTruncateFile(FILENAME, 0);
|
FTruncateFile(FILENAME, fspp::num_bytes_t(0));
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,14 @@ using ::testing::Return;
|
|||||||
using ::testing::WithParamInterface;
|
using ::testing::WithParamInterface;
|
||||||
using ::testing::Values;
|
using ::testing::Values;
|
||||||
|
|
||||||
class FuseFTruncateSizeTest: public FuseFTruncateTest, public WithParamInterface<off_t> {
|
class FuseFTruncateSizeTest: public FuseFTruncateTest, public WithParamInterface<fspp::num_bytes_t> {
|
||||||
};
|
};
|
||||||
INSTANTIATE_TEST_CASE_P(FuseFTruncateSizeTest, FuseFTruncateSizeTest, Values(0, 1, 10, 1024, 1024*1024*1024));
|
INSTANTIATE_TEST_CASE_P(FuseFTruncateSizeTest, FuseFTruncateSizeTest, Values(
|
||||||
|
fspp::num_bytes_t(0),
|
||||||
|
fspp::num_bytes_t(1),
|
||||||
|
fspp::num_bytes_t(10),
|
||||||
|
fspp::num_bytes_t(1024),
|
||||||
|
fspp::num_bytes_t(1024*1024*1024)));
|
||||||
|
|
||||||
|
|
||||||
TEST_P(FuseFTruncateSizeTest, FTruncateFile) {
|
TEST_P(FuseFTruncateSizeTest, FTruncateFile) {
|
||||||
@ -18,5 +23,5 @@ TEST_P(FuseFTruncateSizeTest, FTruncateFile) {
|
|||||||
//Needed to make ::ftruncate system call return successfully
|
//Needed to make ::ftruncate system call return successfully
|
||||||
ReturnIsFileOnFstat(0);
|
ReturnIsFileOnFstat(0);
|
||||||
|
|
||||||
FTruncateFile(FILENAME, GetParam());
|
FTruncateFile(FILENAME, fspp::num_bytes_t(GetParam()));
|
||||||
}
|
}
|
||||||
|
@ -3,16 +3,16 @@
|
|||||||
using cpputils::unique_ref;
|
using cpputils::unique_ref;
|
||||||
using cpputils::make_unique_ref;
|
using cpputils::make_unique_ref;
|
||||||
|
|
||||||
void FuseFTruncateTest::FTruncateFile(const char *filename, off_t size) {
|
void FuseFTruncateTest::FTruncateFile(const char *filename, fspp::num_bytes_t size) {
|
||||||
int error = FTruncateFileReturnError(filename, size);
|
int error = FTruncateFileReturnError(filename, size);
|
||||||
EXPECT_EQ(0, error);
|
EXPECT_EQ(0, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FuseFTruncateTest::FTruncateFileReturnError(const char *filename, off_t size) {
|
int FuseFTruncateTest::FTruncateFileReturnError(const char *filename, fspp::num_bytes_t size) {
|
||||||
auto fs = TestFS();
|
auto fs = TestFS();
|
||||||
|
|
||||||
auto fd = OpenFile(fs.get(), filename);
|
auto fd = OpenFile(fs.get(), filename);
|
||||||
int retval = ::ftruncate(fd->fd(), size);
|
int retval = ::ftruncate(fd->fd(), size.value());
|
||||||
if (0 == retval) {
|
if (0 == retval) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,8 +9,8 @@ class FuseFTruncateTest: public FuseTest {
|
|||||||
public:
|
public:
|
||||||
const char *FILENAME = "/myfile";
|
const char *FILENAME = "/myfile";
|
||||||
|
|
||||||
void FTruncateFile(const char *filename, off_t size);
|
void FTruncateFile(const char *filename, fspp::num_bytes_t size);
|
||||||
int FTruncateFileReturnError(const char *filename, off_t size);
|
int FTruncateFileReturnError(const char *filename, fspp::num_bytes_t size);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cpputils::unique_ref<OpenFileHandle> OpenFile(const TempTestFS *fs, const char *filename);
|
cpputils::unique_ref<OpenFileHandle> OpenFile(const TempTestFS *fs, const char *filename);
|
||||||
|
@ -3,25 +3,25 @@
|
|||||||
using ::testing::WithParamInterface;
|
using ::testing::WithParamInterface;
|
||||||
using ::testing::Values;
|
using ::testing::Values;
|
||||||
|
|
||||||
class FuseLstatReturnSizeTest: public FuseLstatReturnTest<off_t>, public WithParamInterface<off_t> {
|
class FuseLstatReturnSizeTest: public FuseLstatReturnTest<fspp::num_bytes_t>, public WithParamInterface<fspp::num_bytes_t> {
|
||||||
private:
|
private:
|
||||||
void set(struct stat *stat, off_t value) override {
|
void set(struct stat *stat, fspp::num_bytes_t value) override {
|
||||||
stat->st_size = value;
|
stat->st_size = value.value();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
INSTANTIATE_TEST_CASE_P(FuseLstatReturnSizeTest, FuseLstatReturnSizeTest, Values(
|
INSTANTIATE_TEST_CASE_P(FuseLstatReturnSizeTest, FuseLstatReturnSizeTest, Values(
|
||||||
0,
|
fspp::num_bytes_t(0),
|
||||||
1,
|
fspp::num_bytes_t(1),
|
||||||
4096,
|
fspp::num_bytes_t(4096),
|
||||||
1024*1024*1024
|
fspp::num_bytes_t(1024*1024*1024)
|
||||||
));
|
));
|
||||||
|
|
||||||
TEST_P(FuseLstatReturnSizeTest, ReturnedFileSizeIsCorrect) {
|
TEST_P(FuseLstatReturnSizeTest, ReturnedFileSizeIsCorrect) {
|
||||||
struct ::stat result = CallDirLstatWithValue(GetParam());
|
struct ::stat result = CallDirLstatWithValue(GetParam());
|
||||||
EXPECT_EQ(GetParam(), result.st_size);
|
EXPECT_EQ(GetParam(), fspp::num_bytes_t(result.st_size));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(FuseLstatReturnSizeTest, ReturnedDirSizeIsCorrect) {
|
TEST_P(FuseLstatReturnSizeTest, ReturnedDirSizeIsCorrect) {
|
||||||
struct ::stat result = CallDirLstatWithValue(GetParam());
|
struct ::stat result = CallDirLstatWithValue(GetParam());
|
||||||
EXPECT_EQ(GetParam(), result.st_size);
|
EXPECT_EQ(GetParam(), fspp::num_bytes_t(result.st_size));
|
||||||
}
|
}
|
||||||
|
@ -33,10 +33,10 @@ private:
|
|||||||
INSTANTIATE_TEST_CASE_P(FuseOpenFileDescriptorTest, FuseOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024));
|
INSTANTIATE_TEST_CASE_P(FuseOpenFileDescriptorTest, FuseOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024));
|
||||||
|
|
||||||
TEST_P(FuseOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
TEST_P(FuseOpenFileDescriptorTest, TestReturnedFileDescriptor) {
|
||||||
ReturnIsFileOnLstatWithSize(FILENAME, 1);
|
ReturnIsFileOnLstatWithSize(FILENAME, fspp::num_bytes_t(1));
|
||||||
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _))
|
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _))
|
||||||
.Times(1).WillOnce(Return(GetParam()));
|
.Times(1).WillOnce(Return(GetParam()));
|
||||||
EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(1));
|
EXPECT_CALL(fsimpl, read(GetParam(), _, _, _)).Times(1).WillOnce(Return(fspp::num_bytes_t(1)));
|
||||||
|
|
||||||
OpenAndReadFile(FILENAME);
|
OpenAndReadFile(FILENAME);
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ using namespace fspp::fuse;
|
|||||||
|
|
||||||
class FuseReadErrorTest: public FuseReadTest, public WithParamInterface<int> {
|
class FuseReadErrorTest: public FuseReadTest, public WithParamInterface<int> {
|
||||||
public:
|
public:
|
||||||
size_t FILESIZE = 64*1024*1024;
|
fspp::num_bytes_t FILESIZE = fspp::num_bytes_t(64*1024*1024);
|
||||||
size_t READCOUNT = 32*1024*1024;
|
fspp::num_bytes_t READCOUNT = fspp::num_bytes_t(32*1024*1024);
|
||||||
|
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
//Make the file size big enough that fuse should issue at least two reads
|
//Make the file size big enough that fuse should issue at least two reads
|
||||||
@ -30,8 +30,8 @@ TEST_P(FuseReadErrorTest, ReturnErrorOnFirstReadCall) {
|
|||||||
EXPECT_CALL(fsimpl, read(0, _, _, _))
|
EXPECT_CALL(fsimpl, read(0, _, _, _))
|
||||||
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
|
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
|
||||||
|
|
||||||
char *buf = new char[READCOUNT];
|
char *buf = new char[READCOUNT.value()];
|
||||||
auto retval = ReadFileReturnError(FILENAME, buf, READCOUNT, 0);
|
auto retval = ReadFileReturnError(FILENAME, buf, READCOUNT, fspp::num_bytes_t(0));
|
||||||
EXPECT_EQ(GetParam(), retval.error);
|
EXPECT_EQ(GetParam(), retval.error);
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
}
|
}
|
||||||
@ -40,19 +40,19 @@ TEST_P(FuseReadErrorTest, ReturnErrorOnSecondReadCall) {
|
|||||||
// The first read request is from the beginning of the file and works, but the later ones fail.
|
// The first read request is from the beginning of the file and works, but the later ones fail.
|
||||||
// We store the number of bytes the first call could successfully read and check later that our
|
// We store the number of bytes the first call could successfully read and check later that our
|
||||||
// read syscall returns exactly this number of bytes
|
// read syscall returns exactly this number of bytes
|
||||||
size_t successfullyReadBytes = -1;
|
fspp::num_bytes_t successfullyReadBytes = fspp::num_bytes_t(-1);
|
||||||
EXPECT_CALL(fsimpl, read(0, _, _, Eq(0)))
|
EXPECT_CALL(fsimpl, read(0, _, _, Eq(fspp::num_bytes_t(0))))
|
||||||
.Times(1)
|
.Times(1)
|
||||||
.WillOnce(Invoke([&successfullyReadBytes](int, void*, size_t count, off_t) {
|
.WillOnce(Invoke([&successfullyReadBytes](int, void*, fspp::num_bytes_t count, fspp::num_bytes_t) {
|
||||||
// Store the number of successfully read bytes
|
// Store the number of successfully read bytes
|
||||||
successfullyReadBytes = count;
|
successfullyReadBytes = count;
|
||||||
return count;
|
return count;
|
||||||
}));
|
}));
|
||||||
EXPECT_CALL(fsimpl, read(0, _, _, Ne(0)))
|
EXPECT_CALL(fsimpl, read(0, _, _, Ne(fspp::num_bytes_t(0))))
|
||||||
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
|
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
|
||||||
|
|
||||||
char *buf = new char[READCOUNT];
|
char *buf = new char[READCOUNT.value()];
|
||||||
auto retval = ReadFileReturnError(FILENAME, buf, READCOUNT, 0);
|
auto retval = ReadFileReturnError(FILENAME, buf, READCOUNT, fspp::num_bytes_t(0));
|
||||||
EXPECT_EQ(0, retval.error);
|
EXPECT_EQ(0, retval.error);
|
||||||
EXPECT_EQ(successfullyReadBytes, retval.read_bytes); // Check that we're getting the number of successfully read bytes (the first read call) returned
|
EXPECT_EQ(successfullyReadBytes, retval.read_bytes); // Check that we're getting the number of successfully read bytes (the first read call) returned
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
|
@ -15,11 +15,11 @@ INSTANTIATE_TEST_CASE_P(FuseReadFileDescriptorTest, FuseReadFileDescriptorTest,
|
|||||||
|
|
||||||
|
|
||||||
TEST_P(FuseReadFileDescriptorTest, FileDescriptorIsCorrect) {
|
TEST_P(FuseReadFileDescriptorTest, FileDescriptorIsCorrect) {
|
||||||
ReturnIsFileOnLstatWithSize(FILENAME, 1);
|
ReturnIsFileOnLstatWithSize(FILENAME, fspp::num_bytes_t(1));
|
||||||
OnOpenReturnFileDescriptor(FILENAME, GetParam());
|
OnOpenReturnFileDescriptor(FILENAME, GetParam());
|
||||||
EXPECT_CALL(fsimpl, read(Eq(GetParam()), _, _, _))
|
EXPECT_CALL(fsimpl, read(Eq(GetParam()), _, _, _))
|
||||||
.Times(1).WillOnce(ReturnSuccessfulRead);
|
.Times(1).WillOnce(ReturnSuccessfulRead);
|
||||||
|
|
||||||
char buf[1];
|
char buf[1];
|
||||||
ReadFile(FILENAME, buf, 1, 0);
|
ReadFile(FILENAME, buf, fspp::num_bytes_t(1), fspp::num_bytes_t(0));
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,9 @@ using namespace fspp::fuse;
|
|||||||
|
|
||||||
class FuseReadOverflowTest: public FuseReadTest {
|
class FuseReadOverflowTest: public FuseReadTest {
|
||||||
public:
|
public:
|
||||||
static constexpr size_t FILESIZE = 1000;
|
static constexpr fspp::num_bytes_t FILESIZE = fspp::num_bytes_t(1000);
|
||||||
static constexpr size_t READSIZE = 2000;
|
static constexpr fspp::num_bytes_t READSIZE = fspp::num_bytes_t(2000);
|
||||||
static constexpr size_t OFFSET = 500;
|
static constexpr fspp::num_bytes_t OFFSET = fspp::num_bytes_t(500);
|
||||||
|
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
ReturnIsFileOnLstatWithSize(FILENAME, FILESIZE);
|
ReturnIsFileOnLstatWithSize(FILENAME, FILESIZE);
|
||||||
@ -20,19 +20,19 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr size_t FuseReadOverflowTest::FILESIZE;
|
constexpr fspp::num_bytes_t FuseReadOverflowTest::FILESIZE;
|
||||||
constexpr size_t FuseReadOverflowTest::READSIZE;
|
constexpr fspp::num_bytes_t FuseReadOverflowTest::READSIZE;
|
||||||
constexpr size_t FuseReadOverflowTest::OFFSET;
|
constexpr fspp::num_bytes_t FuseReadOverflowTest::OFFSET;
|
||||||
|
|
||||||
|
|
||||||
TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromBeginning) {
|
TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromBeginning) {
|
||||||
char buf[READSIZE];
|
char buf[READSIZE.value()];
|
||||||
auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, 0);
|
auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, fspp::num_bytes_t(0));
|
||||||
EXPECT_EQ(FILESIZE, retval.read_bytes);
|
EXPECT_EQ(FILESIZE, retval.read_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromMiddle) {
|
TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromMiddle) {
|
||||||
char buf[READSIZE];
|
char buf[READSIZE.value()];
|
||||||
auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, OFFSET);
|
auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, OFFSET);
|
||||||
EXPECT_EQ(FILESIZE-OFFSET, retval.read_bytes);
|
EXPECT_EQ(FILESIZE-OFFSET, retval.read_bytes);
|
||||||
}
|
}
|
||||||
|
@ -29,19 +29,19 @@ using namespace fspp::fuse;
|
|||||||
|
|
||||||
struct TestData {
|
struct TestData {
|
||||||
TestData(): count(0), offset(0), additional_bytes_at_end_of_file(0) {}
|
TestData(): count(0), offset(0), additional_bytes_at_end_of_file(0) {}
|
||||||
TestData(const tuple<size_t, off_t, size_t> &data): count(get<0>(data)), offset(get<1>(data)), additional_bytes_at_end_of_file(get<2>(data)) {}
|
TestData(const tuple<fspp::num_bytes_t, fspp::num_bytes_t, fspp::num_bytes_t> &data): count(get<0>(data)), offset(get<1>(data)), additional_bytes_at_end_of_file(get<2>(data)) {}
|
||||||
size_t count;
|
fspp::num_bytes_t count;
|
||||||
off_t offset;
|
fspp::num_bytes_t offset;
|
||||||
//How many more bytes does the file have after the read block?
|
//How many more bytes does the file have after the read block?
|
||||||
size_t additional_bytes_at_end_of_file;
|
fspp::num_bytes_t additional_bytes_at_end_of_file;
|
||||||
size_t fileSize() {
|
fspp::num_bytes_t fileSize() {
|
||||||
return count + offset + additional_bytes_at_end_of_file;
|
return count + offset + additional_bytes_at_end_of_file;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The testcase creates random data in memory, offers a mock read() implementation to read from this
|
// The testcase creates random data in memory, offers a mock read() implementation to read from this
|
||||||
// memory region and check methods to check for data equality of a region.
|
// memory region and check methods to check for data equality of a region.
|
||||||
class FuseReadReturnedDataTest: public FuseReadTest, public WithParamInterface<tuple<size_t, off_t, size_t>> {
|
class FuseReadReturnedDataTest: public FuseReadTest, public WithParamInterface<tuple<fspp::num_bytes_t, fspp::num_bytes_t, fspp::num_bytes_t>> {
|
||||||
public:
|
public:
|
||||||
std::unique_ptr<InMemoryFile> testFile;
|
std::unique_ptr<InMemoryFile> testFile;
|
||||||
TestData testData;
|
TestData testData;
|
||||||
@ -49,7 +49,7 @@ public:
|
|||||||
FuseReadReturnedDataTest()
|
FuseReadReturnedDataTest()
|
||||||
: testFile(nullptr),
|
: testFile(nullptr),
|
||||||
testData(GetParam()) {
|
testData(GetParam()) {
|
||||||
testFile = std::make_unique<InMemoryFile>(DataFixture::generate(testData.fileSize()));
|
testFile = std::make_unique<InMemoryFile>(DataFixture::generate(testData.fileSize().value()));
|
||||||
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
|
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
|
||||||
OnOpenReturnFileDescriptor(FILENAME, 0);
|
OnOpenReturnFileDescriptor(FILENAME, 0);
|
||||||
EXPECT_CALL(fsimpl, read(0, _, _, _))
|
EXPECT_CALL(fsimpl, read(0, _, _, _))
|
||||||
@ -57,15 +57,19 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This read() mock implementation reads from the stored virtual file (testFile).
|
// This read() mock implementation reads from the stored virtual file (testFile).
|
||||||
Action<size_t(int, void*, size_t, off_t)> ReadFromFile = Invoke([this](int, void *buf, size_t count, off_t offset) {
|
Action<fspp::num_bytes_t(int, void*, fspp::num_bytes_t, fspp::num_bytes_t)> ReadFromFile = Invoke([this](int, void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
return testFile->read(buf, count, offset);
|
return testFile->read(buf, count, offset);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
INSTANTIATE_TEST_CASE_P(FuseReadReturnedDataTest, FuseReadReturnedDataTest, Combine(Values(0,1,10,1000,1024, 10*1024*1024), Values(0, 1, 10, 1024, 10*1024*1024), Values(0, 1, 10, 1024, 10*1024*1024)));
|
INSTANTIATE_TEST_CASE_P(FuseReadReturnedDataTest, FuseReadReturnedDataTest, Combine(
|
||||||
|
Values(fspp::num_bytes_t(0), fspp::num_bytes_t(1), fspp::num_bytes_t(10), fspp::num_bytes_t(1000), fspp::num_bytes_t(1024), fspp::num_bytes_t(10*1024*1024)),
|
||||||
|
Values(fspp::num_bytes_t(0), fspp::num_bytes_t(1), fspp::num_bytes_t(10), fspp::num_bytes_t(1024), fspp::num_bytes_t(10*1024*1024)),
|
||||||
|
Values(fspp::num_bytes_t(0), fspp::num_bytes_t(1), fspp::num_bytes_t(10), fspp::num_bytes_t(1024), fspp::num_bytes_t(10*1024*1024))
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
TEST_P(FuseReadReturnedDataTest, ReturnedDataRangeIsCorrect) {
|
TEST_P(FuseReadReturnedDataTest, ReturnedDataRangeIsCorrect) {
|
||||||
Data buf(testData.count);
|
Data buf(testData.count.value());
|
||||||
ReadFile(FILENAME, buf.data(), testData.count, testData.offset);
|
ReadFile(FILENAME, buf.data(), testData.count, testData.offset);
|
||||||
EXPECT_TRUE(testFile->fileContentEquals(buf, testData.offset));
|
EXPECT_TRUE(testFile->fileContentEquals(buf, testData.offset));
|
||||||
}
|
}
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
using cpputils::make_unique_ref;
|
using cpputils::make_unique_ref;
|
||||||
using cpputils::unique_ref;
|
using cpputils::unique_ref;
|
||||||
|
|
||||||
void FuseReadTest::ReadFile(const char *filename, void *buf, size_t count, off_t offset) {
|
void FuseReadTest::ReadFile(const char *filename, void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
auto retval = ReadFileReturnError(filename, buf, count, offset);
|
auto retval = ReadFileReturnError(filename, buf, count, offset);
|
||||||
EXPECT_EQ(0, retval.error);
|
EXPECT_EQ(0, retval.error);
|
||||||
EXPECT_EQ(count, retval.read_bytes);
|
EXPECT_EQ(count, retval.read_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
FuseReadTest::ReadError FuseReadTest::ReadFileReturnError(const char *filename, void *buf, size_t count, off_t offset) {
|
FuseReadTest::ReadError FuseReadTest::ReadFileReturnError(const char *filename, void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
auto fs = TestFS();
|
auto fs = TestFS();
|
||||||
|
|
||||||
auto fd = OpenFile(fs.get(), filename);
|
auto fd = OpenFile(fs.get(), filename);
|
||||||
|
|
||||||
ReadError result{};
|
ReadError result{};
|
||||||
errno = 0;
|
errno = 0;
|
||||||
result.read_bytes = ::pread(fd->fd(), buf, count, offset);
|
result.read_bytes = fspp::num_bytes_t(::pread(fd->fd(), buf, count.value(), offset.value()));
|
||||||
result.error = errno;
|
result.error = errno;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -11,20 +11,20 @@ public:
|
|||||||
|
|
||||||
struct ReadError {
|
struct ReadError {
|
||||||
int error;
|
int error;
|
||||||
size_t read_bytes;
|
fspp::num_bytes_t read_bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ReadFile(const char *filename, void *buf, size_t count, off_t offset);
|
void ReadFile(const char *filename, void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset);
|
||||||
ReadError ReadFileReturnError(const char *filename, void *buf, size_t count, off_t offset);
|
ReadError ReadFileReturnError(const char *filename, void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset);
|
||||||
|
|
||||||
::testing::Action<size_t(int, void*, size_t, off_t)> ReturnSuccessfulRead =
|
::testing::Action<fspp::num_bytes_t(int, void*, fspp::num_bytes_t, fspp::num_bytes_t)> ReturnSuccessfulRead =
|
||||||
::testing::Invoke([](int, void *, size_t count, off_t) {
|
::testing::Invoke([](int, void *, fspp::num_bytes_t count, fspp::num_bytes_t) {
|
||||||
return count;
|
return count;
|
||||||
});
|
});
|
||||||
|
|
||||||
::testing::Action<size_t(int, void*, size_t, off_t)> ReturnSuccessfulReadRegardingSize(size_t filesize) {
|
::testing::Action<fspp::num_bytes_t(int, void*, fspp::num_bytes_t, fspp::num_bytes_t)> ReturnSuccessfulReadRegardingSize(fspp::num_bytes_t filesize) {
|
||||||
return ::testing::Invoke([filesize](int, void *, size_t count, off_t offset) {
|
return ::testing::Invoke([filesize](int, void *, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
size_t ableToReadCount = std::min(count, static_cast<size_t>(filesize - offset));
|
fspp::num_bytes_t ableToReadCount = std::min(count, filesize - offset);
|
||||||
return ableToReadCount;
|
return ableToReadCount;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,6 @@ TEST_P(FuseTruncateErrorTest, ReturnedErrorIsCorrect) {
|
|||||||
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), _))
|
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), _))
|
||||||
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
|
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
|
||||||
|
|
||||||
int error = TruncateFileReturnError(FILENAME, 0);
|
int error = TruncateFileReturnError(FILENAME, fspp::num_bytes_t(0));
|
||||||
EXPECT_EQ(GetParam(), error);
|
EXPECT_EQ(GetParam(), error);
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ TEST_F(FuseTruncateFilenameTest, TruncateFile) {
|
|||||||
EXPECT_CALL(fsimpl, truncate(StrEq("/myfile"), _))
|
EXPECT_CALL(fsimpl, truncate(StrEq("/myfile"), _))
|
||||||
.Times(1).WillOnce(Return());
|
.Times(1).WillOnce(Return());
|
||||||
|
|
||||||
TruncateFile("/myfile", 0);
|
TruncateFile("/myfile", fspp::num_bytes_t(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FuseTruncateFilenameTest, TruncateFileNested) {
|
TEST_F(FuseTruncateFilenameTest, TruncateFileNested) {
|
||||||
@ -21,7 +21,7 @@ TEST_F(FuseTruncateFilenameTest, TruncateFileNested) {
|
|||||||
EXPECT_CALL(fsimpl, truncate(StrEq("/mydir/myfile"), _))
|
EXPECT_CALL(fsimpl, truncate(StrEq("/mydir/myfile"), _))
|
||||||
.Times(1).WillOnce(Return());
|
.Times(1).WillOnce(Return());
|
||||||
|
|
||||||
TruncateFile("/mydir/myfile", 0);
|
TruncateFile("/mydir/myfile", fspp::num_bytes_t(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FuseTruncateFilenameTest, TruncateFileNested2) {
|
TEST_F(FuseTruncateFilenameTest, TruncateFileNested2) {
|
||||||
@ -31,5 +31,5 @@ TEST_F(FuseTruncateFilenameTest, TruncateFileNested2) {
|
|||||||
EXPECT_CALL(fsimpl, truncate(StrEq("/mydir/mydir2/myfile"), _))
|
EXPECT_CALL(fsimpl, truncate(StrEq("/mydir/mydir2/myfile"), _))
|
||||||
.Times(1).WillOnce(Return());
|
.Times(1).WillOnce(Return());
|
||||||
|
|
||||||
TruncateFile("/mydir/mydir2/myfile", 0);
|
TruncateFile("/mydir/mydir2/myfile", fspp::num_bytes_t(0));
|
||||||
}
|
}
|
||||||
|
@ -4,15 +4,21 @@ using ::testing::StrEq;
|
|||||||
using ::testing::Return;
|
using ::testing::Return;
|
||||||
using ::testing::WithParamInterface;
|
using ::testing::WithParamInterface;
|
||||||
using ::testing::Values;
|
using ::testing::Values;
|
||||||
|
using ::testing::Eq;
|
||||||
|
|
||||||
class FuseTruncateSizeTest: public FuseTruncateTest, public WithParamInterface<off_t> {
|
class FuseTruncateSizeTest: public FuseTruncateTest, public WithParamInterface<fspp::num_bytes_t> {
|
||||||
};
|
};
|
||||||
INSTANTIATE_TEST_CASE_P(FuseTruncateSizeTest, FuseTruncateSizeTest, Values(0, 1, 10, 1024, 1024*1024*1024));
|
INSTANTIATE_TEST_CASE_P(FuseTruncateSizeTest, FuseTruncateSizeTest, Values(
|
||||||
|
fspp::num_bytes_t(0),
|
||||||
|
fspp::num_bytes_t(1),
|
||||||
|
fspp::num_bytes_t(10),
|
||||||
|
fspp::num_bytes_t(1024),
|
||||||
|
fspp::num_bytes_t(1024*1024*1024)));
|
||||||
|
|
||||||
|
|
||||||
TEST_P(FuseTruncateSizeTest, TruncateFile) {
|
TEST_P(FuseTruncateSizeTest, TruncateFile) {
|
||||||
ReturnIsFileOnLstat(FILENAME);
|
ReturnIsFileOnLstat(FILENAME);
|
||||||
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), GetParam()))
|
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), Eq(GetParam())))
|
||||||
.Times(1).WillOnce(Return());
|
.Times(1).WillOnce(Return());
|
||||||
|
|
||||||
TruncateFile(FILENAME, GetParam());
|
TruncateFile(FILENAME, GetParam());
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
#include "FuseTruncateTest.h"
|
#include "FuseTruncateTest.h"
|
||||||
|
|
||||||
void FuseTruncateTest::TruncateFile(const char *filename, off_t size) {
|
void FuseTruncateTest::TruncateFile(const char *filename, fspp::num_bytes_t size) {
|
||||||
int error = TruncateFileReturnError(filename, size);
|
int error = TruncateFileReturnError(filename, size);
|
||||||
EXPECT_EQ(0, error);
|
EXPECT_EQ(0, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
int FuseTruncateTest::TruncateFileReturnError(const char *filename, off_t size) {
|
int FuseTruncateTest::TruncateFileReturnError(const char *filename, fspp::num_bytes_t size) {
|
||||||
auto fs = TestFS();
|
auto fs = TestFS();
|
||||||
|
|
||||||
auto realpath = fs->mountDir() / filename;
|
auto realpath = fs->mountDir() / filename;
|
||||||
int retval = ::truncate(realpath.string().c_str(), size);
|
int retval = ::truncate(realpath.string().c_str(), size.value());
|
||||||
if (retval == 0) {
|
if (retval == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
@ -8,8 +8,8 @@ class FuseTruncateTest: public FuseTest {
|
|||||||
public:
|
public:
|
||||||
const char *FILENAME = "/myfile";
|
const char *FILENAME = "/myfile";
|
||||||
|
|
||||||
void TruncateFile(const char *filename, off_t size);
|
void TruncateFile(const char *filename, fspp::num_bytes_t size);
|
||||||
int TruncateFileReturnError(const char *filename, off_t size);
|
int TruncateFileReturnError(const char *filename, fspp::num_bytes_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -26,19 +26,19 @@ using namespace fspp::fuse;
|
|||||||
|
|
||||||
struct TestData {
|
struct TestData {
|
||||||
TestData(): count(0), offset(0), additional_bytes_at_end_of_file(0) {}
|
TestData(): count(0), offset(0), additional_bytes_at_end_of_file(0) {}
|
||||||
TestData(const tuple<size_t, off_t, size_t> &data): count(get<0>(data)), offset(get<1>(data)), additional_bytes_at_end_of_file(get<2>(data)) {}
|
TestData(const tuple<fspp::num_bytes_t, fspp::num_bytes_t, fspp::num_bytes_t> &data): count(get<0>(data)), offset(get<1>(data)), additional_bytes_at_end_of_file(get<2>(data)) {}
|
||||||
size_t count;
|
fspp::num_bytes_t count;
|
||||||
off_t offset;
|
fspp::num_bytes_t offset;
|
||||||
//How many more bytes does the file have after the read block?
|
//How many more bytes does the file have after the read block?
|
||||||
size_t additional_bytes_at_end_of_file;
|
fspp::num_bytes_t additional_bytes_at_end_of_file;
|
||||||
size_t fileSize() {
|
fspp::num_bytes_t fileSize() {
|
||||||
return count + offset + additional_bytes_at_end_of_file;
|
return count + offset + additional_bytes_at_end_of_file;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// The testcase creates random data in memory, offers a mock write() implementation to write to this
|
// The testcase creates random data in memory, offers a mock write() implementation to write to this
|
||||||
// memory region and check methods to check for data equality of a region.
|
// memory region and check methods to check for data equality of a region.
|
||||||
class FuseWriteDataTest: public FuseWriteTest, public WithParamInterface<tuple<size_t, off_t, size_t>> {
|
class FuseWriteDataTest: public FuseWriteTest, public WithParamInterface<tuple<fspp::num_bytes_t, fspp::num_bytes_t, fspp::num_bytes_t>> {
|
||||||
public:
|
public:
|
||||||
std::unique_ptr<WriteableInMemoryFile> testFile;
|
std::unique_ptr<WriteableInMemoryFile> testFile;
|
||||||
TestData testData;
|
TestData testData;
|
||||||
@ -46,7 +46,7 @@ public:
|
|||||||
FuseWriteDataTest()
|
FuseWriteDataTest()
|
||||||
: testFile(nullptr),
|
: testFile(nullptr),
|
||||||
testData(GetParam()) {
|
testData(GetParam()) {
|
||||||
testFile = std::make_unique<WriteableInMemoryFile>(DataFixture::generate(testData.fileSize(), 1));
|
testFile = std::make_unique<WriteableInMemoryFile>(DataFixture::generate(testData.fileSize().value(), 1));
|
||||||
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
|
ReturnIsFileOnLstatWithSize(FILENAME, testData.fileSize());
|
||||||
OnOpenReturnFileDescriptor(FILENAME, 0);
|
OnOpenReturnFileDescriptor(FILENAME, 0);
|
||||||
EXPECT_CALL(fsimpl, write(0, _, _, _))
|
EXPECT_CALL(fsimpl, write(0, _, _, _))
|
||||||
@ -54,25 +54,29 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This write() mock implementation writes to the stored virtual file.
|
// This write() mock implementation writes to the stored virtual file.
|
||||||
Action<void(int, const void*, size_t, off_t)> WriteToFile = Invoke([this](int, const void *buf, size_t count, off_t offset) {
|
Action<void(int, const void*, fspp::num_bytes_t, fspp::num_bytes_t)> WriteToFile = Invoke([this](int, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
testFile->write(buf, count, offset);
|
testFile->write(buf, count, offset);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
INSTANTIATE_TEST_CASE_P(FuseWriteDataTest, FuseWriteDataTest, Combine(Values(0,1,10,1000,1024, 10*1024*1024), Values(0, 1, 10, 1024, 10*1024*1024), Values(0, 1, 10, 1024, 10*1024*1024)));
|
INSTANTIATE_TEST_CASE_P(FuseWriteDataTest, FuseWriteDataTest, Combine(
|
||||||
|
Values(fspp::num_bytes_t(0), fspp::num_bytes_t(1), fspp::num_bytes_t(10), fspp::num_bytes_t(1000), fspp::num_bytes_t(1024), fspp::num_bytes_t(10*1024*1024)),
|
||||||
|
Values(fspp::num_bytes_t(0), fspp::num_bytes_t(1), fspp::num_bytes_t(10), fspp::num_bytes_t(1024), fspp::num_bytes_t(10*1024*1024)),
|
||||||
|
Values(fspp::num_bytes_t(0), fspp::num_bytes_t(1), fspp::num_bytes_t(10), fspp::num_bytes_t(1024), fspp::num_bytes_t(10*1024*1024))
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
TEST_P(FuseWriteDataTest, DataWasCorrectlyWritten) {
|
TEST_P(FuseWriteDataTest, DataWasCorrectlyWritten) {
|
||||||
Data randomWriteData = DataFixture::generate(testData.count, 2);
|
Data randomWriteData = DataFixture::generate(testData.count.value(), 2);
|
||||||
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
|
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
|
||||||
|
|
||||||
EXPECT_TRUE(testFile->fileContentEquals(randomWriteData, testData.offset));
|
EXPECT_TRUE(testFile->fileContentEquals(randomWriteData, testData.offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_P(FuseWriteDataTest, RestOfFileIsUnchanged) {
|
TEST_P(FuseWriteDataTest, RestOfFileIsUnchanged) {
|
||||||
Data randomWriteData = DataFixture::generate(testData.count, 2);
|
Data randomWriteData = DataFixture::generate(testData.count.value(), 2);
|
||||||
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
|
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
|
||||||
|
|
||||||
EXPECT_TRUE(testFile->sizeUnchanged());
|
EXPECT_TRUE(testFile->sizeUnchanged());
|
||||||
EXPECT_TRUE(testFile->regionUnchanged(0, testData.offset));
|
EXPECT_TRUE(testFile->regionUnchanged(fspp::num_bytes_t(0), testData.offset));
|
||||||
EXPECT_TRUE(testFile->regionUnchanged(testData.offset + testData.count, testData.additional_bytes_at_end_of_file));
|
EXPECT_TRUE(testFile->regionUnchanged(testData.offset + testData.count, testData.additional_bytes_at_end_of_file));
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ using namespace fspp::fuse;
|
|||||||
|
|
||||||
class FuseWriteErrorTest: public FuseWriteTest, public WithParamInterface<int> {
|
class FuseWriteErrorTest: public FuseWriteTest, public WithParamInterface<int> {
|
||||||
public:
|
public:
|
||||||
size_t FILESIZE = 64*1024*1024;
|
fspp::num_bytes_t FILESIZE = fspp::num_bytes_t(64*1024*1024);
|
||||||
size_t WRITECOUNT = 32*1024*1024;
|
fspp::num_bytes_t WRITECOUNT = fspp::num_bytes_t(32*1024*1024);
|
||||||
|
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
//Make the file size big enough that fuse should issue at least two writes
|
//Make the file size big enough that fuse should issue at least two writes
|
||||||
@ -30,8 +30,8 @@ TEST_P(FuseWriteErrorTest, ReturnErrorOnFirstWriteCall) {
|
|||||||
EXPECT_CALL(fsimpl, write(0, _, _, _))
|
EXPECT_CALL(fsimpl, write(0, _, _, _))
|
||||||
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
|
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
|
||||||
|
|
||||||
char *buf = new char[WRITECOUNT];
|
char *buf = new char[WRITECOUNT.value()];
|
||||||
auto retval = WriteFileReturnError(FILENAME, buf, WRITECOUNT, 0);
|
auto retval = WriteFileReturnError(FILENAME, buf, WRITECOUNT, fspp::num_bytes_t(0));
|
||||||
EXPECT_EQ(GetParam(), retval.error);
|
EXPECT_EQ(GetParam(), retval.error);
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
}
|
}
|
||||||
@ -40,18 +40,18 @@ TEST_P(FuseWriteErrorTest, ReturnErrorOnSecondWriteCall) {
|
|||||||
// The first write request is from the beginning of the file and works, but the later ones fail.
|
// The first write request is from the beginning of the file and works, but the later ones fail.
|
||||||
// We store the number of bytes the first call could successfully write and check later that our
|
// We store the number of bytes the first call could successfully write and check later that our
|
||||||
// write syscall returns exactly this number of bytes
|
// write syscall returns exactly this number of bytes
|
||||||
size_t successfullyWrittenBytes = -1;
|
fspp::num_bytes_t successfullyWrittenBytes = fspp::num_bytes_t(-1);
|
||||||
EXPECT_CALL(fsimpl, write(0, _, _, Eq(0)))
|
EXPECT_CALL(fsimpl, write(0, _, _, Eq(fspp::num_bytes_t(0))))
|
||||||
.Times(1)
|
.Times(1)
|
||||||
.WillOnce(Invoke([&successfullyWrittenBytes](int, const void*, size_t count, off_t) {
|
.WillOnce(Invoke([&successfullyWrittenBytes](int, const void*, fspp::num_bytes_t count, fspp::num_bytes_t) {
|
||||||
// Store the number of successfully written bytes
|
// Store the number of successfully written bytes
|
||||||
successfullyWrittenBytes = count;
|
successfullyWrittenBytes = count;
|
||||||
}));
|
}));
|
||||||
EXPECT_CALL(fsimpl, write(0, _, _, Ne(0)))
|
EXPECT_CALL(fsimpl, write(0, _, _, Ne(fspp::num_bytes_t(0))))
|
||||||
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
|
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
|
||||||
|
|
||||||
char *buf = new char[WRITECOUNT];
|
char *buf = new char[WRITECOUNT.value()];
|
||||||
auto retval = WriteFileReturnError(FILENAME, buf, WRITECOUNT, 0);
|
auto retval = WriteFileReturnError(FILENAME, buf, WRITECOUNT, fspp::num_bytes_t(0));
|
||||||
EXPECT_EQ(0, retval.error);
|
EXPECT_EQ(0, retval.error);
|
||||||
EXPECT_EQ(successfullyWrittenBytes, retval.written_bytes); // Check that we're getting the number of successfully written bytes (the first write call) returned
|
EXPECT_EQ(successfullyWrittenBytes, retval.written_bytes); // Check that we're getting the number of successfully written bytes (the first write call) returned
|
||||||
delete[] buf;
|
delete[] buf;
|
||||||
|
@ -22,5 +22,5 @@ TEST_P(FuseWriteFileDescriptorTest, FileDescriptorIsCorrect) {
|
|||||||
.Times(1).WillOnce(Return());
|
.Times(1).WillOnce(Return());
|
||||||
|
|
||||||
char buf[1];
|
char buf[1];
|
||||||
WriteFile(FILENAME, buf, 1, 0);
|
WriteFile(FILENAME, buf, fspp::num_bytes_t(1), fspp::num_bytes_t(0));
|
||||||
}
|
}
|
||||||
|
@ -15,44 +15,44 @@ using namespace fspp::fuse;
|
|||||||
|
|
||||||
class FuseWriteOverflowTest: public FuseWriteTest {
|
class FuseWriteOverflowTest: public FuseWriteTest {
|
||||||
public:
|
public:
|
||||||
size_t FILESIZE;
|
fspp::num_bytes_t FILESIZE;
|
||||||
size_t WRITESIZE;
|
fspp::num_bytes_t WRITESIZE;
|
||||||
size_t OFFSET;
|
fspp::num_bytes_t OFFSET;
|
||||||
|
|
||||||
WriteableInMemoryFile testFile;
|
WriteableInMemoryFile testFile;
|
||||||
Data writeData;
|
Data writeData;
|
||||||
|
|
||||||
FuseWriteOverflowTest(size_t filesize, size_t writesize, size_t offset)
|
FuseWriteOverflowTest(fspp::num_bytes_t filesize, fspp::num_bytes_t writesize, fspp::num_bytes_t offset)
|
||||||
: FILESIZE(filesize), WRITESIZE(writesize), OFFSET(offset), testFile(DataFixture::generate(FILESIZE)), writeData(DataFixture::generate(WRITESIZE)) {
|
: FILESIZE(filesize), WRITESIZE(writesize), OFFSET(offset), testFile(DataFixture::generate(FILESIZE.value())), writeData(DataFixture::generate(WRITESIZE.value())) {
|
||||||
ReturnIsFileOnLstatWithSize(FILENAME, FILESIZE);
|
ReturnIsFileOnLstatWithSize(FILENAME, FILESIZE);
|
||||||
OnOpenReturnFileDescriptor(FILENAME, 0);
|
OnOpenReturnFileDescriptor(FILENAME, 0);
|
||||||
EXPECT_CALL(fsimpl, write(0, _, _, _)).WillRepeatedly(WriteToFile);
|
EXPECT_CALL(fsimpl, write(0, _, _, _)).WillRepeatedly(WriteToFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This write() mock implementation writes to the stored virtual file.
|
// This write() mock implementation writes to the stored virtual file.
|
||||||
Action<void(int, const void*, size_t, off_t)> WriteToFile =
|
Action<void(int, const void*, fspp::num_bytes_t, fspp::num_bytes_t)> WriteToFile =
|
||||||
Invoke([this](int, const void *buf, size_t count, off_t offset) {
|
Invoke([this](int, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
testFile.write(buf, count, offset);
|
testFile.write(buf, count, offset);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
class FuseWriteOverflowTestWithNonemptyFile: public FuseWriteOverflowTest {
|
class FuseWriteOverflowTestWithNonemptyFile: public FuseWriteOverflowTest {
|
||||||
public:
|
public:
|
||||||
FuseWriteOverflowTestWithNonemptyFile(): FuseWriteOverflowTest(1000, 2000, 500) {}
|
FuseWriteOverflowTestWithNonemptyFile(): FuseWriteOverflowTest(fspp::num_bytes_t(1000), fspp::num_bytes_t(2000), fspp::num_bytes_t(500)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(FuseWriteOverflowTestWithNonemptyFile, WriteMoreThanFileSizeFromBeginning) {
|
TEST_F(FuseWriteOverflowTestWithNonemptyFile, WriteMoreThanFileSizeFromBeginning) {
|
||||||
WriteFile(FILENAME, writeData.data(), WRITESIZE, 0);
|
WriteFile(FILENAME, writeData.data(), WRITESIZE, fspp::num_bytes_t(0));
|
||||||
|
|
||||||
EXPECT_EQ(WRITESIZE, testFile.size());
|
EXPECT_EQ(WRITESIZE, testFile.size());
|
||||||
EXPECT_TRUE(testFile.fileContentEquals(writeData, 0));
|
EXPECT_TRUE(testFile.fileContentEquals(writeData, fspp::num_bytes_t(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FuseWriteOverflowTestWithNonemptyFile, WriteMoreThanFileSizeFromMiddle) {
|
TEST_F(FuseWriteOverflowTestWithNonemptyFile, WriteMoreThanFileSizeFromMiddle) {
|
||||||
WriteFile(FILENAME, writeData.data(), WRITESIZE, OFFSET);
|
WriteFile(FILENAME, writeData.data(), WRITESIZE, OFFSET);
|
||||||
|
|
||||||
EXPECT_EQ(OFFSET + WRITESIZE, testFile.size());
|
EXPECT_EQ(OFFSET + WRITESIZE, testFile.size());
|
||||||
EXPECT_TRUE(testFile.regionUnchanged(0, OFFSET));
|
EXPECT_TRUE(testFile.regionUnchanged(fspp::num_bytes_t(0), OFFSET));
|
||||||
EXPECT_TRUE(testFile.fileContentEquals(writeData, OFFSET));
|
EXPECT_TRUE(testFile.fileContentEquals(writeData, OFFSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,20 +60,20 @@ TEST_F(FuseWriteOverflowTestWithNonemptyFile, WriteAfterFileEnd) {
|
|||||||
WriteFile(FILENAME, writeData.data(), WRITESIZE, FILESIZE + OFFSET);
|
WriteFile(FILENAME, writeData.data(), WRITESIZE, FILESIZE + OFFSET);
|
||||||
|
|
||||||
EXPECT_EQ(FILESIZE + OFFSET + WRITESIZE, testFile.size());
|
EXPECT_EQ(FILESIZE + OFFSET + WRITESIZE, testFile.size());
|
||||||
EXPECT_TRUE(testFile.regionUnchanged(0, FILESIZE));
|
EXPECT_TRUE(testFile.regionUnchanged(fspp::num_bytes_t(0), FILESIZE));
|
||||||
EXPECT_TRUE(testFile.fileContentEquals(writeData, FILESIZE + OFFSET));
|
EXPECT_TRUE(testFile.fileContentEquals(writeData, FILESIZE + OFFSET));
|
||||||
}
|
}
|
||||||
|
|
||||||
class FuseWriteOverflowTestWithEmptyFile: public FuseWriteOverflowTest {
|
class FuseWriteOverflowTestWithEmptyFile: public FuseWriteOverflowTest {
|
||||||
public:
|
public:
|
||||||
FuseWriteOverflowTestWithEmptyFile(): FuseWriteOverflowTest(0, 2000, 500) {}
|
FuseWriteOverflowTestWithEmptyFile(): FuseWriteOverflowTest(fspp::num_bytes_t(0), fspp::num_bytes_t(2000), fspp::num_bytes_t(500)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(FuseWriteOverflowTestWithEmptyFile, WriteToBeginOfEmptyFile) {
|
TEST_F(FuseWriteOverflowTestWithEmptyFile, WriteToBeginOfEmptyFile) {
|
||||||
WriteFile(FILENAME, writeData.data(), WRITESIZE, 0);
|
WriteFile(FILENAME, writeData.data(), WRITESIZE, fspp::num_bytes_t(0));
|
||||||
|
|
||||||
EXPECT_EQ(WRITESIZE, testFile.size());
|
EXPECT_EQ(WRITESIZE, testFile.size());
|
||||||
EXPECT_TRUE(testFile.fileContentEquals(writeData, 0));
|
EXPECT_TRUE(testFile.fileContentEquals(writeData, fspp::num_bytes_t(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FuseWriteOverflowTestWithEmptyFile, WriteAfterFileEnd) {
|
TEST_F(FuseWriteOverflowTestWithEmptyFile, WriteAfterFileEnd) {
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
using cpputils::unique_ref;
|
using cpputils::unique_ref;
|
||||||
using cpputils::make_unique_ref;
|
using cpputils::make_unique_ref;
|
||||||
|
|
||||||
void FuseWriteTest::WriteFile(const char *filename, const void *buf, size_t count, off_t offset) {
|
void FuseWriteTest::WriteFile(const char *filename, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
auto retval = WriteFileReturnError(filename, buf, count, offset);
|
auto retval = WriteFileReturnError(filename, buf, count, offset);
|
||||||
EXPECT_EQ(0, retval.error);
|
EXPECT_EQ(0, retval.error);
|
||||||
EXPECT_EQ(count, retval.written_bytes);
|
EXPECT_EQ(count, retval.written_bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
FuseWriteTest::WriteError FuseWriteTest::WriteFileReturnError(const char *filename, const void *buf, size_t count, off_t offset) {
|
FuseWriteTest::WriteError FuseWriteTest::WriteFileReturnError(const char *filename, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
auto fs = TestFS();
|
auto fs = TestFS();
|
||||||
|
|
||||||
auto fd = OpenFile(fs.get(), filename);
|
auto fd = OpenFile(fs.get(), filename);
|
||||||
|
|
||||||
WriteError result{};
|
WriteError result{};
|
||||||
errno = 0;
|
errno = 0;
|
||||||
result.written_bytes = ::pwrite(fd->fd(), buf, count, offset);
|
result.written_bytes = fspp::num_bytes_t(::pwrite(fd->fd(), buf, count.value(), offset.value()));
|
||||||
result.error = errno;
|
result.error = errno;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,11 @@ public:
|
|||||||
|
|
||||||
struct WriteError {
|
struct WriteError {
|
||||||
int error;
|
int error;
|
||||||
size_t written_bytes;
|
fspp::num_bytes_t written_bytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
void WriteFile(const char *filename, const void *buf, size_t count, off_t offset);
|
void WriteFile(const char *filename, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset);
|
||||||
WriteError WriteFileReturnError(const char *filename, const void *buf, size_t count, off_t offset);
|
WriteError WriteFileReturnError(const char *filename, const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
cpputils::unique_ref<OpenFileHandle> OpenFile(const TempTestFS *fs, const char *filename);
|
cpputils::unique_ref<OpenFileHandle> OpenFile(const TempTestFS *fs, const char *filename);
|
||||||
|
@ -18,9 +18,9 @@ public:
|
|||||||
~MockOpenFile() {destructed = true;}
|
~MockOpenFile() {destructed = true;}
|
||||||
|
|
||||||
MOCK_CONST_METHOD0(stat, OpenFile::stat_info());
|
MOCK_CONST_METHOD0(stat, OpenFile::stat_info());
|
||||||
MOCK_CONST_METHOD1(truncate, void(off_t));
|
MOCK_CONST_METHOD1(truncate, void(fspp::num_bytes_t));
|
||||||
MOCK_CONST_METHOD3(read, size_t(void*, size_t, off_t));
|
MOCK_CONST_METHOD3(read, fspp::num_bytes_t(void*, fspp::num_bytes_t, fspp::num_bytes_t));
|
||||||
MOCK_METHOD3(write, void(const void*, size_t, off_t));
|
MOCK_METHOD3(write, void(const void*, fspp::num_bytes_t, fspp::num_bytes_t));
|
||||||
MOCK_METHOD0(flush, void());
|
MOCK_METHOD0(flush, void());
|
||||||
MOCK_METHOD0(fsync, void());
|
MOCK_METHOD0(fsync, void());
|
||||||
MOCK_METHOD0(fdatasync, void());
|
MOCK_METHOD0(fdatasync, void());
|
||||||
|
@ -65,16 +65,16 @@ const bf::path &FuseTest::TempTestFS::mountDir() const {
|
|||||||
return _mountDir.path();
|
return _mountDir.path();
|
||||||
}
|
}
|
||||||
|
|
||||||
Action<void(const char*, struct ::stat*)> FuseTest::ReturnIsFileWithSize(size_t size) {
|
Action<void(const char*, struct ::stat*)> FuseTest::ReturnIsFileWithSize(fspp::num_bytes_t size) {
|
||||||
return Invoke([size](const char*, struct ::stat* result) {
|
return Invoke([size](const char*, struct ::stat* result) {
|
||||||
result->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
|
result->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
|
||||||
result->st_nlink = 1;
|
result->st_nlink = 1;
|
||||||
result->st_size = size;
|
result->st_size = size.value();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Combine ReturnIsFile and ReturnIsFileFstat. This should be possible in gmock by either (a) using ::testing::Undefined as parameter type or (b) using action macros
|
//TODO Combine ReturnIsFile and ReturnIsFileFstat. This should be possible in gmock by either (a) using ::testing::Undefined as parameter type or (b) using action macros
|
||||||
Action<void(const char*, struct ::stat*)> FuseTest::ReturnIsFile = ReturnIsFileWithSize(0);
|
Action<void(const char*, struct ::stat*)> FuseTest::ReturnIsFile = ReturnIsFileWithSize(fspp::num_bytes_t(0));
|
||||||
|
|
||||||
Action<void(int, struct ::stat*)> FuseTest::ReturnIsFileFstat =
|
Action<void(int, struct ::stat*)> FuseTest::ReturnIsFileFstat =
|
||||||
Invoke([](int, struct ::stat* result) {
|
Invoke([](int, struct ::stat* result) {
|
||||||
@ -82,12 +82,12 @@ Action<void(int, struct ::stat*)> FuseTest::ReturnIsFileFstat =
|
|||||||
result->st_nlink = 1;
|
result->st_nlink = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
Action<void(int, struct ::stat*)> FuseTest::ReturnIsFileFstatWithSize(size_t size) {
|
Action<void(int, struct ::stat*)> FuseTest::ReturnIsFileFstatWithSize(fspp::num_bytes_t size) {
|
||||||
return Invoke([size](int, struct ::stat *result) {
|
return Invoke([size](int, struct ::stat *result) {
|
||||||
result->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
|
result->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
|
||||||
result->st_nlink = 1;
|
result->st_nlink = 1;
|
||||||
result->st_size = size;
|
result->st_size = size.value();
|
||||||
std::cout << "Return size: " << size <<std::endl;
|
std::cout << "Return size: " << size.value() <<std::endl;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ void FuseTest::ReturnIsFileOnLstat(const bf::path &path) {
|
|||||||
EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnIsFile);
|
EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnIsFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FuseTest::ReturnIsFileOnLstatWithSize(const bf::path &path, const size_t size) {
|
void FuseTest::ReturnIsFileOnLstatWithSize(const bf::path &path, const fspp::num_bytes_t size) {
|
||||||
EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnIsFileWithSize(size));
|
EXPECT_CALL(fsimpl, lstat(::testing::StrEq(path.string().c_str()), ::testing::_)).WillRepeatedly(ReturnIsFileWithSize(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +123,6 @@ void FuseTest::ReturnIsFileOnFstat(int descriptor) {
|
|||||||
EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstat);
|
EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FuseTest::ReturnIsFileOnFstatWithSize(int descriptor, size_t size) {
|
void FuseTest::ReturnIsFileOnFstatWithSize(int descriptor, fspp::num_bytes_t size) {
|
||||||
EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstatWithSize(size));
|
EXPECT_CALL(fsimpl, fstat(descriptor, _)).WillRepeatedly(ReturnIsFileFstatWithSize(size));
|
||||||
}
|
}
|
@ -48,10 +48,10 @@ public:
|
|||||||
MOCK_METHOD1(closeFile, void(int));
|
MOCK_METHOD1(closeFile, void(int));
|
||||||
MOCK_PATH_METHOD2(lstat, void, struct ::stat*);
|
MOCK_PATH_METHOD2(lstat, void, struct ::stat*);
|
||||||
MOCK_METHOD2(fstat, void(int, struct ::stat*));
|
MOCK_METHOD2(fstat, void(int, struct ::stat*));
|
||||||
MOCK_PATH_METHOD2(truncate, void, off_t);
|
MOCK_PATH_METHOD2(truncate, void, fspp::num_bytes_t);
|
||||||
MOCK_METHOD2(ftruncate, void(int, off_t));
|
MOCK_METHOD2(ftruncate, void(int, fspp::num_bytes_t));
|
||||||
MOCK_METHOD4(read, size_t(int, void*, size_t, off_t));
|
MOCK_METHOD4(read, fspp::num_bytes_t(int, void*, fspp::num_bytes_t, fspp::num_bytes_t));
|
||||||
MOCK_METHOD4(write, void(int, const void*, size_t, off_t));
|
MOCK_METHOD4(write, void(int, const void*, fspp::num_bytes_t, fspp::num_bytes_t));
|
||||||
MOCK_METHOD1(flush, void(int));
|
MOCK_METHOD1(flush, void(int));
|
||||||
MOCK_METHOD1(fsync, void(int));
|
MOCK_METHOD1(fsync, void(int));
|
||||||
MOCK_METHOD1(fdatasync, void(int));
|
MOCK_METHOD1(fdatasync, void(int));
|
||||||
@ -79,7 +79,7 @@ public:
|
|||||||
MOCK_PATH_METHOD2(chmod, void, mode_t);
|
MOCK_PATH_METHOD2(chmod, void, mode_t);
|
||||||
MOCK_PATH_METHOD3(chown, void, uid_t, gid_t);
|
MOCK_PATH_METHOD3(chown, void, uid_t, gid_t);
|
||||||
MOCK_METHOD4(createSymlink, void(const char*, const char*, uid_t, gid_t));
|
MOCK_METHOD4(createSymlink, void(const char*, const char*, uid_t, gid_t));
|
||||||
MOCK_PATH_METHOD3(readSymlink, void, char*, size_t);
|
MOCK_PATH_METHOD3(readSymlink, void, char*, fspp::num_bytes_t);
|
||||||
};
|
};
|
||||||
|
|
||||||
class FuseTest: public ::testing::Test {
|
class FuseTest: public ::testing::Test {
|
||||||
@ -107,19 +107,19 @@ public:
|
|||||||
|
|
||||||
//TODO Combine ReturnIsFile and ReturnIsFileFstat. This should be possible in gmock by either (a) using ::testing::Undefined as parameter type or (b) using action macros
|
//TODO Combine ReturnIsFile and ReturnIsFileFstat. This should be possible in gmock by either (a) using ::testing::Undefined as parameter type or (b) using action macros
|
||||||
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsFile;
|
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsFile;
|
||||||
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsFileWithSize(size_t size);
|
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsFileWithSize(fspp::num_bytes_t size);
|
||||||
static ::testing::Action<void(int, struct ::stat*)> ReturnIsFileFstat;
|
static ::testing::Action<void(int, struct ::stat*)> ReturnIsFileFstat;
|
||||||
static ::testing::Action<void(int, struct ::stat*)> ReturnIsFileFstatWithSize(size_t size);
|
static ::testing::Action<void(int, struct ::stat*)> ReturnIsFileFstatWithSize(fspp::num_bytes_t size);
|
||||||
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsDir;
|
static ::testing::Action<void(const char*, struct ::stat*)> ReturnIsDir;
|
||||||
static ::testing::Action<void(const char*, struct ::stat*)> ReturnDoesntExist;
|
static ::testing::Action<void(const char*, struct ::stat*)> ReturnDoesntExist;
|
||||||
|
|
||||||
void ReturnIsFileOnLstat(const boost::filesystem::path &path);
|
void ReturnIsFileOnLstat(const boost::filesystem::path &path);
|
||||||
void ReturnIsFileOnLstatWithSize(const boost::filesystem::path &path, const size_t size);
|
void ReturnIsFileOnLstatWithSize(const boost::filesystem::path &path, fspp::num_bytes_t size);
|
||||||
void ReturnIsDirOnLstat(const boost::filesystem::path &path);
|
void ReturnIsDirOnLstat(const boost::filesystem::path &path);
|
||||||
void ReturnDoesntExistOnLstat(const boost::filesystem::path &path);
|
void ReturnDoesntExistOnLstat(const boost::filesystem::path &path);
|
||||||
void OnOpenReturnFileDescriptor(const char *filename, int descriptor);
|
void OnOpenReturnFileDescriptor(const char *filename, int descriptor);
|
||||||
void ReturnIsFileOnFstat(int descriptor);
|
void ReturnIsFileOnFstat(int descriptor);
|
||||||
void ReturnIsFileOnFstatWithSize(int descriptor, const size_t size);
|
void ReturnIsFileOnFstatWithSize(int descriptor, fspp::num_bytes_t size);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -8,9 +8,9 @@ InMemoryFile::InMemoryFile(Data data): _data(std::move(data)) {
|
|||||||
InMemoryFile::~InMemoryFile() {
|
InMemoryFile::~InMemoryFile() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int InMemoryFile::read(void *buf, size_t count, off_t offset) const {
|
fspp::num_bytes_t InMemoryFile::read(void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) const {
|
||||||
size_t realCount = std::min(count, static_cast<size_t>(_data.size() - offset));
|
fspp::num_bytes_t realCount = std::min(count, fspp::num_bytes_t(_data.size()) - offset);
|
||||||
std::memcpy(buf, _data.dataOffset(offset), realCount);
|
std::memcpy(buf, _data.dataOffset(offset.value()), realCount.value());
|
||||||
return realCount;
|
return realCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,31 +18,31 @@ const void *InMemoryFile::data() const {
|
|||||||
return _data.data();
|
return _data.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InMemoryFile::fileContentEquals(const Data &expected, off_t offset) const {
|
bool InMemoryFile::fileContentEquals(const Data &expected, fspp::num_bytes_t offset) const {
|
||||||
return 0 == std::memcmp(expected.data(), _data.dataOffset(offset), expected.size());
|
return 0 == std::memcmp(expected.data(), _data.dataOffset(offset.value()), expected.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t InMemoryFile::size() const {
|
fspp::num_bytes_t InMemoryFile::size() const {
|
||||||
return _data.size();
|
return fspp::num_bytes_t(_data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteableInMemoryFile::WriteableInMemoryFile(Data data): InMemoryFile(std::move(data)), _originalData(_data.copy()) {
|
WriteableInMemoryFile::WriteableInMemoryFile(Data data): InMemoryFile(std::move(data)), _originalData(_data.copy()) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteableInMemoryFile::write(const void *buf, size_t count, off_t offset) {
|
void WriteableInMemoryFile::write(const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
|
||||||
_extendFileSizeIfNecessary(count + offset);
|
_extendFileSizeIfNecessary(count + offset);
|
||||||
|
|
||||||
std::memcpy(_data.dataOffset(offset), buf, count);
|
std::memcpy(_data.dataOffset(offset.value()), buf, count.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteableInMemoryFile::_extendFileSizeIfNecessary(size_t size) {
|
void WriteableInMemoryFile::_extendFileSizeIfNecessary(fspp::num_bytes_t size) {
|
||||||
if (size > _data.size()) {
|
if (size > fspp::num_bytes_t(_data.size())) {
|
||||||
_extendFileSize(size);
|
_extendFileSize(size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteableInMemoryFile::_extendFileSize(size_t size) {
|
void WriteableInMemoryFile::_extendFileSize(fspp::num_bytes_t size) {
|
||||||
Data newfile(size);
|
Data newfile(size.value());
|
||||||
std::memcpy(newfile.data(), _data.data(), _data.size());
|
std::memcpy(newfile.data(), _data.data(), _data.size());
|
||||||
_data = std::move(newfile);
|
_data = std::move(newfile);
|
||||||
}
|
}
|
||||||
@ -51,6 +51,6 @@ bool WriteableInMemoryFile::sizeUnchanged() const {
|
|||||||
return _data.size() == _originalData.size();
|
return _data.size() == _originalData.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WriteableInMemoryFile::regionUnchanged(off_t offset, size_t count) const {
|
bool WriteableInMemoryFile::regionUnchanged(fspp::num_bytes_t offset, fspp::num_bytes_t count) const {
|
||||||
return 0 == std::memcmp(_data.dataOffset(offset), _originalData.dataOffset(offset), count);
|
return 0 == std::memcmp(_data.dataOffset(offset.value()), _originalData.dataOffset(offset.value()), count.value());
|
||||||
}
|
}
|
||||||
|
@ -3,18 +3,19 @@
|
|||||||
#define MESSMER_FSPP_TEST_TESTUTILS_INMEMORYFILE_H_
|
#define MESSMER_FSPP_TEST_TESTUTILS_INMEMORYFILE_H_
|
||||||
|
|
||||||
#include <cpp-utils/data/Data.h>
|
#include <cpp-utils/data/Data.h>
|
||||||
|
#include <fspp/fs_interface/Types.h>
|
||||||
|
|
||||||
class InMemoryFile {
|
class InMemoryFile {
|
||||||
public:
|
public:
|
||||||
InMemoryFile(cpputils::Data data);
|
InMemoryFile(cpputils::Data data);
|
||||||
virtual ~InMemoryFile();
|
virtual ~InMemoryFile();
|
||||||
|
|
||||||
int read(void *buf, size_t count, off_t offset) const;
|
fspp::num_bytes_t read(void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) const;
|
||||||
|
|
||||||
const void *data() const;
|
const void *data() const;
|
||||||
size_t size() const;
|
fspp::num_bytes_t size() const;
|
||||||
|
|
||||||
bool fileContentEquals(const cpputils::Data &expected, off_t offset) const;
|
bool fileContentEquals(const cpputils::Data &expected, fspp::num_bytes_t offset) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
cpputils::Data _data;
|
cpputils::Data _data;
|
||||||
@ -24,14 +25,14 @@ class WriteableInMemoryFile: public InMemoryFile {
|
|||||||
public:
|
public:
|
||||||
WriteableInMemoryFile(cpputils::Data data);
|
WriteableInMemoryFile(cpputils::Data data);
|
||||||
|
|
||||||
void write(const void *buf, size_t count, off_t offset);
|
void write(const void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset);
|
||||||
|
|
||||||
bool sizeUnchanged() const;
|
bool sizeUnchanged() const;
|
||||||
bool regionUnchanged(off_t offset, size_t count) const;
|
bool regionUnchanged(fspp::num_bytes_t offset, fspp::num_bytes_t count) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _extendFileSizeIfNecessary(size_t size);
|
void _extendFileSizeIfNecessary(fspp::num_bytes_t size);
|
||||||
void _extendFileSize(size_t size);
|
void _extendFileSize(fspp::num_bytes_t size);
|
||||||
|
|
||||||
cpputils::Data _originalData;
|
cpputils::Data _originalData;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user