Changeset b5e68c8 in mainline for uspace/lib/c/generic/vfs/vfs.c
- Timestamp:
- 2011-05-12T16:49:44Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f36787d7
- Parents:
- e80329d6 (diff), 750636a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
re80329d6 rb5e68c8 1 1 /* 2 * Copyright (c) 2008 Jakub Jermar 2 * Copyright (c) 2008 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 43 43 #include <sys/stat.h> 44 44 #include <sys/types.h> 45 #include <ipc/ipc.h>46 45 #include <ipc/services.h> 46 #include <ipc/ns.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; … … 66 69 char *ncwd_path; 67 70 char *ncwd_path_nc; 68 69 futex_down(&cwd_futex); 71 size_t total_size; 72 73 fibril_mutex_lock(&cwd_mutex); 70 74 size_t size = str_size(path); 71 75 if (*path != '/') { 72 76 if (!cwd_path) { 73 f utex_up(&cwd_futex);77 fibril_mutex_unlock(&cwd_mutex); 74 78 return NULL; 75 79 } 76 ncwd_path_nc = malloc(cwd_size + 1 + size + 1); 80 total_size = cwd_size + 1 + size + 1; 81 ncwd_path_nc = malloc(total_size); 77 82 if (!ncwd_path_nc) { 78 f utex_up(&cwd_futex);83 fibril_mutex_unlock(&cwd_mutex); 79 84 return NULL; 80 85 } 81 str_cpy(ncwd_path_nc, cwd_size + 1 + size + 1, cwd_path);86 str_cpy(ncwd_path_nc, total_size, cwd_path); 82 87 ncwd_path_nc[cwd_size] = '/'; 83 88 ncwd_path_nc[cwd_size + 1] = '\0'; 84 89 } else { 85 ncwd_path_nc = malloc(size + 1); 90 total_size = size + 1; 91 ncwd_path_nc = malloc(total_size); 86 92 if (!ncwd_path_nc) { 87 f utex_up(&cwd_futex);93 fibril_mutex_unlock(&cwd_mutex); 88 94 return NULL; 89 95 } 90 96 ncwd_path_nc[0] = '\0'; 91 97 } 92 str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path);98 str_append(ncwd_path_nc, total_size, path); 93 99 ncwd_path = canonify(ncwd_path_nc, retlen); 94 100 if (!ncwd_path) { 95 f utex_up(&cwd_futex);101 fibril_mutex_unlock(&cwd_mutex); 96 102 free(ncwd_path_nc); 97 103 return NULL; … … 105 111 free(ncwd_path_nc); 106 112 if (!ncwd_path) { 107 f utex_up(&cwd_futex);113 fibril_mutex_unlock(&cwd_mutex); 108 114 return NULL; 109 115 } 110 f utex_up(&cwd_futex);116 fibril_mutex_unlock(&cwd_mutex); 111 117 return ncwd_path; 112 118 } 113 119 120 /** Connect to VFS service and create session. */ 114 121 static void vfs_connect(void) 115 122 { 116 123 while (vfs_phone < 0) 117 vfs_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VFS, 0, 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); 118 150 } 119 151 … … 136 168 } 137 169 138 dev _handle_t dev_handle;139 int res = devmap_device_get_handle(fqdn, &dev _handle, flags);170 devmap_handle_t devmap_handle; 171 int res = devmap_device_get_handle(fqdn, &devmap_handle, flags); 140 172 if (res != EOK) { 141 173 if (null_id != -1) … … 154 186 } 155 187 156 futex_down(&vfs_phone_futex); 157 async_serialize_start(); 158 vfs_connect(); 159 160 ipcarg_t rc_orig; 161 aid_t req = async_send_2(vfs_phone, VFS_IN_MOUNT, dev_handle, flags, NULL); 162 ipcarg_t rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size); 163 if (rc != EOK) { 164 async_wait_for(req, &rc_orig); 165 async_serialize_end(); 166 futex_up(&vfs_phone_futex); 188 int vfs_phone = vfs_exchange_begin(); 189 190 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); 167 195 free(mpa); 196 async_wait_for(req, &rc_orig); 168 197 169 198 if (null_id != -1) … … 178 207 rc = async_data_write_start(vfs_phone, (void *) opts, str_size(opts)); 179 208 if (rc != EOK) { 180 async_wait_for(req, &rc_orig); 181 async_serialize_end(); 182 futex_up(&vfs_phone_futex); 209 vfs_exchange_end(vfs_phone); 183 210 free(mpa); 211 async_wait_for(req, &rc_orig); 184 212 185 213 if (null_id != -1) … … 194 222 rc = async_data_write_start(vfs_phone, (void *) fs_name, str_size(fs_name)); 195 223 if (rc != EOK) { 196 async_wait_for(req, &rc_orig); 197 async_serialize_end(); 198 futex_up(&vfs_phone_futex); 224 vfs_exchange_end(vfs_phone); 199 225 free(mpa); 226 async_wait_for(req, &rc_orig); 200 227 201 228 if (null_id != -1) … … 211 238 rc = async_req_0_0(vfs_phone, IPC_M_PING); 212 239 if (rc != EOK) { 213 async_wait_for(req, &rc_orig); 214 async_serialize_end(); 215 futex_up(&vfs_phone_futex); 240 vfs_exchange_end(vfs_phone); 216 241 free(mpa); 242 async_wait_for(req, &rc_orig); 217 243 218 244 if (null_id != -1) … … 225 251 } 226 252 227 async_wait_for(req, &rc); 228 async_serialize_end(); 229 futex_up(&vfs_phone_futex); 253 vfs_exchange_end(vfs_phone); 230 254 free(mpa); 255 async_wait_for(req, &rc); 231 256 232 257 if ((rc != EOK) && (null_id != -1)) … … 238 263 int unmount(const char *mp) 239 264 { 240 ipcarg_t rc;241 ipcarg_t rc_orig;265 sysarg_t rc; 266 sysarg_t rc_orig; 242 267 aid_t req; 243 268 size_t mpa_size; … … 248 273 return ENOMEM; 249 274 250 futex_down(&vfs_phone_futex); 251 async_serialize_start(); 252 vfs_connect(); 275 int vfs_phone = vfs_exchange_begin(); 253 276 254 277 req = async_send_0(vfs_phone, VFS_IN_UNMOUNT, NULL); 255 278 rc = async_data_write_start(vfs_phone, (void *) mpa, mpa_size); 256 279 if (rc != EOK) { 257 async_wait_for(req, &rc_orig); 258 async_serialize_end(); 259 futex_up(&vfs_phone_futex); 280 vfs_exchange_end(vfs_phone); 260 281 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); 282 async_wait_for(req, &rc_orig); 283 if (rc_orig == EOK) 284 return (int) rc; 285 else 286 return (int) rc_orig; 287 } 288 289 290 vfs_exchange_end(vfs_phone); 271 291 free(mpa); 292 async_wait_for(req, &rc); 272 293 273 294 return (int) rc; … … 276 297 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 277 298 { 278 futex_down(&vfs_phone_futex); 279 async_serialize_start(); 280 vfs_connect(); 299 int vfs_phone = vfs_exchange_begin(); 281 300 282 301 ipc_call_t answer; 283 302 aid_t req = async_send_3(vfs_phone, VFS_IN_OPEN, lflag, oflag, 0, &answer); 284 ipcarg_t rc = async_data_write_start(vfs_phone, abs, abs_size); 285 286 if (rc != EOK) { 287 ipcarg_t rc_orig; 288 async_wait_for(req, &rc_orig); 289 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); 303 sysarg_t rc = async_data_write_start(vfs_phone, abs, abs_size); 304 305 if (rc != EOK) { 306 vfs_exchange_end(vfs_phone); 307 308 sysarg_t rc_orig; 309 async_wait_for(req, &rc_orig); 310 311 if (rc_orig == EOK) 312 return (int) rc; 313 else 314 return (int) rc_orig; 315 } 316 317 vfs_exchange_end(vfs_phone); 318 async_wait_for(req, &rc); 302 319 303 320 if (rc != EOK) … … 322 339 int open_node(fdi_node_t *node, int oflag) 323 340 { 324 futex_down(&vfs_phone_futex); 325 async_serialize_start(); 326 vfs_connect(); 341 int vfs_phone = vfs_exchange_begin(); 327 342 328 343 ipc_call_t answer; 329 344 aid_t req = async_send_4(vfs_phone, VFS_IN_OPEN_NODE, node->fs_handle, 330 node->dev _handle, node->index, oflag, &answer);331 332 ipcarg_t rc;333 async_wait_for(req, &rc); 334 async_serialize_end();335 futex_up(&vfs_phone_futex);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); 336 351 337 352 if (rc != EOK) … … 343 358 int close(int fildes) 344 359 { 345 ipcarg_t rc; 346 347 futex_down(&vfs_phone_futex); 348 async_serialize_start(); 349 vfs_connect(); 360 sysarg_t rc; 361 362 int vfs_phone = vfs_exchange_begin(); 350 363 351 364 rc = async_req_1_0(vfs_phone, VFS_IN_CLOSE, fildes); 352 365 353 async_serialize_end(); 354 futex_up(&vfs_phone_futex); 366 vfs_exchange_end(vfs_phone); 355 367 356 368 return (int)rc; … … 359 371 ssize_t read(int fildes, void *buf, size_t nbyte) 360 372 { 361 ipcarg_t rc;373 sysarg_t rc; 362 374 ipc_call_t answer; 363 375 aid_t req; 364 376 365 futex_down(&vfs_phone_futex); 366 async_serialize_start(); 367 vfs_connect(); 377 int vfs_phone = vfs_exchange_begin(); 368 378 369 379 req = async_send_1(vfs_phone, VFS_IN_READ, fildes, &answer); 370 rc = async_data_read_start(vfs_phone, (void *)buf, nbyte); 371 if (rc != EOK) { 372 ipcarg_t rc_orig; 373 374 async_wait_for(req, &rc_orig); 375 async_serialize_end(); 376 futex_up(&vfs_phone_futex); 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); 384 385 sysarg_t rc_orig; 386 async_wait_for(req, &rc_orig); 387 377 388 if (rc_orig == EOK) 378 389 return (ssize_t) rc; … … 380 391 return (ssize_t) rc_orig; 381 392 } 382 async_wait_for(req, &rc); 383 async_serialize_end(); 384 futex_up(&vfs_phone_futex); 393 vfs_exchange_end(vfs_phone); 394 async_wait_for(req, &rc); 385 395 if (rc == EOK) 386 396 return (ssize_t) IPC_GET_ARG1(answer); … … 391 401 ssize_t write(int fildes, const void *buf, size_t nbyte) 392 402 { 393 ipcarg_t rc;403 sysarg_t rc; 394 404 ipc_call_t answer; 395 405 aid_t req; 396 406 397 futex_down(&vfs_phone_futex); 398 async_serialize_start(); 399 vfs_connect(); 407 int vfs_phone = vfs_exchange_begin(); 400 408 401 409 req = async_send_1(vfs_phone, VFS_IN_WRITE, fildes, &answer); 402 rc = async_data_write_start(vfs_phone, (void *)buf, nbyte); 403 if (rc != EOK) { 404 ipcarg_t rc_orig; 405 406 async_wait_for(req, &rc_orig); 407 async_serialize_end(); 408 futex_up(&vfs_phone_futex); 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); 414 415 sysarg_t rc_orig; 416 async_wait_for(req, &rc_orig); 417 409 418 if (rc_orig == EOK) 410 419 return (ssize_t) rc; … … 412 421 return (ssize_t) rc_orig; 413 422 } 414 async_wait_for(req, &rc); 415 async_serialize_end(); 416 futex_up(&vfs_phone_futex); 423 vfs_exchange_end(vfs_phone); 424 async_wait_for(req, &rc); 417 425 if (rc == EOK) 418 426 return (ssize_t) IPC_GET_ARG1(answer); … … 423 431 int fsync(int fildes) 424 432 { 425 futex_down(&vfs_phone_futex); 426 async_serialize_start(); 427 vfs_connect(); 428 429 ipcarg_t rc = async_req_1_0(vfs_phone, VFS_IN_SYNC, fildes); 430 431 async_serialize_end(); 432 futex_up(&vfs_phone_futex); 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); 433 438 434 439 return (int) rc; … … 437 442 off64_t lseek(int fildes, off64_t offset, int whence) 438 443 { 439 futex_down(&vfs_phone_futex); 440 async_serialize_start(); 441 vfs_connect(); 442 443 ipcarg_t newoff_lo; 444 ipcarg_t newoff_hi; 445 ipcarg_t rc = async_req_4_2(vfs_phone, VFS_IN_SEEK, fildes, 444 int vfs_phone = vfs_exchange_begin(); 445 446 sysarg_t newoff_lo; 447 sysarg_t newoff_hi; 448 sysarg_t rc = async_req_4_2(vfs_phone, VFS_IN_SEEK, fildes, 446 449 LOWER32(offset), UPPER32(offset), whence, 447 450 &newoff_lo, &newoff_hi); 448 451 449 async_serialize_end(); 450 futex_up(&vfs_phone_futex); 452 vfs_exchange_end(vfs_phone); 451 453 452 454 if (rc != EOK) … … 458 460 int ftruncate(int fildes, aoff64_t length) 459 461 { 460 ipcarg_t rc; 461 462 futex_down(&vfs_phone_futex); 463 async_serialize_start(); 464 vfs_connect(); 462 sysarg_t rc; 463 464 int vfs_phone = vfs_exchange_begin(); 465 465 466 466 rc = async_req_3_0(vfs_phone, VFS_IN_TRUNCATE, fildes, 467 467 LOWER32(length), UPPER32(length)); 468 async_serialize_end(); 469 futex_up(&vfs_phone_futex); 468 vfs_exchange_end(vfs_phone); 470 469 471 470 return (int) rc; … … 474 473 int fstat(int fildes, struct stat *stat) 475 474 { 476 ipcarg_t rc;475 sysarg_t rc; 477 476 aid_t req; 478 477 479 futex_down(&vfs_phone_futex); 480 async_serialize_start(); 481 vfs_connect(); 478 int vfs_phone = vfs_exchange_begin(); 482 479 483 480 req = async_send_1(vfs_phone, VFS_IN_FSTAT, fildes, NULL); 484 481 rc = async_data_read_start(vfs_phone, (void *) stat, sizeof(struct stat)); 485 482 if (rc != EOK) { 486 ipcarg_t rc_orig;487 488 async_wait_for(req, &rc_orig);489 async_ serialize_end();490 futex_up(&vfs_phone_futex); 483 vfs_exchange_end(vfs_phone); 484 485 sysarg_t rc_orig; 486 async_wait_for(req, &rc_orig); 487 491 488 if (rc_orig == EOK) 492 489 return (ssize_t) rc; … … 494 491 return (ssize_t) rc_orig; 495 492 } 496 async_wait_for(req, &rc); 497 async_serialize_end(); 498 futex_up(&vfs_phone_futex); 493 vfs_exchange_end(vfs_phone); 494 async_wait_for(req, &rc); 499 495 500 496 return rc; … … 503 499 int stat(const char *path, struct stat *stat) 504 500 { 505 ipcarg_t rc;506 ipcarg_t rc_orig;501 sysarg_t rc; 502 sysarg_t rc_orig; 507 503 aid_t req; 508 504 … … 512 508 return ENOMEM; 513 509 514 futex_down(&vfs_phone_futex); 515 async_serialize_start(); 516 vfs_connect(); 510 int vfs_phone = vfs_exchange_begin(); 517 511 518 512 req = async_send_0(vfs_phone, VFS_IN_STAT, NULL); 519 513 rc = async_data_write_start(vfs_phone, pa, pa_size); 520 514 if (rc != EOK) { 521 async_wait_for(req, &rc_orig); 522 async_serialize_end(); 523 futex_up(&vfs_phone_futex); 515 vfs_exchange_end(vfs_phone); 524 516 free(pa); 517 async_wait_for(req, &rc_orig); 525 518 if (rc_orig == EOK) 526 519 return (int) rc; … … 530 523 rc = async_data_read_start(vfs_phone, stat, sizeof(struct stat)); 531 524 if (rc != EOK) { 532 async_wait_for(req, &rc_orig); 533 async_serialize_end(); 534 futex_up(&vfs_phone_futex); 525 vfs_exchange_end(vfs_phone); 535 526 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); 527 async_wait_for(req, &rc_orig); 528 if (rc_orig == EOK) 529 return (int) rc; 530 else 531 return (int) rc_orig; 532 } 533 vfs_exchange_end(vfs_phone); 544 534 free(pa); 535 async_wait_for(req, &rc); 545 536 return rc; 546 537 } … … 593 584 int mkdir(const char *path, mode_t mode) 594 585 { 595 ipcarg_t rc;586 sysarg_t rc; 596 587 aid_t req; 597 588 … … 601 592 return ENOMEM; 602 593 603 futex_down(&vfs_phone_futex); 604 async_serialize_start(); 605 vfs_connect(); 594 int vfs_phone = vfs_exchange_begin(); 606 595 607 596 req = async_send_1(vfs_phone, VFS_IN_MKDIR, mode, NULL); 608 597 rc = async_data_write_start(vfs_phone, pa, pa_size); 609 598 if (rc != EOK) { 610 ipcarg_t rc_orig; 611 612 async_wait_for(req, &rc_orig); 613 async_serialize_end(); 614 futex_up(&vfs_phone_futex); 599 vfs_exchange_end(vfs_phone); 615 600 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); 601 602 sysarg_t rc_orig; 603 async_wait_for(req, &rc_orig); 604 605 if (rc_orig == EOK) 606 return (int) rc; 607 else 608 return (int) rc_orig; 609 } 610 vfs_exchange_end(vfs_phone); 624 611 free(pa); 612 async_wait_for(req, &rc); 625 613 return rc; 626 614 } … … 628 616 static int _unlink(const char *path, int lflag) 629 617 { 630 ipcarg_t rc;618 sysarg_t rc; 631 619 aid_t req; 632 620 … … 636 624 return ENOMEM; 637 625 638 futex_down(&vfs_phone_futex); 639 async_serialize_start(); 640 vfs_connect(); 626 int vfs_phone = vfs_exchange_begin(); 641 627 642 628 req = async_send_0(vfs_phone, VFS_IN_UNLINK, NULL); 643 629 rc = async_data_write_start(vfs_phone, pa, pa_size); 644 630 if (rc != EOK) { 645 ipcarg_t rc_orig; 646 647 async_wait_for(req, &rc_orig); 648 async_serialize_end(); 649 futex_up(&vfs_phone_futex); 631 vfs_exchange_end(vfs_phone); 650 632 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); 633 634 sysarg_t rc_orig; 635 async_wait_for(req, &rc_orig); 636 637 if (rc_orig == EOK) 638 return (int) rc; 639 else 640 return (int) rc_orig; 641 } 642 vfs_exchange_end(vfs_phone); 659 643 free(pa); 644 async_wait_for(req, &rc); 660 645 return rc; 661 646 } … … 673 658 int rename(const char *old, const char *new) 674 659 { 675 ipcarg_t rc;676 ipcarg_t rc_orig;660 sysarg_t rc; 661 sysarg_t rc_orig; 677 662 aid_t req; 678 663 … … 689 674 } 690 675 691 futex_down(&vfs_phone_futex); 692 async_serialize_start(); 693 vfs_connect(); 676 int vfs_phone = vfs_exchange_begin(); 694 677 695 678 req = async_send_0(vfs_phone, VFS_IN_RENAME, NULL); 696 679 rc = async_data_write_start(vfs_phone, olda, olda_size); 697 680 if (rc != EOK) { 698 async_wait_for(req, &rc_orig); 699 async_serialize_end(); 700 futex_up(&vfs_phone_futex); 681 vfs_exchange_end(vfs_phone); 701 682 free(olda); 702 683 free(newa); 684 async_wait_for(req, &rc_orig); 703 685 if (rc_orig == EOK) 704 686 return (int) rc; … … 708 690 rc = async_data_write_start(vfs_phone, newa, newa_size); 709 691 if (rc != EOK) { 710 async_wait_for(req, &rc_orig); 711 async_serialize_end(); 712 futex_up(&vfs_phone_futex); 692 vfs_exchange_end(vfs_phone); 713 693 free(olda); 714 694 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); 695 async_wait_for(req, &rc_orig); 696 if (rc_orig == EOK) 697 return (int) rc; 698 else 699 return (int) rc_orig; 700 } 701 vfs_exchange_end(vfs_phone); 723 702 free(olda); 724 703 free(newa); 704 async_wait_for(req, &rc); 725 705 return rc; 726 706 } … … 740 720 } 741 721 742 f utex_down(&cwd_futex);722 fibril_mutex_lock(&cwd_mutex); 743 723 744 724 if (cwd_fd >= 0) … … 753 733 cwd_size = abs_size; 754 734 755 f utex_up(&cwd_futex);735 fibril_mutex_unlock(&cwd_mutex); 756 736 return EOK; 757 737 } … … 762 742 return NULL; 763 743 764 f utex_down(&cwd_futex);744 fibril_mutex_lock(&cwd_mutex); 765 745 766 746 if ((cwd_size == 0) || (size < cwd_size + 1)) { 767 f utex_up(&cwd_futex);747 fibril_mutex_unlock(&cwd_mutex); 768 748 return NULL; 769 749 } 770 750 771 751 str_cpy(buf, size, cwd_path); 772 f utex_up(&cwd_futex);752 fibril_mutex_unlock(&cwd_mutex); 773 753 774 754 return buf; … … 776 756 777 757 int fd_phone(int fildes) 758 { 759 struct stat stat; 760 761 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) 778 772 { 779 773 struct stat stat; … … 781 775 782 776 rc = fstat(fildes, &stat); 783 784 if (!stat.device)785 return -1;786 787 return devmap_device_connect(stat.device, 0);788 }789 790 int fd_node(int fildes, fdi_node_t *node)791 {792 struct stat stat;793 int rc;794 795 rc = fstat(fildes, &stat);796 777 797 778 if (rc == EOK) { 798 779 node->fs_handle = stat.fs_handle; 799 node->dev _handle = stat.dev_handle;780 node->devmap_handle = stat.devmap_handle; 800 781 node->index = stat.index; 801 782 } … … 806 787 int dup2(int oldfd, int newfd) 807 788 { 808 futex_down(&vfs_phone_futex); 809 async_serialize_start(); 810 vfs_connect(); 811 812 ipcarg_t ret; 813 ipcarg_t rc = async_req_2_1(vfs_phone, VFS_IN_DUP, oldfd, newfd, &ret); 814 815 async_serialize_end(); 816 futex_up(&vfs_phone_futex); 789 int vfs_phone = vfs_exchange_begin(); 790 791 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); 817 795 818 796 if (rc == EOK)
Note:
See TracChangeset
for help on using the changeset viewer.