forked from ShawnZhong/MadFS
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwrite.cpp
38 lines (35 loc) · 1.2 KB
/
write.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
#include "lib.h"
#include "utils/timer.h"
namespace madfs {
extern "C" {
ssize_t write(int fd, const void* buf, size_t count) {
if (auto file = get_file(fd)) {
timer.start<Event::WRITE>(count);
ssize_t res = file->write(static_cast<const char*>(buf), count);
timer.stop<Event::WRITE>();
LOG_DEBUG("madfs::write(%s, buf, %zu) = %zu", file->path, count, res);
return res;
} else {
ssize_t res = posix::write(fd, buf, count);
LOG_DEBUG("posix::write(%d, buf, %zu) = %zu", fd, count, res);
return res;
}
}
ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) {
if (auto file = get_file(fd)) {
TimerGuard<Event::PWRITE> timer_guard(count);
ssize_t res = file->pwrite(static_cast<const char*>(buf), count,
static_cast<size_t>(offset));
LOG_DEBUG("madfs::pwrite(%s, buf, %zu, %zu) = %zu", file->path, count,
offset, res);
return res;
} else {
LOG_DEBUG("posix::pwrite(%d, buf, %zu, %ld)", fd, count, offset);
return posix::pwrite(fd, buf, count, offset);
}
}
ssize_t pwrite64(int fd, const void* buf, size_t count, off64_t offset) {
return pwrite(fd, buf, count, offset);
}
}
} // namespace madfs