Changes in / [e8d5f9f:4ce90544] in mainline
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
re8d5f9f r4ce90544 114 114 rootvirt \ 115 115 test1 \ 116 test2 \ 117 test3 116 test2 118 117 119 118 RD_DRV_CFG = -
uspace/Makefile
re8d5f9f r4ce90544 90 90 drv/rootvirt \ 91 91 drv/test1 \ 92 drv/test2 \ 93 drv/test3 92 drv/test2 94 93 95 94 ## Networking -
uspace/app/tester/Makefile
re8d5f9f r4ce90544 53 53 mm/malloc3.c \ 54 54 devs/devman1.c \ 55 devs/devman2.c \56 55 hw/misc/virtchar1.c \ 57 56 hw/serial/serial1.c -
uspace/app/tester/tester.c
re8d5f9f r4ce90544 67 67 #include "hw/misc/virtchar1.def" 68 68 #include "devs/devman1.def" 69 #include "devs/devman2.def"70 69 {NULL, NULL, NULL, false} 71 70 }; -
uspace/app/tester/tester.h
re8d5f9f r4ce90544 100 100 extern const char *test_virtchar1(void); 101 101 extern const char *test_devman1(void); 102 extern const char *test_devman2(void);103 102 104 103 extern test_t tests[]; -
uspace/drv/rootvirt/devices.def
re8d5f9f r4ce90544 21 21 .match_id = "virtual&test1" 22 22 }, 23 {24 .name = "test3",25 .match_id = "virtual&test3"26 },27 23 #endif -
uspace/srv/vfs/vfs.h
re8d5f9f r4ce90544 176 176 vfs_pair_t *, ...); 177 177 extern int vfs_open_node_internal(vfs_lookup_res_t *); 178 extern int vfs_close_internal(vfs_file_t *); 178 179 179 180 extern bool vfs_nodes_init(void); -
uspace/srv/vfs/vfs_file.c
re8d5f9f r4ce90544 79 79 for (i = 0; i < MAX_OPEN_FILES; i++) { 80 80 if (FILES[i]) { 81 (void) vfs_close_internal(FILES[i]); 81 82 (void) vfs_fd_free(i); 82 83 } … … 107 108 } 108 109 109 /** Close the file in the endpoint FS server. */110 static int vfs_file_close_remote(vfs_file_t *file)111 {112 ipc_call_t answer;113 aid_t msg;114 sysarg_t rc;115 int phone;116 117 assert(!file->refcnt);118 119 phone = vfs_grab_phone(file->node->fs_handle);120 msg = async_send_2(phone, VFS_OUT_CLOSE, file->node->devmap_handle,121 file->node->index, &answer);122 async_wait_for(msg, &rc);123 vfs_release_phone(file->node->fs_handle, phone);124 125 return IPC_GET_ARG1(answer);126 }127 128 129 110 /** Increment reference count of VFS file structure. 130 111 * … … 144 125 * decremented. 145 126 */ 146 static int vfs_file_delref(vfs_file_t *file) 147 { 148 int rc = EOK; 149 127 static void vfs_file_delref(vfs_file_t *file) 128 { 150 129 assert(fibril_mutex_is_locked(&VFS_DATA->lock)); 151 130 152 131 if (file->refcnt-- == 1) { 153 132 /* 154 * Lost the last reference to a file, need to close it in the155 * endpoint FS and drop our referenceto the underlying VFS node.133 * Lost the last reference to a file, need to drop our reference 134 * to the underlying VFS node. 156 135 */ 157 rc = vfs_file_close_remote(file);158 136 vfs_node_delref(file->node); 159 137 free(file); 160 138 } 161 162 return rc;163 139 } 164 140 … … 225 201 int vfs_fd_free(int fd) 226 202 { 227 int rc;228 229 203 if (!vfs_files_init()) 230 204 return ENOMEM; … … 236 210 } 237 211 238 rc =vfs_file_delref(FILES[fd]);212 vfs_file_delref(FILES[fd]); 239 213 FILES[fd] = NULL; 240 214 fibril_mutex_unlock(&VFS_DATA->lock); 241 215 242 return rc;216 return EOK; 243 217 } 244 218 -
uspace/srv/vfs/vfs_ops.c
re8d5f9f r4ce90544 717 717 } 718 718 719 int vfs_close_internal(vfs_file_t *file) 720 { 721 /* 722 * Lock the open file structure so that no other thread can manipulate 723 * the same open file at a time. 724 */ 725 fibril_mutex_lock(&file->lock); 726 727 if (file->refcnt <= 1) { 728 /* Only close the file on the destination FS server 729 if there are no more file descriptors (except the 730 present one) pointing to this file. */ 731 732 int fs_phone = vfs_grab_phone(file->node->fs_handle); 733 734 /* Make a VFS_OUT_CLOSE request at the destination FS server. */ 735 aid_t msg; 736 ipc_call_t answer; 737 msg = async_send_2(fs_phone, VFS_OUT_CLOSE, 738 file->node->devmap_handle, file->node->index, &answer); 739 740 /* Wait for reply from the FS server. */ 741 sysarg_t rc; 742 async_wait_for(msg, &rc); 743 744 vfs_release_phone(file->node->fs_handle, fs_phone); 745 fibril_mutex_unlock(&file->lock); 746 747 return IPC_GET_ARG1(answer); 748 } 749 750 fibril_mutex_unlock(&file->lock); 751 return EOK; 752 } 753 719 754 void vfs_close(ipc_callid_t rid, ipc_call_t *request) 720 755 { 721 756 int fd = IPC_GET_ARG1(*request); 722 int ret; 723 757 758 /* Lookup the file structure corresponding to the file descriptor. */ 759 vfs_file_t *file = vfs_file_get(fd); 760 if (!file) { 761 async_answer_0(rid, ENOENT); 762 return; 763 } 764 765 int ret = vfs_close_internal(file); 766 if (ret != EOK) 767 async_answer_0(rid, ret); 768 769 vfs_file_put(file); 724 770 ret = vfs_fd_free(fd); 725 771 async_answer_0(rid, ret); … … 1323 1369 fibril_mutex_lock(&oldfile->lock); 1324 1370 1325 /* Make sure newfd is closed. */ 1326 (void) vfs_fd_free(newfd); 1371 /* Lookup an open file structure possibly corresponding to newfd. */ 1372 vfs_file_t *newfile = vfs_file_get(newfd); 1373 if (newfile) { 1374 /* Close the originally opened file. */ 1375 int ret = vfs_close_internal(newfile); 1376 if (ret != EOK) { 1377 fibril_mutex_unlock(&oldfile->lock); 1378 vfs_file_put(oldfile); 1379 vfs_file_put(newfile); 1380 async_answer_0(rid, ret); 1381 return; 1382 } 1383 1384 ret = vfs_fd_free(newfd); 1385 if (ret != EOK) { 1386 fibril_mutex_unlock(&oldfile->lock); 1387 vfs_file_put(oldfile); 1388 vfs_file_put(newfile); 1389 async_answer_0(rid, ret); 1390 return; 1391 } 1392 vfs_file_put(newfile); 1393 } 1327 1394 1328 1395 /* Assign the old file to newfd. */
Note:
See TracChangeset
for help on using the changeset viewer.