Introduce fspp::num_bytes_t

This commit is contained in:
Sebastian Messmer 2018-09-15 14:32:58 -07:00
parent 26e33a44ea
commit 8d21e09159
71 changed files with 391 additions and 358 deletions

View File

@ -59,7 +59,7 @@ void DataLeafNode::resize(uint32_t 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);
ZEROES.FillWithZeroes();
node().write(ZEROES.data(), begin, end-begin);

View File

@ -28,7 +28,7 @@ public:
void resize(uint32_t size);
private:
void fillDataWithZeroesFromTo(off_t begin, off_t end);
void fillDataWithZeroesFromTo(uint64_t begin, uint64_t end);
DISALLOW_COPY_AND_ASSIGN(DataLeafNode);
};

View File

@ -40,7 +40,7 @@ unique_ref<fspp::OpenFile> CryFile::open(int flags) {
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();
auto blob = LoadBlob(); // NOLINT (workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82481 )
blob->resize(size);

View File

@ -15,7 +15,7 @@ public:
~CryFile();
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;
void remove() override;

View File

@ -35,19 +35,19 @@ fspp::Node::stat_info CryOpenFile::stat() const {
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();
_fileBlob->resize(size);
_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();
_parent->updateAccessTimestampForChild(_fileBlob->blockId(), fsblobstore::TimestampUpdateBehavior::RELATIME);
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();
_parent->updateModificationTimestampForChild(_fileBlob->blockId());
_fileBlob->write(buf, offset, count);

View File

@ -15,9 +15,9 @@ public:
~CryOpenFile();
stat_info stat() const override;
void truncate(off_t size) const override;
size_t read(void *buf, size_t count, off_t offset) const override;
void write(const void *buf, size_t count, off_t offset) override;
void truncate(fspp::num_bytes_t size) 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, fspp::num_bytes_t count, fspp::num_bytes_t offset) override;
void flush() override;
void fsync() override;
void fdatasync() override;

View File

@ -58,7 +58,7 @@ public:
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);
}
@ -102,11 +102,11 @@ public:
return _base->blockId();
}
off_t lstat_size() const {
fspp::num_bytes_t lstat_size() const {
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);
}

View File

