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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
#include "fuseDirs.h"
#include <entCache.h>
#include <lockHelpers.h>
#include <numeric.h>
namespace NetFS {
FuseApp::OpenDir::OpenDir(DirectoryPrxPtr r, std::string p) : remote(std::move(r)), path(std::move(p)) { }
template<>
std::map<FuseApp::FuseHandleTypeId, FuseApp::OpenDirPtr> &
FuseApp::getMap<FuseApp::OpenDirPtr>()
{
return openDirs;
}
int
FuseApp::opendir(const char * p, struct fuse_file_info * fi)
{
try {
auto remote = volume->opendir(reqEnv(), p);
setProxy<OpenDirPtr>(fi->fh, remote, p);
return 0;
}
catch (SystemError & e) {
return -e.syserrno;
}
}
int
FuseApp::releasedir(const char *, struct fuse_file_info * fi)
{
try {
auto remote = getProxy<OpenDirPtr>(fi->fh)->remote;
remote->close();
clearProxy<OpenDirPtr>(fi->fh);
return 0;
}
catch (SystemError & e) {
clearProxy<OpenDirPtr>(fi->fh);
return -e.syserrno;
}
}
int
FuseApp::readdir(const char * p, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi,
enum fuse_readdir_flags flags)
{
try {
auto od = getProxy<OpenDirPtr>(fi->fh);
const std::filesystem::path path {p};
auto expiry = time(nullptr) + 2;
if (flags & FUSE_READDIR_PLUS) {
for (const auto & e : od->remote->listdir()) {
if (auto stat = converter.convert(e.second); stat.st_mode) {
filler(buf, e.first.c_str(), nullptr, 0, FUSE_FILL_DIR_PLUS);
const auto k {std::filesystem::hash_value(path / e.first)};
statCache.remove(k);
statCache.add(k, stat, expiry);
}
}
}
else {
// Standard read dir cannot know the local system cannot represent the inode
for (const auto & e : od->remote->readdir()) {
filler(buf, e.c_str(), nullptr, 0, fuse_fill_dir_flags {});
}
}
return 0;
}
catch (SystemError & e) {
return -e.syserrno;
}
}
int
FuseApp::mkdir(const char * p, mode_t m)
{
try {
volume->mkdir(reqEnv(), p, safe {m});
return 0;
}
catch (SystemError & e) {
return -e.syserrno;
}
}
int
FuseApp::rmdir(const char * p)
{
try {
volume->rmdir(reqEnv(), p);
return 0;
}
catch (SystemError & e) {
return -e.syserrno;
}
}
}
|