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
|
#include "daemonFile.h"
#include <Ice/ObjectAdapter.h>
#include <cerrno>
#include <entCache.h>
#include <fcntl.h>
#include <map>
#include <sys/stat.h>
#include <typeConverter.h>
#include <unistd.h>
FileServer::FileServer(int f, EntryTypeConverter & t) : EntryTypeConverter(t), fd(f) { }
void
FileServer::ftruncate(const NetFS::ReqEnv re, Ice::Long size, const Ice::Current &)
{
(void)re;
errno = 0;
if (::ftruncate(fd, size) != 0) {
throw NetFS::SystemError(errno);
}
}
NetFS::Attr
FileServer::fgetattr(const NetFS::ReqEnv re, const Ice::Current &)
{
(void)re;
struct stat s {
};
if (::fstat(fd, &s) != 0) {
throw NetFS::SystemError(errno);
}
return convert(s);
}
void
FileServer::close(const Ice::Current & ice)
{
errno = 0;
if (::close(fd) != 0) {
throw NetFS::SystemError(errno);
}
ice.adapter->removeAllFacets(ice.id);
}
NetFS::Buffer
FileServer::read(Ice::Long offset, Ice::Long size, const Ice::Current &)
{
NetFS::Buffer buf;
buf.resize(size);
errno = 0;
int r = pread(fd, &buf[0], size, offset);
if (r == -1) {
throw NetFS::SystemError(errno);
}
else if (r != size) {
buf.resize(r);
}
return buf;
}
void
FileServer::write(Ice::Long offset, Ice::Long size, const NetFS::Buffer data, const Ice::Current &)
{
errno = 0;
if (pwrite(fd, &data.front(), size, offset) != size) {
throw NetFS::SystemError(errno);
}
}
Ice::Long
FileServer::copyrange(NetFS::FilePrxPtr to, Ice::Long offsrc, Ice::Long offdst, Ice::Long size, Ice::Int flags,
const Ice::Current & ice)
{
if (auto obj = ice.adapter->findByProxy(to); auto file = std::dynamic_pointer_cast<FileServer>(obj)) {
errno = 0;
off_t src = offsrc, dst = offdst;
if (auto rtn = copy_file_range(fd, &src, file->fd, &dst, size, flags); rtn != -1) {
return rtn;
}
throw NetFS::SystemError(errno);
}
else {
to->write(offdst, size, read(offsrc, size, ice));
return size;
}
}
|