@ -16,19 +16,19 @@ public:
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);
}
off_t size() const {
fspp::num_bytes_t size() const {
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);
}
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);
}
@ -40,7 +40,7 @@ public:
return _base->blockId();
}
off_t lstat_size() const {
fspp::num_bytes_t lstat_size() const {
return _base->lstat_size();
}

View File

@ -13,7 +13,7 @@ class FsBlobRef {
public:
virtual ~FsBlobRef();
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 {
return _baseBlob->parentPointer();

View File

@ -24,7 +24,7 @@ public:
return _base->blockId();
}
off_t lstat_size() const {
fspp::num_bytes_t lstat_size() const {
return _base->lstat_size();
}

View File

@ -24,9 +24,9 @@ using boost::none;
namespace cryfs {
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) {
ASSERT(baseBlob().blobType() == FsBlobView::BlobType::DIR, "Loaded blob is not a directory");
_readEntriesFromBlob();
@ -43,7 +43,7 @@ void DirBlob::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);
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;
}
@ -140,7 +140,7 @@ fspp::Node::stat_info DirBlob::statChild(const BlockId &blockId) const {
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;
auto childOpt = GetChild(blockId);
@ -158,7 +158,7 @@ fspp::Node::stat_info DirBlob::statChildWithKnownSize(const BlockId &blockId, ui
result.mtime = child.lastModificationTime();
result.ctime = child.lastMetadataChangeTime();
//TODO Move ceilDivision to general utils which can be used by cryfs as well
result.blocks = blobstore::onblocks::utils::ceilDivision(size, static_cast<uint64_t>(512));
result.blocks = blobstore::onblocks::utils::ceilDivision(size.value(), static_cast<int64_t>(512));
return result;
}
@ -194,7 +194,7 @@ void DirBlob::utimensChild(const BlockId &blockId, timespec lastAccessTime, time
_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);
_getLstatSize = getLstatSize;
}

View File

@ -16,17 +16,17 @@ namespace cryfs {
class DirBlob final : public FsBlob {
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,
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();
off_t lstat_size() const override;
fspp::num_bytes_t lstat_size() const override;
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 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);
@ -71,7 +71,7 @@ namespace cryfs {
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:
@ -83,7 +83,7 @@ namespace cryfs {
cpputils::unique_ref<blobstore::Blob> releaseBaseBlob() override;
FsBlobStore *_fsBlobStore;
std::function<off_t (const blockstore::BlockId&)> _getLstatSize;
std::function<fspp::num_bytes_t (const blockstore::BlockId&)> _getLstatSize;
DirEntryList _entries;
mutable std::mutex _mutex;
bool _changed;

View File

@ -21,28 +21,28 @@ unique_ref<FileBlob> FileBlob::InitializeEmptyFile(unique_ref<Blob> blob, const
return make_unique_ref<FileBlob>(std::move(blob));
}
size_t FileBlob::read(void *target, uint64_t offset, uint64_t count) const {
return baseBlob().tryRead(target, offset, count);
fspp::num_bytes_t FileBlob::read(void *target, fspp::num_bytes_t offset, fspp::num_bytes_t count) const {
return fspp::num_bytes_t(baseBlob().tryRead(target, offset.value(), count.value()));
}
void FileBlob::write(const void *source, uint64_t offset, uint64_t count) {
baseBlob().write(source, offset, count);
void FileBlob::write(const void *source, fspp::num_bytes_t offset, fspp::num_bytes_t count) {
baseBlob().write(source, offset.value(), count.value());
}
void FileBlob::flush() {
baseBlob().flush();
}
void FileBlob::resize(off_t size) {
baseBlob().resize(size);
void FileBlob::resize(fspp::num_bytes_t size) {
baseBlob().resize(size.value());
}
off_t FileBlob::lstat_size() const {
fspp::num_bytes_t FileBlob::lstat_size() const {
return size();
}
off_t FileBlob::size() const {
return baseBlob().size();
fspp::num_bytes_t FileBlob::size() const {
return fspp::num_bytes_t(baseBlob().size());
}
}

View File

@ -13,17 +13,17 @@ namespace cryfs {
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 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:
DISALLOW_COPY_AND_ASSIGN(FileBlob);
};

View File

@ -5,6 +5,7 @@
#include <cpp-utils/pointer/unique_ref.h>
#include <blobstore/interface/Blob.h>
#include "FsBlobView.h"
#include <fspp/fs_interface/Types.h>
namespace cryfs {
namespace fsblobstore {
@ -12,7 +13,7 @@ namespace cryfs {
public:
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 &parentPointer() const;
void setParentPointer(const blockstore::BlockId &parentId);

View File

@ -38,7 +38,7 @@ namespace cryfs {
void _migrate(cpputils::unique_ref<blobstore::Blob> node, const blockstore::BlockId &parentId);
#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;
@ -80,7 +80,7 @@ namespace cryfs {
_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) {
auto blob = load(blockId);
ASSERT(blob != boost::none, "Blob not found");

View File

@ -38,8 +38,8 @@ const bf::path &SymlinkBlob::target() const {
return _target;
}
off_t SymlinkBlob::lstat_size() const {
return target().string().size();
fspp::num_bytes_t SymlinkBlob::lstat_size() const {
return fspp::num_bytes_t(target().string().size());
}
}

View File

@ -17,7 +17,7 @@ namespace cryfs {
const boost::filesystem::path &target() const;
off_t lstat_size() const override;
fspp::num_bytes_t lstat_size() const override;
private:
boost::filesystem::path _target;

View File

@ -54,7 +54,7 @@ public:
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);
}
@ -98,7 +98,7 @@ public:
return _base->blockId();
}
off_t lstat_size() const override {
fspp::num_bytes_t lstat_size() const override {
return _base->lstat_size();
}

View File

@ -12,19 +12,19 @@ class FileBlobRef final: public FsBlobRef {
public:
FileBlobRef(cachingfsblobstore::FileBlobRef *base) : _base(base) {}
void resize(off_t size) {
void resize(fspp::num_bytes_t size) {
return _base->resize(size);
}
off_t size() const {
fspp::num_bytes_t size() const {
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);
}
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);
}
@ -36,7 +36,7 @@ public:
return _base->blockId();
}
off_t lstat_size() const override {
fspp::num_bytes_t lstat_size() const override {
return _base->lstat_size();
}

View File

@ -12,7 +12,7 @@ class FsBlobRef: public parallelaccessstore::ParallelAccessStore<cachingfsblobst
public:
virtual ~FsBlobRef() {}
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 void setParentPointer(const blockstore::BlockId &parentId) = 0;

View File

@ -35,7 +35,7 @@ namespace cryfs {
cpputils::unique_ref<cachingfsblobstore::CachingFsBlobStore> _baseBlobStore;
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);
};
@ -50,7 +50,7 @@ namespace cryfs {
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) {
auto blob = load(blockId);
ASSERT(blob != boost::none, "Blob not found");

View File

@ -20,7 +20,7 @@ public:
return _base->blockId();
}
off_t lstat_size() const override {
fspp::num_bytes_t lstat_size() const override {
return _base->lstat_size();
}

View File

@ -3,6 +3,7 @@
#define MESSMER_FSPP_FSINTERFACE_FILE_H_
#include <cpp-utils/pointer/unique_ref.h>
#include "Types.h"
namespace fspp {
class Device;
@ -13,7 +14,7 @@ public:
virtual ~File() {}
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;
};
}

View File

@ -15,9 +15,9 @@ public:
using stat_info = fspp::stat_info;
virtual stat_info stat() const = 0;
virtual void truncate(off_t size) const = 0;
virtual size_t read(void *buf, size_t count, off_t offset) const = 0;
virtual void write(const void *buf, size_t count, off_t offset) = 0;
virtual void truncate(fspp::num_bytes_t size) 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, fspp::num_bytes_t count, fspp::num_bytes_t offset) = 0;
virtual void flush() = 0;
virtual void fsync() = 0;
virtual void fdatasync() = 0;

View File

@ -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 {
uint32_t nlink;
fspp::mode_t mode;
fspp::uid_t uid;
fspp::gid_t gid;
uint64_t size;
fspp::num_bytes_t size;
uint64_t blocks;
struct timespec atime;
struct timespec mtime;

View File

@ -24,36 +24,36 @@ public:
}
void Test_Truncate_DontChange1(fspp::File *file, fspp::Node *node) {
file->truncate(0);
this->EXPECT_SIZE(0, file, node);
file->truncate(fspp::num_bytes_t(0));
this->EXPECT_SIZE(fspp::num_bytes_t(0), file, node);
}
void Test_Truncate_GrowTo1(fspp::File *file, fspp::Node *node) {
file->truncate(1);
this->EXPECT_SIZE(1, file, node);
file->truncate(fspp::num_bytes_t(1));
this->EXPECT_SIZE(fspp::num_bytes_t(1), file, node);
}
void Test_Truncate_Grow(fspp::File *file, fspp::Node *node) {
file->truncate(10*1024*1024);
this->EXPECT_SIZE(10*1024*1024, file, node);
file->truncate(fspp::num_bytes_t(10*1024*1024));
this->EXPECT_SIZE(fspp::num_bytes_t(10*1024*1024), file, node);
}
void Test_Truncate_DontChange2(fspp::File *file, fspp::Node *node) {
file->truncate(10*1024*1024);
file->truncate(10*1024*1024);
this->EXPECT_SIZE(10*1024*1024, file, node);
file->truncate(fspp::num_bytes_t(10*1024*1024));
file->truncate(fspp::num_bytes_t(10*1024*1024));
this->EXPECT_SIZE(fspp::num_bytes_t(10*1024*1024), file, node);
}
void Test_Truncate_Shrink(fspp::File *file, fspp::Node *node) {
file->truncate(10*1024*1024);
file->truncate(5*1024*1024);
this->EXPECT_SIZE(5*1024*1024, file, node);
file->truncate(fspp::num_bytes_t(10*1024*1024));
file->truncate(fspp::num_bytes_t(5*1024*1024));
this->EXPECT_SIZE(fspp::num_bytes_t(5*1024*1024), file, node);
}
void Test_Truncate_ShrinkTo0(fspp::File *file, fspp::Node *node) {
file->truncate(10*1024*1024);
file->truncate(0);
this->EXPECT_SIZE(0, file, node);
file->truncate(fspp::num_bytes_t(10*1024*1024));
file->truncate(fspp::num_bytes_t(0));
this->EXPECT_SIZE(fspp::num_bytes_t(0), file, node);
}
void Test_Chown_Uid(fspp::File *file, fspp::Node *node) {

View File

@ -7,7 +7,7 @@
template<class ConcreteFileSystemTestFixture>
class FsppFileTest_Timestamps: public TimestampTestUtils<ConcreteFileSystemTestFixture> {
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);
file->truncate(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) {
auto file = this->CreateFileWithSize("/myfile", 0);
auto file = this->CreateFileWithSize("/myfile", fspp::num_bytes_t(0));
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});
}
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] () {
file->truncate(10);
file->truncate(fspp::num_bytes_t(10));
};
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
}
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] () {
file->truncate(0);
file->truncate(fspp::num_bytes_t(0));
};
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
}
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] () {
file->truncate(5);
file->truncate(fspp::num_bytes_t(5));
};
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
}
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] () {
file->truncate(20);
file->truncate(fspp::num_bytes_t(20));
};
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
}

View File

@ -26,7 +26,7 @@ TYPED_TEST_CASE_P(FsppNodeTest_Stat_FileOnly);
TYPED_TEST_P(FsppNodeTest_Stat_FileOnly, CreatedFileIsEmpty) {
this->CreateFile("/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) {

View File

@ -12,20 +12,20 @@ public:
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) {
EXPECT_EQ(expectedSize, static_cast<uint64_t>(st.size));
EXPECT_EQ(expectedSize, st.size);
});
EXPECT_NUMBYTES_READABLE(expectedSize, openFile);
}
void EXPECT_NUMBYTES_READABLE(uint64_t expectedSize, fspp::OpenFile *openFile) {
cpputils::Data data(expectedSize);
void EXPECT_NUMBYTES_READABLE(fspp::num_bytes_t expectedSize, fspp::OpenFile *openFile) {
cpputils::Data data(expectedSize.value());
//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)
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) {
auto file = this->CreateFile("/myfile");
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) {

View File

@ -10,7 +10,7 @@ public:
cpputils::unique_ref<fspp::OpenFile> CreateAndOpenFile(const boost::filesystem::path &path) {
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);
file->truncate(size);
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) {
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 0);
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(0));
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});
}
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] () {
openFile->truncate(10);
openFile->truncate(fspp::num_bytes_t(10));
};
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
}
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] () {
openFile->truncate(0);
openFile->truncate(fspp::num_bytes_t(0));
};
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
}
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] () {
openFile->truncate(5);
openFile->truncate(fspp::num_bytes_t(5));
};
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
}
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] () {
openFile->truncate(20);
openFile->truncate(fspp::num_bytes_t(20));
};
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS(*openFile, operation, {this->ExpectDoesntUpdateAccessTimestamp, this->ExpectUpdatesModificationTimestamp, this->ExpectUpdatesMetadataTimestamp});
}
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] () {
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});
}
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] () {
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});
}
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] () {
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});
}
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] () {
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});
}
TYPED_TEST_P(FsppOpenFileTest_Timestamps, flush) {
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
openFile->write("content", 7, 0);
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
openFile->write("content", fspp::num_bytes_t(7), fspp::num_bytes_t(0));
auto operation = [&openFile] () {
openFile->flush();
};
@ -113,8 +113,8 @@ TYPED_TEST_P(FsppOpenFileTest_Timestamps, flush) {
}
TYPED_TEST_P(FsppOpenFileTest_Timestamps, fsync) {
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
openFile->write("content", 7, 0);
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
openFile->write("content", fspp::num_bytes_t(7), fspp::num_bytes_t(0));
auto operation = [&openFile] () {
openFile->fsync();
};
@ -122,8 +122,8 @@ TYPED_TEST_P(FsppOpenFileTest_Timestamps, fsync) {
}
TYPED_TEST_P(FsppOpenFileTest_Timestamps, fdatasync) {
auto openFile = this->CreateAndOpenFileWithSize("/myfile", 10);
openFile->write("content", 7, 0);
auto openFile = this->CreateAndOpenFileWithSize("/myfile", fspp::num_bytes_t(10));
openFile->write("content", fspp::num_bytes_t(7), fspp::num_bytes_t(0));
auto operation = [&openFile] () {
openFile->fdatasync();
};

View File

@ -35,21 +35,21 @@ public:
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) {
EXPECT_EQ(expectedSize, static_cast<uint64_t>(st.size));
EXPECT_EQ(expectedSize, st.size);
});
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);
cpputils::Data data(expectedSize);
cpputils::Data data(expectedSize.value());
//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)
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) {

View File

@ -14,9 +14,9 @@ public:
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) {
EXPECT_EQ(expectedSize, static_cast<uint64_t>(st.size));
EXPECT_EQ(expectedSize, st.size);
});
}
};

