-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMessage.h
112 lines (102 loc) · 4.06 KB
/
Message.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef MESSAGE_H
#define MESSAGE_H
// Serialization and deserialization of all the messages.
#include <cstdlib>
#include <iostream>
#include <fuse.h>
#include <sstream>
#include <vector>
// Message codes.
#define MAX_SIZE 512
#define CONNECT_CODE 1
#define GETATTR 2
#define STATFS 3
#define OPENDIR 4
#define READDIR 5
#define CLOSEDIR 6
#define OPEN 7
#define CLOSE 8
#define READ 9
#define WRITE 10
#define MKNOD 11
#define ACCESS 12
#define UNLINK 13
#define RENAME 14
class Message {
public:
Message(int, std::string);
int _code;
int _ret;
// Size that makes sense in the continued buffer
int _size;
char _buffer[MAX_SIZE];
~Message() {
}
Message(const Message &m) {
_code = m._code;
_ret = m._ret;
_size = m._size;
for (int i = 0; i < _size; i++)
_buffer[i] = m._buffer[i];
}
Message() {
_code = -1;
_ret = -1;
_size = 0;
}
/*
* * Message creaters.
* * Modify already instantiated Message.
* */
void create_access(const char * path, int mode);
void create_getAttr(const char * path);
void create_readlink(const char * path, char *link, size_t size);
void create_mknod(const char * path, mode_t mode, dev_t dev);
void create_mkdir(const char * path, mode_t mode);
void create_unlink(const char * path);
void create_rmdir(const char * path);
void create_symlink(const char * path, const char *link);
void create_rename(const char * path, const char * newPath);
void create_link(const char * path, const char *newPath);
void create_chmod(const char * path, mode_t mode);
void create_chown(const char * path, uid_t uid, gid_t gid);
void create_utime(const char * path, struct utimbuf *ubuf);
void create_truncate(const char * path, off_t newSize);
void create_open(const char * path);
void create_read(const char * path, size_t size, off_t offset);
void create_write(const char * path, const char *buf, size_t size,
off_t offset);
void create_statfs(const char * path);
void create_flush(const char * path, struct fuse_file_info *fileInfo);
void create_release(const char * path, struct fuse_file_info *fileInfo);
void create_fsync(const char * path, int datasync, struct fuse_file_info *fileInfo);
void create_setxattr(const char * path, const char *name, const char *value,
size_t size, int flags);
void create_getxattr(const char * path, const char *name, char *value, size_t size);
void create_listxattr(const char * path, char *list, size_t size);
void create_removexattr(const char * path, const char *name);
void create_opendir(const char * path);
void create_readdir(const char * path);
void create_releasedir(const char * path, struct fuse_file_info *fileInfo);
void create_fsyncdir(const char * path, int datasync, struct fuse_file_info *fileInfo);
void create_init(struct fuse_conn_info *conn);
void create_closedir(const char * path);
void create_close(const char * path);
// Networking stuff.
const char *serialize();
static Message * toMessage(char *buffer) {
Message *msg = new Message();
memcpy(&msg -> _code, buffer, sizeof(int));
memcpy(&msg -> _ret, buffer + sizeof(int), sizeof(int));
memcpy(&msg -> _size, buffer + 2 * sizeof(int), sizeof(int));
memcpy(msg -> _buffer, buffer + 3 * sizeof(int), msg -> _size);
return msg;
}
static void fillMessage(Message *msg, char *buffer) {
memcpy(&msg -> _code, buffer, sizeof(int));
memcpy(&msg -> _ret, buffer + sizeof(int), sizeof(int));
memcpy(&msg -> _size, buffer + 2 * sizeof(int), sizeof(int));
memcpy(msg -> _buffer, buffer + 3 * sizeof(int), msg -> _size);
}
};
#endif