Changes in uspace/lib/c/generic/vfs/vfs.c [79ae36dd:8e80d3f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r79ae36dd r8e80d3f 33 33 */ 34 34 35 #include <vfs/vfs.h> 35 36 #include <vfs/canonify.h> 36 #include <vfs/vfs.h>37 #include <vfs/vfs_sess.h>38 37 #include <macros.h> 39 38 #include <stdlib.h> … … 45 44 #include <sys/types.h> 46 45 #include <ipc/services.h> 47 #include < ns.h>46 #include <ipc/ns.h> 48 47 #include <async.h> 49 48 #include <fibril_synch.h> … … 55 54 #include <ipc/devmap.h> 56 55 57 static FIBRIL_MUTEX_INITIALIZE(vfs_mutex); 58 static async_sess_t *vfs_sess = NULL; 56 static async_sess_t vfs_session; 57 58 static FIBRIL_MUTEX_INITIALIZE(vfs_phone_mutex); 59 static int vfs_phone = -1; 59 60 60 61 static FIBRIL_MUTEX_INITIALIZE(cwd_mutex); … … 64 65 static size_t cwd_size = 0; 65 66 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 94 67 char *absolutize(const char *path, size_t *retlen) 95 68 { 96 69 char *ncwd_path; 97 70 char *ncwd_path_nc; 71 size_t total_size; 98 72 99 73 fibril_mutex_lock(&cwd_mutex); … … 104 78 return NULL; 105 79 } 106 ncwd_path_nc = malloc(cwd_size + 1 + size + 1); 80 total_size = cwd_size + 1 + size + 1; 81 ncwd_path_nc = malloc(total_size); 107 82 if (!ncwd_path_nc) { 108 83 fibril_mutex_unlock(&cwd_mutex); 109 84 return NULL; 110 85 } 111 str_cpy(ncwd_path_nc, cwd_size + 1 + size + 1, cwd_path);86 str_cpy(ncwd_path_nc, total_size, cwd_path); 112 87 ncwd_path_nc[cwd_size] = '/'; 113 88 ncwd_path_nc[cwd_size + 1] = '\0'; 114 89 } else { 115 ncwd_path_nc = malloc(size + 1); 90 total_size = size + 1; 91 ncwd_path_nc = malloc(total_size); 116 92 if (!ncwd_path_nc) { 117 93 fibril_mutex_unlock(&cwd_mutex); … … 120 96 ncwd_path_nc[0] = '\0'; 121 97 } 122 str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path);98 str_append(ncwd_path_nc, total_size, path); 123 99 ncwd_path = canonify(ncwd_path_nc, retlen); 124 100 if (!ncwd_path) { … … 142 118 } 143 119 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 144 152 int mount(const char *fs_name, const char *mp, const char *fqdn, 145 153 const char *opts, unsigned int flags) … … 178 186 } 179 187 180 async_exch_t *exch= vfs_exchange_begin();188 int vfs_phone = vfs_exchange_begin(); 181 189 182 190 sysarg_t rc_orig; 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);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); 187 195 free(mpa); 188 196 async_wait_for(req, &rc_orig); … … 197 205 } 198 206 199 rc = async_data_write_start( exch, (void *) opts, str_size(opts));200 if (rc != EOK) { 201 vfs_exchange_end( exch);207 rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts)); 208 if (rc != EOK) { 209 vfs_exchange_end(vfs_phone); 202 210 free(mpa); 203 211 async_wait_for(req, &rc_orig); … … 212 220 } 213 221 214 rc = async_data_write_start( exch, (void *) fs_name, str_size(fs_name));215 if (rc != EOK) { 216 vfs_exchange_end( exch);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); 217 225 free(mpa); 218 226 async_wait_for(req, &rc_orig); … … 228 236 229 237 /* Ask VFS whether it likes fs_name. */ 230 rc = async_req_0_0( exch, VFS_IN_PING);231 if (rc != EOK) { 232 vfs_exchange_end( exch);238 rc = async_req_0_0(vfs_phone, IPC_M_PING); 239 if (rc != EOK) { 240 vfs_exchange_end(vfs_phone); 233 241 free(mpa); 234 242 async_wait_for(req, &rc_orig); … … 243 251 } 244 252 245 vfs_exchange_end( exch);253 vfs_exchange_end(vfs_phone); 246 254 free(mpa); 247 255 async_wait_for(req, &rc); … … 265 273 return ENOMEM; 266 274 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);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); 273 281 free(mpa); 274 282 async_wait_for(req, &rc_orig); … … 280 288 281 289 282 vfs_exchange_end( exch);290 vfs_exchange_end(vfs_phone); 283 291 free(mpa); 284 292 async_wait_for(req, &rc); … … 289 297 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 290 298 { 291 async_exch_t *exch= vfs_exchange_begin();299 int vfs_phone = vfs_exchange_begin(); 292 300 293 301 ipc_call_t answer; 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);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); 299 307 300 308 sysarg_t rc_orig; … … 307 315 } 308 316 309 vfs_exchange_end( exch);317 vfs_exchange_end(vfs_phone); 310 318 async_wait_for(req, &rc); 311 319 … … 331 339 int open_node(fdi_node_t *node, int oflag) 332 340 { 333 async_exch_t *exch= vfs_exchange_begin();341 int vfs_phone = vfs_exchange_begin(); 334 342 335 343 ipc_call_t answer; 336 aid_t req = async_send_4( exch, VFS_IN_OPEN_NODE, node->fs_handle,344 aid_t req = async_send_4(vfs_phone, VFS_IN_OPEN_NODE, node->fs_handle, 337 345 node->devmap_handle, node->index, oflag, &answer); 338 346 339 vfs_exchange_end( exch);347 vfs_exchange_end(vfs_phone); 340 348 341 349 sysarg_t rc; … … 352 360 sysarg_t rc; 353 361 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; 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; 359 369 } 360 370 … … 364 374 ipc_call_t answer; 365 375 aid_t req; 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); 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); 373 384 374 385 sysarg_t rc_orig; … … 380 391 return (ssize_t) rc_orig; 381 392 } 382 vfs_exchange_end( exch);393 vfs_exchange_end(vfs_phone); 383 394 async_wait_for(req, &rc); 384 395 if (rc == EOK) … … 393 404 ipc_call_t answer; 394 405 aid_t req; 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); 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); 402 414 403 415 sysarg_t rc_orig; … … 409 421 return (ssize_t) rc_orig; 410 422 } 411 vfs_exchange_end( exch);423 vfs_exchange_end(vfs_phone); 412 424 async_wait_for(req, &rc); 413 425 if (rc == EOK) … … 419 431 int fsync(int fildes) 420 432 { 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); 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); 424 438 425 439 return (int) rc; … … 428 442 off64_t lseek(int fildes, off64_t offset, int whence) 429 443 { 430 async_exch_t *exch= vfs_exchange_begin();444 int vfs_phone = vfs_exchange_begin(); 431 445 432 446 sysarg_t newoff_lo; 433 447 sysarg_t newoff_hi; 434 sysarg_t rc = async_req_4_2( exch, VFS_IN_SEEK, fildes,448 sysarg_t rc = async_req_4_2(vfs_phone, VFS_IN_SEEK, fildes, 435 449 LOWER32(offset), UPPER32(offset), whence, 436 450 &newoff_lo, &newoff_hi); 437 451 438 vfs_exchange_end( exch);452 vfs_exchange_end(vfs_phone); 439 453 440 454 if (rc != EOK) … … 448 462 sysarg_t rc; 449 463 450 async_exch_t *exch = vfs_exchange_begin(); 451 rc = async_req_3_0(exch, VFS_IN_TRUNCATE, fildes, 464 int vfs_phone = vfs_exchange_begin(); 465 466 rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes, 452 467 LOWER32(length), UPPER32(length)); 453 vfs_exchange_end( exch);468 vfs_exchange_end(vfs_phone); 454 469 455 470 return (int) rc; … … 460 475 sysarg_t rc; 461 476 aid_t req; 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);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); 469 484 470 485 sysarg_t rc_orig; … … 476 491 return (ssize_t) rc_orig; 477 492 } 478 vfs_exchange_end( exch);493 vfs_exchange_end(vfs_phone); 479 494 async_wait_for(req, &rc); 480 495 … … 493 508 return ENOMEM; 494 509 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);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); 501 516 free(pa); 502 517 async_wait_for(req, &rc_orig); … … 506 521 return (int) rc_orig; 507 522 } 508 rc = async_data_read_start( exch, stat, sizeof(struct stat));509 if (rc != EOK) { 510 vfs_exchange_end( exch);523 rc = async_data_read_start(vfs_phone, stat, sizeof(struct stat)); 524 if (rc != EOK) { 525 vfs_exchange_end(vfs_phone); 511 526 free(pa); 512 527 async_wait_for(req, &rc_orig); … … 516 531 return (int) rc_orig; 517 532 } 518 vfs_exchange_end( exch);533 vfs_exchange_end(vfs_phone); 519 534 free(pa); 520 535 async_wait_for(req, &rc); … … 577 592 return ENOMEM; 578 593 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);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); 585 600 free(pa); 586 601 … … 593 608 return (int) rc_orig; 594 609 } 595 vfs_exchange_end( exch);610 vfs_exchange_end(vfs_phone); 596 611 free(pa); 597 612 async_wait_for(req, &rc); … … 608 623 if (!pa) 609 624 return ENOMEM; 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);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); 617 632 free(pa); 618 633 … … 625 640 return (int) rc_orig; 626 641 } 627 vfs_exchange_end( exch);642 vfs_exchange_end(vfs_phone); 628 643 free(pa); 629 644 async_wait_for(req, &rc); … … 658 673 return ENOMEM; 659 674 } 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);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); 667 682 free(olda); 668 683 free(newa); … … 673 688 return (int) rc_orig; 674 689 } 675 rc = async_data_write_start( exch, newa, newa_size);676 if (rc != EOK) { 677 vfs_exchange_end( exch);690 rc = async_data_write_start(vfs_phone, newa, newa_size); 691 if (rc != EOK) { 692 vfs_exchange_end(vfs_phone); 678 693 free(olda); 679 694 free(newa); … … 684 699 return (int) rc_orig; 685 700 } 686 vfs_exchange_end( exch);701 vfs_exchange_end(vfs_phone); 687 702 free(olda); 688 703 free(newa); … … 740 755 } 741 756 742 async_sess_t *fd_session(exch_mgmt_t mgmt,int fildes)757 int fd_phone(int fildes) 743 758 { 744 759 struct stat stat; 760 745 761 int rc = fstat(fildes, &stat); 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); 762 if (rc != 0) 763 return rc; 764 765 if (!stat.device) 766 return -1; 767 768 return devmap_device_connect(stat.device, 0); 757 769 } 758 770 … … 760 772 { 761 773 struct stat stat; 762 int rc = fstat(fildes, &stat); 774 int rc; 775 776 rc = fstat(fildes, &stat); 763 777 764 778 if (rc == EOK) { … … 773 787 int dup2(int oldfd, int newfd) 774 788 { 775 async_exch_t *exch= vfs_exchange_begin();789 int vfs_phone = vfs_exchange_begin(); 776 790 777 791 sysarg_t ret; 778 sysarg_t rc = async_req_2_1( exch, VFS_IN_DUP, oldfd, newfd, &ret);779 780 vfs_exchange_end( exch);792 sysarg_t rc = async_req_2_1(vfs_phone, VFS_IN_DUP, oldfd, newfd, &ret); 793 794 vfs_exchange_end(vfs_phone); 781 795 782 796 if (rc == EOK)
Note:
See TracChangeset
for help on using the changeset viewer.