View File

@ -25,10 +25,10 @@ public:
virtual void chmod(const boost::filesystem::path &path, ::mode_t mode) = 0;
//TODO Test chown
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 ftruncate(int descriptor, off_t size) = 0;
virtual size_t read(int descriptor, void *buf, size_t count, off_t offset) = 0;
virtual void write(int descriptor, const void *buf, size_t count, off_t offset) = 0;
virtual void truncate(const boost::filesystem::path &path, fspp::num_bytes_t size) = 0;
virtual void ftruncate(int descriptor, fspp::num_bytes_t size) = 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, fspp::num_bytes_t count, fspp::num_bytes_t offset) = 0;
virtual void fsync(int descriptor) = 0;
virtual void fdatasync(int descriptor) = 0;
virtual void access(const boost::filesystem::path &path, int mask) = 0;
@ -44,7 +44,7 @@ public:
//TODO Test createSymlink
virtual void createSymlink(const boost::filesystem::path &to, const boost::filesystem::path &from, ::uid_t uid, ::gid_t gid) = 0;
//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;
};
}

View File

@ -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);
}
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);
}
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);
}
@ -100,11 +100,11 @@ int fusepp_release(const char *path, fuse_file_info *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);
}
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);
}
@ -129,7 +129,7 @@ int fusepp_opendir(const char *path, fuse_file_info *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);
}
@ -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_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_write_buf(const char*, fuse_bufvec *buf, off_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_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, int64_t off, fuse_file_info*)
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() {
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
try {
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;
} catch(const cpputils::AssertFailed &e) {
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
LOG(DEBUG, "truncate({}, {})", path, size);
#endif
try {
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;
} catch(const cpputils::AssertFailed &e) {
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
LOG(DEBUG, "ftruncate({}, {})", path, size);
#endif
UNUSED(path);
try {
_fs->ftruncate(fileinfo->fh, size);
_fs->ftruncate(fileinfo->fh, fspp::num_bytes_t(size));
return 0;
} catch(const cpputils::AssertFailed &e) {
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
LOG(DEBUG, "read({}, _, {}, {}, _)", path, size, offset);
#endif
UNUSED(path);
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) {
LOG(ERR, "AssertFailed in Fuse::read: {}", e.what());
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
LOG(DEBUG, "write({}, _, {}, {}, _)", path, size, offsset);
#endif
UNUSED(path);
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;
} catch(const cpputils::AssertFailed &e) {
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;
}
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
LOG(DEBUG, "readdir({}, _, _, {}, _)", path, offest);
#endif

View File

@ -39,18 +39,18 @@ public:
int link(const boost::filesystem::path &from, const boost::filesystem::path &to);
int chmod(const boost::filesystem::path &path, ::mode_t mode);
int chown(const boost::filesystem::path &path, ::uid_t uid, ::gid_t gid);
int truncate(const boost::filesystem::path &path, off_t size);
int ftruncate(const boost::filesystem::path &path, off_t size, fuse_file_info *fileinfo);
int truncate(const boost::filesystem::path &path, int64_t size);
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 open(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 write(const boost::filesystem::path &path, const 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, int64_t offset, fuse_file_info *fileinfo);
int statfs(const boost::filesystem::path &path, struct ::statvfs *fsstat);
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 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 fsyncdir(const boost::filesystem::path &path, int datasync, fuse_file_info *fileinfo);
void init(fuse_conn_info *conn);

View File

@ -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_uid = input.uid.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_atim = input.atime;
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);
LoadFile(path)->truncate(size);
}
void FilesystemImpl::ftruncate(int descriptor, off_t size) {
void FilesystemImpl::ftruncate(int descriptor, fspp::num_bytes_t size) {
PROFILE(_ftruncateNanosec);
_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);
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);
_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));
}
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);
string target = LoadSymlink(path)->target().string();
PROFILE(_readSymlinkNanosec_withoutLoading);
std::memcpy(buf, target.c_str(), std::min(target.size()+1, size));
buf[size-1] = '\0';
std::memcpy(buf, target.c_str(), std::min(static_cast<int64_t>(target.size()+1), size.value()));
buf[size.value()-1] = '\0';
}

