summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--netfs/daemon.cpp10
-rw-r--r--netfs/daemon.h1
-rw-r--r--netfs/daemonDirs.cpp6
-rw-r--r--netfs/daemonFiles.cpp19
-rw-r--r--netfs/daemonMisc.cpp16
-rw-r--r--netfs/fuseFiles.cpp2
6 files changed, 42 insertions, 12 deletions
diff --git a/netfs/daemon.cpp b/netfs/daemon.cpp
index d9990fe..9d0e4f7 100644
--- a/netfs/daemon.cpp
+++ b/netfs/daemon.cpp
@@ -11,10 +11,11 @@
#include "misc.h"
#include "daemon.h"
-Sender::Sender(int i, FILE * f)
+Sender::Sender(int i, FILE * f) :
+ replicatedRequest(false),
+ idx(i),
+ host(f)
{
- idx = i;
- host = f;
}
void Sender::Send(DataPayloadPtr p)
{
@@ -82,6 +83,9 @@ runDaemonOn(FILE * f, DaemonGlobalStatePtr)
TRYCLASS(CreateRequest);
// FS
TRYCLASS(StatfsRequest);
+
+ if (s.replicatedRequest) {
+ }
}
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *);
diff --git a/netfs/daemon.h b/netfs/daemon.h
index 565ca05..6b57976 100644
--- a/netfs/daemon.h
+++ b/netfs/daemon.h
@@ -19,6 +19,7 @@ class Sender {
public:
Sender(int i, FILE * f);
void Send(DataPayloadPtr p);
+ bool replicatedRequest;
private:
int idx;
FILE * host;
diff --git a/netfs/daemonDirs.cpp b/netfs/daemonDirs.cpp
index 20ab82d..17f9367 100644
--- a/netfs/daemonDirs.cpp
+++ b/netfs/daemonDirs.cpp
@@ -16,6 +16,7 @@ handler(OpenDirRequest)
if (od) {
dirs[++dirNo] = od;
r->data.handle = dirNo;
+ s.replicatedRequest = true;
}
r->data.error = errno;
s.Send(r);
@@ -31,6 +32,7 @@ handler(CloseDirRequest)
else {
dirs.erase(req->data.handle);
}
+ s.replicatedRequest = true;
}
else {
r->data.error = EBADF;
@@ -62,6 +64,8 @@ handler(MkDirRequest)
errno = 0;
mkdir(req->data.path.c_str(), req->data.mode);
r->data.value = errno;
+ if (errno == 0)
+ s.replicatedRequest = true;
s.Send(r);
}
handler(RmDirRequest)
@@ -70,5 +74,7 @@ handler(RmDirRequest)
errno = 0;
rmdir(req->data.path.c_str());
r->data.value = errno;
+ if (errno == 0)
+ s.replicatedRequest = true;
s.Send(r);
}
diff --git a/netfs/daemonFiles.cpp b/netfs/daemonFiles.cpp
index fe518ae..eb274f0 100644
--- a/netfs/daemonFiles.cpp
+++ b/netfs/daemonFiles.cpp
@@ -14,6 +14,7 @@ handler(TruncateRequest)
}
else {
r->data.value = 0;
+ s.replicatedRequest = true;
}
s.Send(r);
}
@@ -26,6 +27,7 @@ handler(FtruncateRequest)
}
else {
r->data.value = 0;
+ s.replicatedRequest = true;
}
s.Send(r);
}
@@ -35,6 +37,8 @@ handler(UnlinkRequest)
errno = 0;
unlink(req->data.path.c_str());
r->data.value = errno;
+ if (errno == 0)
+ s.replicatedRequest = true;
s.Send(r);
}
int fileNo = 0;
@@ -47,6 +51,7 @@ handler(OpenRequest)
if (fd != -1) {
files[++fileNo] = fd;
r->data.handle = fileNo;
+ s.replicatedRequest = true;
}
r->data.error = errno;
s.Send(r);
@@ -59,6 +64,7 @@ handler(CreateRequest)
if (fd != -1) {
files[++fileNo] = fd;
r->data.handle = fileNo;
+ s.replicatedRequest = true;
}
r->data.error = errno;
s.Send(r);
@@ -68,12 +74,11 @@ handler(CloseRequest)
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) {
- r->data.error = errno;
- }
- else {
+ if (close(files[req->data.handle]) == 0) {
files.erase(req->data.handle);
}
+ r->data.error = errno;
+ s.replicatedRequest = true;
}
else {
r->data.error = EBADF;
@@ -86,9 +91,10 @@ handler(ReadRequest)
if (files.find(req->data.handle) != files.end()) {
char * tmpdata = new char[req->data.size]();
errno = 0;
- if (pread(files[req->data.handle], tmpdata, req->data.size, req->data.offset) != -1) {
+ int rs = pread(files[req->data.handle], tmpdata, req->data.size, req->data.offset);
+ if (rs != -1) {
r->data.data = tmpdata;
- r->data.size = req->data.size;
+ r->data.size = rs;
}
else {
r->data.size = 0;
@@ -107,6 +113,7 @@ handler(WriteRequest)
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;
}
diff --git a/netfs/daemonMisc.cpp b/netfs/daemonMisc.cpp
index e3cebc3..2341b21 100644
--- a/netfs/daemonMisc.cpp
+++ b/netfs/daemonMisc.cpp
@@ -7,6 +7,8 @@
#include "daemon.h"
#include "misc.h"
+extern std::map<int, int> files;
+
handler(AccessRequest)
{
TypedPayload<AccessRequest::Reply> * r = new TypedPayload<AccessRequest::Reply>();
@@ -25,8 +27,13 @@ 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;
+ if (files.find(req->data.handle) != files.end()) {
+ fstat(files[req->data.handle], &r->data.val);
+ r->data.res = errno;
+ }
+ else {
+ r->data.res = EBADF;
+ }
s.Send(r);
}
handler(SymlinkRequest)
@@ -38,6 +45,7 @@ handler(SymlinkRequest)
}
else {
r->data.value = 0;
+ s.replicatedRequest = true;
}
s.Send(r);
}
@@ -50,6 +58,7 @@ handler(LinkRequest)
}
else {
r->data.value = 0;
+ s.replicatedRequest = true;
}
s.Send(r);
}
@@ -62,6 +71,7 @@ handler(RenameRequest)
}
else {
r->data.value = 0;
+ s.replicatedRequest = true;
}
s.Send(r);
}
@@ -90,6 +100,7 @@ handler(ChmodRequest)
}
else {
r->data.value = 0;
+ s.replicatedRequest = true;
}
s.Send(r);
}
@@ -102,6 +113,7 @@ handler(ChownRequest)
}
else {
r->data.value = 0;
+ s.replicatedRequest = true;
}
s.Send(r);
}
diff --git a/netfs/fuseFiles.cpp b/netfs/fuseFiles.cpp
index 42b3012..9343bcf 100644
--- a/netfs/fuseFiles.cpp
+++ b/netfs/fuseFiles.cpp
@@ -39,7 +39,7 @@ NetFS::read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info *
TypedPayload<ReadReply>::Ptr rep = msg->exchange(this);
if (rep->data.size) {
memcpy(buf, rep->data.data, std::min(s, rep->data.size));
- return rep->data.size;
+ return s;
}
else {
return -rep->data.error;