-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCopyOpenFile.cpp
67 lines (53 loc) · 1.68 KB
/
CopyOpenFile.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "CopyDevice.h"
#include "CopyOpenFile.h"
#include <sys/types.h>
#include <fcntl.h>
#include "messmer/fspp/fuse/FuseErrnoException.h"
#include <messmer/cpp-utils/assert/assert.h>
namespace bf = boost::filesystem;
//TODO Get rid of this in favor of a exception hierarchy
using fspp::fuse::CHECK_RETVAL;
namespace copyfs {
CopyOpenFile::CopyOpenFile(const CopyDevice *device, const bf::path &path, int flags)
:_descriptor(::open((device->RootDir() / path).c_str(), flags)) {
CHECK_RETVAL(_descriptor);
}
CopyOpenFile::~CopyOpenFile() {
int retval = ::close(_descriptor);
CHECK_RETVAL(retval);
}
void CopyOpenFile::flush() {
}
void CopyOpenFile::stat(struct ::stat *result) const {
int retval = ::fstat(_descriptor, result);
CHECK_RETVAL(retval);
}
void CopyOpenFile::truncate(off_t size) const {
int retval = ::ftruncate(_descriptor, size);
CHECK_RETVAL(retval);
}
size_t CopyOpenFile::read(void *buf, size_t count, off_t offset) const {
int retval = ::pread(_descriptor, buf, count, offset);
CHECK_RETVAL(retval);
ASSERT(static_cast<unsigned int>(retval) <= count, "Read wrong number of bytes");
return retval;
}
void CopyOpenFile::write(const void *buf, size_t count, off_t offset) {
int retval = ::pwrite(_descriptor, buf, count, offset);
CHECK_RETVAL(retval);
ASSERT(static_cast<unsigned int>(retval) == count, "Wrong number of bytes written");
}
void CopyOpenFile::fsync() {
int retval = ::fsync(_descriptor);
CHECK_RETVAL(retval);
}
void CopyOpenFile::fdatasync() {
#ifdef F_FULLFSYNC
// This is MacOSX, which doesn't know fdatasync
int retval = fcntl(_descriptor, F_FULLFSYNC);
#else
int retval = ::fdatasync(_descriptor);
#endif
CHECK_RETVAL(retval);
}
}