View File

@ -31,10 +31,10 @@ public:
void fstat(int descriptor, struct ::stat *stbuf) 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 truncate(const boost::filesystem::path &path, off_t size) override;
void ftruncate(int descriptor, off_t size) override;
size_t read(int descriptor, void *buf, size_t count, off_t offset) override;
void write(int descriptor, const void *buf, size_t count, off_t offset) override;
void truncate(const boost::filesystem::path &path, fspp::num_bytes_t size) override;
void ftruncate(int descriptor, fspp::num_bytes_t size) 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, fspp::num_bytes_t count, fspp::num_bytes_t offset) override;
void fsync(int descriptor) override;
void fdatasync(int descriptor) 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 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 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:
cpputils::unique_ref<File> LoadFile(const boost::filesystem::path &path);

View File

@ -64,9 +64,9 @@ TEST_F(BlobReadWriteTest, WritingCloseTo16ByteLimitDoesntDestroySize) {
}
struct DataRange {
size_t blobsize;
off_t offset;
size_t count;
uint64_t blobsize;
uint64_t offset;
uint64_t count;
};
class BlobReadWriteDataTest: public BlobReadWriteTest, public WithParamInterface<DataRange> {
public:
@ -79,7 +79,7 @@ public:
}
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 end(GetParam().blobsize - count - start);
@ -90,7 +90,7 @@ public:
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);
ZEROES.FillWithZeroes();
EXPECT_DATA_READS_AS_OUTSIDE_OF(ZEROES, blob, start, count);

View File

@ -259,9 +259,9 @@ TEST_F(DataLeafNodeTest, CopyDataLeaf) {
struct DataRange {
size_t leafsize;
off_t offset;
size_t count;
uint64_t leafsize;
uint64_t offset;
uint64_t count;
};
class DataLeafNodeDataTest: public DataLeafNodeTest, public WithParamInterface<DataRange> {
@ -282,13 +282,13 @@ public:
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);
leaf.read(read.data(), offset, count);
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 end(GetParam().leafsize - count - start);
@ -299,7 +299,7 @@ public:
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);
ZEROES.FillWithZeroes();
EXPECT_DATA_READS_AS_OUTSIDE_OF(ZEROES, leaf, start, count);

View File

@ -5,9 +5,9 @@
// This file is meant to be included by BlockStoreTest.h only
struct DataRange {
size_t blocksize;
off_t offset;
size_t count;
uint64_t blocksize;
uint64_t offset;
uint64_t count;
};
class BlockStoreDataParametrizedTest {
@ -116,13 +116,13 @@ private:
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);
std::memcpy(read.data(), static_cast<const uint8_t*>(block.data()) + offset, count);
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 end(testData.blocksize - count - start);
@ -133,7 +133,7 @@ private:
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);
ZEROES.FillWithZeroes();
EXPECT_DATA_READS_AS_OUTSIDE_OF(ZEROES, block, start, count);

View File

@ -36,9 +36,9 @@ TEST_P(FuseCreateAndOpenFileDescriptorTest, TestReturnedFileDescriptor) {
ReturnDoesntExistOnLstat(FILENAME);
EXPECT_CALL(fsimpl, createAndOpenFile(StrEq(FILENAME), _, _, _))
.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.
ReturnIsFileOnFstatWithSize(GetParam(), 1);
ReturnIsFileOnFstatWithSize(GetParam(), fspp::num_bytes_t(1));
CreateAndOpenAndReadFile(FILENAME);
}

View File

@ -21,6 +21,6 @@ TEST_P(FuseFTruncateErrorTest, ReturnedErrorIsCorrect) {
//Needed to make ::ftruncate system call return successfully
ReturnIsFileOnFstat(0);
int error = FTruncateFileReturnError(FILENAME, 0);
int error = FTruncateFileReturnError(FILENAME, fspp::num_bytes_t(0));
EXPECT_EQ(GetParam(), error);
}

