-
Notifications
You must be signed in to change notification settings - Fork 0
/
yfs_client.h
87 lines (70 loc) · 2.03 KB
/
yfs_client.h
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
#ifndef yfs_client_h
#define yfs_client_h
#include <string>
//#include "yfs_protocol.h"
#include "extent_client.h"
#include "lock_client_cache.h"
#include <vector>
class custom_lock_release_user : public lock_release_user {
private:
extent_client *ec;
void dorelease(lock_protocol::lockid_t);
public:
custom_lock_release_user(extent_client *ec) {
this->ec = ec;
}
};
class yfs_client {
extent_client *ec;
lock_client_cache *lc;
public:
typedef unsigned long long inum;
enum xxstatus { OK, RPCERR, NOENT, IOERR, FBIG };
typedef int status;
struct fileinfo {
unsigned long long size;
unsigned long atime;
unsigned long mtime;
unsigned long ctime;
};
struct dirinfo {
unsigned long atime;
unsigned long mtime;
unsigned long ctime;
};
struct dirent {
std::string name;
unsigned long long inum;
dirent() {};
dirent(std::string name, unsigned long long inum) {
this->name = name;
this->inum = inum;
}
};
typedef std::vector<dirent> dirent_lst_t;
private:
static std::string filename(inum);
static inum n2i(std::string);
std::string serialize(dirent_lst_t lst);
dirent_lst_t unserialize(std::string serialized);
int get_all_in_dir(inum parent, dirent_lst_t& dirent_lst);
int put_all_in_dir(inum parent, dirent_lst_t dirent_lst);
inum create_random_inum(bool is_dir);
public:
yfs_client(std::string, std::string);
bool isfile(inum);
bool isdir(inum);
inum ilookup(inum di, std::string name);
int getfile(inum, fileinfo &);
int getdir(inum, dirinfo &);
int create(inum parent, const char *name, int is_dir, inum& inum);
int lookup(inum parent, const char *name, inum& inum);
int readdir(inum parent, dirent_lst_t& dirent_lst);
int read(inum inum, off_t offset, size_t size, std::string& data);
int write(inum inum, off_t offset, size_t size, std::string data);
int resize(inum inum, int size);
int unlink(inum parent, const char *name);
void acquire_lock(inum inum);
void release_lock(inum inum);
};
#endif