Changeset 58898d1d in mainline for uspace/app


Ignore:
Timestamp:
2017-03-24T20:31:54Z (9 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/app
Files:
12 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;
Note: See TracChangeset for help on using the changeset viewer.