View File

@ -23,5 +23,5 @@ TEST_P(FuseFTruncateFileDescriptorTest, FileDescriptorIsCorrect) {
//Needed to make ::ftruncate system call return successfully
ReturnIsFileOnFstat(GetParam());
FTruncateFile(FILENAME, 0);
FTruncateFile(FILENAME, fspp::num_bytes_t(0));
}

View File

@ -5,9 +5,14 @@ using ::testing::Return;
using ::testing::WithParamInterface;
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) {
@ -18,5 +23,5 @@ TEST_P(FuseFTruncateSizeTest, FTruncateFile) {
//Needed to make ::ftruncate system call return successfully
ReturnIsFileOnFstat(0);
FTruncateFile(FILENAME, GetParam());
FTruncateFile(FILENAME, fspp::num_bytes_t(GetParam()));
}

View File

@ -3,16 +3,16 @@
using cpputils::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);
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 fd = OpenFile(fs.get(), filename);
int retval = ::ftruncate(fd->fd(), size);
int retval = ::ftruncate(fd->fd(), size.value());
if (0 == retval) {
return 0;
} else {

View File

@ -9,8 +9,8 @@ class FuseFTruncateTest: public FuseTest {
public:
const char *FILENAME = "/myfile";
void FTruncateFile(const char *filename, off_t size);
int FTruncateFileReturnError(const char *filename, off_t size);
void FTruncateFile(const char *filename, fspp::num_bytes_t size);
int FTruncateFileReturnError(const char *filename, fspp::num_bytes_t size);
private:
cpputils::unique_ref<OpenFileHandle> OpenFile(const TempTestFS *fs, const char *filename);

View File

@ -3,25 +3,25 @@
using ::testing::WithParamInterface;
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:
void set(struct stat *stat, off_t value) override {
stat->st_size = value;
void set(struct stat *stat, fspp::num_bytes_t value) override {
stat->st_size = value.value();
}
};
INSTANTIATE_TEST_CASE_P(FuseLstatReturnSizeTest, FuseLstatReturnSizeTest, Values(
0,
1,
4096,
1024*1024*1024
fspp::num_bytes_t(0),
fspp::num_bytes_t(1),
fspp::num_bytes_t(4096),
fspp::num_bytes_t(1024*1024*1024)
));
TEST_P(FuseLstatReturnSizeTest, ReturnedFileSizeIsCorrect) {
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) {
struct ::stat result = CallDirLstatWithValue(GetParam());
EXPECT_EQ(GetParam(), result.st_size);
EXPECT_EQ(GetParam(), fspp::num_bytes_t(result.st_size));
}

View File

@ -33,10 +33,10 @@ private:
INSTANTIATE_TEST_CASE_P(FuseOpenFileDescriptorTest, FuseOpenFileDescriptorTest, Values(0, 2, 5, 1000, 1024*1024*1024));
TEST_P(FuseOpenFileDescriptorTest, TestReturnedFileDescriptor) {
ReturnIsFileOnLstatWithSize(FILENAME, 1);
ReturnIsFileOnLstatWithSize(FILENAME, fspp::num_bytes_t(1));
EXPECT_CALL(fsimpl, openFile(StrEq(FILENAME), _))
.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);
}

View File

@ -14,8 +14,8 @@ using namespace fspp::fuse;
class FuseReadErrorTest: public FuseReadTest, public WithParamInterface<int> {
public:
size_t FILESIZE = 64*1024*1024;
size_t READCOUNT = 32*1024*1024;
fspp::num_bytes_t FILESIZE = fspp::num_bytes_t(64*1024*1024);
fspp::num_bytes_t READCOUNT = fspp::num_bytes_t(32*1024*1024);
void SetUp() override {
//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, _, _, _))
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
char *buf = new char[READCOUNT];
auto retval = ReadFileReturnError(FILENAME, buf, READCOUNT, 0);
char *buf = new char[READCOUNT.value()];
auto retval = ReadFileReturnError(FILENAME, buf, READCOUNT, fspp::num_bytes_t(0));
EXPECT_EQ(GetParam(), retval.error);
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.
// 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
size_t successfullyReadBytes = -1;
EXPECT_CALL(fsimpl, read(0, _, _, Eq(0)))
fspp::num_bytes_t successfullyReadBytes = fspp::num_bytes_t(-1);
EXPECT_CALL(fsimpl, read(0, _, _, Eq(fspp::num_bytes_t(0))))
.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
successfullyReadBytes = 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())));
char *buf = new char[READCOUNT];
auto retval = ReadFileReturnError(FILENAME, buf, READCOUNT, 0);
char *buf = new char[READCOUNT.value()];
auto retval = ReadFileReturnError(FILENAME, buf, READCOUNT, fspp::num_bytes_t(0));
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
delete[] buf;

View File

@ -15,11 +15,11 @@ INSTANTIATE_TEST_CASE_P(FuseReadFileDescriptorTest, FuseReadFileDescriptorTest,
TEST_P(FuseReadFileDescriptorTest, FileDescriptorIsCorrect) {
ReturnIsFileOnLstatWithSize(FILENAME, 1);
ReturnIsFileOnLstatWithSize(FILENAME, fspp::num_bytes_t(1));
OnOpenReturnFileDescriptor(FILENAME, GetParam());
EXPECT_CALL(fsimpl, read(Eq(GetParam()), _, _, _))
.Times(1).WillOnce(ReturnSuccessfulRead);
char buf[1];
ReadFile(FILENAME, buf, 1, 0);
ReadFile(FILENAME, buf, fspp::num_bytes_t(1), fspp::num_bytes_t(0));
}

View File

@ -9,9 +9,9 @@ using namespace fspp::fuse;
class FuseReadOverflowTest: public FuseReadTest {
public:
static constexpr size_t FILESIZE = 1000;
static constexpr size_t READSIZE = 2000;
static constexpr size_t OFFSET = 500;
static constexpr fspp::num_bytes_t FILESIZE = fspp::num_bytes_t(1000);
static constexpr fspp::num_bytes_t READSIZE = fspp::num_bytes_t(2000);
static constexpr fspp::num_bytes_t OFFSET = fspp::num_bytes_t(500);
void SetUp() override {
ReturnIsFileOnLstatWithSize(FILENAME, FILESIZE);
@ -20,19 +20,19 @@ public:
}
};
constexpr size_t FuseReadOverflowTest::FILESIZE;
constexpr size_t FuseReadOverflowTest::READSIZE;
constexpr size_t FuseReadOverflowTest::OFFSET;
constexpr fspp::num_bytes_t FuseReadOverflowTest::FILESIZE;
constexpr fspp::num_bytes_t FuseReadOverflowTest::READSIZE;
constexpr fspp::num_bytes_t FuseReadOverflowTest::OFFSET;
TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromBeginning) {
char buf[READSIZE];
auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, 0);
char buf[READSIZE.value()];
auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, fspp::num_bytes_t(0));
EXPECT_EQ(FILESIZE, retval.read_bytes);
}
TEST_F(FuseReadOverflowTest, ReadMoreThanFileSizeFromMiddle) {
char buf[READSIZE];
char buf[READSIZE.value()];
auto retval = ReadFileReturnError(FILENAME, buf, READSIZE, OFFSET);
EXPECT_EQ(FILESIZE-OFFSET, retval.read_bytes);
}

