-
Notifications
You must be signed in to change notification settings - Fork 0
/
yfs_client.cc
98 lines (80 loc) · 1.65 KB
/
yfs_client.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// yfs client. implements FS operations using extent and lock server
#include "yfs_client.h"
#include "extent_client.h"
#include "lock_client.h"
#include <sstream>
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
yfs_client::yfs_client(std::string extent_dst, std::string lock_dst)
{
ec = new extent_client(extent_dst);
}
yfs_client::inum
yfs_client::n2i(std::string n)
{
std::istringstream ist(n);
unsigned long long finum;
ist >> finum;
return finum;
}
std::string
yfs_client::filename(inum inum)
{
std::ostringstream ost;
ost << inum;
return ost.str();
}
bool
yfs_client::isfile(inum inum)
{
if(inum & 0x80000000)
return true;
return false;
}
bool
yfs_client::isdir(inum inum)
{
return ! isfile(inum);
}
int
yfs_client::getfile(inum inum, fileinfo &fin)
{
int r = OK;
// You modify this function for Lab 3
// - hold and release the file lock
printf("getfile %016llx\n", inum);
extent_protocol::attr a;
if (ec->getattr(inum, a) != extent_protocol::OK) {
r = IOERR;
goto release;
}
fin.atime = a.atime;
fin.mtime = a.mtime;
fin.ctime = a.ctime;
fin.size = a.size;
printf("getfile %016llx -> sz %llu\n", inum, fin.size);
release:
return r;
}
int
yfs_client::getdir(inum inum, dirinfo &din)
{
int r = OK;
// You modify this function for Lab 3
// - hold and release the directory lock
printf("getdir %016llx\n", inum);
extent_protocol::attr a;
if (ec->getattr(inum, a) != extent_protocol::OK) {
r = IOERR;
goto release;
}
din.atime = a.atime;
din.mtime = a.mtime;
din.ctime = a.ctime;
release:
return r;
}