blob: 7533f614a900da67c39ae57d44f55fbf31ac778f (
plain)
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
|
#include <dirent.h>
#include <errno.h>
#include <map>
#include <sys/stat.h>
#include <sys/types.h>
#include "daemonDirs.h"
DirsServer::DirsServer(DaemonGlobalStatePtr dgs) :
DaemonModule(dgs)
{
}
Ice::Int
DirsServer::opendir(const NetFSComms::ReqEnv & re, const std::string & path, const Ice::Current&)
{
SessionPtr sess(dgs->getSession(re.tok));
errno = 0;
DIR * od = ::opendir((sess->exportCfg->root / path).string().c_str());
if (!od) {
throw NetFSComms::SystemError(errno);
}
sess->dirs[++sess->dirNo] = od;
//s.replicatedRequest = true;
return sess->dirNo;
}
void
DirsServer::closedir(Ice::Long tok, Ice::Int id, const Ice::Current&)
{
SessionPtr sess(dgs->getSession(tok));
if (sess->dirs.find(id) == sess->dirs.end()) {
throw NetFSComms::SystemError(EBADF);
}
errno = 0;
if (::closedir(sess->dirs[id]) != 0) {
throw NetFSComms::SystemError(errno);
}
sess->dirs.erase(id);
//s.replicatedRequest = true;
}
NetFSComms::NameList
DirsServer::readdir(Ice::Long tok, Ice::Int id, const Ice::Current&)
{
SessionPtr sess(dgs->getSession(tok));
if (sess->dirs.find(id) == sess->dirs.end()) {
throw NetFSComms::SystemError(EBADF);
}
errno = 0;
dirent * d;
NetFSComms::NameList list;
while ((d = ::readdir(sess->dirs[id]))) {
if (errno) {
throw NetFSComms::SystemError(errno);
}
list.push_back(d->d_name);
}
return list;
}
void
DirsServer::mkdir(const NetFSComms::ReqEnv & re, const std::string & path, Ice::Int mode, const Ice::Current&)
{
SessionPtr sess(dgs->getSession(re.tok));
errno = 0;
if (::mkdir((sess->exportCfg->root / path).string().c_str(), mode) != 0) {
throw NetFSComms::SystemError(errno);
}
// s.replicatedRequest = true;
}
void
DirsServer::rmdir(const NetFSComms::ReqEnv & re, const std::string & path, const Ice::Current&)
{
SessionPtr sess(dgs->getSession(re.tok));
errno = 0;
if (::rmdir((sess->exportCfg->root / path).string().c_str()) != 0) {
throw NetFSComms::SystemError(errno);
}
// s.replicatedRequest = true;
}
|