View File

@ -29,19 +29,19 @@ using namespace fspp::fuse;
struct TestData {
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)) {}
size_t count;
off_t offset;
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)) {}
fspp::num_bytes_t count;
fspp::num_bytes_t offset;
//How many more bytes does the file have after the read block?
size_t additional_bytes_at_end_of_file;
size_t fileSize() {
fspp::num_bytes_t additional_bytes_at_end_of_file;
fspp::num_bytes_t fileSize() {
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
// 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:
std::unique_ptr<InMemoryFile> testFile;
TestData testData;
@ -49,7 +49,7 @@ public:
FuseReadReturnedDataTest()
: testFile(nullptr),
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());
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, read(0, _, _, _))
@ -57,15 +57,19 @@ public:
}
// 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);
});
};
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) {
Data buf(testData.count);
Data buf(testData.count.value());
ReadFile(FILENAME, buf.data(), testData.count, testData.offset);
EXPECT_TRUE(testFile->fileContentEquals(buf, testData.offset));
}

View File

@ -3,20 +3,20 @@
using cpputils::make_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);
EXPECT_EQ(0, retval.error);
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 fd = OpenFile(fs.get(), filename);
ReadError result{};
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;
return result;
}

View File

@ -11,20 +11,20 @@ public:
struct ReadError {
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);
ReadError ReadFileReturnError(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, fspp::num_bytes_t count, fspp::num_bytes_t offset);
::testing::Action<size_t(int, void*, size_t, off_t)> ReturnSuccessfulRead =
::testing::Invoke([](int, void *, size_t count, off_t) {
::testing::Action<fspp::num_bytes_t(int, void*, fspp::num_bytes_t, fspp::num_bytes_t)> ReturnSuccessfulRead =
::testing::Invoke([](int, void *, fspp::num_bytes_t count, fspp::num_bytes_t) {
return count;
});
::testing::Action<size_t(int, void*, size_t, off_t)> ReturnSuccessfulReadRegardingSize(size_t filesize) {
return ::testing::Invoke([filesize](int, void *, size_t count, off_t offset) {
size_t ableToReadCount = std::min(count, static_cast<size_t>(filesize - offset));
::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 *, fspp::num_bytes_t count, fspp::num_bytes_t offset) {
fspp::num_bytes_t ableToReadCount = std::min(count, filesize - offset);
return ableToReadCount;
});
}

View File

@ -18,6 +18,6 @@ TEST_P(FuseTruncateErrorTest, ReturnedErrorIsCorrect) {
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), _))
.Times(1).WillOnce(Throw(FuseErrnoException(GetParam())));
int error = TruncateFileReturnError(FILENAME, 0);
int error = TruncateFileReturnError(FILENAME, fspp::num_bytes_t(0));
EXPECT_EQ(GetParam(), error);
}

View File

@ -12,7 +12,7 @@ TEST_F(FuseTruncateFilenameTest, TruncateFile) {
EXPECT_CALL(fsimpl, truncate(StrEq("/myfile"), _))
.Times(1).WillOnce(Return());
TruncateFile("/myfile", 0);
TruncateFile("/myfile", fspp::num_bytes_t(0));
}
TEST_F(FuseTruncateFilenameTest, TruncateFileNested) {
@ -21,7 +21,7 @@ TEST_F(FuseTruncateFilenameTest, TruncateFileNested) {
EXPECT_CALL(fsimpl, truncate(StrEq("/mydir/myfile"), _))
.Times(1).WillOnce(Return());
TruncateFile("/mydir/myfile", 0);
TruncateFile("/mydir/myfile", fspp::num_bytes_t(0));
}
TEST_F(FuseTruncateFilenameTest, TruncateFileNested2) {
@ -31,5 +31,5 @@ TEST_F(FuseTruncateFilenameTest, TruncateFileNested2) {
EXPECT_CALL(fsimpl, truncate(StrEq("/mydir/mydir2/myfile"), _))
.Times(1).WillOnce(Return());
TruncateFile("/mydir/mydir2/myfile", 0);
TruncateFile("/mydir/mydir2/myfile", fspp::num_bytes_t(0));
}

View File

@ -4,15 +4,21 @@ using ::testing::StrEq;
using ::testing::Return;
using ::testing::WithParamInterface;
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) {
ReturnIsFileOnLstat(FILENAME);
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), GetParam()))
EXPECT_CALL(fsimpl, truncate(StrEq(FILENAME), Eq(GetParam())))
.Times(1).WillOnce(Return());
TruncateFile(FILENAME, GetParam());

View File

