Changes in uspace/lib/c/generic/vfs/vfs.c [6b8e5b7:8e80d3f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r6b8e5b7 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> … … 51 50 #include <assert.h> 52 51 #include <str.h> 53 #include < loc.h>52 #include <devmap.h> 54 53 #include <ipc/vfs.h> 55 #include <ipc/loc.h> 56 57 static FIBRIL_MUTEX_INITIALIZE(vfs_mutex); 58 static async_sess_t *vfs_sess = NULL; 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; 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 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 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 144 int mount(const char *fs_name, const char *mp, const char *fqsn, 145 const char *opts, unsigned int flags, unsigned int instance) 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) 146 154 { 147 155 int null_id = -1; 148 char null[ LOC_NAME_MAXLEN];149 150 if (str_cmp(fq sn, "") == 0) {156 char null[DEVMAP_NAME_MAXLEN]; 157 158 if (str_cmp(fqdn, "") == 0) { 151 159 /* No device specified, create a fresh 152 160 null/%d device instead */ 153 null_id = loc_null_create();161 null_id = devmap_null_create(); 154 162 155 163 if (null_id == -1) 156 164 return ENOMEM; 157 165 158 snprintf(null, LOC_NAME_MAXLEN, "null/%d", null_id);159 fq sn = null;160 } 161 162 service_id_t service_id;163 int res = loc_service_get_id(fqsn, &service_id, flags);166 snprintf(null, DEVMAP_NAME_MAXLEN, "null/%d", null_id); 167 fqdn = null; 168 } 169 170 devmap_handle_t devmap_handle; 171 int res = devmap_device_get_handle(fqdn, &devmap_handle, flags); 164 172 if (res != EOK) { 165 173 if (null_id != -1) 166 loc_null_destroy(null_id);174 devmap_null_destroy(null_id); 167 175 168 176 return res; … … 173 181 if (!mpa) { 174 182 if (null_id != -1) 175 loc_null_destroy(null_id);183 devmap_null_destroy(null_id); 176 184 177 185 return ENOMEM; 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_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); 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); 188 195 free(mpa); 189 196 async_wait_for(req, &rc_orig); 190 197 191 198 if (null_id != -1) 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);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); 203 210 free(mpa); 204 211 async_wait_for(req, &rc_orig); 205 212 206 213 if (null_id != -1) 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);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); 218 225 free(mpa); 219 226 async_wait_for(req, &rc_orig); 220 227 221 228 if (null_id != -1) 222 loc_null_destroy(null_id);229 devmap_null_destroy(null_id); 223 230 224 231 if (rc_orig == EOK) … … 229 236 230 237 /* Ask VFS whether it likes fs_name. */ 231 rc = async_req_0_0( exch, VFS_IN_PING);232 if (rc != EOK) { 233 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); 234 241 free(mpa); 235 242 async_wait_for(req, &rc_orig); 236 243 237 244 if (null_id != -1) 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);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); 247 254 free(mpa); 248 255 async_wait_for(req, &rc); 249 256 250 257 if ((rc != EOK) && (null_id != -1)) 251 loc_null_destroy(null_id);258 devmap_null_destroy(null_id); 252 259 253 260 return (int) rc; … … 266 273 return ENOMEM; 267 274 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);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); 274 281 free(mpa); 275 282 async_wait_for(req, &rc_orig); … … 281 288 282 289 283 vfs_exchange_end( exch);290 vfs_exchange_end(vfs_phone); 284 291 free(mpa); 285 292 async_wait_for(req, &rc); … … 290 297 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 291 298 { 292 async_exch_t *exch= vfs_exchange_begin();299 int vfs_phone = vfs_exchange_begin(); 293 300 294 301 ipc_call_t answer; 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);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); 300 307 301 308 sysarg_t rc_orig; … … 308 315 } 309 316 310 vfs_exchange_end( exch);317 vfs_exchange_end(vfs_phone); 311 318 async_wait_for(req, &rc); 312 319 … … 330 337 } 331 338 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 332 358 int close(int fildes) 333 359 { 334 360 sysarg_t rc; 335 361 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; 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; 341 369 } 342 370 … … 346 374 ipc_call_t answer; 347 375 aid_t req; 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); 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); 355 384 356 385 sysarg_t rc_orig; … … 362 391 return (ssize_t) rc_orig; 363 392 } 364 vfs_exchange_end( exch);393 vfs_exchange_end(vfs_phone); 365 394 async_wait_for(req, &rc); 366 395 if (rc == EOK) … … 375 404 ipc_call_t answer; 376 405 aid_t req; 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); 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); 384 414 385 415 sysarg_t rc_orig; … … 391 421 return (ssize_t) rc_orig; 392 422 } 393 vfs_exchange_end( exch);423 vfs_exchange_end(vfs_phone); 394 424 async_wait_for(req, &rc); 395 425 if (rc == EOK) … … 399 429 } 400 430 401 /** Read entire buffer.402 *403 * In face of short reads this function continues reading until either404 * the entire buffer is read or no more data is available (at end of file).405 *406 * @param fildes File descriptor407 * @param buf Buffer, @a nbytes bytes long408 * @param nbytes Number of bytes to read409 *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 descriptor436 * @param buf Data, @a nbytes bytes long437 * @param nbytes Number of bytes to write438 *439 * @return EOK on error, return value from write() if writing440 * 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 463 431 int fsync(int fildes) 464 432 { 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); 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); 468 438 469 439 return (int) rc; … … 472 442 off64_t lseek(int fildes, off64_t offset, int whence) 473 443 { 474 async_exch_t *exch= vfs_exchange_begin();444 int vfs_phone = vfs_exchange_begin(); 475 445 476 446 sysarg_t newoff_lo; 477 447 sysarg_t newoff_hi; 478 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, 479 449 LOWER32(offset), UPPER32(offset), whence, 480 450 &newoff_lo, &newoff_hi); 481 451 482 vfs_exchange_end( exch);452 vfs_exchange_end(vfs_phone); 483 453 484 454 if (rc != EOK) … … 492 462 sysarg_t rc; 493 463 494 async_exch_t *exch = vfs_exchange_begin(); 495 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, 496 467 LOWER32(length), UPPER32(length)); 497 vfs_exchange_end( exch);468 vfs_exchange_end(vfs_phone); 498 469 499 470 return (int) rc; … … 504 475 sysarg_t rc; 505 476 aid_t req; 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);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); 513 484 514 485 sysarg_t rc_orig; … … 520 491 return (ssize_t) rc_orig; 521 492 } 522 vfs_exchange_end( exch);493 vfs_exchange_end(vfs_phone); 523 494 async_wait_for(req, &rc); 524 495 … … 537 508 return ENOMEM; 538 509 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);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); 545 516 free(pa); 546 517 async_wait_for(req, &rc_orig); … … 550 521 return (int) rc_orig; 551 522 } 552 rc = async_data_read_start( exch, stat, sizeof(struct stat));553 if (rc != EOK) { 554 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); 555 526 free(pa); 556 527 async_wait_for(req, &rc_orig); … … 560 531 return (int) rc_orig; 561 532 } 562 vfs_exchange_end( exch);533 vfs_exchange_end(vfs_phone); 563 534 free(pa); 564 535 async_wait_for(req, &rc); … … 621 592 return ENOMEM; 622 593 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);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); 629 600 free(pa); 630 601 … … 637 608 return (int) rc_orig; 638 609 } 639 vfs_exchange_end( exch);610 vfs_exchange_end(vfs_phone); 640 611 free(pa); 641 612 async_wait_for(req, &rc); … … 652 623 if (!pa) 653 624 return ENOMEM; 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);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); 661 632 free(pa); 662 633 … … 669 640 return (int) rc_orig; 670 641 } 671 vfs_exchange_end( exch);642 vfs_exchange_end(vfs_phone); 672 643 free(pa); 673 644 async_wait_for(req, &rc); … … 702 673 return ENOMEM; 703 674 } 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);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); 711 682 free(olda); 712 683 free(newa); … … 717 688 return (int) rc_orig; 718 689 } 719 rc = async_data_write_start( exch, newa, newa_size);720 if (rc != EOK) { 721 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); 722 693 free(olda); 723 694 free(newa); … … 728 699 return (int) rc_orig; 729 700 } 730 vfs_exchange_end( exch);701 vfs_exchange_end(vfs_phone); 731 702 free(olda); 732 703 free(newa); … … 784 755 } 785 756 786 async_sess_t *fd_session(exch_mgmt_t mgmt,int fildes)757 int fd_phone(int fildes) 787 758 { 788 759 struct stat stat; 760 789 761 int rc = fstat(fildes, &stat); 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); 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; 801 785 } 802 786 803 787 int dup2(int oldfd, int newfd) 804 788 { 805 async_exch_t *exch= vfs_exchange_begin();789 int vfs_phone = vfs_exchange_begin(); 806 790 807 791 sysarg_t ret; 808 sysarg_t rc = async_req_2_1( exch, VFS_IN_DUP, oldfd, newfd, &ret);809 810 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); 811 795 812 796 if (rc == EOK) … … 816 800 } 817 801 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 894 802 /** @} 895 803 */
Note:
See TracChangeset
for help on using the changeset viewer.