Introduce fspp::openflags_t
This commit is contained in:
parent
d1273677a5
commit
43ffff5900
@ -32,7 +32,7 @@ unique_ref<parallelaccessfsblobstore::FileBlobRef> CryFile::LoadBlob() const {
|
||||
return std::move(*file_blob);
|
||||
}
|
||||
|
||||
unique_ref<fspp::OpenFile> CryFile::open(int flags) {
|
||||
unique_ref<fspp::OpenFile> CryFile::open(fspp::openflags_t flags) {
|
||||
// TODO Should we honor open flags?
|
||||
UNUSED(flags);
|
||||
device()->callFsActionCallbacks();
|
||||
|
@ -14,7 +14,7 @@ public:
|
||||
CryFile(CryDevice *device, cpputils::unique_ref<parallelaccessfsblobstore::DirBlobRef> parent, boost::optional<cpputils::unique_ref<parallelaccessfsblobstore::DirBlobRef>> grandparent, const blockstore::BlockId &blockId);
|
||||
~CryFile();
|
||||
|
||||
cpputils::unique_ref<fspp::OpenFile> open(int flags) override;
|
||||
cpputils::unique_ref<fspp::OpenFile> open(fspp::openflags_t flags) override;
|
||||
void truncate(fspp::num_bytes_t size) override;
|
||||
fspp::Dir::EntryType getType() const override;
|
||||
void remove() override;
|
||||
|
@ -13,7 +13,7 @@ class File {
|
||||
public:
|
||||
virtual ~File() {}
|
||||
|
||||
virtual cpputils::unique_ref<OpenFile> open(int flags) = 0;
|
||||
virtual cpputils::unique_ref<OpenFile> open(fspp::openflags_t flags) = 0;
|
||||
virtual void truncate(fspp::num_bytes_t size) = 0;
|
||||
};
|
||||
|
||||
|
@ -130,6 +130,21 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
struct openflags_t final : cpputils::value_type::FlagsValueType<openflags_t, int> {
|
||||
// TODO Remove default constructor
|
||||
constexpr openflags_t() noexcept: FlagsValueType(0) {}
|
||||
|
||||
constexpr explicit openflags_t(int id) noexcept : FlagsValueType(id) {}
|
||||
|
||||
constexpr int value() const noexcept {
|
||||
return value_;
|
||||
}
|
||||
|
||||
static constexpr openflags_t RDONLY() { return openflags_t(0x0000); };
|
||||
static constexpr openflags_t WRONLY() { return openflags_t(0x0001); };
|
||||
static constexpr openflags_t RDWR() { return openflags_t(0x0002); };
|
||||
};
|
||||
|
||||
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) {}
|
||||
|
@ -12,15 +12,15 @@ template<class ConcreteFileSystemTestFixture>
|
||||
class FsppFileTest: public FileTest<ConcreteFileSystemTestFixture> {
|
||||
public:
|
||||
void Test_Open_RDONLY(fspp::File *file) {
|
||||
file->open(O_RDONLY);
|
||||
file->open(fspp::openflags_t::RDONLY());
|
||||
}
|
||||
|
||||
void Test_Open_WRONLY(fspp::File *file) {
|
||||
file->open(O_WRONLY);
|
||||
file->open(fspp::openflags_t::WRONLY());
|
||||
}
|
||||
|
||||
void Test_Open_RDWR(fspp::File *file) {
|
||||
file->open(O_RDONLY);
|
||||
file->open(fspp::openflags_t::RDONLY());
|
||||
}
|
||||
|
||||
void Test_Truncate_DontChange1(fspp::File *file, fspp::Node *node) {
|
||||
|
@ -19,7 +19,7 @@ TYPED_TEST_CASE_P(FsppFileTest_Timestamps);
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, open_nomode) {
|
||||
auto file = this->CreateFile("/myfile");
|
||||
auto operation = [&file] () {
|
||||
file->open(0);
|
||||
file->open(fspp::openflags_t(0));
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAnyTimestamps});
|
||||
}
|
||||
@ -27,7 +27,7 @@ TYPED_TEST_P(FsppFileTest_Timestamps, open_nomode) {
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, open_rdonly) {
|
||||
auto file = this->CreateFile("/myfile");
|
||||
auto operation = [&file] () {
|
||||
file->open(O_RDONLY);
|
||||
file->open(fspp::openflags_t::RDONLY());
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAnyTimestamps});
|
||||
}
|
||||
@ -35,7 +35,7 @@ TYPED_TEST_P(FsppFileTest_Timestamps, open_rdonly) {
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, open_wronly) {
|
||||
auto file = this->CreateFile("/myfile");
|
||||
auto operation = [&file] () {
|
||||
file->open(O_WRONLY);
|
||||
file->open(fspp::openflags_t::WRONLY());
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAnyTimestamps});
|
||||
}
|
||||
@ -43,7 +43,7 @@ TYPED_TEST_P(FsppFileTest_Timestamps, open_wronly) {
|
||||
TYPED_TEST_P(FsppFileTest_Timestamps, open_rdwr) {
|
||||
auto file = this->CreateFile("/myfile");
|
||||
auto operation = [&file] () {
|
||||
file->open(O_RDWR);
|
||||
file->open(fspp::openflags_t::RDWR());
|
||||
};
|
||||
this->EXPECT_OPERATION_UPDATES_TIMESTAMPS_AS("/myfile", operation, {this->ExpectDoesntUpdateAnyTimestamps});
|
||||
}
|
||||
|
@ -33,13 +33,13 @@ TYPED_TEST_CASE_P(FsppOpenFileTest);
|
||||
|
||||
TYPED_TEST_P(FsppOpenFileTest, CreatedFileIsEmpty) {
|
||||
auto file = this->CreateFile("/myfile");
|
||||
auto openFile = this->LoadFile("/myfile")->open(O_RDONLY);
|
||||
auto openFile = this->LoadFile("/myfile")->open(fspp::openflags_t::RDONLY());
|
||||
this->EXPECT_SIZE(fspp::num_bytes_t(0), openFile.get());
|
||||
}
|
||||
|
||||
TYPED_TEST_P(FsppOpenFileTest, FileIsFile) {
|
||||
auto file = this->CreateFile("/myfile");
|
||||
auto openFile = this->LoadFile("/myfile")->open(O_RDONLY);
|
||||
auto openFile = this->LoadFile("/myfile")->open(fspp::openflags_t::RDONLY());
|
||||
this->IN_STAT(openFile.get(), [] (const fspp::OpenFile::stat_info& st) {
|
||||
EXPECT_TRUE(st.mode.hasFileFlag());
|
||||
});
|
||||
|
@ -8,12 +8,12 @@ template<class ConcreteFileSystemTestFixture>
|
||||
class FsppOpenFileTest_Timestamps: public TimestampTestUtils<ConcreteFileSystemTestFixture> {
|
||||
public:
|
||||
cpputils::unique_ref<fspp::OpenFile> CreateAndOpenFile(const boost::filesystem::path &path) {
|
||||
return this->CreateFile(path)->open(O_RDWR);
|
||||
return this->CreateFile(path)->open(fspp::openflags_t::RDWR());
|
||||
}
|
||||
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);
|
||||
auto openFile = file->open(fspp::openflags_t::RDWR());
|
||||
assert(this->stat(*openFile).size == size);
|
||||
assert(this->stat(*this->Load(path)).size == size);
|
||||
return openFile;
|
||||
|
@ -31,7 +31,7 @@ public:
|
||||
void IN_STAT(fspp::File *file, fspp::Node *node, std::function<void (const fspp::Node::stat_info&)> callback) {
|
||||
auto st1 = node->stat();
|
||||
callback(st1);
|
||||
auto st2 = file->open(O_RDONLY)->stat();
|
||||
auto st2 = file->open(fspp::openflags_t::RDONLY())->stat();
|
||||
callback(st2);
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ public:
|
||||
}
|
||||
|
||||
void EXPECT_NUMBYTES_READABLE(fspp::num_bytes_t expectedSize, fspp::File *file) {
|
||||
auto openFile = file->open(O_RDONLY);
|
||||
auto openFile = file->open(fspp::openflags_t::RDONLY());
|
||||
cpputils::Data data(expectedSize.value());
|
||||
//Try to read one byte more than the expected size
|
||||
fspp::num_bytes_t readBytes = openFile->read(data.data(), expectedSize+fspp::num_bytes_t(1), fspp::num_bytes_t(0));
|
||||
|
@ -125,7 +125,7 @@ int FilesystemImpl::openFile(const bf::path &path, int flags) {
|
||||
|
||||
int FilesystemImpl::openFile(File *file, int flags) {
|
||||
PROFILE(_openFileNanosec);
|
||||
return _open_files.open(file->open(flags));
|
||||
return _open_files.open(file->open(fspp::openflags_t(flags)));
|
||||
}
|
||||
|
||||
void FilesystemImpl::flush(int descriptor) {
|
||||
|
Loading…
Reference in New Issue
Block a user