summaryrefslogtreecommitdiff
path: root/netfs/fuse/fuseFiles.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'netfs/fuse/fuseFiles.cpp')
-rw-r--r--netfs/fuse/fuseFiles.cpp49
1 files changed, 15 insertions, 34 deletions
diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp
index 2fc6b26..350e74f 100644
--- a/netfs/fuse/fuseFiles.cpp
+++ b/netfs/fuse/fuseFiles.cpp
@@ -1,5 +1,5 @@
#include <string.h>
-#include "fuseApp.h"
+#include "fuseApp.impl.h"
#include "lockHelpers.h"
#include <entCache.h>
@@ -11,30 +11,11 @@ FuseApp::OpenFile::OpenFile(FilePrx r, const std::string & p, int f) :
{
}
-void
-NetFS::FuseApp::setProxy(OpenFilePtr of, uint64_t & fh)
-{
- Lock(_lock);
- while (openFiles.find(fh = ++openFileID) != openFiles.end()) ;
- openFiles.insert({ fh, of });
-}
-
-NetFS::FuseApp::OpenFilePtr
-NetFS::FuseApp::getFileProxy(uint64_t localID) const
-{
- SharedLock(_lock);
- OpenFiles::const_iterator i = openFiles.find(localID);
- if (i != openFiles.end()) {
- return i->second;
- }
- throw NetFS::SystemError(EBADF);
-}
-
-void
-FuseApp::clearFileProxy(uint64_t localID)
+template<>
+std::map<int, FuseApp::OpenFilePtr> &
+FuseApp::getMap<FuseApp::OpenFilePtr>()
{
- Lock(_lock);
- openFiles.erase(localID);
+ return openFiles;
}
void
@@ -81,7 +62,7 @@ FuseApp::open(const char * p, struct fuse_file_info * fi)
{
try {
auto remote = volume->open(reqEnv(), p, fi->flags);
- setProxy(new OpenFile(remote, p, fi->flags), fi->fh);
+ setProxy<OpenFilePtr>(new OpenFile(remote, p, fi->flags), fi->fh);
return 0;
}
catch (SystemError & e) {
@@ -94,7 +75,7 @@ FuseApp::create(const char * p, mode_t m, struct fuse_file_info * fi)
{
try {
auto remote = volume->create(reqEnv(), p, fi->flags, m);
- setProxy(new OpenFile(remote, p, fi->flags), fi->fh);
+ setProxy<OpenFilePtr>(new OpenFile(remote, p, fi->flags), fi->fh);
return 0;
}
catch (SystemError & e) {
@@ -106,7 +87,7 @@ int
FuseApp::release(const char *, struct fuse_file_info * fi)
{
try {
- auto of = getFileProxy(fi->fh);
+ auto of = getProxy<OpenFilePtr>(fi->fh);
auto remote = of->remote;
try {
of->flush();
@@ -114,11 +95,11 @@ FuseApp::release(const char *, struct fuse_file_info * fi)
catch (SystemError & e) {
}
remote->close();
- clearFileProxy(fi->fh);
+ clearProxy<OpenFilePtr>(fi->fh);
return 0;
}
catch (SystemError & e) {
- clearFileProxy(fi->fh);
+ clearProxy<OpenFilePtr>(fi->fh);
return -e.syserrno;
}
}
@@ -127,7 +108,7 @@ int
FuseApp::flush(const char *, struct fuse_file_info * fi)
{
try {
- getFileProxy(fi->fh)->flush();
+ getProxy<OpenFilePtr>(fi->fh)->flush();
return 0;
}
catch (SystemError & e) {
@@ -139,7 +120,7 @@ int
FuseApp::read(const char *, char * buf, size_t s, off_t o, struct fuse_file_info * fi)
{
try {
- auto of = getFileProxy(fi->fh);
+ auto of = getProxy<OpenFilePtr>(fi->fh);
of->wait();
auto remote = of->remote;
Buffer data = remote->read(o, s);
@@ -155,7 +136,7 @@ int
FuseApp::write(const char *, const char * buf, size_t s, off_t o, struct fuse_file_info * fi)
{
try {
- auto of = getFileProxy(fi->fh);
+ auto of = getProxy<OpenFilePtr>(fi->fh);
auto remote = of->remote;
auto r = remote->begin_write(o, s, Buffer(buf, buf + s));
if (fcr->Async) {
@@ -190,7 +171,7 @@ int
FuseApp::ftruncate(const char *, off_t o, fuse_file_info * fi)
{
try {
- auto of = getFileProxy(fi->fh);
+ auto of = getProxy<OpenFilePtr>(fi->fh);
of->wait();
auto remote = of->remote;
remote->ftruncate(reqEnv(), o);
@@ -205,7 +186,7 @@ int
FuseApp::fgetattr(const char *, struct stat * s, fuse_file_info * fi)
{
try {
- auto of = getFileProxy(fi->fh);
+ auto of = getProxy<OpenFilePtr>(fi->fh);
of->wait();
auto remote = of->remote;
*s = converter.convert(remote->fgetattr(reqEnv()));