2014-11-28 12:27:39 +01:00
|
|
|
#include "FuseFdatasyncTest.h"
|
2015-11-30 13:51:16 +01:00
|
|
|
#include <fcntl.h>
|
2014-11-28 12:27:39 +01:00
|
|
|
|
2017-08-25 01:14:16 +02:00
|
|
|
using cpputils::unique_ref;
|
|
|
|
using cpputils::make_unique_ref;
|
|
|
|
|
2014-11-28 12:27:39 +01:00
|
|
|
void FuseFdatasyncTest::FdatasyncFile(const char *filename) {
|
2014-12-06 15:33:01 +01:00
|
|
|
int error = FdatasyncFileReturnError(filename);
|
|
|
|
EXPECT_EQ(0, error);
|
2014-11-28 12:27:39 +01:00
|
|
|
}
|
|
|
|
|
2014-12-06 15:33:01 +01:00
|
|
|
int FuseFdatasyncTest::FdatasyncFileReturnError(const char *filename) {
|
2014-11-28 12:27:39 +01:00
|
|
|
auto fs = TestFS();
|
|
|
|
|
2017-08-25 01:14:16 +02:00
|
|
|
auto fd = OpenFile(fs.get(), filename);
|
2015-11-30 13:51:16 +01:00
|
|
|
#ifdef F_FULLFSYNC
|
|
|
|
// This is MacOSX, which doesn't know fdatasync
|
2017-08-25 01:14:16 +02:00
|
|
|
int retval = fcntl(fd->fd(), F_FULLFSYNC);
|
2015-11-30 13:51:16 +01:00
|
|
|
#else
|
2017-09-05 01:38:24 +02:00
|
|
|
int retval = ::fdatasync(fd->fd());
|
2015-11-30 13:51:16 +01:00
|
|
|
#endif
|
|
|
|
if (retval != -1) {
|
2014-12-06 15:33:01 +01:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return errno;
|
|
|
|
}
|
2014-11-28 12:27:39 +01:00
|
|
|
}
|
|
|
|
|
2017-08-25 01:14:16 +02:00
|
|
|
unique_ref<OpenFileHandle> FuseFdatasyncTest::OpenFile(const TempTestFS *fs, const char *filename) {
|
2014-11-28 12:27:39 +01:00
|
|
|
auto realpath = fs->mountDir() / filename;
|
2018-05-21 01:20:38 +02:00
|
|
|
auto fd = make_unique_ref<OpenFileHandle>(realpath.string().c_str(), O_RDWR);
|
2017-08-25 01:14:16 +02:00
|
|
|
EXPECT_GE(fd->fd(), 0) << "Error opening file";
|
2014-11-28 12:27:39 +01:00
|
|
|
return fd;
|
|
|
|
}
|