summaryrefslogtreecommitdiff
path: root/netfs/fuse/fuseApp.h
blob: 335a1c0fa5a4b18d2217a57d169c52e820862d90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#ifndef NETFS_FUSE_H
#define NETFS_FUSE_H

#include <boost/thread/shared_mutex.hpp>
#include <Ice/Ice.h>
#include <Glacier2/Session.h>
#include <service.h>
#include "fuseAppBase.h"
#include "fuseConfig.h"
#include "cache.h"

namespace NetFS {
	class FuseApp : public FuseAppBase {
		private:
			class OpenDir : public IceUtil::Shared {
				public:
					OpenDir(DirectoryPrx remote, const std::string & path);

					DirectoryPrx remote;
					const std::string path;
			};
			typedef IceUtil::Handle<OpenDir> OpenDirPtr;
			typedef std::map<int, OpenDirPtr> OpenDirs;

			class OpenFile : public IceUtil::Shared {
				public:
					OpenFile(FilePrx remote, const std::string & path, int flags);

					FilePrx remote;
					const std::string path;
					const int flags;
			};
			typedef IceUtil::Handle<OpenFile> OpenFilePtr;
			typedef std::map<int, OpenFilePtr> OpenFiles;

		public:
			FuseApp(int & argc, char ** argv);
			~FuseApp();

		private:
			void * init (struct fuse_conn_info * info);
			int opt_parse(void *, const char * arg, int key, struct fuse_args *);

			void connectSession();
			void connectToService();
			void connectToVolume();
			void connectHandles();
			void verifyConnection();

		public:
			// 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 *);
			int utimens(const char *, const struct timespec tv[2]);
			int mknod(const char *, mode_t, dev_t);
			// 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
			int onError(const std::exception & err) throw();

			virtual struct fuse_context * fuse_get_context() = 0;

		protected:
			virtual NetFS::Client::ConfigurationPtr ReadConfiguration(const std::string &) const;

		private:
			void setProxy(OpenFilePtr, uint64_t & fh);
			OpenFilePtr getFileProxy(uint64_t localID) const;
			void clearFileProxy(uint64_t localID);

			void setProxy(OpenDirPtr, uint64_t & fh);
			OpenDirPtr getDirProxy(uint64_t localID) const;
			void clearDirProxy(uint64_t localID);

			ReqEnv reqEnv();

			int & _argc;
			char ** _argv;
			Ice::CommunicatorPtr ic;
			Client::ConfigurationPtr fc;
			mutable boost::shared_mutex _lock;

			NetFS::VolumePrx volume;
			NetFS::ServicePrx service;
			Glacier2::SessionPrx session;
			bool sessionOpened;

			std::string mountPoint;
			std::string resourceName;
			std::string configPath;

			OpenDirs openDirs;
			int openDirID;
			OpenFiles openFiles;
			int openFileID;

			typedef Cache<struct stat, std::string, IceUtil::Shared, IceUtil::Handle<Cacheable<struct stat, std::string, IceUtil::Shared>>> StatCache;
			StatCache statCache;
	};
}

#endif