Rev 4581 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4581 | Rev 4718 | ||
---|---|---|---|
Line 36... | Line 36... | ||
36 | #include <vfs/canonify.h> |
36 | #include <vfs/canonify.h> |
37 | #include <stdlib.h> |
37 | #include <stdlib.h> |
38 | #include <unistd.h> |
38 | #include <unistd.h> |
39 | #include <dirent.h> |
39 | #include <dirent.h> |
40 | #include <fcntl.h> |
40 | #include <fcntl.h> |
41 | #include <sys/stat.h> |
- | |
42 | #include <stdio.h> |
41 | #include <stdio.h> |
- | 42 | #include <sys/stat.h> |
|
43 | #include <sys/types.h> |
43 | #include <sys/types.h> |
44 | #include <ipc/ipc.h> |
44 | #include <ipc/ipc.h> |
45 | #include <ipc/services.h> |
45 | #include <ipc/services.h> |
46 | #include <async.h> |
46 | #include <async.h> |
47 | #include <atomic.h> |
47 | #include <atomic.h> |
Line 135... | Line 135... | ||
135 | 135 | ||
136 | futex_down(&vfs_phone_futex); |
136 | futex_down(&vfs_phone_futex); |
137 | async_serialize_start(); |
137 | async_serialize_start(); |
138 | vfs_connect(); |
138 | vfs_connect(); |
139 | 139 | ||
140 | req = async_send_2(vfs_phone, VFS_MOUNT, dev_handle, flags, NULL); |
140 | req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL); |
141 | rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_size); |
141 | rc = ipc_data_write_start(vfs_phone, (void *) mpa, mpa_size); |
142 | if (rc != EOK) { |
142 | if (rc != EOK) { |
143 | async_wait_for(req, NULL); |
143 | async_wait_for(req, NULL); |
144 | async_serialize_end(); |
144 | async_serialize_end(); |
145 | futex_up(&vfs_phone_futex); |
145 | futex_up(&vfs_phone_futex); |
Line 196... | Line 196... | ||
196 | 196 | ||
197 | futex_down(&vfs_phone_futex); |
197 | futex_down(&vfs_phone_futex); |
198 | async_serialize_start(); |
198 | async_serialize_start(); |
199 | vfs_connect(); |
199 | vfs_connect(); |
200 | 200 | ||
201 | req = async_send_3(vfs_phone, VFS_OPEN, lflag, oflag, 0, &answer); |
201 | req = async_send_3(vfs_phone, VFS_IN_OPEN, lflag, oflag, 0, &answer); |
202 | rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
202 | rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
203 | if (rc != EOK) { |
203 | if (rc != EOK) { |
204 | async_wait_for(req, NULL); |
204 | async_wait_for(req, NULL); |
205 | async_serialize_end(); |
205 | async_serialize_end(); |
206 | futex_up(&vfs_phone_futex); |
206 | futex_up(&vfs_phone_futex); |
Line 228... | Line 228... | ||
228 | futex_down(&vfs_phone_futex); |
228 | futex_down(&vfs_phone_futex); |
229 | async_serialize_start(); |
229 | async_serialize_start(); |
230 | vfs_connect(); |
230 | vfs_connect(); |
231 | 231 | ||
232 | ipc_call_t answer; |
232 | ipc_call_t answer; |
233 | aid_t req = async_send_4(vfs_phone, VFS_OPEN_NODE, node->fs_handle, |
233 | aid_t req = async_send_4(vfs_phone, VFS_IN_OPEN_NODE, node->fs_handle, |
234 | node->dev_handle, node->index, oflag, &answer); |
234 | node->dev_handle, node->index, oflag, &answer); |
235 | 235 | ||
236 | ipcarg_t rc; |
236 | ipcarg_t rc; |
237 | async_wait_for(req, &rc); |
237 | async_wait_for(req, &rc); |
238 | async_serialize_end(); |
238 | async_serialize_end(); |
Line 250... | Line 250... | ||
250 | 250 | ||
251 | futex_down(&vfs_phone_futex); |
251 | futex_down(&vfs_phone_futex); |
252 | async_serialize_start(); |
252 | async_serialize_start(); |
253 | vfs_connect(); |
253 | vfs_connect(); |
254 | 254 | ||
255 | rc = async_req_1_0(vfs_phone, VFS_CLOSE, fildes); |
255 | rc = async_req_1_0(vfs_phone, VFS_IN_CLOSE, fildes); |
256 | 256 | ||
257 | async_serialize_end(); |
257 | async_serialize_end(); |
258 | futex_up(&vfs_phone_futex); |
258 | futex_up(&vfs_phone_futex); |
259 | 259 | ||
260 | return (int)rc; |
260 | return (int)rc; |
Line 268... | Line 268... | ||
268 | 268 | ||
269 | futex_down(&vfs_phone_futex); |
269 | futex_down(&vfs_phone_futex); |
270 | async_serialize_start(); |
270 | async_serialize_start(); |
271 | vfs_connect(); |
271 | vfs_connect(); |
272 | 272 | ||
273 | req = async_send_1(vfs_phone, VFS_READ, fildes, &answer); |
273 | req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer); |
274 | rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte); |
274 | rc = ipc_data_read_start(vfs_phone, (void *)buf, nbyte); |
275 | if (rc != EOK) { |
275 | if (rc != EOK) { |
276 | async_wait_for(req, NULL); |
276 | async_wait_for(req, NULL); |
277 | async_serialize_end(); |
277 | async_serialize_end(); |
278 | futex_up(&vfs_phone_futex); |
278 | futex_up(&vfs_phone_futex); |
Line 295... | Line 295... | ||
295 | 295 | ||
296 | futex_down(&vfs_phone_futex); |
296 | futex_down(&vfs_phone_futex); |
297 | async_serialize_start(); |
297 | async_serialize_start(); |
298 | vfs_connect(); |
298 | vfs_connect(); |
299 | 299 | ||
300 | req = async_send_1(vfs_phone, VFS_WRITE, fildes, &answer); |
300 | req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer); |
301 | rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte); |
301 | rc = ipc_data_write_start(vfs_phone, (void *)buf, nbyte); |
302 | if (rc != EOK) { |
302 | if (rc != EOK) { |
303 | async_wait_for(req, NULL); |
303 | async_wait_for(req, NULL); |
304 | async_serialize_end(); |
304 | async_serialize_end(); |
305 | futex_up(&vfs_phone_futex); |
305 | futex_up(&vfs_phone_futex); |
Line 312... | Line 312... | ||
312 | return (ssize_t) IPC_GET_ARG1(answer); |
312 | return (ssize_t) IPC_GET_ARG1(answer); |
313 | else |
313 | else |
314 | return -1; |
314 | return -1; |
315 | } |
315 | } |
316 | 316 | ||
317 | int fd_phone(int fildes) |
317 | int fsync(int fildes) |
318 | { |
318 | { |
319 | futex_down(&vfs_phone_futex); |
319 | futex_down(&vfs_phone_futex); |
320 | async_serialize_start(); |
320 | async_serialize_start(); |
321 | vfs_connect(); |
321 | vfs_connect(); |
322 | 322 | ||
323 | ipcarg_t device; |
- | |
324 | ipcarg_t rc = async_req_1_1(vfs_phone, VFS_DEVICE, fildes, &device); |
323 | ipcarg_t rc = async_req_1_0(vfs_phone, VFS_IN_SYNC, fildes); |
325 | 324 | ||
326 | async_serialize_end(); |
325 | async_serialize_end(); |
327 | futex_up(&vfs_phone_futex); |
326 | futex_up(&vfs_phone_futex); |
328 | 327 | ||
329 | if (rc != EOK) |
- | |
330 | return -1; |
328 | return (int) rc; |
331 | - | ||
332 | return devmap_device_connect((dev_handle_t) device, 0); |
- | |
333 | } |
329 | } |
334 | 330 | ||
335 | int fd_node(int fildes, fdi_node_t *node) |
331 | off_t lseek(int fildes, off_t offset, int whence) |
336 | { |
332 | { |
- | 333 | ipcarg_t rc; |
|
- | 334 | ||
337 | futex_down(&vfs_phone_futex); |
335 | futex_down(&vfs_phone_futex); |
338 | async_serialize_start(); |
336 | async_serialize_start(); |
339 | vfs_connect(); |
337 | vfs_connect(); |
340 | 338 | ||
341 | ipcarg_t fs_handle; |
- | |
342 | ipcarg_t dev_handle; |
- | |
343 | ipcarg_t index; |
339 | ipcarg_t newoffs; |
344 | ipcarg_t rc = async_req_1_3(vfs_phone, VFS_NODE, fildes, &fs_handle, |
340 | rc = async_req_3_1(vfs_phone, VFS_IN_SEEK, fildes, offset, whence, |
345 | &dev_handle, &index); |
341 | &newoffs); |
346 | 342 | ||
347 | async_serialize_end(); |
343 | async_serialize_end(); |
348 | futex_up(&vfs_phone_futex); |
344 | futex_up(&vfs_phone_futex); |
- | 345 | ||
- | 346 | if (rc != EOK) |
|
- | 347 | return (off_t) -1; |
|
349 | 348 | ||
350 | if (rc == EOK) { |
- | |
351 | node->fs_handle = (fs_handle_t) fs_handle; |
- | |
352 | node->dev_handle = (dev_handle_t) dev_handle; |
- | |
353 | node->index = (fs_index_t) index; |
- | |
354 | } |
- | |
355 | - | ||
356 | return rc; |
349 | return (off_t) newoffs; |
357 | } |
350 | } |
358 | 351 | ||
359 | int fsync(int fildes) |
352 | int ftruncate(int fildes, off_t length) |
360 | { |
353 | { |
- | 354 | ipcarg_t rc; |
|
- | 355 | ||
361 | futex_down(&vfs_phone_futex); |
356 | futex_down(&vfs_phone_futex); |
362 | async_serialize_start(); |
357 | async_serialize_start(); |
363 | vfs_connect(); |
358 | vfs_connect(); |
364 | 359 | ||
365 | ipcarg_t rc = async_req_1_0(vfs_phone, VFS_SYNC, fildes); |
360 | rc = async_req_2_0(vfs_phone, VFS_IN_TRUNCATE, fildes, length); |
366 | - | ||
367 | async_serialize_end(); |
361 | async_serialize_end(); |
368 | futex_up(&vfs_phone_futex); |
362 | futex_up(&vfs_phone_futex); |
369 | - | ||
370 | return (int) rc; |
363 | return (int) rc; |
371 | } |
364 | } |
372 | 365 | ||
373 | off_t lseek(int fildes, off_t offset, int whence) |
366 | int fstat(int fildes, struct stat *stat) |
374 | { |
367 | { |
375 | ipcarg_t rc; |
368 | ipcarg_t rc; |
- | 369 | aid_t req; |
|
376 | 370 | ||
377 | futex_down(&vfs_phone_futex); |
371 | futex_down(&vfs_phone_futex); |
378 | async_serialize_start(); |
372 | async_serialize_start(); |
379 | vfs_connect(); |
373 | vfs_connect(); |
380 | 374 | ||
- | 375 | req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL); |
|
- | 376 | rc = ipc_data_read_start(vfs_phone, (void *)stat, sizeof(struct stat)); |
|
381 | ipcarg_t newoffs; |
377 | if (rc != EOK) { |
- | 378 | async_wait_for(req, NULL); |
|
- | 379 | async_serialize_end(); |
|
382 | rc = async_req_3_1(vfs_phone, VFS_SEEK, fildes, offset, whence, |
380 | futex_up(&vfs_phone_futex); |
383 | &newoffs); |
381 | return (ssize_t) rc; |
384 | 382 | } |
|
- | 383 | async_wait_for(req, &rc); |
|
385 | async_serialize_end(); |
384 | async_serialize_end(); |
386 | futex_up(&vfs_phone_futex); |
385 | futex_up(&vfs_phone_futex); |
387 | 386 | ||
388 | if (rc != EOK) |
- | |
389 | return (off_t) -1; |
387 | return rc; |
390 | - | ||
391 | return (off_t) newoffs; |
- | |
392 | } |
388 | } |
393 | 389 | ||
394 | int ftruncate(int fildes, off_t length) |
390 | int stat(const char *path, struct stat *stat) |
395 | { |
391 | { |
396 | ipcarg_t rc; |
392 | ipcarg_t rc; |
- | 393 | aid_t req; |
|
- | 394 | ||
- | 395 | size_t pa_size; |
|
- | 396 | char *pa = absolutize(path, &pa_size); |
|
- | 397 | if (!pa) |
|
- | 398 | return ENOMEM; |
|
397 | 399 | ||
398 | futex_down(&vfs_phone_futex); |
400 | futex_down(&vfs_phone_futex); |
399 | async_serialize_start(); |
401 | async_serialize_start(); |
400 | vfs_connect(); |
402 | vfs_connect(); |
401 | 403 | ||
402 | rc = async_req_2_0(vfs_phone, VFS_TRUNCATE, fildes, length); |
404 | req = async_send_0(vfs_phone, VFS_IN_STAT, NULL); |
- | 405 | rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
|
- | 406 | if (rc != EOK) { |
|
- | 407 | async_wait_for(req, NULL); |
|
- | 408 | async_serialize_end(); |
|
- | 409 | futex_up(&vfs_phone_futex); |
|
- | 410 | free(pa); |
|
- | 411 | return (int) rc; |
|
- | 412 | } |
|
- | 413 | rc = ipc_data_read_start(vfs_phone, stat, sizeof(struct stat)); |
|
- | 414 | if (rc != EOK) { |
|
- | 415 | async_wait_for(req, NULL); |
|
- | 416 | async_serialize_end(); |
|
- | 417 | futex_up(&vfs_phone_futex); |
|
- | 418 | free(pa); |
|
- | 419 | return (int) rc; |
|
- | 420 | } |
|
- | 421 | async_wait_for(req, &rc); |
|
403 | async_serialize_end(); |
422 | async_serialize_end(); |
404 | futex_up(&vfs_phone_futex); |
423 | futex_up(&vfs_phone_futex); |
- | 424 | free(pa); |
|
405 | return (int) rc; |
425 | return rc; |
406 | } |
426 | } |
407 | 427 | ||
408 | DIR *opendir(const char *dirname) |
428 | DIR *opendir(const char *dirname) |
409 | { |
429 | { |
410 | DIR *dirp = malloc(sizeof(DIR)); |
430 | DIR *dirp = malloc(sizeof(DIR)); |
Line 450... | Line 470... | ||
450 | 470 | ||
451 | futex_down(&vfs_phone_futex); |
471 | futex_down(&vfs_phone_futex); |
452 | async_serialize_start(); |
472 | async_serialize_start(); |
453 | vfs_connect(); |
473 | vfs_connect(); |
454 | 474 | ||
455 | req = async_send_1(vfs_phone, VFS_MKDIR, mode, NULL); |
475 | req = async_send_1(vfs_phone, VFS_IN_MKDIR, mode, NULL); |
456 | rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
476 | rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
457 | if (rc != EOK) { |
477 | if (rc != EOK) { |
458 | async_wait_for(req, NULL); |
478 | async_wait_for(req, NULL); |
459 | async_serialize_end(); |
479 | async_serialize_end(); |
460 | futex_up(&vfs_phone_futex); |
480 | futex_up(&vfs_phone_futex); |
Line 480... | Line 500... | ||
480 | 500 | ||
481 | futex_down(&vfs_phone_futex); |
501 | futex_down(&vfs_phone_futex); |
482 | async_serialize_start(); |
502 | async_serialize_start(); |
483 | vfs_connect(); |
503 | vfs_connect(); |
484 | 504 | ||
485 | req = async_send_0(vfs_phone, VFS_UNLINK, NULL); |
505 | req = async_send_0(vfs_phone, VFS_IN_UNLINK, NULL); |
486 | rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
506 | rc = ipc_data_write_start(vfs_phone, pa, pa_size); |
487 | if (rc != EOK) { |
507 | if (rc != EOK) { |
488 | async_wait_for(req, NULL); |
508 | async_wait_for(req, NULL); |
489 | async_serialize_end(); |
509 | async_serialize_end(); |
490 | futex_up(&vfs_phone_futex); |
510 | futex_up(&vfs_phone_futex); |
Line 527... | Line 547... | ||
527 | 547 | ||
528 | futex_down(&vfs_phone_futex); |
548 | futex_down(&vfs_phone_futex); |
529 | async_serialize_start(); |
549 | async_serialize_start(); |
530 | vfs_connect(); |
550 | vfs_connect(); |
531 | 551 | ||
532 | req = async_send_0(vfs_phone, VFS_RENAME, NULL); |
552 | req = async_send_0(vfs_phone, VFS_IN_RENAME, NULL); |
533 | rc = ipc_data_write_start(vfs_phone, olda, olda_size); |
553 | rc = ipc_data_write_start(vfs_phone, olda, olda_size); |
534 | if (rc != EOK) { |
554 | if (rc != EOK) { |
535 | async_wait_for(req, NULL); |
555 | async_wait_for(req, NULL); |
536 | async_serialize_end(); |
556 | async_serialize_end(); |
537 | futex_up(&vfs_phone_futex); |
557 | futex_up(&vfs_phone_futex); |
Line 596... | Line 616... | ||
596 | str_cpy(buf, size, cwd_path); |
616 | str_cpy(buf, size, cwd_path); |
597 | futex_up(&cwd_futex); |
617 | futex_up(&cwd_futex); |
598 | return buf; |
618 | return buf; |
599 | } |
619 | } |
600 | 620 | ||
- | 621 | int fd_phone(int fildes) |
|
- | 622 | { |
|
- | 623 | struct stat stat; |
|
- | 624 | int rc; |
|
- | 625 | ||
- | 626 | rc = fstat(fildes, &stat); |
|
- | 627 | ||
- | 628 | if (!stat.devfs_stat.device) |
|
- | 629 | return -1; |
|
- | 630 | ||
- | 631 | return devmap_device_connect(stat.devfs_stat.device, 0); |
|
- | 632 | } |
|
- | 633 | ||
- | 634 | int fd_node(int fildes, fdi_node_t *node) |
|
- | 635 | { |
|
- | 636 | struct stat stat; |
|
- | 637 | int rc; |
|
- | 638 | ||
- | 639 | rc = fstat(fildes, &stat); |
|
- | 640 | ||
- | 641 | if (rc == EOK) { |
|
- | 642 | node->fs_handle = stat.fs_handle; |
|
- | 643 | node->dev_handle = stat.dev_handle; |
|
- | 644 | node->index = stat.index; |
|
- | 645 | } |
|
- | 646 | ||
- | 647 | return rc; |
|
- | 648 | } |
|
- | 649 | ||
601 | /** @} |
650 | /** @} |
602 | */ |
651 | */ |