-
Notifications
You must be signed in to change notification settings - Fork 0
/
extent_server.cc
80 lines (60 loc) · 1.51 KB
/
extent_server.cc
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
// the extent server implementation
#include "extent_server.h"
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
extent_server::extent_server()
{
im = new inode_manager();
}
int extent_server::create(uint32_t type, extent_protocol::extentid_t &id)
{
// alloc a new inode and return inum
printf("extent_server: create inode\n");
id = im->alloc_inode(type);
return extent_protocol::OK;
}
int extent_server::put(extent_protocol::extentid_t id, std::string buf, int &)
{
id &= 0x7fffffff;
const char * cbuf = buf.c_str();
int size = buf.size();
im->write_file(id, cbuf, size);
return extent_protocol::OK;
}
int extent_server::get(extent_protocol::extentid_t id, std::string &buf)
{
printf("extent_server: get %lld\n", id);
id &= 0x7fffffff;
int size = 0;
char *cbuf = NULL;
im->read_file(id, &cbuf, &size);
if (size == 0)
buf = "";
else {
buf.assign(cbuf, size);
free(cbuf);
}
return extent_protocol::OK;
}
int extent_server::getattr(extent_protocol::extentid_t id, extent_protocol::attr &a)
{
printf("extent_server: getattr %lld\n", id);
id &= 0x7fffffff;
extent_protocol::attr attr;
memset(&attr, 0, sizeof(attr));
im->getattr(id, attr);
a = attr;
return extent_protocol::OK;
}
int extent_server::remove(extent_protocol::extentid_t id, int &)
{
printf("extent_server: write %lld\n", id);
id &= 0x7fffffff;
im->remove_file(id);
return extent_protocol::OK;
}