Changeset a28ab12 in mainline
- Timestamp:
- 2011-01-26T00:27:37Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8b65e547
- Parents:
- b75e929
- git-author:
- Vojtech Horky <> (2011-01-26 00:27:37)
- git-committer:
- Jakub Jermar <jakub@…> (2011-01-26 00:27:37)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
rb75e929 ra28ab12 46 46 #include <ipc/services.h> 47 47 #include <async.h> 48 #include <atomic.h> 49 #include <futex.h> 48 #include <fibril_synch.h> 50 49 #include <errno.h> 50 #include <assert.h> 51 51 #include <str.h> 52 52 #include <devmap.h> … … 54 54 #include <ipc/devmap.h> 55 55 56 static async_sess_t vfs_session; 57 58 static FIBRIL_MUTEX_INITIALIZE(vfs_phone_mutex); 56 59 static int vfs_phone = -1; 57 static futex_t vfs_phone_futex = FUTEX_INITIALIZER; 58 static futex_t cwd_futex = FUTEX_INITIALIZER;60 61 static FIBRIL_MUTEX_INITIALIZE(cwd_mutex); 59 62 60 63 static int cwd_fd = -1; … … 67 70 char *ncwd_path_nc; 68 71 69 f utex_down(&cwd_futex);72 fibril_mutex_lock(&cwd_mutex); 70 73 size_t size = str_size(path); 71 74 if (*path != '/') { 72 75 if (!cwd_path) { 73 f utex_up(&cwd_futex);76 fibril_mutex_unlock(&cwd_mutex); 74 77 return NULL; 75 78 } 76 79 ncwd_path_nc = malloc(cwd_size + 1 + size + 1); 77 80 if (!ncwd_path_nc) { 78 f utex_up(&cwd_futex);81 fibril_mutex_unlock(&cwd_mutex); 79 82 return NULL; 80 83 } … … 85 88 ncwd_path_nc = malloc(size + 1); 86 89 if (!ncwd_path_nc) { 87 f utex_up(&cwd_futex);90 fibril_mutex_unlock(&cwd_mutex); 88 91 return NULL; 89 92 } … … 93 96 ncwd_path = canonify(ncwd_path_nc, retlen); 94 97 if (!ncwd_path) { 95 f utex_up(&cwd_futex);98 fibril_mutex_unlock(&cwd_mutex); 96 99 free(ncwd_path_nc); 97 100 return NULL; … … 105 108 free(ncwd_path_nc); 106 109 if (!ncwd_path) { 107 f utex_up(&cwd_futex);110 fibril_mutex_unlock(&cwd_mutex); 108 111 return NULL; 109 112 } 110 f utex_up(&cwd_futex);113 fibril_mutex_unlock(&cwd_mutex); 111 114 return ncwd_path; 112 115 } 113 116 117 /** Connect to VFS service and create session. */ 114 118 static void vfs_connect(void) 115 119 { 116 while (vfs_phone < 0) 117 vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 0); 120 while (vfs_phone < 0) { 121 vfs_phone = async_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 122 0, 0); 123 } 124 125 async_session_create(&vfs_session, vfs_phone, 0); 126 } 127 128 /** Start an async exchange on the VFS session. 129 * 130 * @return New phone to be used during the exchange. 131 */ 132 static int vfs_exchange_begin(void) 133 { 134 fibril_mutex_lock(&vfs_phone_mutex); 135 if (vfs_phone < 0) 136 vfs_connect(); 137 fibril_mutex_unlock(&vfs_phone_mutex); 138 139 return async_exchange_begin(&vfs_session); 140 } 141 142 /** End an async exchange on the VFS session. 143 * 144 * @param phone Phone used during the exchange. 145 */ 146 static void vfs_exchange_end(int phone) 147 { 148 async_exchange_end(&vfs_session, phone); 118 149 } 119 150 … … 154 185 } 155 186 156 futex_down(&vfs_phone_futex); 157 async_serialize_start(); 158 vfs_connect(); 159 187 int vfs_phone = vfs_exchange_begin(); 188 160 189 sysarg_t rc_orig; 161 190 aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, devmap_handle, flags, NULL); 162 191 sysarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size); 163 192 if (rc != EOK) { 164 async_wait_for(req, &rc_orig); 165 async_serialize_end(); 166 futex_up(&vfs_phone_futex); 193 vfs_exchange_end(vfs_phone); 167 194 free(mpa); 195 async_wait_for(req, &rc_orig); 168 196 169 197 if (null_id != -1) … … 178 206 rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts)); 179 207 if (rc != EOK) { 180 async_wait_for(req, &rc_orig); 181 async_serialize_end(); 182 futex_up(&vfs_phone_futex); 208 vfs_exchange_end(vfs_phone); 183 209 free(mpa); 210 async_wait_for(req, &rc_orig); 184 211 185 212 if (null_id != -1) … … 194 221 rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name)); 195 222 if (rc != EOK) { 196 async_wait_for(req, &rc_orig); 197 async_serialize_end(); 198 futex_up(&vfs_phone_futex); 223 vfs_exchange_end(vfs_phone); 199 224 free(mpa); 225 async_wait_for(req, &rc_orig); 200 226 201 227 if (null_id != -1) … … 211 237 rc = async_req_0_0(vfs_phone, IPC_M_PING); 212 238 if (rc != EOK) { 213 async_wait_for(req, &rc_orig); 214 async_serialize_end(); 215 futex_up(&vfs_phone_futex); 239 vfs_exchange_end(vfs_phone); 216 240 free(mpa); 241 async_wait_for(req, &rc_orig); 217 242 218 243 if (null_id != -1) … … 225 250 } 226 251 227 async_wait_for(req, &rc); 228 async_serialize_end(); 229 futex_up(&vfs_phone_futex); 252 vfs_exchange_end(vfs_phone); 230 253 free(mpa); 254 async_wait_for(req, &rc); 231 255 232 256 if ((rc != EOK) && (null_id != -1)) … … 248 272 return ENOMEM; 249 273 250 futex_down(&vfs_phone_futex); 251 async_serialize_start(); 252 vfs_connect(); 274 int vfs_phone = vfs_exchange_begin(); 253 275 254 276 req = async_send_0(vfs_phone, VFS_IN_UNMOUNT, NULL); 255 277 rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size); 256 278 if (rc != EOK) { 257 async_wait_for(req, &rc_orig); 258 async_serialize_end(); 259 futex_up(&vfs_phone_futex); 279 vfs_exchange_end(vfs_phone); 260 280 free(mpa); 261 if (rc_orig == EOK) 262 return (int) rc; 263 else 264 return (int) rc_orig; 265 } 266 267 268 async_wait_for(req, &rc); 269 async_serialize_end(); 270 futex_up(&vfs_phone_futex); 281 async_wait_for(req, &rc_orig); 282 if (rc_orig == EOK) 283 return (int) rc; 284 else 285 return (int) rc_orig; 286 } 287 288 289 vfs_exchange_end(vfs_phone); 271 290 free(mpa); 291 async_wait_for(req, &rc); 272 292 273 293 return (int) rc; … … 276 296 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 277 297 { 278 futex_down(&vfs_phone_futex); 279 async_serialize_start(); 280 vfs_connect(); 298 int vfs_phone = vfs_exchange_begin(); 281 299 282 300 ipc_call_t answer; … … 285 303 286 304 if (rc != EOK) { 305 vfs_exchange_end(vfs_phone); 306 287 307 sysarg_t rc_orig; 288 308 async_wait_for(req, &rc_orig); 289 309 290 async_serialize_end(); 291 futex_up(&vfs_phone_futex); 292 293 if (rc_orig == EOK) 294 return (int) rc; 295 else 296 return (int) rc_orig; 297 } 298 299 async_wait_for(req, &rc); 300 async_serialize_end(); 301 futex_up(&vfs_phone_futex); 310 if (rc_orig == EOK) 311 return (int) rc; 312 else 313 return (int) rc_orig; 314 } 315 316 vfs_exchange_end(vfs_phone); 317 async_wait_for(req, &rc); 302 318 303 319 if (rc != EOK) … … 322 338 int open_node(fdi_node_t *node, int oflag) 323 339 { 324 futex_down(&vfs_phone_futex); 325 async_serialize_start(); 326 vfs_connect(); 340 int vfs_phone = vfs_exchange_begin(); 327 341 328 342 ipc_call_t answer; … … 330 344 node->devmap_handle, node->index, oflag, &answer); 331 345 332 sysarg_t rc;333 async_wait_for(req, &rc); 334 async_serialize_end();335 futex_up(&vfs_phone_futex);346 vfs_exchange_end(vfs_phone); 347 348 sysarg_t rc; 349 async_wait_for(req, &rc); 336 350 337 351 if (rc != EOK) … … 345 359 sysarg_t rc; 346 360 347 futex_down(&vfs_phone_futex); 348 async_serialize_start(); 349 vfs_connect(); 361 int vfs_phone = vfs_exchange_begin(); 350 362 351 363 rc = async_req_1_0(vfs_phone, VFS_IN_CLOSE, fildes); 352 364 353 async_serialize_end(); 354 futex_up(&vfs_phone_futex); 365 vfs_exchange_end(vfs_phone); 355 366 356 367 return (int)rc; … … 363 374 aid_t req; 364 375 365 futex_down(&vfs_phone_futex); 366 async_serialize_start(); 367 vfs_connect(); 376 int vfs_phone = vfs_exchange_begin(); 368 377 369 378 req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer); 370 379 rc = async_data_read_start(vfs_phone, (void *)buf, nbyte); 371 380 if (rc != EOK) { 381 vfs_exchange_end(vfs_phone); 382 372 383 sysarg_t rc_orig; 373 374 async_wait_for(req, &rc_orig); 375 async_serialize_end(); 376 futex_up(&vfs_phone_futex); 384 async_wait_for(req, &rc_orig); 385 377 386 if (rc_orig == EOK) 378 387 return (ssize_t) rc; … … 380 389 return (ssize_t) rc_orig; 381 390 } 382 async_wait_for(req, &rc); 383 async_serialize_end(); 384 futex_up(&vfs_phone_futex); 391 vfs_exchange_end(vfs_phone); 392 async_wait_for(req, &rc); 385 393 if (rc == EOK) 386 394 return (ssize_t) IPC_GET_ARG1(answer); … … 395 403 aid_t req; 396 404 397 futex_down(&vfs_phone_futex); 398 async_serialize_start(); 399 vfs_connect(); 405 int vfs_phone = vfs_exchange_begin(); 400 406 401 407 req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer); 402 408 rc = async_data_write_start(vfs_phone, (void *)buf, nbyte); 403 409 if (rc != EOK) { 410 vfs_exchange_end(vfs_phone); 411 404 412 sysarg_t rc_orig; 405 406 async_wait_for(req, &rc_orig); 407 async_serialize_end(); 408 futex_up(&vfs_phone_futex); 413 async_wait_for(req, &rc_orig); 414 409 415 if (rc_orig == EOK) 410 416 return (ssize_t) rc; … … 412 418 return (ssize_t) rc_orig; 413 419 } 414 async_wait_for(req, &rc); 415 async_serialize_end(); 416 futex_up(&vfs_phone_futex); 420 vfs_exchange_end(vfs_phone); 421 async_wait_for(req, &rc); 417 422 if (rc == EOK) 418 423 return (ssize_t) IPC_GET_ARG1(answer); … … 423 428 int fsync(int fildes) 424 429 { 425 futex_down(&vfs_phone_futex); 426 async_serialize_start(); 427 vfs_connect(); 430 int vfs_phone = vfs_exchange_begin(); 428 431 429 432 sysarg_t rc = async_req_1_0(vfs_phone, VFS_IN_SYNC, fildes); 430 433 431 async_serialize_end(); 432 futex_up(&vfs_phone_futex); 434 vfs_exchange_end(vfs_phone); 433 435 434 436 return (int) rc; … … 437 439 off64_t lseek(int fildes, off64_t offset, int whence) 438 440 { 439 futex_down(&vfs_phone_futex); 440 async_serialize_start(); 441 vfs_connect(); 441 int vfs_phone = vfs_exchange_begin(); 442 442 443 443 sysarg_t newoff_lo; … … 447 447 &newoff_lo, &newoff_hi); 448 448 449 async_serialize_end(); 450 futex_up(&vfs_phone_futex); 449 vfs_exchange_end(vfs_phone); 451 450 452 451 if (rc != EOK) … … 460 459 sysarg_t rc; 461 460 462 futex_down(&vfs_phone_futex); 463 async_serialize_start(); 464 vfs_connect(); 461 int vfs_phone = vfs_exchange_begin(); 465 462 466 463 rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes, 467 464 LOWER32(length), UPPER32(length)); 468 async_serialize_end(); 469 futex_up(&vfs_phone_futex); 465 vfs_exchange_end(vfs_phone); 470 466 471 467 return (int) rc; … … 477 473 aid_t req; 478 474 479 futex_down(&vfs_phone_futex); 480 async_serialize_start(); 481 vfs_connect(); 475 int vfs_phone = vfs_exchange_begin(); 482 476 483 477 req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL); 484 478 rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat)); 485 479 if (rc != EOK) { 480 vfs_exchange_end(vfs_phone); 481 486 482 sysarg_t rc_orig; 487 488 async_wait_for(req, &rc_orig); 489 async_serialize_end(); 490 futex_up(&vfs_phone_futex); 483 async_wait_for(req, &rc_orig); 484 491 485 if (rc_orig == EOK) 492 486 return (ssize_t) rc; … … 494 488 return (ssize_t) rc_orig; 495 489 } 496 async_wait_for(req, &rc); 497 async_serialize_end(); 498 futex_up(&vfs_phone_futex); 490 vfs_exchange_end(vfs_phone); 491 async_wait_for(req, &rc); 499 492 500 493 return rc; … … 512 505 return ENOMEM; 513 506 514 futex_down(&vfs_phone_futex); 515 async_serialize_start(); 516 vfs_connect(); 507 int vfs_phone = vfs_exchange_begin(); 517 508 518 509 req = async_send_0(vfs_phone, VFS_IN_STAT, NULL); 519 510 rc = async_data_write_start(vfs_phone, pa, pa_size); 520 511 if (rc != EOK) { 521 async_wait_for(req, &rc_orig); 522 async_serialize_end(); 523 futex_up(&vfs_phone_futex); 512 vfs_exchange_end(vfs_phone); 524 513 free(pa); 514 async_wait_for(req, &rc_orig); 525 515 if (rc_orig == EOK) 526 516 return (int) rc; … … 530 520 rc = async_data_read_start(vfs_phone, stat, sizeof(struct stat)); 531 521 if (rc != EOK) { 532 async_wait_for(req, &rc_orig); 533 async_serialize_end(); 534 futex_up(&vfs_phone_futex); 522 vfs_exchange_end(vfs_phone); 535 523 free(pa); 536 if (rc_orig == EOK) 537 return (int) rc; 538 else 539 return (int) rc_orig; 540 } 541 async_wait_for(req, &rc); 542 async_serialize_end(); 543 futex_up(&vfs_phone_futex); 524 async_wait_for(req, &rc_orig); 525 if (rc_orig == EOK) 526 return (int) rc; 527 else 528 return (int) rc_orig; 529 } 530 vfs_exchange_end(vfs_phone); 544 531 free(pa); 532 async_wait_for(req, &rc); 545 533 return rc; 546 534 } … … 601 589 return ENOMEM; 602 590 603 futex_down(&vfs_phone_futex); 604 async_serialize_start(); 605 vfs_connect(); 591 int vfs_phone = vfs_exchange_begin(); 606 592 607 593 req = async_send_1(vfs_phone, VFS_IN_MKDIR, mode, NULL); 608 594 rc = async_data_write_start(vfs_phone, pa, pa_size); 609 595 if (rc != EOK) { 596 vfs_exchange_end(vfs_phone); 597 free(pa); 598 610 599 sysarg_t rc_orig; 611 612 async_wait_for(req, &rc_orig); 613 async_serialize_end(); 614 futex_up(&vfs_phone_futex); 615 free(pa); 616 if (rc_orig == EOK) 617 return (int) rc; 618 else 619 return (int) rc_orig; 620 } 621 async_wait_for(req, &rc); 622 async_serialize_end(); 623 futex_up(&vfs_phone_futex); 600 async_wait_for(req, &rc_orig); 601 602 if (rc_orig == EOK) 603 return (int) rc; 604 else 605 return (int) rc_orig; 606 } 607 vfs_exchange_end(vfs_phone); 624 608 free(pa); 609 async_wait_for(req, &rc); 625 610 return rc; 626 611 } … … 636 621 return ENOMEM; 637 622 638 futex_down(&vfs_phone_futex); 639 async_serialize_start(); 640 vfs_connect(); 623 int vfs_phone = vfs_exchange_begin(); 641 624 642 625 req = async_send_0(vfs_phone, VFS_IN_UNLINK, NULL); 643 626 rc = async_data_write_start(vfs_phone, pa, pa_size); 644 627 if (rc != EOK) { 628 vfs_exchange_end(vfs_phone); 629 free(pa); 630 645 631 sysarg_t rc_orig; 646 647 async_wait_for(req, &rc_orig); 648 async_serialize_end(); 649 futex_up(&vfs_phone_futex); 650 free(pa); 651 if (rc_orig == EOK) 652 return (int) rc; 653 else 654 return (int) rc_orig; 655 } 656 async_wait_for(req, &rc); 657 async_serialize_end(); 658 futex_up(&vfs_phone_futex); 632 async_wait_for(req, &rc_orig); 633 634 if (rc_orig == EOK) 635 return (int) rc; 636 else 637 return (int) rc_orig; 638 } 639 vfs_exchange_end(vfs_phone); 659 640 free(pa); 641 async_wait_for(req, &rc); 660 642 return rc; 661 643 } … … 689 671 } 690 672 691 futex_down(&vfs_phone_futex); 692 async_serialize_start(); 693 vfs_connect(); 673 int vfs_phone = vfs_exchange_begin(); 694 674 695 675 req = async_send_0(vfs_phone, VFS_IN_RENAME, NULL); 696 676 rc = async_data_write_start(vfs_phone, olda, olda_size); 697 677 if (rc != EOK) { 698 async_wait_for(req, &rc_orig); 699 async_serialize_end(); 700 futex_up(&vfs_phone_futex); 678 vfs_exchange_end(vfs_phone); 701 679 free(olda); 702 680 free(newa); 681 async_wait_for(req, &rc_orig); 703 682 if (rc_orig == EOK) 704 683 return (int) rc; … … 708 687 rc = async_data_write_start(vfs_phone, newa, newa_size); 709 688 if (rc != EOK) { 710 async_wait_for(req, &rc_orig); 711 async_serialize_end(); 712 futex_up(&vfs_phone_futex); 689 vfs_exchange_end(vfs_phone); 713 690 free(olda); 714 691 free(newa); 715 if (rc_orig == EOK) 716 return (int) rc; 717 else 718 return (int) rc_orig; 719 } 720 async_wait_for(req, &rc); 721 async_serialize_end(); 722 futex_up(&vfs_phone_futex); 692 async_wait_for(req, &rc_orig); 693 if (rc_orig == EOK) 694 return (int) rc; 695 else 696 return (int) rc_orig; 697 } 698 vfs_exchange_end(vfs_phone); 723 699 free(olda); 724 700 free(newa); 701 async_wait_for(req, &rc); 725 702 return rc; 726 703 } … … 740 717 } 741 718 742 f utex_down(&cwd_futex);719 fibril_mutex_lock(&cwd_mutex); 743 720 744 721 if (cwd_fd >= 0) … … 753 730 cwd_size = abs_size; 754 731 755 f utex_up(&cwd_futex);732 fibril_mutex_unlock(&cwd_mutex); 756 733 return EOK; 757 734 } … … 762 739 return NULL; 763 740 764 f utex_down(&cwd_futex);741 fibril_mutex_lock(&cwd_mutex); 765 742 766 743 if ((cwd_size == 0) || (size < cwd_size + 1)) { 767 f utex_up(&cwd_futex);744 fibril_mutex_unlock(&cwd_mutex); 768 745 return NULL; 769 746 } 770 747 771 748 str_cpy(buf, size, cwd_path); 772 f utex_up(&cwd_futex);749 fibril_mutex_unlock(&cwd_mutex); 773 750 774 751 return buf; … … 806 783 int dup2(int oldfd, int newfd) 807 784 { 808 futex_down(&vfs_phone_futex); 809 async_serialize_start(); 810 vfs_connect(); 785 int vfs_phone = vfs_exchange_begin(); 811 786 812 787 sysarg_t ret; 813 788 sysarg_t rc = async_req_2_1(vfs_phone, VFS_IN_DUP, oldfd, newfd, &ret); 814 789 815 async_serialize_end(); 816 futex_up(&vfs_phone_futex); 790 vfs_exchange_end(vfs_phone); 817 791 818 792 if (rc == EOK)
Note:
See TracChangeset
for help on using the changeset viewer.