Changes in uspace/lib/c/generic/vfs/vfs.c [6afc9d7:38db6288] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
r6afc9d7 r38db6288 75 75 76 76 while (vfs_sess == NULL) 77 vfs_sess = service_connect_blocking( SERVICE_VFS, INTERFACE_VFS,78 0 );77 vfs_sess = service_connect_blocking(EXCHANGE_PARALLEL, SERVICE_VFS, 78 0, 0); 79 79 80 80 fibril_mutex_unlock(&vfs_mutex); … … 93 93 } 94 94 95 char * vfs_absolutize(const char *path, size_t *retlen)95 char *absolutize(const char *path, size_t *retlen) 96 96 { 97 97 char *ncwd_path; … … 101 101 size_t size = str_size(path); 102 102 if (*path != '/') { 103 if ( cwd_path == NULL) {103 if (!cwd_path) { 104 104 fibril_mutex_unlock(&cwd_mutex); 105 105 return NULL; 106 106 } 107 107 ncwd_path_nc = malloc(cwd_size + 1 + size + 1); 108 if ( ncwd_path_nc == NULL) {108 if (!ncwd_path_nc) { 109 109 fibril_mutex_unlock(&cwd_mutex); 110 110 return NULL; … … 115 115 } else { 116 116 ncwd_path_nc = malloc(size + 1); 117 if ( ncwd_path_nc == NULL) {117 if (!ncwd_path_nc) { 118 118 fibril_mutex_unlock(&cwd_mutex); 119 119 return NULL; … … 123 123 str_append(ncwd_path_nc, cwd_size + 1 + size + 1, path); 124 124 ncwd_path = canonify(ncwd_path_nc, retlen); 125 if ( ncwd_path == NULL) {125 if (!ncwd_path) { 126 126 fibril_mutex_unlock(&cwd_mutex); 127 127 free(ncwd_path_nc); … … 135 135 ncwd_path = str_dup(ncwd_path); 136 136 free(ncwd_path_nc); 137 if ( ncwd_path == NULL) {137 if (!ncwd_path) { 138 138 fibril_mutex_unlock(&cwd_mutex); 139 139 return NULL; … … 143 143 } 144 144 145 int vfs_mount(const char *fs_name, const char *mp, const char *fqsn,145 int mount(const char *fs_name, const char *mp, const char *fqsn, 146 146 const char *opts, unsigned int flags, unsigned int instance) 147 147 { … … 171 171 172 172 size_t mpa_size; 173 char *mpa = vfs_absolutize(mp, &mpa_size);174 if ( mpa == NULL) {173 char *mpa = absolutize(mp, &mpa_size); 174 if (!mpa) { 175 175 if (null_id != -1) 176 176 loc_null_destroy(null_id); … … 255 255 } 256 256 257 int vfs_unmount(const char *mp)257 int unmount(const char *mp) 258 258 { 259 259 sysarg_t rc; … … 263 263 char *mpa; 264 264 265 mpa = vfs_absolutize(mp, &mpa_size);266 if ( mpa == NULL)265 mpa = absolutize(mp, &mpa_size); 266 if (!mpa) 267 267 return ENOMEM; 268 268 … … 289 289 } 290 290 291 /** Open file (internal). 292 * 293 * @param abs Absolute path to file 294 * @param abs_size Size of @a abs string 295 * @param lflag L_xxx flags 296 * @param oflag O_xxx flags 297 * @param fd Place to store new file descriptor 298 * 299 * @return EOK on success, non-zero error code on error 300 */ 301 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag, 302 int *fd) 291 static int open_internal(const char *abs, size_t abs_size, int lflag, int oflag) 303 292 { 304 293 async_exch_t *exch = vfs_exchange_begin(); … … 326 315 return (int) rc; 327 316 328 *fd = (int) IPC_GET_ARG1(answer); 329 return EOK; 330 } 331 332 /** Open file. 333 * 334 * @param path File path 335 * @param oflag O_xxx flags 336 * @param mode File mode (only with O_CREAT) 337 * 338 * @return Nonnegative file descriptor on success. On error -1 is returned 339 * and errno is set. 340 */ 317 return (int) IPC_GET_ARG1(answer); 318 } 319 341 320 int open(const char *path, int oflag, ...) 342 321 { 343 322 size_t abs_size; 344 char *abs = vfs_absolutize(path, &abs_size); 345 int fd = -1; 346 347 if (abs == NULL) { 348 errno = ENOMEM; 349 return -1; 350 } 351 352 int rc = open_internal(abs, abs_size, L_FILE, oflag, &fd); 323 char *abs = absolutize(path, &abs_size); 324 if (!abs) 325 return ENOMEM; 326 327 int ret = open_internal(abs, abs_size, L_FILE, oflag); 353 328 free(abs); 354 329 355 if (rc != EOK) { 356 errno = rc; 357 return -1; 358 } 359 360 return fd; 361 } 362 363 /** Close file. 364 * 365 * @param fildes File descriptor 366 * @return Zero on success. On error -1 is returned and errno is set. 367 */ 330 return ret; 331 } 332 368 333 int close(int fildes) 369 334 { … … 374 339 vfs_exchange_end(exch); 375 340 376 if (rc != EOK) { 377 errno = rc; 378 return -1; 379 } 380 381 return 0; 382 } 383 384 /** Read bytes from file. 385 * 386 * Read up to @a nbyte bytes from file. The actual number of bytes read 387 * may be lower, but greater than zero if there are any bytes available. 388 * If there are no bytes available for reading, then the function will 389 * return success with zero bytes read. 390 * 391 * @param fildes File descriptor 392 * @param buf Buffer 393 * @param nbyte Maximum number of bytes to read 394 * @param nread Place to store actual number of bytes read (0 or more) 395 * 396 * @return EOK on success, non-zero error code on error. 397 */ 398 static int _read_short(int fildes, void *buf, size_t nbyte, ssize_t *nread) 341 return (int) rc; 342 } 343 344 ssize_t read(int fildes, void *buf, size_t nbyte) 399 345 { 400 346 sysarg_t rc; … … 411 357 if (rc != EOK) { 412 358 vfs_exchange_end(exch); 413 359 414 360 sysarg_t rc_orig; 415 361 async_wait_for(req, &rc_orig); 416 417 if (rc_orig == EOK) 418 return rc;419 else 420 return rc_orig;421 } 422 423 vfs_exchange_end(exch);424 async_wait_for(req, &rc);425 426 if (rc != EOK)362 363 if (rc_orig == EOK) 364 return (ssize_t) rc; 365 else 366 return (ssize_t) rc_orig; 367 } 368 vfs_exchange_end(exch); 369 async_wait_for(req, &rc); 370 if (rc == EOK) 371 return (ssize_t) IPC_GET_ARG1(answer); 372 else 427 373 return rc; 428 429 *nread = (ssize_t) IPC_GET_ARG1(answer); 430 return EOK; 431 } 432 433 /** Write bytes to file. 434 * 435 * Write up to @a nbyte bytes from file. The actual number of bytes written 436 * may be lower, but greater than zero. 437 * 438 * @param fildes File descriptor 439 * @param buf Buffer 440 * @param nbyte Maximum number of bytes to write 441 * @param nread Place to store actual number of bytes written (0 or more) 442 * 443 * @return EOK on success, non-zero error code on error. 444 */ 445 static int _write_short(int fildes, const void *buf, size_t nbyte, 446 ssize_t *nwritten) 374 } 375 376 ssize_t write(int fildes, const void *buf, size_t nbyte) 447 377 { 448 378 sysarg_t rc; … … 459 389 if (rc != EOK) { 460 390 vfs_exchange_end(exch); 461 391 462 392 sysarg_t rc_orig; 463 393 async_wait_for(req, &rc_orig); 464 465 if (rc_orig == EOK) 466 return rc; 467 else 468 return rc_orig; 469 } 470 471 vfs_exchange_end(exch); 472 async_wait_for(req, &rc); 473 474 if (rc != EOK) 475 return rc; 476 477 *nwritten = (ssize_t) IPC_GET_ARG1(answer); 478 return EOK; 479 } 480 481 /** Read data. 482 * 483 * Read up to @a nbytes bytes from file if available. This function always reads 484 * all the available bytes up to @a nbytes. 394 395 if (rc_orig == EOK) 396 return (ssize_t) rc; 397 else 398 return (ssize_t) rc_orig; 399 } 400 vfs_exchange_end(exch); 401 async_wait_for(req, &rc); 402 if (rc == EOK) 403 return (ssize_t) IPC_GET_ARG1(answer); 404 else 405 return -1; 406 } 407 408 /** Read entire buffer. 409 * 410 * In face of short reads this function continues reading until either 411 * the entire buffer is read or no more data is available (at end of file). 485 412 * 486 413 * @param fildes File descriptor … … 488 415 * @param nbytes Number of bytes to read 489 416 * 490 * @return On success, nonnegative number of bytes read.491 * On failure, -1 and sets errno.417 * @return On success, positive number of bytes read. 418 * On failure, negative error code from read(). 492 419 */ 493 ssize_t read (int fildes, void *buf, size_t nbyte)420 ssize_t read_all(int fildes, void *buf, size_t nbyte) 494 421 { 495 422 ssize_t cnt = 0; 496 423 size_t nread = 0; 497 424 uint8_t *bp = (uint8_t *) buf; 498 int rc; 499 425 500 426 do { 501 427 bp += cnt; 502 428 nread += cnt; 503 rc = _read_short(fildes, bp, nbyte - nread, &cnt); 504 } while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0); 505 506 if (rc != EOK) { 507 errno = rc; 508 return -1; 509 } 510 429 cnt = read(fildes, bp, nbyte - nread); 430 } while (cnt > 0 && (nbyte - nread - cnt) > 0); 431 432 if (cnt < 0) 433 return cnt; 434 511 435 return nread + cnt; 512 436 } 513 437 514 /** Write data.438 /** Write entire buffer. 515 439 * 516 440 * This function fails if it cannot write exactly @a len bytes to the file. … … 520 444 * @param nbytes Number of bytes to write 521 445 * 522 * @return On success, nonnegative number of bytes written.523 * On failure, -1 and sets errno.446 * @return EOK on error, return value from write() if writing 447 * failed. 524 448 */ 525 ssize_t write (int fildes, const void *buf, size_t nbyte)449 ssize_t write_all(int fildes, const void *buf, size_t nbyte) 526 450 { 527 451 ssize_t cnt = 0; 528 452 ssize_t nwritten = 0; 529 453 const uint8_t *bp = (uint8_t *) buf; 530 int rc;531 454 532 455 do { 533 456 bp += cnt; 534 457 nwritten += cnt; 535 rc = _write_short(fildes, bp, nbyte - nwritten, &cnt); 536 } while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0); 537 538 if (rc != EOK) { 539 errno = rc; 540 return -1; 541 } 458 cnt = write(fildes, bp, nbyte - nwritten); 459 } while (cnt > 0 && ((ssize_t )nbyte - nwritten - cnt) > 0); 460 461 if (cnt < 0) 462 return cnt; 463 464 if ((ssize_t)nbyte - nwritten - cnt > 0) 465 return EIO; 542 466 543 467 return nbyte; 544 468 } 545 469 546 /** Synchronize file.547 *548 * @param fildes File descriptor549 * @return 0 on success. On error returns -1 and sets errno.550 */551 470 int fsync(int fildes) 552 471 { … … 555 474 vfs_exchange_end(exch); 556 475 557 if (rc != EOK) { 558 errno = rc; 559 return -1; 560 } 561 562 return 0; 563 } 564 565 /** Seek to a position. 566 * 567 * @param fildes File descriptor 568 * @param offset Offset 569 * @param whence SEEK_SET, SEEK_CUR or SEEK_END 570 * 571 * @return On success the nonnegative offset from start of file. On error 572 * returns (off64_t)-1 and sets errno. 573 */ 476 return (int) rc; 477 } 478 574 479 off64_t lseek(int fildes, off64_t offset, int whence) 575 480 { … … 584 489 vfs_exchange_end(exch); 585 490 586 if (rc != EOK) { 587 errno = rc; 491 if (rc != EOK) 588 492 return (off64_t) -1; 589 }590 493 591 494 return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi); 592 495 } 593 496 594 /** Truncate file to a specified length.595 *596 * Truncate file so that its size is exactly @a length597 *598 * @param fildes File descriptor599 * @param length Length600 *601 * @return 0 on success, -1 on error and sets errno.602 */603 497 int ftruncate(int fildes, aoff64_t length) 604 498 { … … 610 504 vfs_exchange_end(exch); 611 505 612 if (rc != EOK) { 613 errno = rc; 614 return -1; 615 } 616 617 return 0; 618 } 619 620 /** Get file status. 621 * 622 * @param fildes File descriptor 623 * @param stat Place to store file information 624 * 625 * @return 0 on success, -1 on error and sets errno. 626 */ 506 return (int) rc; 507 } 508 627 509 int fstat(int fildes, struct stat *stat) 628 510 { … … 636 518 if (rc != EOK) { 637 519 vfs_exchange_end(exch); 638 520 639 521 sysarg_t rc_orig; 640 522 async_wait_for(req, &rc_orig); 641 642 if (rc_orig != EOK) 643 rc = rc_orig; 644 if (rc != EOK) { 645 errno = rc; 646 return -1; 647 } 648 649 return 0; 650 } 651 652 vfs_exchange_end(exch); 653 async_wait_for(req, &rc); 654 655 if (rc != EOK) { 656 errno = rc; 657 return -1; 658 } 659 660 return 0; 661 } 662 663 /** Get file status. 664 * 665 * @param path Path to file 666 * @param stat Place to store file information 667 * 668 * @return 0 on success, -1 on error and sets errno. 669 */ 523 524 if (rc_orig == EOK) 525 return (ssize_t) rc; 526 else 527 return (ssize_t) rc_orig; 528 } 529 vfs_exchange_end(exch); 530 async_wait_for(req, &rc); 531 532 return rc; 533 } 534 670 535 int stat(const char *path, struct stat *stat) 671 536 { … … 675 540 676 541 size_t pa_size; 677 char *pa = vfs_absolutize(path, &pa_size); 678 if (pa == NULL) { 679 errno = ENOMEM; 680 return -1; 681 } 542 char *pa = absolutize(path, &pa_size); 543 if (!pa) 544 return ENOMEM; 682 545 683 546 async_exch_t *exch = vfs_exchange_begin(); … … 689 552 free(pa); 690 553 async_wait_for(req, &rc_orig); 691 if (rc_orig != EOK) 692 rc = rc_orig; 693 if (rc != EOK) { 694 errno = rc; 695 return -1; 696 } 554 if (rc_orig == EOK) 555 return (int) rc; 556 else 557 return (int) rc_orig; 697 558 } 698 559 rc = async_data_read_start(exch, stat, sizeof(struct stat)); … … 701 562 free(pa); 702 563 async_wait_for(req, &rc_orig); 703 if (rc_orig != EOK) 704 rc = rc_orig; 705 if (rc != EOK) { 706 errno = rc; 707 return -1; 708 } 564 if (rc_orig == EOK) 565 return (int) rc; 566 else 567 return (int) rc_orig; 709 568 } 710 569 vfs_exchange_end(exch); 711 570 free(pa); 712 571 async_wait_for(req, &rc); 713 if (rc != EOK) { 714 errno = rc; 715 return -1; 716 } 572 return rc; 573 } 574 575 DIR *opendir(const char *dirname) 576 { 577 DIR *dirp = malloc(sizeof(DIR)); 578 if (!dirp) 579 return NULL; 580 581 size_t abs_size; 582 char *abs = absolutize(dirname, &abs_size); 583 if (!abs) { 584 free(dirp); 585 return NULL; 586 } 587 588 int ret = open_internal(abs, abs_size, L_DIRECTORY, 0); 589 free(abs); 590 591 if (ret < 0) { 592 free(dirp); 593 return NULL; 594 } 595 596 dirp->fd = ret; 597 return dirp; 598 } 599 600 struct dirent *readdir(DIR *dirp) 601 { 602 ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1); 603 if (len <= 0) 604 return NULL; 605 return &dirp->res; 606 } 607 608 void rewinddir(DIR *dirp) 609 { 610 (void) lseek(dirp->fd, 0, SEEK_SET); 611 } 612 613 int closedir(DIR *dirp) 614 { 615 (void) close(dirp->fd); 616 free(dirp); 717 617 return 0; 718 618 } 719 619 720 /** Open directory.721 *722 * @param dirname Directory pathname723 *724 * @return Non-NULL pointer on success. On error returns @c NULL and sets errno.725 */726 DIR *opendir(const char *dirname)727 {728 DIR *dirp = malloc(sizeof(DIR));729 int fd = -1;730 731 if (dirp == NULL) {732 errno = ENOMEM;733 return NULL;734 }735 736 size_t abs_size;737 char *abs = vfs_absolutize(dirname, &abs_size);738 if (abs == NULL) {739 free(dirp);740 errno = ENOMEM;741 return NULL;742 }743 744 int rc = open_internal(abs, abs_size, L_DIRECTORY, 0, &fd);745 free(abs);746 747 if (rc != EOK) {748 free(dirp);749 errno = rc;750 return NULL;751 }752 753 dirp->fd = fd;754 return dirp;755 }756 757 /** Read directory entry.758 *759 * @param dirp Open directory760 * @return Non-NULL pointer to directory entry on success. On error returns761 * @c NULL and sets errno.762 */763 struct dirent *readdir(DIR *dirp)764 {765 int rc;766 ssize_t len;767 768 rc = _read_short(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1, &len);769 if (rc != EOK) {770 errno = rc;771 return NULL;772 }773 774 (void) len;775 return &dirp->res;776 }777 778 /** Rewind directory position to the beginning.779 *780 * @param dirp Open directory781 */782 void rewinddir(DIR *dirp)783 {784 (void) lseek(dirp->fd, 0, SEEK_SET);785 }786 787 /** Close directory.788 *789 * @param dirp Open directory790 * @return 0 on success. On error returns -1 and sets errno.791 */792 int closedir(DIR *dirp)793 {794 int rc;795 796 rc = close(dirp->fd);797 free(dirp);798 799 /* On error errno was set by close() */800 return rc;801 }802 803 /** Create directory.804 *805 * @param path Path806 * @param mode File mode807 * @return 0 on success. On error returns -1 and sets errno.808 */809 620 int mkdir(const char *path, mode_t mode) 810 621 { … … 813 624 814 625 size_t pa_size; 815 char *pa = vfs_absolutize(path, &pa_size); 816 if (pa == NULL) { 817 errno = ENOMEM; 818 return -1; 819 } 626 char *pa = absolutize(path, &pa_size); 627 if (!pa) 628 return ENOMEM; 820 629 821 630 async_exch_t *exch = vfs_exchange_begin(); … … 826 635 vfs_exchange_end(exch); 827 636 free(pa); 828 637 829 638 sysarg_t rc_orig; 830 639 async_wait_for(req, &rc_orig); 831 832 if (rc_orig != EOK) 833 rc = rc_orig; 834 835 if (rc != EOK) { 836 errno = rc; 837 return -1; 838 } 839 840 return 0; 841 } 842 640 641 if (rc_orig == EOK) 642 return (int) rc; 643 else 644 return (int) rc_orig; 645 } 843 646 vfs_exchange_end(exch); 844 647 free(pa); 845 648 async_wait_for(req, &rc); 846 847 if (rc != EOK) { 848 errno = rc; 849 return -1; 850 } 851 852 return 0; 853 } 854 855 /** Unlink a file or directory. 856 * 857 * @param path Path to file or empty directory 858 * @param lflag L_xxx flag (L_NONE, L_FILE or L_DIRECTORY) 859 * @return EOK on success, non-zero error code on error 860 */ 649 return rc; 650 } 651 861 652 static int _unlink(const char *path, int lflag) 862 653 { … … 865 656 866 657 size_t pa_size; 867 char *pa = vfs_absolutize(path, &pa_size);868 if ( pa == NULL)658 char *pa = absolutize(path, &pa_size); 659 if (!pa) 869 660 return ENOMEM; 870 661 … … 891 682 } 892 683 893 /** Unlink file or directory.894 *895 * @param path Path896 * @return EOk on success, error code on error897 */898 684 int unlink(const char *path) 899 685 { 900 int rc; 901 902 rc = _unlink(path, L_NONE); 903 if (rc != EOK) { 904 errno = rc; 905 return -1; 906 } 907 908 return 0; 909 } 910 911 /** Remove empty directory. 912 * 913 * @param path Path 914 * @return 0 on success. On error returns -1 and sets errno. 915 */ 686 return _unlink(path, L_NONE); 687 } 688 916 689 int rmdir(const char *path) 917 690 { 918 int rc; 919 920 rc = _unlink(path, L_DIRECTORY); 921 if (rc != EOK) { 922 errno = rc; 923 return -1; 924 } 925 926 return 0; 927 } 928 929 /** Rename directory entry. 930 * 931 * @param old Old name 932 * @param new New name 933 * 934 * @return 0 on success. On error returns -1 and sets errno. 935 */ 691 return _unlink(path, L_DIRECTORY); 692 } 693 936 694 int rename(const char *old, const char *new) 937 695 { … … 941 699 942 700 size_t olda_size; 943 char *olda = vfs_absolutize(old, &olda_size); 944 if (olda == NULL) { 945 errno = ENOMEM; 946 return -1; 947 } 701 char *olda = absolutize(old, &olda_size); 702 if (!olda) 703 return ENOMEM; 948 704 949 705 size_t newa_size; 950 char *newa = vfs_absolutize(new, &newa_size);951 if ( newa == NULL) {706 char *newa = absolutize(new, &newa_size); 707 if (!newa) { 952 708 free(olda); 953 errno = ENOMEM; 954 return -1; 709 return ENOMEM; 955 710 } 956 711 … … 964 719 free(newa); 965 720 async_wait_for(req, &rc_orig); 966 if (rc_orig != EOK) 967 rc = rc_orig; 968 if (rc != EOK) { 969 errno = rc; 970 return -1; 971 } 972 return 0; 721 if (rc_orig == EOK) 722 return (int) rc; 723 else 724 return (int) rc_orig; 973 725 } 974 726 rc = async_data_write_start(exch, newa, newa_size); … … 978 730 free(newa); 979 731 async_wait_for(req, &rc_orig); 980 if (rc_orig != EOK) 981 rc = rc_orig; 982 if (rc != EOK) { 983 errno = rc; 984 return -1; 985 } 986 return 0; 732 if (rc_orig == EOK) 733 return (int) rc; 734 else 735 return (int) rc_orig; 987 736 } 988 737 vfs_exchange_end(exch); … … 990 739 free(newa); 991 740 async_wait_for(req, &rc); 992 993 if (rc != EOK) { 994 errno = rc; 995 return -1; 996 } 997 998 return 0; 999 } 1000 1001 /** Remove directory entry. 1002 * 1003 * @param path Path 1004 * @return 0 on success. On error returns -1 and sets errno. 1005 */ 741 return rc; 742 } 743 1006 744 int remove(const char *path) 1007 745 { … … 1009 747 } 1010 748 1011 /** Change working directory.1012 *1013 * @param path Path1014 * @return 0 on success. On error returns -1 and sets errno.1015 */1016 749 int chdir(const char *path) 1017 750 { 1018 751 size_t abs_size; 1019 char *abs = vfs_absolutize(path, &abs_size); 1020 int fd = -1; 1021 1022 if (abs == NULL) { 1023 errno = ENOMEM; 1024 return -1; 1025 } 1026 1027 int rc = open_internal(abs, abs_size, L_DIRECTORY, O_DESC, &fd); 1028 1029 if (rc != EOK) { 752 char *abs = absolutize(path, &abs_size); 753 if (!abs) 754 return ENOMEM; 755 756 int fd = open_internal(abs, abs_size, L_DIRECTORY, O_DESC); 757 758 if (fd < 0) { 1030 759 free(abs); 1031 errno = rc; 1032 return -1; 760 return ENOENT; 1033 761 } 1034 762 … … 1037 765 if (cwd_fd >= 0) 1038 766 close(cwd_fd); 767 1039 768 1040 769 if (cwd_path) … … 1046 775 1047 776 fibril_mutex_unlock(&cwd_mutex); 1048 return 0; 1049 } 1050 1051 /** Get current working directory path. 1052 * 1053 * @param buf Buffer 1054 * @param size Size of @a buf 1055 * @return On success returns @a buf. On failure returns @c NULL and sets errno. 1056 */ 777 return EOK; 778 } 779 1057 780 char *getcwd(char *buf, size_t size) 1058 781 { 1059 if (size == 0) { 1060 errno = EINVAL; 782 if (size == 0) 1061 783 return NULL; 1062 }1063 784 1064 785 fibril_mutex_lock(&cwd_mutex); … … 1066 787 if ((cwd_size == 0) || (size < cwd_size + 1)) { 1067 788 fibril_mutex_unlock(&cwd_mutex); 1068 errno = ERANGE;1069 789 return NULL; 1070 790 } … … 1076 796 } 1077 797 1078 /** Open session to service represented by a special file. 1079 * 1080 * Given that the file referred to by @a fildes represents a service, 1081 * open a session to that service. 1082 * 1083 * @param fildes File descriptor 1084 * @param iface Interface to connect to (XXX Should be automatic) 1085 * @return On success returns session pointer. On error returns @c NULL. 1086 */ 1087 async_sess_t *vfs_fd_session(int fildes, iface_t iface) 798 async_sess_t *fd_session(exch_mgmt_t mgmt, int fildes) 1088 799 { 1089 800 struct stat stat; 1090 801 int rc = fstat(fildes, &stat); 1091 if (rc != 0) 802 if (rc != 0) { 803 errno = rc; 1092 804 return NULL; 1093 1094 if (stat.service == 0) 805 } 806 807 if (!stat.service) { 808 errno = ENOENT; 1095 809 return NULL; 1096 1097 return loc_service_connect(stat.service, iface, 0); 1098 } 1099 1100 /** Duplicate open file. 1101 * 1102 * Duplicate open file under a new file descriptor. 1103 * 1104 * @param oldfd Old file descriptor 1105 * @param newfd New file descriptor 1106 * @return 0 on success. On error -1 is returned and errno is set 1107 */ 810 } 811 812 return loc_service_connect(mgmt, stat.service, 0); 813 } 814 1108 815 int dup2(int oldfd, int newfd) 1109 816 { … … 1116 823 1117 824 if (rc == EOK) 1118 rc = ret; 1119 1120 if (rc != EOK) { 1121 errno = rc; 1122 return -1; 1123 } 1124 1125 return 0; 1126 } 1127 1128 int vfs_fd_wait(void) 825 return (int) ret; 826 827 return (int) rc; 828 } 829 830 int fd_wait(void) 1129 831 { 1130 832 async_exch_t *exch = vfs_exchange_begin(); … … 1141 843 } 1142 844 1143 int vfs_get_mtab_list(list_t *mtab_list)845 int get_mtab_list(list_t *mtab_list) 1144 846 { 1145 847 sysarg_t rc; … … 1161 863 1162 864 mtab_ent = malloc(sizeof(mtab_ent_t)); 1163 if ( mtab_ent == NULL) {865 if (!mtab_ent) { 1164 866 rc = ENOMEM; 1165 867 goto exit; … … 1202 904 } 1203 905 1204 /** Get filesystem statistics.1205 *1206 * @param path Mount point path1207 * @param st Buffer for storing information1208 * @return 0 on success. On error -1 is returned and errno is set.1209 */1210 906 int statfs(const char *path, struct statfs *st) 1211 907 { … … 1214 910 size_t pa_size; 1215 911 1216 char *pa = vfs_absolutize(path, &pa_size); 1217 if (pa == NULL) { 1218 errno = ENOMEM; 1219 return -1; 1220 } 912 char *pa = absolutize(path, &pa_size); 913 if (!pa) 914 return ENOMEM; 1221 915 1222 916 async_exch_t *exch = vfs_exchange_begin(); … … 1233 927 free(pa); 1234 928 async_wait_for(req, &rc_orig); 1235 rc = (rc_orig != EOK ? rc_orig : rc); 1236 1237 if (rc != EOK) { 1238 errno = rc; 1239 return -1; 1240 } 1241 1242 return 0; 929 return (int) (rc_orig != EOK ? rc_orig : rc); 1243 930 } 1244 931
Note:
See TracChangeset
for help on using the changeset viewer.