@ -1,15 +1,15 @@
#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);
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 realpath = fs->mountDir() / filename;
int retval = ::truncate(realpath.string().c_str(), size);
int retval = ::truncate(realpath.string().c_str(), size.value());
if (retval == 0) {
return 0;
} else {

View File

@ -8,8 +8,8 @@ class FuseTruncateTest: public FuseTest {
public:
const char *FILENAME = "/myfile";
void TruncateFile(const char *filename, off_t size);
int TruncateFileReturnError(const char *filename, off_t size);
void TruncateFile(const char *filename, fspp::num_bytes_t size);
int TruncateFileReturnError(const char *filename, fspp::num_bytes_t size);
};
#endif

View File

@ -26,19 +26,19 @@ using namespace fspp::fuse;
struct TestData {
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)) {}
size_t count;
off_t offset;
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)) {}
fspp::num_bytes_t count;
fspp::num_bytes_t offset;
//How many more bytes does the file have after the read block?
size_t additional_bytes_at_end_of_file;
size_t fileSize() {
fspp::num_bytes_t additional_bytes_at_end_of_file;
fspp::num_bytes_t fileSize() {
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
// 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:
std::unique_ptr<WriteableInMemoryFile> testFile;
TestData testData;
@ -46,7 +46,7 @@ public:
FuseWriteDataTest()
: testFile(nullptr),
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());
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, write(0, _, _, _))
@ -54,25 +54,29 @@ public:
}
// 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);
});
};
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) {
Data randomWriteData = DataFixture::generate(testData.count, 2);
Data randomWriteData = DataFixture::generate(testData.count.value(), 2);
WriteFile(FILENAME, randomWriteData.data(), testData.count, testData.offset);
EXPECT_TRUE(testFile->fileContentEquals(randomWriteData, testData.offset));
}
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);
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));
}

View File

@ -14,8 +14,8 @@ using namespace fspp::fuse;
class FuseWriteErrorTest: public FuseWriteTest, public WithParamInterface<int> {
public:
size_t FILESIZE = 64*1024*1024;
size_t WRITECOUNT = 32*1024*1024;
fspp::num_bytes_t FILESIZE = fspp::num_bytes_t(64*1024*1024);
fspp::num_bytes_t WRITECOUNT = fspp::num_bytes_t(32*1024*1024);
void SetUp() override {
//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, _, _, _))
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
char *buf = new char[WRITECOUNT];
auto retval = WriteFileReturnError(FILENAME, buf, WRITECOUNT, 0);
char *buf = new char[WRITECOUNT.value()];
auto retval = WriteFileReturnError(FILENAME, buf, WRITECOUNT, fspp::num_bytes_t(0));
EXPECT_EQ(GetParam(), retval.error);
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.
// 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
size_t successfullyWrittenBytes = -1;
EXPECT_CALL(fsimpl, write(0, _, _, Eq(0)))
fspp::num_bytes_t successfullyWrittenBytes = fspp::num_bytes_t(-1);
EXPECT_CALL(fsimpl, write(0, _, _, Eq(fspp::num_bytes_t(0))))
.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
successfullyWrittenBytes = count;
}));
EXPECT_CALL(fsimpl, write(0, _, _, Ne(0)))
EXPECT_CALL(fsimpl, write(0, _, _, Ne(fspp::num_bytes_t(0))))
.WillRepeatedly(Throw(FuseErrnoException(GetParam())));
char *buf = new char[WRITECOUNT];
auto retval = WriteFileReturnError(FILENAME, buf, WRITECOUNT, 0);
char *buf = new char[WRITECOUNT.value()];
auto retval = WriteFileReturnError(FILENAME, buf, WRITECOUNT, fspp::num_bytes_t(0));
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
delete[] buf;

View File

@ -22,5 +22,5 @@ TEST_P(FuseWriteFileDescriptorTest, FileDescriptorIsCorrect) {
.Times(1).WillOnce(Return());
char buf[1];
WriteFile(FILENAME, buf, 1, 0);
WriteFile(FILENAME, buf, fspp::num_bytes_t(1), fspp::num_bytes_t(0));
}

View File

@ -15,44 +15,44 @@ using namespace fspp::fuse;
class FuseWriteOverflowTest: public FuseWriteTest {
public:
size_t FILESIZE;
size_t WRITESIZE;
size_t OFFSET;
fspp::num_bytes_t FILESIZE;
fspp::num_bytes_t WRITESIZE;
fspp::num_bytes_t OFFSET;
WriteableInMemoryFile testFile;
Data writeData;
FuseWriteOverflowTest(size_t filesize, size_t writesize, size_t offset)
: FILESIZE(filesize), WRITESIZE(writesize), OFFSET(offset), testFile(DataFixture::generate(FILESIZE)), writeData(DataFixture::generate(WRITESIZE)) {
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.value())), writeData(DataFixture::generate(WRITESIZE.value())) {
ReturnIsFileOnLstatWithSize(FILENAME, FILESIZE);
OnOpenReturnFileDescriptor(FILENAME, 0);
EXPECT_CALL(fsimpl, write(0, _, _, _)).WillRepeatedly(WriteToFile);
}
// 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);
});
};
class FuseWriteOverflowTestWithNonemptyFile: public FuseWriteOverflowTest {
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) {
WriteFile(FILENAME, writeData.data(), WRITESIZE, 0);
WriteFile(FILENAME, writeData.data(), WRITESIZE, fspp::num_bytes_t(0));
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) {
WriteFile(FILENAME, writeData.data(), WRITESIZE, OFFSET);
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));
}
@ -60,20 +60,20 @@ TEST_F(FuseWriteOverflowTestWithNonemptyFile, WriteAfterFileEnd) {
WriteFile(FILENAME, writeData.data(), WRITESIZE, FILESIZE + OFFSET);
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));
}
class FuseWriteOverflowTestWithEmptyFile: public FuseWriteOverflowTest {
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) {
WriteFile(FILENAME, writeData.data(), WRITESIZE, 0);
WriteFile(FILENAME, writeData.data(), WRITESIZE, fspp::num_bytes_t(0));
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) {

View File

@ -3,20 +3,20 @@
using cpputils::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);
EXPECT_EQ(0, retval.error);
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 fd = OpenFile(fs.get(), filename);
WriteError result{};
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;
return result;
}

View File

@ -11,11 +11,11 @@ public:
struct WriteError {
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);
WriteError WriteFileReturnError(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, fspp::num_bytes_t count, fspp::num_bytes_t offset);
private:
cpputils::unique_ref<OpenFileHandle> OpenFile(const TempTestFS *fs, const char *filename);

View File

