-
Notifications
You must be signed in to change notification settings - Fork 0
/
mfs.h
102 lines (81 loc) · 2.15 KB
/
mfs.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
#ifndef __MFS_h__
#define __MFS_h__
#include "udp.h"
// #define MFS_DIRECTORY (0)
// #define MFS_REGULAR_FILE (1)
static int server_port = 10000;
static int client_port = 20000;
enum BLOCK_ENUM
{
MFS_DIRECTORY,
MFS_REGULAR_FILE,
MFS_ERROR = -1
};
#define MFS_BLOCK_SIZE (4096)
#define FILE_NAME_SIZE (28)
typedef struct __MFS_Stat_t
{
enum BLOCK_ENUM type; // MFS_DIRECTORY or MFS_REGULAR
int size; // bytes
} MFS_Stat_t;
// 32 bit
typedef struct __MFS_DirEnt_t
{
char name[FILE_NAME_SIZE]; // up to 28 bytes of name in directory (including \0)
int inum; // inode number of entry (-1 means entry not used)
} MFS_DirEnt_t;
enum MESSAGE_ENUM
{
M_INIT,
M_LOOKUP,
M_STAT,
M_WRITE,
M_READ,
M_CREAT,
M_UNLINK,
M_SHUTDOWN,
M_ERROR = -1
};
typedef struct __Message_t
{
enum MESSAGE_ENUM message_type;
int type;
int port;
int pinum;
int inum;
int block;
MFS_Stat_t stat;
char buffer[MFS_BLOCK_SIZE];
char name[FILE_NAME_SIZE];
} Message_t;
typedef struct __Checkpoint_t
{
int inode_number;
off_t imaps_addr;
} Checkpoint_t;
// used for write, read, seek wrapper in mfs.c
enum SIZE_ENUM
{
SIZE_DIR = sizeof(MFS_DirEnt_t),
SIZE_INODE_H = sizeof(MFS_Stat_t),
SIZE_ADDR = sizeof(off_t),
SIZE_BLOCK = MFS_BLOCK_SIZE
};
#define SERVER_BUFFER_SIZE (1000)
int MFS_Init(char *hostname, int port);
int MFS_Init_SERVER(int fd, struct sockaddr_in *addr);
int MFS_Lookup(int pinum, char name[FILE_NAME_SIZE]);
int MFS_Lookup_SERVER(int pinum, char name[FILE_NAME_SIZE]);
int MFS_Stat(int inum, MFS_Stat_t *m);
int MFS_Stat_SERVER(int inum, MFS_Stat_t *m);
int MFS_Write(int inum, char *buffer, int block);
int MFS_Write_SERVER(int inum, char *buffer, int block);
int MFS_Read(int inum, char buffer[SIZE_BLOCK], int block);
int MFS_Read_SERVER(int inum, char buffer[SIZE_BLOCK], int block);
int MFS_Creat(int pinum, int type, char *name);
int MFS_Creat_SERVER(int pinum, int type, char *name);
int MFS_Unlink(int pinum, char *name);
int MFS_Unlink_SERVER(int pinum, char *name);
int MFS_Shutdown();
int MFS_Shutdown_SERVER();
#endif // __MFS_h__