summaryrefslogtreecommitdiff
path: root/netfs/daemonMisc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'netfs/daemonMisc.cpp')
-rw-r--r--netfs/daemonMisc.cpp168
1 files changed, 88 insertions, 80 deletions
diff --git a/netfs/daemonMisc.cpp b/netfs/daemonMisc.cpp
index 2341b21..5a30e31 100644
--- a/netfs/daemonMisc.cpp
+++ b/netfs/daemonMisc.cpp
@@ -1,120 +1,128 @@
#include <errno.h>
-#include <set>
+#include <map>
#include <unistd.h>
+#include <sys/stat.h>
#include <limits.h>
-#include "comms.h"
-#include "msgtypes.h"
-#include "daemon.h"
-#include "misc.h"
+#include "daemonMisc.h"
-extern std::map<int, int> files;
+extern std::map<Ice::Int, int> files;
-handler(AccessRequest)
+Ice::Int
+MiscServer::access(const std::string & path, Ice::Int mode, const Ice::Current &)
{
- TypedPayload<AccessRequest::Reply> * r = new TypedPayload<AccessRequest::Reply>();
- r->data.value = access(req->data.path.c_str(), req->data.access);
- s.Send(r);
+ return ::access(path.c_str(), mode);
}
-handler(GetAttrRequest)
+
+NetFSComms::Attr
+MiscServer::getattr(const std::string & path, const Ice::Current &)
{
- TypedPayload<GetAttrRequest::Reply> * r = new TypedPayload<GetAttrRequest::Reply>();
- errno = 0;
- r->data.res = stat(req->data.path.c_str(), &r->data.val);
- r->data.res = errno;
- s.Send(r);
+ 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;
}
-handler(FgetAttrRequest)
+
+NetFSComms::Attr
+MiscServer::fgetattr(Ice::Int id, const Ice::Current &)
{
- TypedPayload<FgetAttrRequest::Reply> * r = new TypedPayload<FgetAttrRequest::Reply>();
- errno = 0;
- if (files.find(req->data.handle) != files.end()) {
- fstat(files[req->data.handle], &r->data.val);
- r->data.res = errno;
+ if (files.find(id) == files.end()) {
+ throw NetFSComms::SystemError(EBADF);
}
- else {
- r->data.res = EBADF;
+ struct stat s;
+ if (::fstat(files[id], &s) != 0) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ 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;
}
-handler(SymlinkRequest)
+
+void
+MiscServer::symlink(const std::string & path1, const std::string & path2, const Ice::Current &)
{
- TypedPayload<SymlinkRequest::Reply> * r = new TypedPayload<SymlinkRequest::Reply>();
errno = 0;
- if (symlink(req->data.path1.c_str(), req->data.path2.c_str()) != 0) {
- r->data.value = errno;
- }
- else {
- r->data.value = 0;
- s.replicatedRequest = true;
+ if (::symlink(path1.c_str(), path2.c_str()) != 0) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ // s.replicatedRequest = true;
}
-handler(LinkRequest)
+
+void
+MiscServer::link(const std::string & path1, const std::string & path2, const Ice::Current &)
{
- TypedPayload<LinkRequest::Reply> * r = new TypedPayload<LinkRequest::Reply>();
errno = 0;
- if (link(req->data.path1.c_str(), req->data.path2.c_str()) != 0) {
- r->data.value = errno;
- }
- else {
- r->data.value = 0;
- s.replicatedRequest = true;
+ if (::link(path1.c_str(), path2.c_str()) != 0) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ // s.replicatedRequest = true;
}
-handler(RenameRequest)
+
+void
+MiscServer::rename(const std::string & from, const std::string & to, const Ice::Current &)
{
- TypedPayload<RenameRequest::Reply> * r = new TypedPayload<RenameRequest::Reply>();
errno = 0;
- if (rename(req->data.path1.c_str(), req->data.path2.c_str()) != 0) {
- r->data.value = errno;
- }
- else {
- r->data.value = 0;
- s.replicatedRequest = true;
+ if (::rename(from.c_str(), to.c_str()) != 0) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ // s.replicatedRequest = true;
}
-handler(ReadlinkRequest)
+
+std::string
+MiscServer::readlink(const std::string & path, const Ice::Current &)
{
- TypedPayload<ReadlinkRequest::Reply> * r = new TypedPayload<ReadlinkRequest::Reply>();
errno = 0;
char buf[PATH_MAX];
- ssize_t rc = readlink(req->data.path.c_str(), buf, PATH_MAX);
+ ssize_t rc = ::readlink(path.c_str(), buf, PATH_MAX);
if (rc == -1) {
- r->data.error = errno;
- }
- else {
- buf[rc] = '\0';
- r->data.path = buf;
- r->data.error = 0;
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ return std::string(buf, rc);
}
-handler(ChmodRequest)
+
+void
+MiscServer::chmod(const std::string & path, Ice::Int mode, const Ice::Current &)
{
- TypedPayload<ChmodRequest::Reply> * r = new TypedPayload<ChmodRequest::Reply>();
errno = 0;
- if (chmod(req->data.path.c_str(), req->data.mode) != 0) {
- r->data.value = errno;
- }
- else {
- r->data.value = 0;
- s.replicatedRequest = true;
+ if (::chmod(path.c_str(), mode) != 0) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ // s.replicatedRequest = true;
}
-handler(ChownRequest)
+
+void
+MiscServer::chown(const std::string & path, Ice::Int uid, Ice::Int gid, const Ice::Current &)
{
- TypedPayload<ChownRequest::Reply> * r = new TypedPayload<ChownRequest::Reply>();
errno = 0;
- if (chown(req->data.path.c_str(), req->data.user, req->data.group) != 0) {
- r->data.value = errno;
- }
- else {
- r->data.value = 0;
- s.replicatedRequest = true;
+ if (::chown(path.c_str(), uid, gid) != 0) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ // s.replicatedRequest = true;
}