@ -18,9 +18,9 @@ public:
~MockOpenFile() {destructed = true;}
MOCK_CONST_METHOD0(stat, OpenFile::stat_info());
MOCK_CONST_METHOD1(truncate, void(off_t));
MOCK_CONST_METHOD3(read, size_t(void*, size_t, off_t));
MOCK_METHOD3(write, void(const void*, size_t, off_t));
MOCK_CONST_METHOD1(truncate, void(fspp::num_bytes_t));
MOCK_CONST_METHOD3(read, fspp::num_bytes_t(void*, fspp::num_bytes_t, fspp::num_bytes_t));
MOCK_METHOD3(write, void(const void*, fspp::num_bytes_t, fspp::num_bytes_t));
MOCK_METHOD0(flush, void());
MOCK_METHOD0(fsync, void());
MOCK_METHOD0(fdatasync, void());

View File

@ -65,16 +65,16 @@ const bf::path &FuseTest::TempTestFS::mountDir() const {
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) {
result->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
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
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 =
Invoke([](int, struct ::stat* result) {
@ -82,12 +82,12 @@ Action<void(int, struct ::stat*)> FuseTest::ReturnIsFileFstat =
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) {
result->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH;
result->st_nlink = 1;
result->st_size = size;
std::cout << "Return size: " << size <<std::endl;
result->st_size = size.value();
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);
}
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));
}
@ -123,6 +123,6 @@ void FuseTest::ReturnIsFileOnFstat(int descriptor) {
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));
}

View File

@ -48,10 +48,10 @@ public:
MOCK_METHOD1(closeFile, void(int));
MOCK_PATH_METHOD2(lstat, void, struct ::stat*);
MOCK_METHOD2(fstat, void(int, struct ::stat*));
MOCK_PATH_METHOD2(truncate, void, off_t);
MOCK_METHOD2(ftruncate, void(int, off_t));
MOCK_METHOD4(read, size_t(int, void*, size_t, off_t));
MOCK_METHOD4(write, void(int, const void*, size_t, off_t));
MOCK_PATH_METHOD2(truncate, void, fspp::num_bytes_t);
MOCK_METHOD2(ftruncate, void(int, fspp::num_bytes_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*, fspp::num_bytes_t, fspp::num_bytes_t));
MOCK_METHOD1(flush, void(int));
MOCK_METHOD1(fsync, void(int));
MOCK_METHOD1(fdatasync, void(int));
@ -79,7 +79,7 @@ public:
MOCK_PATH_METHOD2(chmod, void, mode_t);
MOCK_PATH_METHOD3(chown, void, 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 {
@ -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
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*)> 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*)> ReturnDoesntExist;
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 ReturnDoesntExistOnLstat(const boost::filesystem::path &path);
void OnOpenReturnFileDescriptor(const char *filename, int descriptor);
void ReturnIsFileOnFstat(int descriptor);
void ReturnIsFileOnFstatWithSize(int descriptor, const size_t size);
void ReturnIsFileOnFstatWithSize(int descriptor, fspp::num_bytes_t size);
};
#endif

View File

@ -8,9 +8,9 @@ InMemoryFile::InMemoryFile(Data data): _data(std::move(data)) {
InMemoryFile::~InMemoryFile() {
}
int InMemoryFile::read(void *buf, size_t count, off_t offset) const {
size_t realCount = std::min(count, static_cast<size_t>(_data.size() - offset));
std::memcpy(buf, _data.dataOffset(offset), realCount);
fspp::num_bytes_t InMemoryFile::read(void *buf, fspp::num_bytes_t count, fspp::num_bytes_t offset) const {
fspp::num_bytes_t realCount = std::min(count, fspp::num_bytes_t(_data.size()) - offset);
std::memcpy(buf, _data.dataOffset(offset.value()), realCount.value());
return realCount;
}
@ -18,31 +18,31 @@ const void *InMemoryFile::data() const {
return _data.data();
}
bool InMemoryFile::fileContentEquals(const Data &expected, off_t offset) const {
return 0 == std::memcmp(expected.data(), _data.dataOffset(offset), expected.size());
bool InMemoryFile::fileContentEquals(const Data &expected, fspp::num_bytes_t offset) const {
return 0 == std::memcmp(expected.data(), _data.dataOffset(offset.value()), expected.size());
}
size_t InMemoryFile::size() const {
return _data.size();
fspp::num_bytes_t InMemoryFile::size() const {
return fspp::num_bytes_t(_data.size());
}
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);
std::memcpy(_data.dataOffset(offset), buf, count);
std::memcpy(_data.dataOffset(offset.value()), buf, count.value());
}
void WriteableInMemoryFile::_extendFileSizeIfNecessary(size_t size) {
if (size > _data.size()) {
void WriteableInMemoryFile::_extendFileSizeIfNecessary(fspp::num_bytes_t size) {
if (size > fspp::num_bytes_t(_data.size())) {
_extendFileSize(size);
}
}
void WriteableInMemoryFile::_extendFileSize(size_t size) {
Data newfile(size);
void WriteableInMemoryFile::_extendFileSize(fspp::num_bytes_t size) {
Data newfile(size.value());
std::memcpy(newfile.data(), _data.data(), _data.size());
_data = std::move(newfile);
}
@ -51,6 +51,6 @@ bool WriteableInMemoryFile::sizeUnchanged() const {
return _data.size() == _originalData.size();
}
bool WriteableInMemoryFile::regionUnchanged(off_t offset, size_t count) const {
return 0 == std::memcmp(_data.dataOffset(offset), _originalData.dataOffset(offset), count);
bool WriteableInMemoryFile::regionUnchanged(fspp::num_bytes_t offset, fspp::num_bytes_t count) const {
return 0 == std::memcmp(_data.dataOffset(offset.value()), _originalData.dataOffset(offset.value()), count.value());
}

View File

@ -3,18 +3,19 @@
#define MESSMER_FSPP_TEST_TESTUTILS_INMEMORYFILE_H_
#include <cpp-utils/data/Data.h>
#include <fspp/fs_interface/Types.h>
class InMemoryFile {
public:
InMemoryFile(cpputils::Data data);
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;
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:
cpputils::Data _data;
@ -24,14 +25,14 @@ class WriteableInMemoryFile: public InMemoryFile {
public:
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 regionUnchanged(off_t offset, size_t count) const;
bool regionUnchanged(fspp::num_bytes_t offset, fspp::num_bytes_t count) const;
private:
void _extendFileSizeIfNecessary(size_t size);
void _extendFileSize(size_t size);
void _extendFileSizeIfNecessary(fspp::num_bytes_t size);
void _extendFileSize(fspp::num_bytes_t size);
cpputils::Data _originalData;
};