• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 #ifndef FS_DEFS_H
13 #define FS_DEFS_H
14 
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <sys/statfs.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /* This file will be used in both `fsm`, client, server */
24 
25 #define AT_FDROOT           (-101)
26 #define FS_REQ_PATH_BUF_LEN (256)
27 #define FS_REQ_PATH_LEN     (255)
28 #define FS_BUF_SIZE         (IPC_SHM_AVAILABLE - sizeof(struct fs_request))
29 
30 /* IPC request type for fs */
31 enum fs_req_type {
32     FS_REQ_UNDEFINED = 0,
33 
34     FS_REQ_OPEN,
35     FS_REQ_CLOSE,
36 
37     FS_REQ_CREAT,
38     FS_REQ_MKDIR,
39     FS_REQ_RMDIR,
40     FS_REQ_SYMLINKAT,
41     FS_REQ_UNLINK,
42     FS_REQ_RENAME,
43     FS_REQ_READLINKAT,
44 
45     FS_REQ_READ,
46     FS_REQ_WRITE,
47 
48     FS_REQ_FSTAT,
49     FS_REQ_FSTATAT,
50     FS_REQ_STATFS,
51     FS_REQ_FSTATFS,
52 
53     FS_REQ_LSEEK,
54     FS_REQ_GETDENTS64,
55 
56     FS_REQ_FTRUNCATE,
57     FS_REQ_FALLOCATE,
58 
59     FS_REQ_FACCESSAT,
60 
61     FS_REQ_FCNTL,
62 
63 #ifdef CHCORE_ENABLE_FMAP
64     FS_REQ_FMAP, /* The first phase of mmap. */
65     FS_REQ_FUNMAP,
66 #endif
67 
68     FS_REQ_MOUNT,
69     FS_REQ_UMOUNT,
70 
71     FS_REQ_SYNC,
72     FS_REQ_FSYNC,
73     FS_REQ_FDATASYNC,
74 
75     FS_REQ_TEST_PERF, /* Test the page cache miss/hit count,disk I/O count
76                          . */
77 
78     FS_REQ_MAX
79 };
80 
81 /* Client send fsm_req to FSM */
82 enum fsm_req_type {
83     FSM_REQ_UNDEFINED = 0,
84 
85     FSM_REQ_PARSE_PATH,
86     FSM_REQ_MOUNT,
87     FSM_REQ_UMOUNT,
88 
89     FSM_REQ_SYNC,
90     /*
91      * Since procmgr is booted after fsm and fsm needs to send IPCs to
92      * procmgr, procmgr will issue the following IPC to connect itself with
93      * fsm.
94      */
95     FSM_REQ_CONNECT_PROCMGR_AND_FSM,
96 };
97 
98 #define FS_READ_BUF_SIZE \
99     (IPC_SHM_AVAILABLE - (u64)(&(((fs_request *)(0))->read_buff_begin)))
100 #define FS_WRITE_BUF_SIZE \
101     (IPC_SHM_AVAILABLE - (u64)(&(((fs_request *)(0))->write->write_buff_begin)))
102 
103 /* Clients send fs_request to fs_server */
104 struct fs_request {
105     enum fs_req_type req;
106     union {
107         struct {
108             int paritition;
109             off_t offset;
110         } mount;
111         struct {
112             int new_fd;
113             char pathname[FS_REQ_PATH_BUF_LEN];
114             int flags;
115             mode_t mode;
116             int fid;
117         } open;
118         struct {
119             char pathname[FS_REQ_PATH_BUF_LEN];
120             mode_t mode;
121         } creat;
122         struct {
123             int fd;
124         } close;
125         struct {
126             int fd;
127             size_t count;
128         } read;
129         struct {
130             int fd;
131             size_t count;
132             char write_buff_begin;
133         } write;
134         struct {
135             int fd;
136             off_t offset;
137             int whence;
138             /**
139              * For acquiring 64bit return value
140              * on 32bit architectures
141              */
142             off_t ret;
143         } lseek;
144         struct {
145             char pathname[FS_REQ_PATH_BUF_LEN];
146             mode_t mode;
147         } mkdir;
148         struct {
149             int fd;
150             off_t length;
151         } ftruncate;
152         struct {
153             int fd;
154             int dirfd;
155             char pathname[FS_REQ_PATH_BUF_LEN];
156             int flags;
157         } stat;
158         struct {
159             int fd;
160             mode_t mode;
161             off_t offset;
162             off_t len;
163         } fallocate;
164         struct {
165             int fd;
166             int fcntl_cmd;
167             int fcntl_arg;
168         } fcntl;
169         struct {
170             char pathname[FS_REQ_PATH_BUF_LEN];
171             int flags;
172         } unlink;
173         struct {
174             char pathname[FS_REQ_PATH_BUF_LEN];
175             int flags;
176         } rmdir;
177         struct {
178             char oldpath[FS_REQ_PATH_BUF_LEN];
179             char newpath[FS_REQ_PATH_BUF_LEN];
180         } rename;
181         struct {
182             int fd;
183         } fsync;
184         struct {
185             int fd;
186         } fdatasync;
187 #ifdef CHCORE_ENABLE_FMAP
188         struct {
189             void *addr;
190             size_t length;
191             int prot;
192             int flags;
193             int fd;
194             off_t offset;
195         } mmap;
196         struct {
197             void *addr;
198             size_t length;
199         } munmap;
200 #endif
201         struct {
202             int fd;
203             size_t count;
204         } getdents64;
205         struct {
206             char pathname[FS_REQ_PATH_BUF_LEN];
207             mode_t mode;
208             int flags;
209         } faccessat;
210         struct {
211             char target[FS_REQ_PATH_BUF_LEN];
212             char linkpath[FS_REQ_PATH_BUF_LEN];
213         } symlinkat;
214         struct {
215             char pathname[FS_REQ_PATH_BUF_LEN];
216             char buf[FS_REQ_PATH_BUF_LEN];
217             size_t bufsiz;
218         } readlinkat;
219     };
220 };
221 
222 struct fsm_request {
223     /* Request Type */
224     enum fsm_req_type req;
225 
226     /* Arguments */
227     // Means `path to parse` in normal cases. `device_name` for
228     // FSM_REQ_MOUNT/UMOUNT
229     char path[FS_REQ_PATH_BUF_LEN];
230     int path_len;
231 
232     /* Arguments or Response */
233     // As arguements when FSM_REQ_MOUNT/UMOUNT, as reponse when
234     // FSM_REQ_PARSE_PATH
235     char mount_path[FS_REQ_PATH_BUF_LEN];
236     int mount_path_len;
237 
238     /* Response */
239     int mount_id;
240     int new_cap_flag;
241 };
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 
247 #endif /* FS_DEFS_H */