diff options
Diffstat (limited to 'netfs/daemonMisc.cpp')
-rw-r--r-- | netfs/daemonMisc.cpp | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/netfs/daemonMisc.cpp b/netfs/daemonMisc.cpp new file mode 100644 index 0000000..e3cebc3 --- /dev/null +++ b/netfs/daemonMisc.cpp @@ -0,0 +1,108 @@ +#include <errno.h> +#include <set> +#include <unistd.h> +#include <limits.h> +#include "comms.h" +#include "msgtypes.h" +#include "daemon.h" +#include "misc.h" + +handler(AccessRequest) +{ + TypedPayload<AccessRequest::Reply> * r = new TypedPayload<AccessRequest::Reply>(); + r->data.value = access(req->data.path.c_str(), req->data.access); + s.Send(r); +} +handler(GetAttrRequest) +{ + 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); +} +handler(FgetAttrRequest) +{ + TypedPayload<FgetAttrRequest::Reply> * r = new TypedPayload<FgetAttrRequest::Reply>(); + errno = 0; + r->data.res = fstat(req->data.handle, &r->data.val); + r->data.res = errno; + s.Send(r); +} +handler(SymlinkRequest) +{ + 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.Send(r); +} +handler(LinkRequest) +{ + 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.Send(r); +} +handler(RenameRequest) +{ + 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.Send(r); +} +handler(ReadlinkRequest) +{ + 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); + if (rc == -1) { + r->data.error = errno; + } + else { + buf[rc] = '\0'; + r->data.path = buf; + r->data.error = 0; + } + s.Send(r); +} +handler(ChmodRequest) +{ + 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.Send(r); +} +handler(ChownRequest) +{ + 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.Send(r); +} + |