Changeset 58898d1d in mainline for uspace/lib/c/generic/vfs/vfs.c
- Timestamp:
- 2017-03-24T20:31:54Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 8e9b2534
- Parents:
- c9e3692
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/vfs/vfs.c
rc9e3692 r58898d1d 444 444 * 445 445 * @param fildes File descriptor 446 * @param pos Position to read from 446 447 * @param buf Buffer 447 448 * @param nbyte Maximum number of bytes to read … … 450 451 * @return EOK on success, non-zero error code on error. 451 452 */ 452 static int _read_short(int fildes, void *buf, size_t nbyte, ssize_t *nread) 453 static int _read_short(int fildes, aoff64_t pos, void *buf, size_t nbyte, 454 ssize_t *nread) 453 455 { 454 456 sysarg_t rc; … … 461 463 async_exch_t *exch = vfs_exchange_begin(); 462 464 463 req = async_send_1(exch, VFS_IN_READ, fildes, &answer); 465 req = async_send_3(exch, VFS_IN_READ, fildes, LOWER32(pos), 466 UPPER32(pos), &answer); 464 467 rc = async_data_read_start(exch, (void *) buf, nbyte); 465 468 … … 484 487 * 485 488 * @param fildes File descriptor 489 * @param pos Position to write to 486 490 * @param buf Buffer 487 491 * @param nbyte Maximum number of bytes to write … … 490 494 * @return EOK on success, non-zero error code on error. 491 495 */ 492 static int _write_short(int fildes, const void *buf, size_t nbyte,496 static int _write_short(int fildes, aoff64_t pos, const void *buf, size_t nbyte, 493 497 ssize_t *nwritten) 494 498 { … … 502 506 async_exch_t *exch = vfs_exchange_begin(); 503 507 504 req = async_send_1(exch, VFS_IN_WRITE, fildes, &answer); 508 req = async_send_3(exch, VFS_IN_WRITE, fildes, LOWER32(pos), 509 UPPER32(pos), &answer); 505 510 rc = async_data_write_start(exch, (void *) buf, nbyte); 506 511 … … 525 530 * 526 531 * @param fildes File descriptor 532 * @param pos Pointer to position to read from 527 533 * @param buf Buffer, @a nbytes bytes long 528 534 * @param nbytes Number of bytes to read … … 531 537 * On failure, -1 and sets errno. 532 538 */ 533 ssize_t read(int fildes, void *buf, size_t nbyte)539 ssize_t read(int fildes, aoff64_t *pos, void *buf, size_t nbyte) 534 540 { 535 541 ssize_t cnt = 0; … … 541 547 bp += cnt; 542 548 nread += cnt; 543 rc = _read_short(fildes, bp, nbyte - nread, &cnt); 549 *pos += cnt; 550 rc = _read_short(fildes, *pos, bp, nbyte - nread, &cnt); 544 551 } while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0); 545 552 … … 549 556 } 550 557 558 *pos += cnt; 551 559 return nread + cnt; 552 560 } … … 557 565 * 558 566 * @param fildes File descriptor 567 * @param pos Pointer to position to write to 559 568 * @param buf Data, @a nbytes bytes long 560 569 * @param nbytes Number of bytes to write … … 563 572 * On failure, -1 and sets errno. 564 573 */ 565 ssize_t write(int fildes, const void *buf, size_t nbyte)574 ssize_t write(int fildes, aoff64_t *pos, const void *buf, size_t nbyte) 566 575 { 567 576 ssize_t cnt = 0; … … 573 582 bp += cnt; 574 583 nwritten += cnt; 575 rc = _write_short(fildes, bp, nbyte - nwritten, &cnt); 584 *pos += cnt; 585 rc = _write_short(fildes, *pos, bp, nbyte - nwritten, &cnt); 576 586 } while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0); 577 587 … … 581 591 } 582 592 593 *pos += cnt; 583 594 return nbyte; 584 595 } … … 601 612 602 613 return 0; 603 }604 605 /** Seek to a position.606 *607 * @param fildes File descriptor608 * @param offset Offset609 * @param whence SEEK_SET, SEEK_CUR or SEEK_END610 *611 * @return On success the nonnegative offset from start of file. On error612 * returns (off64_t)-1 and sets errno.613 */614 off64_t lseek(int fildes, off64_t offset, int whence)615 {616 async_exch_t *exch = vfs_exchange_begin();617 618 sysarg_t newoff_lo;619 sysarg_t newoff_hi;620 sysarg_t rc = async_req_4_2(exch, VFS_IN_SEEK, fildes,621 LOWER32(offset), UPPER32(offset), whence,622 &newoff_lo, &newoff_hi);623 624 vfs_exchange_end(exch);625 626 if (rc != EOK) {627 errno = rc;628 return (off64_t) -1;629 }630 631 return (off64_t) MERGE_LOUP32(newoff_lo, newoff_hi);632 614 } 633 615 … … 757 739 758 740 dirp->fd = fd; 741 dirp->pos = 0; 759 742 return dirp; 760 743 } … … 771 754 ssize_t len; 772 755 773 rc = _read_short(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1, &len); 756 rc = _read_short(dirp->fd, dirp->pos, &dirp->res.d_name[0], 757 NAME_MAX + 1, &len); 774 758 if (rc != EOK) { 775 759 errno = rc; … … 777 761 } 778 762 779 (void) len; 763 dirp->pos += len; 764 780 765 return &dirp->res; 781 766 } … … 787 772 void rewinddir(DIR *dirp) 788 773 { 789 (void) lseek(dirp->fd, 0, SEEK_SET);774 dirp->pos = 0; 790 775 } 791 776
Note:
See TracChangeset
for help on using the changeset viewer.