summaryrefslogtreecommitdiff
path: root/netfs/fuse/fuseDirs.cpp
blob: 3d77101a1a3839e75e57c6ad5e2b626f4043e20f (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
#include "fuseApp.impl.h"
#include <lockHelpers.h>
#include <entCache.h>

namespace NetFS {
FuseApp::OpenDir::OpenDir(DirectoryPrxPtr r, const std::string & p) :
	remote(r),
	remoteV2(r->ice_getFacet() >= "v02" ? Ice::uncheckedCast<DirectoryV2Prx>(r) : nullptr),
	path(p)
{
}

template<>
std::map<int, FuseApp::OpenDirPtr> &
FuseApp::getMap<FuseApp::OpenDirPtr>()
{
	return openDirs;
}

int
FuseApp::opendir(const char * p, struct fuse_file_info * fi)
{
	try {
		auto remote = volume->opendir(reqEnv(), p);
		setProxy<OpenDirPtr>(fi->fh, remote, p);
		return 0;
	}
	catch (SystemError & e) {
		return -e.syserrno;
	}
}

int
FuseApp::releasedir(const char *, struct fuse_file_info * fi)
{
	try {
		auto remote = getProxy<OpenDirPtr>(fi->fh)->remote;
		remote->close();
		clearProxy<OpenDirPtr>(fi->fh);
		return 0;
	}
	catch (SystemError & e) {
		clearProxy<OpenDirPtr>(fi->fh);
		return -e.syserrno;
	}
}

int
FuseApp::readdir(const char * p, void * buf, fuse_fill_dir_t filler, off_t, struct fuse_file_info * fi)
{
	try {
		auto od = getProxy<OpenDirPtr>(fi->fh);
		std::string path(p);
		path += "/";
		auto expiry = time(NULL) + 2;
		if (fcr->ListDir && od->remoteV2) {
			for (const auto & e : od->remoteV2->listdir()) {
				filler(buf, e.first.c_str(), NULL, 0);
				statCache.add(path + e.first, converter.convert(e.second), expiry);
			}
		}
		else {
			for (const auto & e : od->remote->readdir()) {
				filler(buf, e.c_str(), NULL, 0);
			}
		}
		return 0;
	}
	catch (SystemError & e) {
		return -e.syserrno;
	}
}

int
FuseApp::mkdir(const char * p, mode_t m)
{
	try {
		volume->mkdir(reqEnv(), p, m);
		return 0;
	}
	catch (SystemError & e) {
		return -e.syserrno;
	}
}

int
FuseApp::rmdir(const char * p)
{
	try {
		volume->rmdir(reqEnv(), p);
		return 0;
	}
	catch (SystemError & e) {
		return -e.syserrno;
	}
}
}