Changes in uspace/srv/vfs/vfs_ops.c [228e490:ffa2c8ef] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/vfs/vfs_ops.c
r228e490 rffa2c8ef 37 37 38 38 #include "vfs.h" 39 #include <ipc/ipc.h>40 39 #include <macros.h> 41 40 #include <stdint.h> … … 91 90 /* Trying to mount root FS over root FS */ 92 91 fibril_rwlock_write_unlock(&namespace_rwlock); 93 ipc_answer_0(rid, EBUSY);92 async_answer_0(rid, EBUSY); 94 93 return; 95 94 } … … 99 98 /* The lookup failed for some reason. */ 100 99 fibril_rwlock_write_unlock(&namespace_rwlock); 101 ipc_answer_0(rid, rc);100 async_answer_0(rid, rc); 102 101 return; 103 102 } … … 106 105 if (!mp_node) { 107 106 fibril_rwlock_write_unlock(&namespace_rwlock); 108 ipc_answer_0(rid, ENOMEM);107 async_answer_0(rid, ENOMEM); 109 108 return; 110 109 } … … 134 133 vfs_release_phone(fs_handle, phone); 135 134 fibril_rwlock_write_unlock(&namespace_rwlock); 136 ipc_answer_0(rid, rc);135 async_answer_0(rid, rc); 137 136 return; 138 137 } … … 142 141 if (rc != EOK) { 143 142 fibril_rwlock_write_unlock(&namespace_rwlock); 144 ipc_answer_0(rid, rc);143 async_answer_0(rid, rc); 145 144 return; 146 145 } … … 165 164 166 165 fibril_rwlock_write_unlock(&namespace_rwlock); 167 ipc_answer_0(rid, rc);166 async_answer_0(rid, rc); 168 167 return; 169 168 } else { … … 173 172 */ 174 173 fibril_rwlock_write_unlock(&namespace_rwlock); 175 ipc_answer_0(rid, ENOENT);174 async_answer_0(rid, ENOENT); 176 175 return; 177 176 } … … 202 201 if (mp_node) 203 202 vfs_node_put(mp_node); 204 ipc_answer_0(rid, rc);203 async_answer_0(rid, rc); 205 204 fibril_rwlock_write_unlock(&namespace_rwlock); 206 205 return; … … 218 217 vfs_node_put(mp_node); 219 218 fibril_rwlock_write_unlock(&namespace_rwlock); 220 ipc_answer_0(rid, rc);219 async_answer_0(rid, rc); 221 220 return; 222 221 } … … 245 244 } 246 245 247 ipc_answer_0(rid, rc);246 async_answer_0(rid, rc); 248 247 fibril_rwlock_write_unlock(&namespace_rwlock); 249 248 } … … 275 274 0, NULL); 276 275 if (rc != EOK) { 277 ipc_answer_0(rid, rc);276 async_answer_0(rid, rc); 278 277 return; 279 278 } … … 285 284 if (rc != EOK) { 286 285 free(mp); 287 ipc_answer_0(rid, rc);286 async_answer_0(rid, rc); 288 287 return; 289 288 } … … 299 298 free(mp); 300 299 free(opts); 301 ipc_answer_0(rid, rc);300 async_answer_0(rid, rc); 302 301 return; 303 302 } … … 310 309 ipc_callid_t callid = async_get_call(&data); 311 310 if (IPC_GET_IMETHOD(data) != IPC_M_PING) { 312 ipc_answer_0(callid, ENOTSUP);313 ipc_answer_0(rid, ENOTSUP);311 async_answer_0(callid, ENOTSUP); 312 async_answer_0(rid, ENOTSUP); 314 313 free(mp); 315 314 free(opts); … … 333 332 334 333 fibril_mutex_unlock(&fs_head_lock); 335 ipc_answer_0(callid, ENOENT);336 ipc_answer_0(rid, ENOENT);334 async_answer_0(callid, ENOENT); 335 async_answer_0(rid, ENOENT); 337 336 free(mp); 338 337 free(fs_name); … … 343 342 344 343 /* Acknowledge that we know fs_name. */ 345 ipc_answer_0(callid, EOK);344 async_answer_0(callid, EOK); 346 345 347 346 /* Do the mount */ … … 367 366 0, NULL); 368 367 if (rc != EOK) 369 ipc_answer_0(rid, rc);368 async_answer_0(rid, rc); 370 369 371 370 /* … … 386 385 fibril_rwlock_write_unlock(&namespace_rwlock); 387 386 free(mp); 388 ipc_answer_0(rid, rc);387 async_answer_0(rid, rc); 389 388 return; 390 389 } … … 393 392 fibril_rwlock_write_unlock(&namespace_rwlock); 394 393 free(mp); 395 ipc_answer_0(rid, ENOMEM);394 async_answer_0(rid, ENOMEM); 396 395 return; 397 396 } … … 409 408 vfs_node_put(mr_node); 410 409 free(mp); 411 ipc_answer_0(rid, EBUSY);410 async_answer_0(rid, EBUSY); 412 411 return; 413 412 } … … 430 429 fibril_rwlock_write_unlock(&namespace_rwlock); 431 430 vfs_node_put(mr_node); 432 ipc_answer_0(rid, rc);431 async_answer_0(rid, rc); 433 432 return; 434 433 } … … 449 448 fibril_rwlock_write_unlock(&namespace_rwlock); 450 449 vfs_node_put(mr_node); 451 ipc_answer_0(rid, rc);450 async_answer_0(rid, rc); 452 451 return; 453 452 } … … 456 455 fibril_rwlock_write_unlock(&namespace_rwlock); 457 456 vfs_node_put(mr_node); 458 ipc_answer_0(rid, ENOMEM);457 async_answer_0(rid, ENOMEM); 459 458 return; 460 459 } … … 468 467 vfs_node_put(mp_node); 469 468 vfs_node_put(mr_node); 470 ipc_answer_0(rid, rc);469 async_answer_0(rid, rc); 471 470 return; 472 471 } … … 486 485 487 486 fibril_rwlock_write_unlock(&namespace_rwlock); 488 ipc_answer_0(rid, EOK);487 async_answer_0(rid, EOK); 489 488 } 490 489 491 490 void vfs_open(ipc_callid_t rid, ipc_call_t *request) 492 491 { 493 if (!vfs_files_init()) {494 ipc_answer_0(rid, ENOMEM);495 return;496 }497 498 492 /* 499 493 * The POSIX interface is open(path, oflag, mode). … … 519 513 ((lflag & (L_FILE | L_DIRECTORY)) == (L_FILE | L_DIRECTORY)) || 520 514 (lflag & (L_OPEN | L_ROOT | L_MP))) { 521 ipc_answer_0(rid, EINVAL);515 async_answer_0(rid, EINVAL); 522 516 return; 523 517 } … … 531 525 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL); 532 526 if (rc != EOK) { 533 ipc_answer_0(rid, rc);527 async_answer_0(rid, rc); 534 528 return; 535 529 } … … 553 547 else 554 548 fibril_rwlock_read_unlock(&namespace_rwlock); 555 ipc_answer_0(rid, rc);549 async_answer_0(rid, rc); 556 550 free(path); 557 551 return; … … 576 570 fibril_rwlock_write_unlock(&node->contents_rwlock); 577 571 vfs_node_put(node); 578 ipc_answer_0(rid, rc);572 async_answer_0(rid, rc); 579 573 return; 580 574 } … … 591 585 if (fd < 0) { 592 586 vfs_node_put(node); 593 ipc_answer_0(rid, fd);587 async_answer_0(rid, fd); 594 588 return; 595 589 } … … 609 603 vfs_node_addref(node); 610 604 vfs_node_put(node); 605 vfs_file_put(file); 611 606 612 607 /* Success! Return the new file descriptor to the client. */ 613 ipc_answer_1(rid, EOK, fd);608 async_answer_1(rid, EOK, fd); 614 609 } 615 610 … … 617 612 { 618 613 // FIXME: check for sanity of the supplied fs, dev and index 619 620 if (!vfs_files_init()) {621 ipc_answer_0(rid, ENOMEM);622 return;623 }624 614 625 615 /* … … 638 628 if (rc != EOK) { 639 629 fibril_rwlock_read_unlock(&namespace_rwlock); 640 ipc_answer_0(rid, rc);630 async_answer_0(rid, rc); 641 631 return; 642 632 } … … 654 644 fibril_rwlock_write_unlock(&node->contents_rwlock); 655 645 vfs_node_put(node); 656 ipc_answer_0(rid, rc);646 async_answer_0(rid, rc); 657 647 return; 658 648 } … … 669 659 if (fd < 0) { 670 660 vfs_node_put(node); 671 ipc_answer_0(rid, fd);661 async_answer_0(rid, fd); 672 662 return; 673 663 } … … 686 676 vfs_node_addref(node); 687 677 vfs_node_put(node); 678 vfs_file_put(file); 688 679 689 680 /* Success! Return the new file descriptor to the client. */ 690 ipc_answer_1(rid, EOK, fd);681 async_answer_1(rid, EOK, fd); 691 682 } 692 683 … … 698 689 vfs_file_t *file = vfs_file_get(fd); 699 690 if (!file) { 700 ipc_answer_0(rid, ENOENT);691 async_answer_0(rid, ENOENT); 701 692 return; 702 693 } … … 721 712 vfs_release_phone(file->node->fs_handle, fs_phone); 722 713 fibril_mutex_unlock(&file->lock); 723 724 ipc_answer_0(rid, rc); 714 715 vfs_file_put(file); 716 async_answer_0(rid, rc); 725 717 } 726 718 … … 767 759 vfs_file_t *file = vfs_file_get(fd); 768 760 if (!file) { 769 ipc_answer_0(rid, ENOENT);761 async_answer_0(rid, ENOENT); 770 762 return; 771 763 } … … 773 765 int ret = vfs_close_internal(file); 774 766 if (ret != EOK) 775 ipc_answer_0(rid, ret); 776 767 async_answer_0(rid, ret); 768 769 vfs_file_put(file); 777 770 ret = vfs_fd_free(fd); 778 ipc_answer_0(rid, ret);771 async_answer_0(rid, ret); 779 772 } 780 773 … … 798 791 vfs_file_t *file = vfs_file_get(fd); 799 792 if (!file) { 800 ipc_answer_0(rid, ENOENT);793 async_answer_0(rid, ENOENT); 801 794 return; 802 795 } … … 875 868 file->pos += bytes; 876 869 fibril_mutex_unlock(&file->lock); 877 870 vfs_file_put(file); 871 878 872 /* 879 873 * FS server's reply is the final result of the whole operation we 880 874 * return to the client. 881 875 */ 882 ipc_answer_1(rid, rc, bytes);876 async_answer_1(rid, rc, bytes); 883 877 } 884 878 … … 903 897 vfs_file_t *file = vfs_file_get(fd); 904 898 if (!file) { 905 ipc_answer_0(rid, ENOENT);899 async_answer_0(rid, ENOENT); 906 900 return; 907 901 } … … 915 909 file->pos = (aoff64_t) off; 916 910 fibril_mutex_unlock(&file->lock); 917 ipc_answer_1(rid, EOK, off); 911 vfs_file_put(file); 912 async_answer_1(rid, EOK, off); 918 913 return; 919 914 } … … 922 917 if ((off >= 0) && (file->pos + off < file->pos)) { 923 918 fibril_mutex_unlock(&file->lock); 924 ipc_answer_0(rid, EOVERFLOW); 919 vfs_file_put(file); 920 async_answer_0(rid, EOVERFLOW); 925 921 return; 926 922 } … … 928 924 if ((off < 0) && (file->pos < (aoff64_t) -off)) { 929 925 fibril_mutex_unlock(&file->lock); 930 ipc_answer_0(rid, EOVERFLOW); 926 vfs_file_put(file); 927 async_answer_0(rid, EOVERFLOW); 931 928 return; 932 929 } … … 936 933 937 934 fibril_mutex_unlock(&file->lock); 938 ipc_answer_2(rid, EOK, LOWER32(newoff), 935 vfs_file_put(file); 936 async_answer_2(rid, EOK, LOWER32(newoff), 939 937 UPPER32(newoff)); 940 938 return; … … 946 944 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 947 945 fibril_mutex_unlock(&file->lock); 948 ipc_answer_0(rid, EOVERFLOW); 946 vfs_file_put(file); 947 async_answer_0(rid, EOVERFLOW); 949 948 return; 950 949 } … … 953 952 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 954 953 fibril_mutex_unlock(&file->lock); 955 ipc_answer_0(rid, EOVERFLOW); 954 vfs_file_put(file); 955 async_answer_0(rid, EOVERFLOW); 956 956 return; 957 957 } … … 962 962 fibril_rwlock_read_unlock(&file->node->contents_rwlock); 963 963 fibril_mutex_unlock(&file->lock); 964 ipc_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff)); 964 vfs_file_put(file); 965 async_answer_2(rid, EOK, LOWER32(newoff), UPPER32(newoff)); 965 966 return; 966 967 } 967 968 968 969 fibril_mutex_unlock(&file->lock); 969 ipc_answer_0(rid, EINVAL); 970 vfs_file_put(file); 971 async_answer_0(rid, EINVAL); 970 972 } 971 973 … … 992 994 vfs_file_t *file = vfs_file_get(fd); 993 995 if (!file) { 994 ipc_answer_0(rid, ENOENT);996 async_answer_0(rid, ENOENT); 995 997 return; 996 998 } … … 1005 1007 1006 1008 fibril_mutex_unlock(&file->lock); 1007 ipc_answer_0(rid, (sysarg_t)rc); 1009 vfs_file_put(file); 1010 async_answer_0(rid, (sysarg_t)rc); 1008 1011 } 1009 1012 … … 1015 1018 vfs_file_t *file = vfs_file_get(fd); 1016 1019 if (!file) { 1017 ipc_answer_0(rid, ENOENT);1020 async_answer_0(rid, ENOENT); 1018 1021 return; 1019 1022 } … … 1021 1024 ipc_callid_t callid; 1022 1025 if (!async_data_read_receive(&callid, NULL)) { 1023 ipc_answer_0(callid, EINVAL); 1024 ipc_answer_0(rid, EINVAL); 1026 vfs_file_put(file); 1027 async_answer_0(callid, EINVAL); 1028 async_answer_0(rid, EINVAL); 1025 1029 return; 1026 1030 } … … 1033 1037 msg = async_send_3(fs_phone, VFS_OUT_STAT, file->node->devmap_handle, 1034 1038 file->node->index, true, NULL); 1035 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); 1036 1040 async_wait_for(msg, &rc); 1037 1041 vfs_release_phone(file->node->fs_handle, fs_phone); 1038 1042 1039 1043 fibril_mutex_unlock(&file->lock); 1040 ipc_answer_0(rid, rc); 1044 vfs_file_put(file); 1045 async_answer_0(rid, rc); 1041 1046 } 1042 1047 … … 1046 1051 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL); 1047 1052 if (rc != EOK) { 1048 ipc_answer_0(rid, rc);1053 async_answer_0(rid, rc); 1049 1054 return; 1050 1055 } … … 1053 1058 if (!async_data_read_receive(&callid, NULL)) { 1054 1059 free(path); 1055 ipc_answer_0(callid, EINVAL);1056 ipc_answer_0(rid, EINVAL);1060 async_answer_0(callid, EINVAL); 1061 async_answer_0(rid, EINVAL); 1057 1062 return; 1058 1063 } … … 1064 1069 if (rc != EOK) { 1065 1070 fibril_rwlock_read_unlock(&namespace_rwlock); 1066 ipc_answer_0(callid, rc);1067 ipc_answer_0(rid, rc);1071 async_answer_0(callid, rc); 1072 async_answer_0(rid, rc); 1068 1073 return; 1069 1074 } … … 1071 1076 if (!node) { 1072 1077 fibril_rwlock_read_unlock(&namespace_rwlock); 1073 ipc_answer_0(callid, ENOMEM);1074 ipc_answer_0(rid, ENOMEM);1078 async_answer_0(callid, ENOMEM); 1079 async_answer_0(rid, ENOMEM); 1075 1080 return; 1076 1081 } … … 1082 1087 msg = async_send_3(fs_phone, VFS_OUT_STAT, node->devmap_handle, 1083 1088 node->index, false, NULL); 1084 ipc_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME);1089 async_forward_fast(callid, fs_phone, 0, 0, 0, IPC_FF_ROUTE_FROM_ME); 1085 1090 1086 1091 sysarg_t rv; … … 1088 1093 vfs_release_phone(node->fs_handle, fs_phone); 1089 1094 1090 ipc_answer_0(rid, rv);1095 async_answer_0(rid, rv); 1091 1096 1092 1097 vfs_node_put(node); … … 1100 1105 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL); 1101 1106 if (rc != EOK) { 1102 ipc_answer_0(rid, rc);1107 async_answer_0(rid, rc); 1103 1108 return; 1104 1109 } … … 1112 1117 fibril_rwlock_write_unlock(&namespace_rwlock); 1113 1118 free(path); 1114 ipc_answer_0(rid, rc);1119 async_answer_0(rid, rc); 1115 1120 } 1116 1121 … … 1122 1127 int rc = async_data_write_accept((void **) &path, true, 0, 0, 0, NULL); 1123 1128 if (rc != EOK) { 1124 ipc_answer_0(rid, rc);1129 async_answer_0(rid, rc); 1125 1130 return; 1126 1131 } … … 1133 1138 if (rc != EOK) { 1134 1139 fibril_rwlock_write_unlock(&namespace_rwlock); 1135 ipc_answer_0(rid, rc);1140 async_answer_0(rid, rc); 1136 1141 return; 1137 1142 } … … 1148 1153 fibril_rwlock_write_unlock(&namespace_rwlock); 1149 1154 vfs_node_put(node); 1150 ipc_answer_0(rid, EOK);1155 async_answer_0(rid, EOK); 1151 1156 } 1152 1157 … … 1157 1162 int rc = async_data_write_accept((void **) &old, true, 0, 0, 0, NULL); 1158 1163 if (rc != EOK) { 1159 ipc_answer_0(rid, rc);1164 async_answer_0(rid, rc); 1160 1165 return; 1161 1166 } … … 1166 1171 if (rc != EOK) { 1167 1172 free(old); 1168 ipc_answer_0(rid, rc);1173 async_answer_0(rid, rc); 1169 1174 return; 1170 1175 } … … 1176 1181 1177 1182 if ((!oldc) || (!newc)) { 1178 ipc_answer_0(rid, EINVAL);1183 async_answer_0(rid, EINVAL); 1179 1184 free(old); 1180 1185 free(new); … … 1195 1200 * - oldc and newc are equal. 1196 1201 */ 1197 ipc_answer_0(rid, EINVAL);1202 async_answer_0(rid, EINVAL); 1198 1203 free(old); 1199 1204 free(new); … … 1210 1215 if (rc != EOK) { 1211 1216 fibril_rwlock_write_unlock(&namespace_rwlock); 1212 ipc_answer_0(rid, rc);1217 async_answer_0(rid, rc); 1213 1218 free(old); 1214 1219 free(new); … … 1219 1224 if (!old_node) { 1220 1225 fibril_rwlock_write_unlock(&namespace_rwlock); 1221 ipc_answer_0(rid, ENOMEM);1226 async_answer_0(rid, ENOMEM); 1222 1227 free(old); 1223 1228 free(new); … … 1229 1234 if (!parentc) { 1230 1235 fibril_rwlock_write_unlock(&namespace_rwlock); 1231 ipc_answer_0(rid, rc);1236 async_answer_0(rid, rc); 1232 1237 free(old); 1233 1238 free(new); … … 1246 1251 if (rc != EOK) { 1247 1252 fibril_rwlock_write_unlock(&namespace_rwlock); 1248 ipc_answer_0(rid, rc);1253 async_answer_0(rid, rc); 1249 1254 free(old); 1250 1255 free(new); … … 1256 1261 (old_node->devmap_handle != new_par_lr.triplet.devmap_handle)) { 1257 1262 fibril_rwlock_write_unlock(&namespace_rwlock); 1258 ipc_answer_0(rid, EXDEV); /* different file systems */1263 async_answer_0(rid, EXDEV); /* different file systems */ 1259 1264 free(old); 1260 1265 free(new); … … 1274 1279 if (!new_node) { 1275 1280 fibril_rwlock_write_unlock(&namespace_rwlock); 1276 ipc_answer_0(rid, ENOMEM);1281 async_answer_0(rid, ENOMEM); 1277 1282 free(old); 1278 1283 free(new); … … 1285 1290 default: 1286 1291 fibril_rwlock_write_unlock(&namespace_rwlock); 1287 ipc_answer_0(rid, ENOTEMPTY);1292 async_answer_0(rid, ENOTEMPTY); 1288 1293 free(old); 1289 1294 free(new); … … 1297 1302 if (new_node) 1298 1303 vfs_node_put(new_node); 1299 ipc_answer_0(rid, rc);1304 async_answer_0(rid, rc); 1300 1305 free(old); 1301 1306 free(new); … … 1314 1319 if (new_node) 1315 1320 vfs_node_put(new_node); 1316 ipc_answer_0(rid, rc);1321 async_answer_0(rid, rc); 1317 1322 free(old); 1318 1323 free(new); … … 1331 1336 free(old); 1332 1337 free(new); 1333 ipc_answer_0(rid, EOK);1338 async_answer_0(rid, EOK); 1334 1339 } 1335 1340 … … 1338 1343 int oldfd = IPC_GET_ARG1(*request); 1339 1344 int newfd = IPC_GET_ARG2(*request); 1345 1346 /* If the file descriptors are the same, do nothing. */ 1347 if (oldfd == newfd) { 1348 async_answer_1(rid, EOK, newfd); 1349 return; 1350 } 1340 1351 1341 1352 /* Lookup the file structure corresponding to oldfd. */ 1342 1353 vfs_file_t *oldfile = vfs_file_get(oldfd); 1343 1354 if (!oldfile) { 1344 ipc_answer_0(rid, EBADF); 1345 return; 1346 } 1347 1348 /* If the file descriptors are the same, do nothing. */ 1349 if (oldfd == newfd) { 1350 ipc_answer_1(rid, EOK, newfd); 1355 async_answer_0(rid, EBADF); 1351 1356 return; 1352 1357 } … … 1365 1370 if (ret != EOK) { 1366 1371 fibril_mutex_unlock(&oldfile->lock); 1367 ipc_answer_0(rid, ret); 1372 vfs_file_put(oldfile); 1373 vfs_file_put(newfile); 1374 async_answer_0(rid, ret); 1368 1375 return; 1369 1376 } … … 1372 1379 if (ret != EOK) { 1373 1380 fibril_mutex_unlock(&oldfile->lock); 1374 ipc_answer_0(rid, ret); 1375 return; 1376 } 1381 vfs_file_put(oldfile); 1382 vfs_file_put(newfile); 1383 async_answer_0(rid, ret); 1384 return; 1385 } 1386 vfs_file_put(newfile); 1377 1387 } 1378 1388 … … 1380 1390 int ret = vfs_fd_assign(oldfile, newfd); 1381 1391 fibril_mutex_unlock(&oldfile->lock); 1392 vfs_file_put(oldfile); 1382 1393 1383 1394 if (ret != EOK) 1384 ipc_answer_0(rid, ret);1395 async_answer_0(rid, ret); 1385 1396 else 1386 ipc_answer_1(rid, EOK, newfd);1397 async_answer_1(rid, EOK, newfd); 1387 1398 } 1388 1399
Note:
See TracChangeset
for help on using the changeset viewer.