Changes in uspace/srv/vfs/vfs_ops.c [1882525:ccca251] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_ops.c
r1882525 rccca251 37 37 38 38 #include "vfs.h" 39 #include <ipc/ipc.h>40 39 #include <macros.h> 41 40 #include <stdint.h> … … 55 54 56 55 /* Forward declarations of static functions. */ 57 static int vfs_truncate_internal(fs_handle_t, dev_handle_t, fs_index_t, aoff64_t); 56 static int vfs_truncate_internal(fs_handle_t, devmap_handle_t, fs_index_t, 57 aoff64_t); 58 58 59 59 /** … … 65 65 vfs_pair_t rootfs = { 66 66 .fs_handle = 0, 67 .dev _handle = 067 .devmap_handle = 0 68 68 }; 69 69 70 static void vfs_mount_internal(ipc_callid_t rid, dev _handle_t dev_handle,70 static void vfs_mount_internal(ipc_callid_t rid, devmap_handle_t devmap_handle, 71 71 fs_handle_t fs_handle, char *mp, char *opts) 72 72 { … … 78 78 size_t rsize; 79 79 unsigned rlnkcnt; 80 ipcarg_t rc;80 sysarg_t rc; 81 81 int phone; 82 82 aid_t msg; … … 90 90 /* Trying to mount root FS over root FS */ 91 91 fibril_rwlock_write_unlock(&namespace_rwlock); 92 ipc_answer_0(rid, EBUSY);92 async_answer_0(rid, EBUSY); 93 93 return; 94 94 } … … 98 98 /* The lookup failed for some reason. */ 99 99 fibril_rwlock_write_unlock(&namespace_rwlock); 100 ipc_answer_0(rid, rc);100 async_answer_0(rid, rc); 101 101 return; 102 102 } … … 105 105 if (!mp_node) { 106 106 fibril_rwlock_write_unlock(&namespace_rwlock); 107 ipc_answer_0(rid, ENOMEM);107 async_answer_0(rid, ENOMEM); 108 108 return; 109 109 } … … 125 125 phone = vfs_grab_phone(fs_handle); 126 126 msg = async_send_1(phone, VFS_OUT_MOUNTED, 127 ( ipcarg_t) dev_handle, &answer);127 (sysarg_t) devmap_handle, &answer); 128 128 /* send the mount options */ 129 129 rc = async_data_write_start(phone, (void *)opts, … … 131 131 if (rc != EOK) { 132 132 async_wait_for(msg, NULL); 133 vfs_release_phone( phone);133 vfs_release_phone(fs_handle, phone); 134 134 fibril_rwlock_write_unlock(&namespace_rwlock); 135 ipc_answer_0(rid, rc);135 async_answer_0(rid, rc); 136 136 return; 137 137 } 138 138 async_wait_for(msg, &rc); 139 vfs_release_phone( phone);139 vfs_release_phone(fs_handle, phone); 140 140 141 141 if (rc != EOK) { 142 142 fibril_rwlock_write_unlock(&namespace_rwlock); 143 ipc_answer_0(rid, rc);143 async_answer_0(rid, rc); 144 144 return; 145 145 } … … 150 150 151 151 mr_res.triplet.fs_handle = fs_handle; 152 mr_res.triplet.dev _handle = dev_handle;152 mr_res.triplet.devmap_handle = devmap_handle; 153 153 mr_res.triplet.index = rindex; 154 154 mr_res.size = rsize; … … 157 157 158 158 rootfs.fs_handle = fs_handle; 159 rootfs.dev _handle = dev_handle;159 rootfs.devmap_handle = devmap_handle; 160 160 161 161 /* Add reference to the mounted root. */ … … 164 164 165 165 fibril_rwlock_write_unlock(&namespace_rwlock); 166 ipc_answer_0(rid, rc);166 async_answer_0(rid, rc); 167 167 return; 168 168 } else { … … 172 172 */ 173 173 fibril_rwlock_write_unlock(&namespace_rwlock); 174 ipc_answer_0(rid, ENOENT);174 async_answer_0(rid, ENOENT); 175 175 return; 176 176 } … … 187 187 phone = vfs_grab_phone(mp_res.triplet.fs_handle); 188 188 msg = async_send_4(phone, VFS_OUT_MOUNT, 189 ( ipcarg_t) mp_res.triplet.dev_handle,190 ( ipcarg_t) mp_res.triplet.index,191 ( ipcarg_t) fs_handle,192 ( ipcarg_t) dev_handle, &answer);189 (sysarg_t) mp_res.triplet.devmap_handle, 190 (sysarg_t) mp_res.triplet.index, 191 (sysarg_t) fs_handle, 192 (sysarg_t) devmap_handle, &answer); 193 193 194 194 /* send connection */ … … 196 196 if (rc != EOK) { 197 197 async_wait_for(msg, NULL); 198 vfs_release_phone( mountee_phone);199 vfs_release_phone( phone);198 vfs_release_phone(fs_handle, mountee_phone); 199 vfs_release_phone(mp_res.triplet.fs_handle, phone); 200 200 /* Mount failed, drop reference to mp_node. */ 201 201 if (mp_node) 202 202 vfs_node_put(mp_node); 203 ipc_answer_0(rid, rc);203 async_answer_0(rid, rc); 204 204 fibril_rwlock_write_unlock(&namespace_rwlock); 205 205 return; 206 206 } 207 207 208 vfs_release_phone( mountee_phone);208 vfs_release_phone(fs_handle, mountee_phone); 209 209 210 210 /* send the mount options */ … … 212 212 if (rc != EOK) { 213 213 async_wait_for(msg, NULL); 214 vfs_release_phone( phone);214 vfs_release_phone(mp_res.triplet.fs_handle, phone); 215 215 /* Mount failed, drop reference to mp_node. */ 216 216 if (mp_node) 217 217 vfs_node_put(mp_node); 218 218 fibril_rwlock_write_unlock(&namespace_rwlock); 219 ipc_answer_0(rid, rc);219 async_answer_0(rid, rc); 220 220 return; 221 221 } 222 222 async_wait_for(msg, &rc); 223 vfs_release_phone( phone);223 vfs_release_phone(mp_res.triplet.fs_handle, phone); 224 224 225 225 if (rc == EOK) { … … 229 229 230 230 mr_res.triplet.fs_handle = fs_handle; 231 mr_res.triplet.dev _handle = dev_handle;231 mr_res.triplet.devmap_handle = devmap_handle; 232 232 mr_res.triplet.index = rindex; 233 233 mr_res.size = rsize; … … 244 244 } 245 245 246 ipc_answer_0(rid, rc);246 async_answer_0(rid, rc); 247 247 fibril_rwlock_write_unlock(&namespace_rwlock); 248 248 } … … 250 250 void vfs_mount(ipc_callid_t rid, ipc_call_t *request) 251 251 { 252 devmap_handle_t devmap_handle; 253 252 254 /* 253 255 * We expect the library to do the device-name to device-handle … … 255 257 * in the request. 256 258 */ 257 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);259 devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 258 260 259 261 /* … … 272 274 0, NULL); 273 275 if (rc != EOK) { 274 ipc_answer_0(rid, rc);276 async_answer_0(rid, rc); 275 277 return; 276 278 } … … 282 284 if (rc != EOK) { 283 285 free(mp); 284 ipc_answer_0(rid, rc);286 async_answer_0(rid, rc); 285 287 return; 286 288 } … … 291 293 */ 292 294 char *fs_name; 293 rc = async_data_write_accept((void **) &fs_name, true, 0, FS_NAME_MAXLEN,294 0, NULL);295 rc = async_data_write_accept((void **) &fs_name, true, 0, 296 FS_NAME_MAXLEN, 0, NULL); 295 297 if (rc != EOK) { 296 298 free(mp); 297 299 free(opts); 298 ipc_answer_0(rid, rc);300 async_answer_0(rid, rc); 299 301 return; 300 302 } … … 306 308 ipc_call_t data; 307 309 ipc_callid_t callid = async_get_call(&data); 308 if (IPC_GET_ METHOD(data) != IPC_M_PING) {309 ipc_answer_0(callid, ENOTSUP);310 ipc_answer_0(rid, ENOTSUP);310 if (IPC_GET_IMETHOD(data) != IPC_M_PING) { 311 async_answer_0(callid, ENOTSUP); 312 async_answer_0(rid, ENOTSUP); 311 313 free(mp); 312 314 free(opts); … … 330 332 331 333 fibril_mutex_unlock(&fs_head_lock); 332 ipc_answer_0(callid, ENOENT);333 ipc_answer_0(rid, ENOENT);334 async_answer_0(callid, ENOENT); 335 async_answer_0(rid, ENOENT); 334 336 free(mp); 335 337 free(fs_name); … … 340 342 341 343 /* Acknowledge that we know fs_name. */ 342 ipc_answer_0(callid, EOK);344 async_answer_0(callid, EOK); 343 345 344 346 /* Do the mount */ 345 vfs_mount_internal(rid, dev _handle, fs_handle, mp, opts);347 vfs_mount_internal(rid, devmap_handle, fs_handle, mp, opts); 346 348 free(mp); 347 349 free(fs_name); … … 364 366 0, NULL); 365 367 if (rc != EOK) 366 ipc_answer_0(rid, rc);368 async_answer_0(rid, rc); 367 369 368 370 /* … … 383 385 fibril_rwlock_write_unlock(&namespace_rwlock); 384 386 free(mp); 385 ipc_answer_0(rid, rc);387 async_answer_0(rid, rc); 386 388 return; 387 389 } … … 390 392 fibril_rwlock_write_unlock(&namespace_rwlock); 391 393 free(mp); 392 ipc_answer_0(rid, ENOMEM);394 async_answer_0(rid, ENOMEM); 393 395 return; 394 396 } … … 402 404 */ 403 405 if (vfs_nodes_refcount_sum_get(mr_node->fs_handle, 404 mr_node->dev _handle) != 2) {406 mr_node->devmap_handle) != 2) { 405 407 fibril_rwlock_write_unlock(&namespace_rwlock); 406 408 vfs_node_put(mr_node); 407 409 free(mp); 408 ipc_answer_0(rid, EBUSY);410 async_answer_0(rid, EBUSY); 409 411 return; 410 412 } … … 422 424 phone = vfs_grab_phone(mr_node->fs_handle); 423 425 rc = async_req_1_0(phone, VFS_OUT_UNMOUNTED, 424 mr_node->dev _handle);425 vfs_release_phone( phone);426 mr_node->devmap_handle); 427 vfs_release_phone(mr_node->fs_handle, phone); 426 428 if (rc != EOK) { 427 429 fibril_rwlock_write_unlock(&namespace_rwlock); 428 430 vfs_node_put(mr_node); 429 ipc_answer_0(rid, rc);431 async_answer_0(rid, rc); 430 432 return; 431 433 } 432 434 rootfs.fs_handle = 0; 433 rootfs.dev _handle = 0;435 rootfs.devmap_handle = 0; 434 436 } else { 435 437 … … 446 448 fibril_rwlock_write_unlock(&namespace_rwlock); 447 449 vfs_node_put(mr_node); 448 ipc_answer_0(rid, rc);450 async_answer_0(rid, rc); 449 451 return; 450 452 } … … 453 455 fibril_rwlock_write_unlock(&namespace_rwlock); 454 456 vfs_node_put(mr_node); 455 ipc_answer_0(rid, ENOMEM);457 async_answer_0(rid, ENOMEM); 456 458 return; 457 459 } 458 460 459 461 phone = vfs_grab_phone(mp_node->fs_handle); 460 rc = async_req_2_0(phone, VFS_OUT_UNMOUNT, mp_node->dev_handle,461 mp_node-> index);462 vfs_release_phone( phone);462 rc = async_req_2_0(phone, VFS_OUT_UNMOUNT, 463 mp_node->devmap_handle, mp_node->index); 464 vfs_release_phone(mp_node->fs_handle, phone); 463 465 if (rc != EOK) { 464 466 fibril_rwlock_write_unlock(&namespace_rwlock); 465 467 vfs_node_put(mp_node); 466 468 vfs_node_put(mr_node); 467 ipc_answer_0(rid, rc);469 async_answer_0(rid, rc); 468 470 return; 469 471 } … … 483 485 484 486 fibril_rwlock_write_unlock(&namespace_rwlock); 485 ipc_answer_0(rid, EOK);487 async_answer_0(rid, EOK); 486 488 } 487 489 488 490 void vfs_open(ipc_callid_t rid, ipc_call_t *request) 489 491 { 490 if (!vfs_files_init()) {491 ipc_answer_0(rid, ENOMEM);492 return;493 }494 495 492 /* 496 493 * The POSIX interface is open(path, oflag, mode). … … 516 513 ((lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) || 517 514 (lflag & (L_OPEN | L_ROOT | L_MP))) { 518 ipc_answer_0(rid, EINVAL);515 async_answer_0(rid, EINVAL); 519 516 return; 520 517 } … … 528 525 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL); 529 526 if (rc != EOK) { 530 ipc_answer_0(rid, rc);527 async_answer_0(rid, rc); 531 528 return; 532 529 } … … 550 547 else 551 548 fibril_rwlock_read_unlock(&namespace_rwlock); 552 ipc_answer_0(rid, rc);549 async_answer_0(rid, rc); 553 550 free(path); 554 551 return; … … 569 566 if (node->size) { 570 567 rc = vfs_truncate_internal(node->fs_handle, 571 node->dev _handle, node->index, 0);568 node->devmap_handle, node->index, 0); 572 569 if (rc) { 573 570 fibril_rwlock_write_unlock(&node->contents_rwlock); 574 571 vfs_node_put(node); 575 ipc_answer_0(rid, rc);572 async_answer_0(rid, rc); 576 573 return; 577 574 } … … 588 585 if (fd < 0) { 589 586 vfs_node_put(node); 590 ipc_answer_0(rid, fd);587 async_answer_0(rid, fd); 591 588 return; 592 589 } … … 606 603 vfs_node_addref(node); 607 604 vfs_node_put(node); 605 vfs_file_put(file); 608 606 609 607 /* Success! Return the new file descriptor to the client. */ 610 ipc_answer_1(rid, EOK, fd);608 async_answer_1(rid, EOK, fd); 611 609 } 612 610 … … 615 613 // FIXME: check for sanity of the supplied fs, dev and index 616 614 617 if (!vfs_files_init()) {618 ipc_answer_0(rid, ENOMEM);619 return;620 }621 622 615 /* 623 616 * The interface is open_node(fs, dev, index, oflag). … … 626 619 627 620 lr.triplet.fs_handle = IPC_GET_ARG1(*request); 628 lr.triplet.dev _handle = IPC_GET_ARG2(*request);621 lr.triplet.devmap_handle = IPC_GET_ARG2(*request); 629 622 lr.triplet.index = IPC_GET_ARG3(*request); 630 623 int oflag = IPC_GET_ARG4(*request); … … 635 628 if (rc != EOK) { 636 629 fibril_rwlock_read_unlock(&namespace_rwlock); 637 ipc_answer_0(rid, rc);630 async_answer_0(rid, rc); 638 631 return; 639 632 } … … 647 640 if (node->size) { 648 641 rc = vfs_truncate_internal(node->fs_handle, 649 node->dev _handle, node->index, 0);642 node->devmap_handle, node->index, 0); 650 643 if (rc) { 651 644 fibril_rwlock_write_unlock(&node->contents_rwlock); 652 645 vfs_node_put(node); 653 ipc_answer_0(rid, rc);646 async_answer_0(rid, rc); 654 647 return; 655 648 } … … 666 659 if (fd < 0) { 667 660 vfs_node_put(node); 668 ipc_answer_0(rid, fd);661 async_answer_0(rid, fd); 669 662 return; 670 663 } … … 683 676 vfs_node_addref(node); 684 677 vfs_node_put(node); 678 vfs_file_put(file); 685 679 686 680 /* Success! Return the new file descriptor to the client. */ 687 ipc_answer_1(rid, EOK, fd);681 async_answer_1(rid, EOK, fd); 688 682 } 689 683 … … 695 689 vfs_file_t *file = vfs_file_get(fd); 696 690 if (!file) { 697 ipc_answer_0(rid, ENOENT);691 async_answer_0(rid, ENOENT); 698 692 return; 699 693 } … … 709 703 aid_t msg; 710 704 ipc_call_t answer; 711 msg = async_send_2(fs_phone, VFS_OUT_SYNC, file->node->dev _handle,705 msg = async_send_2(fs_phone, VFS_OUT_SYNC, file->node->devmap_handle, 712 706 file->node->index, &answer); 713 707 714 708 /* Wait for reply from the FS server. */ 715 ipcarg_t rc;709 sysarg_t rc; 716 710 async_wait_for(msg, &rc); 717 711 718 vfs_release_phone(f s_phone);712 vfs_release_phone(file->node->fs_handle, fs_phone); 719 713 fibril_mutex_unlock(&file->lock); 720 721 ipc_answer_0(rid, rc); 714 715 vfs_file_put(file); 716 async_answer_0(rid, rc); 722 717 } 723 718 … … 740 735 aid_t msg; 741 736 ipc_call_t answer; 742 msg = async_send_2(fs_phone, VFS_OUT_CLOSE, file->node->dev_handle,743 file->node-> index, &answer);737 msg = async_send_2(fs_phone, VFS_OUT_CLOSE, 738 file->node->devmap_handle, file->node->index, &answer); 744 739 745 740 /* Wait for reply from the FS server. */ 746 ipcarg_t rc;741 sysarg_t rc; 747 742 async_wait_for(msg, &rc); 748 743 749 vfs_release_phone(f s_phone);744 vfs_release_phone(file->node->fs_handle, fs_phone); 750 745 fibril_mutex_unlock(&file->lock); 751 746 … … 764 759 vfs_file_t *file = vfs_file_get(fd); 765 760 if (!file) { 766 ipc_answer_0(rid, ENOENT);761 async_answer_0(rid, ENOENT); 767 762 return; 768 763 } … … 770 765 int ret = vfs_close_internal(file); 771 766 if (ret != EOK) 772 ipc_answer_0(rid, ret); 773 767 async_answer_0(rid, ret); 768 769 vfs_file_put(file); 774 770 ret = vfs_fd_free(fd); 775 ipc_answer_0(rid, ret);771 async_answer_0(rid, ret); 776 772 } 777 773 778 774 static void vfs_rdwr(ipc_callid_t rid, ipc_call_t *request, bool read) 779 775 { 776 vfs_info_t *vi; 780 777 781 778 /* … … 794 791 vfs_file_t *file = vfs_file_get(fd); 795 792 if (!file) { 796 ipc_answer_0(rid, ENOENT);793 async_answer_0(rid, ENOENT); 797 794 return; 798 795 } … … 804 801 fibril_mutex_lock(&file->lock); 805 802 803 vi = fs_handle_to_info(file->node->fs_handle); 804 assert(vi); 805 806 806 /* 807 807 * Lock the file's node so that no other client can read/write to it at 808 * the same time. 809 */ 810 if (read) 808 * the same time unless the FS supports concurrent reads/writes and its 809 * write implementation does not modify the file size. 810 */ 811 if (read || (vi->concurrent_read_write && vi->write_retains_size)) 811 812 fibril_rwlock_read_lock(&file->node->contents_rwlock); 812 813 else … … 831 832 * don't have to bother. 832 833 */ 833 ipcarg_t rc;834 sysarg_t rc; 834 835 ipc_call_t answer; 835 836 if (read) { 837 rc = async_data_read_forward_3_1(fs_phone, VFS_OUT_READ, 838 file->node->devmap_handle, file->node->index, file->pos, 839 &answer); 840 } else { 836 841 if (file->append) 837 842 file->pos = file->node->size; 838 843 839 rc = async_data_ read_forward_3_1(fs_phone, VFS_OUT_READ,840 file->node->dev _handle, file->node->index, file->pos,844 rc = async_data_write_forward_3_1(fs_phone, VFS_OUT_WRITE, 845 file->node->devmap_handle, file->node->index, file->pos, 841 846 &answer); 842 } else { 843 rc = async_data_write_forward_3_1(fs_phone, VFS_OUT_WRITE, 844 file->node->dev_handle, file->node->index, file->pos, 845 &answer); 846 } 847 848 vfs_release_phone(fs_phone); 847 } 848 849 vfs_release_phone(file->node->fs_handle, fs_phone); 849 850 850 851 size_t bytes = IPC_GET_ARG1(answer); … … 854 855 855 856 /* Unlock the VFS node. */ 856 if (read )857 if (read || (vi->concurrent_read_write && vi->write_retains_size)) 857 858 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 858 859 else { … … 867 868 file->pos += bytes; 868 869 fibril_mutex_unlock(&file->lock); 869 870 vfs_file_put(file); 871 870 872 /* 871 873 * FS server's reply is the final result of the whole operation we 872 874 * return to the client. 873 875 */ 874 ipc_answer_1(rid, rc, bytes);876 async_answer_1(rid, rc, bytes); 875 877 } 876 878 … … 888 890 { 889 891 int fd = (int) IPC_GET_ARG1(*request); 890 off64_t off = 891 (off64_t) MERGE_LOUP32(IPC_GET_ARG2(*request),IPC_GET_ARG3(*request));892 off64_t off = (off64_t) MERGE_LOUP32(IPC_GET_ARG2(*request), 893 IPC_GET_ARG3(*request)); 892 894 int whence = (int) IPC_GET_ARG4(*request); 893 895 … … 895 897 vfs_file_t *file = vfs_file_get(fd); 896 898 if (!file) { 897 ipc_answer_0(rid, ENOENT);899 async_answer_0(rid, ENOENT); 898 900 return; 899 901 } … … 903 905 off64_t newoff; 904 906 switch (whence) { 905 case SEEK_SET: 906 if (off >= 0) { 907 file->pos = (aoff64_t) off; 908 fibril_mutex_unlock(&file->lock); 909 ipc_answer_1(rid, EOK, off); 910 return; 911 } 912 break; 913 case SEEK_CUR: 914 if ((off >= 0) && (file->pos + off < file->pos)) { 915 fibril_mutex_unlock(&file->lock); 916 ipc_answer_0(rid, EOVERFLOW); 917 return; 918 } 919 920 if ((off < 0) && (file->pos < (aoff64_t) -off)) { 921 fibril_mutex_unlock(&file->lock); 922 ipc_answer_0(rid, EOVERFLOW); 923 return; 924 } 925 926 file->pos += off; 927 newoff = (file->pos > OFF64_MAX) ? OFF64_MAX : file->pos; 928 907 case SEEK_SET: 908 if (off >= 0) { 909 file->pos = (aoff64_t) off; 929 910 fibril_mutex_unlock(&file->lock); 930 ipc_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff)); 931 return; 932 case SEEK_END: 933 fibril_rwlock_read_lock(&file->node->contents_rwlock); 934 aoff64_t size = file->node->size; 935 936 if ((off >= 0) && (size + off < size)) { 937 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 938 fibril_mutex_unlock(&file->lock); 939 ipc_answer_0(rid, EOVERFLOW); 940 return; 941 } 942 943 if ((off < 0) && (size < (aoff64_t) -off)) { 944 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 945 fibril_mutex_unlock(&file->lock); 946 ipc_answer_0(rid, EOVERFLOW); 947 return; 948 } 949 950 file->pos = size + off; 951 newoff = (file->pos > OFF64_MAX) ? OFF64_MAX : file->pos; 952 911 vfs_file_put(file); 912 async_answer_1(rid, EOK, off); 913 return; 914 } 915 break; 916 case SEEK_CUR: 917 if ((off >= 0) && (file->pos + off < file->pos)) { 918 fibril_mutex_unlock(&file->lock); 919 vfs_file_put(file); 920 async_answer_0(rid, EOVERFLOW); 921 return; 922 } 923 924 if ((off < 0) && (file->pos < (aoff64_t) -off)) { 925 fibril_mutex_unlock(&file->lock); 926 vfs_file_put(file); 927 async_answer_0(rid, EOVERFLOW); 928 return; 929 } 930 931 file->pos += off; 932 newoff = (file->pos > OFF64_MAX) ? OFF64_MAX : file->pos; 933 934 fibril_mutex_unlock(&file->lock); 935 vfs_file_put(file); 936 async_answer_2(rid, EOK, LOWER32(newoff), 937 UPPER32(newoff)); 938 return; 939 case SEEK_END: 940 fibril_rwlock_read_lock(&file->node->contents_rwlock); 941 aoff64_t size = file->node->size; 942 943 if ((off >= 0) && (size + off < size)) { 953 944 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 954 945 fibril_mutex_unlock(&file->lock); 955 ipc_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff)); 956 return; 946 vfs_file_put(file); 947 async_answer_0(rid, EOVERFLOW); 948 return; 949 } 950 951 if ((off < 0) && (size < (aoff64_t) -off)) { 952 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 953 fibril_mutex_unlock(&file->lock); 954 vfs_file_put(file); 955 async_answer_0(rid, EOVERFLOW); 956 return; 957 } 958 959 file->pos = size + off; 960 newoff = (file->pos > OFF64_MAX) ? OFF64_MAX : file->pos; 961 962 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 963 fibril_mutex_unlock(&file->lock); 964 vfs_file_put(file); 965 async_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff)); 966 return; 957 967 } 958 968 959 969 fibril_mutex_unlock(&file->lock); 960 ipc_answer_0(rid, EINVAL); 961 } 962 963 int vfs_truncate_internal(fs_handle_t fs_handle, dev_handle_t dev_handle, 970 vfs_file_put(file); 971 async_answer_0(rid, EINVAL); 972 } 973 974 int vfs_truncate_internal(fs_handle_t fs_handle, devmap_handle_t devmap_handle, 964 975 fs_index_t index, aoff64_t size) 965 976 { 966 ipcarg_t rc;977 sysarg_t rc; 967 978 int fs_phone; 968 979 969 980 fs_phone = vfs_grab_phone(fs_handle); 970 rc = async_req_4_0(fs_phone, VFS_OUT_TRUNCATE, ( ipcarg_t) dev_handle,971 ( ipcarg_t) index, LOWER32(size), UPPER32(size));972 vfs_release_phone(fs_ phone);981 rc = async_req_4_0(fs_phone, VFS_OUT_TRUNCATE, (sysarg_t) devmap_handle, 982 (sysarg_t) index, LOWER32(size), UPPER32(size)); 983 vfs_release_phone(fs_handle, fs_phone); 973 984 return (int)rc; 974 985 } … … 977 988 { 978 989 int fd = IPC_GET_ARG1(*request); 979 aoff64_t size = 980 (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(*request),IPC_GET_ARG3(*request));990 aoff64_t size = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(*request), 991 IPC_GET_ARG3(*request)); 981 992 int rc; 982 993 983 994 vfs_file_t *file = vfs_file_get(fd); 984 995 if (!file) { 985 ipc_answer_0(rid, ENOENT);996 async_answer_0(rid, ENOENT); 986 997 return; 987 998 } … … 990 1001 fibril_rwlock_write_lock(&file->node->contents_rwlock); 991 1002 rc = vfs_truncate_internal(file->node->fs_handle, 992 file->node->dev _handle, file->node->index, size);1003 file->node->devmap_handle, file->node->index, size); 993 1004 if (rc == EOK) 994 1005 file->node->size = size; … … 996 1007 997 1008 fibril_mutex_unlock(&file->lock); 998 ipc_answer_0(rid, (ipcarg_t)rc); 1009 vfs_file_put(file); 1010 async_answer_0(rid, (sysarg_t)rc); 999 1011 } 1000 1012 … … 1002 1014 { 1003 1015 int fd = IPC_GET_ARG1(*request); 1004 ipcarg_t rc;1016 sysarg_t rc; 1005 1017 1006 1018 vfs_file_t *file = vfs_file_get(fd); 1007 1019 if (!file) { 1008 ipc_answer_0(rid, ENOENT);1020 async_answer_0(rid, ENOENT); 1009 1021 return; 1010 1022 } … … 1012 1024 ipc_callid_t callid; 1013 1025 if (!async_data_read_receive(&callid, NULL)) { 1014 ipc_answer_0(callid, EINVAL); 1015 ipc_answer_0(rid, EINVAL); 1026 vfs_file_put(file); 1027 async_answer_0(callid, EINVAL); 1028 async_answer_0(rid, EINVAL); 1016 1029 return; 1017 1030 } … … 1022 1035 1023 1036 aid_t msg; 1024 msg = async_send_3(fs_phone, VFS_OUT_STAT, file->node->dev _handle,1037 msg = async_send_3(fs_phone, VFS_OUT_STAT, file->node->devmap_handle, 1025 1038 file->node->index, true, NULL); 1026 ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);1039 async_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 1027 1040 async_wait_for(msg, &rc); 1028 vfs_release_phone(f s_phone);1041 vfs_release_phone(file->node->fs_handle, fs_phone); 1029 1042 1030 1043 fibril_mutex_unlock(&file->lock); 1031 ipc_answer_0(rid, rc); 1044 vfs_file_put(file); 1045 async_answer_0(rid, rc); 1032 1046 } 1033 1047 … … 1037 1051 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL); 1038 1052 if (rc != EOK) { 1039 ipc_answer_0(rid, rc);1053 async_answer_0(rid, rc); 1040 1054 return; 1041 1055 } … … 1044 1058 if (!async_data_read_receive(&callid, NULL)) { 1045 1059 free(path); 1046 ipc_answer_0(callid, EINVAL);1047 ipc_answer_0(rid, EINVAL);1060 async_answer_0(callid, EINVAL); 1061 async_answer_0(rid, EINVAL); 1048 1062 return; 1049 1063 } … … 1055 1069 if (rc != EOK) { 1056 1070 fibril_rwlock_read_unlock(&namespace_rwlock); 1057 ipc_answer_0(callid, rc);1058 ipc_answer_0(rid, rc);1071 async_answer_0(callid, rc); 1072 async_answer_0(rid, rc); 1059 1073 return; 1060 1074 } … … 1062 1076 if (!node) { 1063 1077 fibril_rwlock_read_unlock(&namespace_rwlock); 1064 ipc_answer_0(callid, ENOMEM);1065 ipc_answer_0(rid, ENOMEM);1078 async_answer_0(callid, ENOMEM); 1079 async_answer_0(rid, ENOMEM); 1066 1080 return; 1067 1081 } … … 1071 1085 int fs_phone = vfs_grab_phone(node->fs_handle); 1072 1086 aid_t msg; 1073 msg = async_send_3(fs_phone, VFS_OUT_STAT, node->dev _handle,1087 msg = async_send_3(fs_phone, VFS_OUT_STAT, node->devmap_handle, 1074 1088 node->index, false, NULL); 1075 ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);1076 1077 ipcarg_t rv;1089 async_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 1090 1091 sysarg_t rv; 1078 1092 async_wait_for(msg, &rv); 1079 vfs_release_phone( fs_phone);1080 1081 ipc_answer_0(rid, rv);1093 vfs_release_phone(node->fs_handle, fs_phone); 1094 1095 async_answer_0(rid, rv); 1082 1096 1083 1097 vfs_node_put(node); … … 1091 1105 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL); 1092 1106 if (rc != EOK) { 1093 ipc_answer_0(rid, rc);1107 async_answer_0(rid, rc); 1094 1108 return; 1095 1109 } … … 1103 1117 fibril_rwlock_write_unlock(&namespace_rwlock); 1104 1118 free(path); 1105 ipc_answer_0(rid, rc);1119 async_answer_0(rid, rc); 1106 1120 } 1107 1121 … … 1113 1127 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL); 1114 1128 if (rc != EOK) { 1115 ipc_answer_0(rid, rc);1129 async_answer_0(rid, rc); 1116 1130 return; 1117 1131 } … … 1124 1138 if (rc != EOK) { 1125 1139 fibril_rwlock_write_unlock(&namespace_rwlock); 1126 ipc_answer_0(rid, rc);1140 async_answer_0(rid, rc); 1127 1141 return; 1128 1142 } … … 1139 1153 fibril_rwlock_write_unlock(&namespace_rwlock); 1140 1154 vfs_node_put(node); 1141 ipc_answer_0(rid, EOK);1155 async_answer_0(rid, EOK); 1142 1156 } 1143 1157 … … 1148 1162 int rc = async_data_write_accept((void **) &old, true, 0, 0, 0, NULL); 1149 1163 if (rc != EOK) { 1150 ipc_answer_0(rid, rc);1164 async_answer_0(rid, rc); 1151 1165 return; 1152 1166 } … … 1157 1171 if (rc != EOK) { 1158 1172 free(old); 1159 ipc_answer_0(rid, rc);1173 async_answer_0(rid, rc); 1160 1174 return; 1161 1175 } … … 1167 1181 1168 1182 if ((!oldc) || (!newc)) { 1169 ipc_answer_0(rid, EINVAL);1183 async_answer_0(rid, EINVAL); 1170 1184 free(old); 1171 1185 free(new); … … 1186 1200 * - oldc and newc are equal. 1187 1201 */ 1188 ipc_answer_0(rid, EINVAL);1202 async_answer_0(rid, EINVAL); 1189 1203 free(old); 1190 1204 free(new); … … 1201 1215 if (rc != EOK) { 1202 1216 fibril_rwlock_write_unlock(&namespace_rwlock); 1203 ipc_answer_0(rid, rc);1217 async_answer_0(rid, rc); 1204 1218 free(old); 1205 1219 free(new); … … 1210 1224 if (!old_node) { 1211 1225 fibril_rwlock_write_unlock(&namespace_rwlock); 1212 ipc_answer_0(rid, ENOMEM);1226 async_answer_0(rid, ENOMEM); 1213 1227 free(old); 1214 1228 free(new); … … 1220 1234 if (!parentc) { 1221 1235 fibril_rwlock_write_unlock(&namespace_rwlock); 1222 ipc_answer_0(rid, rc); 1236 vfs_node_put(old_node); 1237 async_answer_0(rid, rc); 1223 1238 free(old); 1224 1239 free(new); … … 1237 1252 if (rc != EOK) { 1238 1253 fibril_rwlock_write_unlock(&namespace_rwlock); 1239 ipc_answer_0(rid, rc); 1254 vfs_node_put(old_node); 1255 async_answer_0(rid, rc); 1240 1256 free(old); 1241 1257 free(new); … … 1245 1261 /* Check whether linking to the same file system instance. */ 1246 1262 if ((old_node->fs_handle != new_par_lr.triplet.fs_handle) || 1247 (old_node->dev _handle != new_par_lr.triplet.dev_handle)) {1263 (old_node->devmap_handle != new_par_lr.triplet.devmap_handle)) { 1248 1264 fibril_rwlock_write_unlock(&namespace_rwlock); 1249 ipc_answer_0(rid, EXDEV); /* different file systems */ 1265 vfs_node_put(old_node); 1266 async_answer_0(rid, EXDEV); /* different file systems */ 1250 1267 free(old); 1251 1268 free(new); … … 1265 1282 if (!new_node) { 1266 1283 fibril_rwlock_write_unlock(&namespace_rwlock); 1267 ipc_answer_0(rid, ENOMEM); 1284 vfs_node_put(old_node); 1285 async_answer_0(rid, ENOMEM); 1268 1286 free(old); 1269 1287 free(new); … … 1276 1294 default: 1277 1295 fibril_rwlock_write_unlock(&namespace_rwlock); 1278 ipc_answer_0(rid, ENOTEMPTY); 1296 vfs_node_put(old_node); 1297 async_answer_0(rid, ENOTEMPTY); 1279 1298 free(old); 1280 1299 free(new); … … 1284 1303 /* Create the new link for the new name. */ 1285 1304 rc = vfs_lookup_internal(newc, L_LINK, NULL, NULL, old_node->index); 1286 if (rc != EOK) {1287 fibril_rwlock_write_unlock(&namespace_rwlock);1288 if (new_node)1289 vfs_node_put(new_node);1290 ipc_answer_0(rid, rc);1291 free(old);1292 free(new);1293 return;1294 }1295 1296 fibril_mutex_lock(&nodes_mutex);1297 old_node->lnkcnt++;1298 fibril_mutex_unlock(&nodes_mutex);1299 1300 /* Destroy the link for the old name. */1301 rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL);1302 1305 if (rc != EOK) { 1303 1306 fibril_rwlock_write_unlock(&namespace_rwlock); … … 1305 1308 if (new_node) 1306 1309 vfs_node_put(new_node); 1307 ipc_answer_0(rid, rc); 1310 async_answer_0(rid, rc); 1311 free(old); 1312 free(new); 1313 return; 1314 } 1315 1316 fibril_mutex_lock(&nodes_mutex); 1317 old_node->lnkcnt++; 1318 fibril_mutex_unlock(&nodes_mutex); 1319 1320 /* Destroy the link for the old name. */ 1321 rc = vfs_lookup_internal(oldc, L_UNLINK, NULL, NULL); 1322 if (rc != EOK) { 1323 fibril_rwlock_write_unlock(&namespace_rwlock); 1324 vfs_node_put(old_node); 1325 if (new_node) 1326 vfs_node_put(new_node); 1327 async_answer_0(rid, rc); 1308 1328 free(old); 1309 1329 free(new); … … 1322 1342 free(old); 1323 1343 free(new); 1324 ipc_answer_0(rid, EOK);1344 async_answer_0(rid, EOK); 1325 1345 } 1326 1346 … … 1329 1349 int oldfd = IPC_GET_ARG1(*request); 1330 1350 int newfd = IPC_GET_ARG2(*request); 1351 1352 /* If the file descriptors are the same, do nothing. */ 1353 if (oldfd == newfd) { 1354 async_answer_1(rid, EOK, newfd); 1355 return; 1356 } 1331 1357 1332 1358 /* Lookup the file structure corresponding to oldfd. */ 1333 1359 vfs_file_t *oldfile = vfs_file_get(oldfd); 1334 1360 if (!oldfile) { 1335 ipc_answer_0(rid, EBADF); 1336 return; 1337 } 1338 1339 /* If the file descriptors are the same, do nothing. */ 1340 if (oldfd == newfd) { 1341 ipc_answer_1(rid, EOK, newfd); 1361 async_answer_0(rid, EBADF); 1342 1362 return; 1343 1363 } … … 1356 1376 if (ret != EOK) { 1357 1377 fibril_mutex_unlock(&oldfile->lock); 1358 ipc_answer_0(rid, ret); 1378 vfs_file_put(oldfile); 1379 vfs_file_put(newfile); 1380 async_answer_0(rid, ret); 1359 1381 return; 1360 1382 } … … 1363 1385 if (ret != EOK) { 1364 1386 fibril_mutex_unlock(&oldfile->lock); 1365 ipc_answer_0(rid, ret); 1366 return; 1367 } 1387 vfs_file_put(oldfile); 1388 vfs_file_put(newfile); 1389 async_answer_0(rid, ret); 1390 return; 1391 } 1392 vfs_file_put(newfile); 1368 1393 } 1369 1394 … … 1371 1396 int ret = vfs_fd_assign(oldfile, newfd); 1372 1397 fibril_mutex_unlock(&oldfile->lock); 1398 vfs_file_put(oldfile); 1373 1399 1374 1400 if (ret != EOK) 1375 ipc_answer_0(rid, ret);1401 async_answer_0(rid, ret); 1376 1402 else 1377 ipc_answer_1(rid, EOK, newfd);1403 async_answer_1(rid, EOK, newfd); 1378 1404 } 1379 1405
Note:
See TracChangeset
for help on using the changeset viewer.