-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathread.cpp
56 lines (51 loc) · 1.68 KB
/
read.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
#include "lib.h"
#include "utils/timer.h"
namespace madfs {
extern "C" {
ssize_t read(int fd, void* buf, size_t count) {
if (auto file = get_file(fd)) {
timer.start<Event::READ>(count);
auto res = file->read(static_cast<char*>(buf), count);
LOG_DEBUG("madfs::read(%s, buf, %zu) = %zu", file->path, count, res);
timer.stop<Event::READ>();
return res;
} else {
auto res = posix::read(fd, buf, count);
LOG_DEBUG("posix::read(%d, buf, %zu) = %zu", fd, count, res);
return res;
}
}
ssize_t pread(int fd, void* buf, size_t count, off_t offset) {
if (auto file = get_file(fd)) {
timer.start<Event::PREAD>(count);
auto res = file->pread(static_cast<char*>(buf), count,
static_cast<size_t>(offset));
timer.stop<Event::PREAD>();
LOG_DEBUG("madfs::pread(%s, buf, %zu, %ld) = %zu", file->path, count,
offset, res);
return res;
} else {
auto res = posix::pread(fd, buf, count, offset);
LOG_DEBUG("posix::pread(%d, buf, %zu, %ld) = %zu", fd, count, offset, res);
return res;
}
}
ssize_t pread64(int fd, void* buf, size_t count, off64_t offset) {
return pread(fd, buf, count, offset);
}
ssize_t __read_chk(int fd, void* buf, size_t count,
[[maybe_unused]] size_t buflen) {
if (buflen >= count) {
LOG_WARN("__read_chk(%d, buf, %zu, %zu)", fd, count, buflen);
}
return read(fd, buf, count);
}
ssize_t __pread_chk(int fd, void* buf, size_t count, off_t offset,
[[maybe_unused]] size_t buflen) {
if (buflen >= count) {
LOG_WARN("__pread_chk(%d, buf, %zu, %ld, %zu)", fd, count, offset, buflen);
}
return pread(fd, buf, count, offset);
}
}
} // namespace madfs