summaryrefslogtreecommitdiff
path: root/netfs/daemonMisc.cpp
blob: 9327fad8d3130c6a16b26ff838a81ff91f50488e (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <errno.h>
#include <map>
#include <unistd.h>
#include <sys/stat.h>
#include <limits.h>
#include "daemonMisc.h"

extern std::map<Ice::Int, int> files;

MiscServer::MiscServer(DaemonGlobalStatePtr dgs) :
	DaemonModule(dgs)
{
}

Ice::Int
MiscServer::access(const std::string & path, Ice::Int mode, const Ice::Current &)
{
	return ::access(path.c_str(), mode);
}

NetFSComms::Attr
MiscServer::getattr(const std::string & path, const Ice::Current &)
{
	struct stat s;
	if (::stat(path.c_str(), &s) != 0) {
		throw NetFSComms::SystemError(errno);
	}
	NetFSComms::Attr a;
	a.dev = s.st_dev;
	a.inode = s.st_ino;
	a.mode = s.st_mode;
	a.links = s.st_nlink;
	a.uid = s.st_uid;
	a.gid = s.st_gid;
	a.rdev = s.st_rdev;
	a.size = s.st_size;
	a.blockSize = s.st_blksize;
	a.blocks = s.st_blocks;
	a.atime = s.st_atime;
	a.mtime = s.st_mtime;
	a.ctime = s.st_ctime;
	return a;
}

void
MiscServer::symlink(const std::string & path1, const std::string & path2, const Ice::Current &)
{
	errno = 0;
	if (::symlink(path1.c_str(), path2.c_str()) != 0) {
		throw NetFSComms::SystemError(errno);
	}
	// s.replicatedRequest = true;
}

void
MiscServer::link(const std::string & path1, const std::string & path2, const Ice::Current &)
{
	errno = 0;
	if (::link(path1.c_str(), path2.c_str()) != 0) {
		throw NetFSComms::SystemError(errno);
	}
	// s.replicatedRequest = true;
}

void
MiscServer::rename(const std::string & from, const std::string & to, const Ice::Current &)
{
	errno = 0;
	if (::rename(from.c_str(), to.c_str()) != 0) {
		throw NetFSComms::SystemError(errno);
	}
	// s.replicatedRequest = true;
}

std::string
MiscServer::readlink(const std::string & path, const Ice::Current &)
{
	errno = 0;
	char buf[PATH_MAX];
	ssize_t rc = ::readlink(path.c_str(), buf, PATH_MAX);
	if (rc == -1) {
		throw NetFSComms::SystemError(errno);
	}
	return std::string(buf, rc);
}

void
MiscServer::chmod(const std::string & path, Ice::Int mode, const Ice::Current &)
{
	errno = 0;
	if (::chmod(path.c_str(), mode) != 0) {
		throw NetFSComms::SystemError(errno);
	}
	// s.replicatedRequest = true;
}

void
MiscServer::chown(const std::string & path, Ice::Int uid, Ice::Int gid, const Ice::Current &)
{
	errno = 0;
	if (::chown(path.c_str(), uid, gid) != 0) {
		throw NetFSComms::SystemError(errno);
	}
	// s.replicatedRequest = true;
}