Changeset 58898d1d in mainline for uspace/lib/c/generic/vfs/vfs.c


Ignore:
Timestamp:
2017-03-24T20:31:54Z (7 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8e9b2534
Parents:
c9e3692
Message:

Remove VFS_IN_SEEK from VFS

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/vfs/vfs.c

    rc9e3692 r58898d1d  
    444444 *
    445445 * @param fildes File descriptor
     446 * @param pos Position to read from
    446447 * @param buf Buffer
    447448 * @param nbyte Maximum number of bytes to read
     
    450451 * @return EOK on success, non-zero error code on error.
    451452 */
    452 static int _read_short(int fildes, void *buf, size_t nbyte, ssize_t *nread)
     453static int _read_short(int fildes, aoff64_t pos, void *buf, size_t nbyte,
     454    ssize_t *nread)
    453455{
    454456        sysarg_t rc;
     
    461463        async_exch_t *exch = vfs_exchange_begin();
    462464       
    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);
    464467        rc = async_data_read_start(exch, (void *) buf, nbyte);
    465468
     
    484487 *
    485488 * @param fildes File descriptor
     489 * @param pos Position to write to
    486490 * @param buf Buffer
    487491 * @param nbyte Maximum number of bytes to write
     
    490494 * @return EOK on success, non-zero error code on error.
    491495 */
    492 static int _write_short(int fildes, const void *buf, size_t nbyte,
     496static int _write_short(int fildes, aoff64_t pos, const void *buf, size_t nbyte,
    493497    ssize_t *nwritten)
    494498{
     
    502506        async_exch_t *exch = vfs_exchange_begin();
    503507       
    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);
    505510        rc = async_data_write_start(exch, (void *) buf, nbyte);
    506511       
     
    525530 *
    526531 * @param fildes        File descriptor
     532 * @param pos           Pointer to position to read from
    527533 * @param buf           Buffer, @a nbytes bytes long
    528534 * @param nbytes        Number of bytes to read
     
    531537 *                      On failure, -1 and sets errno.
    532538 */
    533 ssize_t read(int fildes, void *buf, size_t nbyte)
     539ssize_t read(int fildes, aoff64_t *pos, void *buf, size_t nbyte)
    534540{
    535541        ssize_t cnt = 0;
     
    541547                bp += cnt;
    542548                nread += cnt;
    543                 rc = _read_short(fildes, bp, nbyte - nread, &cnt);
     549                *pos += cnt;
     550                rc = _read_short(fildes, *pos, bp, nbyte - nread, &cnt);
    544551        } while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0);
    545552       
     
    549556        }
    550557       
     558        *pos += cnt;
    551559        return nread + cnt;
    552560}
     
    557565 *
    558566 * @param fildes        File descriptor
     567 * @param pos           Pointer to position to write to
    559568 * @param buf           Data, @a nbytes bytes long
    560569 * @param nbytes        Number of bytes to write
     
    563572 *                      On failure, -1 and sets errno.
    564573 */
    565 ssize_t write(int fildes, const void *buf, size_t nbyte)
     574ssize_t write(int fildes, aoff64_t *pos, const void *buf, size_t nbyte)
    566575{
    567576        ssize_t cnt = 0;
     
    573582                bp += cnt;
    574583                nwritten += cnt;
    575                 rc = _write_short(fildes, bp, nbyte - nwritten, &cnt);
     584                *pos += cnt;
     585                rc = _write_short(fildes, *pos, bp, nbyte - nwritten, &cnt);
    576586        } while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0);
    577587
     
    581591        }
    582592
     593        *pos += cnt;
    583594        return nbyte;
    584595}
     
    601612       
    602613        return 0;
    603 }
    604 
    605 /** Seek to a position.
    606  *
    607  * @param fildes File descriptor
    608  * @param offset Offset
    609  * @param whence SEEK_SET, SEEK_CUR or SEEK_END
    610  *
    611  * @return On success the nonnegative offset from start of file. On error
    612  *         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);
    632614}
    633615
     
    757739       
    758740        dirp->fd = fd;
     741        dirp->pos = 0;
    759742        return dirp;
    760743}
     
    771754        ssize_t len;
    772755       
    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);
    774758        if (rc != EOK) {
    775759                errno = rc;
     
    777761        }
    778762       
    779         (void) len;
     763        dirp->pos += len;
     764       
    780765        return &dirp->res;
    781766}
     
    787772void rewinddir(DIR *dirp)
    788773{
    789         (void) lseek(dirp->fd, 0, SEEK_SET);
     774        dirp->pos = 0;
    790775}
    791776
Note: See TracChangeset for help on using the changeset viewer.