Rev 2531 | Rev 2535 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2531 | Rev 2532 | ||
|---|---|---|---|
| Line 37... | Line 37... | ||
| 37 | 37 | ||
| 38 | #include <ipc/ipc.h> |
38 | #include <ipc/ipc.h> |
| 39 | #include <ipc/services.h> |
39 | #include <ipc/services.h> |
| 40 | #include <async.h> |
40 | #include <async.h> |
| 41 | #include <errno.h> |
41 | #include <errno.h> |
| - | 42 | #include <stdio.h> |
|
| 42 | #include <stdlib.h> |
43 | #include <stdlib.h> |
| 43 | #include <string.h> |
44 | #include <string.h> |
| 44 | #include <ctype.h> |
45 | #include <ctype.h> |
| 45 | #include <bool.h> |
46 | #include <bool.h> |
| 46 | #include <futex.h> |
47 | #include <futex.h> |
| 47 | #include <libadt/list.h> |
48 | #include <libadt/list.h> |
| 48 | #include "vfs.h" |
49 | #include "vfs.h" |
| 49 | 50 | ||
| - | 51 | ||
| - | 52 | #define dprintf(...) printf(__VA_ARGS__) |
|
| - | 53 | ||
| 50 | atomic_t fs_head_futex = FUTEX_INITIALIZER; |
54 | atomic_t fs_head_futex = FUTEX_INITIALIZER; |
| 51 | link_t fs_head; |
55 | link_t fs_head; |
| 52 | 56 | ||
| 53 | /** Verify the VFS info structure. |
57 | /** Verify the VFS info structure. |
| 54 | * |
58 | * |
| Line 62... | Line 66... | ||
| 62 | 66 | ||
| 63 | /* |
67 | /* |
| 64 | * Check if the name is non-empty and is composed solely of ASCII |
68 | * Check if the name is non-empty and is composed solely of ASCII |
| 65 | * characters [a-z]+[a-z0-9_-]*. |
69 | * characters [a-z]+[a-z0-9_-]*. |
| 66 | */ |
70 | */ |
| 67 | if (!islower(info->name[0])) |
71 | if (!islower(info->name[0])) { |
| - | 72 | dprintf("The name doesn't start with a lowercase character.\n"); |
|
| 68 | return false; |
73 | return false; |
| - | 74 | } |
|
| 69 | for (i = 1; i < FS_NAME_MAXLEN; i++) { |
75 | for (i = 1; i < FS_NAME_MAXLEN; i++) { |
| 70 | if (!(islower(info->name[i]) || isdigit(info->name[i])) && |
76 | if (!(islower(info->name[i]) || isdigit(info->name[i])) && |
| 71 | (info->name[i] != '-') && (info->name[i] != '_')) { |
77 | (info->name[i] != '-') && (info->name[i] != '_')) { |
| 72 | if (info->name[i] == '\0') |
78 | if (info->name[i] == '\0') { |
| 73 | break; |
79 | break; |
| 74 | else |
80 | } else { |
| - | 81 | dprintf("The name contains illegal " |
|
| - | 82 | "characters.\n"); |
|
| 75 | return false; |
83 | return false; |
| - | 84 | } |
|
| 76 | } |
85 | } |
| 77 | } |
86 | } |
| 78 | 87 | ||
| 79 | 88 | ||
| 80 | /* |
89 | /* |
| 81 | * Check if the FS implements mandatory VFS operations. |
90 | * Check if the FS implements mandatory VFS operations. |
| 82 | */ |
91 | */ |
| 83 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_REGISTER)] != VFS_OP_DEFINED) |
92 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_REGISTER)] != VFS_OP_DEFINED) { |
| - | 93 | dprintf("Operation VFS_REGISTER not defined by the client.\n"); |
|
| 84 | return false; |
94 | return false; |
| - | 95 | } |
|
| 85 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_MOUNT)] != VFS_OP_DEFINED) |
96 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_MOUNT)] != VFS_OP_DEFINED) { |
| - | 97 | dprintf("Operation VFS_MOUNT not defined by the client.\n"); |
|
| 86 | return false; |
98 | return false; |
| - | 99 | } |
|
| 87 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_UNMOUNT)] != VFS_OP_DEFINED) |
100 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_UNMOUNT)] != VFS_OP_DEFINED) { |
| - | 101 | dprintf("Operation VFS_UNMOUNT not defined by the client.\n"); |
|
| 88 | return false; |
102 | return false; |
| - | 103 | } |
|
| 89 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_LOOKUP)] != VFS_OP_DEFINED) |
104 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_LOOKUP)] != VFS_OP_DEFINED) { |
| - | 105 | dprintf("Operation VFS_LOOKUP not defined by the client.\n"); |
|
| 90 | return false; |
106 | return false; |
| - | 107 | } |
|
| 91 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_OPEN)] != VFS_OP_DEFINED) |
108 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_OPEN)] != VFS_OP_DEFINED) { |
| - | 109 | dprintf("Operation VFS_OPEN not defined by the client.\n"); |
|
| 92 | return false; |
110 | return false; |
| - | 111 | } |
|
| 93 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_CLOSE)] != VFS_OP_DEFINED) |
112 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_CLOSE)] != VFS_OP_DEFINED) { |
| - | 113 | dprintf("Operation VFS_CLOSE not defined by the client.\n"); |
|
| 94 | return false; |
114 | return false; |
| - | 115 | } |
|
| 95 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_READ)] != VFS_OP_DEFINED) |
116 | if (info->ops[IPC_METHOD_TO_VFS_OP(VFS_READ)] != VFS_OP_DEFINED) { |
| - | 117 | dprintf("Operation VFS_READ not defined by the client.\n"); |
|
| 96 | return false; |
118 | return false; |
| - | 119 | } |
|
| 97 | 120 | ||
| 98 | /* |
121 | /* |
| 99 | * Check if each operation is either not defined, defined or default. |
122 | * Check if each operation is either not defined, defined or default. |
| 100 | */ |
123 | */ |
| 101 | for (i = VFS_FIRST; i < VFS_LAST; i++) { |
124 | for (i = VFS_FIRST; i < VFS_LAST; i++) { |
| 102 | if ((IPC_METHOD_TO_VFS_OP(i) != VFS_OP_NULL) && |
125 | if ((info->ops[IPC_METHOD_TO_VFS_OP(i)] != VFS_OP_NULL) && |
| 103 | (IPC_METHOD_TO_VFS_OP(i) != VFS_OP_DEFAULT) && |
126 | (info->ops[IPC_METHOD_TO_VFS_OP(i)] != VFS_OP_DEFAULT) && |
| 104 | (IPC_METHOD_TO_VFS_OP(i) != VFS_OP_DEFINED)) |
127 | (info->ops[IPC_METHOD_TO_VFS_OP(i)] != VFS_OP_DEFINED)) { |
| - | 128 | dprintf("Operation info not understood.\n"); |
|
| 105 | return false; |
129 | return false; |
| - | 130 | } |
|
| 106 | } |
131 | } |
| 107 | return true; |
132 | return true; |
| 108 | } |
133 | } |
| 109 | 134 | ||
| 110 | /** VFS_REGISTER protocol function. |
135 | /** VFS_REGISTER protocol function. |
| Line 117... | Line 142... | ||
| 117 | ipc_callid_t callid; |
142 | ipc_callid_t callid; |
| 118 | ipc_call_t call; |
143 | ipc_call_t call; |
| 119 | int rc; |
144 | int rc; |
| 120 | size_t size; |
145 | size_t size; |
| 121 | 146 | ||
| - | 147 | dprintf("Processing VFS_REGISTER request received from %p.\n", |
|
| - | 148 | request->in_phone_hash); |
|
| - | 149 | ||
| 122 | /* |
150 | /* |
| 123 | * The first call has to be IPC_M_DATA_SEND in which we receive the |
151 | * The first call has to be IPC_M_DATA_SEND in which we receive the |
| 124 | * VFS info structure from the client FS. |
152 | * VFS info structure from the client FS. |
| 125 | */ |
153 | */ |
| 126 | if (!ipc_data_receive(&callid, &call, NULL, &size)) { |
154 | if (!ipc_data_receive(&callid, &call, NULL, &size)) { |
| 127 | /* |
155 | /* |
| 128 | * The client doesn't obey the same protocol as we do. |
156 | * The client doesn't obey the same protocol as we do. |
| 129 | */ |
157 | */ |
| - | 158 | dprintf("Receiving of VFS info failed.\n"); |
|
| 130 | ipc_answer_fast(callid, EINVAL, 0, 0); |
159 | ipc_answer_fast(callid, EINVAL, 0, 0); |
| 131 | ipc_answer_fast(rid, EINVAL, 0, 0); |
160 | ipc_answer_fast(rid, EINVAL, 0, 0); |
| 132 | return; |
161 | return; |
| 133 | } |
162 | } |
| 134 | 163 | ||
| - | 164 | dprintf("VFS info received, size = %d\n", size); |
|
| - | 165 | ||
| 135 | /* |
166 | /* |
| 136 | * We know the size of the VFS info structure. See if the client |
167 | * We know the size of the VFS info structure. See if the client |
| 137 | * understands this easy concept too. |
168 | * understands this easy concept too. |
| 138 | */ |
169 | */ |
| 139 | if (size != sizeof(vfs_info_t)) { |
170 | if (size != sizeof(vfs_info_t)) { |
| 140 | /* |
171 | /* |
| 141 | * The client is sending us something, which cannot be |
172 | * The client is sending us something, which cannot be |
| 142 | * the info structure. |
173 | * the info structure. |
| 143 | */ |
174 | */ |
| - | 175 | dprintf("Received VFS info has bad size.\n"); |
|
| 144 | ipc_answer_fast(callid, EINVAL, 0, 0); |
176 | ipc_answer_fast(callid, EINVAL, 0, 0); |
| 145 | ipc_answer_fast(rid, EINVAL, 0, 0); |
177 | ipc_answer_fast(rid, EINVAL, 0, 0); |
| 146 | return; |
178 | return; |
| 147 | } |
179 | } |
| 148 | fs_info_t *fs_info; |
180 | fs_info_t *fs_info; |
| Line 150... | Line 182... | ||
| 150 | /* |
182 | /* |
| 151 | * Allocate and initialize a buffer for the fs_info structure. |
183 | * Allocate and initialize a buffer for the fs_info structure. |
| 152 | */ |
184 | */ |
| 153 | fs_info = (fs_info_t *) malloc(sizeof(fs_info_t)); |
185 | fs_info = (fs_info_t *) malloc(sizeof(fs_info_t)); |
| 154 | if (!fs_info) { |
186 | if (!fs_info) { |
| - | 187 | dprintf("Could not allocate memory for FS info.\n"); |
|
| 155 | ipc_answer_fast(callid, ENOMEM, 0, 0); |
188 | ipc_answer_fast(callid, ENOMEM, 0, 0); |
| 156 | ipc_answer_fast(rid, ENOMEM, 0, 0); |
189 | ipc_answer_fast(rid, ENOMEM, 0, 0); |
| 157 | return; |
190 | return; |
| 158 | } |
191 | } |
| 159 | link_initialize(&fs_info->fs_link); |
192 | link_initialize(&fs_info->fs_link); |
| 160 | 193 | ||
| 161 | rc = ipc_data_deliver(callid, &call, &fs_info->vfs_info, size); |
194 | rc = ipc_data_deliver(callid, &call, &fs_info->vfs_info, size); |
| - | 195 | if (rc != EOK) { |
|
| - | 196 | dprintf("Failed to deliver the VFS info into our AS, rc=%d.\n", |
|
| 162 | if (!rc) { |
197 | rc); |
| 163 | free(fs_info); |
198 | free(fs_info); |
| 164 | ipc_answer_fast(callid, rc, 0, 0); |
199 | ipc_answer_fast(callid, rc, 0, 0); |
| 165 | ipc_answer_fast(rid, rc, 0, 0); |
200 | ipc_answer_fast(rid, rc, 0, 0); |
| 166 | return; |
201 | return; |
| 167 | } |
202 | } |
| - | 203 | ||
| - | 204 | dprintf("VFS info delivered.\n"); |
|
| 168 | 205 | ||
| 169 | if (!vfs_info_sane(&fs_info->vfs_info)) { |
206 | if (!vfs_info_sane(&fs_info->vfs_info)) { |
| 170 | free(fs_info); |
207 | free(fs_info); |
| 171 | ipc_answer_fast(callid, EINVAL, 0, 0); |
208 | ipc_answer_fast(callid, EINVAL, 0, 0); |
| 172 | ipc_answer_fast(rid, EINVAL, 0, 0); |
209 | ipc_answer_fast(rid, EINVAL, 0, 0); |
| Line 185... | Line 222... | ||
| 185 | /* TODO: replace strcmp with strncmp once we have it */ |
222 | /* TODO: replace strcmp with strncmp once we have it */ |
| 186 | if (strcmp(fs_info->vfs_info.name, fi->vfs_info.name) == 0) { |
223 | if (strcmp(fs_info->vfs_info.name, fi->vfs_info.name) == 0) { |
| 187 | /* |
224 | /* |
| 188 | * We already register a fs like this. |
225 | * We already register a fs like this. |
| 189 | */ |
226 | */ |
| - | 227 | dprintf("FS is already registered.\n"); |
|
| 190 | futex_up(&fs_head_futex); |
228 | futex_up(&fs_head_futex); |
| 191 | free(fs_info); |
229 | free(fs_info); |
| 192 | ipc_answer_fast(callid, EEXISTS, 0, 0); |
230 | ipc_answer_fast(callid, EEXISTS, 0, 0); |
| 193 | ipc_answer_fast(rid, EEXISTS, 0, 0); |
231 | ipc_answer_fast(rid, EEXISTS, 0, 0); |
| 194 | return; |
232 | return; |
| Line 196... | Line 234... | ||
| 196 | } |
234 | } |
| 197 | 235 | ||
| 198 | /* |
236 | /* |
| 199 | * Add fs_info to the list of registered FS's. |
237 | * Add fs_info to the list of registered FS's. |
| 200 | */ |
238 | */ |
| - | 239 | dprintf("Adding FS into the registered list.\n"); |
|
| 201 | list_append(&fs_info->fs_link, &fs_head); |
240 | list_append(&fs_info->fs_link, &fs_head); |
| 202 | 241 | ||
| 203 | /* |
242 | /* |
| 204 | * ACK receiving a properly formatted, non-duplicit vfs_info. |
243 | * ACK receiving a properly formatted, non-duplicit vfs_info. |
| 205 | */ |
244 | */ |
| Line 210... | Line 249... | ||
| 210 | * that a callback connection is created and we have a phone through |
249 | * that a callback connection is created and we have a phone through |
| 211 | * which to forward VFS requests to it. |
250 | * which to forward VFS requests to it. |
| 212 | */ |
251 | */ |
| 213 | callid = async_get_call(&call); |
252 | callid = async_get_call(&call); |
| 214 | if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { |
253 | if (IPC_GET_METHOD(call) != IPC_M_CONNECT_TO_ME) { |
| - | 254 | dprintf("Unexpected call, method = %d\n", IPC_GET_METHOD(call)); |
|
| 215 | list_remove(&fs_info->fs_link); |
255 | list_remove(&fs_info->fs_link); |
| 216 | futex_up(&fs_head_futex); |
256 | futex_up(&fs_head_futex); |
| 217 | free(fs_info); |
257 | free(fs_info); |
| 218 | ipc_answer_fast(callid, EINVAL, 0, 0); |
258 | ipc_answer_fast(callid, EINVAL, 0, 0); |
| 219 | ipc_answer_fast(rid, EINVAL, 0, 0); |
259 | ipc_answer_fast(rid, EINVAL, 0, 0); |
| 220 | return; |
260 | return; |
| 221 | } |
261 | } |
| 222 | fs_info->phone = IPC_GET_ARG3(call); |
262 | fs_info->phone = IPC_GET_ARG3(call); |
| 223 | ipc_answer_fast(callid, EOK, 0, 0); |
263 | ipc_answer_fast(callid, EOK, 0, 0); |
| 224 | 264 | ||
| - | 265 | dprintf("Callback connection to FS created.\n"); |
|
| - | 266 | ||
| 225 | futex_up(&fs_head_futex); |
267 | futex_up(&fs_head_futex); |
| 226 | 268 | ||
| 227 | /* |
269 | /* |
| 228 | * That was it. The FS has been registered. |
270 | * That was it. The FS has been registered. |
| 229 | */ |
271 | */ |
| 230 | ipc_answer_fast(rid, EOK, 0, 0); |
272 | ipc_answer_fast(rid, EOK, 0, 0); |
| - | 273 | dprintf("\"%s\" filesystem successfully registered.\n", |
|
| - | 274 | fs_info->vfs_info.name); |
|
| 231 | } |
275 | } |
| 232 | 276 | ||
| 233 | static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall) |
277 | static void vfs_connection(ipc_callid_t iid, ipc_call_t *icall) |
| 234 | { |
278 | { |
| 235 | bool keep_on_going = 1; |
279 | bool keep_on_going = 1; |
| 236 | 280 | ||
| - | 281 | printf("Connection opened from %p\n", icall->in_phone_hash); |
|
| - | 282 | ||
| 237 | /* |
283 | /* |
| 238 | * The connection was opened via the IPC_CONNECT_ME_TO call. |
284 | * The connection was opened via the IPC_CONNECT_ME_TO call. |
| 239 | * This call needs to be answered. |
285 | * This call needs to be answered. |
| 240 | */ |
286 | */ |
| 241 | ipc_answer_fast(iid, EOK, 0, 0); |
287 | ipc_answer_fast(iid, EOK, 0, 0); |
| Line 253... | Line 299... | ||
| 253 | while (keep_on_going) { |
299 | while (keep_on_going) { |
| 254 | ipc_callid_t callid; |
300 | ipc_callid_t callid; |
| 255 | ipc_call_t call; |
301 | ipc_call_t call; |
| 256 | 302 | ||
| 257 | callid = async_get_call(&call); |
303 | callid = async_get_call(&call); |
| - | 304 | ||
| - | 305 | printf("Received call, method=%d\n", IPC_GET_METHOD(call)); |
|
| 258 | 306 | ||
| 259 | switch (IPC_GET_METHOD(call)) { |
307 | switch (IPC_GET_METHOD(call)) { |
| 260 | case IPC_M_PHONE_HUNGUP: |
308 | case IPC_M_PHONE_HUNGUP: |
| 261 | keep_on_going = false; |
309 | keep_on_going = false; |
| 262 | break; |
310 | break; |
| Line 284... | Line 332... | ||
| 284 | 332 | ||
| 285 | int main(int argc, char **argv) |
333 | int main(int argc, char **argv) |
| 286 | { |
334 | { |
| 287 | ipcarg_t phonead; |
335 | ipcarg_t phonead; |
| 288 | 336 | ||
| - | 337 | printf("VFS: HelenOS VFS server\n"); |
|
| - | 338 | ||
| 289 | list_initialize(&fs_head); |
339 | list_initialize(&fs_head); |
| 290 | async_set_client_connection(vfs_connection); |
340 | async_set_client_connection(vfs_connection); |
| 291 | ipc_connect_to_me(PHONE_NS, SERVICE_VFS, 0, &phonead); |
341 | ipc_connect_to_me(PHONE_NS, SERVICE_VFS, 0, &phonead); |
| 292 | async_manager(); |
342 | async_manager(); |
| 293 | return 0; |
343 | return 0; |