Changeset ce04ea44 in mainline


Ignore:
Timestamp:
2017-04-02T12:27:14Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d4067a7
Parents:
163fc09
Message:

Rename read() to vfs_read() and write() to vfs_write()

Location:
uspace
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    r163fc09 rce04ea44  
    251251                }
    252252               
    253                 bytes = read(fd, &pos, buff + copied_bytes, bytes_to_read);
     253                bytes = vfs_read(fd, &pos, buff + copied_bytes, bytes_to_read);
    254254                copied_bytes = 0;
    255255
  • uspace/app/bdsh/cmds/modules/cmp/cmp.c

    r163fc09 rce04ea44  
    9494                        ssize_t size;
    9595                        do {
    96                                 size = read(fd[i], &pos[i],
     96                                size = vfs_read(fd[i], &pos[i],
    9797                                    buffer[i] + offset[i],
    9898                                    CMP_BUFLEN - offset[i]);
    9999                                if (size < 0) {
    100                                         rc = errno;
     100                                        rc = size;
    101101                                        printf("Error reading from %s\n",
    102102                                            fn[i]);
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    r163fc09 rce04ea44  
    413413        }
    414414
    415         while ((bytes = read(fd1, &posr, buff, blen)) > 0) {
    416                 if ((bytes = write(fd2, &posw, buff, bytes)) < 0)
     415        while ((bytes = vfs_read(fd1, &posr, buff, blen)) > 0) {
     416                if ((bytes = vfs_write(fd2, &posw, buff, bytes)) < 0)
    417417                        break;
    418418                copied += bytes;
     
    420420
    421421        if (bytes < 0) {
    422                 printf("\nError copying %s, (%d)\n", src, errno);
     422                printf("\nError copying %s, (%d)\n", src, bytes);
    423423                copied = bytes;
    424424        }
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    r163fc09 rce04ea44  
    166166               
    167167                pos = file_size - 1;
    168                 rc2 = write(fd, &pos, &byte, sizeof(char));
     168                rc2 = vfs_write(fd, &pos, &byte, sizeof(char));
    169169                if (rc2 < 0) {
    170170                        vfs_put(fd);
     
    183183        while (total_written < file_size) {
    184184                to_write = min(file_size - total_written, BUFFER_SIZE);
    185                 rc = write(fd, &pos, buffer, to_write);
     185                rc = vfs_write(fd, &pos, buffer, to_write);
    186186                if (rc <= 0) {
    187187                        printf("%s: Error writing file (%d).\n", cmdname, errno);
  • uspace/app/sysinst/futil.c

    r163fc09 rce04ea44  
    7272
    7373        do {
    74                 nr = read(sf, &posr, buf, BUF_SIZE);
     74                nr = vfs_read(sf, &posr, buf, BUF_SIZE);
    7575                if (nr == 0)
    7676                        break;
     
    7878                        return EIO;
    7979
    80                 nw = write(df, &posw, buf, nr);
     80                nw = vfs_write(df, &posw, buf, nr);
    8181                if (nw <= 0)
    8282                        return EIO;
     
    178178        }
    179179
    180         nr = read(sf, (aoff64_t []) { 0 }, data, fsize);
     180        nr = vfs_read(sf, (aoff64_t []) { 0 }, data, fsize);
    181181        if (nr != (ssize_t)fsize) {
    182182                vfs_put(sf);
  • uspace/app/taskdump/elf_core.c

    r163fc09 rce04ea44  
    207207        }
    208208
    209         rc = write(fd, &pos, &elf_hdr, sizeof(elf_hdr));
     209        rc = vfs_write(fd, &pos, &elf_hdr, sizeof(elf_hdr));
    210210        if (rc != sizeof(elf_hdr)) {
    211211                printf("Failed writing ELF header.\n");
     
    215215
    216216        for (i = 0; i < n_ph; ++i) {
    217                 rc = write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i]));
     217                rc = vfs_write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i]));
    218218                if (rc != sizeof(p_hdr[i])) {
    219219                        printf("Failed writing program header.\n");
     
    232232        note.type = NT_PRSTATUS;
    233233
    234         rc = write(fd, &pos, &note, sizeof(elf_note_t));
     234        rc = vfs_write(fd, &pos, &note, sizeof(elf_note_t));
    235235        if (rc != sizeof(elf_note_t)) {
    236236                printf("Failed writing note header.\n");
     
    239239        }
    240240
    241         rc = write(fd, &pos, "CORE", note.namesz);
     241        rc = vfs_write(fd, &pos, "CORE", note.namesz);
    242242        if (rc != (ssize_t) note.namesz) {
    243243                printf("Failed writing note header.\n");
     
    248248        pos = ALIGN_UP(pos, word_size);
    249249
    250         rc = write(fd, &pos, &pr_status, sizeof(elf_prstatus_t));
     250        rc = vfs_write(fd, &pos, &pr_status, sizeof(elf_prstatus_t));
    251251        if (rc != sizeof(elf_prstatus_t)) {
    252252                printf("Failed writing register data.\n");
     
    310310                }
    311311
    312                 rc = write(fd, pos, buffer, to_copy);
     312                rc = vfs_write(fd, pos, buffer, to_copy);
    313313                if (rc != (ssize_t) to_copy) {
    314314                        printf("Failed writing memory contents.\n");
  • uspace/app/taskdump/symtab.c

    r163fc09 rce04ea44  
    8888        }
    8989
    90         rc = read(fd, &pos, &elf_hdr, sizeof(elf_header_t));
     90        rc = vfs_read(fd, &pos, &elf_hdr, sizeof(elf_header_t));
    9191        if (rc != sizeof(elf_header_t)) {
    9292                printf("failed reading elf header\n");
     
    306306        aoff64_t pos = elf_hdr->e_shoff + idx * sizeof(elf_section_header_t);
    307307
    308         rc = read(fd, &pos, sec_hdr, sizeof(elf_section_header_t));
     308        rc = vfs_read(fd, &pos, sec_hdr, sizeof(elf_section_header_t));
    309309        if (rc != sizeof(elf_section_header_t))
    310310                return EIO;
     
    335335        }
    336336
    337         rc = read(fd, &pos, *ptr, size);
     337        rc = vfs_read(fd, &pos, *ptr, size);
    338338        if (rc != (ssize_t) size) {
    339339                printf("failed reading chunk\n");
  • uspace/app/tester/mm/pager1.c

    r163fc09 rce04ea44  
    5353        (void) vfs_unlink_path(TEST_FILE);
    5454
    55         if (write(fd, (aoff64_t []) {0}, text, sizeof(text)) != sizeof(text)) {
     55        if (vfs_write(fd, (aoff64_t []) {0}, text, sizeof(text)) < 0) {
    5656                vfs_put(fd);
    5757                return NULL;
  • uspace/app/tester/vfs/vfs1.c

    r163fc09 rce04ea44  
    8585       
    8686        size_t size = sizeof(text);
    87         ssize_t cnt = write(fd0, &pos, text, size);
     87        ssize_t cnt = vfs_write(fd0, &pos, text, size);
    8888        if (cnt < 0)
    8989                return "write() failed";
     
    9494        char buf[BUF_SIZE];
    9595        TPRINTF("read..\n");
    96         while ((cnt = read(fd0, &pos, buf, BUF_SIZE))) {
     96        while ((cnt = vfs_read(fd0, &pos, buf, BUF_SIZE))) {
    9797                TPRINTF("read returns %zd\n", cnt);
    9898                if (cnt < 0)
  • uspace/app/viewer/viewer.c

    r163fc09 rce04ea44  
    126126        }
    127127
    128         ssize_t rd = read(fd, (aoff64_t []) {0}, tga, stat.size);
     128        ssize_t rd = vfs_read(fd, (aoff64_t []) {0}, tga, stat.size);
    129129        if ((rd < 0) || (rd != (ssize_t) stat.size)) {
    130130                free(tga);
  • uspace/app/websrv/websrv.c

    r163fc09 rce04ea44  
    240240        aoff64_t pos = 0;
    241241        while (true) {
    242                 ssize_t nr = read(fd, &pos, fbuf, BUFFER_SIZE);
     242                ssize_t nr = vfs_read(fd, &pos, fbuf, BUFFER_SIZE);
    243243                if (nr == 0)
    244244                        break;
  • uspace/drv/bus/isa/isa.c

    r163fc09 rce04ea44  
    281281        }
    282282
    283         r = read(fd, (aoff64_t []) {0}, buf, len);
     283        r = vfs_read(fd, (aoff64_t []) {0}, buf, len);
    284284        if (r < 0) {
    285285                ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
  • uspace/lib/bithenge/src/file.c

    r163fc09 rce04ea44  
    7878                return ELIMIT;
    7979
    80         ssize_t amount_read = read(blob->fd, &offset, buffer, *size);
     80        ssize_t amount_read = vfs_read(blob->fd, &offset, buffer, *size);
    8181        if (amount_read < 0)
    8282                return errno;
  • uspace/lib/c/generic/elf/elf_mod.c

    r163fc09 rce04ea44  
    138138        int i, rc;
    139139
    140         rc = read(elf->fd, &pos, header, sizeof(elf_header_t));
     140        rc = vfs_read(elf->fd, &pos, header, sizeof(elf_header_t));
    141141        if (rc != sizeof(elf_header_t)) {
    142142                DPRINTF("Read error.\n");
     
    197197
    198198                pos = header->e_phoff + i * sizeof(elf_segment_header_t);
    199                 rc = read(elf->fd, &pos, &segment_hdr,
     199                rc = vfs_read(elf->fd, &pos, &segment_hdr,
    200200                    sizeof(elf_segment_header_t));
    201201                if (rc != sizeof(elf_segment_header_t)) {
     
    216216
    217217                pos = header->e_shoff + i * sizeof(elf_section_header_t);
    218                 rc = read(elf->fd, &pos, &section_hdr,
     218                rc = vfs_read(elf->fd, &pos, &section_hdr,
    219219                    sizeof(elf_section_header_t));
    220220                if (rc != sizeof(elf_section_header_t)) {
     
    387387         */
    388388        pos = entry->p_offset;
    389         rc = read(elf->fd, &pos, seg_ptr, entry->p_filesz);
     389        rc = vfs_read(elf->fd, &pos, seg_ptr, entry->p_filesz);
    390390        if (rc < 0) {
    391391                DPRINTF("read error\n");
  • uspace/lib/c/generic/io/io.c

    r163fc09 rce04ea44  
    434434                return 0;
    435435
    436         ssize_t rd = read(stream->fd, &stream->pos, buf, size * nmemb);
     436        ssize_t rd = vfs_read(stream->fd, &stream->pos, buf, size * nmemb);
    437437        if (rd < 0) {
    438                 /* errno was set by read() */
     438                errno = rd;
    439439                stream->error = true;
    440440                rd = 0;
     
    472472                }
    473473        } else {
    474                 wr = write(stream->fd, &stream->pos, buf, size * nmemb);
     474                wr = vfs_write(stream->fd, &stream->pos, buf, size * nmemb);
    475475                if (wr < 0) {
    476                         /* errno was set by write() */
     476                        errno = wr;
    477477                        stream->error = true;
    478478                        wr = 0;
     
    496496        stream->buf_head = stream->buf_tail = stream->buf;
    497497
    498         rc = read(stream->fd, &stream->pos, stream->buf, stream->buf_size);
     498        rc = vfs_read(stream->fd, &stream->pos, stream->buf, stream->buf_size);
    499499        if (rc < 0) {
    500                 /* errno was set by read() */
     500                errno = rc;
    501501                stream->error = true;
    502502                return;
  • uspace/lib/c/generic/vfs/vfs.c

    r163fc09 rce04ea44  
    395395 * return success with zero bytes read.
    396396 *
    397  * @param fildes File descriptor
     397 * @param file File descriptor
    398398 * @param pos Position to read from
    399399 * @param buf Buffer
     
    403403 * @return EOK on success, non-zero error code on error.
    404404 */
    405 static int _read_short(int fildes, aoff64_t pos, void *buf, size_t nbyte,
     405int vfs_read_short(int file, aoff64_t pos, void *buf, size_t nbyte,
    406406    ssize_t *nread)
    407407{
     
    415415        async_exch_t *exch = vfs_exchange_begin();
    416416       
    417         req = async_send_3(exch, VFS_IN_READ, fildes, LOWER32(pos),
     417        req = async_send_3(exch, VFS_IN_READ, file, LOWER32(pos),
    418418            UPPER32(pos), &answer);
    419419        rc = async_data_read_start(exch, (void *) buf, nbyte);
     
    438438 * may be lower, but greater than zero.
    439439 *
    440  * @param fildes File descriptor
     440 * @param file File descriptor
    441441 * @param pos Position to write to
    442442 * @param buf Buffer
     
    446446 * @return EOK on success, non-zero error code on error.
    447447 */
    448 static int _write_short(int fildes, aoff64_t pos, const void *buf, size_t nbyte,
     448int vfs_write_short(int file, aoff64_t pos, const void *buf, size_t nbyte,
    449449    ssize_t *nwritten)
    450450{
     
    458458        async_exch_t *exch = vfs_exchange_begin();
    459459       
    460         req = async_send_3(exch, VFS_IN_WRITE, fildes, LOWER32(pos),
     460        req = async_send_3(exch, VFS_IN_WRITE, file, LOWER32(pos),
    461461            UPPER32(pos), &answer);
    462462        rc = async_data_write_start(exch, (void *) buf, nbyte);
     
    486486 * @param nbytes        Number of bytes to read
    487487 *
    488  * @return              On success, nonnegative number of bytes read.
    489  *                      On failure, -1 and sets errno.
    490  */
    491 ssize_t read(int fildes, aoff64_t *pos, void *buf, size_t nbyte)
     488 * @return              On success, non-negative number of bytes red.
     489 *                      On failure, a negative error code.
     490 */
     491ssize_t vfs_read(int file, aoff64_t *pos, void *buf, size_t nbyte)
    492492{
    493493        ssize_t cnt = 0;
     
    500500                nread += cnt;
    501501                *pos += cnt;
    502                 rc = _read_short(fildes, *pos, bp, nbyte - nread, &cnt);
     502                rc = vfs_read_short(file, *pos, bp, nbyte - nread, &cnt);
    503503        } while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0);
    504504       
    505         if (rc != EOK) {
    506                 errno = rc;
    507                 return -1;
    508         }
     505        if (rc != EOK)
     506                return rc;
    509507       
    510508        *pos += cnt;
     
    516514 * This function fails if it cannot write exactly @a len bytes to the file.
    517515 *
    518  * @param fildes        File descriptor
     516 * @param fil        File descriptor
    519517 * @param pos           Pointer to position to write to
    520518 * @param buf           Data, @a nbytes bytes long
    521519 * @param nbytes        Number of bytes to write
    522520 *
    523  * @return              On success, nonnegative number of bytes written.
    524  *                      On failure, -1 and sets errno.
    525  */
    526 ssize_t write(int fildes, aoff64_t *pos, const void *buf, size_t nbyte)
     521 * @return              On success, non-negative number of bytes written.
     522 *                      On failure, a negative error code.
     523 */
     524ssize_t vfs_write(int file, aoff64_t *pos, const void *buf, size_t nbyte)
    527525{
    528526        ssize_t cnt = 0;
     
    535533                nwritten += cnt;
    536534                *pos += cnt;
    537                 rc = _write_short(fildes, *pos, bp, nbyte - nwritten, &cnt);
     535                rc = vfs_write_short(file, *pos, bp, nbyte - nwritten, &cnt);
    538536        } while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0);
    539537
    540         if (rc != EOK) {
    541                 errno = rc;
    542                 return -1;
    543         }
     538        if (rc != EOK)
     539                return rc;
    544540
    545541        *pos += cnt;
     
    681677        ssize_t len = 0;
    682678       
    683         rc = _read_short(dirp->fd, dirp->pos, &dirp->res.d_name[0],
     679        rc = vfs_read_short(dirp->fd, dirp->pos, &dirp->res.d_name[0],
    684680            NAME_MAX + 1, &len);
    685681        if (rc != EOK) {
  • uspace/lib/c/include/unistd.h

    r163fc09 rce04ea44  
    5858#define getpagesize()  (PAGE_SIZE)
    5959
    60 extern ssize_t write(int, aoff64_t *, const void *, size_t);
    61 extern ssize_t read(int, aoff64_t *, void *, size_t);
    62 
    6360extern char *getcwd(char *, size_t);
    6461extern int chdir(const char *);
  • uspace/lib/c/include/vfs/vfs.h

    r163fc09 rce04ea44  
    9696extern int vfs_open(int, int);
    9797extern int vfs_put(int);
     98extern int vfs_read_short(int, aoff64_t, void *, size_t, ssize_t *);
     99extern ssize_t vfs_read(int, aoff64_t *, void *, size_t);
    98100extern int vfs_rename_path(const char *, const char *);
    99101extern int vfs_resize(int, aoff64_t);
     
    110112extern int vfs_unmount_path(const char *);
    111113extern int vfs_walk(int, const char *, int);
    112 
     114extern int vfs_write_short(int, aoff64_t, const void *, size_t, ssize_t *);
     115extern ssize_t vfs_write(int, aoff64_t *, const void *, size_t);
    113116
    114117#endif
  • uspace/lib/pcut/src/os/helenos.c

    r163fc09 rce04ea44  
    215215
    216216        aoff64_t pos = 0;
    217         read(tempfile, &pos, extra_output_buffer, OUTPUT_BUFFER_SIZE);
     217        vfs_read(tempfile, &pos, extra_output_buffer, OUTPUT_BUFFER_SIZE);
    218218
    219219leave_close_tempfile:
  • uspace/lib/posix/source/stdio.c

    r163fc09 rce04ea44  
    344344{
    345345        const int fildes = *(int *) fd;
    346         ssize_t wr = write(fildes, &posix_pos[fildes], str, size);
     346        ssize_t wr = vfs_write(fildes, &posix_pos[fildes], str, size);
    347347        if (wr < 0)
    348                 return errno;
     348                return wr;
    349349        return str_nlength(str, wr);
    350350}
     
    372372               
    373373                const int fildes = *(int *) fd;
    374                 if (write(fildes, &posix_pos[fildes], buf, sz) != (ssize_t) sz)
     374                if (vfs_write(fildes, &posix_pos[fildes], buf, sz) < 0)
    375375                        break;
    376376               
  • uspace/lib/posix/source/unistd.c

    r163fc09 rce04ea44  
    196196ssize_t posix_read(int fildes, void *buf, size_t nbyte)
    197197{
    198         return negerrno(read, fildes, &posix_pos[fildes], buf, nbyte);
     198        ssize_t size = rcerrno(vfs_read, fildes, &posix_pos[fildes], buf, nbyte);
     199        if (size < 0)
     200                return -1;
     201        return size;
    199202}
    200203
     
    209212ssize_t posix_write(int fildes, const void *buf, size_t nbyte)
    210213{
    211         return negerrno(write, fildes, &posix_pos[fildes], buf, nbyte);
     214        ssize_t size = rcerrno(vfs_write, fildes, &posix_pos[fildes], buf, nbyte);
     215        if (size < 0)
     216                return -1;
     217        return size;
    212218}
    213219
  • uspace/srv/devman/match.c

    r163fc09 rce04ea44  
    229229        }
    230230       
    231         ssize_t read_bytes = read(fd, (aoff64_t []) {0}, buf, len);
     231        ssize_t read_bytes = vfs_read(fd, (aoff64_t []) {0}, buf, len);
    232232        if (read_bytes <= 0) {
    233233                log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%d).", conf_path,
Note: See TracChangeset for help on using the changeset viewer.