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