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