summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netfs/Jamfile.jam77
-rw-r--r--netfs/comms.cpp90
-rw-r--r--netfs/comms.h71
-rw-r--r--netfs/daemon.cpp256
-rw-r--r--netfs/daemon.h40
-rw-r--r--netfs/daemonDirs.cpp111
-rw-r--r--netfs/daemonDirs.h17
-rw-r--r--netfs/daemonFS.cpp20
-rw-r--r--netfs/daemonFiles.cpp170
-rw-r--r--netfs/daemonFiles.h21
-rw-r--r--netfs/daemonMisc.cpp168
-rw-r--r--netfs/daemonMisc.h20
-rw-r--r--netfs/daemonSystem.cpp28
-rw-r--r--netfs/daemonSystem.h12
-rw-r--r--netfs/fuse.cpp72
-rw-r--r--netfs/fuse.h80
-rw-r--r--netfs/fuseDirs.cpp67
-rw-r--r--netfs/fuseFS.cpp13
-rw-r--r--netfs/fuseFiles.cpp112
-rw-r--r--netfs/fuseMisc.cpp141
-rw-r--r--netfs/fuseSystem.cpp25
-rw-r--r--netfs/fusecallers.h4
-rw-r--r--netfs/msgtypes.cpp200
-rw-r--r--netfs/msgtypes.h348
-rw-r--r--netfs/netfsComms.ice76
-rw-r--r--netfs/xfers.h56
26 files changed, 788 insertions, 1507 deletions
diff --git a/netfs/Jamfile.jam b/netfs/Jamfile.jam
index e00fa16..1bd8c19 100644
--- a/netfs/Jamfile.jam
+++ b/netfs/Jamfile.jam
@@ -1,4 +1,6 @@
using gcc ;
+import type : register ;
+import generators : register-standard ;
alias libxmlpp : : : :
<cflags>"`pkg-config --cflags libxml++-2.6`"
@@ -9,25 +11,94 @@ alias fuse : : : :
lib boost_regex : : <name>boost_regex ;
lib boost_filesystem : : <name>boost_filesystem ;
+lib Ice : : <name>Ice ;
+
+import type ;
+import generators ;
+import feature ;
+import "class" : new ;
+import scanner ;
+type.register SLICE : ice ;
+class slice-scanner : scanner
+{
+ import path property-set regex scanner type virtual-target ;
+ rule __init__ ( includes * )
+ {
+ scanner.__init__ ;
+ self.includes = $(includes) ;
+ }
+ rule pattern ( )
+ {
+ return "^[ \t]*#[ \t]*include[ ]*(<(.*)>|\"(.*)\")" ;
+ }
+ rule process ( target : matches * : binding )
+ {
+ local included = [ regex.transform $(matches) : "\"(.*)\"" : 1 ] ;
+ local g = [ on $(target) return $(HDRGRIST) ] ;
+ local b = [ NORMALIZE_PATH $(binding:D) ] ;
+ local g2 = $(g)"#"$(b) ;
+ included = $(included:G=$(g2)) ;
+ #this seems to add the dependency ok to the tree, but
+ #I can't get these new dependencies to build
+ #I've seen virtual-target.register but I don't have access to properties
+ #and project names to do that here.
+ INCLUDES $(target) : $(included) ;
+ scanner.propagate $(__name__) : $(matches) : $(target) ;
+ }
+}
+scanner.register slice-scanner : include ;
+type.set-scanner SLICE : slice-scanner ;
+class slice-generator : generator
+{
+ import "class" : new ;
+ rule __init__ ( * : * )
+ {
+ generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
+ }
+ rule run ( project name ? : property-set : sources * )
+ {
+ #could I register new virtual targets here? The problem is I can't seem to
+ #be able to get the list of includes that the scanner built from anywhere
+ return [ generator.run $(project) $(name) : $(property-set) : $(sources) ] ;
+ }
+ rule generated-targets ( sources + : property-set : project name ? )
+ {
+ return [ generator.generated-targets $(sources) : $(property-set) : $(project) $(name) ] ;
+ }
+}
+generators.register [ new slice-generator slice.slice2cpp : SLICE : CPP H ] ;
+actions slice.slice2cpp
+{
+ slice2cpp --checksum --output-dir $(1[1]:D) $(2)
+}
+IMPORT $(__name__) : slice.slice2cpp : : slice.slice2cpp ;
+
+lib common :
+ netfsComms.ice :
+ <link>static
+ ;
exe netfs :
libxmlpp
- comms.cpp msgtypes.cpp
[ glob fuse*.cpp ]
../libmisc
:
<include>../libmisc/
+ <include>bin/gcc-4.4.4/debug/link-static/
+ <library>common
<library>boost_regex
<library>fuse
+ <library>Ice
;
exe netfsd :
libxmlpp
- comms.cpp msgtypes.cpp
[ glob daemon*.cpp ]
../libmisc
:
<include>../libmisc/
+ <include>bin/gcc-4.4.4/debug/link-static/
+ <library>common
<library>boost_regex
- <library>fuse
+ <library>Ice
;
diff --git a/netfs/comms.cpp b/netfs/comms.cpp
deleted file mode 100644
index 5993ac7..0000000
--- a/netfs/comms.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-#include <queue>
-#include <stdio.h>
-#include <string.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include "threads.h"
-#include "comms.h"
-#include "msgtypes.h"
-
-Semaphore outQueueSl(0);
-Semaphore outQueueSu(30);
-Semaphore inQueueS(0);
-Mutex outQueueM;
-Mutex inQueueM;
-std::queue<PacketPtr> outQueue;
-std::queue<PacketPtr> inQueue;
-
-Packet::Packet(uint8_t i, DataPayloadPtr p) :
- index(i),
- data(p)
-{
-}
-void
-sendPacket(PacketPtr p)
-{
- outQueueSu.wait();
- outQueueSl.post();
- AutoMutex am(outQueueM);
- outQueue.push(p);
-}
-
-void
-packetSender(FILE * host)
-{
- while (1) {
- outQueueSl.wait();
- AutoMutex am(outQueueM);
- // We can indicate an exit request by posting the semaphore without putting
- // anything in the queue
- if (outQueue.size() == 0) {
- break;
- }
- outQueue.front()->write(host);
- outQueueSu.post();
- }
-}
-
-Packet::Packet(FILE * host)
-{
- if (fread(&index, sizeof(index), 1, host) != 1) {
- throw ReadMessageFailed();
- }
- DataPayload::TypeID t = 0;
- if (fread(&t, sizeof(t), 1, host) != 1) {
- throw ReadMessageFailed();
- }
- data = MsgFacs()[t]();
- data->Read(host);
-}
-void
-Packet::write(FILE * host) const
-{
- if (fwrite(&index, sizeof(index), 1, host) != 1) {
- throw WriteMessageFailed();
- }
- DataPayload::TypeID t = data->dataTypeID();
- if (fwrite(&t, sizeof(t), 1, host) != 1) {
- throw WriteMessageFailed();
- }
- data->Send(host);
- if (fflush(host) != 0) {
- throw WriteMessageFailed();
- }
-}
-
-PacketPtr
-recvPacket()
-{
- inQueueS.wait();
- AutoMutex am(inQueueM);
- PacketPtr rtn = inQueue.front();
- inQueue.pop();
- return rtn;
-}
-
-ContentBase::~ContentBase()
-{
-}
-
diff --git a/netfs/comms.h b/netfs/comms.h
deleted file mode 100644
index cd25a9e..0000000
--- a/netfs/comms.h
+++ /dev/null
@@ -1,71 +0,0 @@
-#ifndef COMMS_H
-#define COMMS_H
-
-#include <stdio.h>
-#include <stdint.h>
-#include "smartpointer.h"
-#include "fuseapp.h"
-
-class WriteMessageFailed : std::exception {
-};
-class ReadMessageFailed : std::exception {
-};
-class DataPayload : public IsRefCounted {
- public:
- typedef uint16_t TypeID;
-
- virtual TypeID dataTypeID() const = 0;
- virtual void Send(FILE *) const = 0;
- virtual void Read(FILE *) = 0;
-};
-class NetFS;
-template <class Type>
-class TypedPayload : public DataPayload {
- public:
- typedef SmartPointer<TypedPayload<Type> > Ptr;
- Type data;
- TypeID dataTypeID() const { return Type::TypeID; }
- void Send(FILE * h) const { data.Send(h); }
- void Read(FILE * h) { data.Read(h); }
-};
-typedef SmartPointer<DataPayload> DataPayloadPtr;
-typedef SmartPointer<const DataPayload> DataPayloadCPtr;
-
-template <class Type>
-class TypedPayloadReq : public TypedPayload<Type> {
- public:
- typedef typename Type::Reply Reply;
- typedef SmartPointer<TypedPayloadReq<Type> > Ptr;
- typedef SmartPointer<TypedPayload<Reply> > ReplyPtr;
- TypedPayloadReq(fuse_context * fc)
- {
- TypedPayload<Type>::data.uid = fc->uid;
- TypedPayload<Type>::data.gid = fc->gid;
- }
- ReplyPtr exchange(NetFS * net);
- /*
- {
- DataPayloadPtr p = net->exchange(this);
- return p.as<TypedPayload<typename Type::Reply> >();
- }
- */
-};
-
-
-class Packet : public IsRefCounted {
- public:
- Packet(FILE *);
- Packet(uint8_t i, DataPayloadPtr p);
-
- void write(FILE *) const;
-
- uint8_t index;
- DataPayloadPtr data;
-};
-typedef SmartPointer<Packet> PacketPtr;
-
-void
-sendPacket(PacketPtr p);
-
-#endif
-
diff --git a/netfs/daemon.cpp b/netfs/daemon.cpp
index 691b681..314479a 100644
--- a/netfs/daemon.cpp
+++ b/netfs/daemon.cpp
@@ -1,239 +1,45 @@
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <signal.h>
-#include <errno.h>
-#include <string.h>
-#include <set>
-#include "daemonConfig.h"
-#include "comms.h"
-#include "msgtypes.h"
-#include "misc.h"
+#include <Ice/Ice.h>
#include "daemon.h"
+#include "daemonConfig.h"
+#include "daemonDirs.h"
+#include "daemonFiles.h"
+#include "daemonMisc.h"
+#include "daemonSystem.h"
-Sender::Sender(int i, FILE * f) :
- replicatedRequest(false),
- idx(i),
- host(f)
-{
-}
-void Sender::Send(DataPayloadPtr p)
-{
- PacketPtr r = new Packet(idx, p);
- r->write(host);
-}
-
-class TempUserChange {
- public:
- TempUserChange(uid_t u, gid_t g) :
- ogid(getegid()),
- ouid(geteuid())
- {
- errno = 0;
- setegid(g);
- seteuid(u);
- }
- ~TempUserChange()
- {
- setegid(ogid);
- seteuid(ouid);
- }
- private:
- gid_t ogid;
- uid_t ouid;
-};
-
-#define TRYCLASS(cls) \
- if (type == cls::TypeID) { \
- TypedPayload<cls>::Ptr tp = p->data.as<TypedPayload<cls> >(); \
- TempUserChange tuc(tp->data.uid, tp->data.gid); \
- handle(tp, s); \
- }
-
-void
-runDaemonOn(FILE * f, DaemonGlobalStatePtr)
+int main(int argc, char* argv[])
{
- PacketPtr p = new Packet(f);
- Sender s(p->index, f);
- uint16_t type (p->data->dataTypeID());
- // Dirs
- TRYCLASS(OpenDirRequest);
- TRYCLASS(CloseDirRequest);
- TRYCLASS(ReadDirRequest);
- TRYCLASS(RmDirRequest);
- TRYCLASS(MkDirRequest);
- // Misc
- TRYCLASS(AccessRequest);
- TRYCLASS(GetAttrRequest);
- TRYCLASS(FgetAttrRequest);
- TRYCLASS(UnlinkRequest);
- TRYCLASS(SymlinkRequest);
- TRYCLASS(LinkRequest);
- TRYCLASS(RenameRequest);
- TRYCLASS(ReadlinkRequest);
- TRYCLASS(ChmodRequest);
- TRYCLASS(ChownRequest);
- // Files
- TRYCLASS(OpenRequest);
- TRYCLASS(CloseRequest);
- TRYCLASS(ReadRequest);
- TRYCLASS(WriteRequest);
- TRYCLASS(TruncateRequest);
- TRYCLASS(FtruncateRequest);
- TRYCLASS(CreateRequest);
- // FS
- TRYCLASS(StatfsRequest);
+ DaemonConfigPtr dc = DaemonConfig::Load("daemon.xml");
+ DaemonGlobalStatePtr dgs = new DaemonGlobalState(dc);
- if (s.replicatedRequest) {
+ Ice::CommunicatorPtr ic;
+ try {
+ ic = Ice::initialize(argc, argv);
+ Ice::ObjectAdapterPtr adapter = ic->createObjectAdapterWithEndpoints("NetFSDaemonAdapter", "default -p 10000");
+ adapter->add(new FileServer(), ic->stringToIdentity("Files"));
+ adapter->add(new DirsServer(), ic->stringToIdentity("Dirs"));
+ adapter->add(new MiscServer(), ic->stringToIdentity("Misc"));
+ adapter->add(new SystemServer(), ic->stringToIdentity("System"));
+ adapter->activate();
+ ic->waitForShutdown();
}
-}
-typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
-
-bool running = true;
-void onsigint(int, siginfo_t *, void *)
-{
- running = false;
-}
-
-void setsignal(int sig, sa_sigaction_t f)
-{
- struct sigaction act;
- memset(&act, 0, sizeof(struct sigaction));
- act.sa_sigaction = f;
- sigaction(sig, &act, NULL);
-}
-
-class SocketEventHandler : public IsRefCounted {
- public:
- SocketEventHandler(int sock) : socket(sock) { }
- virtual void onRead() { }
- virtual void onWrite() { }
- virtual void onError() { }
-
- const int socket;
-};
-typedef SmartPointer<SocketEventHandler> SockEvHdlrPtr;
-typedef std::map<int, SockEvHdlrPtr> SocketSet;
-
-class IncomingPacketHandler : public SocketEventHandler {
- public:
- IncomingPacketHandler(int sock, DaemonGlobalStatePtr d) : SocketEventHandler(sock), dgs(d)
- {
- f = fdopen(sock, "a+");
- }
- void onRead()
- {
- runDaemonOn(f, dgs);
- }
- void onError()
- {
- }
- private:
- FILE * f;
- DaemonGlobalStatePtr dgs;
-};
-class ListenAcceptHandler : public SocketEventHandler {
- public:
- ListenAcceptHandler(int sock, SocketSet & socks, DaemonGlobalStatePtr d) :
- SocketEventHandler(sock), sockets(socks), dgs(d)
- {
- }
- void onRead()
- {
- int fd = accept(socket, NULL, NULL);
- sockets[fd] = new IncomingPacketHandler(fd, dgs);
- }
- private:
- SocketSet & sockets;
- DaemonGlobalStatePtr dgs;
-};
-
-
-void
-createListeners(DaemonGlobalStatePtr dgs, SocketSet & lsocks)
-{
- struct addrinfo hints;
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = AI_PASSIVE;
- struct addrinfo *result, *rp;
- if (getaddrinfo(NULL, dgs->config->self->tcpPort.c_str(), &hints, &result) == 0) {
- for (rp = result; rp != NULL; rp = rp->ai_next) {
- int sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
- if (sfd == -1) {
- close(sfd);
- continue;
- }
- if (bind(sfd, rp->ai_addr, rp->ai_addrlen) != 0) {
- close(sfd);
- continue;
- }
- if (listen(sfd, 5)) {
- close(sfd);
- continue;
- }
- lsocks[sfd] = new ListenAcceptHandler(sfd, lsocks, dgs);
- }
+ catch (const Ice::Exception& e) {
+ std::cerr << e << std::endl;
+ return 1;
}
-}
-
-void
-listener(DaemonGlobalStatePtr dgs)
-{
- SocketSet socks;
- createListeners(dgs, socks);
- if (!socks.size()) {
- return;
+ catch (const char* msg) {
+ std::cerr << msg << std::endl;
+ return 1;
}
- while (running) {
- fd_set readSocks;
- fd_set errSocks;
- FD_ZERO(&readSocks);
- FD_ZERO(&errSocks);
- int maxfd = 0;
- foreach(SocketSet::const_iterator, socks, s) {
- FD_SET(s->first, &readSocks);
- FD_SET(s->first, &errSocks);
- maxfd = std::max(s->first, maxfd);
+ if (ic) {
+ try {
+ ic->destroy();
}
- struct timeval to = { 1, 0 };
- int rsel = select(maxfd + 1, &readSocks, NULL, &errSocks, &to);
- if (rsel) {
- std::set<int> toRemove;
- foreach(SocketSet::const_iterator, socks, s) {
- if (FD_ISSET(s->first, &errSocks)) {
- s->second->onError();
- close(s->first);
- toRemove.insert(s->second);
- }
- else {
- if (FD_ISSET(s->first, &readSocks)) {
- try {
- s->second->onRead();
- }
- catch (...) {
- }
- }
- }
- }
- foreach(std::set<int>::const_iterator, toRemove, s) {
- socks.erase(*s);
- }
+ catch (const Ice::Exception& e) {
+ std::cerr << e << std::endl;
+ return 1;
}
}
- foreach(SocketSet::const_iterator, socks, s) {
- close(s->first);
- }
-}
-
-int main(int, char* [])
-{
- DaemonConfigPtr dc = DaemonConfig::Load("daemon.xml");
- DaemonGlobalStatePtr dgs = new DaemonGlobalState(dc);
- setsignal(SIGINT, onsigint);
- listener(dgs);
return 0;
}
diff --git a/netfs/daemon.h b/netfs/daemon.h
index 6b57976..a34c586 100644
--- a/netfs/daemon.h
+++ b/netfs/daemon.h
@@ -1,9 +1,7 @@
#ifndef DAEMON_H
#define DAEMON_H
-#include "comms.h"
#include "daemonConfig.h"
-#include "msgtypes.h"
class DaemonGlobalState : public IsRefCounted {
public:
@@ -15,44 +13,6 @@ class DaemonGlobalState : public IsRefCounted {
const DaemonConfigPtr config;
};
typedef SmartPointer<DaemonGlobalState> DaemonGlobalStatePtr;
-class Sender {
- public:
- Sender(int i, FILE * f);
- void Send(DataPayloadPtr p);
- bool replicatedRequest;
- private:
- int idx;
- FILE * host;
-};
-
-#define handler(type) void handle(SmartPointer<TypedPayload<type> > req, Sender & s)
-// Dirs
-handler(OpenDirRequest);
-handler(CloseDirRequest);
-handler(ReadDirRequest);
-handler(RmDirRequest);
-handler(MkDirRequest);
-// Misc
-handler(AccessRequest);
-handler(GetAttrRequest);
-handler(FgetAttrRequest);
-handler(UnlinkRequest);
-handler(SymlinkRequest);
-handler(LinkRequest);
-handler(RenameRequest);
-handler(ReadlinkRequest);
-handler(ChmodRequest);
-handler(ChownRequest);
-// Files
-handler(OpenRequest);
-handler(CloseRequest);
-handler(ReadRequest);
-handler(WriteRequest);
-handler(TruncateRequest);
-handler(FtruncateRequest);
-handler(CreateRequest);
-// FS
-handler(StatfsRequest);
#endif
diff --git a/netfs/daemonDirs.cpp b/netfs/daemonDirs.cpp
index 17f9367..75ce7c9 100644
--- a/netfs/daemonDirs.cpp
+++ b/netfs/daemonDirs.cpp
@@ -1,80 +1,75 @@
#include <dirent.h>
#include <errno.h>
-#include <set>
-#include "comms.h"
-#include "msgtypes.h"
-#include "daemon.h"
-#include "misc.h"
+#include <map>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include "daemonDirs.h"
int dirNo = 0;
-std::map<int, DIR*> dirs;
-handler(OpenDirRequest)
+std::map<Ice::Int, DIR*> dirs;
+
+Ice::Int
+DirsServer::opendir(const std::string & path, const Ice::Current&)
{
- TypedPayload<OpenDirRequest::Reply> * r = new TypedPayload<OpenDirRequest::Reply>();
errno = 0;
- DIR * od = opendir(req->data.path.c_str());
- if (od) {
- dirs[++dirNo] = od;
- r->data.handle = dirNo;
- s.replicatedRequest = true;
+ DIR * od = ::opendir(path.c_str());
+ if (!od) {
+ throw NetFSComms::SystemError(errno);
}
- r->data.error = errno;
- s.Send(r);
+ dirs[++dirNo] = od;
+ //s.replicatedRequest = true;
+ return dirNo;
}
-handler(CloseDirRequest)
+
+void
+DirsServer::closedir(Ice::Int id, const Ice::Current&)
{
- TypedPayload<CloseDirRequest::Reply> * r = new TypedPayload<CloseDirRequest::Reply>();
- if (dirs.find(req->data.handle) != dirs.end()) {
- errno = 0;
- if (closedir(dirs[req->data.handle]) != 0) {
- r->data.error = errno;
- }
- else {
- dirs.erase(req->data.handle);
- }
- s.replicatedRequest = true;
+ if (dirs.find(id) == dirs.end()) {
+ throw NetFSComms::SystemError(EBADF);
}
- else {
- r->data.error = EBADF;
+ errno = 0;
+ if (::closedir(dirs[id]) != 0) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ dirs.erase(id);
+ //s.replicatedRequest = true;
}
-handler(ReadDirRequest)
+
+NetFSComms::NameList
+DirsServer::readdir(Ice::Int id, const Ice::Current&)
{
- TypedPayload<ReadDirRequest::Reply> * r = new TypedPayload<ReadDirRequest::Reply>();
- if (dirs.find(req->data.handle) != dirs.end()) {
- errno = 0;
- dirent * d;
- while ((d = readdir(dirs[req->data.handle])) && errno == 0) {
- r->data.entries.push_back(ReadDirReply::Entry());
- r->data.entries.back().path = d->d_name;
- stat("/", &r->data.entries.back().val);
- }
- r->data.error = errno;
- s.Send(r);
+ if (dirs.find(id) == dirs.end()) {
+ throw NetFSComms::SystemError(EBADF);
}
- else {
- r->data.error = EBADF;
- s.Send(r);
+ errno = 0;
+ dirent * d;
+ NetFSComms::NameList list;
+ while ((d = ::readdir(dirs[id]))) {
+ if (errno) {
+ throw NetFSComms::SystemError(errno);
+ }
+ list.push_back(d->d_name);
}
+ return list;
}
-handler(MkDirRequest)
+
+void
+DirsServer::mkdir(const std::string & path, Ice::Int mode, const Ice::Current&)
{
- TypedPayload<MkDirRequest::Reply> * r = new TypedPayload<MkDirRequest::Reply>();
errno = 0;
- mkdir(req->data.path.c_str(), req->data.mode);
- r->data.value = errno;
- if (errno == 0)
- s.replicatedRequest = true;
- s.Send(r);
+ if (::mkdir(path.c_str(), mode) != 0) {
+ throw NetFSComms::SystemError(errno);
+ }
+ // s.replicatedRequest = true;
}
-handler(RmDirRequest)
+
+void
+DirsServer::rmdir(const std::string & path, const Ice::Current&)
{
- TypedPayload<MkDirRequest::Reply> * r = new TypedPayload<MkDirRequest::Reply>();
errno = 0;
- rmdir(req->data.path.c_str());
- r->data.value = errno;
- if (errno == 0)
- s.replicatedRequest = true;
- s.Send(r);
+ if (::rmdir(path.c_str()) != 0) {
+ throw NetFSComms::SystemError(errno);
+ }
+ // s.replicatedRequest = true;
}
+
diff --git a/netfs/daemonDirs.h b/netfs/daemonDirs.h
new file mode 100644
index 0000000..8073583
--- /dev/null
+++ b/netfs/daemonDirs.h
@@ -0,0 +1,17 @@
+#ifndef DAEMONDIRS_H
+#define DAEMONDIRS_H
+
+#include "netfsComms.h"
+
+class DirsServer : public NetFSComms::Dirs {
+ public:
+ virtual Ice::Int opendir(const std::string & path, const Ice::Current&);
+ virtual void closedir(Ice::Int id, const Ice::Current&);
+ virtual NetFSComms::NameList readdir(Ice::Int id, const Ice::Current&);
+
+ virtual void mkdir(const std::string & path, Ice::Int id, const Ice::Current&);
+ virtual void rmdir(const std::string & path, const Ice::Current&);
+};
+
+#endif
+
diff --git a/netfs/daemonFS.cpp b/netfs/daemonFS.cpp
deleted file mode 100644
index f8220ea..0000000
--- a/netfs/daemonFS.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include <errno.h>
-#include <sys/vfs.h>
-#include "comms.h"
-#include "msgtypes.h"
-#include "daemon.h"
-#include "misc.h"
-
-handler(StatfsRequest)
-{
- TypedPayload<StatfsRequest::Reply> * r = new TypedPayload<StatfsRequest::Reply>();
- errno = 0;
- if (statvfs(req->data.path.c_str(), &r->data.statfs) != 0) {
- r->data.error = errno;
- }
- else {
- r->data.error = 0;
- }
- s.Send(r);
-}
-
diff --git a/netfs/daemonFiles.cpp b/netfs/daemonFiles.cpp
index eb274f0..31a48cf 100644
--- a/netfs/daemonFiles.cpp
+++ b/netfs/daemonFiles.cpp
@@ -1,125 +1,113 @@
#include <errno.h>
-#include <set>
-#include "comms.h"
-#include "msgtypes.h"
-#include "daemon.h"
-#include "misc.h"
+#include <map>
+#include <fcntl.h>
+#include "daemonFiles.h"
-handler(TruncateRequest)
+int fileNo = 0;
+std::map<Ice::Int, int> files;
+
+void
+FileServer::truncate(const std::string & path, Ice::Long size, const Ice::Current&)
{
- TypedPayload<TruncateRequest::Reply> * r = new TypedPayload<TruncateRequest::Reply>();
errno = 0;
- if (truncate(req->data.path.c_str(), req->data.size) != 0) {
- r->data.value = errno;
- }
- else {
- r->data.value = 0;
- s.replicatedRequest = true;
+ if (::truncate(path.c_str(), size) != 0) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ // s.replicatedRequest = true;
}
-handler(FtruncateRequest)
+
+void
+FileServer::ftruncate(Ice::Int id, Ice::Long size, const Ice::Current&)
{
- TypedPayload<FtruncateRequest::Reply> * r = new TypedPayload<FtruncateRequest::Reply>();
- errno = 0;
- if (ftruncate(req->data.handle, req->data.size) != 0) {
- r->data.value = errno;
+ if (files.find(id) == files.end()) {
+ throw NetFSComms::SystemError(EBADF);
}
- else {
- r->data.value = 0;
- s.replicatedRequest = true;
+ errno = 0;
+ if (::ftruncate(files[id], size) != 0) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ // s.replicatedRequest = true;
}
-handler(UnlinkRequest)
+
+void
+FileServer::unlink(const std::string & path, const Ice::Current&)
{
- TypedPayload<UnlinkRequest::Reply> * r = new TypedPayload<UnlinkRequest::Reply>();
errno = 0;
- unlink(req->data.path.c_str());
- r->data.value = errno;
- if (errno == 0)
- s.replicatedRequest = true;
- s.Send(r);
+ if (::unlink(path.c_str()) != 0) {
+ throw NetFSComms::SystemError(errno);
+ }
+ // s.replicatedRequest = true;
}
-int fileNo = 0;
-std::map<int, int> files;
-handler(OpenRequest)
+
+Ice::Int
+FileServer::open(const std::string & path, Ice::Int flags, const Ice::Current&)
{
- TypedPayload<OpenRequest::Reply> * r = new TypedPayload<OpenRequest::Reply>();
errno = 0;
- int fd = open(req->data.path.c_str(), 0);
- if (fd != -1) {
- files[++fileNo] = fd;
- r->data.handle = fileNo;
- s.replicatedRequest = true;
+ int fd = ::open(path.c_str(), flags);
+ if (fd == -1) {
+ throw NetFSComms::SystemError(errno);
}
- r->data.error = errno;
- s.Send(r);
+ files[++fileNo] = fd;
+ //s.replicatedRequest = true;
+ return fileNo;
}
-handler(CreateRequest)
+
+Ice::Int
+FileServer::create(const std::string & path, Ice::Int flags, Ice::Int mode, const Ice::Current&)
{
- TypedPayload<OpenRequest::Reply> * r = new TypedPayload<OpenRequest::Reply>();
errno = 0;
- int fd = open(req->data.path.c_str(), O_CREAT, req->data.mode);
- if (fd != -1) {
- files[++fileNo] = fd;
- r->data.handle = fileNo;
- s.replicatedRequest = true;
+ int fd = ::open(path.c_str(), O_CREAT | flags, mode);
+ if (fd == -1) {
+ throw NetFSComms::SystemError(errno);
}
- r->data.error = errno;
- s.Send(r);
+ files[++fileNo] = fd;
+ //s.replicatedRequest = true;
+ return fileNo;
}
-handler(CloseRequest)
+
+void
+FileServer::close(Ice::Int id, const Ice::Current&)
{
- TypedPayload<CloseRequest::Reply> * r = new TypedPayload<CloseRequest::Reply>();
- if (files.find(req->data.handle) != files.end()) {
- errno = 0;
- if (close(files[req->data.handle]) == 0) {
- files.erase(req->data.handle);
- }
- r->data.error = errno;
- s.replicatedRequest = true;
+ if (files.find(id) == files.end()) {
+ throw NetFSComms::SystemError(EBADF);
}
- else {
- r->data.error = EBADF;
+ errno = 0;
+ if (::close(files[id]) != 0) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ files.erase(id);
+ // s.replicatedRequest = true;
}
-handler(ReadRequest)
+
+NetFSComms::Buffer
+FileServer::read(Ice::Int id, Ice::Long offset, Ice::Long size, const Ice::Current&)
{
- TypedPayload<ReadRequest::Reply> * r = new TypedPayload<ReadRequest::Reply>();
- if (files.find(req->data.handle) != files.end()) {
- char * tmpdata = new char[req->data.size]();
- errno = 0;
- int rs = pread(files[req->data.handle], tmpdata, req->data.size, req->data.offset);
- if (rs != -1) {
- r->data.data = tmpdata;
- r->data.size = rs;
- }
- else {
- r->data.size = 0;
- r->data.data = NULL;
- }
- r->data.error = errno;
+ if (files.find(id) == files.end()) {
+ throw NetFSComms::SystemError(EBADF);
}
- else {
- r->data.error = EBADF;
+ NetFSComms::Buffer buf;
+ buf.resize(size);
+ errno = 0;
+ int r = pread(files[id], &buf[0], size, offset);
+ if (r == -1) {
+ throw NetFSComms::SystemError(errno);
+ }
+ else if (r != size) {
+ buf.resize(r);
}
- s.Send(r);
+ return buf;
}
-handler(WriteRequest)
+
+void
+FileServer::write(Ice::Int id, Ice::Long offset, Ice::Long size, const NetFSComms::Buffer & data, const Ice::Current&)
{
- TypedPayload<WriteRequest::Reply> * r = new TypedPayload<WriteRequest::Reply>();
- if (files.find(req->data.handle) != files.end()) {
- errno = 0;
- if (pwrite(files[req->data.handle], req->data.data, req->data.size, req->data.offset) != -1) {
- s.replicatedRequest = true;
- }
- r->data.error = errno;
+ if (files.find(id) == files.end()) {
+ throw NetFSComms::SystemError(EBADF);
}
- else {
- r->data.error = EBADF;
+ errno = 0;
+ if (pwrite(files[id], &data[0], size, offset) != size) {
+ throw NetFSComms::SystemError(errno);
}
- s.Send(r);
+ // s.replicatedRequest = true;
}
diff --git a/netfs/daemonFiles.h b/netfs/daemonFiles.h
new file mode 100644
index 0000000..be24586
--- /dev/null
+++ b/netfs/daemonFiles.h
@@ -0,0 +1,21 @@
+#ifndef DAEMONFILES_H
+#define DAEMONFILES_H
+
+#include "netfsComms.h"
+
+class FileServer : public NetFSComms::Files {
+ public:
+ virtual void truncate(const std::string & path, Ice::Long size, const Ice::Current&);
+ virtual void ftruncate(Ice::Int id, Ice::Long size, const Ice::Current&);
+
+ virtual void unlink(const std::string & path, const Ice::Current&);
+
+ virtual Ice::Int open(const std::string & path, Ice::Int flags, const Ice::Current&);
+ virtual Ice::Int create(const std::string & path, Ice::Int flags, Ice::Int mode, const Ice::Current&);
+ virtual void close(Ice::Int id, const Ice::Current&);
+ virtual NetFSComms::Buffer read(Ice::Int id, Ice::Long offset, Ice::Long size, const Ice::Current&);
+ virtual void write(Ice::Int id, Ice::Long offset, Ice::Long size, const NetFSComms::Buffer & data, const Ice::Current&);
+};
+
+#endif
+
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;
}
diff --git a/netfs/daemonMisc.h b/netfs/daemonMisc.h
new file mode 100644
index 0000000..af36392
--- /dev/null
+++ b/netfs/daemonMisc.h
@@ -0,0 +1,20 @@
+#ifndef DAEMONMISC_H
+#define DAEMONMISC_H
+
+#include "netfsComms.h"
+
+class MiscServer : public NetFSComms::Misc {
+ public:
+ virtual Ice::Int access(const std::string & path, Ice::Int mode, const Ice::Current&);
+ virtual NetFSComms::Attr getattr(const std::string & path, const Ice::Current&);
+ virtual NetFSComms::Attr fgetattr(Ice::Int id, const Ice::Current&);
+ virtual void symlink(const std::string & path1, const std::string & path2, const Ice::Current&);
+ virtual void link(const std::string & path1, const std::string & path2, const Ice::Current&);
+ virtual void rename(const std::string & path1, const std::string & path2, const Ice::Current&);
+ virtual std::string readlink(const std::string & path, const Ice::Current&);
+ virtual void chmod(const std::string & path, Ice::Int mode, const Ice::Current&);
+ virtual void chown(const std::string & path, Ice::Int uid, Ice::Int gid, const Ice::Current&);
+};
+
+#endif
+
diff --git a/netfs/daemonSystem.cpp b/netfs/daemonSystem.cpp
new file mode 100644
index 0000000..74c9a57
--- /dev/null
+++ b/netfs/daemonSystem.cpp
@@ -0,0 +1,28 @@
+#include <errno.h>
+#include <sys/statvfs.h>
+#include <sys/vfs.h>
+#include "daemonSystem.h"
+
+NetFSComms::VFS
+SystemServer::statfs(const std::string & path, const Ice::Current&)
+{
+ errno = 0;
+ struct statvfs s;
+ if (::statvfs(path.c_str(), &s) != 0) {
+ throw NetFSComms::SystemError(errno);
+ }
+ NetFSComms::VFS t;
+ t.blockSize = s.f_bsize;
+ t.fragmentSize = s.f_frsize;
+ t.blocks = s.f_blocks;
+ t.freeBlocks = s.f_bfree;
+ t.availBlocks = s.f_bavail;
+ t.files = s.f_files;
+ t.freeFiles = s.f_ffree;
+ t.availFiles = s.f_favail;
+ t.FSID = s.f_fsid;
+ t.flags = s.f_flag;
+ t.maxNameLen = s.f_namemax;
+ return t;
+}
+
diff --git a/netfs/daemonSystem.h b/netfs/daemonSystem.h
new file mode 100644
index 0000000..0e2bedb
--- /dev/null
+++ b/netfs/daemonSystem.h
@@ -0,0 +1,12 @@
+#ifndef DAEMONSYSTEM_H
+#define DAEMONSYSTEM_H
+
+#include "netfsComms.h"
+
+class SystemServer : public NetFSComms::System {
+ public:
+ virtual NetFSComms::VFS statfs(const std::string & path, const Ice::Current&);
+};
+
+#endif
+
diff --git a/netfs/fuse.cpp b/netfs/fuse.cpp
index ceb5cb3..36ace17 100644
--- a/netfs/fuse.cpp
+++ b/netfs/fuse.cpp
@@ -69,63 +69,33 @@ static void fuseDestroy(void * x)
delete (App*)x;
}
-NetFS::NetFS() :
- f(NULL)
+NetFS::NetFS(int & argc, char ** argv) :
+ ic(Ice::initialize(argc, argv))
{
-}
-void
-NetFS::connect()
-{
- while (!f) {
- struct addrinfo hints;
- memset(&hints, 0, sizeof(struct addrinfo));
- hints.ai_family = AF_UNSPEC;
- hints.ai_socktype = SOCK_STREAM;
- hints.ai_flags = AI_PASSIVE;
- struct addrinfo *result, *rp;
- if (getaddrinfo("localhost", "4000", &hints, &result) == 0) {
- for (rp = result; rp != NULL; rp = rp->ai_next) {
- int sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
- if (sfd == -1)
- // Error
- continue;
- if (::connect(sfd, rp->ai_addr, rp->ai_addrlen)) {
- // Error
- continue;
- }
- f = fdopen(sfd, "a+");
- break;
- }
- }
- sleep(5);
+ files = NetFSComms::FilesPrx::checkedCast(ic->stringToProxy("Files:default -p 10000"));
+ if (!files) {
+ throw "Invalid files proxy";
+ }
+ dirs = NetFSComms::DirsPrx::checkedCast(ic->stringToProxy("Dirs:default -p 10000"));
+ if (!dirs) {
+ throw "Invalid directories proxy";
+ }
+ misc = NetFSComms::MiscPrx::checkedCast(ic->stringToProxy("Misc:default -p 10000"));
+ if (!misc) {
+ throw "Invalid misc proxy";
+ }
+ system = NetFSComms::SystemPrx::checkedCast(ic->stringToProxy("System:default -p 10000"));
+ if (!files) {
+ throw "Invalid system proxy";
}
}
+
NetFS::~NetFS()
{
- if (f) {
- fclose(f);
+ if (ic) {
+ ic->destroy();
}
}
-DataPayloadPtr
-NetFS::exchange(DataPayloadPtr dp)
-{
- AutoMutex a(comms);
- PacketPtr recvd;
- PacketPtr sendme = new Packet(0, dp);
- connect();
- while (true) {
- try {
- sendme->write(f);
- recvd = new Packet(f);
- return recvd->data;
- }
- catch (...) {
- f = NULL;
- connect();
- }
- }
- return NULL;
-}
template <class FuseApp>
int runFuseApp(int argc, char* argv[])
@@ -134,7 +104,7 @@ int runFuseApp(int argc, char* argv[])
{ NULL, 0, 0 }
};
- fuseApp = new FuseApp();
+ fuseApp = new FuseApp(argc, argv);
struct fuse_operations operations = {
fuseCall<const char *, struct stat *, &FuseAppBase::getattr>,
fuseCall<const char *, char *, size_t, &FuseAppBase::readlink>,
diff --git a/netfs/fuse.h b/netfs/fuse.h
index f587da4..74374d5 100644
--- a/netfs/fuse.h
+++ b/netfs/fuse.h
@@ -1,55 +1,51 @@
#ifndef FUSE_H
#define FUSE_H
+#include <Ice/Ice.h>
+#include "netfsComms.h"
#include "fuseapp.h"
-#include "comms.h"
-#include "threads.h"
class NetFS : public FuseAppBase
{
- // misc
- int access(const char * p, int a);
- int getattr(const char * p, struct stat * s);
- int fgetattr(const char *, struct stat *, struct fuse_file_info *);
- int chmod(const char *, mode_t);
- int chown(const char *, uid_t, gid_t);
- int link(const char *, const char *);
- int readlink(const char *, char *, size_t);
- int rename(const char *, const char *);
- int symlink(const char *, const char *);
- int unlink(const char *);
- // dirs
- int opendir(const char * p, struct fuse_file_info * fi);
- int releasedir(const char *, struct fuse_file_info * fi);
- int readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi);
- int mkdir(const char *, mode_t);
- int rmdir(const char *);
- // files
- int open(const char * p, struct fuse_file_info * fi);
- int create(const char *, mode_t, struct fuse_file_info *);
- int release(const char *, struct fuse_file_info * fi);
- int read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi);
- int write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi);
- int truncate(const char *, off_t);
- int ftruncate(const char *, off_t, struct fuse_file_info *);
- // fs
- int statfs(const char *, struct statvfs *);
- // stuff
public:
- NetFS();
+ NetFS(int & argc, char ** argv);
~NetFS();
- DataPayloadPtr exchange(DataPayloadPtr dp);
private:
- FILE * f;
- void connect();
- Mutex comms;
+ // misc
+ int access(const char * p, int a);
+ int getattr(const char * p, struct stat * s);
+ int fgetattr(const char *, struct stat *, struct fuse_file_info *);
+ int chmod(const char *, mode_t);
+ int chown(const char *, uid_t, gid_t);
+ int link(const char *, const char *);
+ int readlink(const char *, char *, size_t);
+ int rename(const char *, const char *);
+ int symlink(const char *, const char *);
+ int unlink(const char *);
+ // dirs
+ int opendir(const char * p, struct fuse_file_info * fi);
+ int releasedir(const char *, struct fuse_file_info * fi);
+ int readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi);
+ int mkdir(const char *, mode_t);
+ int rmdir(const char *);
+ // files
+ int open(const char * p, struct fuse_file_info * fi);
+ int create(const char *, mode_t, struct fuse_file_info *);
+ int release(const char *, struct fuse_file_info * fi);
+ int read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi);
+ int write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi);
+ int truncate(const char *, off_t);
+ int ftruncate(const char *, off_t, struct fuse_file_info *);
+ // fs
+ int statfs(const char *, struct statvfs *);
+ // stuff
+
+ Ice::CommunicatorPtr ic;
+
+ NetFSComms::FilesPrx files;
+ NetFSComms::DirsPrx dirs;
+ NetFSComms::MiscPrx misc;
+ NetFSComms::SystemPrx system;
};
-// this needs to go here to avoid circular includes regarding the net->exchange call
-template<class X>
-SmartPointer<TypedPayload<typename X::Reply> > TypedPayloadReq<X>::exchange(NetFS * net)
-{
- DataPayloadPtr p = net->exchange(this);
- return p.as<TypedPayload<typename X::Reply> >();
-}
#endif
diff --git a/netfs/fuseDirs.cpp b/netfs/fuseDirs.cpp
index f756393..846f1de 100644
--- a/netfs/fuseDirs.cpp
+++ b/netfs/fuseDirs.cpp
@@ -1,47 +1,64 @@
#include "fuse.h"
-#include "msgtypes.h"
#include "misc.h"
int
NetFS::opendir(const char * p, struct fuse_file_info * fi)
{
- TypedPayloadReq<OpenDirRequest>::Ptr msg = new TypedPayloadReq<OpenDirRequest>(fuse_get_context());
- msg->data.path = p;
- TypedPayload<OpenDirReply>::Ptr rep = msg->exchange(this);
- fi->fh = rep->data.handle;
- return -rep->data.error;
+ try {
+ fi->fh = dirs->opendir(p);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::releasedir(const char *, struct fuse_file_info * fi)
{
- TypedPayloadReq<CloseDirRequest>::Ptr msg = new TypedPayloadReq<CloseDirRequest>(fuse_get_context());
- msg->data.handle = fi->fh;
- TypedPayload<CloseDirReply>::Ptr rep = msg->exchange(this);
- return -rep->data.error;
+ try {
+ dirs->closedir(fi->fh);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::readdir(const char *, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi)
{
- TypedPayloadReq<ReadDirRequest>::Ptr msg = new TypedPayloadReq<ReadDirRequest>(fuse_get_context());
- msg->data.handle = fi->fh;
- TypedPayload<ReadDirReply>::Ptr rep = msg->exchange(this);
- foreach (std::vector<ReadDirReply::Entry>::const_iterator, rep->data.entries, e) {
- filler(buf, e->path.c_str(), &e->val, 0);
+ try {
+ NetFSComms::NameList ds = dirs->readdir(fi->fh);
+ for (NetFSComms::NameList::const_iterator e = ds.begin(); e != ds.end(); e++) {
+ filler(buf, e->c_str(), NULL, 0);
+ }
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
}
- return -rep->data.error;
}
+
int
-NetFS::mkdir(const char * d, mode_t m)
+NetFS::mkdir(const char * p, mode_t m)
{
- TypedPayloadReq<MkDirRequest>::Ptr msg = new TypedPayloadReq<MkDirRequest>(fuse_get_context());
- msg->data.path = d;
- msg->data.mode = m;
- return -msg->exchange(this)->data.value;
+ try {
+ dirs->mkdir(p, m);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
int
-NetFS::rmdir(const char * d)
+NetFS::rmdir(const char * p)
{
- TypedPayloadReq<RmDirRequest>::Ptr msg = new TypedPayloadReq<RmDirRequest>(fuse_get_context());
- msg->data.path = d;
- return -msg->exchange(this)->data.value;
+ try {
+ dirs->rmdir(p);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
diff --git a/netfs/fuseFS.cpp b/netfs/fuseFS.cpp
deleted file mode 100644
index ab27044..0000000
--- a/netfs/fuseFS.cpp
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "fuse.h"
-#include "msgtypes.h"
-
-int
-NetFS::statfs(const char * p, struct statvfs * vfs)
-{
- TypedPayloadReq<StatfsRequest>::Ptr msg = new TypedPayloadReq<StatfsRequest>(fuse_get_context());
- msg->data.path = p;
- TypedPayload<StatfsReply>::Ptr rep = msg->exchange(this);
- *vfs = rep->data.statfs;
- return -rep->data.error;
-}
-
diff --git a/netfs/fuseFiles.cpp b/netfs/fuseFiles.cpp
index 9343bcf..8cb96b3 100644
--- a/netfs/fuseFiles.cpp
+++ b/netfs/fuseFiles.cpp
@@ -1,75 +1,103 @@
#include <string.h>
#include "fuse.h"
-#include "msgtypes.h"
int
NetFS::open(const char * p, struct fuse_file_info * fi)
{
- TypedPayloadReq<OpenRequest>::Ptr msg = new TypedPayloadReq<OpenRequest>(fuse_get_context());
- msg->data.path = p;
- TypedPayload<OpenReply>::Ptr rep = msg->exchange(this);
- fi->fh = rep->data.handle;
- return -rep->data.error;
+ try {
+ fi->fh = files->open(p, fi->flags);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::create(const char * p, mode_t m, struct fuse_file_info * fi)
{
- TypedPayloadReq<CreateRequest>::Ptr msg = new TypedPayloadReq<CreateRequest>(fuse_get_context());
- msg->data.path = p;
- msg->data.mode = m;
- TypedPayload<OpenReply>::Ptr rep = msg->exchange(this);
- fi->fh = rep->data.handle;
- return -rep->data.error;
+ try {
+ fi->fh = files->create(p, 0, m);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::release(const char *, struct fuse_file_info * fi)
{
- TypedPayloadReq<CloseRequest>::Ptr msg = new TypedPayloadReq<CloseRequest>(fuse_get_context());
- msg->data.handle = fi->fh;
- TypedPayload<CloseReply>::Ptr rep = msg->exchange(this);
- return -rep->data.error;
+ try {
+ files->close(fi->fh);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi)
{
- TypedPayloadReq<ReadRequest>::Ptr msg = new TypedPayloadReq<ReadRequest>(fuse_get_context());
- msg->data.handle = fi->fh;
- msg->data.offset = o;
- msg->data.size = s;
- TypedPayload<ReadReply>::Ptr rep = msg->exchange(this);
- if (rep->data.size) {
- memcpy(buf, rep->data.data, std::min(s, rep->data.size));
- return s;
+ try {
+ NetFSComms::Buffer data = files->read(fi->fh, o, s);
+ for (NetFSComms::Buffer::const_iterator i = data.begin(); i != data.end(); i++, buf++) {
+ *buf = *i;
+ }
+ return data.size();
}
- else {
- return -rep->data.error;
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
}
}
+
int
NetFS::write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi)
{
- TypedPayloadReq<WriteRequest>::Ptr msg = new TypedPayloadReq<WriteRequest>(fuse_get_context());
- msg->data.handle = fi->fh;
- msg->data.offset = o;
- msg->data.size = s;
- msg->data.data = new char[s]();
- memcpy(msg->data.data, buf, s);
- TypedPayload<WriteReply>::Ptr rep = msg->exchange(this);
- return -rep->data.error;
+ try {
+ NetFSComms::Buffer data(buf, buf + s);
+ files->write(fi->fh, o, s, data);
+ return s;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::truncate(const char * p, off_t o)
{
- TypedPayloadReq<TruncateRequest>::Ptr msg = new TypedPayloadReq<TruncateRequest>(fuse_get_context());
- msg->data.path = p;
- msg->data.size = o;
- return -msg->exchange(this)->data.value;
+ try {
+ files->truncate(p, o);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::ftruncate(const char *, off_t o, fuse_file_info * fi)
{
- TypedPayloadReq<FtruncateRequest>::Ptr msg = new TypedPayloadReq<FtruncateRequest>(fuse_get_context());
- msg->data.handle = fi->fh;
- msg->data.size = o;
- return -msg->exchange(this)->data.value;
+ try {
+ files->ftruncate(fi->fh, o);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
+int
+NetFS::unlink(const char * p)
+{
+ try {
+ files->unlink(p);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
+}
+
diff --git a/netfs/fuseMisc.cpp b/netfs/fuseMisc.cpp
index 2746916..074da48 100644
--- a/netfs/fuseMisc.cpp
+++ b/netfs/fuseMisc.cpp
@@ -1,87 +1,132 @@
#include "fuse.h"
-#include "msgtypes.h"
#include <string.h>
int
NetFS::access(const char * p, int a)
{
- TypedPayloadReq<AccessRequest>::Ptr msg = new TypedPayloadReq<AccessRequest>(fuse_get_context());
- msg->data.access = a;
- msg->data.path = p;
- return -msg->exchange(this)->data.value;
+ return -misc->access(p, a);
}
int
NetFS::getattr(const char * p, struct stat * s)
{
- TypedPayloadReq<GetAttrRequest>::Ptr msg = new TypedPayloadReq<GetAttrRequest>(fuse_get_context());
- msg->data.path = p;
- TypedPayload<GetAttrReply>::Ptr rep = msg->exchange(this);
- *s = rep->data.val;
- return -rep->data.res;
+ try {
+ NetFSComms::Attr a = misc->getattr(p);
+ s->st_dev = a.dev;
+ s->st_ino = a.inode;
+ s->st_mode = a.mode;
+ s->st_nlink = a.links;
+ s->st_uid = a.uid;
+ s->st_gid = a.gid;
+ s->st_rdev = a.rdev;
+ s->st_size = a.size;
+ s->st_blksize = a.blockSize;
+ s->st_blocks = a.blocks;
+ s->st_atime = a.atime;
+ s->st_mtime = a.mtime;
+ s->st_ctime = a.ctime;
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::fgetattr(const char *, struct stat * s, fuse_file_info * fi)
{
- TypedPayloadReq<FgetAttrRequest>::Ptr msg = new TypedPayloadReq<FgetAttrRequest>(fuse_get_context());
- msg->data.handle = fi->fh;
- TypedPayload<GetAttrReply>::Ptr rep = msg->exchange(this);
- *s = rep->data.val;
- return -rep->data.res;
+ try {
+ NetFSComms::Attr a = misc->fgetattr(fi->fh);
+ s->st_dev = a.dev;
+ s->st_ino = a.inode;
+ s->st_mode = a.mode;
+ s->st_nlink = a.links;
+ s->st_uid = a.uid;
+ s->st_gid = a.gid;
+ s->st_rdev = a.rdev;
+ s->st_size = a.size;
+ s->st_blksize = a.blockSize;
+ s->st_blocks = a.blocks;
+ s->st_atime = a.atime;
+ s->st_mtime = a.mtime;
+ s->st_ctime = a.ctime;
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::chmod(const char * p, mode_t m)
{
- TypedPayloadReq<ChmodRequest>::Ptr msg = new TypedPayloadReq<ChmodRequest>(fuse_get_context());
- msg->data.path = p;
- msg->data.mode = m;
- return msg->exchange(this)->data.value;
+ try {
+ misc->chmod(p, m);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::chown(const char * p, uid_t u, gid_t g)
{
- TypedPayloadReq<ChownRequest>::Ptr msg = new TypedPayloadReq<ChownRequest>(fuse_get_context());
- msg->data.path = p;
- msg->data.user = u;
- msg->data.group = g;
- return msg->exchange(this)->data.value;
+ try {
+ misc->chown(p, u, g);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::link(const char * p1, const char * p2)
{
- TypedPayloadReq<LinkRequest>::Ptr msg = new TypedPayloadReq<LinkRequest>(fuse_get_context());
- msg->data.path1 = p1;
- msg->data.path2 = p2;
- return msg->exchange(this)->data.value;
+ try {
+ misc->link(p1, p2);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::symlink(const char * p1, const char * p2)
{
- TypedPayloadReq<SymlinkRequest>::Ptr msg = new TypedPayloadReq<SymlinkRequest>(fuse_get_context());
- msg->data.path1 = p1;
- msg->data.path2 = p2;
- return msg->exchange(this)->data.value;
+ try {
+ misc->symlink(p1, p2);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::readlink(const char * p, char * p2, size_t s)
{
- TypedPayloadReq<ReadlinkRequest>::Ptr msg = new TypedPayloadReq<ReadlinkRequest>(fuse_get_context());
- msg->data.path = p;
- TypedPayload<ReadlinkReply>::Ptr rep = msg->exchange(this);
- strncpy(p2, rep->data.path.c_str(), std::min(rep->data.path.length(), s));
- return -rep->data.error;
+ try {
+ std::string l = misc->readlink(p);
+ l.copy(p2, s);
+ p2[s] = '\0';
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
int
NetFS::rename(const char * p1, const char * p2)
{
- TypedPayloadReq<RenameRequest>::Ptr msg = new TypedPayloadReq<RenameRequest>(fuse_get_context());
- msg->data.path1 = p1;
- msg->data.path2 = p2;
- return msg->exchange(this)->data.value;
-}
-int
-NetFS::unlink(const char * p)
-{
- TypedPayloadReq<UnlinkRequest>::Ptr msg = new TypedPayloadReq<UnlinkRequest>(fuse_get_context());
- msg->data.path = p;
- return msg->exchange(this)->data.value;
+ try {
+ misc->rename(p1, p2);
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
}
+
diff --git a/netfs/fuseSystem.cpp b/netfs/fuseSystem.cpp
new file mode 100644
index 0000000..050eaa4
--- /dev/null
+++ b/netfs/fuseSystem.cpp
@@ -0,0 +1,25 @@
+#include "fuse.h"
+
+int
+NetFS::statfs(const char * p, struct statvfs * vfs)
+{
+ try {
+ NetFSComms::VFS v = system->statfs(p);
+ vfs->f_bsize = v.blockSize;
+ vfs->f_frsize = v.fragmentSize;
+ vfs->f_blocks = v.blocks;
+ vfs->f_bfree = v.freeBlocks;
+ vfs->f_bavail = v.availBlocks;
+ vfs->f_files = v.files;
+ vfs->f_ffree = v.freeFiles;
+ vfs->f_favail = v.availFiles;
+ vfs->f_fsid = v.FSID;
+ vfs->f_flag = v.flags;
+ vfs->f_namemax = v.maxNameLen;
+ return 0;
+ }
+ catch (NetFSComms::SystemError & e) {
+ return -e.syserrno;
+ }
+}
+
diff --git a/netfs/fusecallers.h b/netfs/fusecallers.h
deleted file mode 100644
index cb521df..0000000
--- a/netfs/fusecallers.h
+++ /dev/null
@@ -1,4 +0,0 @@
-#ifndef FUSECALLERS_H
-#define FUSECALLERS_H
-#endif
-
diff --git a/netfs/msgtypes.cpp b/netfs/msgtypes.cpp
deleted file mode 100644
index 6ea3c80..0000000
--- a/netfs/msgtypes.cpp
+++ /dev/null
@@ -1,200 +0,0 @@
-#include "msgtypes.h"
-#include "xfers.h"
-#include "misc.h"
-
-MessageFactories & MsgFacs()
-{
- static MessageFactories m;
- return m;
-}
-
-template<class Type> void operator<<(FILE &, const Type & t);
-template<class Type> void operator>>(FILE &, Type & t);
-
-template<> void operator<<(FILE & f, const std::string & t)
-{
- std::string::size_type len = t.length();
- f << len;
- if (fwrite(t.data(), len, 1, &f) != 1) {
- throw WriteMessageFailed();
- }
-}
-template<> void operator>>(FILE & f, std::string & t)
-{
- std::string::size_type len;
- f >> len;
- t.clear();
- t.reserve(len);
- while (len --) {
- int c = fgetc(&f);
- if (c == EOF) {
- throw ReadMessageFailed();
- }
- t.push_back(c);
- }
-}
-template<class Type> void operator<<(FILE & f, const Type & t)
-{
- if (fwrite(&t, sizeof(t), 1, &f) != 1) {
- throw WriteMessageFailed();
- }
-}
-template<class Type> void operator>>(FILE & f, Type & t)
-{
- if (fread(&t, sizeof(t), 1, &f) != 1) {
- throw ReadMessageFailed();
- }
-}
-
-void
-ContentBase::Send(FILE*) const
-{
-}
-void
-ContentBase::Read(FILE*)
-{
-}
-void
-RequestBase::Send(FILE*f) const
-{
- ContentBase::Send(f);
- *f << uid;
- *f << gid;
-}
-void
-RequestBase::Read(FILE*f)
-{
- ContentBase::Read(f);
- *f >> uid;
- *f >> gid;
-}
-Xfer1(3, OpenDirRequest, RequestBase, path)
-Xfer2(4, OpenDirReply, ContentBase, error, handle)
-Xfer1(6, ReadDirRequest, RequestBase, handle)
-Xfer2(7, AccessRequest, RequestBase, path, access)
-Xfer1(8, SimpleInt, ContentBase, value)
-Xfer1(9, GetAttrRequest, RequestBase, path)
-Xfer2(10, GetAttrReply, ContentBase, res, val)
-Xfer1(11, CloseDirRequest, RequestBase, handle)
-Xfer1(12, CloseDirReply, ContentBase, error)
-Xfer1(14, OpenRequest, RequestBase, path)
-Xfer2(15, OpenReply, ContentBase, error, handle)
-Xfer1(16, CloseRequest, RequestBase, handle)
-Xfer1(17, CloseReply, ContentBase, error)
-Xfer3(18, ReadRequest, RequestBase, handle, offset, size)
-Xfer1(19, WriteReply, ContentBase, error)
-Xfer1(20, MkDirRequest, RequestBase, path)
-Xfer1(21, UnlinkRequest, RequestBase, path)
-Xfer2(22, SymlinkRequest, RequestBase, path1, path2)
-Xfer2(23, LinkRequest, RequestBase, path1, path2)
-Xfer2(24, RenameRequest, RequestBase, path1, path2)
-Xfer1(25, ReadlinkRequest, RequestBase, path)
-Xfer1(26, ReadlinkReply, ContentBase, path)
-Xfer2(27, ChmodRequest, RequestBase, path, mode)
-Xfer3(28, ChownRequest, RequestBase, path, user, group)
-Xfer2(29, TruncateRequest, RequestBase, path, size)
-Xfer2(30, FtruncateRequest, RequestBase, handle, size)
-Xfer1(31, StatfsRequest, RequestBase, path)
-Xfer2(32, StatfsReply, ContentBase, statfs, error)
-Xfer1(33, FgetAttrRequest, RequestBase, handle)
-Xfer2(34, CreateRequest, RequestBase, path, mode)
-Xfer1(35, RmDirRequest, RequestBase, path)
-
-MSGTYPE(5, ReadDirReply)
-void
-ReadDirReply::Send(FILE*f) const
-{
- ContentBase::Send(f);
- *f << error;
- *f << entries.size();
- foreach (Entries::const_iterator, entries, e) {
- *f << e->path;
- *f << e->val;
- }
-}
-void
-ReadDirReply::Read(FILE*f)
-{
- ContentBase::Read(f);
- *f >> error;
- size_t count;
- *f >> count;
- entries.resize(count);
- while (count) {
- count -= 1;
- *f >> entries[count].path;
- *f >> entries[count].val;
- }
-}
-
-MSGTYPE(2, ReadReply)
-ReadReply::~ReadReply()
-{
- if (data) {
- delete[] data;
- }
-}
-void
-ReadReply::Send(FILE*f) const
-{
- ContentBase::Send(f);
- *f << error;
- *f << size;
- if (size) {
- if (fwrite(data, size, 1, f) != 1) {
- throw WriteMessageFailed();
- }
- }
-}
-void
-ReadReply::Read(FILE*f)
-{
- ContentBase::Read(f);
- *f >> error;
- *f >> size;
- if (size) {
- data = new char[size]();
- if (fread(data, size, 1, f) != 1) {
- throw ReadMessageFailed();
- }
- }
- else {
- data = NULL;
- }
-}
-
-MSGTYPE(1, WriteRequest)
-WriteRequest::~WriteRequest()
-{
- if (data) {
- delete[] data;
- }
-}
-void
-WriteRequest::Send(FILE*f) const
-{
- RequestBase::Send(f);
- *f << handle;
- *f << size;
- *f << offset;
- if (fwrite(data, size, 1, f) != 1) {
- throw WriteMessageFailed();
- }
-}
-void
-WriteRequest::Read(FILE*f)
-{
- RequestBase::Read(f);
- *f >> handle;
- *f >> size;
- *f >> offset;
- if (size) {
- data = new char[size]();
- if (fread(data, size, 1, f) != 1) {
- throw ReadMessageFailed();
- }
- }
- else {
- data = NULL;
- }
-}
diff --git a/netfs/msgtypes.h b/netfs/msgtypes.h
deleted file mode 100644
index 0f7b3f0..0000000
--- a/netfs/msgtypes.h
+++ /dev/null
@@ -1,348 +0,0 @@
-#ifndef MSGTYPES_H
-#define MSGTYPES_H
-
-#include "smartpointer.h"
-#include "comms.h"
-#include <map>
-#include <string>
-#include <vector>
-#include <sys/stat.h>
-#include <stdint.h>
-
-typedef DataPayloadPtr (*MessageFactory)();
-typedef std::map<uint16_t, MessageFactory> MessageFactories;
-MessageFactories & MsgFacs();
-
-template <class Cls>
-class Factory {
- public:
- Factory() { MsgFacs()[Cls::TypeID] = &create; }
- static DataPayloadPtr create() {
- return new TypedPayload<Cls>();
- }
-};
-
-class ContentBase : public IsRefCounted {
- public:
- ~ContentBase() = 0;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class RequestBase : public ContentBase {
- public:
- uid_t uid;
- gid_t gid;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class SimpleInt : public ContentBase {
- public:
- int value;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class AccessRequest : public RequestBase {
- public:
- std::string path;
- int access;
- const static uint16_t TypeID;
- typedef SimpleInt Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class GetAttrReply : public ContentBase {
- public:
- int res;
- struct stat val;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class GetAttrRequest : public RequestBase {
- public:
- std::string path;
- const static uint16_t TypeID;
- typedef GetAttrReply Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class FgetAttrRequest : public RequestBase {
- public:
- int handle;
- const static uint16_t TypeID;
- typedef GetAttrReply Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class OpenDirReply : public ContentBase {
- public:
- int handle;
- int error;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class OpenDirRequest : public RequestBase {
- public:
- std::string path;
- const static uint16_t TypeID;
- typedef OpenDirReply Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class CloseDirReply : public ContentBase {
- public:
- int error;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class CloseDirRequest : public RequestBase {
- public:
- int handle;
- const static uint16_t TypeID;
- typedef CloseDirReply Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class ReadDirReply : public ContentBase {
- public:
- class Entry {
- public:
- std::string path;
- struct stat val;
- };
- typedef std::vector<Entry> Entries;
- int error;
- Entries entries;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class ReadDirRequest : public RequestBase {
- public:
- int handle;
- const static uint16_t TypeID;
- typedef ReadDirReply Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-class OpenReply : public ContentBase {
- public:
- int error;
- int handle;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class OpenRequest : public RequestBase {
- public:
- std::string path;
- const static uint16_t TypeID;
- typedef OpenReply Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class CreateRequest : public RequestBase {
- public:
- std::string path;
- mode_t mode;
- const static uint16_t TypeID;
- typedef OpenReply Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class CloseReply : public ContentBase {
- public:
- int error;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class CloseRequest : public RequestBase {
- public:
- int handle;
- const static uint16_t TypeID;
- typedef CloseReply Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class ReadReply : public ContentBase {
- public:
- ~ReadReply();
- int error;
- char * data;
- size_t size;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class ReadRequest : public RequestBase {
- public:
- int handle;
- size_t size;
- off_t offset;
- const static uint16_t TypeID;
- typedef ReadReply Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class WriteReply : public ContentBase {
- public:
- int error;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class WriteRequest : public RequestBase {
- public:
- ~WriteRequest();
- int handle;
- size_t size;
- char * data;
- off_t offset;
- const static uint16_t TypeID;
- typedef WriteReply Reply;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class MkDirRequest : public RequestBase {
- public:
- std::string path;
- mode_t mode;
- typedef SimpleInt Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class RmDirRequest : public RequestBase {
- public:
- std::string path;
- typedef SimpleInt Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class UnlinkRequest : public RequestBase {
- public:
- std::string path;
- typedef SimpleInt Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class SymlinkRequest : public RequestBase {
- public:
- std::string path1;
- std::string path2;
- typedef SimpleInt Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class LinkRequest : public RequestBase {
- public:
- std::string path1;
- std::string path2;
- typedef SimpleInt Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class RenameRequest : public RequestBase {
- public:
- std::string path1;
- std::string path2;
- typedef SimpleInt Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class ReadlinkReply : public ContentBase {
- public:
- std::string path;
- int error;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class ReadlinkRequest : public RequestBase {
- public:
- std::string path;
- typedef ReadlinkReply Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class ChmodRequest : public RequestBase {
- public:
- std::string path;
- mode_t mode;
- typedef SimpleInt Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class ChownRequest : public RequestBase {
- public:
- std::string path;
- uid_t user;
- gid_t group;
- typedef SimpleInt Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class TruncateRequest : public RequestBase {
- public:
- std::string path;
- off_t size;
- typedef SimpleInt Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class FtruncateRequest : public RequestBase {
- public:
- int handle;
- off_t size;
- typedef SimpleInt Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class StatfsReply : public ContentBase {
- public:
- struct statvfs statfs;
- int error;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-class StatfsRequest : public RequestBase {
- public:
- std::string path;
- typedef StatfsReply Reply;
- const static uint16_t TypeID;
- virtual void Send(FILE*) const;
- virtual void Read(FILE*);
-};
-
-#define MSGTYPE(id, cls) \
- const uint16_t cls::TypeID = id; \
- namespace MsgFactories { Factory<cls> facFor##id; }
-#endif
-
diff --git a/netfs/netfsComms.ice b/netfs/netfsComms.ice
new file mode 100644
index 0000000..32c96bc
--- /dev/null
+++ b/netfs/netfsComms.ice
@@ -0,0 +1,76 @@
+module NetFSComms {
+ // Exceptions
+ exception SystemError {
+ int syserrno;
+ };
+ // Types
+ struct VFS {
+ long blockSize;
+ long fragmentSize;
+ long blocks;
+ long freeBlocks;
+ long availBlocks;
+ long files;
+ long freeFiles;
+ long availFiles;
+ long FSID;
+ long flags;
+ long maxNameLen;
+ };
+ struct Attr {
+ int dev;
+ long inode;
+ int mode;
+ int links;
+ int uid;
+ int gid;
+ int rdev;
+ long size;
+ long blockSize;
+ long blocks;
+ long atime;
+ long mtime;
+ long ctime;
+ };
+ sequence<byte> Buffer;
+ sequence<string> NameList;
+ // Interfaces
+ interface Files {
+ void truncate(string path, long size);
+ void ftruncate(int id, long size);
+
+ void unlink(string path);
+
+ int open(string path, int flags);
+ int create(string path, int flags, int mode);
+ void close(int id);
+
+ Buffer read(int id, long offset, long size);
+ void write(int id, long offset, long size, Buffer data);
+ };
+ interface Dirs {
+ int opendir(string path) throws SystemError;
+ void closedir(int id) throws SystemError;
+ NameList readdir(int id) throws SystemError;
+
+ void mkdir(string path, int mode) throws SystemError;
+ void rmdir(string path) throws SystemError;
+ };
+ interface System {
+ VFS statfs(string path);
+ };
+ interface Misc {
+ int access(string path, int mode);
+ Attr getattr(string path);
+ Attr fgetattr(int id);
+ void symlink(string path1, string path2);
+ void link(string path1, string path2);
+ void rename(string from, string to);
+ string readlink(string path);
+ void chmod(string path, int mode);
+ void chown(string path, int uid, int gid);
+ };
+ interface Service {
+ };
+};
+
diff --git a/netfs/xfers.h b/netfs/xfers.h
deleted file mode 100644
index baf2eaa..0000000
--- a/netfs/xfers.h
+++ /dev/null
@@ -1,56 +0,0 @@
-#ifndef XFERS_H
-#define XFERS_H
-
-#define Xfer1(id, Ptype, Pbase, v1) \
-MSGTYPE(id, Ptype) \
-void \
-Ptype::Send(FILE*f) const \
-{ \
- Pbase::Send(f); \
- *f << v1; \
-} \
-void \
-Ptype::Read(FILE*f) \
-{ \
- Pbase::Read(f); \
- *f >> v1; \
-}
-
-#define Xfer2(id, Ptype, Pbase, v1, v2) \
-MSGTYPE(id, Ptype) \
-void \
-Ptype::Send(FILE*f) const \
-{ \
- Pbase::Send(f); \
- *f << v1; \
- *f << v2; \
-} \
-void \
-Ptype::Read(FILE*f) \
-{ \
- Pbase::Read(f); \
- *f >> v1; \
- *f >> v2; \
-}
-
-#define Xfer3(id, Ptype, Pbase, v1, v2, v3) \
-MSGTYPE(id, Ptype) \
-void \
-Ptype::Send(FILE*f) const \
-{ \
- Pbase::Send(f); \
- *f << v1; \
- *f << v2; \
- *f << v3; \
-} \
-void \
-Ptype::Read(FILE*f) \
-{ \
- Pbase::Read(f); \
- *f >> v1; \
- *f >> v2; \
- *f >> v3; \
-}
-
-#endif
-