Changeset 58898d1d in mainline


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

Location:
uspace
Files:
33 edited

Legend:

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

    rc9e3692 r58898d1d  
    3131#include <stdlib.h>
    3232#include <unistd.h>
     33#include <sys/stat.h>
    3334#include <getopt.h>
    3435#include <str.h>
     
    187188        size_t offset = 0, copied_bytes = 0;
    188189        off64_t file_size = 0, length = 0;
     190        aoff64_t pos = 0;
    189191
    190192        bool reading_stdin = dash_represents_stdin && (str_cmp(fname, "-") == 0);
     
    205207                close(fd);
    206208                printf("Unable to allocate enough memory to read %s\n",
    207                         fname);
     209                    fname);
    208210                return 1;
    209211        }
    210212
    211213        if (tail != CAT_FULL_FILE) {
    212                 file_size = lseek(fd, 0, SEEK_END);
     214                struct stat st;
     215
     216                if (fstat(fd, &st) != EOK) {
     217                        close(fd);
     218                        free(buff);
     219                        printf("Unable to fstat %d\n", fd);
     220                        return 1;
     221                }
     222                file_size = st.size;
    213223                if (head == CAT_FULL_FILE) {
    214224                        head = file_size;
     
    223233
    224234                if (tail_first) {
    225                         lseek(fd, (tail >= file_size) ? 0 : (file_size - tail), SEEK_SET);
     235                        pos = (tail >= file_size) ? 0 : (file_size - tail);
    226236                } else {
    227                         lseek(fd, ((head - tail) >= file_size) ? 0 : (head - tail), SEEK_SET);
     237                        pos = ((head - tail) >= file_size) ? 0 : (head - tail);
    228238                }
    229239        } else
     
    243253                }
    244254               
    245                 bytes = read(fd, buff + copied_bytes, bytes_to_read);
     255                bytes = read(fd, &pos, buff + copied_bytes, bytes_to_read);
    246256                copied_bytes = 0;
    247257
  • uspace/app/bdsh/cmds/modules/cmp/cmp.c

    rc9e3692 r58898d1d  
    7979        char buffer[2][CMP_BUFLEN];
    8080        ssize_t offset[2];
     81        aoff64_t pos[2] = {};
    8182
    8283        for (int i = 0; i < 2; i++) {
     
    9495                        ssize_t size;
    9596                        do {
    96                                 size = read(fd[i], buffer[i] + offset[i],
     97                                size = read(fd[i], &pos[i],
     98                                    buffer[i] + offset[i],
    9799                                    CMP_BUFLEN - offset[i]);
    98100                                if (size < 0) {
  • uspace/app/bdsh/cmds/modules/cp/cp.c

    rc9e3692 r58898d1d  
    377377        int64_t copied = 0;
    378378        char *buff = NULL;
     379        aoff64_t posr = 0, posw = 0;
     380        struct stat st;
    379381
    380382        if (vb)
     
    392394        }
    393395
    394         total = lseek(fd1, 0, SEEK_END);
    395 
     396        if (fstat(fd1, &st) != EOK) {
     397                printf("Unable to fstat %d\n", fd1);
     398                close(fd1);
     399                close(fd2);
     400                return -1;     
     401        }
     402
     403        total = st.size;
    396404        if (vb)
    397405                printf("%" PRIu64 " bytes to copy\n", total);
    398 
    399         lseek(fd1, 0, SEEK_SET);
    400406
    401407        if (NULL == (buff = (char *) malloc(blen))) {
     
    406412        }
    407413
    408         while ((bytes = read(fd1, buff, blen)) > 0) {
    409                 if ((bytes = write(fd2, buff, bytes)) < 0)
     414        while ((bytes = read(fd1, &posr, buff, blen)) > 0) {
     415                if ((bytes = write(fd2, &posw, buff, bytes)) < 0)
    410416                        break;
    411417                copied += bytes;
  • uspace/app/bdsh/cmds/modules/mkfile/mkfile.c

    rc9e3692 r58898d1d  
    121121        void *buffer;
    122122        bool create_sparse = false;
     123        aoff64_t pos = 0;
    123124
    124125        file_size = 0;
     
    164165        if (create_sparse && file_size > 0) {
    165166                const char byte = 0x00;
    166 
    167                 if ((rc2 = lseek(fd, file_size - 1, SEEK_SET)) < 0) {
    168                         close(fd);
    169                         goto error;
    170                 }
    171 
    172                 rc2 = write(fd, &byte, sizeof(char));
     167               
     168                pos = file_size - 1;
     169                rc2 = write(fd, &pos, &byte, sizeof(char));
    173170                if (rc2 < 0) {
    174171                        close(fd);
     
    187184        while (total_written < file_size) {
    188185                to_write = min(file_size - total_written, BUFFER_SIZE);
    189                 rc = write(fd, buffer, to_write);
     186                rc = write(fd, &pos, buffer, to_write);
    190187                if (rc <= 0) {
    191188                        printf("%s: Error writing file (%d).\n", cmdname, errno);
  • uspace/app/sysinst/futil.c

    rc9e3692 r58898d1d  
    6060        ssize_t nr, nw;
    6161        int rc;
     62        aoff64_t posr = 0, posw = 0;
    6263
    6364        printf("Copy '%s' to '%s'.\n", srcp, destp);
     
    7273
    7374        do {
    74                 nr = read(sf, buf, BUF_SIZE);
     75                nr = read(sf, &posr, buf, BUF_SIZE);
    7576                if (nr == 0)
    7677                        break;
     
    7879                        return EIO;
    7980
    80                 nw = write(df, buf, nr);
     81                nw = write(df, &posw, buf, nr);
    8182                if (nw <= 0)
    8283                        return EIO;
     
    157158        int sf;
    158159        ssize_t nr;
    159         off64_t off;
    160160        size_t fsize;
    161161        char *data;
     162        struct stat st;
    162163
    163164        sf = open(srcp, O_RDONLY);
     
    165166                return ENOENT;
    166167
    167         off = lseek(sf, 0, SEEK_END);
    168         if (off == (off64_t)-1)
     168        if (fstat(sf, &st) != EOK) {
     169                close(sf);
    169170                return EIO;
     171        }       
    170172
    171         fsize = (size_t)off;
    172 
    173         off = lseek(sf, 0, SEEK_SET);
    174         if (off == (off64_t)-1)
    175                 return EIO;
     173        fsize = st.size;
    176174
    177175        data = calloc(fsize, 1);
    178         if (data == NULL)
     176        if (data == NULL) {
     177                close(sf);
    179178                return ENOMEM;
     179        }
    180180
    181         nr = read(sf, data, fsize);
    182         if (nr != (ssize_t)fsize)
     181        nr = read(sf, (aoff64_t []) { 0 }, data, fsize);
     182        if (nr != (ssize_t)fsize) {
     183                close(sf);
     184                free(data);
    183185                return EIO;
     186        }
    184187
    185188        (void) close(sf);
  • uspace/app/taskdump/elf_core.c

    rc9e3692 r58898d1d  
    6767
    6868static off64_t align_foff_up(off64_t, uintptr_t, size_t);
    69 static int align_pos(int, size_t);
    70 static int write_mem_area(int, as_area_info_t *, async_sess_t *);
     69static int write_mem_area(int, aoff64_t *, as_area_info_t *, async_sess_t *);
    7170
    7271#define BUFFER_SIZE 0x1000
     
    9796        elf_note_t note;
    9897        size_t word_size;
     98        aoff64_t pos = 0;
    9999
    100100        int fd;
     
    207207        }
    208208
    209         rc = write(fd, &elf_hdr, sizeof(elf_hdr));
     209        rc = 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, &p_hdr[i], sizeof(p_hdr[i]));
     217                rc = write(fd, &pos, &p_hdr[i], sizeof(p_hdr[i]));
    218218                if (rc != sizeof(p_hdr[i])) {
    219219                        printf("Failed writing program header.\n");
     
    223223        }
    224224
    225         if (lseek(fd, p_hdr[0].p_offset, SEEK_SET) == (off64_t) -1) {
    226                 printf("Failed writing memory data.\n");
    227                 free(p_hdr);
    228                 return EIO;
    229         }
     225        pos = p_hdr[0].p_offset;
    230226
    231227        /*
     
    236232        note.type = NT_PRSTATUS;
    237233
    238         rc = write(fd, &note, sizeof(elf_note_t));
     234        rc = write(fd, &pos, &note, sizeof(elf_note_t));
    239235        if (rc != sizeof(elf_note_t)) {
    240236                printf("Failed writing note header.\n");
     
    243239        }
    244240
    245         rc = write(fd, "CORE", note.namesz);
     241        rc = write(fd, &pos, "CORE", note.namesz);
    246242        if (rc != (ssize_t) note.namesz) {
    247243                printf("Failed writing note header.\n");
     
    250246        }
    251247
    252         rc = align_pos(fd, word_size);
    253         if (rc != EOK) {
    254                 printf("Failed writing note header.\n");
    255                 free(p_hdr);
    256                 return EIO;
    257         }
    258 
    259         rc = write(fd, &pr_status, sizeof(elf_prstatus_t));
     248        pos = ALIGN_UP(pos, word_size);
     249
     250        rc = write(fd, &pos, &pr_status, sizeof(elf_prstatus_t));
    260251        if (rc != sizeof(elf_prstatus_t)) {
    261252                printf("Failed writing register data.\n");
     
    265256
    266257        for (i = 1; i < n_ph; ++i) {
    267                 if (lseek(fd, p_hdr[i].p_offset, SEEK_SET) == (off64_t) -1) {
    268                         printf("Failed writing memory data.\n");
    269                         free(p_hdr);
    270                         return EIO;
    271                 }
    272                 if (write_mem_area(fd, &ainfo[i - 1], sess) != EOK) {
     258                pos = p_hdr[i].p_offset;
     259                if (write_mem_area(fd, &pos, &ainfo[i - 1], sess) != EOK) {
    273260                        printf("Failed writing memory data.\n");
    274261                        free(p_hdr);
     
    297284 *
    298285 * @param fd   File to write to.
     286 * @param pos  Pointer to the position to write to.
    299287 * @param area Memory area info structure.
    300288 * @param sess Debugging session.
     
    303291 *
    304292 */
    305 static int write_mem_area(int fd, as_area_info_t *area, async_sess_t *sess)
     293static int write_mem_area(int fd, aoff64_t *pos, as_area_info_t *area,
     294    async_sess_t *sess)
    306295{
    307296        size_t to_copy;
     
    321310                }
    322311
    323                 rc = write(fd, buffer, to_copy);
     312                rc = write(fd, pos, buffer, to_copy);
    324313                if (rc != (ssize_t) to_copy) {
    325314                        printf("Failed writing memory contents.\n");
     
    334323}
    335324
    336 static int align_pos(int fd, size_t align)
    337 {
    338         off64_t cur_pos;
    339         size_t rem, adv;
    340 
    341         cur_pos = lseek(fd, 0, SEEK_CUR);
    342         if (cur_pos < 0)
    343                 return -1;
    344 
    345         rem = cur_pos % align;
    346         adv = align - rem;
    347 
    348         cur_pos = lseek(fd, adv, SEEK_CUR);
    349         if (cur_pos < 0)
    350                 return -1;
    351 
    352         return EOK;
    353 }
    354 
    355325/** @}
    356326 */
  • uspace/app/taskdump/symtab.c

    rc9e3692 r58898d1d  
    6868        char *shstrt, *sec_name;
    6969        void *data;
     70        aoff64_t pos = 0;
    7071
    7172        int fd;
     
    8889        }
    8990
    90         rc = read(fd, &elf_hdr, sizeof(elf_header_t));
     91        rc = read(fd, &pos, &elf_hdr, sizeof(elf_header_t));
    9192        if (rc != sizeof(elf_header_t)) {
    9293                printf("failed reading elf header\n");
     
    304305{
    305306        int rc;
    306 
    307         rc = lseek(fd, elf_hdr->e_shoff + idx * sizeof(elf_section_header_t),
    308             SEEK_SET);
    309         if (rc == (off64_t) -1)
    310                 return EIO;
    311 
    312         rc = read(fd, sec_hdr, sizeof(elf_section_header_t));
     307        aoff64_t pos = elf_hdr->e_shoff + idx * sizeof(elf_section_header_t);
     308
     309        rc = read(fd, &pos, sec_hdr, sizeof(elf_section_header_t));
    313310        if (rc != sizeof(elf_section_header_t))
    314311                return EIO;
     
    331328{
    332329        ssize_t rc;
    333         off64_t offs;
    334 
    335         offs = lseek(fd, start, SEEK_SET);
    336         if (offs == (off64_t) -1) {
    337                 printf("failed seeking chunk\n");
    338                 *ptr = NULL;
    339                 return EIO;
    340         }
     330        aoff64_t pos = start;
    341331
    342332        *ptr = malloc(size);
     
    346336        }
    347337
    348         rc = read(fd, *ptr, size);
     338        rc = read(fd, &pos, *ptr, size);
    349339        if (rc != (ssize_t) size) {
    350340                printf("failed reading chunk\n");
  • uspace/app/tester/mm/pager1.c

    rc9e3692 r58898d1d  
    5252                return NULL;
    5353        (void) unlink(TEST_FILE);
    54         if (write(fd, text, sizeof(text)) != sizeof(text)) {
     54
     55        if (write(fd, (aoff64_t []) {0}, text, sizeof(text)) != sizeof(text)) {
    5556                close(fd);
    5657                return NULL;
  • uspace/app/tester/vfs/vfs1.c

    rc9e3692 r58898d1d  
    7070const char *test_vfs1(void)
    7171{
     72        aoff64_t pos = 0;
     73
    7274        if (mkdir(TEST_DIRECTORY, 0) != 0) {
    7375                TPRINTF("rc=%d\n", errno);
     
    8284       
    8385        size_t size = sizeof(text);
    84         ssize_t cnt = write(fd0, text, size);
     86        ssize_t cnt = write(fd0, &pos, text, size);
    8587        if (cnt < 0)
    8688                return "write() failed";
    8789        TPRINTF("Written %zd bytes\n", cnt);
    88        
    89         if (lseek(fd0, 0, SEEK_SET) != 0)
    90                 return "lseek() failed";
    91         TPRINTF("Sought to position 0\n");
     90
     91        pos = 0;
    9292       
    9393        char buf[BUF_SIZE];
    9494        TPRINTF("read..\n");
    95         while ((cnt = read(fd0, buf, BUF_SIZE))) {
     95        while ((cnt = read(fd0, &pos, buf, BUF_SIZE))) {
    9696                TPRINTF("read returns %zd\n", cnt);
    9797                if (cnt < 0)
  • uspace/app/trace/trace.c

    rc9e3692 r58898d1d  
    701701
    702702        p = proto_new("vfs");
    703         o = oper_new("read", 1, arg_def, V_ERRNO, 1, resp_def);
     703        o = oper_new("read", 3, arg_def, V_ERRNO, 1, resp_def);
    704704        proto_add_oper(p, VFS_IN_READ, o);
    705         o = oper_new("write", 1, arg_def, V_ERRNO, 1, resp_def);
     705        o = oper_new("write", 3, arg_def, V_ERRNO, 1, resp_def);
    706706        proto_add_oper(p, VFS_IN_WRITE, o);
    707         o = oper_new("seek", 3, arg_def, V_ERRNO, 0, resp_def);
    708         proto_add_oper(p, VFS_IN_SEEK, o);
    709707        o = oper_new("truncate", 5, arg_def, V_ERRNO, 0, resp_def);
    710708        proto_add_oper(p, VFS_IN_TRUNCATE, o);
  • uspace/app/viewer/viewer.c

    rc9e3692 r58898d1d  
    126126                return false;
    127127        }
    128        
    129         ssize_t rd = read(fd, tga, stat.size);
     128
     129        ssize_t rd = read(fd, (aoff64_t []) {0}, tga, stat.size);
    130130        if ((rd < 0) || (rd != (ssize_t) stat.size)) {
    131131                free(tga);
  • uspace/app/websrv/websrv.c

    rc9e3692 r58898d1d  
    238238                return rc;
    239239       
     240        aoff64_t pos = 0;
    240241        while (true) {
    241                 ssize_t nr = read(fd, fbuf, BUFFER_SIZE);
     242                ssize_t nr = read(fd, &pos, fbuf, BUFFER_SIZE);
    242243                if (nr == 0)
    243244                        break;
  • uspace/drv/bus/isa/isa.c

    rc9e3692 r58898d1d  
    254254        size_t len;
    255255        ssize_t r;
     256        struct stat st;
    256257
    257258        fd = open(conf_path, O_RDONLY);
     
    263264        opened = true;
    264265
    265         len = lseek(fd, 0, SEEK_END);
    266         lseek(fd, 0, SEEK_SET);
     266        if (fstat(fd, &st) != EOK) {
     267                ddf_msg(LVL_ERROR, "Unable to fstat %d", fd);
     268                goto cleanup;
     269        }
     270
     271        len = st.size;
    267272        if (len == 0) {
    268273                ddf_msg(LVL_ERROR, "Configuration file '%s' is empty.",
     
    277282        }
    278283
    279         r = read(fd, buf, len);
     284        r = read(fd, (aoff64_t []) {0}, buf, len);
    280285        if (r < 0) {
    281286                ddf_msg(LVL_ERROR, "Unable to read file '%s'.", conf_path);
  • uspace/lib/bithenge/src/file.c

    rc9e3692 r58898d1d  
    7878        if (offset > blob->size)
    7979                return ELIMIT;
    80         if (lseek(blob->fd, offset, SEEK_SET) < 0)
    81                 return errno == EINVAL ? EIO : errno;
    8280
    83         ssize_t amount_read;
    84         aoff64_t remaining_size = *size;
    85         *size = 0;
    86         do {
    87                 amount_read = read(blob->fd, buffer, remaining_size);
    88                 if (amount_read < 0)
    89                         return errno;
    90                 buffer += amount_read;
    91                 *size += amount_read;
    92                 remaining_size -= amount_read;
    93         } while (remaining_size && amount_read);
     81        ssize_t amount_read = read(blob->fd, &offset, buffer, *size);
     82        if (amount_read < 0)
     83                return errno;
     84        *size += amount_read;
    9485        return EOK;
    9586}
  • uspace/lib/c/generic/elf/elf_mod.c

    rc9e3692 r58898d1d  
    135135        elf_header_t header_buf;
    136136        elf_header_t *header = &header_buf;
     137        aoff64_t pos = 0;
    137138        int i, rc;
    138139
    139         rc = read(elf->fd, header, sizeof(elf_header_t));
     140        rc = read(elf->fd, &pos, header, sizeof(elf_header_t));
    140141        if (rc != sizeof(elf_header_t)) {
    141142                DPRINTF("Read error.\n");
     
    195196                elf_segment_header_t segment_hdr;
    196197
    197                 /* Seek to start of segment header */
    198                 lseek(elf->fd, header->e_phoff
    199                         + i * sizeof(elf_segment_header_t), SEEK_SET);
    200 
    201                 rc = read(elf->fd, &segment_hdr,
     198                pos = header->e_phoff + i * sizeof(elf_segment_header_t);
     199                rc = read(elf->fd, &pos, &segment_hdr,
    202200                    sizeof(elf_segment_header_t));
    203201                if (rc != sizeof(elf_segment_header_t)) {
     
    217215                elf_section_header_t section_hdr;
    218216
    219                 /* Seek to start of section header */
    220                 lseek(elf->fd, header->e_shoff
    221                     + i * sizeof(elf_section_header_t), SEEK_SET);
    222 
    223                 rc = read(elf->fd, &section_hdr,
     217                pos = header->e_shoff + i * sizeof(elf_section_header_t);
     218                rc = read(elf->fd, &pos, &section_hdr,
    224219                    sizeof(elf_section_header_t));
    225220                if (rc != sizeof(elf_section_header_t)) {
     
    333328        uintptr_t seg_addr;
    334329        size_t mem_sz;
     330        aoff64_t pos;
    335331        ssize_t rc;
    336332
     
    390386         * Load segment data
    391387         */
    392         rc = lseek(elf->fd, entry->p_offset, SEEK_SET);
    393         if (rc < 0) {
    394                 printf("seek error\n");
    395                 return EE_INVALID;
    396         }
    397 
    398         rc = read(elf->fd, seg_ptr, entry->p_filesz);
     388        pos = entry->p_offset;
     389        rc = read(elf->fd, &pos, seg_ptr, entry->p_filesz);
    399390        if (rc < 0) {
    400391                DPRINTF("read error\n");
  • uspace/lib/c/generic/io/io.c

    rc9e3692 r58898d1d  
    4141#include <stdbool.h>
    4242#include <malloc.h>
     43#include <sys/stat.h>
    4344#include <async.h>
    4445#include <io/kio.h>
     
    5657static FILE stdin_null = {
    5758        .fd = -1,
     59        .pos = 0,
    5860        .error = true,
    5961        .eof = true,
     
    7072static FILE stdout_kio = {
    7173        .fd = -1,
     74        .pos = 0,
    7275        .error = false,
    7376        .eof = false,
     
    8487static FILE stderr_kio = {
    8588        .fd = -1,
     89        .pos = 0,
    8690        .error = false,
    8791        .eof = false,
     
    288292        }
    289293       
     294        stream->pos = 0;
    290295        stream->error = false;
    291296        stream->eof = false;
     
    311316       
    312317        stream->fd = fd;
     318        stream->pos = 0;
    313319        stream->error = false;
    314320        stream->eof = false;
     
    396402static size_t _fread(void *buf, size_t size, size_t nmemb, FILE *stream)
    397403{
    398         size_t left, done;
    399 
    400404        if (size == 0 || nmemb == 0)
    401405                return 0;
    402406
    403         left = size * nmemb;
    404         done = 0;
    405        
    406         while ((left > 0) && (!stream->error) && (!stream->eof)) {
    407                 ssize_t rd = read(stream->fd, buf + done, left);
    408                
    409                 if (rd < 0) {
    410                         /* errno was set by read() */
    411                         stream->error = true;
    412                 } else if (rd == 0) {
    413                         stream->eof = true;
    414                 } else {
    415                         left -= rd;
    416                         done += rd;
    417                 }
    418         }
    419        
    420         return (done / size);
     407        ssize_t rd = read(stream->fd, &stream->pos, buf, size * nmemb);
     408        if (rd < 0) {
     409                /* errno was set by read() */
     410                stream->error = true;
     411                rd = 0;
     412        } else if (rd == 0) {
     413                stream->eof = true;
     414        }
     415       
     416        return (rd / size);
    421417}
    422418
     
    433429static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
    434430{
    435         size_t left;
    436         size_t done;
    437         int rc;
    438 
    439431        if (size == 0 || nmemb == 0)
    440432                return 0;
    441433
    442         left = size * nmemb;
    443         done = 0;
    444 
    445         while ((left > 0) && (!stream->error)) {
    446                 ssize_t wr;
    447                 size_t uwr;
    448                
    449                 if (stream->kio) {
    450                         uwr = 0;
    451                         rc = kio_write(buf + done, left, &uwr);
    452                         if (rc != EOK)
    453                                 errno = rc;
     434        ssize_t wr;
     435        if (stream->kio) {
     436                size_t nwritten;
     437                wr = kio_write(buf, size * nmemb, &nwritten);
     438                if (wr != EOK) {
     439                        stream->error = true;
     440                        wr = 0;
    454441                } else {
    455                         wr = write(stream->fd, buf + done, left);
    456                         if (wr >= 0) {
    457                                 uwr = (size_t)wr;
    458                                 rc = EOK;
    459                         } else {
    460                                 /* errno was set by write */
    461                                 uwr = 0;
    462                                 rc = errno;
    463                         }
    464                 }
    465                
    466                 if (rc != EOK) {
    467                         /* errno was set above */
     442                        wr = nwritten;
     443                }
     444        } else {
     445                wr = write(stream->fd, &stream->pos, buf, size * nmemb);
     446                if (wr < 0) {
     447                        /* errno was set by write() */
    468448                        stream->error = true;
    469                 } else {
    470                         left -= uwr;
    471                         done += uwr;
    472                 }
    473         }
    474 
    475         if (done > 0)
     449                        wr = 0;
     450                }
     451        }
     452
     453        if (wr > 0)
    476454                stream->need_sync = true;
    477455       
    478         return (done / size);
     456        return (wr / size);
    479457}
    480458
     
    489467        stream->buf_head = stream->buf_tail = stream->buf;
    490468
    491         rc = read(stream->fd, stream->buf, stream->buf_size);
     469        rc = read(stream->fd, &stream->pos, stream->buf, stream->buf_size);
    492470        if (rc < 0) {
    493471                /* errno was set by read() */
     
    516494
    517495        /* If buffer has prefetched read data, we need to seek back. */
    518         if (bytes_used > 0 && stream->buf_state == _bs_read) {
    519                 off64_t rc;
    520                 rc = lseek(stream->fd, - (ssize_t) bytes_used, SEEK_CUR);
    521                 if (rc == (off64_t)-1) {
    522                         /* errno was set by lseek */
    523                         stream->error = 1;
    524                         return;
    525                 }
    526         }
     496        if (bytes_used > 0 && stream->buf_state == _bs_read)
     497                stream->pos -= bytes_used;
    527498
    528499        /* If buffer has unwritten data, we need to write them out. */
     
    796767int fseek(FILE *stream, off64_t offset, int whence)
    797768{
    798         off64_t rc;
    799 
    800769        if (stream->error)
    801                 return EOF;
     770                return -1;
    802771
    803772        _fflushbuf(stream);
    804773        if (stream->error) {
    805774                /* errno was set by _fflushbuf() */
    806                 return EOF;
     775                return -1;
    807776        }
    808777
    809778        stream->ungetc_chars = 0;
    810779
    811         rc = lseek(stream->fd, offset, whence);
    812         if (rc == (off64_t) (-1)) {
    813                 /* errno has been set by lseek() */
    814                 return EOF;
     780        struct stat st;
     781        switch (whence) {
     782        case SEEK_SET:
     783                stream->pos = offset;
     784                break;
     785        case SEEK_CUR:
     786                stream->pos += offset;
     787                break;
     788        case SEEK_END:
     789                if (fstat(stream->fd, &st) != EOK) {
     790                        /* errno was set by fstat() */
     791                        stream->error = true;
     792                        return -1;     
     793                }
     794                stream->pos = st.size + offset;
     795                break;
    815796        }
    816797
     
    821802off64_t ftell(FILE *stream)
    822803{
    823         off64_t pos;
    824        
    825804        if (stream->error)
    826805                return EOF;
     
    832811        }
    833812
    834         pos = lseek(stream->fd, 0, SEEK_CUR);
    835         if (pos == (off64_t) -1) {
    836                 /* errno was set by lseek */
    837                 return (off64_t) -1;
    838         }
    839        
    840         return pos - stream->ungetc_chars;
     813        return stream->pos - stream->ungetc_chars;
    841814}
    842815
  • uspace/lib/c/generic/private/stdio.h

    rc9e3692 r58898d1d  
    4949        /** Underlying file descriptor. */
    5050        int fd;
     51
     52        /** File position. */
     53        aoff64_t pos;
    5154       
    5255        /** Error indicator. */
  • 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
  • uspace/lib/c/include/dirent.h

    rc9e3692 r58898d1d  
    3838#define NAME_MAX  256
    3939
     40#include <sys/types.h>
     41
    4042struct dirent {
    4143        char d_name[NAME_MAX + 1];
     
    4547        int fd;
    4648        struct dirent res;
     49        aoff64_t pos;
    4750} DIR;
    4851
  • uspace/lib/c/include/ipc/vfs.h

    rc9e3692 r58898d1d  
    6565        VFS_IN_READ = IPC_FIRST_USER_METHOD,
    6666        VFS_IN_WRITE,
    67         VFS_IN_SEEK,
    6867        VFS_IN_TRUNCATE,
    6968        VFS_IN_FSTAT,
  • uspace/lib/c/include/stdio.h

    rc9e3692 r58898d1d  
    5454                        (void) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) _buf, str_size(_buf)); \
    5555        }
    56 
    57 #ifndef SEEK_SET
    58         #define SEEK_SET  0
    59 #endif
    60 
    61 #ifndef SEEK_CUR
    62         #define SEEK_CUR  1
    63 #endif
    64 
    65 #ifndef SEEK_END
    66         #define SEEK_END  2
    67 #endif
    6856
    6957enum _buffer_type {
  • uspace/lib/c/include/unistd.h

    rc9e3692 r58898d1d  
    6060extern int dup2(int, int);
    6161
    62 extern ssize_t write(int, const void *, size_t);
    63 extern ssize_t read(int, void *, size_t);
     62extern ssize_t write(int, aoff64_t *, const void *, size_t);
     63extern ssize_t read(int, aoff64_t *, void *, size_t);
    6464
    65 extern off64_t lseek(int, off64_t, int);
    6665extern int ftruncate(int, aoff64_t);
    6766
  • uspace/lib/c/include/vfs/vfs.h

    rc9e3692 r58898d1d  
    4343#include <async.h>
    4444
     45#define MAX_OPEN_FILES  128
     46
    4547enum vfs_change_state_type {
    4648        VFS_PASS_HANDLE
  • uspace/lib/pcut/src/os/helenos.c

    rc9e3692 r58898d1d  
    214214        fibril_mutex_unlock(&forced_termination_mutex);
    215215
    216         read(tempfile, extra_output_buffer, OUTPUT_BUFFER_SIZE);
     216        aoff64_t pos = 0;
     217        read(tempfile, &pos, extra_output_buffer, OUTPUT_BUFFER_SIZE);
    217218
    218219leave_close_tempfile:
  • uspace/lib/posix/source/internal/common.h

    rc9e3692 r58898d1d  
    3838#include <stdio.h>
    3939#include <stdlib.h>
     40#include <sys/types.h>
     41#include <vfs/vfs.h>
    4042
    4143#define not_implemented() do { \
     
    5759})
    5860
     61extern aoff64_t posix_pos[MAX_OPEN_FILES];
     62
    5963#endif /* LIBPOSIX_COMMON_H_ */
    6064
  • uspace/lib/posix/source/stdio.c

    rc9e3692 r58898d1d  
    344344static int _dprintf_str_write(const char *str, size_t size, void *fd)
    345345{
    346         ssize_t wr = write(*(int *) fd, str, size);
     346        const int fildes = *(int *) fd;
     347        ssize_t wr = write(fildes, &posix_pos[fildes], str, size);
    347348        if (wr < 0)
    348349                return errno;
     
    371372                }
    372373               
    373                 if (write(*(int *) fd, buf, sz) != (ssize_t) sz) {
     374                const int fildes = *(int *) fd;
     375                if (write(fildes, &posix_pos[fildes], buf, sz) != (ssize_t) sz)
    374376                        break;
    375                 }
    376377               
    377378                chars++;
  • uspace/lib/posix/source/unistd.c

    rc9e3692 r58898d1d  
    4747#include "libc/stats.h"
    4848#include "libc/malloc.h"
     49#include "libc/vfs/vfs.h"
     50#include "libc/sys/stat.h"
     51
     52aoff64_t posix_pos[MAX_OPEN_FILES];
    4953
    5054/* Array of environment variable strings (NAME=VALUE). */
     
    175179int posix_close(int fildes)
    176180{
     181        posix_pos[fildes] = 0;
    177182        return negerrno(close, fildes);
    178183}
     
    188193ssize_t posix_read(int fildes, void *buf, size_t nbyte)
    189194{
    190         return negerrno(read, fildes, buf, nbyte);
     195        return negerrno(read, fildes, &posix_pos[fildes], buf, nbyte);
    191196}
    192197
     
    201206ssize_t posix_write(int fildes, const void *buf, size_t nbyte)
    202207{
    203         return negerrno(write, fildes, buf, nbyte);
     208        return negerrno(write, fildes, &posix_pos[fildes], buf, nbyte);
    204209}
    205210
     
    215220posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence)
    216221{
    217         return negerrno(lseek, fildes, offset, whence);
     222        struct stat st;
     223
     224        switch (whence) {
     225        case SEEK_SET:
     226                posix_pos[fildes] = offset;
     227                break;
     228        case SEEK_CUR:
     229                posix_pos[fildes] += offset;
     230                break;
     231        case SEEK_END:
     232                if (fstat(fildes, &st) != EOK) {
     233                        errno = -errno;
     234                        return -1;
     235                }
     236                posix_pos[fildes] = st.size + offset;
     237                break;
     238        }
     239        return posix_pos[fildes];
    218240}
    219241
  • uspace/srv/devman/match.c

    rc9e3692 r58898d1d  
    201201        int fd;
    202202        size_t len = 0;
     203        struct stat st;
    203204       
    204205        fd = open(conf_path, O_RDONLY);
     
    210211        opened = true;
    211212       
    212         len = lseek(fd, 0, SEEK_END);
    213         lseek(fd, 0, SEEK_SET);
     213        if (fstat(fd, &st) != EOK) {
     214                log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to fstat %d: %s.", fd,
     215                    str_error(errno));
     216                goto cleanup;
     217        }
     218        len = st.size;
    214219        if (len == 0) {
    215220                log_msg(LOG_DEFAULT, LVL_ERROR, "Configuration file '%s' is empty.",
     
    225230        }
    226231       
    227         ssize_t read_bytes = read(fd, buf, len);
     232        ssize_t read_bytes = read(fd, (aoff64_t []) {0}, buf, len);
    228233        if (read_bytes <= 0) {
    229234                log_msg(LOG_DEFAULT, LVL_ERROR, "Unable to read file '%s' (%d).", conf_path,
  • uspace/srv/vfs/vfs.h

    rc9e3692 r58898d1d  
    142142        /** Append on write. */
    143143        bool append;
    144 
    145         /** Current absolute position in the file. */
    146         int64_t pos;
    147144} vfs_file_t;
    148145
     
    190187extern int64_t vfs_node_get_size(vfs_node_t *node);
    191188extern bool vfs_node_has_children(vfs_node_t *node);
    192 
    193 #define MAX_OPEN_FILES  128
    194189
    195190extern void *vfs_client_data_create(void);
     
    216211extern int vfs_op_mtab_get(void);
    217212extern int vfs_op_open2(int fd, int flags);
    218 extern int vfs_op_read(int fd, size_t *out_bytes);
     213extern int vfs_op_read(int fd, aoff64_t, size_t *out_bytes);
    219214extern int vfs_op_rename(int basefd, char *old, char *new);
    220 extern int vfs_op_seek(int fd, int64_t offset, int whence, int64_t *out_offset);
    221215extern int vfs_op_statfs(int fd);
    222216extern int vfs_op_sync(int fd);
     
    226220extern int vfs_op_wait_handle(bool high_fd);
    227221extern int vfs_op_walk(int parentfd, int flags, char *path, int *out_fd);
    228 extern int vfs_op_write(int fd, size_t *out_bytes);
     222extern int vfs_op_write(int fd, aoff64_t, size_t *out_bytes);
    229223
    230224extern void vfs_register(ipc_callid_t, ipc_call_t *);
     
    237231} rdwr_io_chunk_t;
    238232
    239 extern int vfs_rdwr_internal(int, bool, rdwr_io_chunk_t *);
     233extern int vfs_rdwr_internal(int, aoff64_t, bool, rdwr_io_chunk_t *);
    240234
    241235extern void vfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg);
  • uspace/srv/vfs/vfs_file.c

    rc9e3692 r58898d1d  
    4545#include <adt/list.h>
    4646#include <task.h>
     47#include <vfs/vfs.h>
    4748#include "vfs.h"
    4849
  • uspace/srv/vfs/vfs_ipc.c

    rc9e3692 r58898d1d  
    122122{
    123123        int fd = IPC_GET_ARG1(*request);
     124        aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request),
     125            IPC_GET_ARG3(*request));
    124126
    125127        size_t bytes = 0;
    126         int rc = vfs_op_read(fd, &bytes);
     128        int rc = vfs_op_read(fd, pos, &bytes);
    127129        async_answer_1(rid, rc, bytes);
    128130}
     
    170172        if (new)
    171173                free(new);
    172 }
    173 
    174 static void vfs_in_seek(ipc_callid_t rid, ipc_call_t *request)
    175 {
    176         int fd = (int) IPC_GET_ARG1(*request);
    177         int64_t off = (int64_t) MERGE_LOUP32(IPC_GET_ARG2(*request), IPC_GET_ARG3(*request));
    178         int whence = (int) IPC_GET_ARG4(*request);
    179 
    180         int64_t new_offset = 0;
    181         int rc = vfs_op_seek(fd, off, whence, &new_offset);
    182         async_answer_2(rid, rc, LOWER32(new_offset), UPPER32(new_offset));
    183174}
    184175
     
    256247{
    257248        int fd = IPC_GET_ARG1(*request);
     249        aoff64_t pos = MERGE_LOUP32(IPC_GET_ARG2(*request),
     250            IPC_GET_ARG3(*request));
    258251
    259252        size_t bytes = 0;
    260         int rc = vfs_op_write(fd, &bytes);
     253        int rc = vfs_op_write(fd, pos, &bytes);
    261254        async_answer_1(rid, rc, bytes);
    262255}
     
    308301                        vfs_in_rename(callid, &call);
    309302                        break;
    310                 case VFS_IN_SEEK:
    311                         vfs_in_seek(callid, &call);
    312                         break;
    313303                case VFS_IN_STATFS:
    314304                        vfs_in_statfs(callid, &call);
  • uspace/srv/vfs/vfs_ops.c

    rc9e3692 r58898d1d  
    343343}
    344344
    345 typedef int (* rdwr_ipc_cb_t)(async_exch_t *, vfs_file_t *, ipc_call_t *,
    346     bool, void *);
    347 
    348 static int rdwr_ipc_client(async_exch_t *exch, vfs_file_t *file,
     345typedef int (* rdwr_ipc_cb_t)(async_exch_t *, vfs_file_t *, aoff64_t,
     346    ipc_call_t *, bool, void *);
     347
     348static int rdwr_ipc_client(async_exch_t *exch, vfs_file_t *file, aoff64_t pos,
    349349    ipc_call_t *answer, bool read, void *data)
    350350{
     
    363363                rc = async_data_read_forward_4_1(exch, VFS_OUT_READ,
    364364                    file->node->service_id, file->node->index,
    365                     LOWER32(file->pos), UPPER32(file->pos), answer);
     365                    LOWER32(pos), UPPER32(pos), answer);
    366366        } else {
    367367                rc = async_data_write_forward_4_1(exch, VFS_OUT_WRITE,
    368368                    file->node->service_id, file->node->index,
    369                     LOWER32(file->pos), UPPER32(file->pos), answer);
     369                    LOWER32(pos), UPPER32(pos), answer);
    370370        }
    371371
     
    374374}
    375375
    376 static int rdwr_ipc_internal(async_exch_t *exch, vfs_file_t *file,
     376static int rdwr_ipc_internal(async_exch_t *exch, vfs_file_t *file, aoff64_t pos,
    377377    ipc_call_t *answer, bool read, void *data)
    378378{
     
    383383       
    384384        aid_t msg = async_send_fast(exch, read ? VFS_OUT_READ : VFS_OUT_WRITE,
    385             file->node->service_id, file->node->index, LOWER32(file->pos),
    386             UPPER32(file->pos), answer);
     385            file->node->service_id, file->node->index, LOWER32(pos),
     386            UPPER32(pos), answer);
    387387        if (msg == 0)
    388388                return EINVAL;
     
    402402}
    403403
    404 static int vfs_rdwr(int fd, bool read, rdwr_ipc_cb_t ipc_cb, void *ipc_cb_data)
     404static int vfs_rdwr(int fd, aoff64_t pos, bool read, rdwr_ipc_cb_t ipc_cb,
     405    void *ipc_cb_data)
    405406{
    406407        /*
     
    463464        async_exch_t *fs_exch = vfs_exchange_grab(file->node->fs_handle);
    464465       
    465         if (!read && file->append)
    466                 file->pos = file->node->size;
     466        if (!read && file->append) {
     467                if (file->node->size == -1)
     468                        file->node->size = vfs_node_get_size(file->node);
     469                pos = file->node->size;
     470        }
    467471       
    468472        /*
     
    470474         */
    471475        ipc_call_t answer;
    472         int rc = ipc_cb(fs_exch, file, &answer, read, ipc_cb_data);
     476        int rc = ipc_cb(fs_exch, file, pos, &answer, read, ipc_cb_data);
    473477       
    474478        vfs_exchange_release(fs_exch);
    475        
    476         size_t bytes = IPC_GET_ARG1(answer);
    477479       
    478480        if (file->node->type == VFS_NODE_DIRECTORY)
     
    491493        }
    492494       
    493         /* Update the position pointer and unlock the open file. */
    494         if (rc == EOK)
    495                 file->pos += bytes;
    496495        vfs_file_put(file);     
    497496
     
    499498}
    500499
    501 int vfs_rdwr_internal(int fd, bool read, rdwr_io_chunk_t *chunk)
    502 {
    503         return vfs_rdwr(fd, read, rdwr_ipc_internal, chunk);
    504 }
    505 
    506 int vfs_op_read(int fd, size_t *out_bytes)
    507 {
    508         return vfs_rdwr(fd, true, rdwr_ipc_client, out_bytes);
     500int vfs_rdwr_internal(int fd, aoff64_t pos, bool read, rdwr_io_chunk_t *chunk)
     501{
     502        return vfs_rdwr(fd, pos, read, rdwr_ipc_internal, chunk);
     503}
     504
     505int vfs_op_read(int fd, aoff64_t pos, size_t *out_bytes)
     506{
     507        return vfs_rdwr(fd, pos, true, rdwr_ipc_client, out_bytes);
    509508}
    510509
     
    608607        fibril_rwlock_write_unlock(&namespace_rwlock);
    609608        return EOK;
    610 }
    611 
    612 int vfs_op_seek(int fd, int64_t offset, int whence, int64_t *out_offset)
    613 {
    614         vfs_file_t *file = vfs_file_get(fd);
    615         if (!file)
    616                 return EBADF;
    617        
    618         switch (whence) {
    619         case SEEK_SET:
    620                 if (offset < 0) {
    621                         vfs_file_put(file);
    622                         return EINVAL;
    623                 }
    624                 file->pos = offset;
    625                 *out_offset = offset;
    626                 vfs_file_put(file);
    627                 return EOK;
    628         case SEEK_CUR:
    629                 if (offset > 0 && file->pos > (INT64_MAX - offset)) {
    630                         vfs_file_put(file);
    631                         return EOVERFLOW;
    632                 }
    633                
    634                 if (offset < 0 && -file->pos > offset) {
    635                         vfs_file_put(file);
    636                         return EOVERFLOW;
    637                 }
    638                
    639                 file->pos += offset;
    640                 *out_offset = file->pos;
    641                 vfs_file_put(file);
    642                 return EOK;
    643         case SEEK_END:
    644                 fibril_rwlock_read_lock(&file->node->contents_rwlock);
    645                 int64_t size = vfs_node_get_size(file->node);
    646                 fibril_rwlock_read_unlock(&file->node->contents_rwlock);
    647                
    648                 if (offset > 0 && size > (INT64_MAX - offset)) {
    649                         vfs_file_put(file);
    650                         return EOVERFLOW;
    651                 }
    652                
    653                 if (offset < 0 && -size > offset) {
    654                         vfs_file_put(file);
    655                         return EOVERFLOW;
    656                 }
    657                
    658                 file->pos = size + offset;
    659                 *out_offset = file->pos;
    660                 vfs_file_put(file);
    661                 return EOK;
    662         }
    663        
    664         vfs_file_put(file);
    665         return EINVAL;
    666609}
    667610
     
    953896}
    954897
    955 int vfs_op_write(int fd, size_t *out_bytes)
    956 {
    957         return vfs_rdwr(fd, false, rdwr_ipc_client, out_bytes);
     898int vfs_op_write(int fd, aoff64_t pos, size_t *out_bytes)
     899{
     900        return vfs_rdwr(fd, pos, false, rdwr_ipc_client, out_bytes);
    958901}
    959902
  • uspace/srv/vfs/vfs_pager.c

    rc9e3692 r58898d1d  
    5050        int rc;
    5151
    52         vfs_file_t *file = vfs_file_get(fd);
    53         if (!file) {
    54                 async_answer_0(rid, ENOENT);
    55                 return;
    56         }
    57 
    5852        page = as_area_create(AS_AREA_ANY, page_size,
    5953            AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE,
     
    6155
    6256        if (page == AS_MAP_FAILED) {
    63                 vfs_file_put(file);
    6457                async_answer_0(rid, ENOMEM);
    6558                return;
     
    7164        };
    7265
    73         file->pos = offset;
    74         vfs_file_put(file);
    75 
    7666        size_t total = 0;
     67        aoff64_t pos = offset;
    7768        do {
    78                 rc = vfs_rdwr_internal(fd, true, &chunk);
     69                rc = vfs_rdwr_internal(fd, pos, true, &chunk);
    7970                if (rc != EOK)
    8071                        break;
     
    8273                        break;
    8374                total += chunk.size;
     75                pos += chunk.size;
    8476                chunk.buffer += chunk.size;
    8577                chunk.size = page_size - total;
Note: See TracChangeset for help on using the changeset viewer.