Changes in uspace/lib/c/generic/vfs/vfs.c [8e80d3f:6b8e5b7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r8e80d3f r6b8e5b7 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> … … 50 51 #include <assert.h> 51 52 #include <str.h> 52 #include < devmap.h>53 #include <loc.h> 53 54 #include <ipc/vfs.h> 54 #include <ipc/devmap.h> 55 56 static async_sess_t vfs_session; 57 58 static FIBRIL_MUTEX_INITIALIZE(vfs_phone_mutex); 59 static int vfs_phone = -1; 55 #include <ipc/loc.h> 56 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 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 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 int mount(const char *fs_name, const char *mp, const char *fqdn, 153 const char *opts, unsigned int flags) 144 int mount(const char *fs_name, const char *mp, const char *fqsn, 145 const char *opts, unsigned int flags, unsigned int instance) 154 146 { 155 147 int null_id = -1; 156 char null[ DEVMAP_NAME_MAXLEN];157 158 if (str_cmp(fq dn, "") == 0) {148 char null[LOC_NAME_MAXLEN]; 149 150 if (str_cmp(fqsn, "") == 0) { 159 151 /* No device specified, create a fresh 160 152 null/%d device instead */ 161 null_id = devmap_null_create();153 null_id = loc_null_create(); 162 154 163 155 if (null_id == -1) 164 156 return ENOMEM; 165 157 166 snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id);167 fq dn = null;168 } 169 170 devmap_handle_t devmap_handle;171 int res = devmap_device_get_handle(fqdn, &devmap_handle, flags);158 snprintf(null, LOC_NAME_MAXLEN, "null/%d", null_id); 159 fqsn = null; 160 } 161 162 service_id_t service_id; 163 int res = loc_service_get_id(fqsn, &service_id, flags); 172 164 if (res != EOK) { 173 165 if (null_id != -1) 174 devmap_null_destroy(null_id);166 loc_null_destroy(null_id); 175 167 176 168 return res; … … 181 173 if (!mpa) { 182 174 if (null_id != -1) 183 devmap_null_destroy(null_id);175 loc_null_destroy(null_id); 184 176 185 177 return ENOMEM; 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_3(exch, VFS_IN_MOUNT, service_id, flags, 184 instance, NULL); 185 sysarg_t rc = async_data_write_start(exch, (void *) mpa, mpa_size); 186 if (rc != EOK) { 187 vfs_exchange_end(exch); 195 188 free(mpa); 196 189 async_wait_for(req, &rc_orig); 197 190 198 191 if (null_id != -1) 199 devmap_null_destroy(null_id);200 201 if (rc_orig == EOK) 202 return (int) rc; 203 else 204 return (int) rc_orig; 205 } 206 207 rc = async_data_write_start( vfs_phone, (void *) opts, str_size(opts));208 if (rc != EOK) { 209 vfs_exchange_end( vfs_phone);192 loc_null_destroy(null_id); 193 194 if (rc_orig == EOK) 195 return (int) rc; 196 else 197 return (int) rc_orig; 198 } 199 200 rc = async_data_write_start(exch, (void *) opts, str_size(opts)); 201 if (rc != EOK) { 202 vfs_exchange_end(exch); 210 203 free(mpa); 211 204 async_wait_for(req, &rc_orig); 212 205 213 206 if (null_id != -1) 214 devmap_null_destroy(null_id);215 216 if (rc_orig == EOK) 217 return (int) rc; 218 else 219 return (int) rc_orig; 220 } 221 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);207 loc_null_destroy(null_id); 208 209 if (rc_orig == EOK) 210 return (int) rc; 211 else 212 return (int) rc_orig; 213 } 214 215 rc = async_data_write_start(exch, (void *) fs_name, str_size(fs_name)); 216 if (rc != EOK) { 217 vfs_exchange_end(exch); 225 218 free(mpa); 226 219 async_wait_for(req, &rc_orig); 227 220 228 221 if (null_id != -1) 229 devmap_null_destroy(null_id);222 loc_null_destroy(null_id); 230 223 231 224 if (rc_orig == EOK) … … 236 229 237 230 /* 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);231 rc = async_req_0_0(exch, VFS_IN_PING); 232 if (rc != EOK) { 233 vfs_exchange_end(exch); 241 234 free(mpa); 242 235 async_wait_for(req, &rc_orig); 243 236 244 237 if (null_id != -1) 245 devmap_null_destroy(null_id);246 247 if (rc_orig == EOK) 248 return (int) rc; 249 else 250 return (int) rc_orig; 251 } 252 253 vfs_exchange_end( vfs_phone);238 loc_null_destroy(null_id); 239 240 if (rc_orig == EOK) 241 return (int) rc; 242 else 243 return (int) rc_orig; 244 } 245 246 vfs_exchange_end(exch); 254 247 free(mpa); 255 248 async_wait_for(req, &rc); 256 249 257 250 if ((rc != EOK) && (null_id != -1)) 258 devmap_null_destroy(null_id);251 loc_null_destroy(null_id); 259 252 260 253 return (int) rc; … … 273 266 return ENOMEM; 274 267 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);268 async_exch_t *exch = vfs_exchange_begin(); 269 270 req = async_send_0(exch, VFS_IN_UNMOUNT, NULL); 271 rc = async_data_write_start(exch, (void *) mpa, mpa_size); 272 if (rc != EOK) { 273 vfs_exchange_end(exch); 281 274 free(mpa); 282 275 async_wait_for(req, &rc_orig); … … 288 281 289 282 290 vfs_exchange_end( vfs_phone);283 vfs_exchange_end(exch); 291 284 free(mpa); 292 285 async_wait_for(req, &rc); … … 297 290 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 298 291 { 299 int vfs_phone= vfs_exchange_begin();292 async_exch_t *exch = vfs_exchange_begin(); 300 293 301 294 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);295 aid_t req = async_send_3(exch, VFS_IN_OPEN, lflag, oflag, 0, &answer); 296 sysarg_t rc = async_data_write_start(exch, abs, abs_size); 297 298 if (rc != EOK) { 299 vfs_exchange_end(exch); 307 300 308 301 sysarg_t rc_orig; … … 315 308 } 316 309 317 vfs_exchange_end( vfs_phone);310 vfs_exchange_end(exch); 318 311 async_wait_for(req, &rc); 319 312 … … 337 330 } 338 331 339 int open_node(fdi_node_t *node, int oflag)340 {341 int vfs_phone = vfs_exchange_begin();342 343 ipc_call_t answer;344 aid_t req = async_send_4(vfs_phone, VFS_IN_OPEN_NODE, node->fs_handle,345 node->devmap_handle, node->index, oflag, &answer);346 347 vfs_exchange_end(vfs_phone);348 349 sysarg_t rc;350 async_wait_for(req, &rc);351 352 if (rc != EOK)353 return (int) rc;354 355 return (int) IPC_GET_ARG1(answer);356 }357 358 332 int close(int fildes) 359 333 { 360 334 sysarg_t rc; 361 335 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; 336 async_exch_t *exch = vfs_exchange_begin(); 337 rc = async_req_1_0(exch, VFS_IN_CLOSE, fildes); 338 vfs_exchange_end(exch); 339 340 return (int) rc; 369 341 } 370 342 … … 374 346 ipc_call_t answer; 375 347 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); 348 349 async_exch_t *exch = vfs_exchange_begin(); 350 351 req = async_send_1(exch, VFS_IN_READ, fildes, &answer); 352 rc = async_data_read_start(exch, (void *)buf, nbyte); 353 if (rc != EOK) { 354 vfs_exchange_end(exch); 384 355 385 356 sysarg_t rc_orig; … … 391 362 return (ssize_t) rc_orig; 392 363 } 393 vfs_exchange_end( vfs_phone);364 vfs_exchange_end(exch); 394 365 async_wait_for(req, &rc); 395 366 if (rc == EOK) … … 404 375 ipc_call_t answer; 405 376 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); 377 378 async_exch_t *exch = vfs_exchange_begin(); 379 380 req = async_send_1(exch, VFS_IN_WRITE, fildes, &answer); 381 rc = async_data_write_start(exch, (void *)buf, nbyte); 382 if (rc != EOK) { 383 vfs_exchange_end(exch); 414 384 415 385 sysarg_t rc_orig; … … 421 391 return (ssize_t) rc_orig; 422 392 } 423 vfs_exchange_end( vfs_phone);393 vfs_exchange_end(exch); 424 394 async_wait_for(req, &rc); 425 395 if (rc == EOK) … … 429 399 } 430 400 401 /** Read entire buffer. 402 * 403 * In face of short reads this function continues reading until either 404 * the entire buffer is read or no more data is available (at end of file). 405 * 406 * @param fildes File descriptor 407 * @param buf Buffer, @a nbytes bytes long 408 * @param nbytes Number of bytes to read 409 * 410 * @return On success, positive number of bytes read. 411 * On failure, negative error code from read(). 412 */ 413 ssize_t read_all(int fildes, void *buf, size_t nbyte) 414 { 415 ssize_t cnt = 0; 416 size_t nread = 0; 417 uint8_t *bp = (uint8_t *) buf; 418 419 do { 420 bp += cnt; 421 nread += cnt; 422 cnt = read(fildes, bp, nbyte - nread); 423 } while (cnt > 0 && (nbyte - nread - cnt) > 0); 424 425 if (cnt < 0) 426 return cnt; 427 428 return nread + cnt; 429 } 430 431 /** Write entire buffer. 432 * 433 * This function fails if it cannot write exactly @a len bytes to the file. 434 * 435 * @param fildes File descriptor 436 * @param buf Data, @a nbytes bytes long 437 * @param nbytes Number of bytes to write 438 * 439 * @return EOK on error, return value from write() if writing 440 * failed. 441 */ 442 ssize_t write_all(int fildes, const void *buf, size_t nbyte) 443 { 444 ssize_t cnt = 0; 445 ssize_t nwritten = 0; 446 const uint8_t *bp = (uint8_t *) buf; 447 448 do { 449 bp += cnt; 450 nwritten += cnt; 451 cnt = write(fildes, bp, nbyte - nwritten); 452 } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0); 453 454 if (cnt < 0) 455 return cnt; 456 457 if ((ssize_t)nbyte - nwritten - cnt > 0) 458 return EIO; 459 460 return nbyte; 461 } 462 431 463 int fsync(int fildes) 432 464 { 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); 465 async_exch_t *exch = vfs_exchange_begin(); 466 sysarg_t rc = async_req_1_0(exch, VFS_IN_SYNC, fildes); 467 vfs_exchange_end(exch); 438 468 439 469 return (int) rc; … … 442 472 off64_t lseek(int fildes, off64_t offset, int whence) 443 473 { 444 int vfs_phone= vfs_exchange_begin();474 async_exch_t *exch = vfs_exchange_begin(); 445 475 446 476 sysarg_t newoff_lo; 447 477 sysarg_t newoff_hi; 448 sysarg_t rc = async_req_4_2( vfs_phone, VFS_IN_SEEK, fildes,478 sysarg_t rc = async_req_4_2(exch, VFS_IN_SEEK, fildes, 449 479 LOWER32(offset), UPPER32(offset), whence, 450 480 &newoff_lo, &newoff_hi); 451 481 452 vfs_exchange_end( vfs_phone);482 vfs_exchange_end(exch); 453 483 454 484 if (rc != EOK) … … 462 492 sysarg_t rc; 463 493 464 int vfs_phone = vfs_exchange_begin(); 465 466 rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes, 494 async_exch_t *exch = vfs_exchange_begin(); 495 rc = async_req_3_0(exch, VFS_IN_TRUNCATE, fildes, 467 496 LOWER32(length), UPPER32(length)); 468 vfs_exchange_end( vfs_phone);497 vfs_exchange_end(exch); 469 498 470 499 return (int) rc; … … 475 504 sysarg_t rc; 476 505 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);506 507 async_exch_t *exch = vfs_exchange_begin(); 508 509 req = async_send_1(exch, VFS_IN_FSTAT, fildes, NULL); 510 rc = async_data_read_start(exch, (void *) stat, sizeof(struct stat)); 511 if (rc != EOK) { 512 vfs_exchange_end(exch); 484 513 485 514 sysarg_t rc_orig; … … 491 520 return (ssize_t) rc_orig; 492 521 } 493 vfs_exchange_end( vfs_phone);522 vfs_exchange_end(exch); 494 523 async_wait_for(req, &rc); 495 524 … … 508 537 return ENOMEM; 509 538 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);539 async_exch_t *exch = vfs_exchange_begin(); 540 541 req = async_send_0(exch, VFS_IN_STAT, NULL); 542 rc = async_data_write_start(exch, pa, pa_size); 543 if (rc != EOK) { 544 vfs_exchange_end(exch); 516 545 free(pa); 517 546 async_wait_for(req, &rc_orig); … … 521 550 return (int) rc_orig; 522 551 } 523 rc = async_data_read_start( vfs_phone, stat, sizeof(struct stat));524 if (rc != EOK) { 525 vfs_exchange_end( vfs_phone);552 rc = async_data_read_start(exch, stat, sizeof(struct stat)); 553 if (rc != EOK) { 554 vfs_exchange_end(exch); 526 555 free(pa); 527 556 async_wait_for(req, &rc_orig); … … 531 560 return (int) rc_orig; 532 561 } 533 vfs_exchange_end( vfs_phone);562 vfs_exchange_end(exch); 534 563 free(pa); 535 564 async_wait_for(req, &rc); … … 592 621 return ENOMEM; 593 622 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);623 async_exch_t *exch = vfs_exchange_begin(); 624 625 req = async_send_1(exch, VFS_IN_MKDIR, mode, NULL); 626 rc = async_data_write_start(exch, pa, pa_size); 627 if (rc != EOK) { 628 vfs_exchange_end(exch); 600 629 free(pa); 601 630 … … 608 637 return (int) rc_orig; 609 638 } 610 vfs_exchange_end( vfs_phone);639 vfs_exchange_end(exch); 611 640 free(pa); 612 641 async_wait_for(req, &rc); … … 623 652 if (!pa) 624 653 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);654 655 async_exch_t *exch = vfs_exchange_begin(); 656 657 req = async_send_1(exch, VFS_IN_UNLINK, lflag, NULL); 658 rc = async_data_write_start(exch, pa, pa_size); 659 if (rc != EOK) { 660 vfs_exchange_end(exch); 632 661 free(pa); 633 662 … … 640 669 return (int) rc_orig; 641 670 } 642 vfs_exchange_end( vfs_phone);671 vfs_exchange_end(exch); 643 672 free(pa); 644 673 async_wait_for(req, &rc); … … 673 702 return ENOMEM; 674 703 } 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);704 705 async_exch_t *exch = vfs_exchange_begin(); 706 707 req = async_send_0(exch, VFS_IN_RENAME, NULL); 708 rc = async_data_write_start(exch, olda, olda_size); 709 if (rc != EOK) { 710 vfs_exchange_end(exch); 682 711 free(olda); 683 712 free(newa); … … 688 717 return (int) rc_orig; 689 718 } 690 rc = async_data_write_start( vfs_phone, newa, newa_size);691 if (rc != EOK) { 692 vfs_exchange_end( vfs_phone);719 rc = async_data_write_start(exch, newa, newa_size); 720 if (rc != EOK) { 721 vfs_exchange_end(exch); 693 722 free(olda); 694 723 free(newa); … … 699 728 return (int) rc_orig; 700 729 } 701 vfs_exchange_end( vfs_phone);730 vfs_exchange_end(exch); 702 731 free(olda); 703 732 free(newa); … … 755 784 } 756 785 757 int fd_phone(int fildes)786 async_sess_t *fd_session(exch_mgmt_t mgmt, int fildes) 758 787 { 759 788 struct stat stat; 760 761 789 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); 769 } 770 771 int fd_node(int fildes, fdi_node_t *node) 772 { 773 struct stat stat; 774 int rc; 775 776 rc = fstat(fildes, &stat); 777 778 if (rc == EOK) { 779 node->fs_handle = stat.fs_handle; 780 node->devmap_handle = stat.devmap_handle; 781 node->index = stat.index; 782 } 783 784 return rc; 790 if (rc != 0) { 791 errno = rc; 792 return NULL; 793 } 794 795 if (!stat.service) { 796 errno = ENOENT; 797 return NULL; 798 } 799 800 return loc_service_connect(mgmt, stat.service, 0); 785 801 } 786 802 787 803 int dup2(int oldfd, int newfd) 788 804 { 789 int vfs_phone= vfs_exchange_begin();805 async_exch_t *exch = vfs_exchange_begin(); 790 806 791 807 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);808 sysarg_t rc = async_req_2_1(exch, VFS_IN_DUP, oldfd, newfd, &ret); 809 810 vfs_exchange_end(exch); 795 811 796 812 if (rc == EOK) … … 800 816 } 801 817 818 int fd_wait(void) 819 { 820 async_exch_t *exch = vfs_exchange_begin(); 821 822 sysarg_t ret; 823 sysarg_t rc = async_req_0_1(exch, VFS_IN_WAIT_HANDLE, &ret); 824 825 vfs_exchange_end(exch); 826 827 if (rc == EOK) 828 return (int) ret; 829 830 return (int) rc; 831 } 832 833 int get_mtab_list(list_t *mtab_list) 834 { 835 sysarg_t rc; 836 aid_t req; 837 size_t i; 838 sysarg_t num_mounted_fs; 839 840 async_exch_t *exch = vfs_exchange_begin(); 841 842 req = async_send_0(exch, VFS_IN_MTAB_GET, NULL); 843 844 /* Ask VFS how many filesystems are mounted */ 845 rc = async_req_0_1(exch, VFS_IN_PING, &num_mounted_fs); 846 if (rc != EOK) 847 goto exit; 848 849 for (i = 0; i < num_mounted_fs; ++i) { 850 mtab_ent_t *mtab_ent; 851 852 mtab_ent = malloc(sizeof(mtab_ent_t)); 853 if (!mtab_ent) { 854 rc = ENOMEM; 855 goto exit; 856 } 857 858 memset(mtab_ent, 0, sizeof(mtab_ent_t)); 859 860 rc = async_data_read_start(exch, (void *) mtab_ent->mp, 861 MAX_PATH_LEN); 862 if (rc != EOK) 863 goto exit; 864 865 rc = async_data_read_start(exch, (void *) mtab_ent->opts, 866 MAX_MNTOPTS_LEN); 867 if (rc != EOK) 868 goto exit; 869 870 rc = async_data_read_start(exch, (void *) mtab_ent->fs_name, 871 FS_NAME_MAXLEN); 872 if (rc != EOK) 873 goto exit; 874 875 sysarg_t p[2]; 876 877 rc = async_req_0_2(exch, VFS_IN_PING, &p[0], &p[1]); 878 if (rc != EOK) 879 goto exit; 880 881 mtab_ent->instance = p[0]; 882 mtab_ent->service_id = p[1]; 883 884 link_initialize(&mtab_ent->link); 885 list_append(&mtab_ent->link, mtab_list); 886 } 887 888 exit: 889 async_wait_for(req, &rc); 890 vfs_exchange_end(exch); 891 return rc; 892 } 893 802 894 /** @} 803 895 */
Note:
See TracChangeset
for help on using the changeset viewer.