summaryrefslogtreecommitdiff
path: root/netfs/daemon/daemonFile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'netfs/daemon/daemonFile.cpp')
-rw-r--r--netfs/daemon/daemonFile.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp
new file mode 100644
index 0000000..0b94787
--- /dev/null
+++ b/netfs/daemon/daemonFile.cpp
@@ -0,0 +1,75 @@
+#include "pch.hpp"
+#include <errno.h>
+#include <map>
+#include <fcntl.h>
+#include <typeConvert.h>
+#include <sys/stat.h>
+#include "daemonFile.h"
+
+FileServer::FileServer(int f) :
+ fd(f)
+{
+}
+
+FileServer::~FileServer()
+{
+}
+
+void
+FileServer::ftruncate(const NetFS::ReqEnv & re, Ice::Long size, const Ice::Current&)
+{
+ TempPrivs tp(re, &uentries, &gentries);
+ errno = 0;
+ if (::ftruncate(fd, size) != 0) {
+ throw NetFS::SystemError(errno);
+ }
+}
+
+NetFS::Attr
+FileServer::fgetattr(const NetFS::ReqEnv & re, const Ice::Current &)
+{
+ TempPrivs tp(re, &uentries, &gentries);
+ struct stat s;
+ if (::fstat(fd, &s) != 0) {
+ throw NetFS::SystemError(errno);
+ }
+ NetFS::Attr a;
+ a << StatSource { s, boost::bind(&UserEntCache::getName, &uentries, _1), boost::bind(&GroupEntCache::getName, &gentries, _1) };
+ return a;
+}
+
+void
+FileServer::close(const Ice::Current & ice)
+{
+ errno = 0;
+ if (::close(fd) != 0) {
+ throw NetFS::SystemError(errno);
+ }
+ ice.adapter->remove(ice.id);
+}
+
+NetFS::Buffer
+FileServer::read(Ice::Long offset, Ice::Long size, const Ice::Current&)
+{
+ NetFS::Buffer buf;
+ buf.resize(size);
+ errno = 0;
+ int r = pread(fd, &buf[0], size, offset);
+ if (r == -1) {
+ throw NetFS::SystemError(errno);
+ }
+ else if (r != size) {
+ buf.resize(r);
+ }
+ return buf;
+}
+
+void
+FileServer::write(Ice::Long offset, Ice::Long size, const NetFS::Buffer & data, const Ice::Current&)
+{
+ errno = 0;
+ if (pwrite(fd, &data.front(), size, offset) != size) {
+ throw NetFS::SystemError(errno);
+ }
+}
+