Rev 4443 | Rev 4463 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 4443 | Rev 4445 | ||
|---|---|---|---|
| Line 484... | Line 484... | ||
| 484 | free(opts); |
484 | free(opts); |
| 485 | } |
485 | } |
| 486 | 486 | ||
| 487 | void vfs_open(ipc_callid_t rid, ipc_call_t *request) |
487 | void vfs_open(ipc_callid_t rid, ipc_call_t *request) |
| 488 | { |
488 | { |
| 489 | async_serialize_start(); |
- | |
| 490 | - | ||
| 491 | if (!vfs_files_init()) { |
489 | if (!vfs_files_init()) { |
| 492 | ipc_answer_0(rid, ENOMEM); |
490 | ipc_answer_0(rid, ENOMEM); |
| 493 | async_serialize_end(); |
- | |
| 494 | return; |
491 | return; |
| 495 | } |
492 | } |
| 496 | 493 | ||
| 497 | /* |
494 | /* |
| 498 | * The POSIX interface is open(path, oflag, mode). |
495 | * The POSIX interface is open(path, oflag, mode). |
| Line 512... | Line 509... | ||
| 512 | * L_DIRECTORY. |
509 | * L_DIRECTORY. |
| 513 | */ |
510 | */ |
| 514 | if ((lflag & (L_FILE | L_DIRECTORY)) == 0 || |
511 | if ((lflag & (L_FILE | L_DIRECTORY)) == 0 || |
| 515 | (lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) { |
512 | (lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) { |
| 516 | ipc_answer_0(rid, EINVAL); |
513 | ipc_answer_0(rid, EINVAL); |
| 517 | async_serialize_end(); |
- | |
| 518 | return; |
514 | return; |
| 519 | } |
515 | } |
| 520 | 516 | ||
| 521 | if (oflag & O_CREAT) |
517 | if (oflag & O_CREAT) |
| 522 | lflag |= L_CREATE; |
518 | lflag |= L_CREATE; |
| Line 526... | Line 522... | ||
| 526 | ipc_callid_t callid; |
522 | ipc_callid_t callid; |
| 527 | 523 | ||
| 528 | if (!ipc_data_write_receive(&callid, &len)) { |
524 | if (!ipc_data_write_receive(&callid, &len)) { |
| 529 | ipc_answer_0(callid, EINVAL); |
525 | ipc_answer_0(callid, EINVAL); |
| 530 | ipc_answer_0(rid, EINVAL); |
526 | ipc_answer_0(rid, EINVAL); |
| 531 | async_serialize_end(); |
- | |
| 532 | return; |
527 | return; |
| 533 | } |
528 | } |
| 534 | char *path = malloc(len + 1); |
529 | char *path = malloc(len + 1); |
| 535 | if (!path) { |
530 | if (!path) { |
| 536 | ipc_answer_0(callid, ENOMEM); |
531 | ipc_answer_0(callid, ENOMEM); |
| 537 | ipc_answer_0(rid, ENOMEM); |
532 | ipc_answer_0(rid, ENOMEM); |
| 538 | async_serialize_end(); |
- | |
| 539 | return; |
533 | return; |
| 540 | } |
534 | } |
| 541 | int rc; |
535 | int rc; |
| 542 | if ((rc = ipc_data_write_finalize(callid, path, len))) { |
536 | if ((rc = ipc_data_write_finalize(callid, path, len))) { |
| 543 | ipc_answer_0(rid, rc); |
537 | ipc_answer_0(rid, rc); |
| 544 | free(path); |
538 | free(path); |
| 545 | async_serialize_end(); |
- | |
| 546 | return; |
539 | return; |
| 547 | } |
540 | } |
| 548 | path[len] = '\0'; |
541 | path[len] = '\0'; |
| 549 | 542 | ||
| 550 | /* |
543 | /* |
| Line 565... | Line 558... | ||
| 565 | rwlock_write_unlock(&namespace_rwlock); |
558 | rwlock_write_unlock(&namespace_rwlock); |
| 566 | else |
559 | else |
| 567 | rwlock_read_unlock(&namespace_rwlock); |
560 | rwlock_read_unlock(&namespace_rwlock); |
| 568 | ipc_answer_0(rid, rc); |
561 | ipc_answer_0(rid, rc); |
| 569 | free(path); |
562 | free(path); |
| 570 | async_serialize_end(); |
- | |
| 571 | return; |
563 | return; |
| 572 | } |
564 | } |
| 573 | 565 | ||
| 574 | /* Path is no longer needed. */ |
566 | /* Path is no longer needed. */ |
| 575 | free(path); |
567 | free(path); |
| Line 588... | Line 580... | ||
| 588 | node->dev_handle, node->index, 0); |
580 | node->dev_handle, node->index, 0); |
| 589 | if (rc) { |
581 | if (rc) { |
| 590 | rwlock_write_unlock(&node->contents_rwlock); |
582 | rwlock_write_unlock(&node->contents_rwlock); |
| 591 | vfs_node_put(node); |
583 | vfs_node_put(node); |
| 592 | ipc_answer_0(rid, rc); |
584 | ipc_answer_0(rid, rc); |
| 593 | async_serialize_end(); |
- | |
| 594 | return; |
585 | return; |
| 595 | } |
586 | } |
| 596 | node->size = 0; |
587 | node->size = 0; |
| 597 | } |
588 | } |
| 598 | rwlock_write_unlock(&node->contents_rwlock); |
589 | rwlock_write_unlock(&node->contents_rwlock); |
| Line 604... | Line 595... | ||
| 604 | */ |
595 | */ |
| 605 | int fd = vfs_fd_alloc(); |
596 | int fd = vfs_fd_alloc(); |
| 606 | if (fd < 0) { |
597 | if (fd < 0) { |
| 607 | vfs_node_put(node); |
598 | vfs_node_put(node); |
| 608 | ipc_answer_0(rid, fd); |
599 | ipc_answer_0(rid, fd); |
| 609 | async_serialize_end(); |
- | |
| 610 | return; |
600 | return; |
| 611 | } |
601 | } |
| 612 | vfs_file_t *file = vfs_file_get(fd); |
602 | vfs_file_t *file = vfs_file_get(fd); |
| 613 | file->node = node; |
603 | file->node = node; |
| 614 | if (oflag & O_APPEND) |
604 | if (oflag & O_APPEND) |
| Line 624... | Line 614... | ||
| 624 | vfs_node_addref(node); |
614 | vfs_node_addref(node); |
| 625 | vfs_node_put(node); |
615 | vfs_node_put(node); |
| 626 | 616 | ||
| 627 | /* Success! Return the new file descriptor to the client. */ |
617 | /* Success! Return the new file descriptor to the client. */ |
| 628 | ipc_answer_1(rid, EOK, fd); |
618 | ipc_answer_1(rid, EOK, fd); |
| 629 | async_serialize_end(); |
- | |
| 630 | } |
619 | } |
| 631 | 620 | ||
| 632 | void vfs_close(ipc_callid_t rid, ipc_call_t *request) |
621 | void vfs_close(ipc_callid_t rid, ipc_call_t *request) |
| 633 | { |
622 | { |
| 634 | int fd = IPC_GET_ARG1(*request); |
623 | int fd = IPC_GET_ARG1(*request); |