Changes in uspace/srv/vfs/vfs_ops.c [dd2cfa7:1e4cada] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_ops.c
rdd2cfa7 r1e4cada 44 44 #include <string.h> 45 45 #include <bool.h> 46 #include <fibril_sync .h>46 #include <fibril_synch.h> 47 47 #include <adt/list.h> 48 48 #include <unistd.h> … … 125 125 (ipcarg_t) dev_handle, &answer); 126 126 /* send the mount options */ 127 rc = ipc_data_write_start(phone, (void *)opts,127 rc = async_data_write_start(phone, (void *)opts, 128 128 str_size(opts)); 129 129 if (rc != EOK) { … … 207 207 208 208 /* send the mount options */ 209 rc = ipc_data_write_start(phone, (void *)opts, str_size(opts));209 rc = async_data_write_start(phone, (void *)opts, str_size(opts)); 210 210 if (rc != EOK) { 211 211 async_wait_for(msg, NULL); … … 268 268 ipc_callid_t callid; 269 269 size_t size; 270 if (! ipc_data_write_receive(&callid, &size)) {270 if (!async_data_write_receive(&callid, &size)) { 271 271 ipc_answer_0(callid, EINVAL); 272 272 ipc_answer_0(rid, EINVAL); … … 290 290 291 291 /* Deliver the mount point. */ 292 ipcarg_t retval = ipc_data_write_finalize(callid, mp, size);292 ipcarg_t retval = async_data_write_finalize(callid, mp, size); 293 293 if (retval != EOK) { 294 294 ipc_answer_0(rid, retval); … … 299 299 300 300 /* Now we expect to receive the mount options. */ 301 if (! ipc_data_write_receive(&callid, &size)) {301 if (!async_data_write_receive(&callid, &size)) { 302 302 ipc_answer_0(callid, EINVAL); 303 303 ipc_answer_0(rid, EINVAL); … … 324 324 325 325 /* Deliver the mount options. */ 326 retval = ipc_data_write_finalize(callid, opts, size);326 retval = async_data_write_finalize(callid, opts, size); 327 327 if (retval != EOK) { 328 328 ipc_answer_0(rid, retval); … … 337 337 * system. 338 338 */ 339 if (! ipc_data_write_receive(&callid, &size)) {339 if (!async_data_write_receive(&callid, &size)) { 340 340 ipc_answer_0(callid, EINVAL); 341 341 ipc_answer_0(rid, EINVAL); … … 370 370 371 371 /* Deliver the file system name. */ 372 retval = ipc_data_write_finalize(callid, fs_name, size);372 retval = async_data_write_finalize(callid, fs_name, size); 373 373 if (retval != EOK) { 374 374 ipc_answer_0(rid, retval); … … 469 469 470 470 ipc_callid_t callid; 471 if (! ipc_data_write_receive(&callid, &len)) {471 if (!async_data_write_receive(&callid, &len)) { 472 472 ipc_answer_0(callid, EINVAL); 473 473 ipc_answer_0(rid, EINVAL); … … 483 483 484 484 int rc; 485 if ((rc = ipc_data_write_finalize(callid, path, len))) {485 if ((rc = async_data_write_finalize(callid, path, len))) { 486 486 ipc_answer_0(rid, rc); 487 487 free(path); … … 543 543 * structure. 544 544 */ 545 int fd = vfs_fd_alloc( );545 int fd = vfs_fd_alloc((oflag & O_DESC) != 0); 546 546 if (fd < 0) { 547 547 vfs_node_put(node); … … 620 620 * structure. 621 621 */ 622 int fd = vfs_fd_alloc( );622 int fd = vfs_fd_alloc((oflag & O_DESC) != 0); 623 623 if (fd < 0) { 624 624 vfs_node_put(node); … … 679 679 } 680 680 681 static int vfs_close_internal(vfs_file_t *file) 682 { 683 /* 684 * Lock the open file structure so that no other thread can manipulate 685 * the same open file at a time. 686 */ 687 fibril_mutex_lock(&file->lock); 688 689 if (file->refcnt <= 1) { 690 /* Only close the file on the destination FS server 691 if there are no more file descriptors (except the 692 present one) pointing to this file. */ 693 694 int fs_phone = vfs_grab_phone(file->node->fs_handle); 695 696 /* Make a VFS_OUT_CLOSE request at the destination FS server. */ 697 aid_t msg; 698 ipc_call_t answer; 699 msg = async_send_2(fs_phone, VFS_OUT_CLOSE, file->node->dev_handle, 700 file->node->index, &answer); 701 702 /* Wait for reply from the FS server. */ 703 ipcarg_t rc; 704 async_wait_for(msg, &rc); 705 706 vfs_release_phone(fs_phone); 707 fibril_mutex_unlock(&file->lock); 708 709 return IPC_GET_ARG1(answer); 710 } 711 712 fibril_mutex_unlock(&file->lock); 713 return EOK; 714 } 715 681 716 void vfs_close(ipc_callid_t rid, ipc_call_t *request) 682 717 { … … 690 725 } 691 726 692 /* 693 * Lock the open file structure so that no other thread can manipulate 694 * the same open file at a time. 695 */ 696 fibril_mutex_lock(&file->lock); 697 int fs_phone = vfs_grab_phone(file->node->fs_handle); 698 699 /* Make a VFS_OUT_CLOSE request at the destination FS server. */ 700 aid_t msg; 701 ipc_call_t answer; 702 msg = async_send_2(fs_phone, VFS_OUT_CLOSE, file->node->dev_handle, 703 file->node->index, &answer); 704 705 /* Wait for reply from the FS server. */ 706 ipcarg_t rc; 707 async_wait_for(msg, &rc); 708 709 vfs_release_phone(fs_phone); 710 fibril_mutex_unlock(&file->lock); 711 712 int retval = IPC_GET_ARG1(answer); 713 if (retval != EOK) 714 ipc_answer_0(rid, retval); 715 716 retval = vfs_fd_free(fd); 717 ipc_answer_0(rid, retval); 727 int ret = vfs_close_internal(file); 728 if (ret != EOK) 729 ipc_answer_0(rid, ret); 730 731 ret = vfs_fd_free(fd); 732 ipc_answer_0(rid, ret); 718 733 } 719 734 … … 747 762 int res; 748 763 if (read) 749 res = ipc_data_read_receive(&callid, NULL);764 res = async_data_read_receive(&callid, NULL); 750 765 else 751 res = ipc_data_write_receive(&callid, NULL);766 res = async_data_write_receive(&callid, NULL); 752 767 if (!res) { 753 768 ipc_answer_0(callid, EINVAL); … … 934 949 { 935 950 int fd = IPC_GET_ARG1(*request); 936 size_t size = IPC_GET_ARG2(*request);937 951 ipcarg_t rc; 938 952 … … 944 958 945 959 ipc_callid_t callid; 946 if (! ipc_data_read_receive(&callid, NULL)) {960 if (!async_data_read_receive(&callid, NULL)) { 947 961 ipc_answer_0(callid, EINVAL); 948 962 ipc_answer_0(rid, EINVAL); … … 970 984 ipc_callid_t callid; 971 985 972 if (! ipc_data_write_receive(&callid, &len)) {986 if (!async_data_write_receive(&callid, &len)) { 973 987 ipc_answer_0(callid, EINVAL); 974 988 ipc_answer_0(rid, EINVAL); … … 982 996 } 983 997 int rc; 984 if ((rc = ipc_data_write_finalize(callid, path, len))) {998 if ((rc = async_data_write_finalize(callid, path, len))) { 985 999 ipc_answer_0(rid, rc); 986 1000 free(path); … … 989 1003 path[len] = '\0'; 990 1004 991 if (! ipc_data_read_receive(&callid, NULL)) {1005 if (!async_data_read_receive(&callid, NULL)) { 992 1006 free(path); 993 1007 ipc_answer_0(callid, EINVAL); … … 1038 1052 ipc_callid_t callid; 1039 1053 1040 if (! ipc_data_write_receive(&callid, &len)) {1054 if (!async_data_write_receive(&callid, &len)) { 1041 1055 ipc_answer_0(callid, EINVAL); 1042 1056 ipc_answer_0(rid, EINVAL); … … 1050 1064 } 1051 1065 int rc; 1052 if ((rc = ipc_data_write_finalize(callid, path, len))) {1066 if ((rc = async_data_write_finalize(callid, path, len))) { 1053 1067 ipc_answer_0(rid, rc); 1054 1068 free(path); … … 1075 1089 ipc_callid_t callid; 1076 1090 1077 if (! ipc_data_write_receive(&callid, &len)) {1091 if (!async_data_write_receive(&callid, &len)) { 1078 1092 ipc_answer_0(callid, EINVAL); 1079 1093 ipc_answer_0(rid, EINVAL); … … 1087 1101 } 1088 1102 int rc; 1089 if ((rc = ipc_data_write_finalize(callid, path, len))) {1103 if ((rc = async_data_write_finalize(callid, path, len))) { 1090 1104 ipc_answer_0(rid, rc); 1091 1105 free(path); … … 1126 1140 1127 1141 /* Retrieve the old path. */ 1128 if (! ipc_data_write_receive(&callid, &olen)) {1142 if (!async_data_write_receive(&callid, &olen)) { 1129 1143 ipc_answer_0(callid, EINVAL); 1130 1144 ipc_answer_0(rid, EINVAL); … … 1137 1151 return; 1138 1152 } 1139 if ((rc = ipc_data_write_finalize(callid, old, olen))) {1153 if ((rc = async_data_write_finalize(callid, old, olen))) { 1140 1154 ipc_answer_0(rid, rc); 1141 1155 free(old); … … 1145 1159 1146 1160 /* Retrieve the new path. */ 1147 if (! ipc_data_write_receive(&callid, &nlen)) {1161 if (!async_data_write_receive(&callid, &nlen)) { 1148 1162 ipc_answer_0(callid, EINVAL); 1149 1163 ipc_answer_0(rid, EINVAL); … … 1158 1172 return; 1159 1173 } 1160 if ((rc = ipc_data_write_finalize(callid, new, nlen))) {1174 if ((rc = async_data_write_finalize(callid, new, nlen))) { 1161 1175 ipc_answer_0(rid, rc); 1162 1176 free(old); … … 1311 1325 } 1312 1326 1327 void vfs_dup(ipc_callid_t rid, ipc_call_t *request) 1328 { 1329 int oldfd = IPC_GET_ARG1(*request); 1330 int newfd = IPC_GET_ARG2(*request); 1331 1332 /* Lookup the file structure corresponding to oldfd. */ 1333 vfs_file_t *oldfile = vfs_file_get(oldfd); 1334 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); 1342 return; 1343 } 1344 1345 /* 1346 * Lock the open file structure so that no other thread can manipulate 1347 * the same open file at a time. 1348 */ 1349 fibril_mutex_lock(&oldfile->lock); 1350 1351 /* Lookup an open file structure possibly corresponding to newfd. */ 1352 vfs_file_t *newfile = vfs_file_get(newfd); 1353 if (newfile) { 1354 /* Close the originally opened file. */ 1355 int ret = vfs_close_internal(newfile); 1356 if (ret != EOK) { 1357 ipc_answer_0(rid, ret); 1358 return; 1359 } 1360 1361 ret = vfs_fd_free(newfd); 1362 if (ret != EOK) { 1363 ipc_answer_0(rid, ret); 1364 return; 1365 } 1366 } 1367 1368 /* Assign the old file to newfd. */ 1369 int ret = vfs_fd_assign(oldfile, newfd); 1370 fibril_mutex_unlock(&oldfile->lock); 1371 1372 if (ret != EOK) 1373 ipc_answer_0(rid, ret); 1374 else 1375 ipc_answer_1(rid, EOK, newfd); 1376 } 1377 1313 1378 /** 1314 1379 * @}
Note:
See TracChangeset
for help on using the changeset viewer.