Changes in uspace/lib/c/generic/vfs/vfs.c [8e80d3f:79ae36dd] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r8e80d3f r79ae36dd 33 33 */ 34 34 35 #include <vfs/canonify.h> 35 36 #include <vfs/vfs.h> 36 #include <vfs/ canonify.h>37 #include <vfs/vfs_sess.h> 37 38 #include <macros.h> 38 39 #include <stdlib.h> … … 44 45 #include <sys/types.h> 45 46 #include <ipc/services.h> 46 #include < ipc/ns.h>47 #include <ns.h> 47 48 #include <async.h> 48 49 #include <fibril_synch.h> … … 54 55 #include <ipc/devmap.h> 55 56 56 static async_sess_t vfs_session; 57 58 static FIBRIL_MUTEX_INITIALIZE(vfs_phone_mutex); 59 static int vfs_phone = -1; 57 static FIBRIL_MUTEX_INITIALIZE(vfs_mutex); 58 static async_sess_t *vfs_sess = NULL; 60 59 61 60 static FIBRIL_MUTEX_INITIALIZE(cwd_mutex); … … 65 64 static size_t cwd_size = 0; 66 65 66 /** Start an async exchange on the VFS session. 67 * 68 * @return New exchange. 69 * 70 */ 71 static async_exch_t *vfs_exchange_begin(void) 72 { 73 fibril_mutex_lock(&vfs_mutex); 74 75 while (vfs_sess == NULL) 76 vfs_sess = service_connect_blocking(EXCHANGE_PARALLEL, SERVICE_VFS, 77 0, 0); 78 79 fibril_mutex_unlock(&vfs_mutex); 80 81 return async_exchange_begin(vfs_sess); 82 } 83 84 /** Finish an async exchange on the VFS session. 85 * 86 * @param exch Exchange to be finished. 87 * 88 */ 89 static void vfs_exchange_end(async_exch_t *exch) 90 { 91 async_exchange_end(exch); 92 } 93 67 94 char *absolutize(const char *path, size_t *retlen) 68 95 { 69 96 char *ncwd_path; 70 97 char *ncwd_path_nc; 71 size_t total_size;72 98 73 99 fibril_mutex_lock(&cwd_mutex); … … 78 104 return NULL; 79 105 } 80 total_size = cwd_size + 1 + size + 1; 81 ncwd_path_nc = malloc(total_size); 106 ncwd_path_nc = malloc(cwd_size + 1 + size + 1); 82 107 if (!ncwd_path_nc) { 83 108 fibril_mutex_unlock(&cwd_mutex); 84 109 return NULL; 85 110 } 86 str_cpy(ncwd_path_nc, total_size, cwd_path);111 str_cpy(ncwd_path_nc, cwd_size + 1 + size + 1, cwd_path); 87 112 ncwd_path_nc[cwd_size] = '/'; 88 113 ncwd_path_nc[cwd_size + 1] = '\0'; 89 114 } else { 90 total_size = size + 1; 91 ncwd_path_nc = malloc(total_size); 115 ncwd_path_nc = malloc(size + 1); 92 116 if (!ncwd_path_nc) { 93 117 fibril_mutex_unlock(&cwd_mutex); … … 96 120 ncwd_path_nc[0] = '\0'; 97 121 } 98 str_append(ncwd_path_nc, total_size, path);122 str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path); 99 123 ncwd_path = canonify(ncwd_path_nc, retlen); 100 124 if (!ncwd_path) { … … 118 142 } 119 143 120 /** Connect to VFS service and create session. */121 static void vfs_connect(void)122 {123 while (vfs_phone < 0)124 vfs_phone = service_connect_blocking(SERVICE_VFS, 0, 0);125 126 async_session_create(&vfs_session, vfs_phone, 0);127 }128 129 /** Start an async exchange on the VFS session.130 *131 * @return New phone to be used during the exchange.132 */133 static int vfs_exchange_begin(void)134 {135 fibril_mutex_lock(&vfs_phone_mutex);136 if (vfs_phone < 0)137 vfs_connect();138 fibril_mutex_unlock(&vfs_phone_mutex);139 140 return async_exchange_begin(&vfs_session);141 }142 143 /** End an async exchange on the VFS session.144 *145 * @param phone Phone used during the exchange.146 */147 static void vfs_exchange_end(int phone)148 {149 async_exchange_end(&vfs_session, phone);150 }151 152 144 int mount(const char *fs_name, const char *mp, const char *fqdn, 153 145 const char *opts, unsigned int flags) … … 186 178 } 187 179 188 int vfs_phone= vfs_exchange_begin();180 async_exch_t *exch = vfs_exchange_begin(); 189 181 190 182 sysarg_t rc_orig; 191 aid_t req = async_send_2( vfs_phone, VFS_IN_MOUNT, devmap_handle, flags, NULL);192 sysarg_t rc = async_data_write_start( vfs_phone, (void *) mpa, mpa_size);193 if (rc != EOK) { 194 vfs_exchange_end( vfs_phone);183 aid_t req = async_send_2(exch, VFS_IN_MOUNT, devmap_handle, flags, NULL); 184 sysarg_t rc = async_data_write_start(exch, (void *) mpa, mpa_size); 185 if (rc != EOK) { 186 vfs_exchange_end(exch); 195 187 free(mpa); 196 188 async_wait_for(req, &rc_orig); … … 205 197 } 206 198 207 rc = async_data_write_start( vfs_phone, (void *) opts, str_size(opts));208 if (rc != EOK) { 209 vfs_exchange_end( vfs_phone);199 rc = async_data_write_start(exch, (void *) opts, str_size(opts)); 200 if (rc != EOK) { 201 vfs_exchange_end(exch); 210 202 free(mpa); 211 203 async_wait_for(req, &rc_orig); … … 220 212 } 221 213 222 rc = async_data_write_start( vfs_phone, (void *) fs_name, str_size(fs_name));223 if (rc != EOK) { 224 vfs_exchange_end( vfs_phone);214 rc = async_data_write_start(exch, (void *) fs_name, str_size(fs_name)); 215 if (rc != EOK) { 216 vfs_exchange_end(exch); 225 217 free(mpa); 226 218 async_wait_for(req, &rc_orig); … … 236 228 237 229 /* Ask VFS whether it likes fs_name. */ 238 rc = async_req_0_0( vfs_phone, IPC_M_PING);239 if (rc != EOK) { 240 vfs_exchange_end( vfs_phone);230 rc = async_req_0_0(exch, VFS_IN_PING); 231 if (rc != EOK) { 232 vfs_exchange_end(exch); 241 233 free(mpa); 242 234 async_wait_for(req, &rc_orig); … … 251 243 } 252 244 253 vfs_exchange_end( vfs_phone);245 vfs_exchange_end(exch); 254 246 free(mpa); 255 247 async_wait_for(req, &rc); … … 273 265 return ENOMEM; 274 266 275 int vfs_phone= vfs_exchange_begin();276 277 req = async_send_0( vfs_phone, VFS_IN_UNMOUNT, NULL);278 rc = async_data_write_start( vfs_phone, (void *) mpa, mpa_size);279 if (rc != EOK) { 280 vfs_exchange_end( vfs_phone);267 async_exch_t *exch = vfs_exchange_begin(); 268 269 req = async_send_0(exch, VFS_IN_UNMOUNT, NULL); 270 rc = async_data_write_start(exch, (void *) mpa, mpa_size); 271 if (rc != EOK) { 272 vfs_exchange_end(exch); 281 273 free(mpa); 282 274 async_wait_for(req, &rc_orig); … … 288 280 289 281 290 vfs_exchange_end( vfs_phone);282 vfs_exchange_end(exch); 291 283 free(mpa); 292 284 async_wait_for(req, &rc); … … 297 289 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 298 290 { 299 int vfs_phone= vfs_exchange_begin();291 async_exch_t *exch = vfs_exchange_begin(); 300 292 301 293 ipc_call_t answer; 302 aid_t req = async_send_3( vfs_phone, VFS_IN_OPEN, lflag, oflag, 0, &answer);303 sysarg_t rc = async_data_write_start( vfs_phone, abs, abs_size);304 305 if (rc != EOK) { 306 vfs_exchange_end( vfs_phone);294 aid_t req = async_send_3(exch, VFS_IN_OPEN, lflag, oflag, 0, &answer); 295 sysarg_t rc = async_data_write_start(exch, abs, abs_size); 296 297 if (rc != EOK) { 298 vfs_exchange_end(exch); 307 299 308 300 sysarg_t rc_orig; … … 315 307 } 316 308 317 vfs_exchange_end( vfs_phone);309 vfs_exchange_end(exch); 318 310 async_wait_for(req, &rc); 319 311 … … 339 331 int open_node(fdi_node_t *node, int oflag) 340 332 { 341 int vfs_phone= vfs_exchange_begin();333 async_exch_t *exch = vfs_exchange_begin(); 342 334 343 335 ipc_call_t answer; 344 aid_t req = async_send_4( vfs_phone, VFS_IN_OPEN_NODE, node->fs_handle,336 aid_t req = async_send_4(exch, VFS_IN_OPEN_NODE, node->fs_handle, 345 337 node->devmap_handle, node->index, oflag, &answer); 346 338 347 vfs_exchange_end( vfs_phone);339 vfs_exchange_end(exch); 348 340 349 341 sysarg_t rc; … … 360 352 sysarg_t rc; 361 353 362 int vfs_phone = vfs_exchange_begin(); 363 364 rc = async_req_1_0(vfs_phone, VFS_IN_CLOSE, fildes); 365 366 vfs_exchange_end(vfs_phone); 367 368 return (int)rc; 354 async_exch_t *exch = vfs_exchange_begin(); 355 rc = async_req_1_0(exch, VFS_IN_CLOSE, fildes); 356 vfs_exchange_end(exch); 357 358 return (int) rc; 369 359 } 370 360 … … 374 364 ipc_call_t answer; 375 365 aid_t req; 376 377 int vfs_phone = vfs_exchange_begin(); 378 379 req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer); 380 rc = async_data_read_start_generic(vfs_phone, (void *) buf, nbyte, 381 IPC_XF_RESTRICT); 382 if (rc != EOK) { 383 vfs_exchange_end(vfs_phone); 366 367 async_exch_t *exch = vfs_exchange_begin(); 368 369 req = async_send_1(exch, VFS_IN_READ, fildes, &answer); 370 rc = async_data_read_start(exch, (void *)buf, nbyte); 371 if (rc != EOK) { 372 vfs_exchange_end(exch); 384 373 385 374 sysarg_t rc_orig; … … 391 380 return (ssize_t) rc_orig; 392 381 } 393 vfs_exchange_end( vfs_phone);382 vfs_exchange_end(exch); 394 383 async_wait_for(req, &rc); 395 384 if (rc == EOK) … … 404 393 ipc_call_t answer; 405 394 aid_t req; 406 407 int vfs_phone = vfs_exchange_begin(); 408 409 req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer); 410 rc = async_data_write_start_generic(vfs_phone, (void *) buf, nbyte, 411 IPC_XF_RESTRICT); 412 if (rc != EOK) { 413 vfs_exchange_end(vfs_phone); 395 396 async_exch_t *exch = vfs_exchange_begin(); 397 398 req = async_send_1(exch, VFS_IN_WRITE, fildes, &answer); 399 rc = async_data_write_start(exch, (void *)buf, nbyte); 400 if (rc != EOK) { 401 vfs_exchange_end(exch); 414 402 415 403 sysarg_t rc_orig; … … 421 409 return (ssize_t) rc_orig; 422 410 } 423 vfs_exchange_end( vfs_phone);411 vfs_exchange_end(exch); 424 412 async_wait_for(req, &rc); 425 413 if (rc == EOK) … … 431 419 int fsync(int fildes) 432 420 { 433 int vfs_phone = vfs_exchange_begin(); 434 435 sysarg_t rc = async_req_1_0(vfs_phone, VFS_IN_SYNC, fildes); 436 437 vfs_exchange_end(vfs_phone); 421 async_exch_t *exch = vfs_exchange_begin(); 422 sysarg_t rc = async_req_1_0(exch, VFS_IN_SYNC, fildes); 423 vfs_exchange_end(exch); 438 424 439 425 return (int) rc; … … 442 428 off64_t lseek(int fildes, off64_t offset, int whence) 443 429 { 444 int vfs_phone= vfs_exchange_begin();430 async_exch_t *exch = vfs_exchange_begin(); 445 431 446 432 sysarg_t newoff_lo; 447 433 sysarg_t newoff_hi; 448 sysarg_t rc = async_req_4_2( vfs_phone, VFS_IN_SEEK, fildes,434 sysarg_t rc = async_req_4_2(exch, VFS_IN_SEEK, fildes, 449 435 LOWER32(offset), UPPER32(offset), whence, 450 436 &newoff_lo, &newoff_hi); 451 437 452 vfs_exchange_end( vfs_phone);438 vfs_exchange_end(exch); 453 439 454 440 if (rc != EOK) … … 462 448 sysarg_t rc; 463 449 464 int vfs_phone = vfs_exchange_begin(); 465 466 rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes, 450 async_exch_t *exch = vfs_exchange_begin(); 451 rc = async_req_3_0(exch, VFS_IN_TRUNCATE, fildes, 467 452 LOWER32(length), UPPER32(length)); 468 vfs_exchange_end( vfs_phone);453 vfs_exchange_end(exch); 469 454 470 455 return (int) rc; … … 475 460 sysarg_t rc; 476 461 aid_t req; 477 478 int vfs_phone= vfs_exchange_begin();479 480 req = async_send_1( vfs_phone, VFS_IN_FSTAT, fildes, NULL);481 rc = async_data_read_start( vfs_phone, (void *) stat, sizeof(struct stat));482 if (rc != EOK) { 483 vfs_exchange_end( vfs_phone);462 463 async_exch_t *exch = vfs_exchange_begin(); 464 465 req = async_send_1(exch, VFS_IN_FSTAT, fildes, NULL); 466 rc = async_data_read_start(exch, (void *) stat, sizeof(struct stat)); 467 if (rc != EOK) { 468 vfs_exchange_end(exch); 484 469 485 470 sysarg_t rc_orig; … … 491 476 return (ssize_t) rc_orig; 492 477 } 493 vfs_exchange_end( vfs_phone);478 vfs_exchange_end(exch); 494 479 async_wait_for(req, &rc); 495 480 … … 508 493 return ENOMEM; 509 494 510 int vfs_phone= vfs_exchange_begin();511 512 req = async_send_0( vfs_phone, VFS_IN_STAT, NULL);513 rc = async_data_write_start( vfs_phone, pa, pa_size);514 if (rc != EOK) { 515 vfs_exchange_end( vfs_phone);495 async_exch_t *exch = vfs_exchange_begin(); 496 497 req = async_send_0(exch, VFS_IN_STAT, NULL); 498 rc = async_data_write_start(exch, pa, pa_size); 499 if (rc != EOK) { 500 vfs_exchange_end(exch); 516 501 free(pa); 517 502 async_wait_for(req, &rc_orig); … … 521 506 return (int) rc_orig; 522 507 } 523 rc = async_data_read_start( vfs_phone, stat, sizeof(struct stat));524 if (rc != EOK) { 525 vfs_exchange_end( vfs_phone);508 rc = async_data_read_start(exch, stat, sizeof(struct stat)); 509 if (rc != EOK) { 510 vfs_exchange_end(exch); 526 511 free(pa); 527 512 async_wait_for(req, &rc_orig); … … 531 516 return (int) rc_orig; 532 517 } 533 vfs_exchange_end( vfs_phone);518 vfs_exchange_end(exch); 534 519 free(pa); 535 520 async_wait_for(req, &rc); … … 592 577 return ENOMEM; 593 578 594 int vfs_phone= vfs_exchange_begin();595 596 req = async_send_1( vfs_phone, VFS_IN_MKDIR, mode, NULL);597 rc = async_data_write_start( vfs_phone, pa, pa_size);598 if (rc != EOK) { 599 vfs_exchange_end( vfs_phone);579 async_exch_t *exch = vfs_exchange_begin(); 580 581 req = async_send_1(exch, VFS_IN_MKDIR, mode, NULL); 582 rc = async_data_write_start(exch, pa, pa_size); 583 if (rc != EOK) { 584 vfs_exchange_end(exch); 600 585 free(pa); 601 586 … … 608 593 return (int) rc_orig; 609 594 } 610 vfs_exchange_end( vfs_phone);595 vfs_exchange_end(exch); 611 596 free(pa); 612 597 async_wait_for(req, &rc); … … 623 608 if (!pa) 624 609 return ENOMEM; 625 626 int vfs_phone= vfs_exchange_begin();627 628 req = async_send_0( vfs_phone, VFS_IN_UNLINK, NULL);629 rc = async_data_write_start( vfs_phone, pa, pa_size);630 if (rc != EOK) { 631 vfs_exchange_end( vfs_phone);610 611 async_exch_t *exch = vfs_exchange_begin(); 612 613 req = async_send_0(exch, VFS_IN_UNLINK, NULL); 614 rc = async_data_write_start(exch, pa, pa_size); 615 if (rc != EOK) { 616 vfs_exchange_end(exch); 632 617 free(pa); 633 618 … … 640 625 return (int) rc_orig; 641 626 } 642 vfs_exchange_end( vfs_phone);627 vfs_exchange_end(exch); 643 628 free(pa); 644 629 async_wait_for(req, &rc); … … 673 658 return ENOMEM; 674 659 } 675 676 int vfs_phone= vfs_exchange_begin();677 678 req = async_send_0( vfs_phone, VFS_IN_RENAME, NULL);679 rc = async_data_write_start( vfs_phone, olda, olda_size);680 if (rc != EOK) { 681 vfs_exchange_end( vfs_phone);660 661 async_exch_t *exch = vfs_exchange_begin(); 662 663 req = async_send_0(exch, VFS_IN_RENAME, NULL); 664 rc = async_data_write_start(exch, olda, olda_size); 665 if (rc != EOK) { 666 vfs_exchange_end(exch); 682 667 free(olda); 683 668 free(newa); … … 688 673 return (int) rc_orig; 689 674 } 690 rc = async_data_write_start( vfs_phone, newa, newa_size);691 if (rc != EOK) { 692 vfs_exchange_end( vfs_phone);675 rc = async_data_write_start(exch, newa, newa_size); 676 if (rc != EOK) { 677 vfs_exchange_end(exch); 693 678 free(olda); 694 679 free(newa); … … 699 684 return (int) rc_orig; 700 685 } 701 vfs_exchange_end( vfs_phone);686 vfs_exchange_end(exch); 702 687 free(olda); 703 688 free(newa); … … 755 740 } 756 741 757 int fd_phone(int fildes)742 async_sess_t *fd_session(exch_mgmt_t mgmt, int fildes) 758 743 { 759 744 struct stat stat; 760 761 745 int rc = fstat(fildes, &stat); 762 if (rc != 0) 763 return rc; 764 765 if (!stat.device) 766 return -1; 767 768 return devmap_device_connect(stat.device, 0); 746 if (rc != 0) { 747 errno = rc; 748 return NULL; 749 } 750 751 if (!stat.device) { 752 errno = ENOENT; 753 return NULL; 754 } 755 756 return devmap_device_connect(mgmt, stat.device, 0); 769 757 } 770 758 … … 772 760 { 773 761 struct stat stat; 774 int rc; 775 776 rc = fstat(fildes, &stat); 762 int rc = fstat(fildes, &stat); 777 763 778 764 if (rc == EOK) { … … 787 773 int dup2(int oldfd, int newfd) 788 774 { 789 int vfs_phone= vfs_exchange_begin();775 async_exch_t *exch = vfs_exchange_begin(); 790 776 791 777 sysarg_t ret; 792 sysarg_t rc = async_req_2_1( vfs_phone, VFS_IN_DUP, oldfd, newfd, &ret);793 794 vfs_exchange_end( vfs_phone);778 sysarg_t rc = async_req_2_1(exch, VFS_IN_DUP, oldfd, newfd, &ret); 779 780 vfs_exchange_end(exch); 795 781 796 782 if (rc == EOK)
Note:
See TracChangeset
for help on using the changeset viewer.