Changes in uspace/srv/vfs/vfs_ops.c [c69646f8:b72efe8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_ops.c
rc69646f8 rb72efe8 54 54 55 55 /* Forward declarations of static functions. */ 56 static int vfs_truncate_internal(fs_handle_t, service_id_t, fs_index_t,56 static int vfs_truncate_internal(fs_handle_t, devmap_handle_t, fs_index_t, 57 57 aoff64_t); 58 58 … … 65 65 vfs_pair_t rootfs = { 66 66 .fs_handle = 0, 67 . service_id= 067 .devmap_handle = 0 68 68 }; 69 69 70 static void vfs_mount_internal(ipc_callid_t rid, service_id_t service_id,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 { … … 76 76 vfs_node_t *mr_node; 77 77 fs_index_t rindex; 78 aoff64_t rsize;78 size_t rsize; 79 79 unsigned rlnkcnt; 80 80 async_exch_t *exch; … … 125 125 exch = vfs_exchange_grab(fs_handle); 126 126 msg = async_send_1(exch, VFS_OUT_MOUNTED, 127 (sysarg_t) service_id, &answer);127 (sysarg_t) devmap_handle, &answer); 128 128 /* Send the mount options */ 129 129 rc = async_data_write_start(exch, (void *)opts, … … 146 146 147 147 rindex = (fs_index_t) IPC_GET_ARG1(answer); 148 rsize = ( aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(answer), IPC_GET_ARG3(answer));149 rlnkcnt = (unsigned) IPC_GET_ARG 4(answer);148 rsize = (size_t) IPC_GET_ARG2(answer); 149 rlnkcnt = (unsigned) IPC_GET_ARG3(answer); 150 150 151 151 mr_res.triplet.fs_handle = fs_handle; 152 mr_res.triplet. service_id = service_id;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. service_id = service_id;159 rootfs.devmap_handle = devmap_handle; 160 160 161 161 /* Add reference to the mounted root. */ … … 178 178 179 179 /* 180 * At this point, we have all necessary pieces: file system handle181 * and service ID, and we know the mount point VFS node.180 * At this point, we have all necessary pieces: file system and device 181 * handles, and we know the mount point VFS node. 182 182 */ 183 183 … … 187 187 exch = vfs_exchange_grab(mp_res.triplet.fs_handle); 188 188 msg = async_send_4(exch, VFS_OUT_MOUNT, 189 (sysarg_t) mp_res.triplet. service_id,189 (sysarg_t) mp_res.triplet.devmap_handle, 190 190 (sysarg_t) mp_res.triplet.index, 191 191 (sysarg_t) fs_handle, 192 (sysarg_t) service_id, &answer);192 (sysarg_t) devmap_handle, &answer); 193 193 194 194 /* Send connection */ … … 224 224 } 225 225 226 /* 227 * Wait for the answer before releasing the exchange to avoid deadlock 228 * in case the answer depends on further calls to the same file system. 229 * Think of a case when mounting a FS on a file_bd backed by a file on 230 * the same FS. 231 */ 226 vfs_exchange_release(exch); 232 227 async_wait_for(msg, &rc); 233 vfs_exchange_release(exch);234 228 235 229 if (rc == EOK) { 236 230 rindex = (fs_index_t) IPC_GET_ARG1(answer); 237 rsize = (aoff64_t) MERGE_LOUP32(IPC_GET_ARG2(answer), 238 IPC_GET_ARG3(answer)); 239 rlnkcnt = (unsigned) IPC_GET_ARG4(answer); 231 rsize = (size_t) IPC_GET_ARG2(answer); 232 rlnkcnt = (unsigned) IPC_GET_ARG3(answer); 240 233 241 234 mr_res.triplet.fs_handle = fs_handle; 242 mr_res.triplet. service_id = service_id;235 mr_res.triplet.devmap_handle = devmap_handle; 243 236 mr_res.triplet.index = rindex; 244 237 mr_res.size = rsize; … … 261 254 void vfs_mount(ipc_callid_t rid, ipc_call_t *request) 262 255 { 263 service_id_t service_id;256 devmap_handle_t devmap_handle; 264 257 265 258 /* … … 268 261 * in the request. 269 262 */ 270 service_id = (service_id_t) IPC_GET_ARG1(*request);263 devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 271 264 272 265 /* … … 356 349 357 350 /* Do the mount */ 358 vfs_mount_internal(rid, service_id, fs_handle, mp, opts);351 vfs_mount_internal(rid, devmap_handle, fs_handle, mp, opts); 359 352 free(mp); 360 353 free(fs_name); … … 415 408 */ 416 409 if (vfs_nodes_refcount_sum_get(mr_node->fs_handle, 417 mr_node-> service_id) != 2) {410 mr_node->devmap_handle) != 2) { 418 411 fibril_rwlock_write_unlock(&namespace_rwlock); 419 412 vfs_node_put(mr_node); … … 436 429 exch = vfs_exchange_grab(mr_node->fs_handle); 437 430 rc = async_req_1_0(exch, VFS_OUT_UNMOUNTED, 438 mr_node-> service_id);431 mr_node->devmap_handle); 439 432 vfs_exchange_release(exch); 440 433 … … 447 440 448 441 rootfs.fs_handle = 0; 449 rootfs. service_id= 0;442 rootfs.devmap_handle = 0; 450 443 } else { 451 444 … … 476 469 exch = vfs_exchange_grab(mp_node->fs_handle); 477 470 rc = async_req_2_0(exch, VFS_OUT_UNMOUNT, 478 mp_node-> service_id, mp_node->index);471 mp_node->devmap_handle, mp_node->index); 479 472 vfs_exchange_release(exch); 480 473 … … 581 574 if (node->size) { 582 575 rc = vfs_truncate_internal(node->fs_handle, 583 node-> service_id, node->index, 0);576 node->devmap_handle, node->index, 0); 584 577 if (rc) { 585 578 fibril_rwlock_write_unlock(&node->contents_rwlock); … … 624 617 } 625 618 619 void vfs_open_node(ipc_callid_t rid, ipc_call_t *request) 620 { 621 // FIXME: check for sanity of the supplied fs, dev and index 622 623 /* 624 * The interface is open_node(fs, dev, index, oflag). 625 */ 626 vfs_lookup_res_t lr; 627 628 lr.triplet.fs_handle = IPC_GET_ARG1(*request); 629 lr.triplet.devmap_handle = IPC_GET_ARG2(*request); 630 lr.triplet.index = IPC_GET_ARG3(*request); 631 int oflag = IPC_GET_ARG4(*request); 632 633 fibril_rwlock_read_lock(&namespace_rwlock); 634 635 int rc = vfs_open_node_internal(&lr); 636 if (rc != EOK) { 637 fibril_rwlock_read_unlock(&namespace_rwlock); 638 async_answer_0(rid, rc); 639 return; 640 } 641 642 vfs_node_t *node = vfs_node_get(&lr); 643 fibril_rwlock_read_unlock(&namespace_rwlock); 644 645 /* Truncate the file if requested and if necessary. */ 646 if (oflag & O_TRUNC) { 647 fibril_rwlock_write_lock(&node->contents_rwlock); 648 if (node->size) { 649 rc = vfs_truncate_internal(node->fs_handle, 650 node->devmap_handle, node->index, 0); 651 if (rc) { 652 fibril_rwlock_write_unlock(&node->contents_rwlock); 653 vfs_node_put(node); 654 async_answer_0(rid, rc); 655 return; 656 } 657 node->size = 0; 658 } 659 fibril_rwlock_write_unlock(&node->contents_rwlock); 660 } 661 662 /* 663 * Get ourselves a file descriptor and the corresponding vfs_file_t 664 * structure. 665 */ 666 int fd = vfs_fd_alloc((oflag & O_DESC) != 0); 667 if (fd < 0) { 668 vfs_node_put(node); 669 async_answer_0(rid, fd); 670 return; 671 } 672 vfs_file_t *file = vfs_file_get(fd); 673 file->node = node; 674 if (oflag & O_APPEND) 675 file->append = true; 676 677 /* 678 * The following increase in reference count is for the fact that the 679 * file is being opened and that a file structure is pointing to it. 680 * It is necessary so that the file will not disappear when 681 * vfs_node_put() is called. The reference will be dropped by the 682 * respective VFS_IN_CLOSE. 683 */ 684 vfs_node_addref(node); 685 vfs_node_put(node); 686 vfs_file_put(file); 687 688 /* Success! Return the new file descriptor to the client. */ 689 async_answer_1(rid, EOK, fd); 690 } 691 626 692 void vfs_sync(ipc_callid_t rid, ipc_call_t *request) 627 693 { … … 645 711 aid_t msg; 646 712 ipc_call_t answer; 647 msg = async_send_2(fs_exch, VFS_OUT_SYNC, file->node-> service_id,713 msg = async_send_2(fs_exch, VFS_OUT_SYNC, file->node->devmap_handle, 648 714 file->node->index, &answer); 649 715 … … 729 795 ipc_call_t answer; 730 796 if (read) { 731 rc = async_data_read_forward_ 4_1(fs_exch, VFS_OUT_READ,732 file->node-> service_id, file->node->index,733 LOWER32(file->pos), UPPER32(file->pos),&answer);797 rc = async_data_read_forward_3_1(fs_exch, VFS_OUT_READ, 798 file->node->devmap_handle, file->node->index, file->pos, 799 &answer); 734 800 } else { 735 801 if (file->append) 736 802 file->pos = file->node->size; 737 803 738 rc = async_data_write_forward_ 4_1(fs_exch, VFS_OUT_WRITE,739 file->node-> service_id, file->node->index,740 LOWER32(file->pos), UPPER32(file->pos),&answer);804 rc = async_data_write_forward_3_1(fs_exch, VFS_OUT_WRITE, 805 file->node->devmap_handle, file->node->index, file->pos, 806 &answer); 741 807 } 742 808 … … 755 821 /* Update the cached version of node's size. */ 756 822 if (rc == EOK) 757 file->node->size = MERGE_LOUP32(IPC_GET_ARG2(answer), 758 IPC_GET_ARG3(answer)); 823 file->node->size = IPC_GET_ARG2(answer); 759 824 fibril_rwlock_write_unlock(&file->node->contents_rwlock); 760 825 } … … 868 933 } 869 934 870 int vfs_truncate_internal(fs_handle_t fs_handle, service_id_t service_id,935 int vfs_truncate_internal(fs_handle_t fs_handle, devmap_handle_t devmap_handle, 871 936 fs_index_t index, aoff64_t size) 872 937 { 873 938 async_exch_t *exch = vfs_exchange_grab(fs_handle); 874 939 sysarg_t rc = async_req_4_0(exch, VFS_OUT_TRUNCATE, 875 (sysarg_t) service_id, (sysarg_t) index, LOWER32(size),940 (sysarg_t) devmap_handle, (sysarg_t) index, LOWER32(size), 876 941 UPPER32(size)); 877 942 vfs_exchange_release(exch); … … 896 961 fibril_rwlock_write_lock(&file->node->contents_rwlock); 897 962 rc = vfs_truncate_internal(file->node->fs_handle, 898 file->node-> service_id, file->node->index, size);963 file->node->devmap_handle, file->node->index, size); 899 964 if (rc == EOK) 900 965 file->node->size = size; … … 930 995 931 996 aid_t msg; 932 msg = async_send_3(exch, VFS_OUT_STAT, file->node-> service_id,997 msg = async_send_3(exch, VFS_OUT_STAT, file->node->devmap_handle, 933 998 file->node->index, true, NULL); 934 999 async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); … … 983 1048 984 1049 aid_t msg; 985 msg = async_send_3(exch, VFS_OUT_STAT, node-> service_id,1050 msg = async_send_3(exch, VFS_OUT_STAT, node->devmap_handle, 986 1051 node->index, false, NULL); 987 1052 async_forward_fast(callid, exch, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); … … 1160 1225 /* Check whether linking to the same file system instance. */ 1161 1226 if ((old_node->fs_handle != new_par_lr.triplet.fs_handle) || 1162 (old_node-> service_id != new_par_lr.triplet.service_id)) {1227 (old_node->devmap_handle != new_par_lr.triplet.devmap_handle)) { 1163 1228 fibril_rwlock_write_unlock(&namespace_rwlock); 1164 1229 vfs_node_put(old_node); … … 1282 1347 } 1283 1348 1284 void vfs_wait_handle(ipc_callid_t rid, ipc_call_t *request)1285 {1286 int fd = vfs_wait_handle_internal();1287 async_answer_1(rid, EOK, fd);1288 }1289 1290 1349 /** 1291 1350 * @}
Note:
See TracChangeset
for help on using the changeset viewer.