diff options
Diffstat (limited to 'netfs/daemonFiles.cpp')
-rw-r--r-- | netfs/daemonFiles.cpp | 68 |
1 files changed, 38 insertions, 30 deletions
diff --git a/netfs/daemonFiles.cpp b/netfs/daemonFiles.cpp index f447a20..826f7be 100644 --- a/netfs/daemonFiles.cpp +++ b/netfs/daemonFiles.cpp @@ -5,42 +5,44 @@ #include "daemonFiles.h" FileServer::FileServer(DaemonGlobalStatePtr dgs) : - DaemonModule(dgs), - fileNo(0) + DaemonModule(dgs) { } void -FileServer::truncate(const std::string & path, Ice::Long size, const Ice::Current&) +FileServer::truncate(Ice::Long tok, const std::string & path, Ice::Long size, const Ice::Current&) { + SessionPtr sess(dgs->getSession(tok)); errno = 0; - if (::truncate(path.c_str(), size) != 0) { + if (::truncate((sess->exportCfg->root / path).string().c_str(), size) != 0) { throw NetFSComms::SystemError(errno); } // s.replicatedRequest = true; } void -FileServer::ftruncate(Ice::Int id, Ice::Long size, const Ice::Current&) +FileServer::ftruncate(Ice::Long tok, Ice::Int id, Ice::Long size, const Ice::Current&) { - if (files.find(id) == files.end()) { + SessionPtr sess(dgs->getSession(tok)); + if (sess->files.find(id) == sess->files.end()) { throw NetFSComms::SystemError(EBADF); } errno = 0; - if (::ftruncate(files[id], size) != 0) { + if (::ftruncate(sess->files[id], size) != 0) { throw NetFSComms::SystemError(errno); } // s.replicatedRequest = true; } NetFSComms::Attr -FileServer::fgetattr(Ice::Int id, const Ice::Current &) +FileServer::fgetattr(Ice::Long tok, Ice::Int id, const Ice::Current &) { - if (files.find(id) == files.end()) { + SessionPtr sess(dgs->getSession(tok)); + if (sess->files.find(id) == sess->files.end()) { throw NetFSComms::SystemError(EBADF); } struct stat s; - if (::fstat(files[id], &s) != 0) { + if (::fstat(sess->files[id], &s) != 0) { throw NetFSComms::SystemError(errno); } NetFSComms::Attr a; @@ -61,65 +63,70 @@ FileServer::fgetattr(Ice::Int id, const Ice::Current &) } void -FileServer::unlink(const std::string & path, const Ice::Current&) +FileServer::unlink(Ice::Long tok, const std::string & path, const Ice::Current&) { + SessionPtr sess(dgs->getSession(tok)); errno = 0; - if (::unlink(path.c_str()) != 0) { + if (::unlink((sess->exportCfg->root / path).string().c_str()) != 0) { throw NetFSComms::SystemError(errno); } // s.replicatedRequest = true; } Ice::Int -FileServer::open(const std::string & path, Ice::Int flags, const Ice::Current&) +FileServer::open(Ice::Long tok, const std::string & path, Ice::Int flags, const Ice::Current&) { + SessionPtr sess(dgs->getSession(tok)); errno = 0; - int fd = ::open(path.c_str(), flags); + int fd = ::open((sess->exportCfg->root / path).string().c_str(), flags); if (fd == -1) { throw NetFSComms::SystemError(errno); } - files[++fileNo] = fd; + sess->files[++sess->fileNo] = fd; //s.replicatedRequest = true; - return fileNo; + return sess->fileNo; } Ice::Int -FileServer::create(const std::string & path, Ice::Int flags, Ice::Int mode, const Ice::Current&) +FileServer::create(Ice::Long tok, const std::string & path, Ice::Int flags, Ice::Int mode, const Ice::Current&) { + SessionPtr sess(dgs->getSession(tok)); errno = 0; - int fd = ::open(path.c_str(), O_CREAT | flags, mode); + int fd = ::open((sess->exportCfg->root / path).string().c_str(), O_CREAT | flags, mode); if (fd == -1) { throw NetFSComms::SystemError(errno); } - files[++fileNo] = fd; + sess->files[++sess->fileNo] = fd; //s.replicatedRequest = true; - return fileNo; + return sess->fileNo; } void -FileServer::close(Ice::Int id, const Ice::Current&) +FileServer::close(Ice::Long tok, Ice::Int id, const Ice::Current&) { - if (files.find(id) == files.end()) { + SessionPtr sess(dgs->getSession(tok)); + if (sess->files.find(id) == sess->files.end()) { throw NetFSComms::SystemError(EBADF); } errno = 0; - if (::close(files[id]) != 0) { + if (::close(sess->files[id]) != 0) { throw NetFSComms::SystemError(errno); } - files.erase(id); + sess->files.erase(id); // s.replicatedRequest = true; } NetFSComms::Buffer -FileServer::read(Ice::Int id, Ice::Long offset, Ice::Long size, const Ice::Current&) +FileServer::read(Ice::Long tok, Ice::Int id, Ice::Long offset, Ice::Long size, const Ice::Current&) { - if (files.find(id) == files.end()) { + SessionPtr sess(dgs->getSession(tok)); + if (sess->files.find(id) == sess->files.end()) { throw NetFSComms::SystemError(EBADF); } NetFSComms::Buffer buf; buf.resize(size); errno = 0; - int r = pread(files[id], &buf[0], size, offset); + int r = pread(sess->files[id], &buf[0], size, offset); if (r == -1) { throw NetFSComms::SystemError(errno); } @@ -130,13 +137,14 @@ FileServer::read(Ice::Int id, Ice::Long offset, Ice::Long size, const Ice::Curre } void -FileServer::write(Ice::Int id, Ice::Long offset, Ice::Long size, const NetFSComms::Buffer & data, const Ice::Current&) +FileServer::write(Ice::Long tok, Ice::Int id, Ice::Long offset, Ice::Long size, const NetFSComms::Buffer & data, const Ice::Current&) { - if (files.find(id) == files.end()) { + SessionPtr sess(dgs->getSession(tok)); + if (sess->files.find(id) == sess->files.end()) { throw NetFSComms::SystemError(EBADF); } errno = 0; - if (pwrite(files[id], &data[0], size, offset) != size) { + if (pwrite(sess->files[id], &data[0], size, offset) != size) { throw NetFSComms::SystemError(errno); } // s.replicatedRequest = true; |